Cleanup: reformat and rename dcpomaticContext_ -> _dcpomatic_context
[dcpomatic.git] / src / lib / grok / context.h
index 8e03c1d541c71bb5aa2c6cd5129e7f2d1d41186e..1aac6f177ed15f724d5c76dd530ecb374f4f88a9 100644 (file)
@@ -27,8 +27,8 @@
 #include "../dcpomatic_log.h"
 #include "../writer.h"
 #include "messenger.h"
+#include <dcp/array_data.h>
 
-class Film;
 
 static std::mutex launchMutex;
 
@@ -59,13 +59,6 @@ struct GrokLogger : public MessengerLogger {
        }
 };
 
-struct GrokInitializer {
-       GrokInitializer(void) {
-               setMessengerLogger(new GrokLogger("[GROK] "));
-       }
-       ~GrokInitializer()  = default;
-};
-
 struct FrameProxy {
        FrameProxy(int index, Eyes eyes, DCPVideo dcpv) : index_(index), eyes_(eyes), vf(dcpv)
        {}
@@ -81,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;
@@ -94,43 +97,28 @@ 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_;
 };
 
-class GrokContext {
+
+class GrokContext
+{
 public:
-       explicit GrokContext(const DcpomaticContext &dcpomaticContext) :
-                                                               dcpomaticContext_(dcpomaticContext),
-                                                               messenger_(nullptr),
-                                                               launched_(false)
+       explicit GrokContext(DcpomaticContext const& dcpomatic_context)
+               : _dcpomatic_context(dcpomatic_context)
+               , messenger_(nullptr)
+               , launched_(false)
        {
-               struct CompressedData : public dcp::Data {
-                       explicit CompressedData(int dataLen) : data_(new uint8_t[dataLen]), dataLen_(dataLen)
-                       {}
-                       ~CompressedData(void){
-                               delete[] data_;
-                       }
-                       uint8_t const * data () const override {
-                               return data_;
-                       }
-                       uint8_t * data () override {
-                               return data_;
-                       }
-                       int size () const override {
-                               return dataLen_;
-                       }
-                       uint8_t *data_;
-                       int dataLen_;
-               };
                if (Config::instance()->enable_gpu ())  {
-                   boost::filesystem::path folder(dcpomaticContext_.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",
-                                       dcpomaticContext_.location_.c_str());
-                               return;
+                           getMessengerLogger()->error(
+                                   "Invalid binary location %s", _dcpomatic_context._location.c_str()
+                                   );
+                           return;
                    }
                        auto proc = [this](const std::string& str) {
                                try {
@@ -145,9 +133,8 @@ public:
                                                auto  processor =
                                                                [this](FrameProxy srcFrame, uint8_t* compressed, uint32_t compressedFrameLength)
                                                {
-                                                       auto compressedData = std::make_shared<CompressedData>(compressedFrameLength);
-                                                       memcpy(compressedData->data_,compressed,compressedFrameLength );
-                                                       dcpomaticContext_.writer_.write(compressedData, srcFrame.index(), srcFrame.eyes());
+                                                       auto compressed_data = std::make_shared<dcp::ArrayData>(compressed, compressedFrameLength);
+                                                       _dcpomatic_context.writer_.write(compressed_data, srcFrame.index(), srcFrame.eyes());
                                                        frame_done ();
                                                };
                                                int const minimum_size = 16384;
@@ -160,7 +147,7 @@ public:
                                                        }
 
                                                        auto encoded = std::make_shared<dcp::ArrayData>(fp->vf.encode_locally());
-                                                       dcpomaticContext_.writer_.write(encoded, fp->vf.index(), fp->vf.eyes());
+                                                       _dcpomatic_context.writer_.write(encoded, fp->vf.index(), fp->vf.eyes());
                                                        frame_done ();
                                                }
                                        }
@@ -190,18 +177,20 @@ public:
                        return true;
                if (MessengerInit::firstLaunch(true)) {
                        auto s = dcpv.get_size();
-                       dcpomaticContext_.setDimensions(s.width, s.height);
+                       _dcpomatic_context.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(
+                               _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(),
+                               config->gpu_license_server(),
+                               config->gpu_license_port(),
+                               config->gpu_license()
+                               );
                }
                launched_ =  messenger_->waitForClientInit();
 
@@ -231,10 +220,10 @@ public:
                messenger_ = nullptr;
        }
        void frame_done () {
-               dcpomaticContext_.history_.event ();
+               _dcpomatic_context.history_.event();
        }
 private:
-       DcpomaticContext dcpomaticContext_;
+       DcpomaticContext _dcpomatic_context;
        ScheduledMessenger<FrameProxy> *messenger_;
        bool launched_;
 };