diff options
Diffstat (limited to 'src/tools/dcpomatic_player.cc')
| -rw-r--r-- | src/tools/dcpomatic_player.cc | 100 |
1 files changed, 63 insertions, 37 deletions
diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index 415dbf3ba..688deccd3 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -43,18 +43,15 @@ #include "lib/config.h" #include "lib/constants.h" #include "lib/copy_dcp_details_to_film.h" -#include "lib/cross.h" #include "lib/dcp_content.h" #include "lib/dcp_examiner.h" #include "lib/dcpomatic_log.h" #include "lib/dcpomatic_socket.h" #include "lib/examine_content_job.h" -#include "lib/ffmpeg_content.h" #include "lib/file_log.h" #include "lib/film.h" #include "lib/font_config.h" #include "lib/http_server.h" -#include "lib/image.h" #include "lib/image_jpeg.h" #include "lib/image_png.h" #include "lib/internal_player_server.h" @@ -64,9 +61,7 @@ #include "lib/null_log.h" #include "lib/player.h" #include "lib/player_video.h" -#include "lib/ratio.h" #include "lib/scoped_temporary.h" -#include "lib/server.h" #include "lib/text_content.h" #include "lib/update_checker.h" #include "lib/variant.h" @@ -107,7 +102,6 @@ LIBDCP_ENABLE_WARNINGS using std::cout; using std::dynamic_pointer_cast; using std::exception; -using std::list; using std::make_shared; using std::shared_ptr; using std::string; @@ -205,7 +199,7 @@ public: }; - DOMFrame() + explicit DOMFrame(bool auto_play) : wxFrame(nullptr, -1, variant::wx::dcpomatic_player()) , _mode(Config::instance()->player_mode()) /* Use a panel as the only child of the Frame so that we avoid @@ -214,6 +208,7 @@ public: , _overall_panel(new wxPanel(this, wxID_ANY)) , _viewer(_overall_panel, true) , _main_sizer(new wxBoxSizer(wxVERTICAL)) + , _auto_play(auto_play) { dcpomatic_log = make_shared<NullLog>(); @@ -317,7 +312,7 @@ public: UpdateChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::update_checker_state_changed, this)); setup_screen(); - _stress.LoadDCP.connect(boost::bind(&DOMFrame::load_dcp, this, _1)); + _stress.LoadDCP.connect(boost::bind(&DOMFrame::load_dcp, this, _1, boost::none)); setup_internal_player_server(); setup_http_server(); @@ -410,7 +405,7 @@ public: Config::instance()->set_decode_reduction(reduction); } - void load_dcp(boost::filesystem::path dir) + void load_dcp(boost::filesystem::path dir, optional<boost::filesystem::path> kdm = {}) { DCPOMATIC_ASSERT(_film); @@ -420,7 +415,7 @@ public: _stress.set_suspended(true); /* Handler to set things up once the DCP has been examined */ - auto setup = [this](weak_ptr<Film> weak_film, weak_ptr<Job> weak_job, weak_ptr<Content> weak_content) + auto setup = [this, kdm](weak_ptr<Film> weak_film, weak_ptr<Job> weak_job, weak_ptr<Content> weak_content) { auto job = weak_job.lock(); if (!job || !job->finished_ok()) { @@ -440,6 +435,13 @@ public: film->add_content({content}); _stress.set_suspended(false); reset_film(film); + if (kdm) { + add_kdms({*kdm}); + } + + if (_auto_play) { + _viewer.start(); + } }; auto dcp = make_shared<DCPContent>(dir); @@ -623,6 +625,30 @@ public: } } + void add_kdms(vector<boost::filesystem::path> const& paths) + { + DCPOMATIC_ASSERT(_film); + auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front()); + DCPOMATIC_ASSERT(dcp); + try { + dcp::ScopeGuard sg([this]() { + _viewer.set_coalesce_player_changes(false); + }); + _viewer.set_coalesce_player_changes(true); + for (auto path: paths) { + dcp->add_kdm(dcp::EncryptedKDM(dcp::file_to_string(path))); + _kdms.push_back(path); + } + examine_content(); + } catch (exception& e) { + error_dialog(this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what())); + return; + } + + _info->triggered_update(); + set_menu_sensitivity(); + } + private: void examine_content() @@ -810,29 +836,8 @@ private: FileDialog dialog(this, _("Select KDM"), char_to_wx("XML files|*.xml|All files|*.*"), wxFD_MULTIPLE, "AddKDMPath"); if (dialog.show()) { - DCPOMATIC_ASSERT(_film); - auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front()); - DCPOMATIC_ASSERT(dcp); - try { - if (dcp) { - dcp::ScopeGuard sg([this]() { - _viewer.set_coalesce_player_changes(false); - }); - _viewer.set_coalesce_player_changes(true); - for (auto path: dialog.paths()) { - dcp->add_kdm(dcp::EncryptedKDM(dcp::file_to_string(path))); - _kdms.push_back(path); - } - examine_content(); - } - } catch (exception& e) { - error_dialog(this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what())); - return; - } + add_kdms(dialog.paths()); } - - _info->triggered_update(); - set_menu_sensitivity(); } void file_save_frame() @@ -1172,7 +1177,7 @@ private: { try { auto server = new InternalPlayerServer(); - server->LoadDCP.connect(boost::bind(&DOMFrame::load_dcp, this, _1)); + server->LoadDCP.connect(boost::bind(&DOMFrame::load_dcp, this, _1, boost::none)); new thread(boost::bind(&InternalPlayerServer::run, server)); } catch (std::exception& e) { /* This is not the end of the world; probably a failure to bind the server socket @@ -1314,12 +1319,16 @@ private: std::unique_ptr<HTTPServer> _http_server; struct timeval _last_http_server_update = { 0, 0 }; wx_ptr<AudioDialog> _audio_dialog; + bool _auto_play; }; static const wxCmdLineEntryDesc command_line_description[] = { { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_OPTION, "k", "kdm", "KDM to load", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, "a", "auto-play", "start playing given DCP", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_OPTION, "d", "dcp", "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType(0), 0 } }; @@ -1387,7 +1396,7 @@ private: signal_manager = new wxSignalManager(this); - _frame = new DOMFrame(); + _frame = new DOMFrame(_auto_play); SetTopWindow(_frame); _frame->Maximize(); if (splash) { @@ -1398,7 +1407,7 @@ private: if (_dcp_to_load && dcp::filesystem::is_directory(*_dcp_to_load)) { try { - _frame->load_dcp(*_dcp_to_load); + _frame->load_dcp(*_dcp_to_load, _kdm_to_load); } catch (exception& e) { error_dialog(nullptr, wxString::Format(_("Could not load DCP %s"), std_to_wx(_dcp_to_load->string())), std_to_wx(e.what())); } @@ -1437,8 +1446,8 @@ private: bool OnCmdLineParsed(wxCmdLineParser& parser) override { - if (parser.GetParamCount() > 0) { - auto path = boost::filesystem::path(wx_to_std(parser.GetParam(0))); + auto set_dcp_to_load = [this](wxString wx_path) { + auto path = boost::filesystem::path(wx_to_std(wx_path)); /* Go at most two directories higher looking for a DCP that contains the file * that was passed in. */ @@ -1449,6 +1458,10 @@ private: } path = path.parent_path(); } + }; + + if (parser.GetParamCount() > 0) { + set_dcp_to_load(parser.GetParam(0)); } wxString config; @@ -1459,6 +1472,17 @@ private: if (parser.Found(char_to_wx("s"), &stress)) { _stress = wx_to_std(stress); } + wxString kdm; + if (parser.Found(char_to_wx("k"), &kdm)) { + _kdm_to_load = boost::filesystem::path(wx_to_std(kdm)); + } + if (parser.Found(char_to_wx("a"))) { + _auto_play = true; + } + wxString dcp; + if (parser.Found(char_to_wx("d"), &dcp)) { + set_dcp_to_load(dcp); + } return true; } @@ -1524,7 +1548,9 @@ private: DOMFrame* _frame = nullptr; boost::optional<boost::filesystem::path> _dcp_to_load; + boost::optional<boost::filesystem::path> _kdm_to_load; boost::optional<string> _stress; + bool _auto_play = false; }; IMPLEMENT_APP(App) |
