summaryrefslogtreecommitdiff
path: root/test/j2k_encoder_test.cc
blob: 39e3f9135f7bb17386f4e5d38b7ae96630e3beb0 (plain)
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
/*
    Copyright (C) 2024 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/config.h"
#include "lib/cross.h"
#include "lib/image.h"
#include "lib/j2k_encoder.h"
#include "lib/player_video.h"
#include "lib/raw_image_proxy.h"
#include "lib/writer.h"
#include "test.h"
extern "C" {
#include <libavutil/pixfmt.h>
}
#include <boost/test/unit_test.hpp>


using std::make_shared;
using std::weak_ptr;
using boost::optional;


BOOST_AUTO_TEST_CASE(j2k_encoder_deadlock_test)
{
	ConfigRestorer cr;

	auto film = new_test_film2("j2k_encoder_deadlock_test");

	/* Don't call ::start() on this Writer, so it can never write anything */
	Writer writer(film, {});
	writer.set_encoder_threads(4);

	/* We want to test the case where the writer queue fills, and this can't happen unless there
	 * are enough encoding threads (each of which will end up waiting for the writer to empty,
	 * which will never happen).
	 */
	Config::instance()->set_master_encoding_threads(4);
	J2KEncoder encoder(film, writer);
	encoder.begin();

	for (int i = 0; i < 26; ++i) {
		auto image = make_shared<Image>(AV_PIX_FMT_RGB24, dcp::Size(1998, 1080), Image::Alignment::PADDED);
		auto image_proxy = make_shared<RawImageProxy>(image);
		encoder.encode(
			std::make_shared<PlayerVideo>(
				image_proxy,
				Crop(),
				optional<double>(),
				dcp::Size(1998, 1080),
				dcp::Size(1998, 1080),
				Eyes::BOTH,
				Part::WHOLE,
				optional<ColourConversion>(),
				VideoRange::VIDEO,
				weak_ptr<Content>(),
				optional<dcpomatic::ContentTime>(),
				false
				),
			{}
			);
	}

	dcpomatic_sleep_seconds(10);
}