From 985e727e001e1a92ae035364a9cbf1ff99522ff1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 14 Apr 2019 20:17:35 +0100 Subject: [PATCH] Store successful DCP encodes. --- src/lib/analytics.cc | 87 +++++++++++++++++++++++++++++++++++ src/lib/analytics.h | 40 ++++++++++++++++ src/lib/config.cc | 30 +----------- src/lib/config.h | 7 +-- src/lib/state.cc | 54 ++++++++++++++++++++++ src/lib/state.h | 37 +++++++++++++++ src/lib/transcode_job.cc | 7 +++ src/lib/wscript | 2 + src/tools/dcpomatic_cli.cc | 2 +- src/tools/dcpomatic_create.cc | 2 +- 10 files changed, 232 insertions(+), 36 deletions(-) create mode 100644 src/lib/analytics.cc create mode 100644 src/lib/analytics.h create mode 100644 src/lib/state.cc create mode 100644 src/lib/state.h diff --git a/src/lib/analytics.cc b/src/lib/analytics.cc new file mode 100644 index 000000000..74c21a29c --- /dev/null +++ b/src/lib/analytics.cc @@ -0,0 +1,87 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include "analytics.h" +#include "exceptions.h" +#include +#include +#include +#include +#include + +using std::string; +using dcp::raw_convert; +using boost::algorithm::trim; + +Analytics* Analytics::_instance; +int const Analytics::_current_version = 1; + +Analytics::Analytics () + : _successful_dcp_encodes (0) +{ + +} + +void +Analytics::successful_dcp_encode () +{ + ++_successful_dcp_encodes; + write (); +} + +void +Analytics::write () const +{ + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("Analytics"); + + root->add_child("Version")->add_child_text(raw_convert(_current_version)); + root->add_child("SuccessfulDCPEncodes")->add_child_text(raw_convert(_successful_dcp_encodes)); + + try { + doc.write_to_file_formatted(path("analytics.xml").string()); + } catch (xmlpp::exception& e) { + string s = e.what (); + trim (s); + throw FileError (s, path("analytics.xml")); + } +} + +void +Analytics::read () +try +{ + cxml::Document f ("Analytics"); + f.read_file (path("analytics.xml")); + _successful_dcp_encodes = f.number_child("SuccessfulDCPEncodes"); +} catch (...) { + /* Never mind */ +} + +Analytics* +Analytics::instance () +{ + if (!_instance) { + _instance = new Analytics(); + _instance->read(); + } + + return _instance; +} diff --git a/src/lib/analytics.h b/src/lib/analytics.h new file mode 100644 index 000000000..b439fca8c --- /dev/null +++ b/src/lib/analytics.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include "state.h" + +class Analytics : public State +{ +public: + Analytics (); + + void successful_dcp_encode (); + + void write () const; + void read (); + + static Analytics* instance (); + +private: + int _successful_dcp_encodes; + + static Analytics* _instance; + static int const _current_version; +}; diff --git a/src/lib/config.cc b/src/lib/config.cc index c71f3acd3..2e40ab308 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -70,7 +70,6 @@ int const Config::_current_version = 3; boost::signals2::signal Config::FailedToLoad; boost::signals2::signal Config::Warning; boost::signals2::signal Config::BadSignerChain; -boost::optional Config::override_path; /** Construct default configuration */ Config::Config () @@ -609,33 +608,6 @@ catch (...) { write (); } -/** @return Filename to write configuration to */ -boost::filesystem::path -Config::path (string file, bool create_directories) -{ - boost::filesystem::path p; - if (override_path) { - p = *override_path; - } else { -#ifdef DCPOMATIC_OSX - p /= g_get_home_dir (); - p /= "Library"; - p /= "Preferences"; - p /= "com.dcpomatic"; - p /= "2"; -#else - p /= g_get_user_config_dir (); - p /= "dcpomatic2"; -#endif - } - boost::system::error_code ec; - if (create_directories) { - boost::filesystem::create_directories (p, ec); - } - p /= file; - return p; -} - /** @return Singleton instance */ Config * Config::instance () @@ -663,7 +635,7 @@ Config::write_config () const xmlpp::Element* root = doc.create_root_node ("Config"); /* [XML] Version The version number of the configuration file format. */ - root->add_child("Version")->add_child_text (String::compose ("%1", _current_version)); + root->add_child("Version")->add_child_text (raw_convert(_current_version)); /* [XML] MasterEncodingThreads Number of encoding threads to use when running as master. */ root->add_child("MasterEncodingThreads")->add_child_text (raw_convert (_master_encoding_threads)); /* [XML] ServerEncodingThreads Number of encoding threads to use when running as server. */ diff --git a/src/lib/config.h b/src/lib/config.h index a982c9727..8cc25d737 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -27,6 +27,7 @@ #include "isdcf_metadata.h" #include "types.h" +#include "state.h" #include "edid.h" #include #include @@ -46,7 +47,7 @@ class DKDMGroup; /** @class Config * @brief A singleton class holding configuration. */ -class Config : public boost::noncopyable +class Config : public State { public: /** @return number of threads which a master DoM should use for J2K encoding on the local machine */ @@ -1094,10 +1095,6 @@ public: static void restore_defaults (); static bool have_existing (std::string); static boost::filesystem::path config_file (); - static boost::filesystem::path path (std::string file, bool create_directories = true); - - /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml and cinemas.xml */ - static boost::optional override_path; private: Config (); diff --git a/src/lib/state.cc b/src/lib/state.cc new file mode 100644 index 000000000..abb197695 --- /dev/null +++ b/src/lib/state.cc @@ -0,0 +1,54 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include "state.h" +#include + +using std::string; + +boost::optional State::override_path; + +/** @param file State filename + * @return Full path to write @file to */ +boost::filesystem::path +State::path (string file, bool create_directories) +{ + boost::filesystem::path p; + if (override_path) { + p = *override_path; + } else { +#ifdef DCPOMATIC_OSX + p /= g_get_home_dir (); + p /= "Library"; + p /= "Preferences"; + p /= "com.dcpomatic"; + p /= "2"; +#else + p /= g_get_user_config_dir (); + p /= "dcpomatic2"; +#endif + } + boost::system::error_code ec; + if (create_directories) { + boost::filesystem::create_directories (p, ec); + } + p /= file; + return p; +} diff --git a/src/lib/state.h b/src/lib/state.h new file mode 100644 index 000000000..b60c66673 --- /dev/null +++ b/src/lib/state.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include +#include +#include + +class State : public boost::noncopyable +{ +public: + virtual ~State () {} + virtual void read () = 0; + virtual void write () const = 0; + + /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml, cinemas.xml etc. */ + static boost::optional override_path; + +protected: + static boost::filesystem::path path (std::string file, bool create_directories = true); +}; diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index da7571b96..6aa31af97 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -31,6 +31,7 @@ #include "log.h" #include "dcpomatic_log.h" #include "compose.hpp" +#include "analytics.h" #include #include @@ -41,6 +42,7 @@ using std::fixed; using std::setprecision; using std::cout; using boost::shared_ptr; +using boost::dynamic_pointer_cast; /** @param film Film to use */ TranscodeJob::TranscodeJob (shared_ptr film) @@ -89,6 +91,11 @@ TranscodeJob::run () } LOG_GENERAL (N_("Transcode job completed successfully: %1 fps"), fps); + + if (dynamic_pointer_cast(_encoder)) { + Analytics::instance()->successful_dcp_encode(); + } + _encoder.reset (); /* XXX: this shouldn't be here */ diff --git a/src/lib/wscript b/src/lib/wscript index cf38b3689..267600bf8 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -23,6 +23,7 @@ import i18n sources = """ active_text.cc analyse_audio_job.cc + analytics.cc atmos_mxf_content.cc atomicity_checker.cc audio_analysis.cc @@ -144,6 +145,7 @@ sources = """ send_problem_report_job.cc server.cc shuffler.cc + state.cc spl.cc spl_entry.cc string_log_entry.cc diff --git a/src/tools/dcpomatic_cli.cc b/src/tools/dcpomatic_cli.cc index 5535e6218..f049c0c91 100644 --- a/src/tools/dcpomatic_cli.cc +++ b/src/tools/dcpomatic_cli.cc @@ -270,7 +270,7 @@ main (int argc, char* argv[]) } if (config) { - Config::override_path = *config; + State::override_path = *config; } if (servers) { diff --git a/src/tools/dcpomatic_create.cc b/src/tools/dcpomatic_create.cc index 66a1c0dab..1dfabd296 100644 --- a/src/tools/dcpomatic_create.cc +++ b/src/tools/dcpomatic_create.cc @@ -80,7 +80,7 @@ main (int argc, char* argv[]) } if (cc.config_dir) { - Config::override_path = *cc.config_dir; + State::override_path = *cc.config_dir; } signal_manager = new SimpleSignalManager (); -- 2.30.2