Fix incorrect audio MXFs when writing multiple reels.
authorCarl Hetherington <cth@carlh.net>
Sun, 11 Jun 2017 22:05:48 +0000 (23:05 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 11 Jun 2017 22:05:48 +0000 (23:05 +0100)
src/lib/writer.cc
test/data
test/reels_test.cc

index ae00c0122478f6d721ffa23d51dd128d8d37e603..064c3f0ec08db18da764b54a1b218c8f6759c598 100644 (file)
@@ -247,23 +247,21 @@ Writer::write (shared_ptr<const AudioBuffers> audio)
                        return;
                }
 
-               int32_t const this_time = min (
-                       audio->frames() - offset,
-                       (int32_t) (_audio_reel->period().duration().frames_floor(_film->audio_frame_rate()) - _audio_reel->total_written_audio_frames())
-                       );
+               int32_t const remaining = audio->frames() - offset;
+               int32_t const reel_space = _audio_reel->period().duration().frames_floor(_film->audio_frame_rate()) - _audio_reel->total_written_audio_frames();
 
-               if (this_time == audio->frames()) {
+               if (remaining <= reel_space) {
                        /* Easy case: we can write all the audio to this reel */
                        _audio_reel->write (audio);
+                       offset += remaining;
                } else {
                        /* Write the part we can */
-                       shared_ptr<AudioBuffers> part (new AudioBuffers (audio->channels(), this_time));
-                       part->copy_from (audio.get(), this_time, offset, 0);
+                       shared_ptr<AudioBuffers> part (new AudioBuffers (audio->channels(), reel_space));
+                       part->copy_from (audio.get(), reel_space, offset, 0);
                        _audio_reel->write (part);
                        ++_audio_reel;
+                       offset += reel_space;
                }
-
-               offset += this_time;
        }
 }
 
index 8ae9a3a8e7c48c5c0a8c64e6fa2fcc34ee3a1e32..789bd241695300320126152037ae171ec6581466 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 8ae9a3a8e7c48c5c0a8c64e6fa2fcc34ee3a1e32
+Subproject commit 789bd241695300320126152037ae171ec6581466
index b53f26ede7743d73a28fdf7532785d5616765ad5..6dd40c13e8bf6b8dcd50609e5a92e9245fc2fc1b 100644 (file)
@@ -278,3 +278,22 @@ BOOST_AUTO_TEST_CASE (reels_test5)
                BOOST_CHECK (*i++ == DCPTimePeriod (DCPTime(123 + 144000), DCPTime(123 + 192000)));
        }
 }
+
+/** Check reel split with a muxed video/audio source */
+BOOST_AUTO_TEST_CASE (reels_test6)
+{
+       shared_ptr<Film> film = new_test_film ("reels_test6");
+       film->set_name ("reels_test6");
+       film->set_container (Ratio::from_id ("185"));
+       film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST"));
+       shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test2.mp4"));
+       film->examine_and_add_content (A);
+       BOOST_REQUIRE (!wait_for_jobs ());
+
+       film->set_j2k_bandwidth (100000000);
+       film->set_reel_type (REELTYPE_BY_LENGTH);
+       /* This is just over 2.5s at 100Mbit/s; should correspond to 60 frames */
+       film->set_reel_length (31253154);
+       film->make_dcp ();
+       BOOST_REQUIRE (!wait_for_jobs ());
+}