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/reel_writer_test.cc
23 * @brief Test ReelWriter class.
24 * @ingroup selfcontained
28 #include "lib/audio_content.h"
29 #include "lib/content.h"
30 #include "lib/content_factory.h"
31 #include "lib/cross.h"
33 #include "lib/reel_writer.h"
34 #include "lib/video_content.h"
39 #include <dcp/reel_picture_asset.h>
40 #include <dcp/reel_sound_asset.h>
41 #include <boost/test/unit_test.hpp>
44 using std::shared_ptr;
46 using boost::optional;
49 static bool equal (dcp::FrameInfo a, ReelWriter const & writer, shared_ptr<InfoFileHandle> file, Frame frame, Eyes eyes)
51 auto b = writer.read_frame_info(file, frame, eyes);
52 return a.offset == b.offset && a.size == b.size && a.hash == b.hash;
56 BOOST_AUTO_TEST_CASE (write_frame_info_test)
58 auto film = new_test_film2 ("write_frame_info_test");
59 dcpomatic::DCPTimePeriod const period (dcpomatic::DCPTime(0), dcpomatic::DCPTime(96000));
60 ReelWriter writer (film, period, shared_ptr<Job>(), 0, 1, false);
62 /* Write the first one */
64 dcp::FrameInfo info1(0, 123, "12345678901234567890123456789012");
65 writer.write_frame_info (0, Eyes::LEFT, info1);
67 auto file = film->info_file_handle(period, true);
68 BOOST_CHECK (equal(info1, writer, file, 0, Eyes::LEFT));
73 dcp::FrameInfo info2(596, 14921, "123acb789f1234ae782012n456339522");
74 writer.write_frame_info (5, Eyes::RIGHT, info2);
77 auto file = film->info_file_handle(period, true);
78 BOOST_CHECK (equal(info1, writer, file, 0, Eyes::LEFT));
79 BOOST_CHECK (equal(info2, writer, file, 5, Eyes::RIGHT));
82 dcp::FrameInfo info3(12494, 99157123, "xxxxyyyyabc12356ffsfdsf456339522");
83 writer.write_frame_info (10, Eyes::LEFT, info3);
86 auto file = film->info_file_handle(period, true);
87 BOOST_CHECK (equal(info1, writer, file, 0, Eyes::LEFT));
88 BOOST_CHECK (equal(info2, writer, file, 5, Eyes::RIGHT));
89 BOOST_CHECK (equal(info3, writer, file, 10, Eyes::LEFT));
94 dcp::FrameInfo info4(55512494, 123599157123, "ABCDEFGyabc12356ffsfdsf4563395ZZ");
95 writer.write_frame_info (5, Eyes::RIGHT, info4);
98 auto file = film->info_file_handle(period, true);
99 BOOST_CHECK (equal(info1, writer, file, 0, Eyes::LEFT));
100 BOOST_CHECK (equal(info4, writer, file, 5, Eyes::RIGHT));
101 BOOST_CHECK (equal(info3, writer, file, 10, Eyes::LEFT));
106 /** Check that the reel writer correctly re-uses a video asset changed if we remake
107 * a DCP with no video changes.
109 BOOST_AUTO_TEST_CASE (reel_reuse_video_test)
112 auto video = content_factory("test/data/flat_red.png").front();
113 auto audio = content_factory("test/data/white.wav").front();
114 auto film = new_test_film2 ("reel_reuse_video_test", { video, audio });
115 make_and_verify_dcp (film);
117 /* Find main picture and sound asset IDs */
118 dcp::DCP dcp1 (film->dir(film->dcp_name()));
120 BOOST_REQUIRE_EQUAL (dcp1.cpls().size(), 1U);
121 BOOST_REQUIRE_EQUAL (dcp1.cpls()[0]->reels().size(), 1U);
122 BOOST_REQUIRE (dcp1.cpls()[0]->reels()[0]->main_picture());
123 BOOST_REQUIRE (dcp1.cpls()[0]->reels()[0]->main_sound());
124 auto const picture_id = dcp1.cpls()[0]->reels()[0]->main_picture()->asset()->id();
125 auto const sound_id = dcp1.cpls()[0]->reels()[0]->main_sound()->asset()->id();
127 /* Change the audio and re-make */
128 audio->audio->set_gain (-3);
129 make_and_verify_dcp (film);
131 /* Video ID should be the same, sound different */
132 dcp::DCP dcp2 (film->dir(film->dcp_name()));
134 BOOST_REQUIRE_EQUAL (dcp2.cpls().size(), 1U);
135 BOOST_REQUIRE_EQUAL (dcp2.cpls()[0]->reels().size(), 1U);
136 BOOST_REQUIRE (dcp2.cpls()[0]->reels()[0]->main_picture());
137 BOOST_REQUIRE (dcp2.cpls()[0]->reels()[0]->main_sound());
138 BOOST_CHECK_EQUAL (picture_id, dcp2.cpls()[0]->reels()[0]->main_picture()->asset()->id());
139 BOOST_CHECK (sound_id != dcp2.cpls()[0]->reels().front()->main_sound()->asset()->id());
141 /* Crop video and re-make */
142 video->video->set_left_crop (5);
143 make_and_verify_dcp (film);
145 /* Video and sound IDs should be different */
146 dcp::DCP dcp3 (film->dir(film->dcp_name()));
148 BOOST_REQUIRE_EQUAL (dcp3.cpls().size(), 1U);
149 BOOST_REQUIRE_EQUAL (dcp3.cpls()[0]->reels().size(), 1U);
150 BOOST_REQUIRE (dcp3.cpls()[0]->reels()[0]->main_picture());
151 BOOST_REQUIRE (dcp3.cpls()[0]->reels()[0]->main_sound());
152 BOOST_CHECK (picture_id != dcp3.cpls()[0]->reels()[0]->main_picture()->asset()->id());
153 BOOST_CHECK (sound_id != dcp3.cpls()[0]->reels().front()->main_sound()->asset()->id());