aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2013-04-22 18:15:44 +0200
committerAnton Khirnov <anton@khirnov.net>2013-11-04 11:02:13 +0100
commitcf7d6e3374ca3d54e71124b54ead5fdd8d6973e1 (patch)
tree6fb7e8737678fc497e3933645dbaecd0ff01c52c
parent7c6ac43f82d3870f65832f1f5aa74f26bc9cd9ab (diff)
Move Libav global initialization to main.c.
-rw-r--r--src/decoder/libav_decoder_plugin.c39
-rw-r--r--src/main.c34
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 <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) {