swaroop: restart playback after player crash.
authorCarl Hetherington <cth@carlh.net>
Tue, 9 Oct 2018 20:57:35 +0000 (21:57 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 9 Oct 2018 20:57:35 +0000 (21:57 +0100)
src/lib/config.h
src/lib/dcpomatic_time.h
src/lib/spl.cc
src/lib/spl.h
src/tools/dcpomatic_player.cc

index 94690a72709d9a8f1c615b89a428f57e8e2e4095..baf446df318738c1176a7bc4188b9ddb1a961881 100644 (file)
@@ -1033,13 +1033,13 @@ public:
        static void restore_defaults ();
        static bool have_existing (std::string);
        static boost::filesystem::path config_file ();
        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<boost::filesystem::path> override_path;
 
 private:
        Config ();
 
        /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml and cinemas.xml */
        static boost::optional<boost::filesystem::path> override_path;
 
 private:
        Config ();
-       static boost::filesystem::path path (std::string file, bool create_directories = true);
        void read ();
        void set_defaults ();
        void set_kdm_email_to_default ();
        void read ();
        void set_defaults ();
        void set_kdm_email_to_default ();
index 3d792467b465d4a433b5425942018b0e7b06d78b..c687569ecb0dac578809d0ae9294ccaf607960ad 100644 (file)
@@ -221,12 +221,13 @@ public:
                return Time<S, O> (INT64_MAX);
        }
 
                return Time<S, O> (INT64_MAX);
        }
 
+       static const int HZ = 96000;
+
 private:
        friend struct dcpomatic_time_ceil_test;
        friend struct dcpomatic_time_floor_test;
 
        Type _t;
 private:
        friend struct dcpomatic_time_ceil_test;
        friend struct dcpomatic_time_floor_test;
 
        Type _t;
-       static const int HZ = 96000;
 };
 
 class ContentTimeDifferentiator {};
 };
 
 class ContentTimeDifferentiator {};
index ba99e30280944e8108f4668c361f7346e13b02c8..d7c0944d7ee13a96a4a924cb9d9f72eee455663f 100644 (file)
 #include "spl.h"
 #include "spl_entry.h"
 #include <dcp/cpl.h>
 #include "spl.h"
 #include "spl_entry.h"
 #include <dcp/cpl.h>
+#include <dcp/dcp.h>
 #include <libxml++/libxml++.h>
 #include <boost/foreach.hpp>
 
 #include <libxml++/libxml++.h>
 #include <boost/foreach.hpp>
 
