2 Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 /** @file test/torture_test.cc
22 * @brief Entire projects that are programmatically created and checked.
25 #include "lib/audio_content.h"
27 #include "lib/dcp_content_type.h"
28 #include "lib/ratio.h"
29 #include "lib/content_factory.h"
33 #include <dcp/reel_sound_asset.h>
34 #include <dcp/sound_asset.h>
35 #include <boost/test/unit_test.hpp>
38 using boost::shared_ptr;
40 /** Test a fairly complex arrangement of content */
41 BOOST_AUTO_TEST_CASE (torture_test1)
43 shared_ptr<Film> film = new_test_film ("player_torture_test");
44 film->set_dcp_content_type (DCPContentType::from_isdcf_name ("FTR"));
45 film->set_name ("player_torture_test");
46 film->set_container (Ratio::from_id ("185"));
47 film->set_sequence (false);
49 /* Staircase at an offset of 2000 samples, trimmed both start and end, with a gain of 6dB */
50 shared_ptr<Content> staircase = content_factory(film, "test/data/staircase.mov").front ();
51 film->examine_and_add_content (staircase);
53 staircase->set_position (DCPTime::from_frames (2000, film->audio_frame_rate()));
54 staircase->set_trim_start (ContentTime::from_frames (12, 48000));
55 staircase->set_trim_end (ContentTime::from_frames (35, 48000));
56 // staircase->audio->set_gain (20 * log10(2));
58 film->set_video_frame_rate (24);
62 dcp::DCP dcp ("build/test/player_torture_test/" + film->dcp_name(false));
65 list<shared_ptr<dcp::CPL> > cpls = dcp.cpls ();
66 BOOST_REQUIRE_EQUAL (cpls.size(), 1);
67 list<shared_ptr<dcp::Reel> > reels = cpls.front()->reels ();
68 BOOST_REQUIRE_EQUAL (reels.size(), 1);
70 shared_ptr<dcp::ReelSoundAsset> reel_sound = reels.front()->main_sound();
71 BOOST_REQUIRE (reel_sound);
72 shared_ptr<dcp::SoundAsset> sound = reel_sound->asset();
73 BOOST_REQUIRE (sound);
75 shared_ptr<dcp::SoundAssetReader> sound_reader = sound->start_read ();
77 /* First frame silent */
78 shared_ptr<const dcp::SoundFrame> fr = sound_reader->get_frame (0);
79 for (int i = 0; i < fr->samples(); ++i) {
80 for (int j = 0; j < 6; ++j) {
81 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
85 /* The staircase is 4800 - 12 - 35 = 4753 samples. One frame is 2000 samples, so we span 3 frames */
87 BOOST_REQUIRE_EQUAL (fr->samples(), 2000);
91 fr = sound_reader->get_frame (1);
92 for (int i = 0; i < fr->samples(); ++i) {
93 for (int j = 0; j < 6; ++j) {
95 BOOST_CHECK_EQUAL (fr->get(j, i) >> 8, stair);
98 BOOST_CHECK_EQUAL ((fr->get(j, i) + 128) >> 8, 0);
103 fr = sound_reader->get_frame (2);
104 for (int i = 0; i < fr->samples(); ++i) {
105 for (int j = 0; j < 6; ++j) {
107 BOOST_CHECK_EQUAL (fr->get(j, i) >> 8, stair);
110 BOOST_CHECK_EQUAL (fr->get(j, i), 0);
115 fr = sound_reader->get_frame (3);
116 for (int i = 0; i < 4753 - (2000 * 2); ++i) {
117 for (int j = 0; j < 6; ++j) {
119 BOOST_CHECK_EQUAL (fr->get(j, i) >> 8, stair);
122 BOOST_CHECK_EQUAL (fr->get(j, i), 0);