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>
45 using std::make_shared;
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"));
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")[0]});
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")[0]);
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 signer = Config::instance()->signer_chain();
73 BOOST_REQUIRE(signer->valid());
75 auto const decrypted_kdm = encrypted->make_kdm(encrypted_dcp.cpls().front()->file().get(), dcp::LocalTime ("2030-07-21T00:00:00+00:00"), dcp::LocalTime ("2031-07-21T00:00:00+00:00"));
76 auto const kdm = decrypted_kdm.encrypt(signer, Config::instance()->decryption_chain()->leaf(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, true, 0);
78 /* Add just the OV to a new project, move it around a bit and check that
79 the _reels get reused.
81 auto test = new_test_film2 ("check_reuse_old_data_test1");
82 ov_content = make_shared<DCPContent>(ov->dir(ov->dcp_name(false)));
83 test->examine_and_add_content (ov_content);
84 BOOST_REQUIRE (!wait_for_jobs());
85 auto player = make_shared<Player>(test, Image::Alignment::COMPACT);
87 auto decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
88 BOOST_REQUIRE (decoder);
89 auto reels = decoder->reels();
91 ov_content->set_position (test, dcpomatic::DCPTime(96000));
92 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
93 BOOST_REQUIRE (decoder);
94 BOOST_REQUIRE (reels == decoder->reels());
96 /* Add the VF to a new project, then add the OV and check that the
97 _reels did not get reused.
99 test = new_test_film2 ("check_reuse_old_data_test2");
100 auto vf_content = make_shared<DCPContent>(vf->dir(vf->dcp_name(false)));
101 test->examine_and_add_content (vf_content);
102 BOOST_REQUIRE (!wait_for_jobs());
103 player = make_shared<Player>(test, Image::Alignment::COMPACT);
105 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
106 BOOST_REQUIRE (decoder);
107 reels = decoder->reels();
109 vf_content->add_ov (ov->dir(ov->dcp_name(false)));
110 JobManager::instance()->add (make_shared<ExamineContentJob>(test, vf_content));
111 BOOST_REQUIRE (!wait_for_jobs());
112 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
113 BOOST_REQUIRE (decoder);
114 BOOST_REQUIRE (reels != decoder->reels());
116 /* Add a KDM to an encrypted DCP and check that the _reels did not get reused */
117 test = new_test_film2 ("check_reuse_old_data_test3");
118 auto encrypted_content = make_shared<DCPContent>(encrypted->dir(encrypted->dcp_name(false)));
119 test->examine_and_add_content (encrypted_content);
120 BOOST_REQUIRE (!wait_for_jobs());
121 player = make_shared<Player>(test, Image::Alignment::COMPACT);
123 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
124 BOOST_REQUIRE (decoder);
125 reels = decoder->reels();
127 encrypted_content->add_kdm (kdm);
128 JobManager::instance()->add (make_shared<ExamineContentJob>(test, encrypted_content));
129 BOOST_REQUIRE (!wait_for_jobs());
130 decoder = std::dynamic_pointer_cast<DCPDecoder>(player->_pieces.front()->decoder);
131 BOOST_REQUIRE (decoder);
132 BOOST_REQUIRE (reels != decoder->reels());