From 18fbb7b578eb0626c269bbb90de205c2d8fc3326 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 14 Sep 2018 22:34:50 +0100 Subject: [PATCH] Very basic player logging. --- ChangeLog | 2 ++ src/lib/config.cc | 5 ++++ src/lib/config.h | 17 ++++++++++++++ src/tools/dcpomatic_player.cc | 43 ++++++++++++++++++++++++++++++++++ src/wx/player_config_dialog.cc | 21 +++++++++++++++-- 5 files changed, 86 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 243f2aa16..69cd4c010 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2018-09-14 Carl Hetherington + * Very basic logging in player. + * Basic dual-screen mode for player. 2018-09-11 Carl Hetherington diff --git a/src/lib/config.cc b/src/lib/config.cc index 373b71df6..b28f8b957 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -165,6 +165,7 @@ Config::set_defaults () _interface_complexity = INTERFACE_SIMPLE; _player_mode = PLAYER_MODE_WINDOW; _respect_kdm_validity_periods = false; + _player_log_file = boost::none; _allowed_dcp_frame_rates.clear (); _allowed_dcp_frame_rates.push_back (24); @@ -493,6 +494,7 @@ try } _respect_kdm_validity_periods = f.optional_bool_child("RespectKDMValidityPeriods").get_value_or(false); + _player_log_file = f.optional_string_child("PlayerLogFile"); /* Replace any cinemas from config.xml with those from the configured file */ if (boost::filesystem::exists (_cinemas_file)) { @@ -880,6 +882,9 @@ Config::write_config () const } root->add_child("RespectKDMValidityPeriods")->add_child_text(_respect_kdm_validity_periods ? "1" : "0"); + if (_player_log_file) { + root->add_child("PlayerLogFile")->add_child_text(_player_log_file->string()); + } try { doc.write_to_file_formatted(config_file().string()); diff --git a/src/lib/config.h b/src/lib/config.h index c8ae32efd..37c036587 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -473,6 +473,10 @@ public: return _respect_kdm_validity_periods; } + boost::optional player_log_file () const { + return _player_log_file; + } + /* SET (mostly) */ void set_master_encoding_threads (int n) { @@ -879,6 +883,18 @@ public: maybe_set (_respect_kdm_validity_periods, r); } + void set_player_log_file (boost::filesystem::path p) { + maybe_set (_player_log_file, p); + } + + void unset_player_log_file () { + if (!_player_log_file) { + return; + } + _player_log_file = boost::none; + changed (); + } + void changed (Property p = OTHER); boost::signals2::signal Changed; /** Emitted if read() failed on an existing Config file. There is nothing @@ -1063,6 +1079,7 @@ private: Interface _interface_complexity; PlayerMode _player_mode; bool _respect_kdm_validity_periods; + boost::optional _player_log_file; static int const _current_version; diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index c6832772f..7a7e5ac16 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -163,6 +163,8 @@ public: _controls = new Controls (_overall_panel, _viewer); _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ()); _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this)); + _viewer->Started.connect (bind(&DOMFrame::playback_started, this)); + _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this)); _info = new PlayerInformation (_overall_panel, _viewer); wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL); main_sizer->Add (_viewer->panel(), 1, wxEXPAND); @@ -219,6 +221,47 @@ public: return ok; } + void playback_started () + { + optional log = Config::instance()->player_log_file(); + if (!log) { + return; + } + + shared_ptr dcp = boost::dynamic_pointer_cast(_film->content().front()); + DCPOMATIC_ASSERT (dcp); + DCPExaminer ex (dcp); + shared_ptr playing_cpl; + BOOST_FOREACH (shared_ptr i, ex.cpls()) { + if (!dcp->cpl() || i->id() == *dcp->cpl()) { + playing_cpl = i; + } + } + DCPOMATIC_ASSERT (playing_cpl) + + FILE* f = fopen_boost(*log, "a"); + fprintf ( + f, + "%s playback-started %s %s\n", + dcp::LocalTime().as_string().c_str(), + dcp->directories().front().string().c_str(), + playing_cpl->annotation_text().c_str() + ); + fclose (f); + } + + void playback_stopped () + { + optional log = Config::instance()->player_log_file(); + if (!log) { + return; + } + + FILE* f = fopen_boost(*log, "a"); + fprintf (f, "%s playback-stopped\n", dcp::LocalTime().as_string().c_str()); + fclose (f); + } + void set_decode_reduction (optional reduction) { _viewer->set_dcp_decode_reduction (reduction); diff --git a/src/wx/player_config_dialog.cc b/src/wx/player_config_dialog.cc index c84c8b212..8d83f0bc6 100644 --- a/src/wx/player_config_dialog.cc +++ b/src/wx/player_config_dialog.cc @@ -98,15 +98,23 @@ private: table->Add (_respect_kdm, wxGBPosition(r, 0), wxGBSpan(1, 2)); ++r; + add_label_to_sizer (table, _panel, _("Log file"), true, wxGBPosition (r, 0)); + _log_file = new FilePickerCtrl (_panel, _("Select log file"), "*", true); + table->Add (_log_file, wxGBPosition (r, 1)); + ++r; + _player_mode->Bind (wxEVT_CHOICE, bind(&PlayerGeneralPage::player_mode_changed, this)); _respect_kdm->Bind (wxEVT_CHECKBOX, bind(&PlayerGeneralPage::respect_kdm_changed, this)); + _log_file->Bind (wxEVT_FILEPICKER_CHANGED, bind(&PlayerGeneralPage::log_file_changed, this)); } void config_changed () { GeneralPage::config_changed (); - switch (Config::instance()->player_mode()) { + Config* config = Config::instance (); + + switch (config->player_mode()) { case Config::PLAYER_MODE_WINDOW: checked_set (_player_mode, 0); break; @@ -118,7 +126,10 @@ private: break; } - checked_set (_respect_kdm, Config::instance()->respect_kdm_validity_periods()); + checked_set (_respect_kdm, config->respect_kdm_validity_periods()); + if (config->player_log_file()) { + checked_set (_log_file, *config->player_log_file()); + } } private: @@ -142,8 +153,14 @@ private: Config::instance()->set_respect_kdm_validity_periods(_respect_kdm->GetValue()); } + void log_file_changed () + { + Config::instance()->set_player_log_file(wx_to_std(_log_file->GetPath())); + } + wxChoice* _player_mode; wxCheckBox* _respect_kdm; + FilePickerCtrl* _log_file; }; wxPreferencesEditor* -- 2.30.2