Fix crash on rounding in AudioMerger.
authorCarl Hetherington <cth@carlh.net>
Sat, 13 May 2017 12:30:44 +0000 (13:30 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 13 May 2017 12:30:44 +0000 (13:30 +0100)
src/lib/audio_merger.cc

index 275a4769145e5e4ab02d6a80386db4f3a59c61e7..8a69dee5204036381253a4f23e54ba12892587e6 100644 (file)
@@ -69,13 +69,15 @@ AudioMerger::pull (DCPTime time)
                } else if (i.time < time) {
                        /* Overlaps the end of the pull period */
                        shared_ptr<AudioBuffers> audio (new AudioBuffers (i.audio->channels(), frames(DCPTime(time - i.time))));
-                       audio->copy_from (i.audio.get(), audio->frames(), 0, 0);
-                       DCPOMATIC_ASSERT (audio->frames() > 0);
-                       out.push_back (make_pair (audio, i.time));
-                       i.audio->trim_start (audio->frames ());
-                       i.time += DCPTime::from_frames(audio->frames(), _frame_rate);
-                       DCPOMATIC_ASSERT (i.audio->frames() > 0);
-                       new_buffers.push_back (i);
+                       /* Though time > i.time, audio->frames() could be 0 if the difference in time is less than one frame */
+                       if (audio->frames() > 0) {
+                               audio->copy_from (i.audio.get(), audio->frames(), 0, 0);
+                               out.push_back (make_pair (audio, i.time));
+                               i.audio->trim_start (audio->frames ());
+                               i.time += DCPTime::from_frames(audio->frames(), _frame_rate);
+                               DCPOMATIC_ASSERT (i.audio->frames() > 0);
+                               new_buffers.push_back (i);
+                       }
                } else {
                        /* Not involved */
                        DCPOMATIC_ASSERT (i.audio->frames() > 0);