test/run_decder: RAII-style global initialization
This commit is contained in:
parent
65bbb0e0aa
commit
53acb7bfcb
@ -35,6 +35,23 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
class GlobalInit {
|
||||||
|
EventThread io_thread;
|
||||||
|
|
||||||
|
public:
|
||||||
|
GlobalInit() {
|
||||||
|
io_thread.Start();
|
||||||
|
|
||||||
|
input_stream_global_init(io_thread.GetEventLoop());
|
||||||
|
decoder_plugin_init_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
~GlobalInit() {
|
||||||
|
decoder_plugin_deinit_all();
|
||||||
|
input_stream_global_finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
try {
|
try {
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
@ -42,16 +59,10 @@ try {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeDecoder decoder;
|
|
||||||
const char *const decoder_name = argv[1];
|
const char *const decoder_name = argv[1];
|
||||||
const char *const uri = argv[2];
|
const char *const uri = argv[2];
|
||||||
|
|
||||||
EventThread io_thread;
|
const GlobalInit init;
|
||||||
io_thread.Start();
|
|
||||||
|
|
||||||
input_stream_global_init(io_thread.GetEventLoop());
|
|
||||||
|
|
||||||
decoder_plugin_init_all();
|
|
||||||
|
|
||||||
const DecoderPlugin *plugin = decoder_plugin_from_name(decoder_name);
|
const DecoderPlugin *plugin = decoder_plugin_from_name(decoder_name);
|
||||||
if (plugin == nullptr) {
|
if (plugin == nullptr) {
|
||||||
@ -59,6 +70,7 @@ try {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FakeDecoder decoder;
|
||||||
if (plugin->file_decode != nullptr) {
|
if (plugin->file_decode != nullptr) {
|
||||||
plugin->FileDecode(decoder, Path::FromFS(uri));
|
plugin->FileDecode(decoder, Path::FromFS(uri));
|
||||||
} else if (plugin->stream_decode != nullptr) {
|
} else if (plugin->stream_decode != nullptr) {
|
||||||
@ -70,9 +82,6 @@ try {
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder_plugin_deinit_all();
|
|
||||||
input_stream_global_finish();
|
|
||||||
|
|
||||||
if (!decoder.initialized) {
|
if (!decoder.initialized) {
|
||||||
fprintf(stderr, "Decoding failed\n");
|
fprintf(stderr, "Decoding failed\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
Loading…
Reference in New Issue
Block a user