2 Copyright (C) 2019-2020 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 #include "lib/content_factory.h"
23 #include "lib/image_content.h"
24 #include "lib/dcp_subtitle_content.h"
25 #include "lib/text_content.h"
26 #include "lib/video_content.h"
31 #include <dcp/interop_subtitle_asset.h>
32 #include <dcp/reel_closed_caption_asset.h>
33 #include <dcp/reel_subtitle_asset.h>
34 #include <boost/test/unit_test.hpp>
39 using std::shared_ptr;
40 using std::make_shared;
41 using boost::optional;
44 /* Check that timings are done correctly for multi-reel DCPs with PNG subs */
45 BOOST_AUTO_TEST_CASE (subtitle_reel_test)
47 auto film = new_test_film2 ("subtitle_reel_test");
48 film->set_interop (true);
49 auto red_a = make_shared<ImageContent>("test/data/flat_red.png");
50 auto red_b = make_shared<ImageContent>("test/data/flat_red.png");
51 auto sub_a = make_shared<DCPSubtitleContent>("test/data/png_subs/subs.xml");
52 auto sub_b = make_shared<DCPSubtitleContent>("test/data/png_subs/subs.xml");
54 film->examine_and_add_content (red_a);
55 film->examine_and_add_content (red_b);
56 film->examine_and_add_content (sub_a);
57 film->examine_and_add_content (sub_b);
59 BOOST_REQUIRE (!wait_for_jobs());
61 red_a->set_position (film, dcpomatic::DCPTime());
62 red_a->video->set_length (240);
63 sub_a->set_position (film, dcpomatic::DCPTime());
64 red_b->set_position (film, dcpomatic::DCPTime::from_seconds(10));
65 red_b->video->set_length (240);
66 sub_b->set_position (film, dcpomatic::DCPTime::from_seconds(10));
68 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
70 make_and_verify_dcp (film, {dcp::VerificationNote::Code::INVALID_STANDARD});
72 dcp::DCP dcp ("build/test/subtitle_reel_test/" + film->dcp_name());
74 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
75 shared_ptr<dcp::CPL> cpl = dcp.cpls().front();
77 auto reels = cpl->reels ();
78 BOOST_REQUIRE_EQUAL (reels.size(), 2U);
79 auto i = reels.begin ();
80 BOOST_REQUIRE ((*i)->main_subtitle());
81 BOOST_REQUIRE ((*i)->main_subtitle()->asset());
82 auto A = std::dynamic_pointer_cast<dcp::InteropSubtitleAsset>((*i)->main_subtitle()->asset());
85 BOOST_REQUIRE ((*i)->main_subtitle());
86 BOOST_REQUIRE ((*i)->main_subtitle()->asset());
87 auto B = std::dynamic_pointer_cast<dcp::InteropSubtitleAsset>((*i)->main_subtitle()->asset());
90 BOOST_REQUIRE_EQUAL (A->subtitles().size(), 1U);
91 BOOST_REQUIRE_EQUAL (B->subtitles().size(), 1U);
93 /* These times should be the same as they are should be offset from the start of the reel */
94 BOOST_CHECK (A->subtitles().front()->in() == B->subtitles().front()->in());
99 /** Check that with a SMPTE DCP if we have subtitles in one reel, all reels have a
100 * SubtitleAsset (even if it's empty); SMPTE Bv2.1 section 8.3.1.
102 BOOST_AUTO_TEST_CASE (subtitle_in_all_reels_test)
104 auto film = new_test_film2 ("subtitle_in_all_reels_test");
105 film->set_interop (false);
106 film->set_sequence (false);
107 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
108 for (int i = 0; i < 3; ++i) {
109 auto video = content_factory("test/data/flat_red.png").front();
110 film->examine_and_add_content (video);
111 BOOST_REQUIRE (!wait_for_jobs());
112 video->video->set_length (15 * 24);
113 video->set_position (film, dcpomatic::DCPTime::from_seconds(15 * i));
115 auto subs = content_factory("test/data/15s.srt").front();
116 film->examine_and_add_content (subs);
117 BOOST_REQUIRE (!wait_for_jobs());
118 make_and_verify_dcp (
121 dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
122 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
123 dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING
126 dcp::DCP dcp ("build/test/subtitle_in_all_reels_test/" + film->dcp_name());
128 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
129 auto cpl = dcp.cpls()[0];
130 BOOST_REQUIRE_EQUAL (cpl->reels().size(), 3U);
132 for (auto i: cpl->reels()) {
133 BOOST_CHECK (i->main_subtitle());
138 /** Check that with a SMPTE DCP if we have closed captions in one reel, all reels have a
139 * ClosedCaptionAssets for the same set of tracks (even if they are empty); SMPTE Bv2.1 section 8.3.1.
141 BOOST_AUTO_TEST_CASE (closed_captions_in_all_reels_test)
143 auto film = new_test_film2 ("closed_captions_in_all_reels_test");
144 film->set_interop (false);
145 film->set_sequence (false);
146 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
148 for (int i = 0; i < 3; ++i) {
149 auto video = content_factory("test/data/flat_red.png").front();
150 film->examine_and_add_content (video);
151 BOOST_REQUIRE (!wait_for_jobs());
152 video->video->set_length (15 * 24);
153 video->set_position (film, dcpomatic::DCPTime::from_seconds(15 * i));
156 auto ccap1 = content_factory("test/data/15s.srt").front();
157 film->examine_and_add_content (ccap1);
158 BOOST_REQUIRE (!wait_for_jobs());
159 ccap1->text.front()->set_type (TextType::CLOSED_CAPTION);
160 ccap1->text.front()->set_dcp_track (DCPTextTrack("Test", dcp::LanguageTag("de-DE")));
162 auto ccap2 = content_factory("test/data/15s.srt").front();
163 film->examine_and_add_content (ccap2);
164 BOOST_REQUIRE (!wait_for_jobs());
165 ccap2->text.front()->set_type (TextType::CLOSED_CAPTION);
166 ccap2->text.front()->set_dcp_track (DCPTextTrack("Other", dcp::LanguageTag("en-GB")));
168 make_and_verify_dcp (
171 dcp::VerificationNote::Code::INVALID_SUBTITLE_FIRST_TEXT_TIME,
172 dcp::VerificationNote::Code::INVALID_SUBTITLE_SPACING
175 dcp::DCP dcp ("build/test/closed_captions_in_all_reels_test/" + film->dcp_name());
177 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
178 auto cpl = dcp.cpls().front();
179 BOOST_REQUIRE_EQUAL (cpl->reels().size(), 3U);
181 for (auto i: cpl->reels()) {
182 BOOST_REQUIRE_EQUAL (i->closed_captions().size(), 2U);
183 auto first = i->closed_captions().front()->language();
184 auto second = i->closed_captions().back()->language();
185 BOOST_REQUIRE (first);
186 BOOST_REQUIRE (second);
188 (*first == "en-GB" && *second == "de-DE") ||
189 (*first == "de-DE" && *second == "en-GB")
195 BOOST_AUTO_TEST_CASE (subtitles_split_at_reel_boundaries)
197 auto film = new_test_film2 ("subtitles_split_at_reel_boundaries");
198 film->set_interop (true);
200 film->set_sequence (false);
201 film->set_reel_type (ReelType::BY_VIDEO_CONTENT);
203 for (int i = 0; i < 3; ++i) {
204 auto video = content_factory("test/data/flat_red.png").front();
205 film->examine_and_add_content (video);
206 BOOST_REQUIRE (!wait_for_jobs());
207 video->video->set_length (15 * 24);
208 video->set_position (film, dcpomatic::DCPTime::from_seconds(15 * i));
211 auto subtitle = content_factory("test/data/45s.srt").front();
212 film->examine_and_add_content (subtitle);
213 BOOST_REQUIRE (!wait_for_jobs());
215 make_and_verify_dcp (film, { dcp::VerificationNote::Code::INVALID_STANDARD });
217 dcp::DCP dcp (film->dir(film->dcp_name()));
219 BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
220 auto cpl = dcp.cpls()[0];
221 BOOST_REQUIRE_EQUAL (cpl->reels().size(), 3U);
223 for (auto i: cpl->reels()) {
224 auto reel_sub = i->main_subtitle();
225 BOOST_REQUIRE (reel_sub);
226 auto sub = reel_sub->asset();
228 BOOST_CHECK_EQUAL (sub->subtitles().size(), 1U);