Fix errors with WAVs containing markers (#2617).
authorCarl Hetherington <cth@carlh.net>
Tue, 26 Sep 2023 22:16:38 +0000 (00:16 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 28 Sep 2023 22:57:58 +0000 (00:57 +0200)
I'm not 100% sure about this but they seem to end up giving audio
packets with no channels and no frames.  Here we handle such packets
better.

run/tests
src/lib/audio_buffers.cc
src/lib/audio_buffers.h
src/lib/ffmpeg_decoder.cc
test/content_test.cc

index b71cd6a66ccf92b3f55e8acb94e2d2476de0efd4..42d3634fbba35a80171af31604b129ce51321646 100755 (executable)
--- a/run/tests
+++ b/run/tests
@@ -3,7 +3,7 @@
 # e.g. --run_tests=foo
 set -e
 
-PRIVATE_GIT="155d46e5c2a5a37c2269884b021c69b0d7d41f22"
+PRIVATE_GIT="a057b086149254d1ea70a4fd7efcd88791335dcd"
 
 if [ "$1" == "--check" ]; then
        shift 1
index 4f01146f9ddc7e66abce2323a8711d6efb572056..0e31793ea2d7634035343fb2245e562af442b9a0 100644 (file)
@@ -81,7 +81,7 @@ void
 AudioBuffers::allocate (int channels, int frames)
 {
        DCPOMATIC_ASSERT (frames >= 0);
-       DCPOMATIC_ASSERT (channels > 0);
+       DCPOMATIC_ASSERT(frames == 0 || channels > 0);
 
        ScopeGuard sg = [this]() { update_data_pointers(); };
 
index 645348aa0ef7e557513629c9a628a9df5c544fa4..b43179663093ea8eb549692bf841974f694f436a 100644 (file)
@@ -60,7 +60,7 @@ public:
        }
 
        int frames () const {
-               return _data[0].size();
+               return _data.empty() ? 0 : _data[0].size();
        }
 
        void set_frames (int f);
index efe1515302dcfc5170119030aacd01f9b8b03fd1..c3d32bc752306abd1beb81f6042a80a9bc9acc9c 100644 (file)
@@ -266,6 +266,10 @@ deinterleave_audio(AVFrame* frame)
        auto audio = make_shared<AudioBuffers>(channels, frames);
        auto data = audio->data();
 
+       if (frames == 0) {
+               return audio;
+       }
+
        switch (format) {
        case AV_SAMPLE_FMT_U8:
        {
index 47099025efbd18d59d4e599ac4ae4791f5a843d6..5ab714b47ad8e46a5363eef8fc939417853a4b32 100644 (file)
@@ -168,3 +168,12 @@ BOOST_AUTO_TEST_CASE (content_test7)
        content[0]->audio->set_delay(-1000);
        make_and_verify_dcp (film, { dcp::VerificationNote::Code::INVALID_PICTURE_FRAME_RATE_FOR_2K });
 }
+
+
+/** WAVs with markers (I think) can end up making audio packets with no channels and no frames (#2617) */
+BOOST_AUTO_TEST_CASE(wav_with_markers_zero_channels_test)
+{
+       auto content = content_factory(TestPaths::private_data() / "wav_with_markers.wav");
+       auto film = new_test_film2("wav_with_markers_zero_channels_test", content);
+       make_and_verify_dcp(film, { dcp::VerificationNote::Code::MISSING_CPL_METADATA });
+}