Create a single DcpomaticContext for all GrokContexts, rather than copying them.
authorCarl Hetherington <cth@carlh.net>
Tue, 26 Sep 2023 11:29:59 +0000 (13:29 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 16 Oct 2023 15:57:18 +0000 (17:57 +0200)
I think this makes sense, and also allows us to forward-declare the
contexts in a forthcoming commit.

src/lib/grok/context.h
src/lib/j2k_encoder.cc
src/lib/j2k_encoder.h

index 1aac6f177ed15f724d5c76dd530ecb374f4f88a9..96477d597deac87c2961fa322ba233a0056c9d4c 100644 (file)
@@ -106,17 +106,17 @@ struct DcpomaticContext {
 class GrokContext
 {
 public:
-       explicit GrokContext(DcpomaticContext const& dcpomatic_context)
+       explicit GrokContext(DcpomaticContext* dcpomatic_context)
                : _dcpomatic_context(dcpomatic_context)
                , messenger_(nullptr)
                , launched_(false)
        {
                if (Config::instance()->enable_gpu ())  {
-                   boost::filesystem::path folder(_dcpomatic_context._location);
+                   boost::filesystem::path folder(_dcpomatic_context->_location);
                    boost::filesystem::path binaryPath = folder / "grk_compress";
                    if (!boost::filesystem::exists(binaryPath)) {
                            getMessengerLogger()->error(
-                                   "Invalid binary location %s", _dcpomatic_context._location.c_str()
+                                   "Invalid binary location %s", _dcpomatic_context->_location.c_str()
                                    );
                            return;
                    }
@@ -134,7 +134,7 @@ public:
                                                                [this](FrameProxy srcFrame, uint8_t* compressed, uint32_t compressedFrameLength)
                                                {
                                                        auto compressed_data = std::make_shared<dcp::ArrayData>(compressed, compressedFrameLength);
-                                                       _dcpomatic_context.writer_.write(compressed_data, srcFrame.index(), srcFrame.eyes());
+                                                       _dcpomatic_context->writer_.write(compressed_data, srcFrame.index(), srcFrame.eyes());
                                                        frame_done ();
                                                };
                                                int const minimum_size = 16384;
@@ -147,7 +147,7 @@ public:
                                                        }
 
                                                        auto encoded = std::make_shared<dcp::ArrayData>(fp->vf.encode_locally());
-                                                       _dcpomatic_context.writer_.write(encoded, fp->vf.index(), fp->vf.eyes());
+                                                       _dcpomatic_context->writer_.write(encoded, fp->vf.index(), fp->vf.eyes());
                                                        frame_done ();
                                                }
                                        }
@@ -177,16 +177,16 @@ public:
                        return true;
                if (MessengerInit::firstLaunch(true)) {
                        auto s = dcpv.get_size();
-                       _dcpomatic_context.setDimensions(s.width, s.height);
+                       _dcpomatic_context->setDimensions(s.width, s.height);
                        auto config = Config::instance();
                        messenger_->launchGrok(
-                               _dcpomatic_context._location,
-                               _dcpomatic_context.width_,_dcpomatic_context.width_,
-                               _dcpomatic_context.height_,
+                               _dcpomatic_context->_location,
+                               _dcpomatic_context->width_,_dcpomatic_context->width_,
+                               _dcpomatic_context->height_,
                                3, 12, device,
-                               _dcpomatic_context.film_->resolution() == Resolution::FOUR_K,
-                               _dcpomatic_context.film_->video_frame_rate(),
-                               _dcpomatic_context.film_->j2k_bandwidth(),
+                               _dcpomatic_context->film_->resolution() == Resolution::FOUR_K,
+                               _dcpomatic_context->film_->video_frame_rate(),
+                               _dcpomatic_context->film_->j2k_bandwidth(),
                                config->gpu_license_server(),
                                config->gpu_license_port(),
                                config->gpu_license()
@@ -220,10 +220,10 @@ public:
                messenger_ = nullptr;
        }
        void frame_done () {
-               _dcpomatic_context.history_.event();
+               _dcpomatic_context->history_.event();
        }
 private:
-       DcpomaticContext _dcpomatic_context;
+       DcpomaticContext* _dcpomatic_context;
        ScheduledMessenger<FrameProxy> *messenger_;
        bool launched_;
 };
index 22f2ea6d7268a2ef92155b353d8dd51142128737..fe63deacdf96b5ad59d187145a5ec2e44e82b723 100644 (file)
@@ -68,7 +68,7 @@ J2KEncoder::J2KEncoder(shared_ptr<const Film> film, Writer& writer)
        , _history (200)
        , _writer (writer)
 #ifdef DCPOMATIC_GROK
-       , _dcpomatic_context(film, writer, _history, Config::instance()->gpu_binary_location())
+       , _dcpomatic_context(new grk_plugin::DcpomaticContext(film, writer, _history, Config::instance()->gpu_binary_location()))
        , _context(Config::instance()->enable_gpu() ? new grk_plugin::GrokContext(_dcpomatic_context) : nullptr)
 #endif
 {
@@ -84,6 +84,7 @@ J2KEncoder::~J2KEncoder ()
 
 #ifdef DCPOMATIC_GROK
        delete _context;
+       delete _dcpomatic_context;
 #endif
 }
 
index 9d9d8589447baf83195438062f2c37f996821263..913beb5a91b5e0e9eb8bb8b5281b8bc021d0bdea 100644 (file)
@@ -125,7 +125,7 @@ private:
        boost::signals2::scoped_connection _server_found_connection;
 
 #ifdef DCPOMATIC_GROK
-       grk_plugin::DcpomaticContext _dcpomatic_context;
+       grk_plugin::DcpomaticContext* _dcpomatic_context;
        grk_plugin::GrokContext *_context;
 #endif