From 729951e629c0d98d6f1da058029114341dae6e39 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 24 Sep 2023 17:23:57 +0200 Subject: [PATCH] Use boost::filesystem::path for gpu_binary_location(). --- src/lib/config.cc | 2 +- src/lib/config.h | 13 ++++++-- src/lib/grok/context.h | 55 +++++++++++++++++++++------------- src/lib/grok/messenger.h | 28 ++++++++++++----- src/wx/grok/gpu_config_panel.h | 12 ++++---- 5 files changed, 71 insertions(+), 39 deletions(-) diff --git a/src/lib/config.cc b/src/lib/config.cc index bbb3eef27..a4ee4ad99 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -1133,7 +1133,7 @@ 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(_isdcf_name_part_length)); - root->add_child("GpuBinaryLocation")->add_child_text (_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 (_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 0c9affbb6..9aba9e9d2 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::filesystem::path gpu_binary_location() const { return _gpu_binary_location; } @@ -1220,24 +1220,31 @@ public: void set_allow_smpte_bv20(bool allow) { 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); } + void set_enable_gpu (bool enable) { maybe_set (_enable_gpu, enable); } + void set_selected_gpu (int selected) { maybe_set (_selected_gpu, selected); } + void set_gpu_license_server (std::string s) { maybe_set (_gpu_license_server, s); } + void set_gpu_license_port (int p) { maybe_set (_gpu_license_port, p); } + void set_gpu_license (std::string p) { maybe_set (_gpu_license, p); } + void set_isdcf_name_part_length(int length) { maybe_set(_isdcf_name_part_length, length, ISDCF_NAME_PART_LENGTH); } @@ -1485,7 +1492,7 @@ private: /* GPU */ bool _enable_gpu; - std::string _gpu_binary_location; + 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 72e62c4fa..3e4144d07 100644 --- a/src/lib/grok/context.h +++ b/src/lib/grok/context.h @@ -74,12 +74,22 @@ struct FrameProxy { }; struct DcpomaticContext { - DcpomaticContext(std::shared_ptr film, Writer& writer, - EventHistory &history, const std::string &location) : - film_(film), writer_(writer), - history_(history), location_(location), - width_(0), height_(0) - {} + DcpomaticContext( + std::shared_ptr film, + Writer& writer, + EventHistory& history, + boost::filesystem::path const& location + ) + : film_(film) + , writer_(writer) + , history_(history) + , _location(location) + , width_(0) + , height_(0) + { + + } + void setDimensions(uint32_t w, uint32_t h) { width_ = w; height_ = h; @@ -87,7 +97,7 @@ struct DcpomaticContext { std::shared_ptr film_; Writer& writer_; EventHistory &history_; - std::string location_; + boost::filesystem::path _location; uint32_t width_; uint32_t height_; }; @@ -100,12 +110,13 @@ public: launched_(false) { if (Config::instance()->enable_gpu ()) { - boost::filesystem::path folder(dcpomaticContext_.location_); + boost::filesystem::path folder(dcpomaticContext_._location); boost::filesystem::path binaryPath = folder / "grk_compress"; if (!boost::filesystem::exists(binaryPath)) { - getMessengerLogger()->error("Invalid binary location %s", - dcpomaticContext_.location_.c_str()); - return; + getMessengerLogger()->error( + "Invalid binary location %s", dcpomaticContext_._location.c_str() + ); + return; } auto proc = [this](const std::string& str) { try { @@ -166,16 +177,18 @@ public: auto s = dcpv.get_size(); dcpomaticContext_.setDimensions(s.width, s.height); auto config = Config::instance(); - messenger_->launchGrok(dcpomaticContext_.location_, - dcpomaticContext_.width_,dcpomaticContext_.width_, - dcpomaticContext_.height_, - 3, 12, device, - dcpomaticContext_.film_->resolution() == Resolution::FOUR_K, - dcpomaticContext_.film_->video_frame_rate(), - dcpomaticContext_.film_->j2k_bandwidth(), - config->gpu_license_server(), - config->gpu_license_port(), - config->gpu_license()); + messenger_->launchGrok( + dcpomaticContext_._location, + dcpomaticContext_.width_,dcpomaticContext_.width_, + dcpomaticContext_.height_, + 3, 12, device, + dcpomaticContext_.film_->resolution() == Resolution::FOUR_K, + dcpomaticContext_.film_->video_frame_rate(), + dcpomaticContext_.film_->j2k_bandwidth(), + config->gpu_license_server(), + config->gpu_license_port(), + config->gpu_license() + ); } launched_ = messenger_->waitForClientInit(); diff --git a/src/lib/grok/messenger.h b/src/lib/grok/messenger.h index 008e58dd2..5cb21a1cd 100644 --- a/src/lib/grok/messenger.h +++ b/src/lib/grok/messenger.h @@ -542,11 +542,22 @@ struct Messenger sendQueue.push(oss.str()); } - void launchGrok(const std::string &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, - const std::string license) + + void launchGrok( + boost::filesystem::path const& 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, + const std::string license + ) { std::unique_lock lk(shutdownMutex_); @@ -640,13 +651,14 @@ struct Messenger protected: std::condition_variable clientInitializedCondition_; private: - void launch(const std::string &cmd, const std::string &dir) + void launch(std::string const& cmd, boost::filesystem::path const& dir) { // Change the working directory if(!dir.empty()) { - if(chdir(dir.c_str()) != 0) - { + boost::system::error_code ec; + boost::filesystem::current_path(dir, ec); + if (ec) { getMessengerLogger()->error("Error: failed to change the working directory"); return; } diff --git a/src/wx/grok/gpu_config_panel.h b/src/wx/grok/gpu_config_panel.h index 88163ae0c..a0f2a1f7f 100644 --- a/src/wx/grok/gpu_config_panel.h +++ b/src/wx/grok/gpu_config_panel.h @@ -21,15 +21,15 @@ #pragma once -static std::vector get_gpu_names(std::string binary, std::string filename) +static std::vector get_gpu_names(boost::filesystem::path binary, boost::filesystem::path filename) { // Execute the GPU listing program and redirect its output to a file - if (std::system((binary + " > " + filename).c_str()) < 0) { + if (std::system((binary.string() + " > " + filename.string()).c_str()) < 0) { return {}; } std::vector gpu_names; - std::ifstream file(filename); + std::ifstream file(filename.c_str()); if (file.is_open()) { std::string line; @@ -57,8 +57,8 @@ public: } void update(void) { auto cfg = Config::instance(); - auto lister_binary = cfg->gpu_binary_location() + "/" + "gpu_lister"; - auto lister_file = cfg->gpu_binary_location () + "/" + "gpus.txt"; + auto lister_binary = cfg->gpu_binary_location() / "gpu_lister"; + auto lister_file = cfg->gpu_binary_location () / "gpus.txt"; if (boost::filesystem::exists(lister_binary)) { auto gpu_names = get_gpu_names(lister_binary, lister_file); @@ -160,7 +160,7 @@ private: auto config = Config::instance (); checked_set (_enable_gpu, config->enable_gpu()); - _binary_location->SetPath(config->gpu_binary_location ()); + _binary_location->SetPath(std_to_wx(config->gpu_binary_location().string())); _gpu_list_control->update(); _gpu_list_control->setSelection(config->selected_gpu()); checked_set (_server, config->gpu_license_server()); -- 2.30.2