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 "lib/cross.h"
38 #include "lib/config.h"
40 #include "lib/internet.h"
41 #include "lib/update_checker.h"
42 #include "lib/compose.hpp"
43 #include "lib/dcp_content.h"
44 #include "lib/job_manager.h"
47 #include "lib/null_log.h"
48 #include "lib/video_content.h"
49 #include "lib/text_content.h"
50 #include "lib/ratio.h"
51 #include "lib/verify_dcp_job.h"
52 #include "lib/dcp_examiner.h"
53 #include "lib/examine_content_job.h"
54 #include "lib/server.h"
55 #include "lib/dcpomatic_socket.h"
56 #include "lib/scoped_temporary.h"
57 #include "lib/monitor_checker.h"
58 #include "lib/lock_file_checker.h"
59 #include "lib/ffmpeg_content.h"
60 #include "lib/dcpomatic_log.h"
61 #include "lib/file_log.h"
63 #include <dcp/raw_convert.h>
64 #include <dcp/exceptions.h>
66 #include <wx/stdpaths.h>
67 #include <wx/splash.h>
68 #include <wx/cmdline.h>
69 #include <wx/preferences.h>
70 #include <wx/progdlg.h>
71 #include <wx/display.h>
76 #include <ApplicationServices/ApplicationServices.h>
78 #include <boost/bind.hpp>
79 #include <boost/algorithm/string.hpp>
93 using boost::shared_ptr;
94 using boost::weak_ptr;
95 using boost::scoped_array;
96 using boost::optional;
97 using boost::dynamic_pointer_cast;
100 using dcp::raw_convert;
101 using namespace dcpomatic;
103 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
104 /* Interval to check what to do next with the stress checker, in milliseconds */
105 #define STRESS_TEST_CHECK_INTERVAL 20
124 boost::split (bits, line, boost::is_any_of(" "));
125 if (bits[0] == "O") {
126 if (bits.size() != 2) {
130 string_param = bits[1];
131 } else if (bits[0] == "P") {
133 } else if (bits[0] == "W") {
134 if (bits.size() != 2) {
138 int_param = raw_convert<int>(bits[1]);
139 } else if (bits[0] == "S") {
141 } else if (bits[0] == "K") {
142 if (bits.size() != 2) {
146 int_param = raw_convert<int>(bits[1]);
161 /* Allow spare IDs after _history for the recent files list */
164 /* Allow spare IDs for CPLs */
165 ID_view_full_screen = 200,
167 ID_view_closed_captions,
168 ID_view_scale_appropriate,
171 ID_view_scale_quarter,
172 ID_help_report_a_problem,
174 ID_tools_check_for_updates,
176 ID_tools_system_information,
177 /* IDs for shortcuts (with no associated menu item) */
183 class DOMFrame : public wxFrame
187 : wxFrame (0, -1, _("DCP-o-matic Player"))
189 , _update_news_requested (false)
191 , _mode (Config::instance()->player_mode())
195 , _history_position (0)
196 , _history_separator (0)
197 , _system_information_dialog (0)
198 , _view_full_screen (0)
199 , _view_dual_screen (0)
200 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
204 dcpomatic_log.reset (new NullLog());
206 #if defined(DCPOMATIC_WINDOWS)
207 maybe_open_console ();
208 cout << "DCP-o-matic Player is starting." << "\n";
211 wxMenuBar* bar = new wxMenuBar;
213 set_menu_sensitivity ();
216 #ifdef DCPOMATIC_WINDOWS
217 SetIcon (wxIcon (std_to_wx ("id")));
220 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
221 update_from_config (Config::PLAYER_DEBUG_LOG);
223 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
224 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
225 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
226 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
227 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
228 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
229 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
230 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
231 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
232 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
233 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
234 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
235 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
236 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
237 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
238 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
239 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
240 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
241 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
242 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
244 /* Use a panel as the only child of the Frame so that we avoid
245 the dark-grey background on Windows.
247 _overall_panel = new wxPanel (this, wxID_ANY);
249 _viewer.reset (new FilmViewer (_overall_panel));
250 #ifdef DCPOMATIC_VARIANT_SWAROOP
251 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
253 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
255 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
256 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
258 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
260 _controls = new StandardControls (_overall_panel, _viewer, false);
263 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
264 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
265 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
266 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
267 _info = new PlayerInformation (_overall_panel, _viewer);
268 setup_main_sizer (Config::instance()->player_mode());
270 int accelerators = 4;
272 int accelerators = 3;
275 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
276 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
277 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
278 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
280 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
282 wxAcceleratorTable accel_table (accelerators, accel);
283 SetAcceleratorTable (accel_table);
286 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
287 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
288 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
292 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
293 #ifdef DCPOMATIC_VARIANT_SWAROOP
294 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
295 MonitorChecker::instance()->run ();
296 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
297 LockFileChecker::instance()->run ();
301 #ifdef DCPOMATIC_VARIANT_SWAROOP
302 sc->check_restart ();
306 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
307 void stress (boost::filesystem::path script_file)
309 Bind (wxEVT_TIMER, boost::bind(&DOMFrame::check_commands, this));
310 _timer.Start(STRESS_TEST_CHECK_INTERVAL);
311 vector<string> lines;
312 string const script = dcp::file_to_string(script_file);
313 boost::split (lines, script, boost::is_any_of("\n"));
314 BOOST_FOREACH (string i, lines) {
315 _commands.push_back (Command(i));
317 _current_command = _commands.begin();
320 void check_commands ()
322 if (_current_command == _commands.end()) {
324 cout << "ST: finished.\n";
328 switch (_current_command->type) {
330 cout << "ST: load " << _current_command->string_param << "\n";
331 load_dcp (_current_command->string_param);
335 cout << "ST: play\n";
340 /* int_param here is the number of milliseconds to wait */
341 if (_wait_remaining) {
342 _wait_remaining = *_wait_remaining - STRESS_TEST_CHECK_INTERVAL;
343 if (_wait_remaining < 0) {
344 cout << "ST: wait done.\n";
345 _wait_remaining = optional<int>();
349 _wait_remaining = _current_command->int_param;
350 cout << "ST: waiting for " << *_wait_remaining << ".\n";
354 cout << "ST: stop\n";
362 /* int_param here is a number between 0 and 4095, corresponding to the possible slider positions */
363 cout << "ST: seek to " << _current_command->int_param << "\n";
364 _controls->seek (_current_command->int_param);
371 #ifdef DCPOMATIC_VARIANT_SWAROOP
372 void monitor_checker_state_changed ()
374 if (!MonitorChecker::instance()->ok()) {
376 error_dialog (this, _("The required display devices are not connected correctly."));
380 void lock_checker_state_changed ()
382 if (!LockFileChecker::instance()->ok()) {
384 error_dialog (this, _("The lock file is not present."));
389 void setup_main_sizer (Config::PlayerMode mode)
391 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
392 if (mode != Config::PLAYER_MODE_DUAL) {
393 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
395 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
396 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
397 _overall_panel->SetSizer (main_sizer);
398 _overall_panel->Layout ();
401 bool playback_permitted ()
403 #ifdef DCPOMATIC_VARIANT_SWAROOP
404 if (!MonitorChecker::instance()->ok()) {
405 error_dialog (this, _("The required display devices are not connected correctly."));
408 if (!LockFileChecker::instance()->ok()) {
409 error_dialog (this, _("The lock file is not present."));
413 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
418 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
419 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
420 if (d && !d->kdm_timing_window_valid()) {
425 #ifdef DCPOMATIC_VARIANT_SWAROOP
426 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
427 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
428 if (c && !c->kdm_timing_window_valid()) {
435 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
441 void playback_started (DCPTime time)
443 /* XXX: this only logs the first piece of content; probably should be each piece? */
444 if (_film->content().empty()) {
448 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
450 DCPExaminer ex (dcp, true);
451 shared_ptr<dcp::CPL> playing_cpl;
452 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
453 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
457 DCPOMATIC_ASSERT (playing_cpl);
461 "playback-started %s %s %s",
462 time.timecode(_film->video_frame_rate()).c_str(),
463 dcp->directories().front().string().c_str(),
464 playing_cpl->annotation_text().c_str()
469 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
473 "playback-started %s %s",
474 time.timecode(_film->video_frame_rate()).c_str(),
475 ffmpeg->path(0).string().c_str()
481 void playback_stopped (DCPTime time)
483 #ifdef DCPOMATIC_VARIANT_SWAROOP
485 boost::filesystem::remove (Config::path("position"));
491 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
494 void set_decode_reduction (optional<int> reduction)
496 _viewer->set_dcp_decode_reduction (reduction);
497 _info->triggered_update ();
498 Config::instance()->set_decode_reduction (reduction);
501 void load_dcp (boost::filesystem::path dir)
503 DCPOMATIC_ASSERT (_film);
507 shared_ptr<DCPContent> dcp (new DCPContent(dir));
508 _film->examine_and_add_content (dcp, true);
509 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
510 if (!ok || !report_errors_from_last_job(this)) {
513 #ifndef DCPOMATIC_VARIANT_SWAROOP
514 Config::instance()->add_to_player_history (dir);
516 } catch (dcp::DCPReadError& e) {
517 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
521 void reset_film_weak (weak_ptr<Film> weak_film)
523 shared_ptr<Film> film = weak_film.lock ();
529 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
532 _film->set_tolerant (true);
533 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
534 _viewer->set_film (_film);
535 _controls->set_film (_film);
536 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
537 _info->triggered_update ();
540 void film_changed (ChangeType type, Film::Property property)
542 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
546 if (_viewer->playing ()) {
550 /* Start off as Flat */
551 _film->set_container (Ratio::from_id("185"));
553 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
554 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
556 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
561 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
562 if (r->id() == "239") {
563 /* Any scope content means we use scope */
564 _film->set_container(r);
568 /* Any 3D content means we use 3D mode */
569 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
570 _film->set_three_d (true);
574 _viewer->seek (DCPTime(), true);
575 _info->triggered_update ();
577 set_menu_sensitivity ();
579 wxMenuItemList old = _cpl_menu->GetMenuItems();
580 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
581 _cpl_menu->Remove (*i);
584 if (_film->content().size() == 1) {
585 /* Offer a CPL menu */
586 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
588 DCPExaminer ex (first, true);
589 int id = ID_view_cpl;
590 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
591 wxMenuItem* j = _cpl_menu->AppendRadioItem(
593 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
595 j->Check(!first->cpl() || i->id() == *first->cpl());
604 bool report_errors_from_last_job (wxWindow* parent) const
606 JobManager* jm = JobManager::instance ();
608 DCPOMATIC_ASSERT (!jm->get().empty());
610 shared_ptr<Job> last = jm->get().back();
611 if (last->finished_in_error()) {
612 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()));
619 void setup_menu (wxMenuBar* m)
621 _file_menu = new wxMenu;
622 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
623 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
624 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
626 _history_position = _file_menu->GetMenuItems().GetCount();
628 _file_menu->AppendSeparator ();
629 _file_menu->Append (ID_file_close, _("&Close"));
630 _file_menu->AppendSeparator ();
633 _file_menu->Append (wxID_EXIT, _("&Exit"));
635 _file_menu->Append (wxID_EXIT, _("&Quit"));
639 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
641 wxMenu* edit = new wxMenu;
642 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
645 prefs->Enable (Config::instance()->have_write_permission());
647 _cpl_menu = new wxMenu;
649 wxMenu* view = new wxMenu;
650 optional<int> c = Config::instance()->decode_reduction();
651 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
652 view->AppendSeparator();
653 #ifndef DCPOMATIC_VARIANT_SWAROOP
654 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
655 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
658 view->AppendSeparator();
659 view->Append(ID_view_closed_captions, _("Closed captions..."));
660 view->AppendSeparator();
661 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
662 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
663 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
664 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
666 wxMenu* tools = new wxMenu;
667 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
668 tools->AppendSeparator ();
669 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
670 tools->Append (ID_tools_timing, _("Timing..."));
671 tools->Append (ID_tools_system_information, _("System information..."));
673 wxMenu* help = new wxMenu;
675 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
677 help->Append (wxID_ABOUT, _("About"));
679 help->Append (ID_help_report_a_problem, _("Report a problem..."));
681 m->Append (_file_menu, _("&File"));
683 m->Append (edit, _("&Edit"));
685 m->Append (view, _("&View"));
686 m->Append (tools, _("&Tools"));
687 m->Append (help, _("&Help"));
692 wxString d = wxStandardPaths::Get().GetDocumentsDir();
693 if (Config::instance()->last_player_load_directory()) {
694 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
697 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
702 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
703 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
710 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
712 Config::instance()->set_last_player_load_directory (dcp.parent_path());
720 wxDirDialog* c = new wxDirDialog (
722 _("Select DCP to open as OV"),
723 wxStandardPaths::Get().GetDocumentsDir(),
724 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
730 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
731 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
738 DCPOMATIC_ASSERT (_film);
739 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
740 DCPOMATIC_ASSERT (dcp);
741 dcp->add_ov (wx_to_std(c->GetPath()));
742 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
743 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
744 if (!ok || !report_errors_from_last_job(this)) {
747 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
751 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
753 _film->set_container(r);
759 _info->triggered_update ();
764 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
766 if (d->ShowModal() == wxID_OK) {
767 DCPOMATIC_ASSERT (_film);
768 #ifdef DCPOMATIC_VARIANT_SWAROOP
769 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
772 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
773 } catch (exception& e) {
774 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
780 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
781 #ifndef DCPOMATIC_VARIANT_SWAROOP
782 DCPOMATIC_ASSERT (dcp);
786 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
787 dcp->examine (_film, shared_ptr<Job>());
789 } catch (exception& e) {
790 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
797 _info->triggered_update ();
800 void file_history (wxCommandEvent& event)
802 vector<boost::filesystem::path> history = Config::instance()->player_history ();
803 int n = event.GetId() - ID_file_history;
804 if (n >= 0 && n < static_cast<int> (history.size ())) {
806 load_dcp (history[n]);
807 } catch (exception& e) {
808 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
816 _info->triggered_update ();
817 set_menu_sensitivity ();
825 void edit_preferences ()
827 if (!Config::instance()->have_write_permission()) {
831 if (!_config_dialog) {
832 _config_dialog = create_player_config_dialog ();
834 _config_dialog->Show (this);
837 void view_cpl (wxCommandEvent& ev)
839 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
840 DCPOMATIC_ASSERT (dcp);
841 DCPExaminer ex (dcp, true);
842 int id = ev.GetId() - ID_view_cpl;
843 DCPOMATIC_ASSERT (id >= 0);
844 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
845 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
846 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
852 dcp->set_cpl ((*i)->id());
853 dcp->examine (_film, shared_ptr<Job>());
856 void view_full_screen ()
858 if (_mode == Config::PLAYER_MODE_FULL) {
859 _mode = Config::PLAYER_MODE_WINDOW;
861 _mode = Config::PLAYER_MODE_FULL;
867 void view_dual_screen ()
869 if (_mode == Config::PLAYER_MODE_DUAL) {
870 _mode = Config::PLAYER_MODE_WINDOW;
872 _mode = Config::PLAYER_MODE_DUAL;
880 if (_view_full_screen) {
881 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
883 if (_view_dual_screen) {
884 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
890 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
891 _info->Show (_mode != Config::PLAYER_MODE_FULL);
892 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
893 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
894 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
896 if (_mode == Config::PLAYER_MODE_DUAL) {
897 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
898 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
899 _dual_screen->ShowFullScreen (true);
900 _viewer->panel()->Reparent (_dual_screen);
901 _dual_screen->Show ();
902 if (wxDisplay::GetCount() > 1) {
903 switch (Config::instance()->image_display()) {
905 _dual_screen->Move (0, 0);
906 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
909 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
910 // (0, 0) doesn't seem to work for some strange reason
917 _viewer->panel()->Reparent (_overall_panel);
918 _dual_screen->Destroy ();
923 setup_main_sizer (_mode);
926 void view_closed_captions ()
928 _viewer->show_closed_captions ();
933 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
934 DCPOMATIC_ASSERT (dcp);
936 JobManager* jm = JobManager::instance ();
937 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
938 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
943 DCPOMATIC_ASSERT (!jm->get().empty());
944 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
945 DCPOMATIC_ASSERT (last);
947 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
952 void tools_check_for_updates ()
954 UpdateChecker::instance()->run ();
955 _update_news_requested = true;
960 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
965 void tools_system_information ()
967 if (!_system_information_dialog) {
968 _system_information_dialog = new SystemInformationDialog (this, _viewer);
971 _system_information_dialog->Show ();
976 AboutDialog* d = new AboutDialog (this);
981 void help_report_a_problem ()
983 ReportProblemDialog* d = new ReportProblemDialog (this);
984 if (d->ShowModal () == wxID_OK) {
990 void update_checker_state_changed ()
992 UpdateChecker* uc = UpdateChecker::instance ();
994 bool const announce =
995 _update_news_requested ||
996 (uc->stable() && Config::instance()->check_for_updates()) ||
997 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
999 _update_news_requested = false;
1005 if (uc->state() == UpdateChecker::YES) {
1006 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
1007 dialog->ShowModal ();
1009 } else if (uc->state() == UpdateChecker::FAILED) {
1010 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
1012 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
1015 _update_news_requested = false;
1018 void config_changed (Config::Property prop)
1020 /* Instantly save any config changes when using the player GUI */
1022 Config::instance()->write_config();
1023 } catch (FileError& e) {
1024 if (prop != Config::HISTORY) {
1028 _("Could not write to config file at %s. Your changes have not been saved."),
1029 std_to_wx(e.file().string())
1033 } catch (exception& e) {
1036 _("Could not write to config file. Your changes have not been saved.")
1040 update_from_config (prop);
1043 void update_from_config (Config::Property prop)
1045 for (int i = 0; i < _history_items; ++i) {
1046 delete _file_menu->Remove (ID_file_history + i);
1049 if (_history_separator) {
1050 _file_menu->Remove (_history_separator);
1052 delete _history_separator;
1053 _history_separator = 0;
1055 int pos = _history_position;
1057 /* Clear out non-existant history items before we re-build the menu */
1058 Config::instance()->clean_player_history ();
1059 vector<boost::filesystem::path> history = Config::instance()->player_history ();
1061 if (!history.empty ()) {
1062 _history_separator = _file_menu->InsertSeparator (pos++);
1065 for (size_t i = 0; i < history.size(); ++i) {
1068 s = String::compose ("&%1 %2", i + 1, history[i].string());
1070 s = history[i].string();
1072 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1075 _history_items = history.size ();
1077 if (prop == Config::PLAYER_DEBUG_LOG) {
1078 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1080 dcpomatic_log.reset (new FileLog(*p));
1082 dcpomatic_log.reset (new NullLog());
1084 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
1088 void set_menu_sensitivity ()
1090 _tools_verify->Enable (static_cast<bool>(_film));
1091 _file_add_ov->Enable (static_cast<bool>(_film));
1092 _file_add_kdm->Enable (static_cast<bool>(_film));
1093 _view_cpl->Enable (static_cast<bool>(_film));
1096 void start_stop_pressed ()
1098 if (_viewer->playing()) {
1107 _viewer->seek_by (-_viewer->one_video_frame(), true);
1110 void forward_frame ()
1112 _viewer->seek_by (_viewer->one_video_frame(), true);
1117 wxFrame* _dual_screen;
1118 bool _update_news_requested;
1119 PlayerInformation* _info;
1120 Config::PlayerMode _mode;
1121 wxPreferencesEditor* _config_dialog;
1122 wxPanel* _overall_panel;
1124 wxMenuItem* _view_cpl;
1127 int _history_position;
1128 wxMenuItem* _history_separator;
1129 shared_ptr<FilmViewer> _viewer;
1130 Controls* _controls;
1131 SystemInformationDialog* _system_information_dialog;
1132 boost::shared_ptr<Film> _film;
1133 boost::signals2::scoped_connection _config_changed_connection;
1134 wxMenuItem* _file_add_ov;
1135 wxMenuItem* _file_add_kdm;
1136 wxMenuItem* _tools_verify;
1137 wxMenuItem* _view_full_screen;
1138 wxMenuItem* _view_dual_screen;
1139 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1141 list<Command> _commands;
1142 list<Command>::const_iterator _current_command;
1143 /** Remaining time that the script must wait, in milliseconds */
1144 optional<int> _wait_remaining;
1148 static const wxCmdLineEntryDesc command_line_description[] = {
1149 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1150 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1151 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1152 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1154 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1157 class PlayServer : public Server
1160 explicit PlayServer (DOMFrame* frame)
1161 : Server (PLAYER_PLAY_PORT)
1165 void handle (shared_ptr<Socket> socket)
1168 int const length = socket->read_uint32 ();
1169 scoped_array<char> buffer (new char[length]);
1170 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1171 string s (buffer.get());
1172 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1173 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1184 * @brief The magic App class for wxWidgets.
1186 class App : public wxApp
1193 #ifdef DCPOMATIC_LINUX
1202 wxSplashScreen* splash = 0;
1204 wxInitAllImageHandlers ();
1206 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1207 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1209 splash = maybe_show_splash ();
1211 SetAppName (_("DCP-o-matic Player"));
1213 if (!wxApp::OnInit()) {
1217 #ifdef DCPOMATIC_LINUX
1218 unsetenv ("UBUNTU_MENUPROXY");
1222 ProcessSerialNumber serial;
1223 GetCurrentProcess (&serial);
1224 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1227 dcpomatic_setup_path_encoding ();
1229 /* Enable i18n; this will create a Config object
1230 to look for a force-configured language. This Config
1231 object will be wrong, however, because dcpomatic_setup
1232 hasn't yet been called and there aren't any filters etc.
1235 dcpomatic_setup_i18n ();
1237 /* Set things up, including filters etc.
1238 which will now be internationalised correctly.
1242 /* Force the configuration to be re-loaded correctly next
1247 signal_manager = new wxSignalManager (this);
1249 _frame = new DOMFrame ();
1250 SetTopWindow (_frame);
1251 _frame->Maximize ();
1258 PlayServer* server = new PlayServer (_frame);
1259 new thread (boost::bind (&PlayServer::run, server));
1261 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1263 _frame->load_dcp (_dcp_to_load);
1264 } catch (exception& e) {
1265 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1269 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1272 _frame->stress (_stress.get());
1273 } catch (exception& e) {
1274 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1279 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1281 if (Config::instance()->check_for_updates ()) {
1282 UpdateChecker::instance()->run ();
1285 catch (exception& e)
1290 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1296 void OnInitCmdLine (wxCmdLineParser& parser)
1298 parser.SetDesc (command_line_description);
1299 parser.SetSwitchChars (wxT ("-"));
1302 bool OnCmdLineParsed (wxCmdLineParser& parser)
1304 if (parser.GetParamCount() > 0) {
1305 _dcp_to_load = wx_to_std (parser.GetParam (0));
1309 if (parser.Found("c", &config)) {
1310 Config::override_path = wx_to_std (config);
1312 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1314 if (parser.Found("s", &stress)) {
1315 _stress = wx_to_std (stress);
1322 void report_exception ()
1326 } catch (FileError& e) {
1330 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1331 std_to_wx (e.what()),
1332 std_to_wx (e.file().string().c_str ())
1335 } catch (exception& e) {
1339 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1340 std_to_wx (e.what ())
1344 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1348 /* An unhandled exception has occurred inside the main event loop */
1349 bool OnExceptionInMainLoop ()
1351 report_exception ();
1352 /* This will terminate the program */
1356 void OnUnhandledException ()
1358 report_exception ();
1363 signal_manager->ui_idle ();
1366 void config_failed_to_load ()
1368 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1371 void config_warning (string m)
1373 message_dialog (_frame, std_to_wx (m));
1377 string _dcp_to_load;
1378 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1379 boost::optional<string> _stress;