2 Copyright (C) 2017-2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "wx/wx_signal_manager.h"
22 #include "wx/wx_util.h"
23 #include "wx/about_dialog.h"
24 #include "wx/report_problem_dialog.h"
25 #include "wx/film_viewer.h"
26 #include "wx/player_information.h"
27 #include "wx/update_dialog.h"
28 #include "wx/player_config_dialog.h"
29 #include "wx/verify_dcp_dialog.h"
30 #include "wx/standard_controls.h"
31 #include "wx/playlist_controls.h"
32 #ifdef DCPOMATIC_VARIANT_SWAROOP
33 #include "wx/swaroop_controls.h"
35 #include "wx/timer_display.h"
36 #include "wx/system_information_dialog.h"
37 #include "wx/player_stress_tester.h"
38 #include "lib/cross.h"
39 #include "lib/config.h"
41 #include "lib/internet.h"
42 #include "lib/update_checker.h"
43 #include "lib/compose.hpp"
44 #include "lib/dcp_content.h"
45 #include "lib/job_manager.h"
48 #include "lib/null_log.h"
49 #include "lib/video_content.h"
50 #include "lib/text_content.h"
51 #include "lib/ratio.h"
52 #include "lib/verify_dcp_job.h"
53 #include "lib/dcp_examiner.h"
54 #include "lib/examine_content_job.h"
55 #include "lib/server.h"
56 #include "lib/dcpomatic_socket.h"
57 #include "lib/scoped_temporary.h"
58 #include "lib/monitor_checker.h"
59 #include "lib/lock_file_checker.h"
60 #include "lib/ffmpeg_content.h"
61 #include "lib/dcpomatic_log.h"
62 #include "lib/file_log.h"
64 #include <dcp/raw_convert.h>
65 #include <dcp/exceptions.h>
67 #include <wx/stdpaths.h>
68 #include <wx/splash.h>
69 #include <wx/cmdline.h>
70 #include <wx/preferences.h>
71 #include <wx/progdlg.h>
72 #include <wx/display.h>
76 #include <boost/bind.hpp>
77 #include <boost/algorithm/string.hpp>
91 using boost::shared_ptr;
92 using boost::weak_ptr;
93 using boost::scoped_array;
94 using boost::optional;
95 using boost::dynamic_pointer_cast;
98 using dcp::raw_convert;
99 using namespace dcpomatic;
106 /* Allow spare IDs after _history for the recent files list */
109 /* Allow spare IDs for CPLs */
110 ID_view_full_screen = 200,
112 ID_view_closed_captions,
113 ID_view_scale_appropriate,
116 ID_view_scale_quarter,
117 ID_help_report_a_problem,
119 ID_tools_check_for_updates,
121 ID_tools_system_information,
122 /* IDs for shortcuts (with no associated menu item) */
126 ID_go_back_small_amount,
127 ID_go_forward_small_amount,
128 ID_go_back_medium_amount,
129 ID_go_forward_medium_amount,
130 ID_go_back_large_amount,
131 ID_go_forward_large_amount,
136 class DOMFrame : public wxFrame
140 : wxFrame (0, -1, _("DCP-o-matic Player"))
142 , _update_news_requested (false)
144 , _mode (Config::instance()->player_mode())
148 , _history_position (0)
149 , _history_separator (0)
150 , _system_information_dialog (0)
151 , _view_full_screen (0)
152 , _view_dual_screen (0)
154 dcpomatic_log.reset (new NullLog());
156 #if defined(DCPOMATIC_WINDOWS)
157 maybe_open_console ();
158 cout << "DCP-o-matic Player is starting." << "\n";
161 wxMenuBar* bar = new wxMenuBar;
163 set_menu_sensitivity ();
166 #ifdef DCPOMATIC_WINDOWS
167 SetIcon (wxIcon (std_to_wx ("id")));
170 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
171 update_from_config (Config::PLAYER_DEBUG_LOG);
173 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
174 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
175 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
182 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
183 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
184 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
185 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
188 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
189 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
190 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
192 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
194 /* Use a panel as the only child of the Frame so that we avoid
195 the dark-grey background on Windows.
197 _overall_panel = new wxPanel (this, wxID_ANY);
199 _viewer.reset (new FilmViewer (_overall_panel));
200 #ifdef DCPOMATIC_VARIANT_SWAROOP
201 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
203 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
205 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
206 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
208 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
210 _controls = new StandardControls (_overall_panel, _viewer, false);
213 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
214 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
215 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
216 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
217 _info = new PlayerInformation (_overall_panel, _viewer);
218 setup_main_sizer (Config::instance()->player_mode());
220 int accelerators = 12;
222 int accelerators = 11;
225 _stress.setup (this, _controls);
227 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
228 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
229 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_go_back_frame);
230 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_go_forward_frame);
231 accel[3].Set(wxACCEL_SHIFT, WXK_LEFT, ID_go_back_small_amount);
232 accel[4].Set(wxACCEL_SHIFT, WXK_RIGHT, ID_go_forward_small_amount);
233 accel[5].Set(wxACCEL_CTRL, WXK_LEFT, ID_go_back_medium_amount);
234 accel[6].Set(wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_medium_amount);
235 accel[7].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_LEFT, ID_go_back_large_amount);
236 accel[8].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_large_amount);
237 accel[9].Set(wxACCEL_NORMAL, WXK_HOME, ID_go_to_start);
238 accel[10].Set(wxACCEL_NORMAL, WXK_END, ID_go_to_end);
240 accel[11].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
242 wxAcceleratorTable accel_table (accelerators, accel);
243 SetAcceleratorTable (accel_table);
246 Bind (wxEVT_MENU, boost::bind(&DOMFrame::start_stop_pressed, this), ID_start_stop);
247 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_back_frame, this), ID_go_back_frame);
248 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_forward_frame, this), ID_go_forward_frame);
249 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -60), ID_go_back_small_amount);
250 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 60), ID_go_forward_small_amount);
251 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -600), ID_go_back_medium_amount);
252 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 600), ID_go_forward_medium_amount);
253 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -3600), ID_go_back_large_amount);
254 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 3600), ID_go_forward_large_amount);
255 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_start, this), ID_go_to_start);
256 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_end, this), ID_go_to_end);
260 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
261 #ifdef DCPOMATIC_VARIANT_SWAROOP
262 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
263 MonitorChecker::instance()->run ();
264 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
265 LockFileChecker::instance()->run ();
269 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
271 #ifdef DCPOMATIC_VARIANT_SWAROOP
272 sc->check_restart ();
276 #ifdef DCPOMATIC_VARIANT_SWAROOP
277 void monitor_checker_state_changed ()
279 if (!MonitorChecker::instance()->ok()) {
281 error_dialog (this, _("The required display devices are not connected correctly."));
285 void lock_checker_state_changed ()
287 if (!LockFileChecker::instance()->ok()) {
289 error_dialog (this, _("The lock file is not present."));
294 void setup_main_sizer (Config::PlayerMode mode)
296 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
297 if (mode != Config::PLAYER_MODE_DUAL) {
298 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
300 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
301 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
302 _overall_panel->SetSizer (main_sizer);
303 _overall_panel->Layout ();
306 bool playback_permitted ()
308 #ifdef DCPOMATIC_VARIANT_SWAROOP
309 if (!MonitorChecker::instance()->ok()) {
310 error_dialog (this, _("The required display devices are not connected correctly."));
313 if (!LockFileChecker::instance()->ok()) {
314 error_dialog (this, _("The lock file is not present."));
318 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
323 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
324 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
325 if (d && !d->kdm_timing_window_valid()) {
330 #ifdef DCPOMATIC_VARIANT_SWAROOP
331 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
332 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
333 if (c && !c->kdm_timing_window_valid()) {
340 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
346 void playback_started (DCPTime time)
348 /* XXX: this only logs the first piece of content; probably should be each piece? */
349 if (_film->content().empty()) {
353 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
355 DCPExaminer ex (dcp, true);
356 shared_ptr<dcp::CPL> playing_cpl;
357 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
358 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
362 DCPOMATIC_ASSERT (playing_cpl);
366 "playback-started %s %s %s",
367 time.timecode(_film->video_frame_rate()).c_str(),
368 dcp->directories().front().string().c_str(),
369 playing_cpl->annotation_text().c_str()
374 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
378 "playback-started %s %s",
379 time.timecode(_film->video_frame_rate()).c_str(),
380 ffmpeg->path(0).string().c_str()
386 void playback_stopped (DCPTime time)
388 #ifdef DCPOMATIC_VARIANT_SWAROOP
390 boost::filesystem::remove (Config::path("position"));
396 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
399 void set_decode_reduction (optional<int> reduction)
401 _viewer->set_dcp_decode_reduction (reduction);
402 _info->triggered_update ();
403 Config::instance()->set_decode_reduction (reduction);
406 void load_dcp (boost::filesystem::path dir)
408 DCPOMATIC_ASSERT (_film);
412 _stress.set_suspended (true);
413 shared_ptr<DCPContent> dcp (new DCPContent(dir));
414 shared_ptr<Job> job (new ExamineContentJob(_film, dcp));
415 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
416 JobManager::instance()->add (job);
417 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
418 if (!ok || !report_errors_from_last_job(this)) {
421 #ifndef DCPOMATIC_VARIANT_SWAROOP
422 Config::instance()->add_to_player_history (dir);
424 } catch (dcp::ReadError& e) {
425 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
426 } catch (DCPError& e) {
427 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
431 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
433 shared_ptr<Job> job = weak_job.lock ();
434 if (!job || !job->finished_ok()) {
438 shared_ptr<Content> content = weak_content.lock ();
443 _film->add_content (content);
444 _stress.set_suspended (false);
447 void reset_film_weak (weak_ptr<Film> weak_film)
449 shared_ptr<Film> film = weak_film.lock ();
455 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
458 _film->set_tolerant (true);
459 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
460 _viewer->set_film (_film);
461 _controls->set_film (_film);
462 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
463 _info->triggered_update ();
466 void film_changed (ChangeType type, Film::Property property)
468 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
472 if (_viewer->playing ()) {
476 /* Start off as Flat */
477 _film->set_container (Ratio::from_id("185"));
479 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
480 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
482 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
487 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
488 if (r->id() == "239") {
489 /* Any scope content means we use scope */
490 _film->set_container(r);
494 /* Any 3D content means we use 3D mode */
495 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
496 _film->set_three_d (true);
500 _viewer->seek (DCPTime(), true);
501 _info->triggered_update ();
503 set_menu_sensitivity ();
505 wxMenuItemList old = _cpl_menu->GetMenuItems();
506 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
507 _cpl_menu->Remove (*i);
510 if (_film->content().size() == 1) {
511 /* Offer a CPL menu */
512 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
514 DCPExaminer ex (first, true);
515 int id = ID_view_cpl;
516 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
517 wxMenuItem* j = _cpl_menu->AppendRadioItem(
519 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
521 j->Check(!first->cpl() || i->id() == *first->cpl());
528 void load_stress_script (boost::filesystem::path path)
530 _stress.load_script (path);
535 bool report_errors_from_last_job (wxWindow* parent) const
537 JobManager* jm = JobManager::instance ();
539 DCPOMATIC_ASSERT (!jm->get().empty());
541 shared_ptr<Job> last = jm->get().back();
542 if (last->finished_in_error()) {
543 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()));
550 void setup_menu (wxMenuBar* m)
552 _file_menu = new wxMenu;
553 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
554 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
555 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
557 _history_position = _file_menu->GetMenuItems().GetCount();
559 _file_menu->AppendSeparator ();
560 _file_menu->Append (ID_file_close, _("&Close"));
561 _file_menu->AppendSeparator ();
564 _file_menu->Append (wxID_EXIT, _("&Exit"));
566 _file_menu->Append (wxID_EXIT, _("&Quit"));
570 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
572 wxMenu* edit = new wxMenu;
573 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
576 prefs->Enable (Config::instance()->have_write_permission());
578 _cpl_menu = new wxMenu;
580 wxMenu* view = new wxMenu;
581 optional<int> c = Config::instance()->decode_reduction();
582 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
583 view->AppendSeparator();
584 #ifndef DCPOMATIC_VARIANT_SWAROOP
585 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
586 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
589 view->AppendSeparator();
590 view->Append(ID_view_closed_captions, _("Closed captions..."));
591 view->AppendSeparator();
592 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
593 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
594 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
595 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
597 wxMenu* tools = new wxMenu;
598 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
599 tools->AppendSeparator ();
600 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
601 tools->Append (ID_tools_timing, _("Timing..."));
602 tools->Append (ID_tools_system_information, _("System information..."));
604 wxMenu* help = new wxMenu;
606 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
608 help->Append (wxID_ABOUT, _("About"));
610 help->Append (ID_help_report_a_problem, _("Report a problem..."));
612 m->Append (_file_menu, _("&File"));
614 m->Append (edit, _("&Edit"));
616 m->Append (view, _("&View"));
617 m->Append (tools, _("&Tools"));
618 m->Append (help, _("&Help"));
623 wxString d = wxStandardPaths::Get().GetDocumentsDir();
624 if (Config::instance()->last_player_load_directory()) {
625 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
628 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
633 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
634 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
641 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
643 Config::instance()->set_last_player_load_directory (dcp.parent_path());
651 wxDirDialog* c = new wxDirDialog (
653 _("Select DCP to open as OV"),
654 wxStandardPaths::Get().GetDocumentsDir(),
655 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
661 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
662 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
669 DCPOMATIC_ASSERT (_film);
670 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
671 DCPOMATIC_ASSERT (dcp);
672 dcp->add_ov (wx_to_std(c->GetPath()));
673 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
674 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
675 if (!ok || !report_errors_from_last_job(this)) {
678 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
682 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
684 _film->set_container(r);
690 _info->triggered_update ();
695 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
697 if (d->ShowModal() == wxID_OK) {
698 DCPOMATIC_ASSERT (_film);
699 #ifdef DCPOMATIC_VARIANT_SWAROOP
700 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
703 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
704 } catch (exception& e) {
705 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
711 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
712 #ifndef DCPOMATIC_VARIANT_SWAROOP
713 DCPOMATIC_ASSERT (dcp);
717 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
718 dcp->examine (_film, shared_ptr<Job>());
720 } catch (exception& e) {
721 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
728 _info->triggered_update ();
731 void file_history (wxCommandEvent& event)
733 vector<boost::filesystem::path> history = Config::instance()->player_history ();
734 int n = event.GetId() - ID_file_history;
735 if (n >= 0 && n < static_cast<int> (history.size ())) {
737 load_dcp (history[n]);
738 } catch (exception& e) {
739 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
747 _info->triggered_update ();
748 set_menu_sensitivity ();
756 void edit_preferences ()
758 if (!Config::instance()->have_write_permission()) {
762 if (!_config_dialog) {
763 _config_dialog = create_player_config_dialog ();
765 _config_dialog->Show (this);
768 void view_cpl (wxCommandEvent& ev)
770 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
771 DCPOMATIC_ASSERT (dcp);
772 DCPExaminer ex (dcp, true);
773 int id = ev.GetId() - ID_view_cpl;
774 DCPOMATIC_ASSERT (id >= 0);
775 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
776 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
777 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
783 dcp->set_cpl ((*i)->id());
784 dcp->examine (_film, shared_ptr<Job>());
787 void view_full_screen ()
789 if (_mode == Config::PLAYER_MODE_FULL) {
790 _mode = Config::PLAYER_MODE_WINDOW;
792 _mode = Config::PLAYER_MODE_FULL;
798 void view_dual_screen ()
800 if (_mode == Config::PLAYER_MODE_DUAL) {
801 _mode = Config::PLAYER_MODE_WINDOW;
803 _mode = Config::PLAYER_MODE_DUAL;
811 if (_view_full_screen) {
812 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
814 if (_view_dual_screen) {
815 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
821 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
822 _info->Show (_mode != Config::PLAYER_MODE_FULL);
823 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
824 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
825 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
827 if (_mode == Config::PLAYER_MODE_DUAL) {
828 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
829 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
830 _dual_screen->ShowFullScreen (true);
831 _viewer->panel()->Reparent (_dual_screen);
832 _dual_screen->Show ();
833 if (wxDisplay::GetCount() > 1) {
834 switch (Config::instance()->image_display()) {
836 _dual_screen->Move (0, 0);
837 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
840 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
841 // (0, 0) doesn't seem to work for some strange reason
848 _viewer->panel()->Reparent (_overall_panel);
849 _dual_screen->Destroy ();
854 setup_main_sizer (_mode);
857 void view_closed_captions ()
859 _viewer->show_closed_captions ();
864 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
865 DCPOMATIC_ASSERT (dcp);
867 JobManager* jm = JobManager::instance ();
868 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
869 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
874 DCPOMATIC_ASSERT (!jm->get().empty());
875 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
876 DCPOMATIC_ASSERT (last);
878 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
883 void tools_check_for_updates ()
885 UpdateChecker::instance()->run ();
886 _update_news_requested = true;
891 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
896 void tools_system_information ()
898 if (!_system_information_dialog) {
899 _system_information_dialog = new SystemInformationDialog (this, _viewer);
902 _system_information_dialog->Show ();
907 AboutDialog* d = new AboutDialog (this);
912 void help_report_a_problem ()
914 ReportProblemDialog* d = new ReportProblemDialog (this);
915 if (d->ShowModal () == wxID_OK) {
921 void update_checker_state_changed ()
923 UpdateChecker* uc = UpdateChecker::instance ();
925 bool const announce =
926 _update_news_requested ||
927 (uc->stable() && Config::instance()->check_for_updates()) ||
928 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
930 _update_news_requested = false;
936 if (uc->state() == UpdateChecker::YES) {
937 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
938 dialog->ShowModal ();
940 } else if (uc->state() == UpdateChecker::FAILED) {
941 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
943 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
946 _update_news_requested = false;
949 void config_changed (Config::Property prop)
951 /* Instantly save any config changes when using the player GUI */
953 Config::instance()->write_config();
954 } catch (FileError& e) {
955 if (prop != Config::HISTORY) {
959 _("Could not write to config file at %s. Your changes have not been saved."),
960 std_to_wx(e.file().string())
964 } catch (exception& e) {
967 _("Could not write to config file. Your changes have not been saved.")
971 update_from_config (prop);
974 void update_from_config (Config::Property prop)
976 for (int i = 0; i < _history_items; ++i) {
977 delete _file_menu->Remove (ID_file_history + i);
980 if (_history_separator) {
981 _file_menu->Remove (_history_separator);
983 delete _history_separator;
984 _history_separator = 0;
986 int pos = _history_position;
988 /* Clear out non-existant history items before we re-build the menu */
989 Config::instance()->clean_player_history ();
990 vector<boost::filesystem::path> history = Config::instance()->player_history ();
992 if (!history.empty ()) {
993 _history_separator = _file_menu->InsertSeparator (pos++);
996 for (size_t i = 0; i < history.size(); ++i) {
999 s = String::compose ("&%1 %2", i + 1, history[i].string());
1001 s = history[i].string();
1003 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1006 _history_items = history.size ();
1008 if (prop == Config::PLAYER_DEBUG_LOG) {
1009 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1011 dcpomatic_log.reset (new FileLog(*p));
1013 dcpomatic_log.reset (new NullLog());
1015 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
1019 void set_menu_sensitivity ()
1021 _tools_verify->Enable (static_cast<bool>(_film));
1022 _file_add_ov->Enable (static_cast<bool>(_film));
1023 _file_add_kdm->Enable (static_cast<bool>(_film));
1024 _view_cpl->Enable (static_cast<bool>(_film));
1027 void start_stop_pressed ()
1029 if (_viewer->playing()) {
1036 void go_back_frame ()
1038 _viewer->seek_by (-_viewer->one_video_frame(), true);
1041 void go_forward_frame ()
1043 _viewer->seek_by (_viewer->one_video_frame(), true);
1046 void go_seconds (int s)
1048 _viewer->seek_by (DCPTime::from_seconds(s), true);
1053 _viewer->seek (DCPTime(), true);
1058 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
1061 wxFrame* _dual_screen;
1062 bool _update_news_requested;
1063 PlayerInformation* _info;
1064 Config::PlayerMode _mode;
1065 wxPreferencesEditor* _config_dialog;
1066 wxPanel* _overall_panel;
1068 wxMenuItem* _view_cpl;
1071 int _history_position;
1072 wxMenuItem* _history_separator;
1073 shared_ptr<FilmViewer> _viewer;
1074 Controls* _controls;
1075 SystemInformationDialog* _system_information_dialog;
1076 boost::shared_ptr<Film> _film;
1077 boost::signals2::scoped_connection _config_changed_connection;
1078 boost::signals2::scoped_connection _examine_job_connection;
1079 wxMenuItem* _file_add_ov;
1080 wxMenuItem* _file_add_kdm;
1081 wxMenuItem* _tools_verify;
1082 wxMenuItem* _view_full_screen;
1083 wxMenuItem* _view_dual_screen;
1084 PlayerStressTester _stress;
1087 static const wxCmdLineEntryDesc command_line_description[] = {
1088 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1089 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1090 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1091 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1094 class PlayServer : public Server
1097 explicit PlayServer (DOMFrame* frame)
1098 : Server (PLAYER_PLAY_PORT)
1102 void handle (shared_ptr<Socket> socket)
1105 int const length = socket->read_uint32 ();
1106 scoped_array<char> buffer (new char[length]);
1107 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1108 string s (buffer.get());
1109 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1110 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1121 * @brief The magic App class for wxWidgets.
1123 class App : public wxApp
1130 #ifdef DCPOMATIC_LINUX
1139 wxSplashScreen* splash = 0;
1141 wxInitAllImageHandlers ();
1143 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1144 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1146 splash = maybe_show_splash ();
1148 SetAppName (_("DCP-o-matic Player"));
1150 if (!wxApp::OnInit()) {
1154 #ifdef DCPOMATIC_LINUX
1155 unsetenv ("UBUNTU_MENUPROXY");
1158 #ifdef DCPOMATIC_OSX
1159 make_foreground_application ();
1162 dcpomatic_setup_path_encoding ();
1164 /* Enable i18n; this will create a Config object
1165 to look for a force-configured language. This Config
1166 object will be wrong, however, because dcpomatic_setup
1167 hasn't yet been called and there aren't any filters etc.
1170 dcpomatic_setup_i18n ();
1172 /* Set things up, including filters etc.
1173 which will now be internationalised correctly.
1177 /* Force the configuration to be re-loaded correctly next
1182 signal_manager = new wxSignalManager (this);
1184 _frame = new DOMFrame ();
1185 SetTopWindow (_frame);
1186 _frame->Maximize ();
1193 PlayServer* server = new PlayServer (_frame);
1194 new thread (boost::bind (&PlayServer::run, server));
1196 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1198 _frame->load_dcp (_dcp_to_load);
1199 } catch (exception& e) {
1200 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1206 _frame->load_stress_script (*_stress);
1207 } catch (exception& e) {
1208 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1212 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1214 if (Config::instance()->check_for_updates ()) {
1215 UpdateChecker::instance()->run ();
1218 catch (exception& e)
1223 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1229 void OnInitCmdLine (wxCmdLineParser& parser)
1231 parser.SetDesc (command_line_description);
1232 parser.SetSwitchChars (wxT ("-"));
1235 bool OnCmdLineParsed (wxCmdLineParser& parser)
1237 if (parser.GetParamCount() > 0) {
1238 _dcp_to_load = wx_to_std (parser.GetParam (0));
1242 if (parser.Found("c", &config)) {
1243 Config::override_path = wx_to_std (config);
1246 if (parser.Found("s", &stress)) {
1247 _stress = wx_to_std (stress);
1253 void report_exception ()
1257 } catch (FileError& e) {
1261 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1262 std_to_wx (e.what()),
1263 std_to_wx (e.file().string().c_str ())
1266 } catch (exception& e) {
1270 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1271 std_to_wx (e.what ())
1275 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1279 /* An unhandled exception has occurred inside the main event loop */
1280 bool OnExceptionInMainLoop ()
1282 report_exception ();
1283 /* This will terminate the program */
1287 void OnUnhandledException ()
1289 report_exception ();
1294 signal_manager->ui_idle ();
1297 void config_failed_to_load ()
1299 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1302 void config_warning (string m)
1304 message_dialog (_frame, std_to_wx (m));
1308 string _dcp_to_load;
1309 boost::optional<string> _stress;