1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*
Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
DCP-o-matic is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DCP-o-matic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lib/audio_buffers.h"
#include "lib/content.h"
#include "lib/content_factory.h"
#include "lib/cross.h"
#include "lib/film.h"
#include "lib/job.h"
#include "lib/video_content.h"
#include "lib/writer.h"
#include "test.h"
#include <dcp/openjpeg_image.h>
#include <dcp/j2k_transcode.h>
#include <boost/test/unit_test.hpp>
#include <memory>
using std::make_shared;
using std::shared_ptr;
using std::vector;
BOOST_AUTO_TEST_CASE (test_write_odd_amount_of_silence)
{
auto content = content_factory("test/data/flat_red.png");
auto film = new_test_film2 ("test_write_odd_amount_of_silence", content);
content[0]->video->set_length(24);
auto writer = make_shared<Writer>(film, shared_ptr<Job>());
auto audio = make_shared<AudioBuffers>(6, 48000);
audio->make_silent ();
writer->write (audio, dcpomatic::DCPTime(1));
}
BOOST_AUTO_TEST_CASE (interrupt_writer)
{
Cleanup cl;
auto film = new_test_film2 ("test_interrupt_writer", {}, &cl);
auto content = content_factory("test/data/check_image0.png")[0];
film->examine_and_add_content (content);
BOOST_REQUIRE (!wait_for_jobs());
/* Add some dummy content to the film so that it has a reel of the right length */
auto constexpr frames = 24 * 60;
content->video->set_length (frames);
/* Make a random J2K image */
auto size = dcp::Size(1998, 1080);
auto image = make_shared<dcp::OpenJPEGImage>(size);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < (size.width * size.height); ++j) {
image->data(i)[j] = rand();
}
}
/* Write some data */
auto video = dcp::compress_j2k(image, 100000000, 24, false, false);
auto video_ptr = make_shared<dcp::ArrayData>(video.data(), video.size());
auto audio = make_shared<AudioBuffers>(6, 48000 / 24);
auto writer = make_shared<Writer>(film, shared_ptr<Job>());
writer->start ();
for (int i = 0; i < frames; ++i) {
writer->write (video_ptr, i, Eyes::BOTH);
writer->write (audio, dcpomatic::DCPTime::from_frames(i, 24));
}
/* Start digest calculations then abort them; there should be no crash or error */
boost::thread thread([film, writer]() {
writer->finish(film->dir(film->dcp_name()));
});
dcpomatic_sleep_seconds (1);
thread.interrupt ();
thread.join ();
dcpomatic_sleep_seconds (1);
cl.run ();
}
BOOST_AUTO_TEST_CASE (writer_disambiguate_font_ids1)
{
auto film = new_test_film2("writer_disambiguate_font_ids1", {});
Writer writer(film, {});
auto fonts = vector<shared_ptr<dcpomatic::Font>> {
make_shared<dcpomatic::Font>("a"),
make_shared<dcpomatic::Font>("b"),
make_shared<dcpomatic::Font>("c")
};
writer.write(fonts);
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[0]), "a");
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[1]), "b");
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[2]), "c");
}
BOOST_AUTO_TEST_CASE (writer_disambiguate_font_ids2)
{
auto film = new_test_film2("writer_disambiguate_font_ids2", {});
Writer writer(film, {});
auto fonts = vector<shared_ptr<dcpomatic::Font>> {
make_shared<dcpomatic::Font>("a"),
make_shared<dcpomatic::Font>("a"),
make_shared<dcpomatic::Font>("a")
};
writer.write(fonts);
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[0]), "a");
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[1]), "a_0");
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[2]), "a_1");
}
BOOST_AUTO_TEST_CASE (writer_disambiguate_font_ids3)
{
auto film = new_test_film2("writer_disambiguate_font_ids3", {});
Writer writer(film, {});
auto fonts = vector<shared_ptr<dcpomatic::Font>> {
make_shared<dcpomatic::Font>("a_2"),
make_shared<dcpomatic::Font>("a_1"),
make_shared<dcpomatic::Font>("a_1"),
make_shared<dcpomatic::Font>("b")
};
writer.write(fonts);
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[1]), "a_1");
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[0]), "a_2");
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[2]), "a_3");
BOOST_CHECK_EQUAL(writer._fonts.get(fonts[3]), "b");
}
|