diff options
author | Max Kellermann <max@duempel.org> | 2011-11-27 23:39:21 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-11-28 11:39:21 +0100 |
commit | e1b032cbad5db7698104a93c2235fb7da1f8b580 (patch) | |
tree | 85140e9f2e7a0486b69705e2709154f794769c5d | |
parent | 6f365c30eb33c40193defb827b03a8fd293bfc23 (diff) | |
download | mpd-e1b032cbad5db7698104a93c2235fb7da1f8b580.tar.gz mpd-e1b032cbad5db7698104a93c2235fb7da1f8b580.tar.xz mpd-e1b032cbad5db7698104a93c2235fb7da1f8b580.zip |
decoder/ffmpeg: work around bogus channel count
Initialize the audio_format before calling avcodec_open(), because
avcodec_open() will fill bogus values.
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | src/decoder/ffmpeg_decoder_plugin.c | 20 |
2 files changed, 13 insertions, 8 deletions
@@ -1,6 +1,7 @@ ver 0.16.6 (2010/??/??) * decoder: - fix assertion failure when resuming streams + - ffmpeg: work around bogus channel count * encoder: - flac, null, wave: fix buffer corruption bug - wave: support packed 24 bit samples diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index ba47b2c2c..34a6b3ebd 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -407,13 +407,6 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) return; } - if (avcodec_open(codec_context, codec)<0) { - g_warning("Could not open codec\n"); - av_close_input_stream(format_context); - mpd_ffmpeg_stream_close(stream); - return; - } - GError *error = NULL; struct audio_format audio_format; if (!audio_format_init_checked(&audio_format, @@ -422,7 +415,18 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input) codec_context->channels, &error)) { g_warning("%s", error->message); g_error_free(error); - avcodec_close(codec_context); + av_close_input_stream(format_context); + mpd_ffmpeg_stream_close(stream); + return; + } + + /* the audio format must be read from AVCodecContext by now, + because avcodec_open() has been demonstrated to fill bogus + values into AVCodecContext.channels - a change that will be + reverted later by avcodec_decode_audio3() */ + + if (avcodec_open(codec_context, codec)<0) { + g_warning("Could not open codec\n"); av_close_input_stream(format_context); mpd_ffmpeg_stream_close(stream); return; |