2 Copyright (C) 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 #include "lib/audio_buffers.h"
23 #include "lib/content.h"
24 #include "lib/content_factory.h"
25 #include "lib/cross.h"
28 #include "lib/video_content.h"
29 #include "lib/writer.h"
31 #include <dcp/openjpeg_image.h>
32 #include <dcp/j2k_transcode.h>
33 #include <boost/test/unit_test.hpp>
37 using std::make_shared;
38 using std::shared_ptr;
42 BOOST_AUTO_TEST_CASE (test_write_odd_amount_of_silence)
44 auto content = content_factory("test/data/flat_red.png").front();
45 auto film = new_test_film2 ("test_write_odd_amount_of_silence", {content});
46 content->video->set_length(24);
47 auto writer = make_shared<Writer>(film, shared_ptr<Job>());
49 auto audio = make_shared<AudioBuffers>(6, 48000);
50 audio->make_silent ();
51 writer->write (audio, dcpomatic::DCPTime(1));
55 BOOST_AUTO_TEST_CASE (interrupt_writer)
59 auto film = new_test_film2 ("test_interrupt_writer", {}, &cl);
61 auto content = content_factory("test/data/check_image0.png").front();
62 film->examine_and_add_content (content);
63 BOOST_REQUIRE (!wait_for_jobs());
65 /* Add some dummy content to the film so that it has a reel of the right length */
66 auto constexpr frames = 24 * 60;
67 content->video->set_length (frames);
69 /* Make a random J2K image */
70 auto size = dcp::Size(1998, 1080);
71 auto image = make_shared<dcp::OpenJPEGImage>(size);
72 for (int i = 0; i < 3; ++i) {
73 for (int j = 0; j < (size.width * size.height); ++j) {
74 image->data(i)[j] = rand();
79 auto video = dcp::compress_j2k(image, 100000000, 24, false, false);
80 auto video_ptr = make_shared<dcp::ArrayData>(video.data(), video.size());
81 auto audio = make_shared<AudioBuffers>(6, 48000 / 24);
83 auto writer = make_shared<Writer>(film, shared_ptr<Job>());
86 for (int i = 0; i < frames; ++i) {
87 writer->write (video_ptr, i, Eyes::BOTH);
88 writer->write (audio, dcpomatic::DCPTime::from_frames(i, 24));
91 /* Start digest calculations then abort them; there should be no crash or error */
92 boost::thread thread([film, writer]() {
93 writer->finish(film->dir(film->dcp_name()));
96 dcpomatic_sleep_seconds (1);
101 dcpomatic_sleep_seconds (1);
106 BOOST_AUTO_TEST_CASE (writer_disambiguate_font_ids1)
108 auto film = new_test_film2("writer_disambiguate_font_ids1", {});
109 Writer writer(film, {});
111 auto fonts = vector<shared_ptr<dcpomatic::Font>> {
112 make_shared<dcpomatic::Font>("a"),
113 make_shared<dcpomatic::Font>("b"),
114 make_shared<dcpomatic::Font>("c")
119 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[0]), "a");
120 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[1]), "b");
121 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[2]), "c");
125 BOOST_AUTO_TEST_CASE (writer_disambiguate_font_ids2)
127 auto film = new_test_film2("writer_disambiguate_font_ids2", {});
128 Writer writer(film, {});
130 auto fonts = vector<shared_ptr<dcpomatic::Font>> {
131 make_shared<dcpomatic::Font>("a"),
132 make_shared<dcpomatic::Font>("a"),
133 make_shared<dcpomatic::Font>("a")
138 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[0]), "a");
139 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[1]), "a_0");
140 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[2]), "a_1");
144 BOOST_AUTO_TEST_CASE (writer_disambiguate_font_ids3)
146 auto film = new_test_film2("writer_disambiguate_font_ids3", {});
147 Writer writer(film, {});
149 auto fonts = vector<shared_ptr<dcpomatic::Font>> {
150 make_shared<dcpomatic::Font>("a_2"),
151 make_shared<dcpomatic::Font>("a_1"),
152 make_shared<dcpomatic::Font>("a_1"),
153 make_shared<dcpomatic::Font>("b")
158 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[1]), "a_1");
159 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[0]), "a_2");
160 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[2]), "a_3");
161 BOOST_CHECK_EQUAL(writer._fonts.get(fonts[3]), "b");