diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -71,6 +71,10 @@ #include <glib.h> +#include <libavcodec/avcodec.h> +#include <libavformat/avformat.h> +#include <libavutil/log.h> + #include <unistd.h> #include <stdlib.h> #include <errno.h> @@ -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) { |