summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-11-21 14:32:45 +0100
committerCarl Hetherington <cth@carlh.net>2021-11-25 00:55:02 +0100
commit72ee4688cbaef0832eb44dee78063bbc0df97bf8 (patch)
treebcc4d4325961936366458f749fb14f145d98a6f9 /test
parentd930131bac027fb37af01c2326f5a76ebc23fef7 (diff)
Add fastvideo J2K encoding backend.
Diffstat (limited to 'test')
-rw-r--r--test/barrier_test.cc98
-rw-r--r--test/fastvideo_test.cc73
-rw-r--r--test/wscript6
3 files changed, 177 insertions, 0 deletions
diff --git a/test/barrier_test.cc b/test/barrier_test.cc
new file mode 100644
index 000000000..c7bfbb801
--- /dev/null
+++ b/test/barrier_test.cc
@@ -0,0 +1,98 @@
+/*
+ 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/barrier.h"
+#include "lib/cross.h"
+#include <boost/test/unit_test.hpp>
+#include <boost/thread/thread.hpp>
+
+
+BOOST_AUTO_TEST_CASE (barrier_test)
+{
+ int constexpr num_threads = 128;
+
+ Barrier barrier (num_threads);
+
+ boost::mutex mutex;
+ int count = 0;
+
+ auto thread_body = [&barrier, &mutex, &count]() {
+ barrier.wait();
+ boost::mutex::scoped_lock lm(mutex);
+ ++count;
+ };
+
+ std::vector<boost::thread*> threads;
+ for (int i = 0; i < num_threads - 1; ++i) {
+ threads.push_back(new boost::thread(thread_body));
+ }
+
+ dcpomatic_sleep_seconds(5);
+
+ BOOST_CHECK_EQUAL (count, 0);
+
+ threads.push_back(new boost::thread(thread_body));
+ dcpomatic_sleep_seconds(5);
+
+ BOOST_CHECK_EQUAL (count, num_threads);
+
+ for (auto i: threads) {
+ i->join();
+ delete i;
+ }
+}
+
+
+BOOST_AUTO_TEST_CASE (barrier_test_lower)
+{
+ int constexpr num_threads = 128;
+
+ Barrier barrier (num_threads);
+
+ boost::mutex mutex;
+ int count = 0;
+
+ auto thread_body = [&barrier, &mutex, &count]() {
+ barrier.wait();
+ boost::mutex::scoped_lock lm(mutex);
+ ++count;
+ };
+
+ std::vector<boost::thread*> threads;
+ for (int i = 0; i < num_threads / 2; ++i) {
+ threads.push_back(new boost::thread(thread_body));
+ }
+
+ dcpomatic_sleep_seconds(5);
+
+ BOOST_CHECK_EQUAL (count, 0);
+
+ barrier.lower();
+ dcpomatic_sleep_seconds(5);
+
+ BOOST_CHECK_EQUAL (count, num_threads / 2);
+
+ for (auto i: threads) {
+ i->join();
+ delete i;
+ }
+}
+
diff --git a/test/fastvideo_test.cc b/test/fastvideo_test.cc
new file mode 100644
index 000000000..23369de62
--- /dev/null
+++ b/test/fastvideo_test.cc
@@ -0,0 +1,73 @@
+/*
+ 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/barrier.h"
+#include "lib/colour_conversion.h"
+#include "lib/dcp_video.h"
+#include "lib/ffmpeg_image_proxy.h"
+#include "lib/player_video.h"
+#include "lib/j2k_encoder_fastvideo_backend.h"
+#include "test.h"
+#include <boost/test/unit_test.hpp>
+
+
+BOOST_AUTO_TEST_CASE (fastvideo_frame_size_test)
+{
+ auto test = [](int j2k_bandwidth) {
+ Barrier barrier (1);
+ J2KEncoderFastvideoBackend backend (barrier);
+
+ auto image_proxy = std::make_shared<FFmpegImageProxy>(TestPaths::private_data() / "prophet_frame.tiff");
+ auto player_video = std::make_shared<PlayerVideo> (
+ image_proxy,
+ Crop(),
+ boost::optional<double>(),
+ dcp::Size(1998, 1080),
+ dcp::Size(1998, 1080),
+ Eyes::BOTH,
+ Part::WHOLE,
+ PresetColourConversion::from_id("rec709").conversion,
+ VideoRange::FULL,
+ std::weak_ptr<Content>(),
+ boost::optional<Frame>(),
+ false
+ );
+
+ DCPVideo dcp_video (
+ player_video,
+ 0,
+ 24,
+ j2k_bandwidth,
+ Resolution::TWO_K
+ );
+
+ auto result = backend.encode ({dcp_video});
+ return result[0].size() * 8L * 24 / 1000000.0f;
+ };
+
+ auto bandwidth = std::vector<int>{ 50, 100, 150, 200, 250 };
+
+ for (auto b: bandwidth) {
+ auto mbps = test(b * 1000000.0f);
+ BOOST_CHECK_CLOSE (mbps, b, 5);
+ }
+}
+
diff --git a/test/wscript b/test/wscript
index ff6895d9a..d039e083e 100644
--- a/test/wscript
+++ b/test/wscript
@@ -40,6 +40,8 @@ def build(bld):
obj.uselib += 'WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE '
if bld.env.TARGET_LINUX:
obj.uselib += 'DL '
+ if bld.env.ENABLE_FASTVIDEO:
+ obj.uselib += ' FASTVIDEO'
obj.use = 'libdcpomatic2'
obj.source = """
4k_test.cc
@@ -53,6 +55,7 @@ def build(bld):
audio_processor_test.cc
audio_processor_delay_test.cc
audio_ring_buffers_test.cc
+ barrier_test.cc
butler_test.cc
cinema_sound_processor_test.cc
client_server_test.cc
@@ -152,6 +155,9 @@ def build(bld):
obj.source += " disk_writer_test.cc"
obj.uselib += "LWEXT4 NANOMSG "
+ if bld.env.ENABLE_FASTVIDEO:
+ obj.source += " fastvideo_test.cc"
+
# Some difference in font rendering between the test machine and others...
# burnt_subtitle_test.cc
# This one doesn't check anything