Use boost::filesystem::path for gpu_binary_location().
authorCarl Hetherington <cth@carlh.net>
Sun, 24 Sep 2023 15:23:57 +0000 (17:23 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 16 Dec 2023 01:07:38 +0000 (02:07 +0100)
src/lib/config.cc
src/lib/config.h
src/lib/grok/context.h
src/lib/grok/messenger.h
src/wx/grok/gpu_config_panel.h

index 8ae511361d511ea3ff3c624639f75acc58c1eb5e..4eb7b47f745b6464e714fbff6d5dfa0cc6e9a8e5 100644 (file)
@@ -1134,7 +1134,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<string>(_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<string> (_selected_gpu));
        root->add_child("GpuLicenseServer")->add_child_text (_gpu_license_server);
index 0c9affbb6b1b3ba9e40c096fce07926ea55e0e7a..9aba9e9d2fb8d444d9fbf53be634a65b148ec839 100644 (file)
@@ -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;
index 72e62c4fad592d3afd938520a3e099f44d8fa69b..3e4144d0778099da8313250b74a0bb78a087a930 100644 (file)
@@ -74,12 +74,22 @@ struct FrameProxy {
 };
 
 struct DcpomaticContext {
-       DcpomaticContext(std::shared_ptr<const Film> 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<const Film> 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<const Film> 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();
 
index 008e58dd27c76d6eec29aeb8d46ded5ae5073817..5cb21a1cd800fff1ad33b871ba8b6ddad1552852 100644 (file)
@@ -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<std::mutex> 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;
                        }
index 88163ae0ccc0218ecfab0b4d5d7fa2ec97cfe5a0..a0f2a1f7fdfd8ae99f6978c37d51ca478c260cb3 100644 (file)
 
 #pragma once
 
-static std::vector<std::string> get_gpu_names(std::string binary, std::string filename)
+static std::vector<std::string> 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<std::string> 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());