summaryrefslogtreecommitdiff
path: root/test/j2k_encoder_test.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-09-13 00:56:17 +0200
committerCarl Hetherington <cth@carlh.net>2024-09-13 01:14:21 +0200
commitf02501491e262c52b65c3fea6e180814e132dad8 (patch)
tree2581f29b86cee412697b4d72c0aa521ff404fd45 /test/j2k_encoder_test.cc
parent518dc747e2437d0a51ff4582e79f47ea1754f057 (diff)
Hopefully fix occasional hang in j2k_encoder_deadlock_test.
Previously too many frames were queued for encoding, which AFAICS meant that (if the CPU was busy) we would get to the point where too many frames were in the encoder queue, so that we blocked waiting for it to clear, and then simultaneously too many frames were in the writer queue, which (in this test) would never clear. At this point we would be backed up waiting for Writer::write() to happen in J2KEncoder::encoder_thread() so that the encoder queue could be cleared, but nobody is calling Writer::write().
Diffstat (limited to 'test/j2k_encoder_test.cc')
-rw-r--r--test/j2k_encoder_test.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/test/j2k_encoder_test.cc b/test/j2k_encoder_test.cc
index bc3bd97b2..b3167dacc 100644
--- a/test/j2k_encoder_test.cc
+++ b/test/j2k_encoder_test.cc
@@ -44,19 +44,25 @@ BOOST_AUTO_TEST_CASE(j2k_encoder_deadlock_test)
auto film = new_test_film2("j2k_encoder_deadlock_test");
+ auto constexpr threads = 4;
+
/* Don't call ::start() on this Writer, so it can never write anything */
Writer writer(film, {});
- writer.set_encoder_threads(4);
+ writer.set_encoder_threads(threads);
/* 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);
+ Config::instance()->set_master_encoding_threads(threads);
J2KEncoder encoder(film, writer);
encoder.begin();
- for (int i = 0; i < 26; ++i) {
+ /* The queue will be full when we write another frame when there are already
+ * more than (threads * frames_in_memory_multiplier [i.e. 3])
+ * in the queue, so to fill the queue we must add threads * 3 + 2.
+ */
+ for (int i = 0; i < (threads * 3) + 2; ++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(