X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=test%2Ftorture_test.cc;h=764491c0a63ea5d31af368d41411b660b8f56934;hb=a5051181d4f6fe8d30aea66f5c14c2fab9337df0;hp=21494e5d80a7dbd5fe40bbb96fdac81398100b79;hpb=080051edd655be1a8aa4b8dc21d0c262282d8444;p=dcpomatic.git diff --git a/test/torture_test.cc b/test/torture_test.cc index 21494e5d8..764491c0a 100644 --- a/test/torture_test.cc +++ b/test/torture_test.cc @@ -19,7 +19,8 @@ */ /** @file test/torture_test.cc - * @brief Entire projects that are programmatically created and checked. + * @brief Tricky arrangements of content whose resulting DCPs are checked programmatically. + * @ingroup completedcp */ #include "lib/audio_content.h" @@ -27,49 +28,65 @@ #include "lib/dcp_content_type.h" #include "lib/ratio.h" #include "lib/content_factory.h" +#include "lib/video_content.h" #include "test.h" #include #include #include +#include #include +#include +#include +#include #include +#include using std::list; +using std::cout; using boost::shared_ptr; +using boost::dynamic_pointer_cast; +using namespace dcpomatic; -/** Test a fairly complex arrangement of content */ +/** Test start/end trim and positioning of some audio content */ BOOST_AUTO_TEST_CASE (torture_test1) { - shared_ptr film = new_test_film ("torture_test"); + shared_ptr film = new_test_film ("torture_test1"); film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR")); - film->set_name ("torture_test"); + film->set_name ("torture_test1"); film->set_container (Ratio::from_id ("185")); film->set_sequence (false); - /* Staircase at an offset of 2000 samples, trimmed both start and end, with a gain of 6dB */ - shared_ptr staircase = content_factory(film, "test/data/staircase.wav").front (); + /* Staircase at an offset of 2000 samples, trimmed both start and end, with a gain of exactly 2 (linear) */ + shared_ptr staircase = content_factory("test/data/staircase.wav").front (); film->examine_and_add_content (staircase); - wait_for_jobs (); - staircase->set_position (DCPTime::from_frames (2000, film->audio_frame_rate())); + BOOST_REQUIRE (!wait_for_jobs()); + staircase->set_position (film, DCPTime::from_frames (2000, film->audio_frame_rate())); staircase->set_trim_start (ContentTime::from_frames (12, 48000)); staircase->set_trim_end (ContentTime::from_frames (35, 48000)); staircase->audio->set_gain (20 * log10(2)); - /* And again at an offset of 50000 samples, trimmed both start and end, with a gain of 6dB */ - staircase = content_factory(film, "test/data/staircase.wav").front (); + /* And again at an offset of 50000 samples, trimmed both start and end, with a gain of exactly 2 (linear) */ + staircase = content_factory("test/data/staircase.wav").front (); film->examine_and_add_content (staircase); - wait_for_jobs (); - staircase->set_position (DCPTime::from_frames (50000, film->audio_frame_rate())); + BOOST_REQUIRE (!wait_for_jobs()); + staircase->set_position (film, DCPTime::from_frames(50000, film->audio_frame_rate())); staircase->set_trim_start (ContentTime::from_frames (12, 48000)); staircase->set_trim_end (ContentTime::from_frames (35, 48000)); staircase->audio->set_gain (20 * log10(2)); + /* 1s of red at 5s in */ + shared_ptr red = content_factory("test/data/flat_red.png").front (); + film->examine_and_add_content (red); + BOOST_REQUIRE (!wait_for_jobs()); + red->set_position (film, DCPTime::from_seconds(5)); + red->video->set_length (24); + film->set_video_frame_rate (24); film->write_metadata (); film->make_dcp (); - wait_for_jobs (); + BOOST_REQUIRE (!wait_for_jobs()); - dcp::DCP dcp ("build/test/torture_test/" + film->dcp_name(false)); + dcp::DCP dcp ("build/test/torture_test1/" + film->dcp_name(false)); dcp.read (); list > cpls = dcp.cpls (); @@ -77,10 +94,13 @@ BOOST_AUTO_TEST_CASE (torture_test1) list > reels = cpls.front()->reels (); BOOST_REQUIRE_EQUAL (reels.size(), 1); + /* Check sound */ + shared_ptr reel_sound = reels.front()->main_sound(); BOOST_REQUIRE (reel_sound); shared_ptr sound = reel_sound->asset(); BOOST_REQUIRE (sound); + BOOST_CHECK_EQUAL (sound->intrinsic_duration(), 144); shared_ptr sound_reader = sound->start_read (); @@ -146,6 +166,7 @@ BOOST_AUTO_TEST_CASE (torture_test1) } /* Then the same thing again */ + stair = 12; fr = sound_reader->get_frame (25); @@ -183,4 +204,86 @@ BOOST_AUTO_TEST_CASE (torture_test1) } } } + + /* Then some silence */ + + for (int i = 28; i < 144; ++i) { + fr = sound_reader->get_frame (i); + for (int j = 0; j < fr->samples(); ++j) { + for (int k = 0; k < 6; ++k) { + BOOST_CHECK_EQUAL (fr->get(k, j), 0); + } + } + } + + /* Check picture */ + + shared_ptr reel_picture = reels.front()->main_picture(); + BOOST_REQUIRE (reel_picture); + shared_ptr picture = dynamic_pointer_cast (reel_picture->asset()); + BOOST_REQUIRE (picture); + BOOST_CHECK_EQUAL (picture->intrinsic_duration(), 144); + + shared_ptr picture_reader = picture->start_read (); + + /* First 5 * 24 = 120 frames should be black */ + + shared_ptr ref; + for (int i = 0; i < 120; ++i) { + shared_ptr fr = picture_reader->get_frame (i); + shared_ptr image = fr->xyz_image (); + dcp::Size const size = image->size (); + if (i == 0) { + for (int c = 0; c < 3; ++c) { + for (int y = 0; y < size.height; ++y) { + for (int x = 0; x < size.width; ++x) { + BOOST_REQUIRE_EQUAL (image->data(c)[y * size.height + x], 0); + } + } + } + ref = image; + } else { + for (int c = 0; c < 3; ++c) { + BOOST_REQUIRE_MESSAGE ( + memcmp (image->data(c), ref->data(c), size.width * size.height * sizeof(int)) == 0, + "failed on frame " << i << " component " << c + ); + } + } + } + + /* Then 24 red */ + + for (int i = 120; i < 144; ++i) { + shared_ptr fr = picture_reader->get_frame (i); + shared_ptr image = fr->xyz_image (); + dcp::Size const size = image->size (); + if (i == 120) { + for (int y = 0; y < size.height; ++y) { + for (int x = 0; x < size.width; ++x) { + BOOST_REQUIRE_MESSAGE ( + abs(image->data(0)[y * size.height + x] - 2808) <= 2, + "failed on frame " << i << " with image data " << image->data(0)[y * size.height + x] + ); + BOOST_REQUIRE_MESSAGE ( + abs(image->data(1)[y * size.height + x] - 2176) <= 2, + "failed on frame " << i << " with image data " << image->data(1)[y * size.height + x] + ); + BOOST_REQUIRE_MESSAGE ( + abs(image->data(2)[y * size.height + x] - 865) <= 2, + "failed on frame " << i << " with image data " << image->data(2)[y * size.height + x] + ); + } + } + ref = image; + } else { + for (int c = 0; c < 3; ++c) { + BOOST_REQUIRE_MESSAGE ( + memcmp (image->data(c), ref->data(c), size.width * size.height * sizeof(int)) == 0, + "failed on frame " << i << " component " << c + ); + } + } + } + }