Very basic player logging. v2.13.49
authorCarl Hetherington <cth@carlh.net>
Fri, 14 Sep 2018 21:34:50 +0000 (22:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 14 Sep 2018 21:34:50 +0000 (22:34 +0100)
ChangeLog
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic_player.cc
src/wx/player_config_dialog.cc

index 243f2aa..69cd4c0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2018-09-14  Carl Hetherington  <cth@carlh.net>
 
+       * Very basic logging in player.
+
        * Basic dual-screen mode for player.
 
 2018-09-11  Carl Hetherington  <cth@carlh.net>
index 373b71d..b28f8b9 100644 (file)
@@ -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());
index c8ae32e..37c0365 100644 (file)
@@ -473,6 +473,10 @@ public:
                return _respect_kdm_validity_periods;
        }
 
+       boost::optional<boost::filesystem::path> 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<void (Property)> 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<boost::filesystem::path> _player_log_file;
 
        static int const _current_version;
 
index c683277..7a7e5ac 100644 (file)
@@ -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<boost::filesystem::path> log = Config::instance()->player_log_file();
+               if (!log) {
+                       return;
+               }
+
+               shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
+               DCPOMATIC_ASSERT (dcp);
+               DCPExaminer ex (dcp);
+               shared_ptr<dcp::CPL> playing_cpl;
+               BOOST_FOREACH (shared_ptr<dcp::CPL> 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<boost::filesystem::path> 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<int> reduction)
        {
                _viewer->set_dcp_decode_reduction (reduction);
index c84c8b2..8d83f0b 100644 (file)
@@ -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*