diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-09-28 23:39:30 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-09-30 00:19:51 +0200 |
| commit | 19a0537345d9c39962f70420299a07293fe6a975 (patch) | |
| tree | fbb80397f84647d5e251b9905b102a2d715969fe /src/lib | |
| parent | d78552513e17250cc9b6c5327e735ea05fa928d5 (diff) | |
Allow configuration of Grok or nvjpeg2k GPU encoding.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/config.cc | 33 | ||||
| -rw-r--r-- | src/lib/config.h | 16 | ||||
| -rw-r--r-- | src/lib/encode_cli.cc | 14 | ||||
| -rw-r--r-- | src/lib/grok/context.h | 5 | ||||
| -rw-r--r-- | src/lib/j2k_encoder.cc | 18 |
5 files changed, 58 insertions, 28 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index af97c7af7..12046d3c2 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -240,6 +240,7 @@ Config::set_defaults() #ifdef DCPOMATIC_GROK _grok = {}; #endif + _gpu_type = GPUType::NONE; _main_divider_sash_position = {}; _main_content_divider_sash_position = {}; @@ -679,9 +680,25 @@ try #ifdef DCPOMATIC_GROK if (auto grok = f.optional_node_child("Grok")) { _grok = Grok(grok); + /* We used to use an <Enable> tag in the <Grok> tag, but now we look at + * the _gpu_type. + */ + if (grok->optional_bool_child("Enable").get_value_or(false)) { + _gpu_type = GPUType::GROK; + } } #endif + if (auto gpu_type = f.optional_string_child("GPUType")) { + if (*gpu_type == "grok") { + _gpu_type = GPUType::GROK; + } else if (*gpu_type == "nvjpeg2k") { + _gpu_type = GPUType::NVJPEG2K; + } else { + _gpu_type = GPUType::NONE; + } + } + _export.read(f.optional_node_child("Export")); } catch (...) { @@ -1168,6 +1185,18 @@ Config::write_config() const #ifdef DCPOMATIC_GROK _grok.as_xml(cxml::add_child(root, "Grok")); #endif + /* [XML] GPUType none for no GPU accleration, grok to use Grok, nvjpeg2k to use the NVIDIA nvjpeg2k library */ + switch (_gpu_type) { + case GPUType::NONE: + cxml::add_text_child(root, "GPUType", "none"); + break; + case GPUType::GROK: + cxml::add_text_child(root, "GPUType", "grok"); + break; + case GPUType::NVJPEG2K: + cxml::add_text_child(root, "GPUType", "nvjpeg2k"); + break; + } _export.write(cxml::add_child(root, "Export")); @@ -1764,8 +1793,7 @@ Config::Grok::Grok() Config::Grok::Grok(cxml::ConstNodePtr node) - : enable(node->bool_child("Enable")) - , binary_location(node->string_child("BinaryLocation")) + : binary_location(node->string_child("BinaryLocation")) , selected(node->number_child<int>("Selected")) , licence_server(node->string_child("LicenceServer")) , licence(node->string_child("Licence")) @@ -1780,7 +1808,6 @@ void Config::Grok::as_xml(xmlpp::Element* node) const { node->add_child("BinaryLocation")->add_child_text(binary_location.string()); - node->add_child("Enable")->add_child_text((enable ? "1" : "0")); node->add_child("Selected")->add_child_text(fmt::to_string(selected)); node->add_child("LicenceServer")->add_child_text(licence_server); node->add_child("Licence")->add_child_text(licence); diff --git a/src/lib/config.h b/src/lib/config.h index d8ff70db8..4deaf7eb6 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -665,7 +665,6 @@ public: void as_xml(xmlpp::Element* node) const; - bool enable = false; boost::filesystem::path binary_location; int selected = 0; std::string licence_server; @@ -677,6 +676,16 @@ public: } #endif + enum class GPUType { + NONE, + GROK, + NVJPEG2K + }; + + GPUType gpu_type() const { + return _gpu_type; + } + int isdcf_name_part_length() const { return _isdcf_name_part_length; } @@ -1253,6 +1262,10 @@ public: void set_grok(Grok const& grok); #endif + void set_gpu_type(GPUType type) { + maybe_set(_gpu_type, type); + } + void set_isdcf_name_part_length(int length) { maybe_set(_isdcf_name_part_length, length, ISDCF_NAME_PART_LENGTH); } @@ -1526,6 +1539,7 @@ private: #ifdef DCPOMATIC_GROK Grok _grok; #endif + GPUType _gpu_type; ExportConfig _export; diff --git a/src/lib/encode_cli.cc b/src/lib/encode_cli.cc index cff6f3724..91e399439 100644 --- a/src/lib/encode_cli.cc +++ b/src/lib/encode_cli.cc @@ -422,17 +422,15 @@ encode_cli(int argc, char* argv[], function<void (string)> out, function<void () #ifdef DCPOMATIC_GROK config_params.push_back( - {"grok-enable", "1 to enable the Grok encoder, 0 to disable it", + {"gpu-type", "\"grok\" to enable the Grok encoder, \"none\" to disable it", [](Config* config, string value) -> optional<string> { - auto grok = config->grok(); - if (value == "1") { - grok.enable = true; - } else if (value == "0") { - grok.enable = false; + if (value == "grok") { + config->set_gpu_type(Config::GPUType::GROK); + } else if (value == "none") { + config->set_gpu_type(Config::GPUType::NONE); } else { - return fmt::format("Invalid value {} for grok-enable (use 1 to enable, 0 to disable)", value); + return fmt::format("Invalid value {} for gpu-type (use \"grok\" to enable the Grok encoder, \"none\" to disable it)", value); } - config->set_grok(grok); return {}; }}); config_params.push_back( diff --git a/src/lib/grok/context.h b/src/lib/grok/context.h index b31867cf6..bd1996b1f 100644 --- a/src/lib/grok/context.h +++ b/src/lib/grok/context.h @@ -99,11 +99,6 @@ public: explicit GrokContext(DcpomaticContext* dcpomatic_context) : _dcpomatic_context(dcpomatic_context) { - auto grok = Config::instance()->grok(); - if (!grok.enable) { - return; - } - boost::filesystem::path folder(_dcpomatic_context->location); boost::filesystem::path binary_path = folder / "grk_compress"; if (!boost::filesystem::exists(binary_path)) { diff --git a/src/lib/j2k_encoder.cc b/src/lib/j2k_encoder.cc index 441e91827..07e4012b1 100644 --- a/src/lib/j2k_encoder.cc +++ b/src/lib/j2k_encoder.cc @@ -97,9 +97,9 @@ J2KEncoder::J2KEncoder(shared_ptr<const Film> film, Writer& writer) #endif { #ifdef DCPOMATIC_GROK - auto grok = Config::instance()->grok(); - _dcpomatic_context = new grk_plugin::DcpomaticContext(film, writer, _history, grok.binary_location); - if (grok.enable) { + auto config = Config::instance(); + _dcpomatic_context = new grk_plugin::DcpomaticContext(film, writer, _history, config->grok().binary_location); + if (config->gpu_type() == Config::GPUType::GROK) { _context = new grk_plugin::GrokContext(_dcpomatic_context); } #endif @@ -133,11 +133,7 @@ void J2KEncoder::servers_list_changed() { auto config = Config::instance(); -#ifdef DCPOMATIC_GROK - auto const grok_enable = config->grok().enable; -#else - auto const grok_enable = false; -#endif + auto const grok_enable = config->gpu_type() == Config::GPUType::GROK; auto const cpu = (grok_enable || config->only_servers_encode()) ? 0 : config->master_encoding_threads(); auto const gpu = grok_enable ? config->master_encoding_threads() : 0; @@ -161,7 +157,7 @@ void J2KEncoder::pause() { #ifdef DCPOMATIC_GROK - if (!Config::instance()->grok().enable) { + if (Config::instance()->gpu_type() != Config::GPUType::GROK) { return; } return; @@ -182,7 +178,7 @@ J2KEncoder::pause() void J2KEncoder::resume() { #ifdef DCPOMATIC_GROK - if (!Config::instance()->grok().enable) { + if (Config::instance()->gpu_type() != Config::GPUType::GROK) { return; } @@ -225,7 +221,7 @@ J2KEncoder::end() */ for (auto & i: _queue) { #ifdef DCPOMATIC_GROK - if (Config::instance()->grok().enable) { + if (Config::instance()->gpu_type() == Config::GPUType::GROK) { if (!_context->scheduleCompress(i)){ LOG_GENERAL (N_("[{}] J2KEncoder thread pushes frame {} back onto queue after failure"), thread_id(), i.index()); // handle error |
