From cf7d6e3374ca3d54e71124b54ead5fdd8d6973e1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Apr 2013 18:15:44 +0200 Subject: Move Libav global initialization to main.c. --- src/decoder/libav_decoder_plugin.c | 39 -------------------------------------- src/main.c | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/decoder/libav_decoder_plugin.c b/src/decoder/libav_decoder_plugin.c index 2b37e67d..88dd4a8f 100644 --- a/src/decoder/libav_decoder_plugin.c +++ b/src/decoder/libav_decoder_plugin.c @@ -54,35 +54,6 @@ typedef struct LibavDecContext { AVStream *ast; } LibavDecContext; -static GLogLevelFlags level_libav_to_glib(int level) -{ - if (level <= AV_LOG_FATAL) - return G_LOG_LEVEL_CRITICAL; - - if (level <= AV_LOG_ERROR) - return G_LOG_LEVEL_WARNING; - - if (level <= AV_LOG_INFO) - return G_LOG_LEVEL_MESSAGE; - - return G_LOG_LEVEL_DEBUG; -} - -static void mpd_libav_log_callback(void *ptr, int level, - const char *fmt, va_list vl) -{ - const AVClass * cls = NULL; - - if (ptr != NULL) - cls = *(const AVClass *const*)ptr; - - if (cls != NULL) { - char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL); - g_logv(domain, level_libav_to_glib(level), fmt, vl); - g_free(domain); - } -} - static int mpd_libav_stream_read(void *opaque, uint8_t *buf, int size) { LibavDecContext *stream = opaque; @@ -176,15 +147,6 @@ fail: return ret; } -static bool -libav_init(const struct config_param *param) -{ - av_log_set_callback(mpd_libav_log_callback); - - av_register_all(); - return true; -} - static double time_from_libav(int64_t t, const AVRational time_base) { assert(t != (int64_t)AV_NOPTS_VALUE); @@ -524,7 +486,6 @@ static const char *const libav_mime_types[] = { const struct decoder_plugin libav_decoder_plugin = { .name = "libav", - .init = libav_init, .stream_decode = libav_decode, .scan_stream = libav_scan_stream, .suffixes = libav_suffixes, diff --git a/src/main.c b/src/main.c index b13358c1..aa8d9e3b 100644 --- a/src/main.c +++ b/src/main.c @@ -71,6 +71,10 @@ #include +#include +#include +#include + #include #include #include @@ -97,6 +101,34 @@ GCond *main_cond; struct player_control *global_player_control; +static GLogLevelFlags level_libav_to_glib(int level) +{ + if (level <= AV_LOG_FATAL) + return G_LOG_LEVEL_CRITICAL; + + if (level <= AV_LOG_ERROR) + return G_LOG_LEVEL_WARNING; + + if (level <= AV_LOG_INFO) + return G_LOG_LEVEL_MESSAGE; + + return G_LOG_LEVEL_DEBUG; +} + +static void libav_log_callback(void *ptr, int level, const char *fmt, va_list vl) +{ + const AVClass * cls = NULL; + + if (ptr != NULL) + cls = *(const AVClass *const*)ptr; + + if (cls != NULL) { + char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL); + g_logv(domain, level_libav_to_glib(level), fmt, vl); + g_free(domain); + } +} + static bool glue_daemonize_init(const struct options *options, GError **error_r) { @@ -346,6 +378,8 @@ int mpd_main(int argc, char *argv[]) idle_init(); tag_pool_init(); config_global_init(); + av_register_all(); + av_log_set_callback(libav_log_callback); success = parse_cmdline(argc, argv, &options, &error); if (!success) { -- cgit v1.2.3