Fix crash when a frame being deinterleaved has fewer audio channels
authorCarl Hetherington <cth@carlh.net>
Tue, 9 Feb 2016 00:15:31 +0000 (00:15 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 9 Feb 2016 00:15:31 +0000 (00:15 +0000)
than its stream; I'm not sure why this happens but the file that
triggered this commit was stereo AC3 and the crash happened when
(embedded) subtitles were enabled and the file seek was seeked
randomly.  There were frame-sync errors from FFmpeg around the crash.

src/lib/ffmpeg_decoder.cc

index c25efa463c8f61121d70a5e6fcac98a88bb63211..c1448ad905c35b0f20f118fab2a92d8e5f662a32 100644 (file)
@@ -225,9 +225,13 @@ FFmpegDecoder::deinterleave_audio (shared_ptr<FFmpegAudioStream> stream, uint8_t
        case AV_SAMPLE_FMT_FLTP:
        {
                float** p = reinterpret_cast<float**> (data);
-               for (int i = 0; i < stream->channels(); ++i) {
+               /* Sometimes there aren't as many channels in the _frame as in the stream */
+               for (int i = 0; i < _frame->channels; ++i) {
                        memcpy (audio->data(i), p[i], frames * sizeof(float));
                }
+               for (int i = _frame->channels; i < stream->channels(); ++i) {
+                       audio->make_silent (i);
+               }
        }
        break;