X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Fffmpeg_audio_only_test.cc;h=a8a7184c4e264883b7de730afec4adc3cc4c073c;hb=16013e6658cdba6f5682b6e57402094d142b5f84;hp=a7e2ca02548181d81eca3e6f7330f723fefd1b6a;hpb=639fd201ac8c94b76ee686b07bcc8ec3f1e83da7;p=dcpomatic.git diff --git a/test/ffmpeg_audio_only_test.cc b/test/ffmpeg_audio_only_test.cc index a7e2ca025..a8a7184c4 100644 --- a/test/ffmpeg_audio_only_test.cc +++ b/test/ffmpeg_audio_only_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington + Copyright (C) 2016-2017 Carl Hetherington This file is part of DCP-o-matic. @@ -18,6 +18,11 @@ */ +/** @file test/ffmpeg_audio_only_test.cc + * @brief Test FFmpeg content with audio but no video. + * @ingroup specific + */ + #include "lib/film.h" #include "lib/ffmpeg_content.h" #include "lib/dcp_content_type.h" @@ -25,9 +30,13 @@ #include "lib/job_manager.h" #include "lib/audio_buffers.h" #include "test.h" +#include +#include #include #include +#include +using std::min; using boost::shared_ptr; static SNDFILE* ref = 0; @@ -57,23 +66,23 @@ audio (boost::shared_ptr audio, int channels) } /** Test the FFmpeg code with audio-only content */ -static void +static shared_ptr test (boost::filesystem::path file) { shared_ptr 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)); + shared_ptr c (new FFmpegContent(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 (); + BOOST_REQUIRE (!wait_for_jobs()); BOOST_CHECK (!JobManager::instance()->errors()); - /* Compare the audio data we read with what libsndfile reads */ + /* Compare the audio data player reads with what libsndfile reads */ SF_INFO info; info.format = 0; @@ -89,16 +98,105 @@ test (boost::filesystem::path file) while (!player->pass ()) {} sf_close (ref); + delete[] ref_buffer; + + return film; } BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test1) { /* S16 */ - test ("test/data/staircase.wav"); + shared_ptr film = test ("test/data/staircase.wav"); + + /* Compare the audio data in the DCP with what libsndfile reads */ + + SF_INFO info; + info.format = 0; + ref = sf_open ("test/data/staircase.wav", SFM_READ, &info); + /* 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]; + + dcp::SoundAsset asset (dcp_file(film, "pcm")); + shared_ptr reader = asset.start_read (); + for (int i = 0; i < asset.intrinsic_duration(); ++i) { + shared_ptr frame = reader->get_frame(i); + sf_count_t this_time = min (info.frames, sf_count_t(2000)); + sf_readf_short (ref, buffer, 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 */ - test ("test/data/sine_440.wav"); + shared_ptr film = test ("test/data/sine_440.wav"); + + /* Compare the audio data in the DCP with what libsndfile reads */ + + SF_INFO info; + info.format = 0; + ref = sf_open ("test/data/sine_440.wav", SFM_READ, &info); + /* 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]; + + dcp::SoundAsset asset (dcp_file(film, "pcm")); + shared_ptr reader = asset.start_read (); + for (int i = 0; i < asset.intrinsic_duration(); ++i) { + shared_ptr frame = reader->get_frame(i); + sf_count_t this_time = min (info.frames, sf_count_t(2000)); + sf_readf_int (ref, buffer, this_time); + for (int j = 0; j < this_time; ++j) { + int32_t s = frame->get(2, j); + if (s > (1 << 23)) { + s -= (1 << 24); + } + BOOST_REQUIRE_MESSAGE (abs(s - (buffer[j] / 256)) <= 1, "failed on asset frame " << i << " sample " << j); + } + 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"); + + /* Compare the audio data in the DCP with what libsndfile reads */ + + SF_INFO info; + info.format = 0; + ref = sf_open ("test/data/sine_24_48_440.wav", SFM_READ, &info); + /* 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]; + + dcp::SoundAsset asset (dcp_file(film, "pcm")); + shared_ptr reader = asset.start_read (); + for (int i = 0; i < asset.intrinsic_duration(); ++i) { + shared_ptr frame = reader->get_frame(i); + sf_count_t this_time = min (info.frames, sf_count_t(2000)); + sf_readf_int (ref, buffer, this_time); + for (int j = 0; j < this_time; ++j) { + int32_t s = frame->get(2, j); + if (s > (1 << 23)) { + s -= (1 << 24); + } + BOOST_REQUIRE_MESSAGE (abs(s - buffer[j] /256) <= 1, "failed on asset frame " << i << " sample " << j); + } + info.frames -= this_time; + } + + delete[] buffer; }