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 #if BOOST_VERSION >= 106100
99 using namespace boost::placeholders;
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)
156 , _main_sizer (new wxBoxSizer (wxVERTICAL))
158 dcpomatic_log.reset (new NullLog());
160 #if defined(DCPOMATIC_WINDOWS)
161 maybe_open_console ();
162 cout << "DCP-o-matic Player is starting." << "\n";
165 wxMenuBar* bar = new wxMenuBar;
167 set_menu_sensitivity ();
170 #ifdef DCPOMATIC_WINDOWS
171 SetIcon (wxIcon (std_to_wx ("id")));
174 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
175 update_from_config (Config::PLAYER_DEBUG_LOG);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
182 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
183 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
184 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
185 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
188 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
189 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
190 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
192 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
193 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
194 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
195 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
196 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
198 /* Use a panel as the only child of the Frame so that we avoid
199 the dark-grey background on Windows.
201 _overall_panel = new wxPanel (this, wxID_ANY);
203 _viewer.reset (new FilmViewer (_overall_panel));
204 #ifdef DCPOMATIC_VARIANT_SWAROOP
205 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
207 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
209 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
210 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
212 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
214 _controls = new StandardControls (_overall_panel, _viewer, false);
217 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
218 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
219 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
220 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
221 _info = new PlayerInformation (_overall_panel, _viewer);
222 setup_main_sizer (Config::instance()->player_mode());
224 int accelerators = 12;
226 int accelerators = 11;
229 _stress.setup (this, _controls);
231 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
232 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
233 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_go_back_frame);
234 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_go_forward_frame);
235 accel[3].Set(wxACCEL_SHIFT, WXK_LEFT, ID_go_back_small_amount);
236 accel[4].Set(wxACCEL_SHIFT, WXK_RIGHT, ID_go_forward_small_amount);
237 accel[5].Set(wxACCEL_CTRL, WXK_LEFT, ID_go_back_medium_amount);
238 accel[6].Set(wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_medium_amount);
239 accel[7].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_LEFT, ID_go_back_large_amount);
240 accel[8].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_large_amount);
241 accel[9].Set(wxACCEL_NORMAL, WXK_HOME, ID_go_to_start);
242 accel[10].Set(wxACCEL_NORMAL, WXK_END, ID_go_to_end);
244 accel[11].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
246 wxAcceleratorTable accel_table (accelerators, accel);
247 SetAcceleratorTable (accel_table);
250 Bind (wxEVT_MENU, boost::bind(&DOMFrame::start_stop_pressed, this), ID_start_stop);
251 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_back_frame, this), ID_go_back_frame);
252 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_forward_frame, this), ID_go_forward_frame);
253 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -60), ID_go_back_small_amount);
254 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 60), ID_go_forward_small_amount);
255 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -600), ID_go_back_medium_amount);
256 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 600), ID_go_forward_medium_amount);
257 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -3600), ID_go_back_large_amount);
258 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 3600), ID_go_forward_large_amount);
259 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_start, this), ID_go_to_start);
260 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_end, this), ID_go_to_end);
264 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
265 #ifdef DCPOMATIC_VARIANT_SWAROOP
266 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
267 MonitorChecker::instance()->run ();
268 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
269 LockFileChecker::instance()->run ();
273 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
275 #ifdef DCPOMATIC_VARIANT_SWAROOP
276 sc->check_restart ();
280 #ifdef DCPOMATIC_VARIANT_SWAROOP
281 void monitor_checker_state_changed ()
283 if (!MonitorChecker::instance()->ok()) {
285 error_dialog (this, _("The required display devices are not connected correctly."));
289 void lock_checker_state_changed ()
291 if (!LockFileChecker::instance()->ok()) {
293 error_dialog (this, _("The lock file is not present."));
298 void setup_main_sizer (Config::PlayerMode mode)
300 _main_sizer->Detach (_viewer->panel());
301 _main_sizer->Detach (_controls);
302 _main_sizer->Detach (_info);
303 if (mode != Config::PLAYER_MODE_DUAL) {
304 _main_sizer->Add (_viewer->panel(), 1, wxEXPAND);
306 _main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
307 _main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
308 _overall_panel->SetSizer (_main_sizer);
309 _overall_panel->Layout ();
312 bool playback_permitted ()
314 #ifdef DCPOMATIC_VARIANT_SWAROOP
315 if (!MonitorChecker::instance()->ok()) {
316 error_dialog (this, _("The required display devices are not connected correctly."));
319 if (!LockFileChecker::instance()->ok()) {
320 error_dialog (this, _("The lock file is not present."));
324 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
329 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
330 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
331 if (d && !d->kdm_timing_window_valid()) {
336 #ifdef DCPOMATIC_VARIANT_SWAROOP
337 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
338 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
339 if (c && !c->kdm_timing_window_valid()) {
346 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
352 void playback_started (DCPTime time)
354 /* XXX: this only logs the first piece of content; probably should be each piece? */
355 if (_film->content().empty()) {
359 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
361 DCPExaminer ex (dcp, true);
362 shared_ptr<dcp::CPL> playing_cpl;
363 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
364 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
368 DCPOMATIC_ASSERT (playing_cpl);
372 "playback-started %s %s %s",
373 time.timecode(_film->video_frame_rate()).c_str(),
374 dcp->directories().front().string().c_str(),
375 playing_cpl->annotation_text().c_str()
380 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
384 "playback-started %s %s",
385 time.timecode(_film->video_frame_rate()).c_str(),
386 ffmpeg->path(0).string().c_str()
392 void playback_stopped (DCPTime time)
394 #ifdef DCPOMATIC_VARIANT_SWAROOP
396 boost::filesystem::remove (Config::path("position"));
402 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
405 void set_decode_reduction (optional<int> reduction)
407 _viewer->set_dcp_decode_reduction (reduction);
408 _info->triggered_update ();
409 Config::instance()->set_decode_reduction (reduction);
412 void load_dcp (boost::filesystem::path dir)
414 DCPOMATIC_ASSERT (_film);
418 _stress.set_suspended (true);
419 shared_ptr<DCPContent> dcp (new DCPContent(dir));
420 shared_ptr<Job> job (new ExamineContentJob(_film, dcp));
421 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
422 JobManager::instance()->add (job);
423 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
424 if (!ok || !report_errors_from_last_job(this)) {
427 #ifndef DCPOMATIC_VARIANT_SWAROOP
428 Config::instance()->add_to_player_history (dir);
430 } catch (dcp::ReadError& e) {
431 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
432 } catch (DCPError& e) {
433 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
437 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
439 shared_ptr<Job> job = weak_job.lock ();
440 if (!job || !job->finished_ok()) {
444 shared_ptr<Content> content = weak_content.lock ();
449 _film->add_content (content);
450 _stress.set_suspended (false);
453 void reset_film_weak (weak_ptr<Film> weak_film)
455 shared_ptr<Film> film = weak_film.lock ();
461 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
464 _film->set_tolerant (true);
465 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
466 _viewer->set_film (_film);
467 _controls->set_film (_film);
468 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
469 _info->triggered_update ();
472 void film_changed (ChangeType type, Film::Property property)
474 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
478 if (_viewer->playing ()) {
482 /* Start off as Flat */
483 _film->set_container (Ratio::from_id("185"));
485 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
486 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
488 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
493 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
494 if (r->id() == "239") {
495 /* Any scope content means we use scope */
496 _film->set_container(r);
500 /* Any 3D content means we use 3D mode */
501 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
502 _film->set_three_d (true);
506 _viewer->seek (DCPTime(), true);
507 _info->triggered_update ();
509 set_menu_sensitivity ();
511 wxMenuItemList old = _cpl_menu->GetMenuItems();
512 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
513 _cpl_menu->Remove (*i);
516 if (_film->content().size() == 1) {
517 /* Offer a CPL menu */
518 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
520 DCPExaminer ex (first, true);
521 int id = ID_view_cpl;
522 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
523 wxMenuItem* j = _cpl_menu->AppendRadioItem(
525 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
527 j->Check(!first->cpl() || i->id() == *first->cpl());
534 void load_stress_script (boost::filesystem::path path)
536 _stress.load_script (path);
541 bool report_errors_from_last_job (wxWindow* parent) const
543 JobManager* jm = JobManager::instance ();
545 DCPOMATIC_ASSERT (!jm->get().empty());
547 shared_ptr<Job> last = jm->get().back();
548 if (last->finished_in_error()) {
549 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()));
556 void setup_menu (wxMenuBar* m)
558 _file_menu = new wxMenu;
559 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
560 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
561 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
563 _history_position = _file_menu->GetMenuItems().GetCount();
565 _file_menu->AppendSeparator ();
566 _file_menu->Append (ID_file_close, _("&Close"));
567 _file_menu->AppendSeparator ();
570 _file_menu->Append (wxID_EXIT, _("&Exit"));
572 _file_menu->Append (wxID_EXIT, _("&Quit"));
576 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
578 wxMenu* edit = new wxMenu;
579 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
582 prefs->Enable (Config::instance()->have_write_permission());
584 _cpl_menu = new wxMenu;
586 wxMenu* view = new wxMenu;
587 optional<int> c = Config::instance()->decode_reduction();
588 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
589 view->AppendSeparator();
590 #ifndef DCPOMATIC_VARIANT_SWAROOP
591 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
592 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
595 view->AppendSeparator();
596 view->Append(ID_view_closed_captions, _("Closed captions..."));
597 view->AppendSeparator();
598 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
599 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
600 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
601 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
603 wxMenu* tools = new wxMenu;
604 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
605 tools->AppendSeparator ();
606 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
607 tools->Append (ID_tools_timing, _("Timing..."));
608 tools->Append (ID_tools_system_information, _("System information..."));
610 wxMenu* help = new wxMenu;
612 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
614 help->Append (wxID_ABOUT, _("About"));
616 help->Append (ID_help_report_a_problem, _("Report a problem..."));
618 m->Append (_file_menu, _("&File"));
620 m->Append (edit, _("&Edit"));
622 m->Append (view, _("&View"));
623 m->Append (tools, _("&Tools"));
624 m->Append (help, _("&Help"));
629 wxString d = wxStandardPaths::Get().GetDocumentsDir();
630 if (Config::instance()->last_player_load_directory()) {
631 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
634 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
639 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
640 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
647 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
649 Config::instance()->set_last_player_load_directory (dcp.parent_path());
657 wxDirDialog* c = new wxDirDialog (
659 _("Select DCP to open as OV"),
660 wxStandardPaths::Get().GetDocumentsDir(),
661 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
667 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
668 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
675 DCPOMATIC_ASSERT (_film);
676 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
677 DCPOMATIC_ASSERT (dcp);
678 dcp->add_ov (wx_to_std(c->GetPath()));
679 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
680 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
681 if (!ok || !report_errors_from_last_job(this)) {
684 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
688 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
690 _film->set_container(r);
696 _info->triggered_update ();
701 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
703 if (d->ShowModal() == wxID_OK) {
704 DCPOMATIC_ASSERT (_film);
705 #ifdef DCPOMATIC_VARIANT_SWAROOP
706 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
709 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
710 } catch (exception& e) {
711 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
717 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
718 #ifndef DCPOMATIC_VARIANT_SWAROOP
719 DCPOMATIC_ASSERT (dcp);
723 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
724 dcp->examine (_film, shared_ptr<Job>());
726 } catch (exception& e) {
727 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
734 _info->triggered_update ();
737 void file_history (wxCommandEvent& event)
739 vector<boost::filesystem::path> history = Config::instance()->player_history ();
740 int n = event.GetId() - ID_file_history;
741 if (n >= 0 && n < static_cast<int> (history.size ())) {
743 load_dcp (history[n]);
744 } catch (exception& e) {
745 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
753 _info->triggered_update ();
754 set_menu_sensitivity ();
762 void edit_preferences ()
764 if (!Config::instance()->have_write_permission()) {
768 if (!_config_dialog) {
769 _config_dialog = create_player_config_dialog ();
771 _config_dialog->Show (this);
774 void view_cpl (wxCommandEvent& ev)
776 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
777 DCPOMATIC_ASSERT (dcp);
778 DCPExaminer ex (dcp, true);
779 int id = ev.GetId() - ID_view_cpl;
780 DCPOMATIC_ASSERT (id >= 0);
781 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
782 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
783 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
789 dcp->set_cpl ((*i)->id());
790 dcp->examine (_film, shared_ptr<Job>());
791 _info->triggered_update ();
794 void view_full_screen ()
796 if (_mode == Config::PLAYER_MODE_FULL) {
797 _mode = Config::PLAYER_MODE_WINDOW;
799 _mode = Config::PLAYER_MODE_FULL;
805 void view_dual_screen ()
807 if (_mode == Config::PLAYER_MODE_DUAL) {
808 _mode = Config::PLAYER_MODE_WINDOW;
810 _mode = Config::PLAYER_MODE_DUAL;
818 if (_view_full_screen) {
819 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
821 if (_view_dual_screen) {
822 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
828 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
829 _info->Show (_mode != Config::PLAYER_MODE_FULL);
830 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
831 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
832 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
834 if (_mode == Config::PLAYER_MODE_DUAL) {
835 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
836 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
837 _dual_screen->ShowFullScreen (true);
838 _viewer->panel()->Reparent (_dual_screen);
839 _dual_screen->Show ();
840 if (wxDisplay::GetCount() > 1) {
841 switch (Config::instance()->image_display()) {
843 _dual_screen->Move (0, 0);
844 Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
847 _dual_screen->Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
848 // (0, 0) doesn't seem to work for some strange reason
855 _viewer->panel()->Reparent (_overall_panel);
856 _dual_screen->Destroy ();
861 setup_main_sizer (_mode);
864 void view_closed_captions ()
866 _viewer->show_closed_captions ();
871 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
872 DCPOMATIC_ASSERT (dcp);
874 JobManager* jm = JobManager::instance ();
875 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
876 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
881 DCPOMATIC_ASSERT (!jm->get().empty());
882 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
883 DCPOMATIC_ASSERT (last);
885 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
890 void tools_check_for_updates ()
892 UpdateChecker::instance()->run ();
893 _update_news_requested = true;
898 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
903 void tools_system_information ()
905 if (!_system_information_dialog) {
906 _system_information_dialog = new SystemInformationDialog (this, _viewer);
909 _system_information_dialog->Show ();
914 AboutDialog* d = new AboutDialog (this);
919 void help_report_a_problem ()
921 ReportProblemDialog* d = new ReportProblemDialog (this);
922 if (d->ShowModal () == wxID_OK) {
928 void update_checker_state_changed ()
930 UpdateChecker* uc = UpdateChecker::instance ();
932 bool const announce =
933 _update_news_requested ||
934 (uc->stable() && Config::instance()->check_for_updates()) ||
935 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
937 _update_news_requested = false;
943 if (uc->state() == UpdateChecker::YES) {
944 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
945 dialog->ShowModal ();
947 } else if (uc->state() == UpdateChecker::FAILED) {
948 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
950 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
953 _update_news_requested = false;
956 void config_changed (Config::Property prop)
958 /* Instantly save any config changes when using the player GUI */
960 Config::instance()->write_config();
961 } catch (FileError& e) {
962 if (prop != Config::HISTORY) {
966 _("Could not write to config file at %s. Your changes have not been saved."),
967 std_to_wx(e.file().string())
971 } catch (exception& e) {
974 _("Could not write to config file. Your changes have not been saved.")
978 update_from_config (prop);
981 void update_from_config (Config::Property prop)
983 for (int i = 0; i < _history_items; ++i) {
984 delete _file_menu->Remove (ID_file_history + i);
987 if (_history_separator) {
988 _file_menu->Remove (_history_separator);
990 delete _history_separator;
991 _history_separator = 0;
993 int pos = _history_position;
995 /* Clear out non-existant history items before we re-build the menu */
996 Config::instance()->clean_player_history ();
997 vector<boost::filesystem::path> history = Config::instance()->player_history ();
999 if (!history.empty ()) {
1000 _history_separator = _file_menu->InsertSeparator (pos++);
1003 for (size_t i = 0; i < history.size(); ++i) {
1006 s = String::compose ("&%1 %2", i + 1, history[i].string());
1008 s = history[i].string();
1010 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1013 _history_items = history.size ();
1015 if (prop == Config::PLAYER_DEBUG_LOG) {
1016 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1018 dcpomatic_log.reset (new FileLog(*p));
1020 dcpomatic_log.reset (new NullLog());
1022 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
1026 void set_menu_sensitivity ()
1028 _tools_verify->Enable (static_cast<bool>(_film));
1029 _file_add_ov->Enable (static_cast<bool>(_film));
1030 _file_add_kdm->Enable (static_cast<bool>(_film));
1031 _view_cpl->Enable (static_cast<bool>(_film));
1034 void start_stop_pressed ()
1036 if (_viewer->playing()) {
1043 void go_back_frame ()
1045 _viewer->seek_by (-_viewer->one_video_frame(), true);
1048 void go_forward_frame ()
1050 _viewer->seek_by (_viewer->one_video_frame(), true);
1053 void go_seconds (int s)
1055 _viewer->seek_by (DCPTime::from_seconds(s), true);
1060 _viewer->seek (DCPTime(), true);
1065 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
1068 wxFrame* _dual_screen;
1069 bool _update_news_requested;
1070 PlayerInformation* _info;
1071 Config::PlayerMode _mode;
1072 wxPreferencesEditor* _config_dialog;
1073 wxPanel* _overall_panel;
1075 wxMenuItem* _view_cpl;
1078 int _history_position;
1079 wxMenuItem* _history_separator;
1080 shared_ptr<FilmViewer> _viewer;
1081 Controls* _controls;
1082 SystemInformationDialog* _system_information_dialog;
1083 boost::shared_ptr<Film> _film;
1084 boost::signals2::scoped_connection _config_changed_connection;
1085 boost::signals2::scoped_connection _examine_job_connection;
1086 wxMenuItem* _file_add_ov;
1087 wxMenuItem* _file_add_kdm;
1088 wxMenuItem* _tools_verify;
1089 wxMenuItem* _view_full_screen;
1090 wxMenuItem* _view_dual_screen;
1091 wxSizer* _main_sizer;
1092 PlayerStressTester _stress;
1095 static const wxCmdLineEntryDesc command_line_description[] = {
1096 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1097 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1098 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1099 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1102 class PlayServer : public Server
1105 explicit PlayServer (DOMFrame* frame)
1106 : Server (PLAYER_PLAY_PORT)
1110 void handle (shared_ptr<Socket> socket)
1113 int const length = socket->read_uint32 ();
1114 scoped_array<char> buffer (new char[length]);
1115 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1116 string s (buffer.get());
1117 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1118 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1129 * @brief The magic App class for wxWidgets.
1131 class App : public wxApp
1138 #ifdef DCPOMATIC_LINUX
1147 wxSplashScreen* splash = 0;
1149 wxInitAllImageHandlers ();
1151 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1152 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1154 splash = maybe_show_splash ();
1156 SetAppName (_("DCP-o-matic Player"));
1158 if (!wxApp::OnInit()) {
1162 #ifdef DCPOMATIC_LINUX
1163 unsetenv ("UBUNTU_MENUPROXY");
1166 #ifdef DCPOMATIC_OSX
1167 make_foreground_application ();
1170 dcpomatic_setup_path_encoding ();
1172 /* Enable i18n; this will create a Config object
1173 to look for a force-configured language. This Config
1174 object will be wrong, however, because dcpomatic_setup
1175 hasn't yet been called and there aren't any filters etc.
1178 dcpomatic_setup_i18n ();
1180 /* Set things up, including filters etc.
1181 which will now be internationalised correctly.
1185 /* Force the configuration to be re-loaded correctly next
1190 signal_manager = new wxSignalManager (this);
1192 _frame = new DOMFrame ();
1193 SetTopWindow (_frame);
1194 _frame->Maximize ();
1201 PlayServer* server = new PlayServer (_frame);
1202 new thread (boost::bind (&PlayServer::run, server));
1204 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1206 _frame->load_dcp (_dcp_to_load);
1207 } catch (exception& e) {
1208 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1214 _frame->load_stress_script (*_stress);
1215 } catch (exception& e) {
1216 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1220 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1222 if (Config::instance()->check_for_updates ()) {
1223 UpdateChecker::instance()->run ();
1226 catch (exception& e)
1231 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1237 void OnInitCmdLine (wxCmdLineParser& parser)
1239 parser.SetDesc (command_line_description);
1240 parser.SetSwitchChars (wxT ("-"));
1243 bool OnCmdLineParsed (wxCmdLineParser& parser)
1245 if (parser.GetParamCount() > 0) {
1246 _dcp_to_load = wx_to_std (parser.GetParam (0));
1250 if (parser.Found("c", &config)) {
1251 Config::override_path = wx_to_std (config);
1254 if (parser.Found("s", &stress)) {
1255 _stress = wx_to_std (stress);
1261 void report_exception ()
1265 } catch (FileError& e) {
1269 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1270 std_to_wx (e.what()),
1271 std_to_wx (e.file().string().c_str ())
1274 } catch (exception& e) {
1278 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1279 std_to_wx (e.what ())
1283 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1287 /* An unhandled exception has occurred inside the main event loop */
1288 bool OnExceptionInMainLoop ()
1290 report_exception ();
1291 /* This will terminate the program */
1295 void OnUnhandledException ()
1297 report_exception ();
1302 signal_manager->ui_idle ();
1305 void config_failed_to_load ()
1307 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1310 void config_warning (string m)
1312 message_dialog (_frame, std_to_wx (m));
1316 string _dcp_to_load;
1317 boost::optional<string> _stress;