From e67ce8ae4b9121bbcef2c1dcb61bdb5b9330ad78 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 27 Sep 2023 00:16:38 +0200 Subject: [PATCH 1/1] Fix errors with WAVs containing markers (#2617). 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 | 2 +- src/lib/audio_buffers.cc | 2 +- src/lib/audio_buffers.h | 2 +- src/lib/ffmpeg_decoder.cc | 4 ++++ test/content_test.cc | 9 +++++++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/run/tests b/run/tests index b71cd6a66..42d3634fb 100755 --- 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 diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc index 4f01146f9..0e31793ea 100644 --- a/src/lib/audio_buffers.cc +++ b/src/lib/audio_buffers.cc @@ -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(); }; diff --git a/src/lib/audio_buffers.h b/src/lib/audio_buffers.h index 645348aa0..b43179663 100644 --- a/src/lib/audio_buffers.h +++ b/src/lib/audio_buffers.h @@ -60,7 +60,7 @@ public: } int frames () const { - return _data[0].size(); + return _data.empty() ? 0 : _data[0].size(); } void set_frames (int f); diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index efe151530..c3d32bc75 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -266,6 +266,10 @@ deinterleave_audio(AVFrame* frame) auto audio = make_shared(channels, frames); auto data = audio->data(); + if (frames == 0) { + return audio; + } + switch (format) { case AV_SAMPLE_FMT_U8: { diff --git a/test/content_test.cc b/test/content_test.cc index 47099025e..5ab714b47 100644 --- a/test/content_test.cc +++ b/test/content_test.cc @@ -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 }); +} -- 2.30.2