2 Copyright (C) 2019-2021 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/>.
22 /** @file test/dcp_decoder_test.cc
23 * @brief Test DCPDecoder class.
24 * @ingroup selfcontained
28 #include "lib/config.h"
29 #include "lib/content_factory.h"
30 #include "lib/dcp_content.h"
31 #include "lib/dcp_decoder.h"
32 #include "lib/examine_content_job.h"
34 #include "lib/job_manager.h"
35 #include "lib/piece.h"
36 #include "lib/player.h"
40 #include <boost/test/unit_test.hpp>
44 using std::make_shared;
45 using std::shared_ptr;
50 /* Check that DCPDecoder reuses old data when it should */
51 BOOST_AUTO_TEST_CASE (check_reuse_old_data_test)
55 auto ov = new_test_film2 ("check_reuse_old_data_ov", {content_factory("test/data/flat_red.png").front()});
56 make_and_verify_dcp (ov);
58 auto ov_content = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
59 auto vf = new_test_film2 ("check_reuse_old_data_vf", {ov_content, content_factory("test/data/L.wav").front()});
60 ov_content->set_reference_video (true);
61 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
63 auto encrypted = new_test_film2 ("check_reuse_old_data_decrypted");
64 encrypted->examine_and_add_content (content_factory("test/data/flat_red.png").front());
65 BOOST_REQUIRE (!wait_for_jobs());
66 encrypted->set_encrypted (true);
67 make_and_verify_dcp (encrypted);
69 dcp::DCP encrypted_dcp (encrypted->dir(encrypted->dcp_name()));
70 encrypted_dcp.read ();
72 auto kdm = encrypted->make_kdm (
73 Config::instance()->decryption_chain()->leaf(),
75 encrypted_dcp.cpls().front()->file().get(),
76 dcp::LocalTime ("2030-07-21T00:00:00+00:00"),
77 dcp::LocalTime ("2031-07-21T00:00:00+00:00"),
78 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
83 /* Add just the OV to a new project, move it around a bit and check that
84 the _reels get reused.
86 auto test = new_test_film2 ("check_reuse_old_data_test1");
87 ov_content = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
88 test->examine_and_add_content (ov_content);
89 BOOST_REQUIRE (!wait_for_jobs());
90 auto player = make_shared<Player>(test, Image::Alignment::COMPACT);
92 auto decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
93 BOOST_REQUIRE (decoder);
94 auto reels = decoder->reels();
96 ov_content->set_position (test, dcpomatic::DCPTime(96000));
97 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
98 BOOST_REQUIRE (decoder);
99 BOOST_REQUIRE (reels == decoder->reels());
101 /* Add the VF to a new project, then add the OV and check that the
102 _reels did not get reused.
104 test = new_test_film2 ("check_reuse_old_data_test2");
105 auto vf_content = make_shared<DCPContent>(vf->dir(vf->dcp_name(false)));
106 test->examine_and_add_content (vf_content);
107 BOOST_REQUIRE (!wait_for_jobs());
108 player = make_shared<Player>(test, Image::Alignment::COMPACT);
110 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
111 BOOST_REQUIRE (decoder);
112 reels = decoder->reels();
114 vf_content->add_ov (ov->dir(ov->dcp_name(false)));
115 JobManager::instance()->add (make_shared<ExamineContentJob>(test, vf_content));
116 BOOST_REQUIRE (!wait_for_jobs());
117 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
118 BOOST_REQUIRE (decoder);
119 BOOST_REQUIRE (reels != decoder->reels());
121 /* Add a KDM to an encrypted DCP and check that the _reels did not get reused */
122 test = new_test_film2 ("check_reuse_old_data_test3");
123 auto encrypted_content = make_shared<DCPContent>(encrypted->dir(encrypted->dcp_name(false)));
124 test->examine_and_add_content (encrypted_content);
125 BOOST_REQUIRE (!wait_for_jobs());
126 player = make_shared<Player>(test, Image::Alignment::COMPACT);
128 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
129 BOOST_REQUIRE (decoder);
130 reels = decoder->reels();
132 encrypted_content->add_kdm (kdm);
133 JobManager::instance()->add (make_shared<ExamineContentJob>(test, encrypted_content));
134 BOOST_REQUIRE (!wait_for_jobs());
135 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
136 BOOST_REQUIRE (decoder);
137 BOOST_REQUIRE (reels != decoder->reels());