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;
41 BOOST_AUTO_TEST_CASE (test_write_odd_amount_of_silence)
43 auto content = content_factory("test/data/flat_red.png").front();
44 auto film = new_test_film2 ("test_write_odd_amount_of_silence", {content});
45 content->video->set_length(24);
46 auto writer = make_shared<Writer>(film, shared_ptr<Job>());
48 auto audio = make_shared<AudioBuffers>(6, 48000);
49 audio->make_silent ();
50 writer->write (audio, dcpomatic::DCPTime(1));
54 BOOST_AUTO_TEST_CASE (interrupt_writer)
56 auto film = new_test_film2 ("test_interrupt_writer");
58 auto content = content_factory("test/data/check_image0.png").front();
59 film->examine_and_add_content (content);
60 BOOST_REQUIRE (!wait_for_jobs());
62 /* Add some dummy content to the film so that it has a reel of the right length */
63 auto constexpr frames = 24 * 60 * 60;
64 content->video->set_length (frames);
66 /* Make a random J2K image */
67 auto size = dcp::Size(1998, 1080);
68 auto image = make_shared<dcp::OpenJPEGImage>(size);
69 for (int i = 0; i < 3; ++i) {
70 for (int j = 0; j < (size.width * size.height); ++j) {
71 image->data(i)[j] = rand();
76 auto video = dcp::compress_j2k(image, 100000000, 24, false, false);
77 auto video_ptr = make_shared<dcp::ArrayData>(video.data(), video.size());
78 auto audio = make_shared<AudioBuffers>(6, 48000 / 24);
80 auto writer = make_shared<Writer>(film, shared_ptr<Job>());
83 for (int i = 0; i < frames; ++i) {
84 writer->write (video_ptr, i, Eyes::BOTH);
85 writer->write (audio, dcpomatic::DCPTime::from_frames(i, 24));
88 /* Start digest calculations then abort them; there should be no crash or error */
89 boost::thread thread([film, writer]() {
90 writer->finish(film->dir(film->dcp_name()));
93 dcpomatic_sleep_seconds (1);
97 dcpomatic_sleep_seconds (1);