X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=test%2Fffmpeg_audio_only_test.cc;h=ea9a9c4e54161d18c12616579ad06fcdacd63c52;hp=e3c90cba984e25700189ead6752899142662eeaa;hb=6d686ea45f5cd01a0d11f92a903ac77779ad8562;hpb=4b05c69e14f43826a59128b4b27316c9f9d9a84e diff --git a/test/ffmpeg_audio_only_test.cc b/test/ffmpeg_audio_only_test.cc index e3c90cba9..ea9a9c4e5 100644 --- a/test/ffmpeg_audio_only_test.cc +++ b/test/ffmpeg_audio_only_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016-2017 Carl Hetherington + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,11 +18,13 @@ */ + /** @file test/ffmpeg_audio_only_test.cc * @brief Test FFmpeg content with audio but no video. - * @ingroup specific + * @ingroup feature */ + #include "lib/film.h" #include "lib/ffmpeg_content.h" #include "lib/dcp_content_type.h" @@ -36,20 +38,26 @@ #include #include + using std::min; -using boost::shared_ptr; +using std::shared_ptr; +using std::make_shared; +#if BOOST_VERSION >= 106100 +using namespace boost::placeholders; +#endif + + +static SNDFILE* ref = nullptr; +static std::vector ref_buffer; -static SNDFILE* ref = 0; -static int ref_buffer_size = 0; -static float* ref_buffer = 0; static void -audio (boost::shared_ptr audio, int channels) +audio (std::shared_ptr audio, int channels) { /* Check that we have a big enough buffer */ - BOOST_CHECK (audio->frames() * audio->channels() < ref_buffer_size); + BOOST_CHECK (audio->frames() * audio->channels() < static_cast(ref_buffer.size())); - int const N = sf_readf_float (ref, ref_buffer, audio->frames()); + int const N = sf_readf_float (ref, ref_buffer.data(), audio->frames()); for (int i = 0; i < N; ++i) { switch (channels) { case 1: @@ -65,21 +73,21 @@ audio (boost::shared_ptr audio, int channels) } } + /** Test the FFmpeg code with audio-only content */ static shared_ptr test (boost::filesystem::path file) { - shared_ptr film = new_test_film ("ffmpeg_audio_only_test"); + auto film = new_test_film ("ffmpeg_audio_only_test"); film->set_name ("test_film"); film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST")); - shared_ptr c (new FFmpegContent (film, file)); + auto c = make_shared(file); film->examine_and_add_content (c); - wait_for_jobs (); + BOOST_REQUIRE (!wait_for_jobs()); film->write_metadata (); /* See if can make a DCP without any errors */ - film->make_dcp (); - wait_for_jobs (); + make_and_verify_dcp (film, {dcp::VerificationNote::Code::MISSING_CPL_METADATA}); BOOST_CHECK (!JobManager::instance()->errors()); /* Compare the audio data player reads with what libsndfile reads */ @@ -89,24 +97,23 @@ test (boost::filesystem::path file) ref = sf_open (file.string().c_str(), SFM_READ, &info); /* We don't want to test anything that requires resampling */ BOOST_REQUIRE_EQUAL (info.samplerate, 48000); - ref_buffer_size = info.samplerate * info.channels; - ref_buffer = new float[ref_buffer_size]; + ref_buffer.resize(info.samplerate * info.channels); - shared_ptr player (new Player (film, film->playlist ())); + auto player = make_shared(film, Image::Alignment::COMPACT); player->Audio.connect (bind (&audio, _1, info.channels)); while (!player->pass ()) {} sf_close (ref); - delete[] ref_buffer; return film; } + BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test1) { /* S16 */ - shared_ptr film = test ("test/data/staircase.wav"); + auto film = test ("test/data/staircase.wav"); /* Compare the audio data in the DCP with what libsndfile reads */ @@ -116,27 +123,26 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test1) /* We don't want to test anything that requires resampling */ BOOST_REQUIRE_EQUAL (info.samplerate, 48000); - int16_t* buffer = new int16_t[info.channels * 2000]; + std::vector buffer(info.channels * 2000); dcp::SoundAsset asset (dcp_file(film, "pcm")); - shared_ptr reader = asset.start_read (); + auto reader = asset.start_read (); for (int i = 0; i < asset.intrinsic_duration(); ++i) { - shared_ptr frame = reader->get_frame(i); + auto frame = reader->get_frame(i); sf_count_t this_time = min (info.frames, sf_count_t(2000)); - sf_readf_short (ref, buffer, this_time); + sf_readf_short (ref, buffer.data(), this_time); for (int j = 0; j < this_time; ++j) { BOOST_REQUIRE_EQUAL (frame->get(2, j) >> 8, buffer[j]); } info.frames -= this_time; } - - delete[] buffer; } + BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test2) { /* S32 1 channel */ - shared_ptr film = test ("test/data/sine_440.wav"); + auto film = test ("test/data/sine_440.wav"); /* Compare the audio data in the DCP with what libsndfile reads */ @@ -146,14 +152,14 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test2) /* We don't want to test anything that requires resampling */ BOOST_REQUIRE_EQUAL (info.samplerate, 48000); - int32_t* buffer = new int32_t[info.channels * 2000]; + std::vector buffer(info.channels * 2000); dcp::SoundAsset asset (dcp_file(film, "pcm")); - shared_ptr reader = asset.start_read (); + auto reader = asset.start_read (); for (int i = 0; i < asset.intrinsic_duration(); ++i) { - shared_ptr frame = reader->get_frame(i); + auto frame = reader->get_frame(i); sf_count_t this_time = min (info.frames, sf_count_t(2000)); - sf_readf_int (ref, buffer, this_time); + sf_readf_int (ref, buffer.data(), this_time); for (int j = 0; j < this_time; ++j) { int32_t s = frame->get(2, j); if (s > (1 << 23)) { @@ -163,14 +169,13 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test2) } info.frames -= this_time; } - - delete[] buffer; } + BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test3) { /* S24 1 channel */ - shared_ptr film = test ("test/data/sine_24_48_440.wav"); + auto film = test ("test/data/sine_24_48_440.wav"); /* Compare the audio data in the DCP with what libsndfile reads */ @@ -180,14 +185,14 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test3) /* We don't want to test anything that requires resampling */ BOOST_REQUIRE_EQUAL (info.samplerate, 48000); - int32_t* buffer = new int32_t[info.channels * 2000]; + std::vector buffer(info.channels * 2000); dcp::SoundAsset asset (dcp_file(film, "pcm")); - shared_ptr reader = asset.start_read (); + auto reader = asset.start_read (); for (int i = 0; i < asset.intrinsic_duration(); ++i) { - shared_ptr frame = reader->get_frame(i); + auto frame = reader->get_frame(i); sf_count_t this_time = min (info.frames, sf_count_t(2000)); - sf_readf_int (ref, buffer, this_time); + sf_readf_int (ref, buffer.data(), this_time); for (int j = 0; j < this_time; ++j) { int32_t s = frame->get(2, j); if (s > (1 << 23)) { @@ -197,6 +202,4 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test3) } info.frames -= this_time; } - - delete[] buffer; }