diff options
Diffstat (limited to 'test')
30 files changed, 756 insertions, 409 deletions
diff --git a/test/audio_analysis_test.cc b/test/audio_analysis_test.cc index 77b2aeaf6..b94b12056 100644 --- a/test/audio_analysis_test.cc +++ b/test/audio_analysis_test.cc @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE (audio_analysis_test) AudioAnalysis b ("build/test/audio_analysis_test"); for (int i = 0; i < channels; ++i) { - BOOST_CHECK (b.points(i) == points); + BOOST_CHECK_EQUAL (b.points(i), points); for (int j = 0; j < points; ++j) { AudioPoint p = b.get_point (i, j); BOOST_CHECK_CLOSE (p[AudioPoint::PEAK], random_float (), 1); diff --git a/test/audio_delay_test.cc b/test/audio_delay_test.cc index 77243ea6d..2e02fa999 100644 --- a/test/audio_delay_test.cc +++ b/test/audio_delay_test.cc @@ -18,10 +18,11 @@ */ #include <boost/test/unit_test.hpp> -#include <libdcp/sound_frame.h> -#include <libdcp/cpl.h> -#include <libdcp/reel.h> -#include <libdcp/sound_asset.h> +#include <dcp/sound_frame.h> +#include <dcp/cpl.h> +#include <dcp/reel.h> +#include <dcp/sound_mxf.h> +#include <dcp/reel_sound_asset.h> #include "lib/sndfile_content.h" #include "lib/dcp_content_type.h" #include "lib/ratio.h" @@ -53,10 +54,10 @@ void test_audio_delay (int delay_in_ms) boost::filesystem::path path = "build/test"; path /= film_name; path /= film->dcp_name (); - libdcp::DCP check (path.string ()); + dcp::DCP check (path.string ()); check.read (); - shared_ptr<const libdcp::SoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); + shared_ptr<const dcp::ReelSoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); BOOST_CHECK (sound_asset); /* Sample index in the DCP */ @@ -66,11 +67,11 @@ void test_audio_delay (int delay_in_ms) /* Delay in frames */ int const delay_in_frames = delay_in_ms * 48000 / 1000; - while (n < sound_asset->intrinsic_duration()) { - shared_ptr<const libdcp::SoundFrame> sound_frame = sound_asset->get_frame (frame++); + while (n < sound_asset->mxf()->intrinsic_duration()) { + shared_ptr<const dcp::SoundFrame> sound_frame = sound_asset->mxf()->get_frame (frame++); uint8_t const * d = sound_frame->data (); - for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->channels())) { + for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->mxf()->channels())) { /* Mono input so it will appear on centre */ int const sample = d[i + 7] | (d[i + 8] << 8); diff --git a/test/audio_mapping_test.cc b/test/audio_mapping_test.cc index a2a74104b..1fc20dcaf 100644 --- a/test/audio_mapping_test.cc +++ b/test/audio_mapping_test.cc @@ -35,10 +35,10 @@ BOOST_AUTO_TEST_CASE (audio_mapping_test) for (int i = 0; i < 4; ++i) { for (int j = 0; j < MAX_AUDIO_CHANNELS; ++j) { - BOOST_CHECK_EQUAL (four.get (i, static_cast<libdcp::Channel> (j)), i == j ? 1 : 0); + BOOST_CHECK_EQUAL (four.get (i, static_cast<dcp::Channel> (j)), i == j ? 1 : 0); } } - four.set (0, libdcp::RIGHT, 1); - BOOST_CHECK_EQUAL (four.get (0, libdcp::RIGHT), 1); + four.set (0, dcp::RIGHT, 1); + BOOST_CHECK_EQUAL (four.get (0, dcp::RIGHT), 1); } diff --git a/test/audio_merger_test.cc b/test/audio_merger_test.cc deleted file mode 100644 index 31d055ab7..000000000 --- a/test/audio_merger_test.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> - - This program 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, - 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. - -*/ - -#include <boost/test/unit_test.hpp> -#include <boost/bind.hpp> -#include <boost/function.hpp> -#include <boost/signals2.hpp> -#include "lib/audio_merger.h" -#include "lib/audio_buffers.h" - -using boost::shared_ptr; -using boost::bind; - -static shared_ptr<const AudioBuffers> last_audio; - -static int -pass_through (int x) -{ - return x; -} - -BOOST_AUTO_TEST_CASE (audio_merger_test1) -{ - AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1)); - - /* Push 64 samples, 0 -> 63 at time 0 */ - shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64)); - for (int i = 0; i < 64; ++i) { - buffers->data()[0][i] = i; - } - merger.push (buffers, 0); - - /* Push 64 samples, 0 -> 63 at time 22 */ - merger.push (buffers, 22); - - TimedAudioBuffers<int> tb = merger.pull (22); - BOOST_CHECK (tb.audio != shared_ptr<const AudioBuffers> ()); - BOOST_CHECK_EQUAL (tb.audio->frames(), 22); - BOOST_CHECK_EQUAL (tb.time, 0); - - /* And they should be a staircase */ - for (int i = 0; i < 22; ++i) { - BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i); - } - - tb = merger.flush (); - - /* That flush should give us 64 samples at 22 */ - BOOST_CHECK_EQUAL (tb.audio->frames(), 64); - BOOST_CHECK_EQUAL (tb.time, 22); - - /* Check the sample values */ - for (int i = 0; i < 64; ++i) { - int correct = i; - if (i < (64 - 22)) { - correct += i + 22; - } - BOOST_CHECK_EQUAL (tb.audio->data()[0][i], correct); - } -} - -BOOST_AUTO_TEST_CASE (audio_merger_test2) -{ - AudioMerger<int, int> merger (1, bind (&pass_through, _1), boost::bind (&pass_through, _1)); - - /* Push 64 samples, 0 -> 63 at time 9 */ - shared_ptr<AudioBuffers> buffers (new AudioBuffers (1, 64)); - for (int i = 0; i < 64; ++i) { - buffers->data()[0][i] = i; - } - merger.push (buffers, 9); - - TimedAudioBuffers<int> tb = merger.pull (9); - BOOST_CHECK_EQUAL (tb.audio->frames(), 9); - BOOST_CHECK_EQUAL (tb.time, 0); - - for (int i = 0; i < 9; ++i) { - BOOST_CHECK_EQUAL (tb.audio->data()[0][i], 0); - } - - tb = merger.flush (); - - /* That flush should give us 64 samples at 9 */ - BOOST_CHECK_EQUAL (tb.audio->frames(), 64); - BOOST_CHECK_EQUAL (tb.time, 9); - - /* Check the sample values */ - for (int i = 0; i < 64; ++i) { - BOOST_CHECK_EQUAL (tb.audio->data()[0][i], i); - } -} diff --git a/test/black_fill_test.cc b/test/black_fill_test.cc index c2170d891..a7e44bdfb 100644 --- a/test/black_fill_test.cc +++ b/test/black_fill_test.cc @@ -46,10 +46,10 @@ BOOST_AUTO_TEST_CASE (black_fill_test) film->examine_and_add_content (contentB); wait_for_jobs (); - contentA->set_video_length (3); - contentA->set_position (film->video_frames_to_time (2)); - contentB->set_video_length (1); - contentB->set_position (film->video_frames_to_time (7)); + contentA->set_video_length (ContentTime::from_frames (3, 24)); + contentA->set_position (DCPTime::from_frames (2, film->video_frame_rate ())); + contentB->set_video_length (ContentTime::from_frames (1, 24)); + contentB->set_position (DCPTime::from_frames (7, film->video_frame_rate ())); film->make_dcp (); diff --git a/test/client_server_test.cc b/test/client_server_test.cc index 1ad156ae3..54bbd520f 100644 --- a/test/client_server_test.cc +++ b/test/client_server_test.cc @@ -36,12 +36,12 @@ do_remote_encode (shared_ptr<DCPVideoFrame> frame, ServerDescription description BOOST_CHECK (remotely_encoded); BOOST_CHECK_EQUAL (locally_encoded->size(), remotely_encoded->size()); - BOOST_CHECK (memcmp (locally_encoded->data(), remotely_encoded->data(), locally_encoded->size()) == 0); + BOOST_CHECK_EQUAL (memcmp (locally_encoded->data(), remotely_encoded->data(), locally_encoded->size()), 0); } BOOST_AUTO_TEST_CASE (client_server_test) { - shared_ptr<Image> image (new Image (PIX_FMT_RGB24, libdcp::Size (1998, 1080), true)); + shared_ptr<Image> image (new Image (PIX_FMT_RGB24, dcp::Size (1998, 1080), true)); uint8_t* p = image->data()[0]; for (int y = 0; y < 1080; ++y) { @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE (client_server_test) p += image->stride()[0]; } - shared_ptr<Image> sub_image (new Image (PIX_FMT_RGBA, libdcp::Size (100, 200), true)); + shared_ptr<Image> sub_image (new Image (PIX_FMT_RGBA, dcp::Size (100, 200), true)); p = sub_image->data()[0]; for (int y = 0; y < 200; ++y) { uint8_t* q = p; diff --git a/test/colour_conversion_test.cc b/test/colour_conversion_test.cc index 3e90d542a..0cf3a616b 100644 --- a/test/colour_conversion_test.cc +++ b/test/colour_conversion_test.cc @@ -18,7 +18,7 @@ */ #include <boost/test/unit_test.hpp> -#include <libdcp/colour_matrix.h> +#include <dcp/colour_matrix.h> #include "lib/colour_conversion.h" using std::cout; @@ -26,8 +26,8 @@ using std::cout; /* Basic test of identifier() for ColourConversion (i.e. a hash of the numbers) */ BOOST_AUTO_TEST_CASE (colour_conversion_test) { - ColourConversion A (2.4, true, libdcp::colour_matrix::srgb_to_xyz, 2.6); - ColourConversion B (2.4, false, libdcp::colour_matrix::srgb_to_xyz, 2.6); + ColourConversion A (2.4, true, dcp::colour_matrix::srgb_to_xyz, 2.6); + ColourConversion B (2.4, false, dcp::colour_matrix::srgb_to_xyz, 2.6); BOOST_CHECK_EQUAL (A.identifier(), "246ff9b7dc32c0488948a32a713924b3"); BOOST_CHECK_EQUAL (B.identifier(), "a8d1da30f96a121d8db06a03409758b3"); diff --git a/test/ffmpeg_audio_test.cc b/test/ffmpeg_audio_test.cc index 2e83d45c9..48422259c 100644 --- a/test/ffmpeg_audio_test.cc +++ b/test/ffmpeg_audio_test.cc @@ -17,12 +17,17 @@ */ +/** @file test/ffmpeg_audio_test.cc + * @brief A simple test of reading audio from an FFmpeg file. + */ + #include <boost/test/unit_test.hpp> -#include <libdcp/cpl.h> -#include <libdcp/dcp.h> -#include <libdcp/sound_asset.h> -#include <libdcp/sound_frame.h> -#include <libdcp/reel.h> +#include <dcp/cpl.h> +#include <dcp/dcp.h> +#include <dcp/sound_mxf.h> +#include <dcp/sound_frame.h> +#include <dcp/reel_sound_asset.h> +#include <dcp/reel.h> #include "lib/sndfile_content.h" #include "lib/film.h" #include "lib/dcp_content_type.h" @@ -55,56 +60,56 @@ BOOST_AUTO_TEST_CASE (ffmpeg_audio_test) boost::filesystem::path path = "build/test"; path /= "ffmpeg_audio_test"; path /= film->dcp_name (); - libdcp::DCP check (path.string ()); + dcp::DCP check (path.string ()); check.read (); - shared_ptr<const libdcp::SoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); + shared_ptr<const dcp::ReelSoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); BOOST_CHECK (sound_asset); - BOOST_CHECK (sound_asset->channels () == 6); + BOOST_CHECK_EQUAL (sound_asset->mxf()->channels (), 6); /* Sample index in the DCP */ int n = 0; /* DCP sound asset frame */ int frame = 0; - while (n < sound_asset->intrinsic_duration()) { - shared_ptr<const libdcp::SoundFrame> sound_frame = sound_asset->get_frame (frame++); + while (n < sound_asset->mxf()->intrinsic_duration()) { + shared_ptr<const dcp::SoundFrame> sound_frame = sound_asset->mxf()->get_frame (frame++); uint8_t const * d = sound_frame->data (); - for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->channels())) { + for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->mxf()->channels())) { - if (sound_asset->channels() > 0) { + if (sound_asset->mxf()->channels() > 0) { /* L should be silent */ int const sample = d[i + 0] | (d[i + 1] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 1) { + if (sound_asset->mxf()->channels() > 1) { /* R should be silent */ int const sample = d[i + 2] | (d[i + 3] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 2) { + if (sound_asset->mxf()->channels() > 2) { /* Mono input so it will appear on centre */ int const sample = d[i + 7] | (d[i + 8] << 8); BOOST_CHECK_EQUAL (sample, n); } - if (sound_asset->channels() > 3) { + if (sound_asset->mxf()->channels() > 3) { /* Lfe should be silent */ int const sample = d[i + 9] | (d[i + 10] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 4) { + if (sound_asset->mxf()->channels() > 4) { /* Ls should be silent */ int const sample = d[i + 11] | (d[i + 12] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 5) { + if (sound_asset->mxf()->channels() > 5) { /* Rs should be silent */ int const sample = d[i + 13] | (d[i + 14] << 8); BOOST_CHECK_EQUAL (sample, 0); diff --git a/test/ffmpeg_decoder_seek_test.cc b/test/ffmpeg_decoder_seek_test.cc new file mode 100644 index 000000000..76124786e --- /dev/null +++ b/test/ffmpeg_decoder_seek_test.cc @@ -0,0 +1,85 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +#include <vector> +#include <boost/test/unit_test.hpp> +#include <boost/filesystem.hpp> +#include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_decoder.h" +#include "lib/log.h" +#include "lib/film.h" +#include "test.h" + +using std::cerr; +using std::vector; +using boost::shared_ptr; +using boost::optional; + +static void +check (FFmpegDecoder& decoder, int frame) +{ + optional<ContentVideo> v; + v = decoder.get_video (frame, true); + BOOST_CHECK (v); + BOOST_CHECK_EQUAL (v->frame, frame); +} + +static void +test (boost::filesystem::path file, vector<int> frames) +{ + boost::filesystem::path path = private_data / file; + if (!boost::filesystem::exists (path)) { + cerr << "Skipping test: " << path.string() << " not found.\n"; + return; + } + + shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string()); + shared_ptr<FFmpegContent> content (new FFmpegContent (film, path)); + film->examine_and_add_content (content); + wait_for_jobs (); + shared_ptr<Log> log (new NullLog); + FFmpegDecoder decoder (content, log); + + for (vector<int>::const_iterator i = frames.begin(); i != frames.end(); ++i) { + check (decoder, *i); + } +} + +BOOST_AUTO_TEST_CASE (ffmpeg_decoder_seek_test) +{ + vector<int> frames; + + frames.clear (); + frames.push_back (0); + frames.push_back (42); + frames.push_back (999); + frames.push_back (0); + + test ("boon_telly.mkv", frames); + test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", frames); + + frames.clear (); + frames.push_back (15); + frames.push_back (42); + frames.push_back (999); + frames.push_back (15); + + test ("prophet_clip.mkv", frames); +} + diff --git a/test/ffmpeg_decoder_sequential_test.cc b/test/ffmpeg_decoder_sequential_test.cc new file mode 100644 index 000000000..96de9be27 --- /dev/null +++ b/test/ffmpeg_decoder_sequential_test.cc @@ -0,0 +1,76 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +#include <boost/test/unit_test.hpp> +#include <boost/filesystem.hpp> +#include "lib/ffmpeg_content.h" +#include "lib/ffmpeg_decoder.h" +#include "lib/log.h" +#include "lib/film.h" +#include "test.h" + +using std::cout; +using std::cerr; +using boost::shared_ptr; +using boost::optional; + +/** @param black Frame index of first frame in the video */ +static void +test (boost::filesystem::path file, float fps, int first) +{ + boost::filesystem::path path = private_data / file; + if (!boost::filesystem::exists (path)) { + cerr << "Skipping test: " << path.string() << " not found.\n"; + return; + } + + shared_ptr<Film> film = new_test_film ("ffmpeg_decoder_seek_test_" + file.string()); + shared_ptr<FFmpegContent> content (new FFmpegContent (film, path)); + film->examine_and_add_content (content); + wait_for_jobs (); + shared_ptr<Log> log (new NullLog); + FFmpegDecoder decoder (content, log); + + BOOST_CHECK_CLOSE (decoder.video_content()->video_frame_rate(), fps, 0.01); + + VideoFrame const N = decoder.video_content()->video_length().frames (decoder.video_content()->video_frame_rate ()); + decoder.test_gaps = 0; + for (VideoFrame i = 0; i < N; ++i) { + optional<ContentVideo> v; + v = decoder.get_video (i, true); + if (i < first) { + BOOST_CHECK (!v); + } else { + BOOST_CHECK (v); + BOOST_CHECK_EQUAL (v->frame, i); + } + } + BOOST_CHECK_EQUAL (decoder.test_gaps, 0); +} + +/** Check that the FFmpeg decoder produces sequential frames without gaps or dropped frames; + * (dropped frames being checked by assert() in VideoDecoder). Also that the decoder picks up frame rates correctly. + */ +BOOST_AUTO_TEST_CASE (ffmpeg_decoder_sequential_test) +{ + //test ("boon_telly.mkv", 29.97, 0); + //test ("Sintel_Trailer1.480p.DivX_Plus_HD.mkv", 24, 0); + test ("prophet_clip.mkv", 23.976, 12); +} + diff --git a/test/ffmpeg_examiner_test.cc b/test/ffmpeg_examiner_test.cc index a3b9bb4f6..93a913870 100644 --- a/test/ffmpeg_examiner_test.cc +++ b/test/ffmpeg_examiner_test.cc @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_examiner_test) shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd24.m2ts")); shared_ptr<FFmpegExaminer> examiner (new FFmpegExaminer (content)); - BOOST_CHECK_EQUAL (examiner->first_video().get(), 600); + BOOST_CHECK_EQUAL (examiner->first_video().get(), ContentTime (600)); BOOST_CHECK_EQUAL (examiner->audio_streams().size(), 1); - BOOST_CHECK_EQUAL (examiner->audio_streams()[0]->first_audio.get(), 600); + BOOST_CHECK_EQUAL (examiner->audio_streams()[0]->first_audio.get(), ContentTime (600)); } diff --git a/test/ffmpeg_pts_offset.cc b/test/ffmpeg_pts_offset.cc index 6caf0d07a..dc391ed46 100644 --- a/test/ffmpeg_pts_offset.cc +++ b/test/ffmpeg_pts_offset.cc @@ -34,48 +34,43 @@ BOOST_AUTO_TEST_CASE (ffmpeg_pts_offset_test) { /* Sound == video so no offset required */ - content->_first_video = 0; - content->_audio_stream->first_audio = 0; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._pts_offset, 0); - BOOST_CHECK_EQUAL (decoder._pts_offset, 0); + content->_first_video = ContentTime (); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime ()); } { /* Common offset should be removed */ - content->_first_video = 600; - content->_audio_stream->first_audio = 600; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._pts_offset, -600); - BOOST_CHECK_EQUAL (decoder._pts_offset, -600); + content->_first_video = ContentTime::from_seconds (600); + content->_audio_stream->first_audio = ContentTime::from_seconds (600); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime::from_seconds (-600)); } { /* Video is on a frame boundary */ - content->_first_video = 1.0 / 24.0; - content->_audio_stream->first_audio = 0; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._pts_offset, 0); - BOOST_CHECK_EQUAL (decoder._pts_offset, 0); + content->_first_video = ContentTime::from_frames (1, 24); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_EQUAL (decoder._pts_offset, ContentTime ()); } { /* Video is off a frame boundary */ double const frame = 1.0 / 24.0; - content->_first_video = frame + 0.0215; - content->_audio_stream->first_audio = 0; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_CLOSE (decoder._pts_offset, (frame - 0.0215), 0.00001); - BOOST_CHECK_CLOSE (decoder._pts_offset, (frame - 0.0215), 0.00001); + content->_first_video = ContentTime::from_seconds (frame + 0.0215); + content->_audio_stream->first_audio = ContentTime (); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_CLOSE (decoder._pts_offset.seconds(), (frame - 0.0215), 0.00001); } { /* Video is off a frame boundary and both have a common offset */ double const frame = 1.0 / 24.0; - content->_first_video = frame + 0.0215 + 4.1; - content->_audio_stream->first_audio = 4.1; - FFmpegDecoder decoder (film, content, true, true); - BOOST_CHECK_EQUAL (decoder._pts_offset, (frame - 0.0215) - 4.1); - BOOST_CHECK_EQUAL (decoder._pts_offset, (frame - 0.0215) - 4.1); + content->_first_video = ContentTime::from_seconds (frame + 0.0215 + 4.1); + content->_audio_stream->first_audio = ContentTime::from_seconds (4.1); + FFmpegDecoder decoder (content, film->log()); + BOOST_CHECK_EQUAL (decoder._pts_offset.seconds(), (frame - 0.0215) - 4.1); } } diff --git a/test/frame_rate_test.cc b/test/frame_rate_test.cc index fdfdcf452..2135b3738 100644 --- a/test/frame_rate_test.cc +++ b/test/frame_rate_test.cc @@ -47,91 +47,102 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) content->_video_frame_rate = 60; int best = film->playlist()->best_dcp_frame_rate (); - FrameRateConversion frc = FrameRateConversion (60, best); + FrameRateChange frc = FrameRateChange (60, best); BOOST_CHECK_EQUAL (best, 30); BOOST_CHECK_EQUAL (frc.skip, true); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 50; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (50, best); + frc = FrameRateChange (50, best); BOOST_CHECK_EQUAL (best, 25); BOOST_CHECK_EQUAL (frc.skip, true); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 48; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (48, best); + frc = FrameRateChange (48, best); BOOST_CHECK_EQUAL (best, 24); BOOST_CHECK_EQUAL (frc.skip, true); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 30; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (30, best); + frc = FrameRateChange (30, best); BOOST_CHECK_EQUAL (best, 30); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 29.97; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (29.97, best); + frc = FrameRateChange (29.97, best); BOOST_CHECK_EQUAL (best, 30); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 30 / 29.97, 0.1); content->_video_frame_rate = 25; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (25, best); + frc = FrameRateChange (25, best); BOOST_CHECK_EQUAL (best, 25); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 24; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (24, best); + frc = FrameRateChange (24, best); BOOST_CHECK_EQUAL (best, 24); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 14.5; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (14.5, best); + frc = FrameRateChange (14.5, best); BOOST_CHECK_EQUAL (best, 30); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 15 / 14.5, 0.1); content->_video_frame_rate = 12.6; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (12.6, best); + frc = FrameRateChange (12.6, best); BOOST_CHECK_EQUAL (best, 25); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 25 / 25.2, 0.1); content->_video_frame_rate = 12.4; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (12.4, best); + frc = FrameRateChange (12.4, best); BOOST_CHECK_EQUAL (best, 25); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 25 / 24.8, 0.1); content->_video_frame_rate = 12; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (12, best); + frc = FrameRateChange (12, best); BOOST_CHECK_EQUAL (best, 24); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); /* Now add some more rates and see if it will use them in preference to skip/repeat. @@ -144,34 +155,38 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) content->_video_frame_rate = 60; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (60, best); + frc = FrameRateChange (60, best); BOOST_CHECK_EQUAL (best, 60); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 50; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (50, best); + frc = FrameRateChange (50, best); BOOST_CHECK_EQUAL (best, 50); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); content->_video_frame_rate = 48; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (48, best); + frc = FrameRateChange (48, best); BOOST_CHECK_EQUAL (best, 48); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, false); + BOOST_CHECK_CLOSE (frc.speed_up, 1, 0.1); /* Check some out-there conversions (not the best) */ - frc = FrameRateConversion (14.99, 24); + frc = FrameRateChange (14.99, 24); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 2); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 24 / (2 * 14.99), 0.1); /* Check some conversions with limited DCP targets */ @@ -181,14 +196,15 @@ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_single) content->_video_frame_rate = 25; best = film->playlist()->best_dcp_frame_rate (); - frc = FrameRateConversion (25, best); + frc = FrameRateChange (25, best); BOOST_CHECK_EQUAL (best, 24); BOOST_CHECK_EQUAL (frc.skip, false); BOOST_CHECK_EQUAL (frc.repeat, 1); BOOST_CHECK_EQUAL (frc.change_speed, true); + BOOST_CHECK_CLOSE (frc.speed_up, 24.0 / 25, 0.1); } -/* Test Playlist::best_dcp_frame_rate and FrameRateConversion +/* Test Playlist::best_dcp_frame_rate and FrameRateChange with two pieces of content. */ BOOST_AUTO_TEST_CASE (best_dcp_frame_rate_test_double) @@ -266,7 +282,7 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test) content->_video_frame_rate = 14.99; film->set_video_frame_rate (25); content->set_audio_stream (shared_ptr<FFmpegAudioStream> (new FFmpegAudioStream ("a", 42, 16000, 0))); - /* The FrameRateConversion within output_audio_frame_rate should choose to double-up + /* The FrameRateChange within output_audio_frame_rate should choose to double-up the 14.99 fps video to 30 and then run it slow at 25. */ BOOST_CHECK_EQUAL (content->output_audio_frame_rate(), rint (48000 * 2 * 14.99 / 25)); diff --git a/test/image_test.cc b/test/image_test.cc index 51ad49ebf..f876c8f65 100644 --- a/test/image_test.cc +++ b/test/image_test.cc @@ -28,7 +28,7 @@ using boost::shared_ptr; BOOST_AUTO_TEST_CASE (aligned_image_test) { - Image* s = new Image (PIX_FMT_RGB24, libdcp::Size (50, 50), true); + Image* s = new Image (PIX_FMT_RGB24, dcp::Size (50, 50), true); BOOST_CHECK_EQUAL (s->components(), 1); /* 160 is 150 aligned to the nearest 32 bytes */ BOOST_CHECK_EQUAL (s->stride()[0], 160); @@ -50,12 +50,12 @@ BOOST_AUTO_TEST_CASE (aligned_image_test) BOOST_CHECK (t->data() != s->data()); BOOST_CHECK (t->data()[0] != s->data()[0]); BOOST_CHECK (t->line_size() != s->line_size()); - BOOST_CHECK (t->line_size()[0] == s->line_size()[0]); + BOOST_CHECK_EQUAL (t->line_size()[0], s->line_size()[0]); BOOST_CHECK (t->stride() != s->stride()); - BOOST_CHECK (t->stride()[0] == s->stride()[0]); + BOOST_CHECK_EQUAL (t->stride()[0], s->stride()[0]); /* assignment operator */ - Image* u = new Image (PIX_FMT_YUV422P, libdcp::Size (150, 150), false); + Image* u = new Image (PIX_FMT_YUV422P, dcp::Size (150, 150), false); *u = *s; BOOST_CHECK_EQUAL (u->components(), 1); BOOST_CHECK_EQUAL (u->stride()[0], 160); @@ -67,9 +67,9 @@ BOOST_AUTO_TEST_CASE (aligned_image_test) BOOST_CHECK (u->data() != s->data()); BOOST_CHECK (u->data()[0] != s->data()[0]); BOOST_CHECK (u->line_size() != s->line_size()); - BOOST_CHECK (u->line_size()[0] == s->line_size()[0]); + BOOST_CHECK_EQUAL (u->line_size()[0], s->line_size()[0]); BOOST_CHECK (u->stride() != s->stride()); - BOOST_CHECK (u->stride()[0] == s->stride()[0]); + BOOST_CHECK_EQUAL (u->stride()[0], s->stride()[0]); delete s; delete t; @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE (aligned_image_test) BOOST_AUTO_TEST_CASE (compact_image_test) { - Image* s = new Image (PIX_FMT_RGB24, libdcp::Size (50, 50), false); + Image* s = new Image (PIX_FMT_RGB24, dcp::Size (50, 50), false); BOOST_CHECK_EQUAL (s->components(), 1); BOOST_CHECK_EQUAL (s->stride()[0], 50 * 3); BOOST_CHECK_EQUAL (s->line_size()[0], 50 * 3); @@ -99,12 +99,12 @@ BOOST_AUTO_TEST_CASE (compact_image_test) BOOST_CHECK (t->data() != s->data()); BOOST_CHECK (t->data()[0] != s->data()[0]); BOOST_CHECK (t->line_size() != s->line_size()); - BOOST_CHECK (t->line_size()[0] == s->line_size()[0]); + BOOST_CHECK_EQUAL (t->line_size()[0], s->line_size()[0]); BOOST_CHECK (t->stride() != s->stride()); - BOOST_CHECK (t->stride()[0] == s->stride()[0]); + BOOST_CHECK_EQUAL (t->stride()[0], s->stride()[0]); /* assignment operator */ - Image* u = new Image (PIX_FMT_YUV422P, libdcp::Size (150, 150), true); + Image* u = new Image (PIX_FMT_YUV422P, dcp::Size (150, 150), true); *u = *s; BOOST_CHECK_EQUAL (u->components(), 1); BOOST_CHECK_EQUAL (u->stride()[0], 50 * 3); @@ -116,9 +116,9 @@ BOOST_AUTO_TEST_CASE (compact_image_test) BOOST_CHECK (u->data() != s->data()); BOOST_CHECK (u->data()[0] != s->data()[0]); BOOST_CHECK (u->line_size() != s->line_size()); - BOOST_CHECK (u->line_size()[0] == s->line_size()[0]); + BOOST_CHECK_EQUAL (u->line_size()[0], s->line_size()[0]); BOOST_CHECK (u->stride() != s->stride()); - BOOST_CHECK (u->stride()[0] == s->stride()[0]); + BOOST_CHECK_EQUAL (u->stride()[0], s->stride()[0]); delete s; delete t; @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE (compact_image_test) BOOST_AUTO_TEST_CASE (crop_image_test) { /* This was to check out a bug with valgrind, and is probably not very useful */ - shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, libdcp::Size (16, 16), true)); + shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, dcp::Size (16, 16), true)); image->make_black (); Crop crop; crop.top = 3; @@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE (crop_image_test) BOOST_AUTO_TEST_CASE (crop_image_test2) { /* Here's a 1998 x 1080 image which is black */ - shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, libdcp::Size (1998, 1080), true)); + shared_ptr<Image> image (new Image (PIX_FMT_YUV420P, dcp::Size (1998, 1080), true)); image->make_black (); /* Crop it by 1 pixel */ @@ -170,7 +170,7 @@ boost::shared_ptr<Image> read_file (string file) { Magick::Image magick_image (file.c_str ()); - libdcp::Size size (magick_image.columns(), magick_image.rows()); + dcp::Size size (magick_image.columns(), magick_image.rows()); boost::shared_ptr<Image> image (new Image (PIX_FMT_RGB24, size, true)); @@ -214,7 +214,7 @@ write_file (shared_ptr<Image> image, string file) static void -crop_scale_window_single (AVPixelFormat in_format, libdcp::Size in_size, Crop crop, libdcp::Size inter_size, libdcp::Size out_size) +crop_scale_window_single (AVPixelFormat in_format, dcp::Size in_size, Crop crop, dcp::Size inter_size, dcp::Size out_size) { /* Set up our test image */ shared_ptr<Image> test (new Image (in_format, in_size, true)); @@ -262,12 +262,12 @@ crop_scale_window_single (AVPixelFormat in_format, libdcp::Size in_size, Crop cr /** Test Image::crop_scale_window against separate calls to crop/scale/copy */ BOOST_AUTO_TEST_CASE (crop_scale_window_test) { - crop_scale_window_single (AV_PIX_FMT_YUV422P, libdcp::Size (640, 480), Crop (), libdcp::Size (640, 480), libdcp::Size (640, 480)); - crop_scale_window_single (AV_PIX_FMT_YUV422P, libdcp::Size (640, 480), Crop (2, 4, 6, 8), libdcp::Size (640, 480), libdcp::Size (640, 480)); - crop_scale_window_single (AV_PIX_FMT_YUV422P, libdcp::Size (640, 480), Crop (2, 4, 6, 8), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_YUV422P, libdcp::Size (640, 480), Crop (1, 4, 6, 8), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_YUV420P, libdcp::Size (640, 480), Crop (16, 16, 0, 0), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_YUV420P, libdcp::Size (640, 480), Crop (16, 3, 3, 0), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_RGB24, libdcp::Size (1000, 800), Crop (0, 0, 0, 0), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); - crop_scale_window_single (AV_PIX_FMT_RGB24, libdcp::Size (1000, 800), Crop (55, 0, 1, 9), libdcp::Size (1920, 1080), libdcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_YUV422P, dcp::Size (640, 480), Crop (), dcp::Size (640, 480), dcp::Size (640, 480)); + crop_scale_window_single (AV_PIX_FMT_YUV422P, dcp::Size (640, 480), Crop (2, 4, 6, 8), dcp::Size (640, 480), dcp::Size (640, 480)); + crop_scale_window_single (AV_PIX_FMT_YUV422P, dcp::Size (640, 480), Crop (2, 4, 6, 8), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_YUV422P, dcp::Size (640, 480), Crop (1, 4, 6, 8), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_YUV420P, dcp::Size (640, 480), Crop (16, 16, 0, 0), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_YUV420P, dcp::Size (640, 480), Crop (16, 3, 3, 0), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_RGB24, dcp::Size (1000, 800), Crop (0, 0, 0, 0), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); + crop_scale_window_single (AV_PIX_FMT_RGB24, dcp::Size (1000, 800), Crop (55, 0, 1, 9), dcp::Size (1920, 1080), dcp::Size (1998, 1080)); } diff --git a/test/make_black_test.cc b/test/make_black_test.cc index 7c0f92142..88c1bd0f4 100644 --- a/test/make_black_test.cc +++ b/test/make_black_test.cc @@ -18,7 +18,7 @@ */ #include <boost/test/unit_test.hpp> -#include <libdcp/util.h> +#include <dcp/util.h> extern "C" { #include <libavutil/pixfmt.h> } @@ -32,8 +32,8 @@ using std::list; */ BOOST_AUTO_TEST_CASE (make_black_test) { - libdcp::Size in_size (512, 512); - libdcp::Size out_size (1024, 1024); + dcp::Size in_size (512, 512); + dcp::Size out_size (1024, 1024); list<AVPixelFormat> pix_fmts; pix_fmts.push_back (AV_PIX_FMT_RGB24); diff --git a/test/play_test.cc b/test/play_test.cc deleted file mode 100644 index 51e227256..000000000 --- a/test/play_test.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> - - This program 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, - 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. - -*/ - -#include <boost/test/unit_test.hpp> -#include "lib/player.h" -#include "lib/ratio.h" -#include "lib/dcp_content_type.h" -#include "test.h" - -/* This test needs stuff in Player that is only included in debug mode */ -#ifdef DCPOMATIC_DEBUG - -using std::cout; -using boost::optional; -using boost::shared_ptr; - -struct Video -{ - boost::shared_ptr<Content> content; - boost::shared_ptr<const Image> image; - Time time; -}; - -class PlayerWrapper -{ -public: - PlayerWrapper (shared_ptr<Player> p) - : _player (p) - { - _player->Video.connect (bind (&PlayerWrapper::process_video, this, _1, _2, _5)); - } - - void process_video (shared_ptr<PlayerImage> i, bool, Time t) - { - Video v; - v.content = _player->_last_video; - v.image = i->image (); - v.time = t; - _queue.push_front (v); - } - - optional<Video> get_video () - { - while (_queue.empty() && !_player->pass ()) {} - if (_queue.empty ()) { - return optional<Video> (); - } - - Video v = _queue.back (); - _queue.pop_back (); - return v; - } - - void seek (Time t, bool ac) - { - _player->seek (t, ac); - _queue.clear (); - } - -private: - shared_ptr<Player> _player; - std::list<Video> _queue; -}; - -BOOST_AUTO_TEST_CASE (play_test) -{ - shared_ptr<Film> film = new_test_film ("play_test"); - film->set_dcp_content_type (DCPContentType::from_dci_name ("FTR")); - film->set_container (Ratio::from_id ("185")); - film->set_name ("play_test"); - - shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/red_24.mp4")); - film->examine_and_add_content (A); - wait_for_jobs (); - - BOOST_CHECK_EQUAL (A->video_length_after_3d_combine(), 16); - - shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/red_30.mp4")); - film->examine_and_add_content (B); - wait_for_jobs (); - - BOOST_CHECK_EQUAL (B->video_length_after_3d_combine(), 16); - - /* Film should have been set to 25fps */ - BOOST_CHECK_EQUAL (film->video_frame_rate(), 25); - - BOOST_CHECK_EQUAL (A->position(), 0); - /* A is 16 frames long at 25 fps */ - BOOST_CHECK_EQUAL (B->position(), 16 * TIME_HZ / 25); - - shared_ptr<Player> player = film->make_player (); - PlayerWrapper wrap (player); - /* Seek and audio don't get on at the moment */ - player->disable_audio (); - - for (int i = 0; i < 32; ++i) { - optional<Video> v = wrap.get_video (); - BOOST_CHECK (v); - if (i < 16) { - BOOST_CHECK (v.get().content == A); - } else { - BOOST_CHECK (v.get().content == B); - } - } - - player->seek (10 * TIME_HZ / 25, true); - optional<Video> v = wrap.get_video (); - BOOST_CHECK (v); - BOOST_CHECK_EQUAL (v.get().time, 10 * TIME_HZ / 25); -} - -#endif diff --git a/test/ratio_test.cc b/test/ratio_test.cc index f3cbb504f..f3784cad2 100644 --- a/test/ratio_test.cc +++ b/test/ratio_test.cc @@ -19,7 +19,7 @@ #include <iostream> #include <boost/test/unit_test.hpp> -#include <libdcp/util.h> +#include <dcp/util.h> #include "lib/ratio.h" #include "lib/util.h" @@ -28,7 +28,7 @@ using std::ostream; namespace libdcp { ostream& -operator<< (ostream& s, libdcp::Size const & t) +operator<< (ostream& s, dcp::Size const & t) { s << t.width << "x" << t.height; return s; @@ -42,38 +42,38 @@ BOOST_AUTO_TEST_CASE (ratio_test) Ratio const * r = Ratio::from_id ("119"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1290, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1290, 1080)); r = Ratio::from_id ("133"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1440, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1440, 1080)); r = Ratio::from_id ("137"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1480, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1480, 1080)); r = Ratio::from_id ("138"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1485, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1485, 1080)); r = Ratio::from_id ("166"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1800, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1800, 1080)); r = Ratio::from_id ("178"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1920, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1920, 1080)); r = Ratio::from_id ("185"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (1998, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (1998, 1080)); r = Ratio::from_id ("239"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (2048, 858)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (2048, 858)); r = Ratio::from_id ("full-frame"); BOOST_CHECK (r); - BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), libdcp::Size (2048, 1080)), libdcp::Size (2048, 1080)); + BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (2048, 1080)); } diff --git a/test/recover_test.cc b/test/recover_test.cc index d8caf17fa..c4e4f155d 100644 --- a/test/recover_test.cc +++ b/test/recover_test.cc @@ -18,7 +18,7 @@ */ #include <boost/test/unit_test.hpp> -#include <libdcp/stereo_picture_asset.h> +#include <dcp/stereo_picture_mxf.h> #include "lib/film.h" #include "lib/dcp_content_type.h" #include "lib/image_content.h" @@ -30,7 +30,7 @@ using std::string; using boost::shared_ptr; static void -note (libdcp::NoteType, string n) +note (dcp::NoteType, string n) { cout << n << "\n"; } @@ -62,10 +62,10 @@ BOOST_AUTO_TEST_CASE (recover_test) film->make_dcp (); wait_for_jobs (); - shared_ptr<libdcp::StereoPictureAsset> A (new libdcp::StereoPictureAsset ("build/test/recover_test", "original.mxf")); - shared_ptr<libdcp::StereoPictureAsset> B (new libdcp::StereoPictureAsset ("build/test/recover_test/video", "185_2K_58a090f8d70a2b410c534120d35e5256_24_bicubic_200000000_P_S_3D.mxf")); + shared_ptr<dcp::StereoPictureMXF> A (new dcp::StereoPictureMXF ("build/test/recover_test/original.mxf")); + shared_ptr<dcp::StereoPictureMXF> B (new dcp::StereoPictureMXF ("build/test/recover_test/video/185_2K_58a090f8d70a2b410c534120d35e5256_24_bicubic_200000000_P_S_3D.mxf")); - libdcp::EqualityOptions eq; + dcp::EqualityOptions eq; eq.mxf_names_can_differ = true; BOOST_CHECK (A->equals (B, eq, boost::bind (¬e, _1, _2))); } diff --git a/test/repeat_frame_test.cc b/test/repeat_frame_test.cc new file mode 100644 index 000000000..6cedf9179 --- /dev/null +++ b/test/repeat_frame_test.cc @@ -0,0 +1,50 @@ +/* + Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +#include <boost/test/unit_test.hpp> +#include "test.h" +#include "lib/film.h" +#include "lib/ratio.h" +#include "lib/ffmpeg_content.h" +#include "lib/dcp_content_type.h" + +using boost::shared_ptr; + +/* Test the repeat of frames by the player when putting a 24fps + source into a 48fps DCP. +*/ +BOOST_AUTO_TEST_CASE (repeat_frame_test) +{ + shared_ptr<Film> film = new_test_film ("repeat_frame_test"); + film->set_name ("repeat_frame_test"); + film->set_container (Ratio::from_id ("185")); + film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/red_24.mp4")); + c->set_scale (VideoContentScale (Ratio::from_id ("185"))); + film->examine_and_add_content (c); + + wait_for_jobs (); + + film->set_video_frame_rate (48); + film->make_dcp (); + wait_for_jobs (); + + check_dcp ("test/data/repeat_frame_test", film->dir (film->dcp_name ())); +} + diff --git a/test/resampler_test.cc b/test/resampler_test.cc index 9247159a7..3be251b3a 100644 --- a/test/resampler_test.cc +++ b/test/resampler_test.cc @@ -34,13 +34,13 @@ resampler_test_one (int from, int to) /* 3 hours */ int64_t const N = int64_t (from) * 60 * 60 * 3; - + + /* XXX: no longer checks anything */ for (int64_t i = 0; i < N; i += 1000) { shared_ptr<AudioBuffers> a (new AudioBuffers (1, 1000)); a->make_silent (); - pair<shared_ptr<const AudioBuffers>, AudioContent::Frame> r = resamp.run (a, i); - BOOST_CHECK_EQUAL (r.second, total_out); - total_out += r.first->frames (); + shared_ptr<const AudioBuffers> r = resamp.run (a); + total_out += r->frames (); } } diff --git a/test/scaling_test.cc b/test/scaling_test.cc index f0cf3fe4a..bf8da8aac 100644 --- a/test/scaling_test.cc +++ b/test/scaling_test.cc @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (scaling_test) wait_for_jobs (); - imc->set_video_length (1); + imc->set_video_length (ContentTime::from_frames (1, 24)); scaling_test_for (film, imc, "133", "185"); scaling_test_for (film, imc, "185", "185"); diff --git a/test/seek_zero_test.cc b/test/seek_zero_test.cc new file mode 100644 index 000000000..150e12d90 --- /dev/null +++ b/test/seek_zero_test.cc @@ -0,0 +1,55 @@ +/* + Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +/** @file test/seek_zero_test.cc + * @brief Test seek to zero with a raw FFmpegDecoder (without the player + * confusing things as it might in ffmpeg_seek_test). + */ + +#include <boost/test/unit_test.hpp> +#include "lib/film.h" +#include "lib/ffmpeg_content.h" +#include "lib/ratio.h" +#include "lib/dcp_content_type.h" +#include "lib/ffmpeg_decoder.h" +#include "lib/content_video.h" +#include "test.h" + +using std::cout; +using boost::shared_ptr; +using boost::dynamic_pointer_cast; +using boost::optional; + +BOOST_AUTO_TEST_CASE (seek_zero_test) +{ + shared_ptr<Film> film = new_test_film ("seek_zero_test"); + film->set_name ("seek_zero_test"); + film->set_container (Ratio::from_id ("185")); + film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + shared_ptr<FFmpegContent> content (new FFmpegContent (film, "test/data/count300bd48.m2ts")); + content->set_scale (VideoContentScale (Ratio::from_id ("185"))); + film->examine_and_add_content (content); + wait_for_jobs (); + + FFmpegDecoder decoder (content, film->log()); + optional<ContentVideo> a = decoder.get_video (0, true); + optional<ContentVideo> b = decoder.get_video (0, true); + BOOST_CHECK_EQUAL (a->frame, 0); + BOOST_CHECK_EQUAL (b->frame, 0); +} diff --git a/test/silence_padding_test.cc b/test/silence_padding_test.cc index 82cbad080..e4472ad4f 100644 --- a/test/silence_padding_test.cc +++ b/test/silence_padding_test.cc @@ -18,11 +18,12 @@ */ #include <boost/test/unit_test.hpp> -#include <libdcp/cpl.h> -#include <libdcp/dcp.h> -#include <libdcp/sound_asset.h> -#include <libdcp/sound_frame.h> -#include <libdcp/reel.h> +#include <dcp/cpl.h> +#include <dcp/dcp.h> +#include <dcp/sound_mxf.h> +#include <dcp/sound_frame.h> +#include <dcp/reel.h> +#include <dcp/reel_sound_asset.h> #include "lib/sndfile_content.h" #include "lib/film.h" #include "lib/dcp_content_type.h" @@ -52,56 +53,56 @@ static void test_silence_padding (int channels) boost::filesystem::path path = "build/test"; path /= film_name; path /= film->dcp_name (); - libdcp::DCP check (path.string ()); + dcp::DCP check (path.string ()); check.read (); - shared_ptr<const libdcp::SoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); + shared_ptr<const dcp::ReelSoundAsset> sound_asset = check.cpls().front()->reels().front()->main_sound (); BOOST_CHECK (sound_asset); - BOOST_CHECK (sound_asset->channels () == channels); + BOOST_CHECK_EQUAL (sound_asset->mxf()->channels (), channels); /* Sample index in the DCP */ int n = 0; /* DCP sound asset frame */ int frame = 0; - while (n < sound_asset->intrinsic_duration()) { - shared_ptr<const libdcp::SoundFrame> sound_frame = sound_asset->get_frame (frame++); + while (n < sound_asset->mxf()->intrinsic_duration()) { + shared_ptr<const dcp::SoundFrame> sound_frame = sound_asset->mxf()->get_frame (frame++); uint8_t const * d = sound_frame->data (); - for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->channels())) { + for (int i = 0; i < sound_frame->size(); i += (3 * sound_asset->mxf()->channels())) { - if (sound_asset->channels() > 0) { + if (sound_asset->mxf()->channels() > 0) { /* L should be silent */ int const sample = d[i + 0] | (d[i + 1] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 1) { + if (sound_asset->mxf()->channels() > 1) { /* R should be silent */ int const sample = d[i + 2] | (d[i + 3] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 2) { + if (sound_asset->mxf()->channels() > 2) { /* Mono input so it will appear on centre */ int const sample = d[i + 7] | (d[i + 8] << 8); BOOST_CHECK_EQUAL (sample, n); } - if (sound_asset->channels() > 3) { + if (sound_asset->mxf()->channels() > 3) { /* Lfe should be silent */ int const sample = d[i + 9] | (d[i + 10] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 4) { + if (sound_asset->mxf()->channels() > 4) { /* Ls should be silent */ int const sample = d[i + 11] | (d[i + 12] << 8); BOOST_CHECK_EQUAL (sample, 0); } - if (sound_asset->channels() > 5) { + if (sound_asset->mxf()->channels() > 5) { /* Rs should be silent */ int const sample = d[i + 13] | (d[i + 14] << 8); BOOST_CHECK_EQUAL (sample, 0); diff --git a/test/skip_frame_test.cc b/test/skip_frame_test.cc new file mode 100644 index 000000000..61176a7c6 --- /dev/null +++ b/test/skip_frame_test.cc @@ -0,0 +1,51 @@ +/* + Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +#include <boost/test/unit_test.hpp> +#include "test.h" +#include "lib/film.h" +#include "lib/ratio.h" +#include "lib/ffmpeg_content.h" +#include "lib/dcp_content_type.h" + +using boost::shared_ptr; + +/* Test the skip of frames by the player when putting a 48fps + source into a 24fps DCP. +*/ +BOOST_AUTO_TEST_CASE (skip_frame_test) +{ + shared_ptr<Film> film = new_test_film ("skip_frame_test"); + film->set_name ("skip_frame_test"); + film->set_container (Ratio::from_id ("185")); + film->set_dcp_content_type (DCPContentType::from_pretty_name ("Test")); + shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/count300bd48.m2ts")); + c->set_scale (VideoContentScale (Ratio::from_id ("185"))); + film->examine_and_add_content (c); + + wait_for_jobs (); + film->write_metadata (); + + film->set_video_frame_rate (24); + film->make_dcp (); + wait_for_jobs (); + + check_dcp ("test/data/skip_frame_test", film->dir (film->dcp_name ())); +} + diff --git a/test/stream_test.cc b/test/stream_test.cc index fed3ecabe..1cd7e4a42 100644 --- a/test/stream_test.cc +++ b/test/stream_test.cc @@ -73,11 +73,11 @@ BOOST_AUTO_TEST_CASE (stream_test) BOOST_CHECK_EQUAL (a.name, "hello there world"); BOOST_CHECK_EQUAL (a.mapping.content_channels(), 2); - BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::LEFT), 1); - BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::RIGHT), 0); - BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::CENTRE), 1); - BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::LEFT), 0); - BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::RIGHT), 1); - BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::CENTRE), 1); + BOOST_CHECK_EQUAL (a.mapping.get (0, dcp::LEFT), 1); + BOOST_CHECK_EQUAL (a.mapping.get (0, dcp::RIGHT), 0); + BOOST_CHECK_EQUAL (a.mapping.get (0, dcp::CENTRE), 1); + BOOST_CHECK_EQUAL (a.mapping.get (1, dcp::LEFT), 0); + BOOST_CHECK_EQUAL (a.mapping.get (1, dcp::RIGHT), 1); + BOOST_CHECK_EQUAL (a.mapping.get (1, dcp::CENTRE), 1); } diff --git a/test/subrip_test.cc b/test/subrip_test.cc new file mode 100644 index 000000000..f38ffb59b --- /dev/null +++ b/test/subrip_test.cc @@ -0,0 +1,195 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program 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, + 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. + +*/ + +#include <boost/test/unit_test.hpp> +#include <dcp/subtitle_content.h> +#include "lib/subrip.h" +#include "lib/subrip_content.h" +#include "lib/subrip_decoder.h" +#include "lib/render_subtitles.h" +#include "test.h" + +using std::list; +using std::vector; +using std::string; +using boost::shared_ptr; +using boost::dynamic_pointer_cast; + +/** Test SubRip::convert_time */ +BOOST_AUTO_TEST_CASE (subrip_time_test) +{ + BOOST_CHECK_EQUAL (SubRip::convert_time ("00:03:10,500"), ContentTime::from_seconds ((3 * 60) + 10 + 0.5)); + BOOST_CHECK_EQUAL (SubRip::convert_time ("04:19:51,782"), ContentTime::from_seconds ((4 * 3600) + (19 * 60) + 51 + 0.782)); +} + +/** Test SubRip::convert_coordinate */ +BOOST_AUTO_TEST_CASE (subrip_coordinate_test) +{ + BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("foo:42"), 42); + BOOST_CHECK_EQUAL (SubRip::convert_coordinate ("X1:999"), 999); +} + +/** Test SubRip::convert_content */ +BOOST_AUTO_TEST_CASE (subrip_content_test) +{ + list<string> c; + list<SubRipSubtitlePiece> p; + + c.push_back ("Hello world"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + c.clear (); + + c.push_back ("<b>Hello world</b>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().bold, true); + c.clear (); + + c.push_back ("<i>Hello world</i>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().italic, true); + c.clear (); + + c.push_back ("<u>Hello world</u>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().underline, true); + c.clear (); + + c.push_back ("{b}Hello world{/b}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().bold, true); + c.clear (); + + c.push_back ("{i}Hello world{/i}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().italic, true); + c.clear (); + + c.push_back ("{u}Hello world{/u}"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 1); + BOOST_CHECK_EQUAL (p.front().text, "Hello world"); + BOOST_CHECK_EQUAL (p.front().underline, true); + c.clear (); + + c.push_back ("<b>This is <i>nesting</i> of subtitles</b>"); + p = SubRip::convert_content (c); + BOOST_CHECK_EQUAL (p.size(), 3); + list<SubRipSubtitlePiece>::iterator i = p.begin (); + BOOST_CHECK_EQUAL (i->text, "This is "); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, false); + ++i; + BOOST_CHECK_EQUAL (i->text, "nesting"); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, true); + ++i; + BOOST_CHECK_EQUAL (i->text, " of subtitles"); + BOOST_CHECK_EQUAL (i->bold, true); + BOOST_CHECK_EQUAL (i->italic, false); + ++i; + c.clear (); +} + +/** Test parsing of full SubRip file content */ +BOOST_AUTO_TEST_CASE (subrip_parse_test) +{ + shared_ptr<SubRipContent> content (new SubRipContent (shared_ptr<Film> (), "test/data/subrip.srt")); + content->examine (shared_ptr<Job> ()); + BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471)); + + SubRip s (content); + + vector<SubRipSubtitle>::const_iterator i = s._subtitles.begin(); + + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->from, ContentTime::from_seconds ((1 * 60) + 49.200)); + BOOST_CHECK_EQUAL (i->to, ContentTime::from_seconds ((1 * 60) + 52.351)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "This is a subtitle, and it goes over two lines."); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->from, ContentTime::from_seconds ((1 * 60) + 52.440)); + BOOST_CHECK_EQUAL (i->to, ContentTime::from_seconds ((1 * 60) + 54.351)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "We have emboldened this"); + BOOST_CHECK_EQUAL (i->pieces.front().bold, true); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->from, ContentTime::from_seconds ((1 * 60) + 54.440)); + BOOST_CHECK_EQUAL (i->to, ContentTime::from_seconds ((1 * 60) + 56.590)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "And italicised this."); + BOOST_CHECK_EQUAL (i->pieces.front().italic, true); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->from, ContentTime::from_seconds ((1 * 60) + 56.680)); + BOOST_CHECK_EQUAL (i->to, ContentTime::from_seconds ((1 * 60) + 58.955)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "Shall I compare thee to a summers' day?"); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->from, ContentTime::from_seconds ((2 * 60) + 0.840)); + BOOST_CHECK_EQUAL (i->to, ContentTime::from_seconds ((2 * 60) + 3.400)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "Is this a dagger I see before me?"); + + ++i; + BOOST_CHECK (i != s._subtitles.end ()); + BOOST_CHECK_EQUAL (i->from, ContentTime::from_seconds ((3 * 60) + 54.560)); + BOOST_CHECK_EQUAL (i->to, ContentTime::from_seconds ((3 * 60) + 56.471)); + BOOST_CHECK_EQUAL (i->pieces.size(), 1); + BOOST_CHECK_EQUAL (i->pieces.front().text, "Hello world."); + + ++i; + BOOST_CHECK (i == s._subtitles.end ()); +} + +/** Test rendering of a SubRip subtitle */ +BOOST_AUTO_TEST_CASE (subrip_render_test) +{ + shared_ptr<SubRipContent> content (new SubRipContent (shared_ptr<Film> (), "test/data/subrip.srt")); + content->examine (shared_ptr<Job> ()); + BOOST_CHECK_EQUAL (content->full_length(), DCPTime::from_seconds ((3 * 60) + 56.471)); + + shared_ptr<Film> film = new_test_film ("subrip_render_test"); + + shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (content)); + list<shared_ptr<ContentTextSubtitle> > cts = decoder->get_text_subtitles (ContentTime::from_seconds (109), ContentTime::from_seconds (110)); + BOOST_CHECK_EQUAL (cts.size(), 1); + + PositionImage image = render_subtitles (cts.front()->subs, dcp::Size (1998, 1080)); + write_image (image.image, "build/test/subrip_render_test.png"); + check_file ("build/test/subrip_render_test.png", "test/data/subrip_render_test.png"); +} diff --git a/test/test.cc b/test/test.cc index be2cf1538..f393e80c3 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,8 +19,9 @@ #include <vector> #include <list> +#include <Magick++.h> #include <libxml++/libxml++.h> -#include <libdcp/dcp.h> +#include <dcp/dcp.h> #include "lib/config.h" #include "lib/util.h" #include "lib/ui_signaller.h" @@ -29,6 +30,7 @@ #include "lib/job.h" #include "lib/cross.h" #include "lib/server_finder.h" +#include "lib/image.h" #define BOOST_TEST_DYN_LINK #define BOOST_TEST_MODULE dcpomatic_test #include <boost/test/unit_test.hpp> @@ -41,6 +43,8 @@ using std::cerr; using std::list; using boost::shared_ptr; +boost::filesystem::path private_data = boost::filesystem::path ("test") / boost::filesystem::path ("private"); + class TestUISignaller : public UISignaller { public: @@ -53,15 +57,16 @@ public: struct TestConfig { - TestConfig() + TestConfig () { - dcpomatic_setup(); + dcpomatic_setup (); Config::instance()->set_num_local_encoding_threads (1); Config::instance()->set_server_port_base (61920); Config::instance()->set_default_dci_metadata (DCIMetadata ()); Config::instance()->set_default_container (static_cast<Ratio*> (0)); Config::instance()->set_default_dcp_content_type (static_cast<DCPContentType*> (0)); + Config::instance()->set_default_audio_delay (0); ServerFinder::instance()->disable (); @@ -98,8 +103,8 @@ void check_file (boost::filesystem::path ref, boost::filesystem::path check) { uintmax_t N = boost::filesystem::file_size (ref); - BOOST_CHECK_EQUAL (N, boost::filesystem::file_size(check)); - FILE* ref_file = fopen_boost (ref, "rb"); + BOOST_CHECK_EQUAL (N, boost::filesystem::file_size (check)); + FILE* ref_file = fopen (ref.c_str(), "rb"); BOOST_CHECK (ref_file); FILE* check_file = fopen_boost (check, "rb"); BOOST_CHECK (check_file); @@ -127,26 +132,26 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check) } static void -note (libdcp::NoteType t, string n) +note (dcp::NoteType t, string n) { - if (t == libdcp::ERROR) { + if (t == dcp::ERROR) { cerr << n << "\n"; } } void -check_dcp (string ref, string check) +check_dcp (boost::filesystem::path ref, boost::filesystem::path check) { - libdcp::DCP ref_dcp (ref); + dcp::DCP ref_dcp (ref); ref_dcp.read (); - libdcp::DCP check_dcp (check); + dcp::DCP check_dcp (check); check_dcp.read (); - libdcp::EqualityOptions options; + dcp::EqualityOptions options; options.max_mean_pixel_error = 5; options.max_std_dev_pixel_error = 5; options.max_audio_sample_error = 255; - options.cpl_names_can_differ = true; + options.cpl_annotation_texts_can_differ = true; options.mxf_names_can_differ = true; BOOST_CHECK (ref_dcp.equals (check_dcp, options, boost::bind (note, _1, _2))); @@ -230,3 +235,12 @@ wait_for_jobs () ui_signaller->ui_idle (); } + +void +write_image (shared_ptr<const Image> image, boost::filesystem::path file) +{ + using namespace MagickCore; + + Magick::Image m (image->size().width, image->size().height, "ARGB", CharPixel, (void *) image->data()[0]); + m.write (file.string ()); +} diff --git a/test/test.h b/test/test.h index dd007e8c9..57ea32c57 100644 --- a/test/test.h +++ b/test/test.h @@ -20,10 +20,15 @@ #include <boost/filesystem.hpp> class Film; +class Image; + +extern boost::filesystem::path private_data; extern void wait_for_jobs (); extern boost::shared_ptr<Film> new_test_film (std::string); -extern void check_dcp (std::string, std::string); +extern void check_dcp (boost::filesystem::path, boost::filesystem::path); +extern void check_file (boost::filesystem::path ref, boost::filesystem::path check); extern void check_xml (boost::filesystem::path, boost::filesystem::path, std::list<std::string>); extern void check_file (boost::filesystem::path, boost::filesystem::path); extern boost::filesystem::path test_film_dir (std::string); +extern void write_image (boost::shared_ptr<const Image> image, boost::filesystem::path file); diff --git a/test/util_test.cc b/test/util_test.cc index 750023d9f..b2085afe1 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -54,6 +54,24 @@ BOOST_AUTO_TEST_CASE (md5_digest_test) BOOST_CHECK_THROW (md5_digest (p, shared_ptr<Job> ()), std::runtime_error); } +/* Straightforward test of DCPTime::round_up */ +BOOST_AUTO_TEST_CASE (dcptime_round_up_test) +{ + BOOST_CHECK_EQUAL (DCPTime (0).round_up (DCPTime::HZ / 2), DCPTime (0)); + BOOST_CHECK_EQUAL (DCPTime (1).round_up (DCPTime::HZ / 2), DCPTime (2)); + BOOST_CHECK_EQUAL (DCPTime (2).round_up (DCPTime::HZ / 2), DCPTime (2)); + BOOST_CHECK_EQUAL (DCPTime (3).round_up (DCPTime::HZ / 2), DCPTime (4)); + + BOOST_CHECK_EQUAL (DCPTime (0).round_up (DCPTime::HZ / 42), DCPTime (0)); + BOOST_CHECK_EQUAL (DCPTime (1).round_up (DCPTime::HZ / 42), DCPTime (42)); + BOOST_CHECK_EQUAL (DCPTime (42).round_up (DCPTime::HZ / 42), DCPTime (42)); + BOOST_CHECK_EQUAL (DCPTime (43).round_up (DCPTime::HZ / 42), DCPTime (84)); + + /* Check that rounding up to non-integer frame rates works */ + BOOST_CHECK_EQUAL (DCPTime (45312).round_up (29.976), DCPTime (48045)); +} + + BOOST_AUTO_TEST_CASE (divide_with_round_test) { BOOST_CHECK_EQUAL (divide_with_round (0, 4), 0); diff --git a/test/wscript b/test/wscript index 676f47104..2fbe74150 100644 --- a/test/wscript +++ b/test/wscript @@ -10,7 +10,7 @@ def configure(conf): """, msg = 'Checking for boost unit testing library', lib = 'boost_unit_test_framework%s' % boost_test_suffix, uselib_store = 'BOOST_TEST') def build(bld): - obj = bld(features = 'cxx cxxprogram') + obj = bld(features='cxx cxxprogram') obj.name = 'unit-tests' obj.uselib = 'BOOST_TEST BOOST_THREAD DCP OPENJPEG AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML' obj.use = 'libdcpomatic' @@ -19,12 +19,13 @@ def build(bld): audio_analysis_test.cc audio_delay_test.cc audio_mapping_test.cc - audio_merger_test.cc black_fill_test.cc client_server_test.cc colour_conversion_test.cc ffmpeg_audio_test.cc ffmpeg_dcp_test.cc + ffmpeg_decoder_seek_test.cc + ffmpeg_decoder_sequential_test.cc ffmpeg_examiner_test.cc ffmpeg_pts_offset.cc file_group_test.cc @@ -34,13 +35,16 @@ def build(bld): job_test.cc make_black_test.cc pixel_formats_test.cc - play_test.cc ratio_test.cc + repeat_frame_test.cc recover_test.cc resampler_test.cc scaling_test.cc + seek_zero_test.cc silence_padding_test.cc + skip_frame_test.cc stream_test.cc + subrip_test.cc test.cc threed_test.cc util_test.cc @@ -48,3 +52,14 @@ def build(bld): obj.target = 'unit-tests' obj.install_path = '' + + obj = bld(features='cxx cxxprogram') + obj.name = 'long-unit-tests' + obj.uselib = 'BOOST_TEST DCP OPENJPEG AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML' + obj.use = 'libdcpomatic' + obj.source = """ + test.cc + """ + + obj.target = 'long-unit-tests' + obj.install_path = '' |
