From edd4f83959b196bef442387f99ecece034171464 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 12 Sep 2012 12:06:43 +0100 Subject: Fix crash when FFMpeg doesn't set up the audio channel layout for some reason. --- src/lib/ffmpeg_decoder.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index c12e6728d..3471ffaab 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -142,10 +142,18 @@ FFmpegDecoder::setup_audio () if (_audio_codec == 0) { throw DecodeError ("could not find audio decoder"); } - + if (avcodec_open2 (_audio_codec_context, _audio_codec, 0) < 0) { throw DecodeError ("could not open audio decoder"); } + + /* This is a hack; sometimes it seems that _audio_codec_context->channel_layout isn't set up, + so bodge it here. No idea why we should have to do this. + */ + + if (_audio_codec_context->channel_layout == 0) { + _audio_codec_context->channel_layout = av_get_default_channel_layout (audio_channels ()); + } } bool @@ -200,7 +208,7 @@ FFmpegDecoder::audio_channels () const if (_audio_codec_context == 0) { return 0; } - + return _audio_codec_context->channels; } -- cgit v1.2.3