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>
76 #include <boost/bind.hpp>
77 #include <boost/algorithm/string.hpp>
91 using boost::shared_ptr;
92 using boost::weak_ptr;
93 using boost::scoped_array;
94 using boost::optional;
95 using boost::dynamic_pointer_cast;
98 using dcp::raw_convert;
99 using namespace dcpomatic;
106 /* Allow spare IDs after _history for the recent files list */
109 /* Allow spare IDs for CPLs */
110 ID_view_full_screen = 200,
112 ID_view_closed_captions,
113 ID_view_scale_appropriate,
116 ID_view_scale_quarter,
117 ID_help_report_a_problem,
119 ID_tools_check_for_updates,
121 ID_tools_system_information,
122 /* IDs for shortcuts (with no associated menu item) */
126 ID_go_back_small_amount,
127 ID_go_forward_small_amount,
128 ID_go_back_medium_amount,
129 ID_go_forward_medium_amount,
130 ID_go_back_large_amount,
131 ID_go_forward_large_amount,
136 class DOMFrame : public wxFrame
140 : wxFrame (0, -1, _("DCP-o-matic Player"))
142 , _update_news_requested (false)
144 , _mode (Config::instance()->player_mode())
148 , _history_position (0)
149 , _history_separator (0)
150 , _system_information_dialog (0)
151 , _view_full_screen (0)
152 , _view_dual_screen (0)
153 , _main_sizer (new wxBoxSizer (wxVERTICAL))
155 dcpomatic_log.reset (new NullLog());
157 #if defined(DCPOMATIC_WINDOWS)
158 maybe_open_console ();
159 cout << "DCP-o-matic Player is starting." << "\n";
162 wxMenuBar* bar = new wxMenuBar;
164 set_menu_sensitivity ();
167 #ifdef DCPOMATIC_WINDOWS
168 SetIcon (wxIcon (std_to_wx ("id")));
171 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
172 update_from_config (Config::PLAYER_DEBUG_LOG);
174 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
175 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
182 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
183 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
184 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
185 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
188 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
189 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
190 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
192 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
193 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
195 /* Use a panel as the only child of the Frame so that we avoid
196 the dark-grey background on Windows.
198 _overall_panel = new wxPanel (this, wxID_ANY);
200 _viewer.reset (new FilmViewer (_overall_panel));
201 #ifdef DCPOMATIC_VARIANT_SWAROOP
202 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
204 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
206 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
207 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
209 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
211 _controls = new StandardControls (_overall_panel, _viewer, false);
214 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
215 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
216 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
217 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
218 _info = new PlayerInformation (_overall_panel, _viewer);
219 setup_main_sizer (Config::instance()->player_mode());
221 int accelerators = 12;
223 int accelerators = 11;
226 _stress.setup (this, _controls);
228 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
229 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
230 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_go_back_frame);
231 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_go_forward_frame);
232 accel[3].Set(wxACCEL_SHIFT, WXK_LEFT, ID_go_back_small_amount);
233 accel[4].Set(wxACCEL_SHIFT, WXK_RIGHT, ID_go_forward_small_amount);
234 accel[5].Set(wxACCEL_CTRL, WXK_LEFT, ID_go_back_medium_amount);
235 accel[6].Set(wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_medium_amount);
236 accel[7].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_LEFT, ID_go_back_large_amount);
237 accel[8].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_large_amount);
238 accel[9].Set(wxACCEL_NORMAL, WXK_HOME, ID_go_to_start);
239 accel[10].Set(wxACCEL_NORMAL, WXK_END, ID_go_to_end);
241 accel[11].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
243 wxAcceleratorTable accel_table (accelerators, accel);
244 SetAcceleratorTable (accel_table);
247 Bind (wxEVT_MENU, boost::bind(&DOMFrame::start_stop_pressed, this), ID_start_stop);
248 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_back_frame, this), ID_go_back_frame);
249 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_forward_frame, this), ID_go_forward_frame);
250 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -60), ID_go_back_small_amount);
251 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 60), ID_go_forward_small_amount);
252 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -600), ID_go_back_medium_amount);
253 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 600), ID_go_forward_medium_amount);
254 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -3600), ID_go_back_large_amount);
255 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 3600), ID_go_forward_large_amount);
256 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_start, this), ID_go_to_start);
257 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_end, this), ID_go_to_end);
261 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
262 #ifdef DCPOMATIC_VARIANT_SWAROOP
263 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
264 MonitorChecker::instance()->run ();
265 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
266 LockFileChecker::instance()->run ();
270 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
272 #ifdef DCPOMATIC_VARIANT_SWAROOP
273 sc->check_restart ();
277 #ifdef DCPOMATIC_VARIANT_SWAROOP
278 void monitor_checker_state_changed ()
280 if (!MonitorChecker::instance()->ok()) {
282 error_dialog (this, _("The required display devices are not connected correctly."));
286 void lock_checker_state_changed ()
288 if (!LockFileChecker::instance()->ok()) {
290 error_dialog (this, _("The lock file is not present."));
295 void setup_main_sizer (Config::PlayerMode mode)
297 _main_sizer->Detach (_viewer->panel());
298 _main_sizer->Detach (_controls);
299 _main_sizer->Detach (_info);
300 if (mode != Config::PLAYER_MODE_DUAL) {
301 _main_sizer->Add (_viewer->panel(), 1, wxEXPAND);
303 _main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
304 _main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
305 _overall_panel->SetSizer (_main_sizer);
306 _overall_panel->Layout ();
309 bool playback_permitted ()
311 #ifdef DCPOMATIC_VARIANT_SWAROOP
312 if (!MonitorChecker::instance()->ok()) {
313 error_dialog (this, _("The required display devices are not connected correctly."));
316 if (!LockFileChecker::instance()->ok()) {
317 error_dialog (this, _("The lock file is not present."));
321 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
326 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
327 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
328 if (d && !d->kdm_timing_window_valid()) {
333 #ifdef DCPOMATIC_VARIANT_SWAROOP
334 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
335 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
336 if (c && !c->kdm_timing_window_valid()) {
343 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
349 void playback_started (DCPTime time)
351 /* XXX: this only logs the first piece of content; probably should be each piece? */
352 if (_film->content().empty()) {
356 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
358 DCPExaminer ex (dcp, true);
359 shared_ptr<dcp::CPL> playing_cpl;
360 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
361 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
365 DCPOMATIC_ASSERT (playing_cpl);
369 "playback-started %s %s %s",
370 time.timecode(_film->video_frame_rate()).c_str(),
371 dcp->directories().front().string().c_str(),
372 playing_cpl->annotation_text().c_str()
377 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
381 "playback-started %s %s",
382 time.timecode(_film->video_frame_rate()).c_str(),
383 ffmpeg->path(0).string().c_str()
389 void playback_stopped (DCPTime time)
391 #ifdef DCPOMATIC_VARIANT_SWAROOP
393 boost::filesystem::remove (Config::path("position"));
399 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
402 void set_decode_reduction (optional<int> reduction)
404 _viewer->set_dcp_decode_reduction (reduction);
405 _info->triggered_update ();
406 Config::instance()->set_decode_reduction (reduction);
409 void load_dcp (boost::filesystem::path dir)
411 DCPOMATIC_ASSERT (_film);
415 _stress.set_suspended (true);
416 shared_ptr<DCPContent> dcp (new DCPContent(dir));
417 shared_ptr<Job> job (new ExamineContentJob(_film, dcp));
418 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
419 JobManager::instance()->add (job);
420 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
421 if (!ok || !report_errors_from_last_job(this)) {
424 #ifndef DCPOMATIC_VARIANT_SWAROOP
425 Config::instance()->add_to_player_history (dir);
427 } catch (dcp::ReadError& e) {
428 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
429 } catch (DCPError& e) {
430 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
434 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
436 shared_ptr<Job> job = weak_job.lock ();
437 if (!job || !job->finished_ok()) {
441 shared_ptr<Content> content = weak_content.lock ();
446 _film->add_content (content);
447 _stress.set_suspended (false);
450 void reset_film_weak (weak_ptr<Film> weak_film)
452 shared_ptr<Film> film = weak_film.lock ();
458 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
461 _film->set_tolerant (true);
462 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
463 _viewer->set_film (_film);
464 _controls->set_film (_film);
465 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
466 _info->triggered_update ();
469 void film_changed (ChangeType type, Film::Property property)
471 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
475 if (_viewer->playing ()) {
479 /* Start off as Flat */
480 _film->set_container (Ratio::from_id("185"));
482 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
483 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
485 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
490 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
491 if (r->id() == "239") {
492 /* Any scope content means we use scope */
493 _film->set_container(r);
497 /* Any 3D content means we use 3D mode */
498 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
499 _film->set_three_d (true);
503 _viewer->seek (DCPTime(), true);
504 _info->triggered_update ();
506 set_menu_sensitivity ();
508 wxMenuItemList old = _cpl_menu->GetMenuItems();
509 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
510 _cpl_menu->Remove (*i);
513 if (_film->content().size() == 1) {
514 /* Offer a CPL menu */
515 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
517 DCPExaminer ex (first, true);
518 int id = ID_view_cpl;
519 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
520 wxMenuItem* j = _cpl_menu->AppendRadioItem(
522 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
524 j->Check(!first->cpl() || i->id() == *first->cpl());
531 void load_stress_script (boost::filesystem::path path)
533 _stress.load_script (path);
538 bool report_errors_from_last_job (wxWindow* parent) const
540 JobManager* jm = JobManager::instance ();
542 DCPOMATIC_ASSERT (!jm->get().empty());
544 shared_ptr<Job> last = jm->get().back();
545 if (last->finished_in_error()) {
546 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()));
553 void setup_menu (wxMenuBar* m)
555 _file_menu = new wxMenu;
556 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
557 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
558 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
560 _history_position = _file_menu->GetMenuItems().GetCount();
562 _file_menu->AppendSeparator ();
563 _file_menu->Append (ID_file_close, _("&Close"));
564 _file_menu->AppendSeparator ();
567 _file_menu->Append (wxID_EXIT, _("&Exit"));
569 _file_menu->Append (wxID_EXIT, _("&Quit"));
573 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
575 wxMenu* edit = new wxMenu;
576 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
579 prefs->Enable (Config::instance()->have_write_permission());
581 _cpl_menu = new wxMenu;
583 wxMenu* view = new wxMenu;
584 optional<int> c = Config::instance()->decode_reduction();
585 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
586 view->AppendSeparator();
587 #ifndef DCPOMATIC_VARIANT_SWAROOP
588 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
589 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
592 view->AppendSeparator();
593 view->Append(ID_view_closed_captions, _("Closed captions..."));
594 view->AppendSeparator();
595 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
596 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
597 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
598 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
600 wxMenu* tools = new wxMenu;
601 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
602 tools->AppendSeparator ();
603 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
604 tools->Append (ID_tools_timing, _("Timing..."));
605 tools->Append (ID_tools_system_information, _("System information..."));
607 wxMenu* help = new wxMenu;
609 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
611 help->Append (wxID_ABOUT, _("About"));
613 help->Append (ID_help_report_a_problem, _("Report a problem..."));
615 m->Append (_file_menu, _("&File"));
617 m->Append (edit, _("&Edit"));
619 m->Append (view, _("&View"));
620 m->Append (tools, _("&Tools"));
621 m->Append (help, _("&Help"));
626 wxString d = wxStandardPaths::Get().GetDocumentsDir();
627 if (Config::instance()->last_player_load_directory()) {
628 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
631 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
636 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
637 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
644 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
646 Config::instance()->set_last_player_load_directory (dcp.parent_path());
654 wxDirDialog* c = new wxDirDialog (
656 _("Select DCP to open as OV"),
657 wxStandardPaths::Get().GetDocumentsDir(),
658 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
664 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
665 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
672 DCPOMATIC_ASSERT (_film);
673 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
674 DCPOMATIC_ASSERT (dcp);
675 dcp->add_ov (wx_to_std(c->GetPath()));
676 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
677 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
678 if (!ok || !report_errors_from_last_job(this)) {
681 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
685 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
687 _film->set_container(r);
693 _info->triggered_update ();
698 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
700 if (d->ShowModal() == wxID_OK) {
701 DCPOMATIC_ASSERT (_film);
702 #ifdef DCPOMATIC_VARIANT_SWAROOP
703 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
706 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
707 } catch (exception& e) {
708 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
714 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
715 #ifndef DCPOMATIC_VARIANT_SWAROOP
716 DCPOMATIC_ASSERT (dcp);
720 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
721 dcp->examine (_film, shared_ptr<Job>());
723 } catch (exception& e) {
724 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
731 _info->triggered_update ();
734 void file_history (wxCommandEvent& event)
736 vector<boost::filesystem::path> history = Config::instance()->player_history ();
737 int n = event.GetId() - ID_file_history;
738 if (n >= 0 && n < static_cast<int> (history.size ())) {
740 load_dcp (history[n]);
741 } catch (exception& e) {
742 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
750 _info->triggered_update ();
751 set_menu_sensitivity ();
759 void edit_preferences ()
761 if (!Config::instance()->have_write_permission()) {
765 if (!_config_dialog) {
766 _config_dialog = create_player_config_dialog ();
768 _config_dialog->Show (this);
771 void view_cpl (wxCommandEvent& ev)
773 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
774 DCPOMATIC_ASSERT (dcp);
775 DCPExaminer ex (dcp, true);
776 int id = ev.GetId() - ID_view_cpl;
777 DCPOMATIC_ASSERT (id >= 0);
778 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
779 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
780 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
786 dcp->set_cpl ((*i)->id());
787 dcp->examine (_film, shared_ptr<Job>());
790 void view_full_screen ()
792 if (_mode == Config::PLAYER_MODE_FULL) {
793 _mode = Config::PLAYER_MODE_WINDOW;
795 _mode = Config::PLAYER_MODE_FULL;
801 void view_dual_screen ()
803 if (_mode == Config::PLAYER_MODE_DUAL) {
804 _mode = Config::PLAYER_MODE_WINDOW;
806 _mode = Config::PLAYER_MODE_DUAL;
814 if (_view_full_screen) {
815 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
817 if (_view_dual_screen) {
818 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
824 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
825 _info->Show (_mode != Config::PLAYER_MODE_FULL);
826 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
827 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
828 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
830 if (_mode == Config::PLAYER_MODE_DUAL) {
831 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
832 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
833 _dual_screen->ShowFullScreen (true);
834 _viewer->panel()->Reparent (_dual_screen);
835 _dual_screen->Show ();
836 if (wxDisplay::GetCount() > 1) {
837 switch (Config::instance()->image_display()) {
839 _dual_screen->Move (0, 0);
840 Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
843 _dual_screen->Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
844 // (0, 0) doesn't seem to work for some strange reason
851 _viewer->panel()->Reparent (_overall_panel);
852 _dual_screen->Destroy ();
857 setup_main_sizer (_mode);
860 void view_closed_captions ()
862 _viewer->show_closed_captions ();
867 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
868 DCPOMATIC_ASSERT (dcp);
870 JobManager* jm = JobManager::instance ();
871 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
872 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
877 DCPOMATIC_ASSERT (!jm->get().empty());
878 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
879 DCPOMATIC_ASSERT (last);
881 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
886 void tools_check_for_updates ()
888 UpdateChecker::instance()->run ();
889 _update_news_requested = true;
894 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
899 void tools_system_information ()
901 if (!_system_information_dialog) {
902 _system_information_dialog = new SystemInformationDialog (this, _viewer);
905 _system_information_dialog->Show ();
910 AboutDialog* d = new AboutDialog (this);
915 void help_report_a_problem ()
917 ReportProblemDialog* d = new ReportProblemDialog (this);
918 if (d->ShowModal () == wxID_OK) {
924 void update_checker_state_changed ()
926 UpdateChecker* uc = UpdateChecker::instance ();
928 bool const announce =
929 _update_news_requested ||
930 (uc->stable() && Config::instance()->check_for_updates()) ||
931 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
933 _update_news_requested = false;
939 if (uc->state() == UpdateChecker::YES) {
940 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
941 dialog->ShowModal ();
943 } else if (uc->state() == UpdateChecker::FAILED) {
944 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
946 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
949 _update_news_requested = false;
952 void config_changed (Config::Property prop)
954 /* Instantly save any config changes when using the player GUI */
956 Config::instance()->write_config();
957 } catch (FileError& e) {
958 if (prop != Config::HISTORY) {
962 _("Could not write to config file at %s. Your changes have not been saved."),
963 std_to_wx(e.file().string())
967 } catch (exception& e) {
970 _("Could not write to config file. Your changes have not been saved.")
974 update_from_config (prop);
977 void update_from_config (Config::Property prop)
979 for (int i = 0; i < _history_items; ++i) {
980 delete _file_menu->Remove (ID_file_history + i);
983 if (_history_separator) {
984 _file_menu->Remove (_history_separator);
986 delete _history_separator;
987 _history_separator = 0;
989 int pos = _history_position;
991 /* Clear out non-existant history items before we re-build the menu */
992 Config::instance()->clean_player_history ();
993 vector<boost::filesystem::path> history = Config::instance()->player_history ();
995 if (!history.empty ()) {
996 _history_separator = _file_menu->InsertSeparator (pos++);
999 for (size_t i = 0; i < history.size(); ++i) {
1002 s = String::compose ("&%1 %2", i + 1, history[i].string());
1004 s = history[i].string();
1006 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1009 _history_items = history.size ();
1011 if (prop == Config::PLAYER_DEBUG_LOG) {
1012 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1014 dcpomatic_log.reset (new FileLog(*p));
1016 dcpomatic_log.reset (new NullLog());
1018 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
1022 void set_menu_sensitivity ()
1024 _tools_verify->Enable (static_cast<bool>(_film));
1025 _file_add_ov->Enable (static_cast<bool>(_film));
1026 _file_add_kdm->Enable (static_cast<bool>(_film));
1027 _view_cpl->Enable (static_cast<bool>(_film));
1030 void start_stop_pressed ()
1032 if (_viewer->playing()) {
1039 void go_back_frame ()
1041 _viewer->seek_by (-_viewer->one_video_frame(), true);
1044 void go_forward_frame ()
1046 _viewer->seek_by (_viewer->one_video_frame(), true);
1049 void go_seconds (int s)
1051 _viewer->seek_by (DCPTime::from_seconds(s), true);
1056 _viewer->seek (DCPTime(), true);
1061 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
1064 wxFrame* _dual_screen;
1065 bool _update_news_requested;
1066 PlayerInformation* _info;
1067 Config::PlayerMode _mode;
1068 wxPreferencesEditor* _config_dialog;
1069 wxPanel* _overall_panel;
1071 wxMenuItem* _view_cpl;
1074 int _history_position;
1075 wxMenuItem* _history_separator;
1076 shared_ptr<FilmViewer> _viewer;
1077 Controls* _controls;
1078 SystemInformationDialog* _system_information_dialog;
1079 boost::shared_ptr<Film> _film;
1080 boost::signals2::scoped_connection _config_changed_connection;
1081 boost::signals2::scoped_connection _examine_job_connection;
1082 wxMenuItem* _file_add_ov;
1083 wxMenuItem* _file_add_kdm;
1084 wxMenuItem* _tools_verify;
1085 wxMenuItem* _view_full_screen;
1086 wxMenuItem* _view_dual_screen;
1087 wxSizer* _main_sizer;
1088 PlayerStressTester _stress;
1091 static const wxCmdLineEntryDesc command_line_description[] = {
1092 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1093 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1094 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1095 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1098 class PlayServer : public Server
1101 explicit PlayServer (DOMFrame* frame)
1102 : Server (PLAYER_PLAY_PORT)
1106 void handle (shared_ptr<Socket> socket)
1109 int const length = socket->read_uint32 ();
1110 scoped_array<char> buffer (new char[length]);
1111 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1112 string s (buffer.get());
1113 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1114 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1125 * @brief The magic App class for wxWidgets.
1127 class App : public wxApp
1134 #ifdef DCPOMATIC_LINUX
1143 wxSplashScreen* splash = 0;
1145 wxInitAllImageHandlers ();
1147 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1148 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1150 splash = maybe_show_splash ();
1152 SetAppName (_("DCP-o-matic Player"));
1154 if (!wxApp::OnInit()) {
1158 #ifdef DCPOMATIC_LINUX
1159 unsetenv ("UBUNTU_MENUPROXY");
1162 #ifdef DCPOMATIC_OSX
1163 make_foreground_application ();
1166 dcpomatic_setup_path_encoding ();
1168 /* Enable i18n; this will create a Config object
1169 to look for a force-configured language. This Config
1170 object will be wrong, however, because dcpomatic_setup
1171 hasn't yet been called and there aren't any filters etc.
1174 dcpomatic_setup_i18n ();
1176 /* Set things up, including filters etc.
1177 which will now be internationalised correctly.
1181 /* Force the configuration to be re-loaded correctly next
1186 signal_manager = new wxSignalManager (this);
1188 _frame = new DOMFrame ();
1189 SetTopWindow (_frame);
1190 _frame->Maximize ();
1197 PlayServer* server = new PlayServer (_frame);
1198 new thread (boost::bind (&PlayServer::run, server));
1200 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1202 _frame->load_dcp (_dcp_to_load);
1203 } catch (exception& e) {
1204 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1210 _frame->load_stress_script (*_stress);
1211 } catch (exception& e) {
1212 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1216 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1218 if (Config::instance()->check_for_updates ()) {
1219 UpdateChecker::instance()->run ();
1222 catch (exception& e)
1227 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1233 void OnInitCmdLine (wxCmdLineParser& parser)
1235 parser.SetDesc (command_line_description);
1236 parser.SetSwitchChars (wxT ("-"));
1239 bool OnCmdLineParsed (wxCmdLineParser& parser)
1241 if (parser.GetParamCount() > 0) {
1242 _dcp_to_load = wx_to_std (parser.GetParam (0));
1246 if (parser.Found("c", &config)) {
1247 Config::override_path = wx_to_std (config);
1250 if (parser.Found("s", &stress)) {
1251 _stress = wx_to_std (stress);
1257 void report_exception ()
1261 } catch (FileError& e) {
1265 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1266 std_to_wx (e.what()),
1267 std_to_wx (e.file().string().c_str ())
1270 } catch (exception& e) {
1274 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1275 std_to_wx (e.what ())
1279 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1283 /* An unhandled exception has occurred inside the main event loop */
1284 bool OnExceptionInMainLoop ()
1286 report_exception ();
1287 /* This will terminate the program */
1291 void OnUnhandledException ()
1293 report_exception ();
1298 signal_manager->ui_idle ();
1301 void config_failed_to_load ()
1303 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1306 void config_warning (string m)
1308 message_dialog (_frame, std_to_wx (m));
1312 string _dcp_to_load;
1313 boost::optional<string> _stress;