2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "poznan_encoder.h"
21 #include "exceptions.h"
27 using boost::shared_ptr;
29 PoznanEncoder::PoznanEncoder ()
31 void* config = open_library ("config");
32 void* preprocessing = open_library ("preprocessing");
33 void* dwt = open_library ("dwt");
34 void* tier1 = open_library ("tier1");
35 void* gpu_coeff_coder = open_library ("gpu_coeff_coder");
36 void* tier2 = open_library ("tier2");
38 _init_device = (void (*)(type_parameters *)) dlsym (config, "init_device");
39 _mct = (void (*)(type_image *, type_parameters *)) dlsym (preprocessing, "mct");
40 _fwt = (void (*)(type_tile *)) dlsym (dwt, "fwt");
41 _quantize_tile = (void (*)(type_tile *)) dlsym (tier1, "quantize_tile");
42 _encode_tile = (void (*)(type_tile *)) dlsym (gpu_coeff_coder, "encode_tile");
43 _write_codestream = (void (*)(type_image *)) dlsym (tier2, "write_codestream");
45 if (!_init_device || !_mct || !_fwt || !_quantize_tile || !_encode_tile || !_write_codestream) {
46 throw JPEG2000EncoderUnavailableException (name(), "missing symbol");
51 PoznanEncoder::open_library (string library_name)
53 /* XXX: need cross-platform implementation of dlopen etc. */
55 library_name = "libdcpomatic-" + library_name + ".so";
56 void* lib = dlopen (library_name.c_str(), RTLD_LAZY | RTLD_GLOBAL);
58 throw JPEG2000EncoderUnavailableException (name(), "could not find " + library_name);
64 PoznanEncoder::parameters_changed ()
66 /* One tile which covers entire image */
67 _param.param_tile_w = -1;
68 _param.param_tile_h = -1;
70 /* Wavelet decomposition levels */
71 _param.param_tile_comp_dlvls = _resolution.get() == RESOLUTION_2K ? 5 : 6;
73 /* Power of 2 for maximum codeblock size */
74 _param.param_cblk_exp_w = 5;
75 _param.param_cblk_exp_h = 5;
77 /* DWT 9/7 transform */
78 _param.param_wavelet_type = 1;
81 _param.param_use_mct = 1;
83 /* Device to run on */
84 _param.param_device = 0;
86 /* Target file size */
87 _param.param_target_size = (_bandwidth.get() / _frame_rate.get()) / 8;
89 _param.param_target_size /= 2;
92 /* Bits per pixel per component */
95 /* Don't know about these: use the defaults */
96 _param.param_use_part2_mct = 0;
97 _param.param_mct_compression_method = 0;
98 _param.param_mct_klt_iterations = 10000;
99 _param.param_mct_klt_border_eigenvalue = 0.000001;
100 _param.param_mct_klt_err = 1.0e-7;
102 _init_device (&_param);
106 PoznanEncoder::name () const
108 return _("CUDA (GPU) encoder (Poznan Supercomputing and Networking Center)");
111 shared_ptr<EncodedData>
112 PoznanEncoder::do_encode (shared_ptr<const dcp::XYZImage> input, dcp::NoteHandler note_handler)
115 _mct (&img, &_param);
116 for (size_t i = 0; i < img.num_tiles; ++i) {
117 type_tile* tile = &(img.tile[i]);
119 _quantize_tile (tile);
122 _write_codestream (&img);
123 return shared_ptr<EncodedData> ();