2 Copyright (C) 2023 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/config.h"
23 #include "lib/content_factory.h"
24 #include "lib/dcp_encoder.h"
25 #include "lib/dcp_transcode_job.h"
26 #include "lib/encode_server_description.h"
28 #include "lib/j2k_encoder.h"
29 #include "lib/job_manager.h"
30 #include "lib/make_dcp.h"
31 #include "lib/transcode_job.h"
36 #include <dcp/reel_picture_asset.h>
37 #include <boost/test/unit_test.hpp>
40 using std::dynamic_pointer_cast;
44 BOOST_AUTO_TEST_CASE(local_threads_created_and_destroyed)
46 auto film = new_test_film2("local_threads_created_and_destroyed", {});
47 Writer writer(film, {});
48 J2KEncoder encoder(film, writer);
50 encoder.remake_threads(32, 0, {});
51 BOOST_CHECK_EQUAL(encoder._threads.size(), 32U);
53 encoder.remake_threads(9, 0, {});
54 BOOST_CHECK_EQUAL(encoder._threads.size(), 9U);
57 BOOST_CHECK_EQUAL(encoder._threads.size(), 0U);
61 BOOST_AUTO_TEST_CASE(remote_threads_created_and_destroyed)
63 auto film = new_test_film2("remote_threads_created_and_destroyed", {});
64 Writer writer(film, {});
65 J2KEncoder encoder(film, writer);
67 list<EncodeServerDescription> servers = {
68 { "fred", 7, SERVER_LINK_VERSION },
69 { "jim", 2, SERVER_LINK_VERSION },
70 { "sheila", 14, SERVER_LINK_VERSION },
73 encoder.remake_threads(0, 0, servers);
74 BOOST_CHECK_EQUAL(encoder._threads.size(), 7U + 2U + 14U);
77 { "fred", 7, SERVER_LINK_VERSION },
78 { "jim", 5, SERVER_LINK_VERSION },
79 { "sheila", 14, SERVER_LINK_VERSION },
82 encoder.remake_threads(0, 0, servers);
83 BOOST_CHECK_EQUAL(encoder._threads.size(), 7U + 5U + 14U);
86 { "fred", 0, SERVER_LINK_VERSION },
87 { "jim", 0, SERVER_LINK_VERSION },
88 { "sheila", 11, SERVER_LINK_VERSION },
91 encoder.remake_threads(0, 0, servers);
92 BOOST_CHECK_EQUAL(encoder._threads.size(), 11U);
96 BOOST_AUTO_TEST_CASE(frames_not_lost_when_threads_disappear)
98 auto content = content_factory(TestPaths::private_data() / "clapperboard.mp4");
99 auto film = new_test_film2("frames_not_lost", content);
100 film->write_metadata();
101 auto job = make_dcp(film, TranscodeJob::ChangedBehaviour::IGNORE);
102 auto& encoder = dynamic_pointer_cast<DCPEncoder>(job->_encoder)->_j2k_encoder;
104 while (JobManager::instance()->work_to_do()) {
105 encoder.remake_threads(rand() % 8, 0, {});
106 dcpomatic_sleep_seconds(1);
109 BOOST_CHECK(!JobManager::instance()->errors());
111 dcp::DCP dcp(film->dir(film->dcp_name()));
113 BOOST_REQUIRE_EQUAL(dcp.cpls().size(), 1U);
114 BOOST_REQUIRE_EQUAL(dcp.cpls()[0]->reels().size(), 1U);
115 BOOST_REQUIRE_EQUAL(dcp.cpls()[0]->reels()[0]->main_picture()->intrinsic_duration(), 423U);