Fix crash when FFMpeg doesn't set up the audio channel layout for some reason.
authorCarl Hetherington <cth@carlh.net>
Wed, 12 Sep 2012 11:06:43 +0000 (12:06 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 12 Sep 2012 11:06:43 +0000 (12:06 +0100)
ChangeLog
src/lib/ffmpeg_decoder.cc

index fcb18baa1910672d9e8a1f030133d9b7c0f6d50c..47f701c295dd81e5bc1588654289d78c7992b53c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-09-12  Carl Hetherington  <cth@carlh.net>
+
+       * Fix crash when FFmpeg doesn't set up the audio channel
+       layout for some reason.
+
 2012-09-01  Carl Hetherington  <cth@carlh.net>
 
        * Add 1.66-within-flat format.
index c12e6728df299d310607bd46a17ecc5223e8fec6..3471ffaab1b5ae50ba733ee4c41d9b2b366b12af 100644 (file)
@@ -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;
 }