Fix crash with sub-sample push parts in AudioMerger. v2.15.42
authorCarl Hetherington <cth@carlh.net>
Mon, 27 Jan 2020 23:19:52 +0000 (23:19 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 28 Jan 2020 20:58:47 +0000 (21:58 +0100)
Forward-ported from b86b15391074a68149f8c4a51958c7873d74def0 in master.

src/lib/audio_merger.cc
test/audio_merger_test.cc

index 1cc5ff0a19de156bdee0e7e6a6dd3da56e47dc49..667068f8ff2a284f6f64e5d5fc3374440d970b8d 100644 (file)
@@ -138,9 +138,10 @@ AudioMerger::push (boost::shared_ptr<const AudioBuffers> audio, DCPTime time)
                part->copy_from (audio.get(), part->frames(), frames(DCPTime(i.from - time)), 0);
 
                if (before == _buffers.end() && after == _buffers.end()) {
-                       /* New buffer */
-                       DCPOMATIC_ASSERT (part->frames() > 0);
-                       _buffers.push_back (Buffer (part, time, _frame_rate));
+                       if (part->frames() > 0) {
+                               /* New buffer */
+                               _buffers.push_back (Buffer (part, time, _frame_rate));
+                       }
                } else if (before != _buffers.end() && after == _buffers.end()) {
                        /* We have an existing buffer before this one; append new data to it */
                        before->audio->append (part);
index 4a1f689dd9b6bd4a07b6a88105f269c755b0510d..2ac42964ad80318732cc6dc5a19e59e2054fcdf2 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
  *  @ingroup selfcontained
  */
 
+#include "lib/cross.h"
 #include "lib/audio_merger.h"
 #include "lib/audio_buffers.h"
+#include "lib/dcpomatic_time.h"
+#include "test.h"
+#include <dcp/raw_convert.h>
 #include <boost/test/unit_test.hpp>
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
@@ -34,6 +38,7 @@
 using std::pair;
 using std::list;
 using std::cout;
+using std::string;
 using boost::shared_ptr;
 using boost::bind;
 using namespace dcpomatic;
@@ -135,3 +140,42 @@ BOOST_AUTO_TEST_CASE (audio_merger_test3)
                BOOST_CHECK_EQUAL (tb.front().first->data()[0][i], i);
        }
 }
+
+/* Reply a sequence of calls to AudioMerger that resulted in a crash */
+BOOST_AUTO_TEST_CASE (audio_merger_test4)
+{
+       FILE* f = fopen_boost("test/data/audio_merger_bug1.log", "r");
+       BOOST_REQUIRE (f);
+       list<string> tokens;
+       char buf[64];
+       while (fscanf(f, "%63s", buf) == 1) {
+               tokens.push_back (buf);
+       }
+
+       shared_ptr<AudioMerger> merger;
+       list<string>::const_iterator i = tokens.begin ();
+       while (i != tokens.end()) {
+               BOOST_CHECK (*i++ == "I/AM");
+               string const cmd = *i++;
+               if (cmd == "frame_rate") {
+                       BOOST_REQUIRE (i != tokens.end());
+                       merger.reset (new AudioMerger(dcp::raw_convert<int>(*i++)));
+               } else if (cmd == "clear") {
+                       merger->clear ();
+               } else if (cmd == "push") {
+                       BOOST_REQUIRE (i != tokens.end());
+                       DCPTime time(dcp::raw_convert<DCPTime::Type>(*i++));
+                       BOOST_REQUIRE (i != tokens.end());
+                       int const frames = dcp::raw_convert<int>(*i++);
+                       shared_ptr<AudioBuffers> buffers(new AudioBuffers(1, frames));
+                       BOOST_REQUIRE (merger);
+                       merger->push (buffers, time);
+               } else if (cmd == "pull") {
+                       BOOST_REQUIRE (i != tokens.end());
+                       DCPTime time(dcp::raw_convert<DCPTime::Type>(*i++));
+                       merger->pull (time);
+               }
+       }
+}
+
+