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 #define STRESS_TEST_CHECK_INTERVAL 20
123 boost::split (bits, line, boost::is_any_of(" "));
124 if (bits[0] == "O") {
125 if (bits.size() != 2) {
129 string_param = bits[1];
130 } else if (bits[0] == "P") {
132 } else if (bits[0] == "W") {
133 if (bits.size() != 2) {
137 int_param = raw_convert<int>(bits[1]);
138 } else if (bits[0] == "S") {
140 } else if (bits[0] == "K") {
141 if (bits.size() != 2) {
145 int_param = raw_convert<int>(bits[1]);
160 /* Allow spare IDs after _history for the recent files list */
163 /* Allow spare IDs for CPLs */
164 ID_view_full_screen = 200,
166 ID_view_closed_captions,
167 ID_view_scale_appropriate,
170 ID_view_scale_quarter,
171 ID_help_report_a_problem,
173 ID_tools_check_for_updates,
175 ID_tools_system_information,
176 /* IDs for shortcuts (with no associated menu item) */
182 class DOMFrame : public wxFrame
186 : wxFrame (0, -1, _("DCP-o-matic Player"))
188 , _update_news_requested (false)
190 , _mode (Config::instance()->player_mode())
194 , _history_position (0)
195 , _history_separator (0)
196 , _system_information_dialog (0)
197 , _view_full_screen (0)
198 , _view_dual_screen (0)
199 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
203 dcpomatic_log.reset (new NullLog());
205 #if defined(DCPOMATIC_WINDOWS)
206 maybe_open_console ();
207 cout << "DCP-o-matic Player is starting." << "\n";
210 wxMenuBar* bar = new wxMenuBar;
212 set_menu_sensitivity ();
215 #ifdef DCPOMATIC_WINDOWS
216 SetIcon (wxIcon (std_to_wx ("id")));
219 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
220 update_from_config (Config::PLAYER_DEBUG_LOG);
222 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
223 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
224 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
225 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
226 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
227 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
228 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
229 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
230 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
231 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
232 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
233 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
234 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
235 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
236 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
237 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
238 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
239 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
240 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
241 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
243 /* Use a panel as the only child of the Frame so that we avoid
244 the dark-grey background on Windows.
246 _overall_panel = new wxPanel (this, wxID_ANY);
248 _viewer.reset (new FilmViewer (_overall_panel));
249 #ifdef DCPOMATIC_VARIANT_SWAROOP
250 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
252 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
254 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
255 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
257 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
259 _controls = new StandardControls (_overall_panel, _viewer, false);
262 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
263 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
264 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
265 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
266 _info = new PlayerInformation (_overall_panel, _viewer);
267 setup_main_sizer (Config::instance()->player_mode());
269 int accelerators = 4;
271 int accelerators = 3;
274 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
275 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
276 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
277 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
279 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
281 wxAcceleratorTable accel_table (accelerators, accel);
282 SetAcceleratorTable (accel_table);
285 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
286 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
287 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
291 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
292 #ifdef DCPOMATIC_VARIANT_SWAROOP
293 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
294 MonitorChecker::instance()->run ();
295 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
296 LockFileChecker::instance()->run ();
300 #ifdef DCPOMATIC_VARIANT_SWAROOP
301 sc->check_restart ();
305 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
306 void stress (boost::filesystem::path script_file)
308 Bind (wxEVT_TIMER, boost::bind(&DOMFrame::check_commands, this));
309 _timer.Start(STRESS_TEST_CHECK_INTERVAL);
310 vector<string> lines;
311 string const script = dcp::file_to_string(script_file);
312 boost::split (lines, script, boost::is_any_of("\n"));
313 BOOST_FOREACH (string i, lines) {
314 _commands.push_back (Command(i));
316 _current_command = _commands.begin();
319 void check_commands ()
321 if (_current_command == _commands.end()) {
323 cout << "ST: finished.\n";
327 switch (_current_command->type) {
329 cout << "ST: load " << _current_command->string_param << "\n";
330 load_dcp (_current_command->string_param);
334 cout << "ST: play\n";
339 if (_wait_remaining) {
340 _wait_remaining = *_wait_remaining - STRESS_TEST_CHECK_INTERVAL;
341 if (_wait_remaining < 0) {
342 cout << "ST: wait done.\n";
343 _wait_remaining = optional<int>();
347 _wait_remaining = _current_command->int_param;
348 cout << "ST: waiting for " << *_wait_remaining << ".\n";
352 cout << "ST: stop\n";
360 /* int_param here is a number between 0 and 4095, corresponding to the possible slider positions */
361 cout << "ST: seek to " << _current_command->int_param << "\n";
362 _controls->seek (_current_command->int_param);
369 #ifdef DCPOMATIC_VARIANT_SWAROOP
370 void monitor_checker_state_changed ()
372 if (!MonitorChecker::instance()->ok()) {
374 error_dialog (this, _("The required display devices are not connected correctly."));
378 void lock_checker_state_changed ()
380 if (!LockFileChecker::instance()->ok()) {
382 error_dialog (this, _("The lock file is not present."));
387 void setup_main_sizer (Config::PlayerMode mode)
389 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
390 if (mode != Config::PLAYER_MODE_DUAL) {
391 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
393 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
394 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
395 _overall_panel->SetSizer (main_sizer);
396 _overall_panel->Layout ();
399 bool playback_permitted ()
401 #ifdef DCPOMATIC_VARIANT_SWAROOP
402 if (!MonitorChecker::instance()->ok()) {
403 error_dialog (this, _("The required display devices are not connected correctly."));
406 if (!LockFileChecker::instance()->ok()) {
407 error_dialog (this, _("The lock file is not present."));
411 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
416 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
417 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
418 if (d && !d->kdm_timing_window_valid()) {
423 #ifdef DCPOMATIC_VARIANT_SWAROOP
424 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
425 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
426 if (c && !c->kdm_timing_window_valid()) {
433 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
439 void playback_started (DCPTime time)
441 /* XXX: this only logs the first piece of content; probably should be each piece? */
442 if (_film->content().empty()) {
446 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
448 DCPExaminer ex (dcp, true);
449 shared_ptr<dcp::CPL> playing_cpl;
450 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
451 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
455 DCPOMATIC_ASSERT (playing_cpl);
459 "playback-started %s %s %s",
460 time.timecode(_film->video_frame_rate()).c_str(),
461 dcp->directories().front().string().c_str(),
462 playing_cpl->annotation_text().c_str()
467 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
471 "playback-started %s %s",
472 time.timecode(_film->video_frame_rate()).c_str(),
473 ffmpeg->path(0).string().c_str()
479 void playback_stopped (DCPTime time)
481 #ifdef DCPOMATIC_VARIANT_SWAROOP
483 boost::filesystem::remove (Config::path("position"));
489 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
492 void set_decode_reduction (optional<int> reduction)
494 _viewer->set_dcp_decode_reduction (reduction);
495 _info->triggered_update ();
496 Config::instance()->set_decode_reduction (reduction);
499 void load_dcp (boost::filesystem::path dir)
501 DCPOMATIC_ASSERT (_film);
505 shared_ptr<DCPContent> dcp (new DCPContent(dir));
506 _film->examine_and_add_content (dcp, true);
507 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
508 if (!ok || !report_errors_from_last_job(this)) {
511 #ifndef DCPOMATIC_VARIANT_SWAROOP
512 Config::instance()->add_to_player_history (dir);
514 } catch (dcp::DCPReadError& e) {
515 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
519 void reset_film_weak (weak_ptr<Film> weak_film)
521 shared_ptr<Film> film = weak_film.lock ();
527 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
530 _film->set_tolerant (true);
531 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
532 _viewer->set_film (_film);
533 _controls->set_film (_film);
534 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
535 _info->triggered_update ();
538 void film_changed (ChangeType type, Film::Property property)
540 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
544 if (_viewer->playing ()) {
548 /* Start off as Flat */
549 _film->set_container (Ratio::from_id("185"));
551 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
552 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
554 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
559 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
560 if (r->id() == "239") {
561 /* Any scope content means we use scope */
562 _film->set_container(r);
566 /* Any 3D content means we use 3D mode */
567 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
568 _film->set_three_d (true);
572 _viewer->seek (DCPTime(), true);
573 _info->triggered_update ();
575 set_menu_sensitivity ();
577 wxMenuItemList old = _cpl_menu->GetMenuItems();
578 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
579 _cpl_menu->Remove (*i);
582 if (_film->content().size() == 1) {
583 /* Offer a CPL menu */
584 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
586 DCPExaminer ex (first, true);
587 int id = ID_view_cpl;
588 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
589 wxMenuItem* j = _cpl_menu->AppendRadioItem(
591 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
593 j->Check(!first->cpl() || i->id() == *first->cpl());
602 bool report_errors_from_last_job (wxWindow* parent) const
604 JobManager* jm = JobManager::instance ();
606 DCPOMATIC_ASSERT (!jm->get().empty());
608 shared_ptr<Job> last = jm->get().back();
609 if (last->finished_in_error()) {
610 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()));
617 void setup_menu (wxMenuBar* m)
619 _file_menu = new wxMenu;
620 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
621 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
622 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
624 _history_position = _file_menu->GetMenuItems().GetCount();
626 _file_menu->AppendSeparator ();
627 _file_menu->Append (ID_file_close, _("&Close"));
628 _file_menu->AppendSeparator ();
631 _file_menu->Append (wxID_EXIT, _("&Exit"));
633 _file_menu->Append (wxID_EXIT, _("&Quit"));
637 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
639 wxMenu* edit = new wxMenu;
640 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
643 prefs->Enable (Config::instance()->have_write_permission());
645 _cpl_menu = new wxMenu;
647 wxMenu* view = new wxMenu;
648 optional<int> c = Config::instance()->decode_reduction();
649 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
650 view->AppendSeparator();
651 #ifndef DCPOMATIC_VARIANT_SWAROOP
652 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
653 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
656 view->AppendSeparator();
657 view->Append(ID_view_closed_captions, _("Closed captions..."));
658 view->AppendSeparator();
659 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
660 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
661 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
662 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
664 wxMenu* tools = new wxMenu;
665 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
666 tools->AppendSeparator ();
667 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
668 tools->Append (ID_tools_timing, _("Timing..."));
669 tools->Append (ID_tools_system_information, _("System information..."));
671 wxMenu* help = new wxMenu;
673 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
675 help->Append (wxID_ABOUT, _("About"));
677 help->Append (ID_help_report_a_problem, _("Report a problem..."));
679 m->Append (_file_menu, _("&File"));
681 m->Append (edit, _("&Edit"));
683 m->Append (view, _("&View"));
684 m->Append (tools, _("&Tools"));
685 m->Append (help, _("&Help"));
690 wxString d = wxStandardPaths::Get().GetDocumentsDir();
691 if (Config::instance()->last_player_load_directory()) {
692 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
695 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
700 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
701 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
708 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
710 Config::instance()->set_last_player_load_directory (dcp.parent_path());
718 wxDirDialog* c = new wxDirDialog (
720 _("Select DCP to open as OV"),
721 wxStandardPaths::Get().GetDocumentsDir(),
722 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
728 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
729 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
736 DCPOMATIC_ASSERT (_film);
737 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
738 DCPOMATIC_ASSERT (dcp);
739 dcp->add_ov (wx_to_std(c->GetPath()));
740 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
741 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
742 if (!ok || !report_errors_from_last_job(this)) {
745 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
749 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
751 _film->set_container(r);
757 _info->triggered_update ();
762 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
764 if (d->ShowModal() == wxID_OK) {
765 DCPOMATIC_ASSERT (_film);
766 #ifdef DCPOMATIC_VARIANT_SWAROOP
767 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
770 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
771 } catch (exception& e) {
772 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
778 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
779 #ifndef DCPOMATIC_VARIANT_SWAROOP
780 DCPOMATIC_ASSERT (dcp);
784 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
785 dcp->examine (_film, shared_ptr<Job>());
787 } catch (exception& e) {
788 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
795 _info->triggered_update ();
798 void file_history (wxCommandEvent& event)
800 vector<boost::filesystem::path> history = Config::instance()->player_history ();
801 int n = event.GetId() - ID_file_history;
802 if (n >= 0 && n < static_cast<int> (history.size ())) {
804 load_dcp (history[n]);
805 } catch (exception& e) {
806 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
814 _info->triggered_update ();
815 set_menu_sensitivity ();
823 void edit_preferences ()
825 if (!Config::instance()->have_write_permission()) {
829 if (!_config_dialog) {
830 _config_dialog = create_player_config_dialog ();
832 _config_dialog->Show (this);
835 void view_cpl (wxCommandEvent& ev)
837 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
838 DCPOMATIC_ASSERT (dcp);
839 DCPExaminer ex (dcp, true);
840 int id = ev.GetId() - ID_view_cpl;
841 DCPOMATIC_ASSERT (id >= 0);
842 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
843 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
844 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
850 dcp->set_cpl ((*i)->id());
851 dcp->examine (_film, shared_ptr<Job>());
854 void view_full_screen ()
856 if (_mode == Config::PLAYER_MODE_FULL) {
857 _mode = Config::PLAYER_MODE_WINDOW;
859 _mode = Config::PLAYER_MODE_FULL;
865 void view_dual_screen ()
867 if (_mode == Config::PLAYER_MODE_DUAL) {
868 _mode = Config::PLAYER_MODE_WINDOW;
870 _mode = Config::PLAYER_MODE_DUAL;
878 if (_view_full_screen) {
879 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
881 if (_view_dual_screen) {
882 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
888 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
889 _info->Show (_mode != Config::PLAYER_MODE_FULL);
890 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
891 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
892 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
894 if (_mode == Config::PLAYER_MODE_DUAL) {
895 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
896 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
897 _dual_screen->ShowFullScreen (true);
898 _viewer->panel()->Reparent (_dual_screen);
899 _dual_screen->Show ();
900 if (wxDisplay::GetCount() > 1) {
901 switch (Config::instance()->image_display()) {
903 _dual_screen->Move (0, 0);
904 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
907 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
908 // (0, 0) doesn't seem to work for some strange reason
915 _viewer->panel()->Reparent (_overall_panel);
916 _dual_screen->Destroy ();
921 setup_main_sizer (_mode);
924 void view_closed_captions ()
926 _viewer->show_closed_captions ();
931 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
932 DCPOMATIC_ASSERT (dcp);
934 JobManager* jm = JobManager::instance ();
935 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
936 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
941 DCPOMATIC_ASSERT (!jm->get().empty());
942 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
943 DCPOMATIC_ASSERT (last);
945 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
950 void tools_check_for_updates ()
952 UpdateChecker::instance()->run ();
953 _update_news_requested = true;
958 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
963 void tools_system_information ()
965 if (!_system_information_dialog) {
966 _system_information_dialog = new SystemInformationDialog (this, _viewer);
969 _system_information_dialog->Show ();
974 AboutDialog* d = new AboutDialog (this);
979 void help_report_a_problem ()
981 ReportProblemDialog* d = new ReportProblemDialog (this);
982 if (d->ShowModal () == wxID_OK) {
988 void update_checker_state_changed ()
990 UpdateChecker* uc = UpdateChecker::instance ();
992 bool const announce =
993 _update_news_requested ||
994 (uc->stable() && Config::instance()->check_for_updates()) ||
995 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
997 _update_news_requested = false;
1003 if (uc->state() == UpdateChecker::YES) {
1004 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
1005 dialog->ShowModal ();
1007 } else if (uc->state() == UpdateChecker::FAILED) {
1008 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
1010 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
1013 _update_news_requested = false;
1016 void config_changed (Config::Property prop)
1018 /* Instantly save any config changes when using the player GUI */
1020 Config::instance()->write_config();
1021 } catch (FileError& e) {
1022 if (prop != Config::HISTORY) {
1026 _("Could not write to config file at %s. Your changes have not been saved."),
1027 std_to_wx(e.file().string())
1031 } catch (exception& e) {
1034 _("Could not write to config file. Your changes have not been saved.")
1038 update_from_config (prop);
1041 void update_from_config (Config::Property prop)
1043 for (int i = 0; i < _history_items; ++i) {
1044 delete _file_menu->Remove (ID_file_history + i);
1047 if (_history_separator) {
1048 _file_menu->Remove (_history_separator);
1050 delete _history_separator;
1051 _history_separator = 0;
1053 int pos = _history_position;
1055 /* Clear out non-existant history items before we re-build the menu */
1056 Config::instance()->clean_player_history ();
1057 vector<boost::filesystem::path> history = Config::instance()->player_history ();
1059 if (!history.empty ()) {
1060 _history_separator = _file_menu->InsertSeparator (pos++);
1063 for (size_t i = 0; i < history.size(); ++i) {
1066 s = String::compose ("&%1 %2", i + 1, history[i].string());
1068 s = history[i].string();
1070 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1073 _history_items = history.size ();
1075 if (prop == Config::PLAYER_DEBUG_LOG) {
1076 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1078 dcpomatic_log.reset (new FileLog(*p));
1080 dcpomatic_log.reset (new NullLog());
1082 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
1086 void set_menu_sensitivity ()
1088 _tools_verify->Enable (static_cast<bool>(_film));
1089 _file_add_ov->Enable (static_cast<bool>(_film));
1090 _file_add_kdm->Enable (static_cast<bool>(_film));
1091 _view_cpl->Enable (static_cast<bool>(_film));
1094 void start_stop_pressed ()
1096 if (_viewer->playing()) {
1105 _viewer->seek_by (-_viewer->one_video_frame(), true);
1108 void forward_frame ()
1110 _viewer->seek_by (_viewer->one_video_frame(), true);
1115 wxFrame* _dual_screen;
1116 bool _update_news_requested;
1117 PlayerInformation* _info;
1118 Config::PlayerMode _mode;
1119 wxPreferencesEditor* _config_dialog;
1120 wxPanel* _overall_panel;
1122 wxMenuItem* _view_cpl;
1125 int _history_position;
1126 wxMenuItem* _history_separator;
1127 shared_ptr<FilmViewer> _viewer;
1128 Controls* _controls;
1129 SystemInformationDialog* _system_information_dialog;
1130 boost::shared_ptr<Film> _film;
1131 boost::signals2::scoped_connection _config_changed_connection;
1132 wxMenuItem* _file_add_ov;
1133 wxMenuItem* _file_add_kdm;
1134 wxMenuItem* _tools_verify;
1135 wxMenuItem* _view_full_screen;
1136 wxMenuItem* _view_dual_screen;
1137 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1139 list<Command> _commands;
1140 list<Command>::const_iterator _current_command;
1141 optional<int> _wait_remaining;
1145 static const wxCmdLineEntryDesc command_line_description[] = {
1146 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1147 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1148 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1149 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1151 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1154 class PlayServer : public Server
1157 explicit PlayServer (DOMFrame* frame)
1158 : Server (PLAYER_PLAY_PORT)
1162 void handle (shared_ptr<Socket> socket)
1165 int const length = socket->read_uint32 ();
1166 scoped_array<char> buffer (new char[length]);
1167 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1168 string s (buffer.get());
1169 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1170 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1181 * @brief The magic App class for wxWidgets.
1183 class App : public wxApp
1190 #ifdef DCPOMATIC_LINUX
1199 wxSplashScreen* splash = 0;
1201 wxInitAllImageHandlers ();
1203 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1204 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1206 splash = maybe_show_splash ();
1208 SetAppName (_("DCP-o-matic Player"));
1210 if (!wxApp::OnInit()) {
1214 #ifdef DCPOMATIC_LINUX
1215 unsetenv ("UBUNTU_MENUPROXY");
1219 ProcessSerialNumber serial;
1220 GetCurrentProcess (&serial);
1221 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1224 dcpomatic_setup_path_encoding ();
1226 /* Enable i18n; this will create a Config object
1227 to look for a force-configured language. This Config
1228 object will be wrong, however, because dcpomatic_setup
1229 hasn't yet been called and there aren't any filters etc.
1232 dcpomatic_setup_i18n ();
1234 /* Set things up, including filters etc.
1235 which will now be internationalised correctly.
1239 /* Force the configuration to be re-loaded correctly next
1244 signal_manager = new wxSignalManager (this);
1246 _frame = new DOMFrame ();
1247 SetTopWindow (_frame);
1248 _frame->Maximize ();
1255 PlayServer* server = new PlayServer (_frame);
1256 new thread (boost::bind (&PlayServer::run, server));
1258 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1260 _frame->load_dcp (_dcp_to_load);
1261 } catch (exception& e) {
1262 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1266 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1269 _frame->stress (_stress.get());
1270 } catch (exception& e) {
1271 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1276 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1278 if (Config::instance()->check_for_updates ()) {
1279 UpdateChecker::instance()->run ();
1282 catch (exception& e)
1287 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1293 void OnInitCmdLine (wxCmdLineParser& parser)
1295 parser.SetDesc (command_line_description);
1296 parser.SetSwitchChars (wxT ("-"));
1299 bool OnCmdLineParsed (wxCmdLineParser& parser)
1301 if (parser.GetParamCount() > 0) {
1302 _dcp_to_load = wx_to_std (parser.GetParam (0));
1306 if (parser.Found("c", &config)) {
1307 Config::override_path = wx_to_std (config);
1309 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1311 if (parser.Found("s", &stress)) {
1312 _stress = wx_to_std (stress);
1319 void report_exception ()
1323 } catch (FileError& e) {
1327 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1328 std_to_wx (e.what()),
1329 std_to_wx (e.file().string().c_str ())
1332 } catch (exception& e) {
1336 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1337 std_to_wx (e.what ())
1341 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1345 /* An unhandled exception has occurred inside the main event loop */
1346 bool OnExceptionInMainLoop ()
1348 report_exception ();
1349 /* This will terminate the program */
1353 void OnUnhandledException ()
1355 report_exception ();
1360 signal_manager->ui_idle ();
1363 void config_failed_to_load ()
1365 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1368 void config_warning (string m)
1370 message_dialog (_frame, std_to_wx (m));
1374 string _dcp_to_load;
1375 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1376 boost::optional<string> _stress;