diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-07-07 18:22:05 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-07-07 18:22:05 +0200 |
| commit | 30c546cb120638cf189aa73ed26d7c6ef751c384 (patch) | |
| tree | 16425a36052331964250327ed2874da32fb73683 | |
| parent | 28c4d55d7e7242c1a414a74751abe29b75e6505f (diff) | |
Use boost::filesystem::path for _gpu_binary_location.
| -rw-r--r-- | src/lib/config.cc | 8 | ||||
| -rw-r--r-- | src/lib/config.h | 6 | ||||
| -rw-r--r-- | src/lib/grok_context.h | 19 | ||||
| -rw-r--r-- | src/lib/grok_messenger.h | 4 | ||||
| -rw-r--r-- | src/wx/gpu_config_panel.cc | 19 |
5 files changed, 36 insertions, 20 deletions
diff --git a/src/lib/config.cc b/src/lib/config.cc index 81b7ea857..410b2a899 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -213,7 +213,7 @@ Config::set_defaults () set_notification_email_to_default (); set_cover_sheet_to_default (); - _gpu_binary_location = ""; + _gpu_binary_location = {}; _enable_gpu = false; _selected_gpu = 0; _gpu_license_server = ""; @@ -642,7 +642,7 @@ try _isdcf_name_part_length = f.optional_number_child<int>("ISDCFNamePartLength").get_value_or(14); _enable_gpu = f.optional_bool_child("EnableGpu").get_value_or(false); - _gpu_binary_location = f.string_child("GpuBinaryLocation"); + _gpu_binary_location = f.optional_string_child("GpuBinaryLocation"); _selected_gpu = f.number_child<int>("SelectedGpu"); _gpu_license_server = f.string_child("GpuLicenseServer"); _gpu_license_port = f.number_child<int>("GpuLicensePort"); @@ -1134,7 +1134,9 @@ Config::write_config () const /* [XML] ISDCFNamePartLength Maximum length of the "name" part of an ISDCF name, which should be 14 according to the standard */ root->add_child("ISDCFNamePartLength")->add_child_text(raw_convert<string>(_isdcf_name_part_length)); - root->add_child("GpuBinaryLocation")->add_child_text(_gpu_binary_location); + if (_gpu_binary_location) { + root->add_child("GpuBinaryLocation")->add_child_text(_gpu_binary_location->string()); + } root->add_child("EnableGpu")->add_child_text((_enable_gpu ? "1" : "0")); root->add_child("SelectedGpu")->add_child_text(raw_convert<string>(_selected_gpu)); root->add_child("GpuLicenseServer")->add_child_text(_gpu_license_server); diff --git a/src/lib/config.h b/src/lib/config.h index ad237c04b..eb5e255a7 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -618,7 +618,7 @@ public: return _allow_smpte_bv20; } - std::string gpu_binary_location() const { + boost::optional<boost::filesystem::path> gpu_binary_location() const { return _gpu_binary_location; } @@ -1223,7 +1223,7 @@ public: maybe_set(_allow_smpte_bv20, allow, ALLOW_SMPTE_BV20); } - void set_gpu_binary_location(std::string location) { + void set_gpu_binary_location(boost::filesystem::path location) { maybe_set(_gpu_binary_location, location); } @@ -1494,7 +1494,7 @@ private: /* GPU */ bool _enable_gpu; - std::string _gpu_binary_location; + boost::optional<boost::filesystem::path> _gpu_binary_location; int _selected_gpu; std::string _gpu_license_server; int _gpu_license_port; diff --git a/src/lib/grok_context.h b/src/lib/grok_context.h index 49f916158..dcc40f237 100644 --- a/src/lib/grok_context.h +++ b/src/lib/grok_context.h @@ -18,20 +18,27 @@ */ + #pragma once + #include "config.h" +#include "dcpomatic_assert.h" #include "dcpomatic_log.h" #include "grok_messenger.h" #include "log.h" #include "writer.h" + class Film; + static std::mutex launchMutex; + namespace grk_plugin { + struct GrokLogger : public MessengerLogger { explicit GrokLogger(const std::string& preamble) @@ -111,7 +118,7 @@ struct DcpomaticContext std::shared_ptr<const Film> film_, Writer& writer_, EventHistory& history_, - const std::string& location_ + const boost::optional<boost::filesystem::path>& location_ ) : film(film_) , writer(writer_) @@ -131,7 +138,7 @@ struct DcpomaticContext std::shared_ptr<const Film> film; Writer& writer; EventHistory& history; - std::string location; + boost::optional<boost::filesystem::path> location; uint32_t width; uint32_t height; }; @@ -177,11 +184,12 @@ public: }; if (Config::instance()->enable_gpu()) { - boost::filesystem::path folder(_dcpomatic_context.location); + DCPOMATIC_ASSERT(_dcpomatic_context.location); + boost::filesystem::path folder(*_dcpomatic_context.location); boost::filesystem::path binaryPath = folder / "grk_compress"; if (!boost::filesystem::exists(binaryPath)) { get_messenger_logger()->error("Invalid binary location %s", - _dcpomatic_context.location.c_str()); + _dcpomatic_context.location->c_str()); return; } auto proc = [this](const std::string& str) { @@ -251,7 +259,8 @@ public: auto s = dcpv.get_size(); _dcpomatic_context.set_dimensions(s.width, s.height); auto config = Config::instance(); - _messenger->launch_grok(_dcpomatic_context.location, + DCPOMATIC_ASSERT(_dcpomatic_context.location); + _messenger->launch_grok(*_dcpomatic_context.location, _dcpomatic_context.width, _dcpomatic_context.width, _dcpomatic_context.height, 3, 12, device, diff --git a/src/lib/grok_messenger.h b/src/lib/grok_messenger.h index 873233da4..70dc7ccd9 100644 --- a/src/lib/grok_messenger.h +++ b/src/lib/grok_messenger.h @@ -699,7 +699,7 @@ struct Messenger return (pid != -1 && kill(pid, SIGKILL) != -1); } - void launch_grok(const std::string& dir, uint32_t width, uint32_t stride, + void launch_grok(const boost::filesystem::path& dir, uint32_t width, uint32_t stride, uint32_t height, uint32_t samplesPerPixel, uint32_t depth, int device, bool is4K, uint32_t fps, uint32_t bandwidth, const std::string server, uint32_t port, @@ -811,7 +811,7 @@ protected: std::condition_variable clientInitializedCondition_; private: - void launch(const std::string& cmd, const std::string& dir) + void launch(const std::string& cmd, const boost::filesystem::path& dir) { // Change the working directory if (!dir.empty()) { diff --git a/src/wx/gpu_config_panel.cc b/src/wx/gpu_config_panel.cc index aefac801c..b746d2271 100644 --- a/src/wx/gpu_config_panel.cc +++ b/src/wx/gpu_config_panel.cc @@ -11,13 +11,13 @@ static std::vector<std::string> -get_gpu_names(std::string binary, std::string filename) +get_gpu_names(boost::filesystem::path binary, boost::filesystem::path filename) { // Execute the GPU listing program and redirect its output to a file - std::system((binary + " > " + filename).c_str()); + std::system((binary.string() + " > " + filename.string()).c_str()); std::vector<std::string> gpu_names; - std::ifstream file(filename); + std::ifstream file(filename.string()); if (file.is_open()) { std::string line; while (std::getline(file, line)) { @@ -50,9 +50,10 @@ public: void update() { - auto cfg = Config::instance(); - auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister"; - auto lister_file = cfg->gpu_binary_location() + "/" + "gpus.txt"; + auto binary = Config::instance()->gpu_binary_location(); + DCPOMATIC_ASSERT(binary); + auto lister_binary = *binary / "gpu_lister"; + auto lister_file = *binary / "gpus.txt"; if (boost::filesystem::exists(lister_binary)) { auto gpu_names = get_gpu_names(lister_binary, lister_file); @@ -167,7 +168,11 @@ void GPUPage::config_changed() auto config = Config::instance(); checked_set(_enable_gpu, config->enable_gpu()); - _binary_location->SetPath(config->gpu_binary_location()); + if (auto binary = config->gpu_binary_location()) { + _binary_location->SetPath(std_to_wx(binary->string())); + } else { + _binary_location->SetPath(wxT("")); + } _gpu_list_control->update(); _gpu_list_control->set_selection(config->selected_gpu()); checked_set(_server, config->gpu_license_server()); |
