summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-02-27 00:54:30 +0000
committerCarl Hetherington <cth@carlh.net>2020-08-23 20:33:37 +0200
commit10a0c758dc59b1fb9e2f961485240e80f118eb9d (patch)
tree4d9b975c3882c9627a53d197e6d0413079023d7d
parent1d0b111ac9692dedfd4a23c268f362e522105bcf (diff)
Basics of poznan library integration; colour manipulations are wrong.
-rw-r--r--src/lib/dcp_video.h13
-rw-r--r--src/lib/gpu_j2k_encode_worker.cc71
-rw-r--r--src/lib/wscript2
-rw-r--r--src/tools/wscript2
-rw-r--r--test/gpu_test.cc47
-rw-r--r--test/wscript1
-rw-r--r--wscript3
7 files changed, 135 insertions, 4 deletions
diff --git a/src/lib/dcp_video.h b/src/lib/dcp_video.h
index 81ddc4470..561855cec 100644
--- a/src/lib/dcp_video.h
+++ b/src/lib/dcp_video.h
@@ -45,9 +45,22 @@ public:
DCPVideo (boost::shared_ptr<const PlayerVideo>, int, int, int, Resolution);
DCPVideo (boost::shared_ptr<const PlayerVideo>, cxml::ConstNodePtr);
+ /* XXX: these two should be done in cpu_j2k_encode_worker and remote_j2k_encode_worker */
dcp::Data encode_locally ();
dcp::Data encode_remotely (EncodeServerDescription, int timeout = 30);
+ boost::shared_ptr<const PlayerVideo> frame () const {
+ return _frame;
+ }
+
+ int j2k_bandwidth () const {
+ return _j2k_bandwidth;
+ }
+
+ int frames_per_second () const {
+ return _frames_per_second;
+ }
+
int index () const {
return _index;
}
diff --git a/src/lib/gpu_j2k_encode_worker.cc b/src/lib/gpu_j2k_encode_worker.cc
index 4c38aca27..a875c23d7 100644
--- a/src/lib/gpu_j2k_encode_worker.cc
+++ b/src/lib/gpu_j2k_encode_worker.cc
@@ -22,6 +22,19 @@
#include "dcp_video.h"
#include "cross.h"
#include "dcpomatic_log.h"
+#include <dcp/openjpeg_image.h>
+extern "C" {
+#include <poznanj2k/config/init_device.h>
+#include <poznanj2k/types/image_types.h>
+#include <poznanj2k/types/image.h>
+#include <poznanj2k/preprocessing/mct.h>
+#include <poznanj2k/dwt/dwt.h>
+#include <poznanj2k/tier1/quantizer.h>
+#include <poznanj2k/tier1/coeff_coder/gpu_coder.h>
+#include <poznanj2k/tier2/codestream.h>
+#include <poznanj2k/misc/memory_management.cuh>
+#include <cuda_runtime_api.h>
+}
#include "i18n.h"
@@ -31,14 +44,68 @@ using boost::shared_ptr;
GPUJ2KEncodeWorker::GPUJ2KEncodeWorker ()
{
- /* XXX: setup poznan library */
+ init_device (0);
}
optional<Data>
GPUJ2KEncodeWorker::encode (shared_ptr<DCPVideo> vf)
{
- optional<Data> encoded;
+ shared_ptr<dcp::OpenJPEGImage> image = DCPVideo::convert_to_xyz(vf->frame(), boost::bind(&Log::dcp_log, dcpomatic_log.get(), _1, _2));
+ int const width = image->size().width;
+ int const height = image->size().height;
+
+ type_image img;
+ img.mct_compression_method = 0;
+ img.width = width;
+ img.height = height;
+ img.num_components = 3;
+ img.depth = 36;
+ img.sign = UNSIGNED;
+ /* XXX: 6 for 4K? */
+ img.num_dlvls = 5;
+ img.wavelet_type = 1;
+ img.num_tiles = 1;
+ img.tile_w = width;
+ img.tile_h = height;
+ img.coding_style = CODING_STYLE_PRECINCTS_DEFINED;
+ img.prog_order = COMP_POS_RES_LY_PROG;
+ img.num_layers = 1;
+ img.num_range_bits = 12;
+ img.use_mct = 1;
+ img.use_part2_mct = 0;
+
+ set_coding_parameters (&img, (vf->j2k_bandwidth() / 8) / vf->frames_per_second());
+
+ init_tiles (&img, width, height, 5, 5);
+ type_tile* tile = &(img.tile[0]);
+
+ // XXX: it's a big shame about this int -> float conversion
+ for (int i = 0; i < 3; ++i) {
+ type_tile_comp* c = &tile->tile_comp[i];
+ c->tile_comp_no = i;
+ int const pixels = c->width * c->height;
+ for (int j = 0; j < pixels; ++j) {
+ c->img_data[j] = float (image->data(i)[j]);
+ }
+ cuda_memcpy_htd (c->img_data, c->img_data_d, pixels * sizeof(type_data));
+ }
+
+ mct (&img, 10000, 0.000001, 1.0e-7);
+ fwt (tile);
+ quantize_tile (tile);
+ encode_tile (tile);
+
+ type_buffer buffer;
+ init_buffer (&buffer);
+ encode_codestream (&buffer, &img);
+ cudaThreadSynchronize ();
+
+ image_destroy(&img);
+ // XXX: remove this memcpy
+ dcp::Data encoded (buffer.bytes_count);
+ memcpy (encoded.data().get(), buffer.data, buffer.bytes_count);
+ free (buffer.data);
return encoded;
}
diff --git a/src/lib/wscript b/src/lib/wscript
index 5d417ed4a..10e9fccc5 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -205,7 +205,7 @@ def build(bld):
AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE
BOOST_FILESYSTEM BOOST_THREAD BOOST_DATETIME BOOST_SIGNALS2 BOOST_REGEX
SAMPLERATE POSTPROC TIFF SSH DCP CXML GLIB LZMA XML++
- CURL ZIP FONTCONFIG PANGOMM CAIROMM XMLSEC SUB ICU NETTLE PNG LEQM_NRT
+ CURL ZIP FONTCONFIG PANGOMM CAIROMM XMLSEC SUB ICU NETTLE PNG LEQM_NRT POZNANJ2K
"""
if bld.env.TARGET_OSX:
diff --git a/src/tools/wscript b/src/tools/wscript
index 7eeeecddf..b0ce73a29 100644
--- a/src/tools/wscript
+++ b/src/tools/wscript
@@ -30,7 +30,7 @@ def configure(conf):
def build(bld):
uselib = 'BOOST_THREAD BOOST_DATETIME DCP XMLSEC CXML XMLPP AVFORMAT AVFILTER AVCODEC '
uselib += 'AVUTIL SWSCALE SWRESAMPLE POSTPROC CURL BOOST_FILESYSTEM SSH ZIP CAIROMM FONTCONFIG PANGOMM SUB '
- uselib += 'SNDFILE SAMPLERATE BOOST_REGEX ICU NETTLE RTAUDIO PNG LEQM_NRT '
+ uselib += 'SNDFILE SAMPLERATE BOOST_REGEX ICU NETTLE RTAUDIO PNG LEQM_NRT POZNANJ2K '
if bld.env.ENABLE_DISK:
if bld.env.TARGET_LINUX:
diff --git a/test/gpu_test.cc b/test/gpu_test.cc
new file mode 100644
index 000000000..26c5821e5
--- /dev/null
+++ b/test/gpu_test.cc
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2019 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/gpu_j2k_encode_worker.h"
+#include "lib/ffmpeg_image_proxy.h"
+#include "lib/player_video.h"
+#include "lib/dcp_video.h"
+#include "test.h"
+#include <boost/test/unit_test.hpp>
+
+using boost::shared_ptr;
+using boost::optional;
+using boost::weak_ptr;
+
+BOOST_AUTO_TEST_CASE (gpu_test)
+{
+ GPUJ2KEncodeWorker w;
+ shared_ptr<ImageProxy> ip (new FFmpegImageProxy(private_data / "card.png"));
+ shared_ptr<PlayerVideo> pv (
+ new PlayerVideo(
+ ip, Crop(), optional<double>(), dcp::Size(1998, 1080), dcp::Size(1998, 1080),
+ EYES_BOTH, PART_WHOLE, optional<ColourConversion>(), weak_ptr<Content>(), optional<Frame>()
+ )
+ );
+ shared_ptr<DCPVideo> vf (new DCPVideo(pv, 0, 24, 100000000, RESOLUTION_2K));
+ optional<dcp::Data> encoded = w.encode (vf);
+ FILE* f = fopen("titz.j2k", "wb");
+ fwrite(encoded->data().get(), encoded->size(), 1, f);
+ fclose(f);
+}
diff --git a/test/wscript b/test/wscript
index 0f90001f6..9fa23d104 100644
--- a/test/wscript
+++ b/test/wscript
@@ -85,6 +85,7 @@ def build(bld):
film_metadata_test.cc
frame_interval_checker_test.cc
frame_rate_test.cc
+ gpu_test.cc
image_content_fade_test.cc
image_filename_sorter_test.cc
image_test.cc
diff --git a/wscript b/wscript
index f9aa78439..fa5d43393 100644
--- a/wscript
+++ b/wscript
@@ -565,6 +565,9 @@ def configure(conf):
if v >= 0x022D1F:
conf.env.append_value('CXXFLAGS', '-std=c++11')
+ # poznan
+ conf.check_cfg(package="libpoznanj2k", args='--cflags --libs', uselib_store='POZNANJ2K', mandatory=True)
+
# Other stuff
conf.find_program('msgfmt', var='MSGFMT')