2 Copyright (C) 2017-2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "wx/wx_signal_manager.h"
22 #include "wx/wx_util.h"
23 #include "wx/about_dialog.h"
24 #include "wx/report_problem_dialog.h"
25 #include "wx/film_viewer.h"
26 #include "wx/player_information.h"
27 #include "wx/update_dialog.h"
28 #include "wx/player_config_dialog.h"
29 #include "wx/verify_dcp_dialog.h"
30 #include "wx/standard_controls.h"
31 #include "wx/playlist_controls.h"
32 #ifdef DCPOMATIC_VARIANT_SWAROOP
33 #include "wx/swaroop_controls.h"
35 #include "wx/timer_display.h"
36 #include "wx/system_information_dialog.h"
37 #include "wx/player_stress_tester.h"
38 #include "lib/cross.h"
39 #include "lib/config.h"
41 #include "lib/internet.h"
42 #include "lib/update_checker.h"
43 #include "lib/compose.hpp"
44 #include "lib/dcp_content.h"
45 #include "lib/job_manager.h"
48 #include "lib/null_log.h"
49 #include "lib/video_content.h"
50 #include "lib/text_content.h"
51 #include "lib/ratio.h"
52 #include "lib/verify_dcp_job.h"
53 #include "lib/dcp_examiner.h"
54 #include "lib/examine_content_job.h"
55 #include "lib/server.h"
56 #include "lib/dcpomatic_socket.h"
57 #include "lib/scoped_temporary.h"
58 #include "lib/monitor_checker.h"
59 #include "lib/lock_file_checker.h"
60 #include "lib/ffmpeg_content.h"
61 #include "lib/dcpomatic_log.h"
62 #include "lib/file_log.h"
64 #include <dcp/raw_convert.h>
65 #include <dcp/exceptions.h>
67 #include <wx/stdpaths.h>
68 #include <wx/splash.h>
69 #include <wx/cmdline.h>
70 #include <wx/preferences.h>
71 #include <wx/progdlg.h>
72 #include <wx/display.h>
77 #include <ApplicationServices/ApplicationServices.h>
79 #include <boost/bind.hpp>
80 #include <boost/algorithm/string.hpp>
94 using boost::shared_ptr;
95 using boost::weak_ptr;
96 using boost::scoped_array;
97 using boost::optional;
98 using boost::dynamic_pointer_cast;
101 using dcp::raw_convert;
102 using namespace dcpomatic;
109 /* Allow spare IDs after _history for the recent files list */
112 /* Allow spare IDs for CPLs */
113 ID_view_full_screen = 200,
115 ID_view_closed_captions,
116 ID_view_scale_appropriate,
119 ID_view_scale_quarter,
120 ID_help_report_a_problem,
122 ID_tools_check_for_updates,
124 ID_tools_system_information,
125 /* IDs for shortcuts (with no associated menu item) */
129 ID_go_back_small_amount,
130 ID_go_forward_small_amount,
131 ID_go_back_medium_amount,
132 ID_go_forward_medium_amount,
133 ID_go_back_large_amount,
134 ID_go_forward_large_amount,
139 class DOMFrame : public wxFrame
143 : wxFrame (0, -1, _("DCP-o-matic Player"))
145 , _update_news_requested (false)
147 , _mode (Config::instance()->player_mode())
151 , _history_position (0)
152 , _history_separator (0)
153 , _system_information_dialog (0)
154 , _view_full_screen (0)
155 , _view_dual_screen (0)
157 dcpomatic_log.reset (new NullLog());
159 #if defined(DCPOMATIC_WINDOWS)
160 maybe_open_console ();
161 cout << "DCP-o-matic Player is starting." << "\n";
164 wxMenuBar* bar = new wxMenuBar;
166 set_menu_sensitivity ();
169 #ifdef DCPOMATIC_WINDOWS
170 SetIcon (wxIcon (std_to_wx ("id")));
173 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
174 update_from_config (Config::PLAYER_DEBUG_LOG);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
182 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
183 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
184 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
185 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
188 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
189 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
190 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
192 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
193 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
194 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
195 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
197 /* Use a panel as the only child of the Frame so that we avoid
198 the dark-grey background on Windows.
200 _overall_panel = new wxPanel (this, wxID_ANY);
202 _viewer.reset (new FilmViewer (_overall_panel));
203 #ifdef DCPOMATIC_VARIANT_SWAROOP
204 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
206 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
208 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
209 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
211 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
213 _controls = new StandardControls (_overall_panel, _viewer, false);
216 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
217 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
218 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
219 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
220 _info = new PlayerInformation (_overall_panel, _viewer);
221 setup_main_sizer (Config::instance()->player_mode());
223 int accelerators = 12;
225 int accelerators = 11;
228 _stress.setup (this, _controls);
230 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
231 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
232 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_go_back_frame);
233 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_go_forward_frame);
234 accel[3].Set(wxACCEL_SHIFT, WXK_LEFT, ID_go_back_small_amount);
235 accel[4].Set(wxACCEL_SHIFT, WXK_RIGHT, ID_go_forward_small_amount);
236 accel[5].Set(wxACCEL_CTRL, WXK_LEFT, ID_go_back_medium_amount);
237 accel[6].Set(wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_medium_amount);
238 accel[7].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_LEFT, ID_go_back_large_amount);
239 accel[8].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_large_amount);
240 accel[9].Set(wxACCEL_NORMAL, WXK_HOME, ID_go_to_start);
241 accel[10].Set(wxACCEL_NORMAL, WXK_END, ID_go_to_end);
243 accel[11].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
245 wxAcceleratorTable accel_table (accelerators, accel);
246 SetAcceleratorTable (accel_table);
249 Bind (wxEVT_MENU, boost::bind(&DOMFrame::start_stop_pressed, this), ID_start_stop);
250 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_back_frame, this), ID_go_back_frame);
251 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_forward_frame, this), ID_go_forward_frame);
252 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -60), ID_go_back_small_amount);
253 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 60), ID_go_forward_small_amount);
254 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -600), ID_go_back_medium_amount);
255 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 600), ID_go_forward_medium_amount);
256 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -3600), ID_go_back_large_amount);
257 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 3600), ID_go_forward_large_amount);
258 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_start, this), ID_go_to_start);
259 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_end, this), ID_go_to_end);
263 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
264 #ifdef DCPOMATIC_VARIANT_SWAROOP
265 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
266 MonitorChecker::instance()->run ();
267 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
268 LockFileChecker::instance()->run ();
272 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
274 #ifdef DCPOMATIC_VARIANT_SWAROOP
275 sc->check_restart ();
279 #ifdef DCPOMATIC_VARIANT_SWAROOP
280 void monitor_checker_state_changed ()
282 if (!MonitorChecker::instance()->ok()) {
284 error_dialog (this, _("The required display devices are not connected correctly."));
288 void lock_checker_state_changed ()
290 if (!LockFileChecker::instance()->ok()) {
292 error_dialog (this, _("The lock file is not present."));
297 void setup_main_sizer (Config::PlayerMode mode)
299 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
300 if (mode != Config::PLAYER_MODE_DUAL) {
301 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
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()));
432 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
434 shared_ptr<Job> job = weak_job.lock ();
435 if (!job || !job->finished_ok()) {
439 shared_ptr<Content> content = weak_content.lock ();
444 _film->add_content (content);
445 _stress.set_suspended (false);
448 void reset_film_weak (weak_ptr<Film> weak_film)
450 shared_ptr<Film> film = weak_film.lock ();
456 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
459 _film->set_tolerant (true);
460 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
461 _viewer->set_film (_film);
462 _controls->set_film (_film);
463 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
464 _info->triggered_update ();
467 void film_changed (ChangeType type, Film::Property property)
469 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
473 if (_viewer->playing ()) {
477 /* Start off as Flat */
478 _film->set_container (Ratio::from_id("185"));
480 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
481 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
483 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
488 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
489 if (r->id() == "239") {
490 /* Any scope content means we use scope */
491 _film->set_container(r);
495 /* Any 3D content means we use 3D mode */
496 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
497 _film->set_three_d (true);
501 _viewer->seek (DCPTime(), true);
502 _info->triggered_update ();
504 set_menu_sensitivity ();
506 wxMenuItemList old = _cpl_menu->GetMenuItems();
507 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
508 _cpl_menu->Remove (*i);
511 if (_film->content().size() == 1) {
512 /* Offer a CPL menu */
513 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
515 DCPExaminer ex (first, true);
516 int id = ID_view_cpl;
517 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
518 wxMenuItem* j = _cpl_menu->AppendRadioItem(
520 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
522 j->Check(!first->cpl() || i->id() == *first->cpl());
529 void load_stress_script (boost::filesystem::path path)
531 _stress.load_script (path);
536 bool report_errors_from_last_job (wxWindow* parent) const
538 JobManager* jm = JobManager::instance ();
540 DCPOMATIC_ASSERT (!jm->get().empty());
542 shared_ptr<Job> last = jm->get().back();
543 if (last->finished_in_error()) {
544 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()));
551 void setup_menu (wxMenuBar* m)
553 _file_menu = new wxMenu;
554 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
555 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
556 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
558 _history_position = _file_menu->GetMenuItems().GetCount();
560 _file_menu->AppendSeparator ();
561 _file_menu->Append (ID_file_close, _("&Close"));
562 _file_menu->AppendSeparator ();
565 _file_menu->Append (wxID_EXIT, _("&Exit"));
567 _file_menu->Append (wxID_EXIT, _("&Quit"));
571 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
573 wxMenu* edit = new wxMenu;
574 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
577 prefs->Enable (Config::instance()->have_write_permission());
579 _cpl_menu = new wxMenu;
581 wxMenu* view = new wxMenu;
582 optional<int> c = Config::instance()->decode_reduction();
583 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
584 view->AppendSeparator();
585 #ifndef DCPOMATIC_VARIANT_SWAROOP
586 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
587 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
590 view->AppendSeparator();
591 view->Append(ID_view_closed_captions, _("Closed captions..."));
592 view->AppendSeparator();
593 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
594 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
595 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
596 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
598 wxMenu* tools = new wxMenu;
599 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
600 tools->AppendSeparator ();
601 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
602 tools->Append (ID_tools_timing, _("Timing..."));
603 tools->Append (ID_tools_system_information, _("System information..."));
605 wxMenu* help = new wxMenu;
607 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
609 help->Append (wxID_ABOUT, _("About"));
611 help->Append (ID_help_report_a_problem, _("Report a problem..."));
613 m->Append (_file_menu, _("&File"));
615 m->Append (edit, _("&Edit"));
617 m->Append (view, _("&View"));
618 m->Append (tools, _("&Tools"));
619 m->Append (help, _("&Help"));
624 wxString d = wxStandardPaths::Get().GetDocumentsDir();
625 if (Config::instance()->last_player_load_directory()) {
626 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
629 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
634 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
635 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
642 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
644 Config::instance()->set_last_player_load_directory (dcp.parent_path());
652 wxDirDialog* c = new wxDirDialog (
654 _("Select DCP to open as OV"),
655 wxStandardPaths::Get().GetDocumentsDir(),
656 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
662 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
663 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
670 DCPOMATIC_ASSERT (_film);
671 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
672 DCPOMATIC_ASSERT (dcp);
673 dcp->add_ov (wx_to_std(c->GetPath()));
674 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
675 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
676 if (!ok || !report_errors_from_last_job(this)) {
679 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
683 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
685 _film->set_container(r);
691 _info->triggered_update ();
696 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
698 if (d->ShowModal() == wxID_OK) {
699 DCPOMATIC_ASSERT (_film);
700 #ifdef DCPOMATIC_VARIANT_SWAROOP
701 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
704 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
705 } catch (exception& e) {
706 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
712 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
713 #ifndef DCPOMATIC_VARIANT_SWAROOP
714 DCPOMATIC_ASSERT (dcp);
718 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
719 dcp->examine (_film, shared_ptr<Job>());
721 } catch (exception& e) {
722 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
729 _info->triggered_update ();
732 void file_history (wxCommandEvent& event)
734 vector<boost::filesystem::path> history = Config::instance()->player_history ();
735 int n = event.GetId() - ID_file_history;
736 if (n >= 0 && n < static_cast<int> (history.size ())) {
738 load_dcp (history[n]);
739 } catch (exception& e) {
740 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
748 _info->triggered_update ();
749 set_menu_sensitivity ();
757 void edit_preferences ()
759 if (!Config::instance()->have_write_permission()) {
763 if (!_config_dialog) {
764 _config_dialog = create_player_config_dialog ();
766 _config_dialog->Show (this);
769 void view_cpl (wxCommandEvent& ev)
771 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
772 DCPOMATIC_ASSERT (dcp);
773 DCPExaminer ex (dcp, true);
774 int id = ev.GetId() - ID_view_cpl;
775 DCPOMATIC_ASSERT (id >= 0);
776 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
777 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
778 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
784 dcp->set_cpl ((*i)->id());
785 dcp->examine (_film, shared_ptr<Job>());
788 void view_full_screen ()
790 if (_mode == Config::PLAYER_MODE_FULL) {
791 _mode = Config::PLAYER_MODE_WINDOW;
793 _mode = Config::PLAYER_MODE_FULL;
799 void view_dual_screen ()
801 if (_mode == Config::PLAYER_MODE_DUAL) {
802 _mode = Config::PLAYER_MODE_WINDOW;
804 _mode = Config::PLAYER_MODE_DUAL;
812 if (_view_full_screen) {
813 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
815 if (_view_dual_screen) {
816 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
822 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
823 _info->Show (_mode != Config::PLAYER_MODE_FULL);
824 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
825 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
826 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
828 if (_mode == Config::PLAYER_MODE_DUAL) {
829 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
830 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
831 _dual_screen->ShowFullScreen (true);
832 _viewer->panel()->Reparent (_dual_screen);
833 _dual_screen->Show ();
834 if (wxDisplay::GetCount() > 1) {
835 switch (Config::instance()->image_display()) {
837 _dual_screen->Move (0, 0);
838 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
841 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
842 // (0, 0) doesn't seem to work for some strange reason
849 _viewer->panel()->Reparent (_overall_panel);
850 _dual_screen->Destroy ();
855 setup_main_sizer (_mode);
858 void view_closed_captions ()
860 _viewer->show_closed_captions ();
865 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
866 DCPOMATIC_ASSERT (dcp);
868 JobManager* jm = JobManager::instance ();
869 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
870 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
875 DCPOMATIC_ASSERT (!jm->get().empty());
876 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
877 DCPOMATIC_ASSERT (last);
879 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
884 void tools_check_for_updates ()
886 UpdateChecker::instance()->run ();
887 _update_news_requested = true;
892 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
897 void tools_system_information ()
899 if (!_system_information_dialog) {
900 _system_information_dialog = new SystemInformationDialog (this, _viewer);
903 _system_information_dialog->Show ();
908 AboutDialog* d = new AboutDialog (this);
913 void help_report_a_problem ()
915 ReportProblemDialog* d = new ReportProblemDialog (this);
916 if (d->ShowModal () == wxID_OK) {
922 void update_checker_state_changed ()
924 UpdateChecker* uc = UpdateChecker::instance ();
926 bool const announce =
927 _update_news_requested ||
928 (uc->stable() && Config::instance()->check_for_updates()) ||
929 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
931 _update_news_requested = false;
937 if (uc->state() == UpdateChecker::YES) {
938 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
939 dialog->ShowModal ();
941 } else if (uc->state() == UpdateChecker::FAILED) {
942 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
944 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
947 _update_news_requested = false;
950 void config_changed (Config::Property prop)
952 /* Instantly save any config changes when using the player GUI */
954 Config::instance()->write_config();
955 } catch (FileError& e) {
956 if (prop != Config::HISTORY) {
960 _("Could not write to config file at %s. Your changes have not been saved."),
961 std_to_wx(e.file().string())
965 } catch (exception& e) {
968 _("Could not write to config file. Your changes have not been saved.")
972 update_from_config (prop);
975 void update_from_config (Config::Property prop)
977 for (int i = 0; i < _history_items; ++i) {
978 delete _file_menu->Remove (ID_file_history + i);
981 if (_history_separator) {
982 _file_menu->Remove (_history_separator);
984 delete _history_separator;
985 _history_separator = 0;
987 int pos = _history_position;
989 /* Clear out non-existant history items before we re-build the menu */
990 Config::instance()->clean_player_history ();
991 vector<boost::filesystem::path> history = Config::instance()->player_history ();
993 if (!history.empty ()) {
994 _history_separator = _file_menu->InsertSeparator (pos++);
997 for (size_t i = 0; i < history.size(); ++i) {
1000 s = String::compose ("&%1 %2", i + 1, history[i].string());
1002 s = history[i].string();
1004 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1007 _history_items = history.size ();
1009 if (prop == Config::PLAYER_DEBUG_LOG) {
1010 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1012 dcpomatic_log.reset (new FileLog(*p));
1014 dcpomatic_log.reset (new NullLog());
1016 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
1020 void set_menu_sensitivity ()
1022 _tools_verify->Enable (static_cast<bool>(_film));
1023 _file_add_ov->Enable (static_cast<bool>(_film));
1024 _file_add_kdm->Enable (static_cast<bool>(_film));
1025 _view_cpl->Enable (static_cast<bool>(_film));
1028 void start_stop_pressed ()
1030 if (_viewer->playing()) {
1037 void go_back_frame ()
1039 _viewer->seek_by (-_viewer->one_video_frame(), true);
1042 void go_forward_frame ()
1044 _viewer->seek_by (_viewer->one_video_frame(), true);
1047 void go_seconds (int s)
1049 _viewer->seek_by (DCPTime::from_seconds(s), true);
1054 _viewer->seek (DCPTime(), true);
1059 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
1062 wxFrame* _dual_screen;
1063 bool _update_news_requested;
1064 PlayerInformation* _info;
1065 Config::PlayerMode _mode;
1066 wxPreferencesEditor* _config_dialog;
1067 wxPanel* _overall_panel;
1069 wxMenuItem* _view_cpl;
1072 int _history_position;
1073 wxMenuItem* _history_separator;
1074 shared_ptr<FilmViewer> _viewer;
1075 Controls* _controls;
1076 SystemInformationDialog* _system_information_dialog;
1077 boost::shared_ptr<Film> _film;
1078 boost::signals2::scoped_connection _config_changed_connection;
1079 boost::signals2::scoped_connection _examine_job_connection;
1080 wxMenuItem* _file_add_ov;
1081 wxMenuItem* _file_add_kdm;
1082 wxMenuItem* _tools_verify;
1083 wxMenuItem* _view_full_screen;
1084 wxMenuItem* _view_dual_screen;
1085 PlayerStressTester _stress;
1088 static const wxCmdLineEntryDesc command_line_description[] = {
1089 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1090 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1091 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1092 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1095 class PlayServer : public Server
1098 explicit PlayServer (DOMFrame* frame)
1099 : Server (PLAYER_PLAY_PORT)
1103 void handle (shared_ptr<Socket> socket)
1106 int const length = socket->read_uint32 ();
1107 scoped_array<char> buffer (new char[length]);
1108 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1109 string s (buffer.get());
1110 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1111 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1122 * @brief The magic App class for wxWidgets.
1124 class App : public wxApp
1131 #ifdef DCPOMATIC_LINUX
1140 wxSplashScreen* splash = 0;
1142 wxInitAllImageHandlers ();
1144 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1145 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1147 splash = maybe_show_splash ();
1149 SetAppName (_("DCP-o-matic Player"));
1151 if (!wxApp::OnInit()) {
1155 #ifdef DCPOMATIC_LINUX
1156 unsetenv ("UBUNTU_MENUPROXY");
1160 ProcessSerialNumber serial;
1161 GetCurrentProcess (&serial);
1162 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1165 dcpomatic_setup_path_encoding ();
1167 /* Enable i18n; this will create a Config object
1168 to look for a force-configured language. This Config
1169 object will be wrong, however, because dcpomatic_setup
1170 hasn't yet been called and there aren't any filters etc.
1173 dcpomatic_setup_i18n ();
1175 /* Set things up, including filters etc.
1176 which will now be internationalised correctly.
1180 /* Force the configuration to be re-loaded correctly next
1185 signal_manager = new wxSignalManager (this);
1187 _frame = new DOMFrame ();
1188 SetTopWindow (_frame);
1189 _frame->Maximize ();
1196 PlayServer* server = new PlayServer (_frame);
1197 new thread (boost::bind (&PlayServer::run, server));
1199 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1201 _frame->load_dcp (_dcp_to_load);
1202 } catch (exception& e) {
1203 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1209 _frame->load_stress_script (*_stress);
1210 } catch (exception& e) {
1211 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1215 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1217 if (Config::instance()->check_for_updates ()) {
1218 UpdateChecker::instance()->run ();
1221 catch (exception& e)
1226 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1232 void OnInitCmdLine (wxCmdLineParser& parser)
1234 parser.SetDesc (command_line_description);
1235 parser.SetSwitchChars (wxT ("-"));
1238 bool OnCmdLineParsed (wxCmdLineParser& parser)
1240 if (parser.GetParamCount() > 0) {
1241 _dcp_to_load = wx_to_std (parser.GetParam (0));
1245 if (parser.Found("c", &config)) {
1246 Config::override_path = wx_to_std (config);
1249 if (parser.Found("s", &stress)) {
1250 _stress = wx_to_std (stress);
1256 void report_exception ()
1260 } catch (FileError& e) {
1264 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1265 std_to_wx (e.what()),
1266 std_to_wx (e.file().string().c_str ())
1269 } catch (exception& e) {
1273 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1274 std_to_wx (e.what ())
1278 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1282 /* An unhandled exception has occurred inside the main event loop */
1283 bool OnExceptionInMainLoop ()
1285 report_exception ();
1286 /* This will terminate the program */
1290 void OnUnhandledException ()
1292 report_exception ();
1297 signal_manager->ui_idle ();
1300 void config_failed_to_load ()
1302 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1305 void config_warning (string m)
1307 message_dialog (_frame, std_to_wx (m));
1311 string _dcp_to_load;
1312 boost::optional<string> _stress;