X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fffmpeg_audio_only_test.cc;h=716cf505558e9d9dc6093a8e7fb854e64f49deb5;hb=86765a617035e0283c20c9f2696909743e618156;hp=8541ccecae04cf62a338cd6718640c2aa1768e65;hpb=7557ce631ab3e0b62e9683d03ef641e86a93a5de;p=dcpomatic.git diff --git a/test/ffmpeg_audio_only_test.cc b/test/ffmpeg_audio_only_test.cc index 8541cceca..716cf5055 100644 --- a/test/ffmpeg_audio_only_test.cc +++ b/test/ffmpeg_audio_only_test.cc @@ -1,39 +1,109 @@ /* Copyright (C) 2016 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ +/** @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" +#include "lib/player.h" +#include "lib/job_manager.h" +#include "lib/audio_buffers.h" #include "test.h" +#include #include using boost::shared_ptr; +static SNDFILE* ref = 0; +static int ref_buffer_size = 0; +static float* ref_buffer = 0; + +static void +audio (boost::shared_ptr audio, int channels) +{ + /* Check that we have a big enough buffer */ + BOOST_CHECK (audio->frames() * audio->channels() < ref_buffer_size); + + int const N = sf_readf_float (ref, ref_buffer, audio->frames()); + for (int i = 0; i < N; ++i) { + switch (channels) { + case 1: + BOOST_CHECK_EQUAL (ref_buffer[i], audio->data(2)[i]); + break; + case 2: + BOOST_CHECK_EQUAL (ref_buffer[i*2 + 0], audio->data(0)[i]); + BOOST_CHECK_EQUAL (ref_buffer[i*2 + 1], audio->data(1)[i]); + break; + default: + BOOST_REQUIRE (false); + } + } +} + /** Test the FFmpeg code with audio-only content */ -BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test) +static void +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_pretty_name ("Test")); - shared_ptr c (new FFmpegContent (film, "test/data/sine_440.mp3")); + film->set_dcp_content_type (DCPContentType::from_isdcf_name ("TST")); + shared_ptr c (new FFmpegContent (film, file)); film->examine_and_add_content (c); wait_for_jobs (); + film->write_metadata (); + + /* See if can make a DCP without any errors */ film->make_dcp (); wait_for_jobs (); + BOOST_CHECK (!JobManager::instance()->errors()); + + /* Compare the audio data we read with what libsndfile reads */ + + SF_INFO info; + info.format = 0; + 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]; + + shared_ptr player (new Player (film, film->playlist ())); + + player->Audio.connect (bind (&audio, _1, info.channels)); + while (!player->pass ()) {} + + sf_close (ref); +} + +BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test1) +{ + /* S16 */ + test ("test/data/staircase.wav"); +} + +BOOST_AUTO_TEST_CASE (ffmpeg_audio_only_test2) +{ + /* S32 1 channel */ + test ("test/data/sine_440.wav"); }