2 Copyright (C) 2019 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/reel_writer_test.cc
22 * @brief Test ReelWriter class.
23 * @ingroup selfcontained
26 #include "lib/reel_writer.h"
28 #include "lib/cross.h"
29 #include "lib/content_factory.h"
30 #include "lib/content.h"
31 #include "lib/audio_content.h"
32 #include "lib/video_content.h"
37 #include <dcp/reel_picture_asset.h>
38 #include <dcp/reel_sound_asset.h>
39 #include <boost/test/unit_test.hpp>
42 using boost::shared_ptr;
43 using boost::optional;
45 static bool equal (dcp::FrameInfo a, ReelWriter const & writer, shared_ptr<InfoFileHandle> file, Frame frame, Eyes eyes)
47 dcp::FrameInfo b = writer.read_frame_info(file, frame, eyes);
48 return a.offset == b.offset && a.size == b.size && a.hash == b.hash;
51 BOOST_AUTO_TEST_CASE (write_frame_info_test)
53 shared_ptr<Film> film = new_test_film2 ("write_frame_info_test");
54 dcpomatic::DCPTimePeriod const period (dcpomatic::DCPTime(0), dcpomatic::DCPTime(96000));
55 ReelWriter writer (film, period, shared_ptr<Job>(), 0, 1, optional<string>());
57 /* Write the first one */
59 dcp::FrameInfo info1(0, 123, "12345678901234567890123456789012");
60 writer.write_frame_info (0, EYES_LEFT, info1);
62 shared_ptr<InfoFileHandle> file = film->info_file_handle(period, true);
63 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
68 dcp::FrameInfo info2(596, 14921, "123acb789f1234ae782012n456339522");
69 writer.write_frame_info (5, EYES_RIGHT, info2);
72 shared_ptr<InfoFileHandle> file = film->info_file_handle(period, true);
73 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
74 BOOST_CHECK (equal(info2, writer, file, 5, EYES_RIGHT));
77 dcp::FrameInfo info3(12494, 99157123, "xxxxyyyyabc12356ffsfdsf456339522");
78 writer.write_frame_info (10, EYES_LEFT, info3);
81 shared_ptr<InfoFileHandle> file = film->info_file_handle(period, true);
82 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
83 BOOST_CHECK (equal(info2, writer, file, 5, EYES_RIGHT));
84 BOOST_CHECK (equal(info3, writer, file, 10, EYES_LEFT));
89 dcp::FrameInfo info4(55512494, 123599157123, "ABCDEFGyabc12356ffsfdsf4563395ZZ");
90 writer.write_frame_info (5, EYES_RIGHT, info4);
93 shared_ptr<InfoFileHandle> file = film->info_file_handle(period, true);
94 BOOST_CHECK (equal(info1, writer, file, 0, EYES_LEFT));
95 BOOST_CHECK (equal(info4, writer, file, 5, EYES_RIGHT));
96 BOOST_CHECK (equal(info3, writer, file, 10, EYES_LEFT));
100 /** Check that the reel writer correctly re-uses a video asset changed if we remake
101 * a DCP with no video changes.
103 BOOST_AUTO_TEST_CASE (reel_reuse_video_test)
106 shared_ptr<Film> film = new_test_film2 ("reel_reuse_video_test");
107 shared_ptr<Content> video = content_factory("test/data/flat_red.png").front();
108 film->examine_and_add_content (video);
109 BOOST_REQUIRE (!wait_for_jobs());
110 shared_ptr<Content> audio = content_factory("test/data/white.wav").front();
111 film->examine_and_add_content (audio);
112 BOOST_REQUIRE (!wait_for_jobs());
114 BOOST_REQUIRE (!wait_for_jobs());
116 /* Find main picture and sound asset IDs */
117 dcp::DCP dcp1 (film->dir(film->dcp_name()));
119 BOOST_REQUIRE_EQUAL (dcp1.cpls().size(), 1);
120 BOOST_REQUIRE_EQUAL (dcp1.cpls().front()->reels().size(), 1);
121 BOOST_REQUIRE (dcp1.cpls().front()->reels().front()->main_picture());
122 BOOST_REQUIRE (dcp1.cpls().front()->reels().front()->main_sound());
123 string const picture_id = dcp1.cpls().front()->reels().front()->main_picture()->asset()->id();
124 string const sound_id = dcp1.cpls().front()->reels().front()->main_sound()->asset()->id();
126 /* Change the audio and re-make */
127 audio->audio->set_gain (-3);
129 BOOST_REQUIRE (!wait_for_jobs());
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(), 1);
135 BOOST_REQUIRE_EQUAL (dcp2.cpls().front()->reels().size(), 1);
136 BOOST_REQUIRE (dcp2.cpls().front()->reels().front()->main_picture());
137 BOOST_REQUIRE (dcp2.cpls().front()->reels().front()->main_sound());
138 BOOST_CHECK_EQUAL (picture_id, dcp2.cpls().front()->reels().front()->main_picture()->asset()->id());
139 BOOST_CHECK (sound_id != dcp2.cpls().front()->reels().front()->main_sound()->asset()->id());
141 /* Crop video and re-make */
142 video->video->set_left_crop (5);
144 BOOST_REQUIRE (!wait_for_jobs());
146 /* Video and sound IDs should be different */
147 dcp::DCP dcp3 (film->dir(film->dcp_name()));
149 BOOST_REQUIRE_EQUAL (dcp3.cpls().size(), 1);
150 BOOST_REQUIRE_EQUAL (dcp3.cpls().front()->reels().size(), 1);
151 BOOST_REQUIRE (dcp3.cpls().front()->reels().front()->main_picture());
152 BOOST_REQUIRE (dcp3.cpls().front()->reels().front()->main_sound());
153 BOOST_CHECK (picture_id != dcp3.cpls().front()->reels().front()->main_picture()->asset()->id());
154 BOOST_CHECK (sound_id != dcp3.cpls().front()->reels().front()->main_sound()->asset()->id());