Fix crash when using the player with automatic audio analysis enabled in prefs (...
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 844d92bc81b5fe21dd3eb283d0139e25a6904fa4..550b89ed425944aa2ea6890bb3210ccae8d9f9ca 100644 (file)
@@ -27,7 +27,8 @@
 #include "wx/update_dialog.h"
 #include "wx/player_config_dialog.h"
 #include "wx/verify_dcp_dialog.h"
-#include "wx/controls.h"
+#include "wx/standard_controls.h"
+#include "wx/swaroop_controls.h"
 #include "lib/cross.h"
 #include "lib/config.h"
 #include "lib/util.h"
@@ -38,6 +39,7 @@
 #include "lib/job_manager.h"
 #include "lib/job.h"
 #include "lib/film.h"
+#include "lib/null_log.h"
 #include "lib/video_content.h"
 #include "lib/text_content.h"
 #include "lib/ratio.h"
@@ -48,6 +50,9 @@
 #include "lib/dcpomatic_socket.h"
 #include "lib/scoped_temporary.h"
 #include "lib/monitor_checker.h"
+#include "lib/lock_file_checker.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/dcpomatic_log.h"
 #include <dcp/dcp.h>
 #include <dcp/raw_convert.h>
 #include <dcp/exceptions.h>
@@ -76,6 +81,7 @@ using std::list;
 using std::exception;
 using std::vector;
 using boost::shared_ptr;
+using boost::weak_ptr;
 using boost::scoped_array;
 using boost::optional;
 using boost::dynamic_pointer_cast;
@@ -124,6 +130,7 @@ public:
                , _view_full_screen (0)
                , _view_dual_screen (0)
        {
+               dcpomatic_log.reset (new NullLog());
 
 #if defined(DCPOMATIC_WINDOWS)
                maybe_open_console ();
@@ -167,7 +174,13 @@ public:
                _overall_panel = new wxPanel (this, wxID_ANY);
 
                _viewer.reset (new FilmViewer (_overall_panel));
-               _controls = new Controls (_overall_panel, _viewer, false);
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+               SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
+               _controls = sc;
+               sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
+#else
+               _controls = new StandardControls (_overall_panel, _viewer, false);
+#endif
                _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, _1));
@@ -205,6 +218,8 @@ public:
 #ifdef DCPOMATIC_VARIANT_SWAROOP
                MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
                MonitorChecker::instance()->run ();
+               LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
+               LockFileChecker::instance()->run ();
 #endif
                setup_screen ();
 
@@ -247,8 +262,16 @@ public:
        void monitor_checker_state_changed ()
        {
                if (!MonitorChecker::instance()->ok()) {
+                       _viewer->stop ();
                        error_dialog (this, _("The required display devices are not connected correctly."));
+               }
+       }
+
+       void lock_checker_state_changed ()
+       {
+               if (!LockFileChecker::instance()->ok()) {
                        _viewer->stop ();
+                       error_dialog (this, _("The lock file is not present."));
                }
        }
 #endif
@@ -272,6 +295,10 @@ public:
                        error_dialog (this, _("The required display devices are not connected correctly."));
                        return false;
                }
+               if (!LockFileChecker::instance()->ok()) {
+                       error_dialog (this, _("The lock file is not present."));
+                       return false;
+               }
 #endif
                if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
                        return true;
@@ -299,26 +326,42 @@ public:
                        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;
+               FILE* f = fopen_boost(*log, "a");
+
+               /* XXX: this only logs the first piece of content; probably should be each piece? */
+
+               shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
+               if (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);
+
+                       fprintf (
+                               f,
+                               "%s playback-started %s %s %s\n",
+                               dcp::LocalTime().as_string().c_str(),
+                               time.timecode(_film->video_frame_rate()).c_str(),
+                               dcp->directories().front().string().c_str(),
+                               playing_cpl->annotation_text().c_str()
+                               );
+               }
+
+               shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
+               if (ffmpeg) {
+                       fprintf (
+                               f,
+                               "%s playback-started %s %s\n",
+                               dcp::LocalTime().as_string().c_str(),
+                               time.timecode(_film->video_frame_rate()).c_str(),
+                               ffmpeg->path(0).string().c_str()
+                               );
                }
-               DCPOMATIC_ASSERT (playing_cpl)
 
-               FILE* f = fopen_boost(*log, "a");
-               fprintf (
-                       f,
-                       "%s playback-started %s %s %s\n",
-                       dcp::LocalTime().as_string().c_str(),
-                       time.timecode(_film->video_frame_rate()).c_str(),
-                       dcp->directories().front().string().c_str(),
-                       playing_cpl->annotation_text().c_str()
-                       );
                fclose (f);
        }
 
@@ -365,10 +408,11 @@ public:
        {
                DCPOMATIC_ASSERT (_film);
 
+               reset_film ();
                try {
-                       shared_ptr<DCPContent> dcp (new DCPContent(_film, dir));
-                       _film->examine_and_add_content (dcp);
-                       bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading DCP"));
+                       shared_ptr<DCPContent> dcp (new DCPContent(dir));
+                       _film->examine_and_add_content (dcp, true);
+                       bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
                        if (!ok || !report_errors_from_last_job(this)) {
                                return;
                        }
@@ -421,11 +465,21 @@ public:
                return optional<dcp::EncryptedKDM>();
        }
 
+       void reset_film_weak (weak_ptr<Film> weak_film)
+       {
+               shared_ptr<Film> film = weak_film.lock ();
+               if (film) {
+                       reset_film (film);
+               }
+       }
+
        void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
        {
                _film = film;
                _viewer->set_film (_film);
+               _controls->set_film (_film);
                _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
+               _info->triggered_update ();
        }
 
        void film_changed (ChangeType type, Film::Property property)
@@ -451,12 +505,12 @@ public:
                                kdm = get_kdm_from_url (dcp);
 #endif
                                if (!kdm) {
-                                       get_kdm_from_directory (dcp);
+                                       kdm = get_kdm_from_directory (dcp);
                                }
 
                                if (kdm) {
                                        dcp->add_kdm (*kdm);
-                                       dcp->examine (shared_ptr<Job>());
+                                       dcp->examine (_film, shared_ptr<Job>());
                                }
                        }
 
@@ -630,7 +684,7 @@ private:
                        DCPOMATIC_ASSERT (dcp);
                        dcp->add_ov (wx_to_std(c->GetPath()));
                        JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
-                       bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading DCP"));
+                       bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
                        if (!ok || !report_errors_from_last_job(this)) {
                                return;
                        }
@@ -659,7 +713,7 @@ private:
                        DCPOMATIC_ASSERT (dcp);
                        try {
                                dcp->add_kdm (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)));
-                               dcp->examine (shared_ptr<Job>());
+                               dcp->examine (_film, shared_ptr<Job>());
                        } catch (exception& e) {
                                error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
                                d->Destroy ();
@@ -720,7 +774,7 @@ private:
                }
 
                dcp->set_cpl ((*i)->id());
-               dcp->examine (shared_ptr<Job>());
+               dcp->examine (_film, shared_ptr<Job>());
        }
 
        void view_full_screen ()
@@ -758,10 +812,10 @@ private:
        void setup_screen ()
        {
                _controls->Show (_mode != Config::PLAYER_MODE_FULL);
-               _controls->show_extended_player_controls (_mode == Config::PLAYER_MODE_DUAL);
                _info->Show (_mode != Config::PLAYER_MODE_FULL);
                _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
                ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
+               _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
 
                if (_mode == Config::PLAYER_MODE_DUAL) {
                        _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));