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>
47 using std::make_shared;
48 using std::shared_ptr;
51 /* Check that DCPDecoder reuses old data when it should */
52 BOOST_AUTO_TEST_CASE (check_reuse_old_data_test)
56 auto ov = new_test_film2 ("check_reuse_old_data_ov", content_factory("test/data/flat_red.png"));
57 make_and_verify_dcp (ov);
59 auto ov_content = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
60 auto vf = new_test_film2 ("check_reuse_old_data_vf", {ov_content, content_factory("test/data/L.wav")[0]});
61 ov_content->set_reference_video (true);
62 make_and_verify_dcp (vf, {dcp::VerificationNote::Code::EXTERNAL_ASSET});
64 auto encrypted = new_test_film2 ("check_reuse_old_data_decrypted");
65 encrypted->examine_and_add_content (content_factory("test/data/flat_red.png")[0]);
66 BOOST_REQUIRE (!wait_for_jobs());
67 encrypted->set_encrypted (true);
68 make_and_verify_dcp (encrypted);
70 dcp::DCP encrypted_dcp (encrypted->dir(encrypted->dcp_name()));
71 encrypted_dcp.read ();
73 auto kdm = encrypted->make_kdm (
74 Config::instance()->decryption_chain()->leaf(),
76 encrypted_dcp.cpls().front()->file().get(),
77 dcp::LocalTime ("2030-07-21T00:00:00+00:00"),
78 dcp::LocalTime ("2031-07-21T00:00:00+00:00"),
79 dcp::Formulation::MODIFIED_TRANSITIONAL_1,
84 /* Add just the OV to a new project, move it around a bit and check that
85 the _reels get reused.
87 auto test = new_test_film2 ("check_reuse_old_data_test1");
88 ov_content = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
89 test->examine_and_add_content (ov_content);
90 BOOST_REQUIRE (!wait_for_jobs());
91 auto player = make_shared<Player>(test, Image::Alignment::COMPACT);
93 auto decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
94 BOOST_REQUIRE (decoder);
95 auto reels = decoder->reels();
97 ov_content->set_position (test, dcpomatic::DCPTime(96000));
98 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
99 BOOST_REQUIRE (decoder);
100 BOOST_REQUIRE (reels == decoder->reels());
102 /* Add the VF to a new project, then add the OV and check that the
103 _reels did not get reused.
105 test = new_test_film2 ("check_reuse_old_data_test2");
106 auto vf_content = make_shared<DCPContent>(vf->dir(vf->dcp_name(false)));
107 test->examine_and_add_content (vf_content);
108 BOOST_REQUIRE (!wait_for_jobs());
109 player = make_shared<Player>(test, Image::Alignment::COMPACT);
111 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
112 BOOST_REQUIRE (decoder);
113 reels = decoder->reels();
115 vf_content->add_ov (ov->dir(ov->dcp_name(false)));
116 JobManager::instance()->add (make_shared<ExamineContentJob>(test, vf_content));
117 BOOST_REQUIRE (!wait_for_jobs());
118 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
119 BOOST_REQUIRE (decoder);
120 BOOST_REQUIRE (reels != decoder->reels());
122 /* Add a KDM to an encrypted DCP and check that the _reels did not get reused */
123 test = new_test_film2 ("check_reuse_old_data_test3");
124 auto encrypted_content = make_shared<DCPContent>(encrypted->dir(encrypted->dcp_name(false)));
125 test->examine_and_add_content (encrypted_content);
126 BOOST_REQUIRE (!wait_for_jobs());
127 player = make_shared<Player>(test, Image::Alignment::COMPACT);
129 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
130 BOOST_REQUIRE (decoder);
131 reels = decoder->reels();
133 encrypted_content->add_kdm (kdm);
134 JobManager::instance()->add (make_shared<ExamineContentJob>(test, encrypted_content));
135 BOOST_REQUIRE (!wait_for_jobs());
136 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
137 BOOST_REQUIRE (decoder);
138 BOOST_REQUIRE (reels != decoder->reels());