+using boost::shared_ptr;
+
+SPL::SPL (boost::filesystem::path file)
+{
+       cxml::Document f ("DCPPlaylist");
+       f.read_file (file);
+
+       name = f.string_attribute ("Name");
+       BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("DCP")) {
+               boost::filesystem::path dir(i->content());
+               dcp::DCP dcp (dir);
+               dcp.read ();
+               BOOST_FOREACH (shared_ptr<dcp::CPL> j, dcp.cpls()) {
+                       if (j->id() == i->string_attribute("CPL")) {
+                               playlist.push_back (SPLEntry(j, dir));
+                       }
+               }
+       }
+}
+
 void
 SPL::as_xml (boost::filesystem::path file) const
 {
 void
 SPL::as_xml (boost::filesystem::path file) const
 {
index 526016f458fc7e61bef1c4225966947b82236c81..5e1bd47b2acdeaf5a6a35d3fe5ec887f73ec2c62 100644 (file)
@@ -28,6 +28,9 @@ class SPLEntry;
 class SPL
 {
 public:
 class SPL
 {
 public:
+       SPL () {}
+       SPL (boost::filesystem::path file);
+
        void as_xml (boost::filesystem::path file) const;
 
        std::string name;
        void as_xml (boost::filesystem::path file) const;
 
        std::string name;
index 0b84d1c349989cde59ca30f0f906ff0ee95c0cb0..e855a1cc6042dd582f7bcf19f15de724391117e5 100644 (file)
@@ -51,6 +51,7 @@
 #include "lib/scoped_temporary.h"
 #include "lib/monitor_checker.h"
 #include <dcp/dcp.h>
 #include "lib/scoped_temporary.h"
 #include "lib/monitor_checker.h"
 #include <dcp/dcp.h>
+#include <dcp/raw_convert.h>
 #include <wx/wx.h>
 #include <wx/stdpaths.h>
 #include <wx/splash.h>
 #include <wx/wx.h>
 #include <wx/stdpaths.h>
 #include <wx/splash.h>
@@ -173,6 +174,9 @@ public:
                _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
                _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
                _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
                _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
                _viewer->Seeked.connect (bind(&DOMFrame::playback_seeked, this, _1));
                _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+               _viewer->PositionChanged.connect (bind(&DOMFrame::position_changed, this));
+#endif
                _info = new PlayerInformation (_overall_panel, _viewer);
                setup_main_sizer (Config::instance()->player_mode());
 #ifdef __WXOSX__
                _info = new PlayerInformation (_overall_panel, _viewer);
                setup_main_sizer (Config::instance()->player_mode());
 #ifdef __WXOSX__
@@ -203,6 +207,38 @@ public:
                MonitorChecker::instance()->run ();
 #endif
                setup_screen ();
                MonitorChecker::instance()->run ();
 #endif
                setup_screen ();
+
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+               if (
+                       boost::filesystem::is_regular_file(Config::path("position")) &&
+                       boost::filesystem::is_regular_file(Config::path("spl.xml"))) {
+
+                       set_spl (SPL(Config::path("spl.xml")));
+                       FILE* f = fopen_boost (Config::path("position"), "r");
+                       if (f) {
+                               char buffer[64];
+                               fscanf (f, "%63s", buffer);
+                               _viewer->seek (DCPTime(atoi(buffer)), true);
+                               _viewer->start ();
+                               fclose (f);
+                       }
+               }
+
+#endif
+       }
+
+       void position_changed ()
+       {
+               if (!_viewer->playing() || _viewer->position().get() % DCPTime::HZ) {
+                       return;
+               }
+
+               FILE* f = fopen_boost (Config::path("position"), "w");
+               if (f) {
+                       string const p = dcp::raw_convert<string> (_viewer->position().get());
+                       fwrite (p.c_str(), p.length(), 1, f);
+                       fclose (f);
+               }
        }
 
        void monitor_checker_state_changed ()
        }
 
        void monitor_checker_state_changed ()
@@ -296,6 +332,14 @@ public:
 
        void playback_stopped (DCPTime time)
        {
 
        void playback_stopped (DCPTime time)
        {
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+               try {
+                       boost::filesystem::remove (Config::path("position"));
+               } catch (...) {
+                       /* Never mind */
+               }
+#endif
+
                optional<boost::filesystem::path> log = Config::instance()->player_log_file();
                if (!log) {
                        return;
                optional<boost::filesystem::path> log = Config::instance()->player_log_file();
                if (!log) {
                        return;
@@ -370,6 +414,10 @@ public:
 
        void set_spl (SPL spl)
        {
 
        void set_spl (SPL spl)
        {
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+               spl.as_xml (Config::path("spl.xml"));
+#endif
+
                if (_viewer->playing ()) {
                        _viewer->stop ();
                }
                if (_viewer->playing ()) {
                        _viewer->stop ();
                }
@@ -1077,6 +1125,8 @@ private:
                */
                Config::drop ();
 
                */
                Config::drop ();
 
+               signal_manager = new wxSignalManager (this);
+
                _frame = new DOMFrame ();
                SetTopWindow (_frame);
                _frame->Maximize ();
                _frame = new DOMFrame ();
                SetTopWindow (_frame);
                _frame->Maximize ();
@@ -1085,8 +1135,6 @@ private:
                }
                _frame->Show ();
 
                }
                _frame->Show ();
 
-               signal_manager = new wxSignalManager (this);
-
                PlayServer* server = new PlayServer (_frame);
                new thread (boost::bind (&PlayServer::run, server));
 
                PlayServer* server = new PlayServer (_frame);
                new thread (boost::bind (&PlayServer::run, server));