diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-10-06 21:27:39 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-12-16 02:07:38 +0100 |
| commit | 1c802a1a3e7743087f087fd3e02e49062f54ec07 (patch) | |
| tree | 31307ad325333eb5ea518589a1159fbdde30dcf0 | |
| parent | 25b683b414af85dbed22c465002104a226c622e9 (diff) | |
Cleanup: whitespace / coding style.
| -rw-r--r-- | src/lib/grok/context.h | 262 | ||||
| -rw-r--r-- | src/wx/grok/gpu_config_panel.h | 186 |
2 files changed, 246 insertions, 202 deletions
diff --git a/src/lib/grok/context.h b/src/lib/grok/context.h index ecb9d1f98..d27caa5f6 100644 --- a/src/lib/grok/context.h +++ b/src/lib/grok/context.h @@ -75,33 +75,34 @@ struct FrameProxy { DCPVideo vf; }; -struct DcpomaticContext { +struct DcpomaticContext +{ DcpomaticContext( - std::shared_ptr<const Film> film, - Writer& writer, - EventHistory& history, - boost::filesystem::path const& location + 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) + : film(film_) + , writer(writer_) + , history(history_) + , location(location_) { } - void setDimensions(uint32_t w, uint32_t h) { - width_ = w; - height_ = h; + void set_dimensions(uint32_t w, uint32_t h) + { + width = w; + height = h; } - std::shared_ptr<const Film> film_; - Writer& writer_; - EventHistory &history_; - boost::filesystem::path _location; - uint32_t width_; - uint32_t height_; + + std::shared_ptr<const Film> film; + Writer& writer; + EventHistory& history; + boost::filesystem::path location; + uint32_t width = 0; + uint32_t height = 0; }; @@ -110,140 +111,179 @@ class GrokContext public: explicit GrokContext(DcpomaticContext* dcpomatic_context) : _dcpomatic_context(dcpomatic_context) - , messenger_(nullptr) - , launched_(false) - , launchFailed_(false) { - if (Config::instance()->enable_gpu ()) { - 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() - ); - return; - } - auto proc = [this](const std::string& str) { - try { - Msg msg(str); - auto tag = msg.next(); - if(tag == GRK_MSGR_BATCH_SUBMIT_COMPRESSED) - { - auto clientFrameId = msg.nextUint(); - auto compressedFrameId = msg.nextUint(); - (void)compressedFrameId; - auto compressedFrameLength = msg.nextUint(); - auto processor = - [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()); - frame_done (); - }; - int const minimum_size = 16384; - bool needsRecompression = compressedFrameLength < minimum_size; - messenger_->processCompressed(str, processor, needsRecompression); - if (needsRecompression) { - auto fp = messenger_->retrieve(clientFrameId); - if (!fp) { - return; - } - - auto encoded = std::make_shared<dcp::ArrayData>(fp->vf.encode_locally()); - _dcpomatic_context->writer_.write(encoded, fp->vf.index(), fp->vf.eyes()); - frame_done (); + if (!Config::instance()->enable_gpu()) { + return; + } + + boost::filesystem::path folder(_dcpomatic_context->location); + boost::filesystem::path binary_path = folder / "grk_compress"; + if (!boost::filesystem::exists(binary_path)) { + getMessengerLogger()->error( + "Invalid binary location %s", _dcpomatic_context->location.c_str() + ); + return; + } + + auto proc = [this](const std::string& str) { + try { + Msg msg(str); + auto tag = msg.next(); + if (tag == GRK_MSGR_BATCH_SUBMIT_COMPRESSED) { + auto clientFrameId = msg.nextUint(); + msg.nextUint(); // compressed frame ID + auto compressedFrameLength = msg.nextUint(); + auto processor = [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()); + frame_done (); + }; + + int const minimum_size = 16384; + + bool needsRecompression = compressedFrameLength < minimum_size; + _messenger->processCompressed(str, processor, needsRecompression); + + if (needsRecompression) { + auto fp = _messenger->retrieve(clientFrameId); + if (!fp) { + return; } + + auto encoded = std::make_shared<dcp::ArrayData>(fp->vf.encode_locally()); + _dcpomatic_context->writer.write(encoded, fp->vf.index(), fp->vf.eyes()); + frame_done (); } - } catch (std::exception &ex){ - getMessengerLogger()->error("%s",ex.what()); } - }; - auto clientInit = - MessengerInit(clientToGrokMessageBuf, clientSentSynch, grokReceiveReadySynch, - grokToClientMessageBuf, grokSentSynch, clientReceiveReadySynch, proc, - std::thread::hardware_concurrency()); - messenger_ = new ScheduledMessenger<FrameProxy>(clientInit); - } + } catch (std::exception& ex) { + getMessengerLogger()->error("%s",ex.what()); + } + }; + + auto clientInit = MessengerInit( + clientToGrokMessageBuf, + clientSentSynch, + grokReceiveReadySynch, + grokToClientMessageBuf, + grokSentSynch, + clientReceiveReadySynch, + proc, + std::thread::hardware_concurrency() + ); + + _messenger = new ScheduledMessenger<FrameProxy>(clientInit); } - ~GrokContext(void) { + + ~GrokContext() + { shutdown(); } - bool launch(DCPVideo dcpv, int device){ + + bool launch(DCPVideo dcpv, int device) + { namespace fs = boost::filesystem; - if (!messenger_ ) + if (!_messenger) { return false; - if (launched_) + } + if (_launched) { return true; - if (launchFailed_) + } + if (_launch_failed) { return false; + } + std::unique_lock<std::mutex> lk_global(launchMutex); - if (!messenger_) + + if (!_messenger) { return false; - if (launched_) + } + if (_launched) { return true; - if (launchFailed_) + } + if (_launch_failed) { return false; + } + if (MessengerInit::firstLaunch(true)) { - if (!fs::exists(_dcpomatic_context->_location) || !fs::is_directory(_dcpomatic_context->_location)) { - getMessengerLogger()->error("Invalid directory %s", _dcpomatic_context->_location.c_str()); + if (!fs::exists(_dcpomatic_context->location) || !fs::is_directory(_dcpomatic_context->location)) { + getMessengerLogger()->error("Invalid directory %s", _dcpomatic_context->location.c_str()); return false; - } + } + auto s = dcpv.get_size(); - _dcpomatic_context->setDimensions(s.width, s.height); + _dcpomatic_context->set_dimensions(s.width, s.height); auto config = Config::instance(); - if (!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(), + if (!_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())) { - launchFailed_ = true; + _launch_failed = true; return false; } } - launched_ = messenger_->waitForClientInit(); - launchFailed_ = launched_; - return launched_; + _launched = _messenger->waitForClientInit(); + _launch_failed = _launched; + + return _launched; } - bool scheduleCompress(DCPVideo const& vf){ - if (!messenger_) + + bool scheduleCompress(DCPVideo const& vf) + { + if (!_messenger) { return false; + } auto fp = FrameProxy(vf.index(), vf.eyes(), vf); - auto cvt = [this, &fp](BufferSrc src){ - // xyz conversion + auto cvt = [this, &fp](BufferSrc src) { fp.vf.convert_to_xyz((uint16_t*)src.framePtr_); }; - return messenger_->scheduleCompress(fp, cvt); + + return _messenger->scheduleCompress(fp, cvt); } - void shutdown(void){ - if (!messenger_) + + void shutdown() + { + if (!_messenger) { return; + } std::unique_lock<std::mutex> lk_global(launchMutex); - if (!messenger_) + + if (!_messenger) { return; - if (launched_) - messenger_->shutdown(); - delete messenger_; - messenger_ = nullptr; + } + + if (_launched) { + _messenger->shutdown(); + } + + delete _messenger; + _messenger = nullptr; } - void frame_done () { - _dcpomatic_context->history_.event(); + + void frame_done() + { + _dcpomatic_context->history.event(); } + private: DcpomaticContext* _dcpomatic_context; - ScheduledMessenger<FrameProxy> *messenger_; - bool launched_; - bool launchFailed_; + ScheduledMessenger<FrameProxy>* _messenger = nullptr; + bool _launched = false; + bool _launch_failed = false; }; } diff --git a/src/wx/grok/gpu_config_panel.h b/src/wx/grok/gpu_config_panel.h index a0f2a1f7f..40e999181 100644 --- a/src/wx/grok/gpu_config_panel.h +++ b/src/wx/grok/gpu_config_panel.h @@ -41,111 +41,121 @@ static std::vector<std::string> get_gpu_names(boost::filesystem::path binary, bo return gpu_names; } + class GpuList : public wxPanel { public: - GpuList(wxPanel* parent) : wxPanel(parent, wxID_ANY), selection(0) { - comboBox = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1)); - comboBox->Bind(wxEVT_COMBOBOX, &GpuList::OnComboBox, this); - update(); - - wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); + GpuList(wxPanel* parent) + : wxPanel(parent, wxID_ANY) + { + _combo_box = new wxComboBox(this, wxID_ANY, "", wxDefaultPosition, wxSize(400, -1)); + _combo_box->Bind(wxEVT_COMBOBOX, &GpuList::OnComboBox, this); + update(); - sizer->Add(comboBox, 0, wxALIGN_CENTER_VERTICAL); // Vertically center the comboBox + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(_combo_box, 0, wxALIGN_CENTER_VERTICAL); + SetSizerAndFit(sizer); + } - this->SetSizerAndFit(sizer); - } - 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"; - if (boost::filesystem::exists(lister_binary)) { + void update() + { + auto cfg = Config::instance(); + 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); - comboBox->Clear(); - for (const auto& name : gpu_names) - comboBox->Append(name); - } - } + _combo_box->Clear(); + for (auto const& name: gpu_names) { + _combo_box->Append(name); + } + } + } - int getSelection(void) { - return selection; - } - void setSelection(int sel) { - if ((int)comboBox->GetCount() > sel) - comboBox->SetSelection(sel); - } + void set_selection(int sel) + { + if (sel < static_cast<int>(_combo_box->GetCount())) { + _combo_box->SetSelection(sel); + } + } private: - void OnComboBox(wxCommandEvent&) - { - selection = comboBox->GetSelection(); - if (selection != wxNOT_FOUND) - Config::instance ()->set_selected_gpu(selection); - } + void OnComboBox(wxCommandEvent&) + { + auto selection = _combo_box->GetSelection(); + if (selection != wxNOT_FOUND) { + Config::instance()->set_selected_gpu(selection); + } + } - wxComboBox* comboBox; - int selection; + wxComboBox* _combo_box; + int _selection = 0; }; + class GPUPage : public Page { public: - GPUPage (wxSize panel_size, int border) - : Page (panel_size, border), - _enable_gpu(nullptr), _binary_location(nullptr), _gpu_list_control(nullptr) + GPUPage(wxSize panel_size, int border) + : Page(panel_size, border) {} - wxString GetName () const override + wxString GetName() const override { return _("GPU"); } #ifdef DCPOMATIC_OSX - wxBitmap GetLargeIcon () const override + /* XXX: this icon does not exist */ + wxBitmap GetLargeIcon() const override { - return wxBitmap(icon_path("tms"), wxBITMAP_TYPE_PNG); + return wxBitmap(icon_path("gpu"), wxBITMAP_TYPE_PNG); } #endif private: - void setup () override + void setup() override { - auto config = Config::instance (); - _enable_gpu = new CheckBox(_panel, _("Enable GPU acceleration")); - _panel->GetSizer()->Add (_enable_gpu, 0, wxALL | wxEXPAND, _border); + _panel->GetSizer()->Add(_enable_gpu, 0, wxALL | wxEXPAND, _border); - wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); - table->AddGrowableCol (1, 1); - _panel->GetSizer()->Add (table, 1, wxALL | wxEXPAND, _border); + wxFlexGridSizer* table = new wxFlexGridSizer(2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP); + table->AddGrowableCol(1, 1); + _panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border); add_label_to_sizer(table, _panel, _("Acceleration binary folder"), true, 0, wxLEFT | wxLEFT | wxALIGN_CENTRE_VERTICAL); - _binary_location = new wxDirPickerCtrl (_panel, wxDD_DIR_MUST_EXIST); - table->Add (_binary_location, 1, wxEXPAND); + _binary_location = new wxDirPickerCtrl(_panel, wxDD_DIR_MUST_EXIST); + table->Add(_binary_location, 1, wxEXPAND); add_label_to_sizer(table, _panel, _("GPU selection"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); _gpu_list_control = new GpuList(_panel); - table->Add (_gpu_list_control, 1, wxEXPAND); + table->Add(_gpu_list_control, 1, wxEXPAND); add_label_to_sizer(table, _panel, _("License server"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _server = new wxTextCtrl (_panel, wxID_ANY); - table->Add (_server, 1, wxEXPAND | wxALL); + _server = new wxTextCtrl(_panel, wxID_ANY); + table->Add(_server, 1, wxEXPAND | wxALL); - add_label_to_sizer (table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _port = new wxSpinCtrl (_panel, wxID_ANY); - _port->SetRange (0, 65535); - table->Add (_port); + add_label_to_sizer(table, _panel, _("Port"), false, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _port = new wxSpinCtrl(_panel, wxID_ANY); + _port->SetRange(0, 65535); + table->Add(_port); - add_label_to_sizer (table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); - _license = new PasswordEntry (_panel); - table->Add (_license->get_panel(), 1, wxEXPAND | wxALL); + add_label_to_sizer(table, _panel, _("License"), true, 0, wxLEFT | wxRIGHT | wxALIGN_CENTRE_VERTICAL); + _license = new PasswordEntry(_panel); + table->Add(_license->get_panel(), 1, wxEXPAND | wxALL); _enable_gpu->bind(&GPUPage::enable_gpu_changed, this); - _binary_location->Bind (wxEVT_DIRPICKER_CHANGED, boost::bind (&GPUPage::binary_location_changed, this)); - _server->Bind (wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this)); - _port->Bind (wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this)); - _license->Changed.connect (boost::bind(&GPUPage::license_changed, this)); + _binary_location->Bind(wxEVT_DIRPICKER_CHANGED, boost::bind (&GPUPage::binary_location_changed, this)); + _server->Bind(wxEVT_TEXT, boost::bind(&GPUPage::server_changed, this)); + _port->Bind(wxEVT_SPINCTRL, boost::bind(&GPUPage::port_changed, this)); + _license->Changed.connect(boost::bind(&GPUPage::license_changed, this)); + + setup_sensitivity(); + } + + void setup_sensitivity() + { + auto config = Config::instance(); _binary_location->Enable(config->enable_gpu()); _gpu_list_control->Enable(config->enable_gpu()); @@ -154,57 +164,51 @@ private: _license->get_panel()->Enable(config->enable_gpu()); } - - void config_changed () override + void config_changed() override { - auto config = Config::instance (); + auto config = Config::instance(); - checked_set (_enable_gpu, config->enable_gpu()); + checked_set(_enable_gpu, config->enable_gpu()); _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()); - checked_set (_port, config->gpu_license_port()); - checked_set (_license, config->gpu_license()); + _gpu_list_control->set_selection(config->selected_gpu()); + checked_set(_server, config->gpu_license_server()); + checked_set(_port, config->gpu_license_port()); + checked_set(_license, config->gpu_license()); } - void enable_gpu_changed () + void enable_gpu_changed() { - auto config = Config::instance (); - - config->set_enable_gpu (_enable_gpu->GetValue()); - _binary_location->Enable(config->enable_gpu()); - _gpu_list_control->Enable(config->enable_gpu()); - _server->Enable(config->enable_gpu()); - _port->Enable(config->enable_gpu()); - _license->get_panel()->Enable(config->enable_gpu()); + auto config = Config::instance(); + config->set_enable_gpu(_enable_gpu->GetValue()); + setup_sensitivity(); } - void binary_location_changed () + void binary_location_changed() { - Config::instance()->set_gpu_binary_location (wx_to_std (_binary_location->GetPath ())); + Config::instance()->set_gpu_binary_location(wx_to_std(_binary_location->GetPath())); _gpu_list_control->update(); } - void server_changed () + void server_changed() { Config::instance()->set_gpu_license_server(wx_to_std(_server->GetValue())); } - void port_changed () + void port_changed() { Config::instance()->set_gpu_license_port(_port->GetValue()); } - void license_changed () + void license_changed() { Config::instance()->set_gpu_license(_license->get()); } - CheckBox* _enable_gpu; - wxDirPickerCtrl* _binary_location; - GpuList *_gpu_list_control; - wxTextCtrl* _server; - wxSpinCtrl* _port; - PasswordEntry* _license; + CheckBox* _enable_gpu = nullptr; + wxDirPickerCtrl* _binary_location = nullptr; + GpuList* _gpu_list_control = nullptr; + wxTextCtrl* _server = nullptr; + wxSpinCtrl* _port = nullptr; + PasswordEntry* _license = nullptr; }; |
