2 Copyright (C) 2017-2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "wx/wx_signal_manager.h"
22 #include "wx/wx_util.h"
23 #include "wx/about_dialog.h"
24 #include "wx/report_problem_dialog.h"
25 #include "wx/film_viewer.h"
26 #include "wx/player_information.h"
27 #include "wx/update_dialog.h"
28 #include "wx/player_config_dialog.h"
29 #include "wx/verify_dcp_dialog.h"
30 #include "wx/standard_controls.h"
31 #include "wx/playlist_controls.h"
32 #ifdef DCPOMATIC_VARIANT_SWAROOP
33 #include "wx/swaroop_controls.h"
35 #include "wx/timer_display.h"
36 #include "wx/system_information_dialog.h"
37 #include "wx/player_stress_tester.h"
38 #include "lib/cross.h"
39 #include "lib/config.h"
41 #include "lib/internet.h"
42 #include "lib/update_checker.h"
43 #include "lib/compose.hpp"
44 #include "lib/dcp_content.h"
45 #include "lib/job_manager.h"
48 #include "lib/null_log.h"
49 #include "lib/video_content.h"
50 #include "lib/text_content.h"
51 #include "lib/ratio.h"
52 #include "lib/verify_dcp_job.h"
53 #include "lib/dcp_examiner.h"
54 #include "lib/examine_content_job.h"
55 #include "lib/server.h"
56 #include "lib/dcpomatic_socket.h"
57 #include "lib/scoped_temporary.h"
58 #include "lib/monitor_checker.h"
59 #include "lib/lock_file_checker.h"
60 #include "lib/ffmpeg_content.h"
61 #include "lib/dcpomatic_log.h"
62 #include "lib/file_log.h"
64 #include <dcp/raw_convert.h>
65 #include <dcp/exceptions.h>
67 #include <wx/stdpaths.h>
68 #include <wx/splash.h>
69 #include <wx/cmdline.h>
70 #include <wx/preferences.h>
71 #include <wx/progdlg.h>
72 #include <wx/display.h>
77 #include <ApplicationServices/ApplicationServices.h>
79 #include <boost/bind.hpp>
80 #include <boost/algorithm/string.hpp>
94 using boost::shared_ptr;
95 using boost::weak_ptr;
96 using boost::scoped_array;
97 using boost::optional;
98 using boost::dynamic_pointer_cast;
101 using dcp::raw_convert;
102 using namespace dcpomatic;
109 /* Allow spare IDs after _history for the recent files list */
112 /* Allow spare IDs for CPLs */
113 ID_view_full_screen = 200,
115 ID_view_closed_captions,
116 ID_view_scale_appropriate,
119 ID_view_scale_quarter,
120 ID_help_report_a_problem,
122 ID_tools_check_for_updates,
124 ID_tools_system_information,
125 /* IDs for shortcuts (with no associated menu item) */
131 class DOMFrame : public wxFrame
135 : wxFrame (0, -1, _("DCP-o-matic Player"))
137 , _update_news_requested (false)
139 , _mode (Config::instance()->player_mode())
143 , _history_position (0)
144 , _history_separator (0)
145 , _system_information_dialog (0)
146 , _view_full_screen (0)
147 , _view_dual_screen (0)
149 dcpomatic_log.reset (new NullLog());
151 #if defined(DCPOMATIC_WINDOWS)
152 maybe_open_console ();
153 cout << "DCP-o-matic Player is starting." << "\n";
156 wxMenuBar* bar = new wxMenuBar;
158 set_menu_sensitivity ();
161 #ifdef DCPOMATIC_WINDOWS
162 SetIcon (wxIcon (std_to_wx ("id")));
165 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
166 update_from_config (Config::PLAYER_DEBUG_LOG);
168 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
169 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
170 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
171 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
172 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
173 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
174 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
175 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
182 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
183 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
184 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
185 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
189 /* Use a panel as the only child of the Frame so that we avoid
190 the dark-grey background on Windows.
192 _overall_panel = new wxPanel (this, wxID_ANY);
194 _viewer.reset (new FilmViewer (_overall_panel));
195 #ifdef DCPOMATIC_VARIANT_SWAROOP
196 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
198 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
200 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
201 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
203 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
205 _controls = new StandardControls (_overall_panel, _viewer, false);
208 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
209 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
210 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
211 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
212 _info = new PlayerInformation (_overall_panel, _viewer);
213 setup_main_sizer (Config::instance()->player_mode());
215 int accelerators = 4;
217 int accelerators = 3;
220 _stress.setup (this, _controls);
222 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
223 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
224 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
225 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
227 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
229 wxAcceleratorTable accel_table (accelerators, accel);
230 SetAcceleratorTable (accel_table);
233 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
234 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
235 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
239 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
240 #ifdef DCPOMATIC_VARIANT_SWAROOP
241 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
242 MonitorChecker::instance()->run ();
243 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
244 LockFileChecker::instance()->run ();
248 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
250 #ifdef DCPOMATIC_VARIANT_SWAROOP
251 sc->check_restart ();
255 #ifdef DCPOMATIC_VARIANT_SWAROOP
256 void monitor_checker_state_changed ()
258 if (!MonitorChecker::instance()->ok()) {
260 error_dialog (this, _("The required display devices are not connected correctly."));
264 void lock_checker_state_changed ()
266 if (!LockFileChecker::instance()->ok()) {
268 error_dialog (this, _("The lock file is not present."));
273 void setup_main_sizer (Config::PlayerMode mode)
275 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
276 if (mode != Config::PLAYER_MODE_DUAL) {
277 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
279 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
280 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
281 _overall_panel->SetSizer (main_sizer);
282 _overall_panel->Layout ();
285 bool playback_permitted ()
287 #ifdef DCPOMATIC_VARIANT_SWAROOP
288 if (!MonitorChecker::instance()->ok()) {
289 error_dialog (this, _("The required display devices are not connected correctly."));
292 if (!LockFileChecker::instance()->ok()) {
293 error_dialog (this, _("The lock file is not present."));
297 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
302 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
303 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
304 if (d && !d->kdm_timing_window_valid()) {
309 #ifdef DCPOMATIC_VARIANT_SWAROOP
310 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
311 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
312 if (c && !c->kdm_timing_window_valid()) {
319 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
325 void playback_started (DCPTime time)
327 /* XXX: this only logs the first piece of content; probably should be each piece? */
328 if (_film->content().empty()) {
332 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
334 DCPExaminer ex (dcp, true);
335 shared_ptr<dcp::CPL> playing_cpl;
336 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
337 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
341 DCPOMATIC_ASSERT (playing_cpl);
345 "playback-started %s %s %s",
346 time.timecode(_film->video_frame_rate()).c_str(),
347 dcp->directories().front().string().c_str(),
348 playing_cpl->annotation_text().c_str()
353 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
357 "playback-started %s %s",
358 time.timecode(_film->video_frame_rate()).c_str(),
359 ffmpeg->path(0).string().c_str()
365 void playback_stopped (DCPTime time)
367 #ifdef DCPOMATIC_VARIANT_SWAROOP
369 boost::filesystem::remove (Config::path("position"));
375 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
378 void set_decode_reduction (optional<int> reduction)
380 _viewer->set_dcp_decode_reduction (reduction);
381 _info->triggered_update ();
382 Config::instance()->set_decode_reduction (reduction);
385 void load_dcp (boost::filesystem::path dir)
387 DCPOMATIC_ASSERT (_film);
391 _stress.set_suspended (true);
392 shared_ptr<DCPContent> dcp (new DCPContent(dir));
393 shared_ptr<Job> job (new ExamineContentJob(_film, dcp));
394 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
395 JobManager::instance()->add (job);
396 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
397 if (!ok || !report_errors_from_last_job(this)) {
400 #ifndef DCPOMATIC_VARIANT_SWAROOP
401 Config::instance()->add_to_player_history (dir);
403 } catch (dcp::ReadError& e) {
404 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
408 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
410 shared_ptr<Job> job = weak_job.lock ();
411 if (!job || !job->finished_ok()) {
415 shared_ptr<Content> content = weak_content.lock ();
420 _film->add_content (content);
421 _stress.set_suspended (false);
424 void reset_film_weak (weak_ptr<Film> weak_film)
426 shared_ptr<Film> film = weak_film.lock ();
432 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
435 _film->set_tolerant (true);
436 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
437 _viewer->set_film (_film);
438 _controls->set_film (_film);
439 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
440 _info->triggered_update ();
443 void film_changed (ChangeType type, Film::Property property)
445 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
449 if (_viewer->playing ()) {
453 /* Start off as Flat */
454 _film->set_container (Ratio::from_id("185"));
456 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
457 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
459 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
464 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
465 if (r->id() == "239") {
466 /* Any scope content means we use scope */
467 _film->set_container(r);
471 /* Any 3D content means we use 3D mode */
472 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
473 _film->set_three_d (true);
477 _viewer->seek (DCPTime(), true);
478 _info->triggered_update ();
480 set_menu_sensitivity ();
482 wxMenuItemList old = _cpl_menu->GetMenuItems();
483 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
484 _cpl_menu->Remove (*i);
487 if (_film->content().size() == 1) {
488 /* Offer a CPL menu */
489 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
491 DCPExaminer ex (first, true);
492 int id = ID_view_cpl;
493 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
494 wxMenuItem* j = _cpl_menu->AppendRadioItem(
496 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
498 j->Check(!first->cpl() || i->id() == *first->cpl());
505 void load_stress_script (boost::filesystem::path path)
507 _stress.load_script (path);
512 bool report_errors_from_last_job (wxWindow* parent) const
514 JobManager* jm = JobManager::instance ();
516 DCPOMATIC_ASSERT (!jm->get().empty());
518 shared_ptr<Job> last = jm->get().back();
519 if (last->finished_in_error()) {
520 error_dialog(parent, wxString::Format(_("Could not load DCP.\n\n%s."), std_to_wx(last->error_summary()).data()), std_to_wx(last->error_details()));
527 void setup_menu (wxMenuBar* m)
529 _file_menu = new wxMenu;
530 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
531 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
532 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
534 _history_position = _file_menu->GetMenuItems().GetCount();
536 _file_menu->AppendSeparator ();
537 _file_menu->Append (ID_file_close, _("&Close"));
538 _file_menu->AppendSeparator ();
541 _file_menu->Append (wxID_EXIT, _("&Exit"));
543 _file_menu->Append (wxID_EXIT, _("&Quit"));
547 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
549 wxMenu* edit = new wxMenu;
550 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
553 prefs->Enable (Config::instance()->have_write_permission());
555 _cpl_menu = new wxMenu;
557 wxMenu* view = new wxMenu;
558 optional<int> c = Config::instance()->decode_reduction();
559 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
560 view->AppendSeparator();
561 #ifndef DCPOMATIC_VARIANT_SWAROOP
562 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
563 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
566 view->AppendSeparator();
567 view->Append(ID_view_closed_captions, _("Closed captions..."));
568 view->AppendSeparator();
569 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
570 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
571 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
572 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
574 wxMenu* tools = new wxMenu;
575 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
576 tools->AppendSeparator ();
577 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
578 tools->Append (ID_tools_timing, _("Timing..."));
579 tools->Append (ID_tools_system_information, _("System information..."));
581 wxMenu* help = new wxMenu;
583 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
585 help->Append (wxID_ABOUT, _("About"));
587 help->Append (ID_help_report_a_problem, _("Report a problem..."));
589 m->Append (_file_menu, _("&File"));
591 m->Append (edit, _("&Edit"));
593 m->Append (view, _("&View"));
594 m->Append (tools, _("&Tools"));
595 m->Append (help, _("&Help"));
600 wxString d = wxStandardPaths::Get().GetDocumentsDir();
601 if (Config::instance()->last_player_load_directory()) {
602 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
605 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
610 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
611 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
618 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
620 Config::instance()->set_last_player_load_directory (dcp.parent_path());
628 wxDirDialog* c = new wxDirDialog (
630 _("Select DCP to open as OV"),
631 wxStandardPaths::Get().GetDocumentsDir(),
632 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
638 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
639 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
646 DCPOMATIC_ASSERT (_film);
647 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
648 DCPOMATIC_ASSERT (dcp);
649 dcp->add_ov (wx_to_std(c->GetPath()));
650 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
651 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
652 if (!ok || !report_errors_from_last_job(this)) {
655 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
659 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
661 _film->set_container(r);
667 _info->triggered_update ();
672 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
674 if (d->ShowModal() == wxID_OK) {
675 DCPOMATIC_ASSERT (_film);
676 #ifdef DCPOMATIC_VARIANT_SWAROOP
677 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
680 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
681 } catch (exception& e) {
682 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
688 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
689 #ifndef DCPOMATIC_VARIANT_SWAROOP
690 DCPOMATIC_ASSERT (dcp);
694 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
695 dcp->examine (_film, shared_ptr<Job>());
697 } catch (exception& e) {
698 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
705 _info->triggered_update ();
708 void file_history (wxCommandEvent& event)
710 vector<boost::filesystem::path> history = Config::instance()->player_history ();
711 int n = event.GetId() - ID_file_history;
712 if (n >= 0 && n < static_cast<int> (history.size ())) {
714 load_dcp (history[n]);
715 } catch (exception& e) {
716 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
724 _info->triggered_update ();
725 set_menu_sensitivity ();
733 void edit_preferences ()
735 if (!Config::instance()->have_write_permission()) {
739 if (!_config_dialog) {
740 _config_dialog = create_player_config_dialog ();
742 _config_dialog->Show (this);
745 void view_cpl (wxCommandEvent& ev)
747 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
748 DCPOMATIC_ASSERT (dcp);
749 DCPExaminer ex (dcp, true);
750 int id = ev.GetId() - ID_view_cpl;
751 DCPOMATIC_ASSERT (id >= 0);
752 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
753 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
754 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
760 dcp->set_cpl ((*i)->id());
761 dcp->examine (_film, shared_ptr<Job>());
764 void view_full_screen ()
766 if (_mode == Config::PLAYER_MODE_FULL) {
767 _mode = Config::PLAYER_MODE_WINDOW;
769 _mode = Config::PLAYER_MODE_FULL;
775 void view_dual_screen ()
777 if (_mode == Config::PLAYER_MODE_DUAL) {
778 _mode = Config::PLAYER_MODE_WINDOW;
780 _mode = Config::PLAYER_MODE_DUAL;
788 if (_view_full_screen) {
789 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
791 if (_view_dual_screen) {
792 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
798 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
799 _info->Show (_mode != Config::PLAYER_MODE_FULL);
800 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
801 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
802 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
804 if (_mode == Config::PLAYER_MODE_DUAL) {
805 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
806 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
807 _dual_screen->ShowFullScreen (true);
808 _viewer->panel()->Reparent (_dual_screen);
809 _dual_screen->Show ();
810 if (wxDisplay::GetCount() > 1) {
811 switch (Config::instance()->image_display()) {
813 _dual_screen->Move (0, 0);
814 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
817 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
818 // (0, 0) doesn't seem to work for some strange reason
825 _viewer->panel()->Reparent (_overall_panel);
826 _dual_screen->Destroy ();
831 setup_main_sizer (_mode);
834 void view_closed_captions ()
836 _viewer->show_closed_captions ();
841 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
842 DCPOMATIC_ASSERT (dcp);
844 JobManager* jm = JobManager::instance ();
845 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
846 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
851 DCPOMATIC_ASSERT (!jm->get().empty());
852 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
853 DCPOMATIC_ASSERT (last);
855 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
860 void tools_check_for_updates ()
862 UpdateChecker::instance()->run ();
863 _update_news_requested = true;
868 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
873 void tools_system_information ()
875 if (!_system_information_dialog) {
876 _system_information_dialog = new SystemInformationDialog (this, _viewer);
879 _system_information_dialog->Show ();
884 AboutDialog* d = new AboutDialog (this);
889 void help_report_a_problem ()
891 ReportProblemDialog* d = new ReportProblemDialog (this);
892 if (d->ShowModal () == wxID_OK) {
898 void update_checker_state_changed ()
900 UpdateChecker* uc = UpdateChecker::instance ();
902 bool const announce =
903 _update_news_requested ||
904 (uc->stable() && Config::instance()->check_for_updates()) ||
905 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
907 _update_news_requested = false;
913 if (uc->state() == UpdateChecker::YES) {
914 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
915 dialog->ShowModal ();
917 } else if (uc->state() == UpdateChecker::FAILED) {
918 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
920 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
923 _update_news_requested = false;
926 void config_changed (Config::Property prop)
928 /* Instantly save any config changes when using the player GUI */
930 Config::instance()->write_config();
931 } catch (FileError& e) {
932 if (prop != Config::HISTORY) {
936 _("Could not write to config file at %s. Your changes have not been saved."),
937 std_to_wx(e.file().string())
941 } catch (exception& e) {
944 _("Could not write to config file. Your changes have not been saved.")
948 update_from_config (prop);
951 void update_from_config (Config::Property prop)
953 for (int i = 0; i < _history_items; ++i) {
954 delete _file_menu->Remove (ID_file_history + i);
957 if (_history_separator) {
958 _file_menu->Remove (_history_separator);
960 delete _history_separator;
961 _history_separator = 0;
963 int pos = _history_position;
965 /* Clear out non-existant history items before we re-build the menu */
966 Config::instance()->clean_player_history ();
967 vector<boost::filesystem::path> history = Config::instance()->player_history ();
969 if (!history.empty ()) {
970 _history_separator = _file_menu->InsertSeparator (pos++);
973 for (size_t i = 0; i < history.size(); ++i) {
976 s = String::compose ("&%1 %2", i + 1, history[i].string());
978 s = history[i].string();
980 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
983 _history_items = history.size ();
985 if (prop == Config::PLAYER_DEBUG_LOG) {
986 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
988 dcpomatic_log.reset (new FileLog(*p));
990 dcpomatic_log.reset (new NullLog());
992 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
996 void set_menu_sensitivity ()
998 _tools_verify->Enable (static_cast<bool>(_film));
999 _file_add_ov->Enable (static_cast<bool>(_film));
1000 _file_add_kdm->Enable (static_cast<bool>(_film));
1001 _view_cpl->Enable (static_cast<bool>(_film));
1004 void start_stop_pressed ()
1006 if (_viewer->playing()) {
1015 _viewer->seek_by (-_viewer->one_video_frame(), true);
1018 void forward_frame ()
1020 _viewer->seek_by (_viewer->one_video_frame(), true);
1023 wxFrame* _dual_screen;
1024 bool _update_news_requested;
1025 PlayerInformation* _info;
1026 Config::PlayerMode _mode;
1027 wxPreferencesEditor* _config_dialog;
1028 wxPanel* _overall_panel;
1030 wxMenuItem* _view_cpl;
1033 int _history_position;
1034 wxMenuItem* _history_separator;
1035 shared_ptr<FilmViewer> _viewer;
1036 Controls* _controls;
1037 SystemInformationDialog* _system_information_dialog;
1038 boost::shared_ptr<Film> _film;
1039 boost::signals2::scoped_connection _config_changed_connection;
1040 boost::signals2::scoped_connection _examine_job_connection;
1041 wxMenuItem* _file_add_ov;
1042 wxMenuItem* _file_add_kdm;
1043 wxMenuItem* _tools_verify;
1044 wxMenuItem* _view_full_screen;
1045 wxMenuItem* _view_dual_screen;
1046 PlayerStressTester _stress;
1049 static const wxCmdLineEntryDesc command_line_description[] = {
1050 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1051 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1052 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1053 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1056 class PlayServer : public Server
1059 explicit PlayServer (DOMFrame* frame)
1060 : Server (PLAYER_PLAY_PORT)
1064 void handle (shared_ptr<Socket> socket)
1067 int const length = socket->read_uint32 ();
1068 scoped_array<char> buffer (new char[length]);
1069 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1070 string s (buffer.get());
1071 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1072 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1083 * @brief The magic App class for wxWidgets.
1085 class App : public wxApp
1092 #ifdef DCPOMATIC_LINUX
1101 wxSplashScreen* splash = 0;
1103 wxInitAllImageHandlers ();
1105 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1106 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1108 splash = maybe_show_splash ();
1110 SetAppName (_("DCP-o-matic Player"));
1112 if (!wxApp::OnInit()) {
1116 #ifdef DCPOMATIC_LINUX
1117 unsetenv ("UBUNTU_MENUPROXY");
1121 ProcessSerialNumber serial;
1122 GetCurrentProcess (&serial);
1123 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1126 dcpomatic_setup_path_encoding ();
1128 /* Enable i18n; this will create a Config object
1129 to look for a force-configured language. This Config
1130 object will be wrong, however, because dcpomatic_setup
1131 hasn't yet been called and there aren't any filters etc.
1134 dcpomatic_setup_i18n ();
1136 /* Set things up, including filters etc.
1137 which will now be internationalised correctly.
1141 /* Force the configuration to be re-loaded correctly next
1146 signal_manager = new wxSignalManager (this);
1148 _frame = new DOMFrame ();
1149 SetTopWindow (_frame);
1150 _frame->Maximize ();
1157 PlayServer* server = new PlayServer (_frame);
1158 new thread (boost::bind (&PlayServer::run, server));
1160 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1162 _frame->load_dcp (_dcp_to_load);
1163 } catch (exception& e) {
1164 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1170 _frame->load_stress_script (*_stress);
1171 } catch (exception& e) {
1172 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1176 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1178 if (Config::instance()->check_for_updates ()) {
1179 UpdateChecker::instance()->run ();
1182 catch (exception& e)
1187 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1193 void OnInitCmdLine (wxCmdLineParser& parser)
1195 parser.SetDesc (command_line_description);
1196 parser.SetSwitchChars (wxT ("-"));
1199 bool OnCmdLineParsed (wxCmdLineParser& parser)
1201 if (parser.GetParamCount() > 0) {
1202 _dcp_to_load = wx_to_std (parser.GetParam (0));
1206 if (parser.Found("c", &config)) {
1207 Config::override_path = wx_to_std (config);
1210 if (parser.Found("s", &stress)) {
1211 _stress = wx_to_std (stress);
1217 void report_exception ()
1221 } catch (FileError& e) {
1225 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1226 std_to_wx (e.what()),
1227 std_to_wx (e.file().string().c_str ())
1230 } catch (exception& e) {
1234 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1235 std_to_wx (e.what ())
1239 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1243 /* An unhandled exception has occurred inside the main event loop */
1244 bool OnExceptionInMainLoop ()
1246 report_exception ();
1247 /* This will terminate the program */
1251 void OnUnhandledException ()
1253 report_exception ();
1258 signal_manager->ui_idle ();
1261 void config_failed_to_load ()
1263 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1266 void config_warning (string m)
1268 message_dialog (_frame, std_to_wx (m));
1272 string _dcp_to_load;
1273 boost::optional<string> _stress;