diff options
author | Max Kellermann <max@duempel.org> | 2013-09-27 22:31:24 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-02 08:57:55 +0200 |
commit | 060814daa83f6a94f5934464ae42a406c5c7e947 (patch) | |
tree | f636ec6cdbb8e52fda6db987d2a28fc73c7b94b4 /src/decoder/FfmpegDecoderPlugin.cxx | |
parent | c53492a76a8a05825e1c7f699c05645eee891199 (diff) | |
download | mpd-060814daa83f6a94f5934464ae42a406c5c7e947.tar.gz mpd-060814daa83f6a94f5934464ae42a406c5c7e947.tar.xz mpd-060814daa83f6a94f5934464ae42a406c5c7e947.zip |
Log: new logging library API
Prepare to migrate away from GLib. Currently, we're still using GLib
as a backend.
Diffstat (limited to 'src/decoder/FfmpegDecoderPlugin.cxx')
-rw-r--r-- | src/decoder/FfmpegDecoderPlugin.cxx | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx index a725e1f7d..646b8f974 100644 --- a/src/decoder/FfmpegDecoderPlugin.cxx +++ b/src/decoder/FfmpegDecoderPlugin.cxx @@ -28,6 +28,8 @@ #include "InputStream.hxx" #include "CheckAudioFormat.hxx" #include "util/Error.hxx" +#include "util/Domain.hxx" +#include "LogV.hxx" #include <glib.h> @@ -50,27 +52,26 @@ extern "C" { #include <libavutil/dict.h> } -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "ffmpeg" +static constexpr Domain ffmpeg_domain("ffmpeg"); /* suppress the ffmpeg compatibility macro */ #ifdef SampleFormat #undef SampleFormat #endif -static GLogLevelFlags -level_ffmpeg_to_glib(int level) +static LogLevel +import_ffmpeg_level(int level) { if (level <= AV_LOG_FATAL) - return G_LOG_LEVEL_CRITICAL; + return LogLevel::ERROR; - if (level <= AV_LOG_ERROR) - return G_LOG_LEVEL_WARNING; + if (level <= AV_LOG_WARNING) + return LogLevel::WARNING; if (level <= AV_LOG_INFO) - return G_LOG_LEVEL_MESSAGE; + return LogLevel::INFO; - return G_LOG_LEVEL_DEBUG; + return LogLevel::DEBUG; } static void @@ -83,8 +84,9 @@ mpd_ffmpeg_log_callback(gcc_unused void *ptr, int level, cls = *(const AVClass *const*)ptr; if (cls != NULL) { - char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL); - g_logv(domain, level_ffmpeg_to_glib(level), fmt, vl); + char *domain = g_strconcat(ffmpeg_domain.GetName(), "/", cls->item_name(ptr), NULL); + const Domain d(domain); + LogFormatV(d, import_ffmpeg_level(level), fmt, vl); g_free(domain); } } @@ -287,7 +289,8 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is, if (len < 0) { /* if error, we skip the frame */ - g_message("decoding failed, frame skipped\n"); + LogInfo(ffmpeg_domain, + "decoding failed, frame skipped"); break; } @@ -328,11 +331,13 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt) const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer), sample_fmt); if (name != NULL) - g_warning("Unsupported libavcodec SampleFormat value: %s (%d)", - name, sample_fmt); + FormatError(ffmpeg_domain, + "Unsupported libavcodec SampleFormat value: %s (%d)", + name, sample_fmt); else - g_warning("Unsupported libavcodec SampleFormat value: %d", - sample_fmt); + FormatError(ffmpeg_domain, + "Unsupported libavcodec SampleFormat value: %d", + sample_fmt); return SampleFormat::UNDEFINED; } @@ -377,12 +382,12 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) if (input_format == NULL) return; - g_debug("detected input format '%s' (%s)", - input_format->name, input_format->long_name); + FormatDebug(ffmpeg_domain, "detected input format '%s' (%s)", + input_format->name, input_format->long_name); AvioStream stream(decoder, input); if (!stream.Open()) { - g_warning("Failed to open stream"); + LogError(ffmpeg_domain, "Failed to open stream"); return; } @@ -391,21 +396,21 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) if (mpd_ffmpeg_open_input(&format_context, stream.io, input->uri.c_str(), input_format) != 0) { - g_warning("Open failed\n"); + LogError(ffmpeg_domain, "Open failed"); return; } const int find_result = avformat_find_stream_info(format_context, NULL); if (find_result < 0) { - g_warning("Couldn't find stream info\n"); + LogError(ffmpeg_domain, "Couldn't find stream info"); avformat_close_input(&format_context); return; } int audio_stream = ffmpeg_find_audio_stream(format_context); if (audio_stream == -1) { - g_warning("No audio stream inside\n"); + LogError(ffmpeg_domain, "No audio stream inside"); avformat_close_input(&format_context); return; } @@ -414,12 +419,13 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) AVCodecContext *codec_context = av_stream->codec; if (codec_context->codec_name[0] != 0) - g_debug("codec '%s'", codec_context->codec_name); + FormatDebug(ffmpeg_domain, "codec '%s'", + codec_context->codec_name); AVCodec *codec = avcodec_find_decoder(codec_context->codec_id); if (!codec) { - g_warning("Unsupported audio codec\n"); + LogError(ffmpeg_domain, "Unsupported audio codec"); avformat_close_input(&format_context); return; } @@ -435,7 +441,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) codec_context->sample_rate, sample_format, codec_context->channels, error)) { - g_warning("%s", error.GetMessage()); + LogError(error); avformat_close_input(&format_context); return; } @@ -447,7 +453,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) const int open_result = avcodec_open2(codec_context, codec, NULL); if (open_result < 0) { - g_warning("Could not open codec\n"); + LogError(ffmpeg_domain, "Could not open codec"); avformat_close_input(&format_context); return; } @@ -461,7 +467,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) AVFrame *frame = avcodec_alloc_frame(); if (!frame) { - g_warning("Could not allocate frame\n"); + LogError(ffmpeg_domain, "Could not allocate frame"); avformat_close_input(&format_context); return; } |