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()));
429 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
431 shared_ptr<Job> job = weak_job.lock ();
432 if (!job || !job->finished_ok()) {
436 shared_ptr<Content> content = weak_content.lock ();
441 _film->add_content (content);
442 _stress.set_suspended (false);
445 void reset_film_weak (weak_ptr<Film> weak_film)
447 shared_ptr<Film> film = weak_film.lock ();
453 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
456 _film->set_tolerant (true);
457 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
458 _viewer->set_film (_film);
459 _controls->set_film (_film);
460 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
461 _info->triggered_update ();
464 void film_changed (ChangeType type, Film::Property property)
466 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
470 if (_viewer->playing ()) {
474 /* Start off as Flat */
475 _film->set_container (Ratio::from_id("185"));
477 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
478 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
480 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
485 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
486 if (r->id() == "239") {
487 /* Any scope content means we use scope */
488 _film->set_container(r);
492 /* Any 3D content means we use 3D mode */
493 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
494 _film->set_three_d (true);
498 _viewer->seek (DCPTime(), true);
499 _info->triggered_update ();
501 set_menu_sensitivity ();
503 wxMenuItemList old = _cpl_menu->GetMenuItems();
504 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
505 _cpl_menu->Remove (*i);
508 if (_film->content().size() == 1) {
509 /* Offer a CPL menu */
510 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
512 DCPExaminer ex (first, true);
513 int id = ID_view_cpl;
514 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
515 wxMenuItem* j = _cpl_menu->AppendRadioItem(
517 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
519 j->Check(!first->cpl() || i->id() == *first->cpl());
526 void load_stress_script (boost::filesystem::path path)
528 _stress.load_script (path);
533 bool report_errors_from_last_job (wxWindow* parent) const
535 JobManager* jm = JobManager::instance ();
537 DCPOMATIC_ASSERT (!jm->get().empty());
539 shared_ptr<Job> last = jm->get().back();
540 if (last->finished_in_error()) {
541 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()));
548 void setup_menu (wxMenuBar* m)
550 _file_menu = new wxMenu;
551 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
552 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
553 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
555 _history_position = _file_menu->GetMenuItems().GetCount();
557 _file_menu->AppendSeparator ();
558 _file_menu->Append (ID_file_close, _("&Close"));
559 _file_menu->AppendSeparator ();
562 _file_menu->Append (wxID_EXIT, _("&Exit"));
564 _file_menu->Append (wxID_EXIT, _("&Quit"));
568 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
570 wxMenu* edit = new wxMenu;
571 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
574 prefs->Enable (Config::instance()->have_write_permission());
576 _cpl_menu = new wxMenu;
578 wxMenu* view = new wxMenu;
579 optional<int> c = Config::instance()->decode_reduction();
580 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
581 view->AppendSeparator();
582 #ifndef DCPOMATIC_VARIANT_SWAROOP
583 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
584 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
587 view->AppendSeparator();
588 view->Append(ID_view_closed_captions, _("Closed captions..."));
589 view->AppendSeparator();
590 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
591 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
592 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
593 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
595 wxMenu* tools = new wxMenu;
596 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
597 tools->AppendSeparator ();
598 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
599 tools->Append (ID_tools_timing, _("Timing..."));
600 tools->Append (ID_tools_system_information, _("System information..."));
602 wxMenu* help = new wxMenu;
604 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
606 help->Append (wxID_ABOUT, _("About"));
608 help->Append (ID_help_report_a_problem, _("Report a problem..."));
610 m->Append (_file_menu, _("&File"));
612 m->Append (edit, _("&Edit"));
614 m->Append (view, _("&View"));
615 m->Append (tools, _("&Tools"));
616 m->Append (help, _("&Help"));
621 wxString d = wxStandardPaths::Get().GetDocumentsDir();
622 if (Config::instance()->last_player_load_directory()) {
623 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
626 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
631 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
632 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
639 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
641 Config::instance()->set_last_player_load_directory (dcp.parent_path());
649 wxDirDialog* c = new wxDirDialog (
651 _("Select DCP to open as OV"),
652 wxStandardPaths::Get().GetDocumentsDir(),
653 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
659 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
660 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
667 DCPOMATIC_ASSERT (_film);
668 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
669 DCPOMATIC_ASSERT (dcp);
670 dcp->add_ov (wx_to_std(c->GetPath()));
671 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
672 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
673 if (!ok || !report_errors_from_last_job(this)) {
676 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
680 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
682 _film->set_container(r);
688 _info->triggered_update ();
693 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
695 if (d->ShowModal() == wxID_OK) {
696 DCPOMATIC_ASSERT (_film);
697 #ifdef DCPOMATIC_VARIANT_SWAROOP
698 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
701 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
702 } catch (exception& e) {
703 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
709 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
710 #ifndef DCPOMATIC_VARIANT_SWAROOP
711 DCPOMATIC_ASSERT (dcp);
715 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
716 dcp->examine (_film, shared_ptr<Job>());
718 } catch (exception& e) {
719 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
726 _info->triggered_update ();
729 void file_history (wxCommandEvent& event)
731 vector<boost::filesystem::path> history = Config::instance()->player_history ();
732 int n = event.GetId() - ID_file_history;
733 if (n >= 0 && n < static_cast<int> (history.size ())) {
735 load_dcp (history[n]);
736 } catch (exception& e) {
737 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
745 _info->triggered_update ();
746 set_menu_sensitivity ();
754 void edit_preferences ()
756 if (!Config::instance()->have_write_permission()) {
760 if (!_config_dialog) {
761 _config_dialog = create_player_config_dialog ();
763 _config_dialog->Show (this);
766 void view_cpl (wxCommandEvent& ev)
768 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
769 DCPOMATIC_ASSERT (dcp);
770 DCPExaminer ex (dcp, true);
771 int id = ev.GetId() - ID_view_cpl;
772 DCPOMATIC_ASSERT (id >= 0);
773 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
774 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
775 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
781 dcp->set_cpl ((*i)->id());
782 dcp->examine (_film, shared_ptr<Job>());
785 void view_full_screen ()
787 if (_mode == Config::PLAYER_MODE_FULL) {
788 _mode = Config::PLAYER_MODE_WINDOW;
790 _mode = Config::PLAYER_MODE_FULL;
796 void view_dual_screen ()
798 if (_mode == Config::PLAYER_MODE_DUAL) {
799 _mode = Config::PLAYER_MODE_WINDOW;
801 _mode = Config::PLAYER_MODE_DUAL;
809 if (_view_full_screen) {
810 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
812 if (_view_dual_screen) {
813 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
819 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
820 _info->Show (_mode != Config::PLAYER_MODE_FULL);
821 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
822 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
823 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
825 if (_mode == Config::PLAYER_MODE_DUAL) {
826 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
827 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
828 _dual_screen->ShowFullScreen (true);
829 _viewer->panel()->Reparent (_dual_screen);
830 _dual_screen->Show ();
831 if (wxDisplay::GetCount() > 1) {
832 switch (Config::instance()->image_display()) {
834 _dual_screen->Move (0, 0);
835 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
838 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
839 // (0, 0) doesn't seem to work for some strange reason
846 _viewer->panel()->Reparent (_overall_panel);
847 _dual_screen->Destroy ();
852 setup_main_sizer (_mode);
855 void view_closed_captions ()
857 _viewer->show_closed_captions ();
862 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
863 DCPOMATIC_ASSERT (dcp);
865 JobManager* jm = JobManager::instance ();
866 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
867 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
872 DCPOMATIC_ASSERT (!jm->get().empty());
873 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
874 DCPOMATIC_ASSERT (last);
876 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
881 void tools_check_for_updates ()
883 UpdateChecker::instance()->run ();
884 _update_news_requested = true;
889 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
894 void tools_system_information ()
896 if (!_system_information_dialog) {
897 _system_information_dialog = new SystemInformationDialog (this, _viewer);
900 _system_information_dialog->Show ();
905 AboutDialog* d = new AboutDialog (this);
910 void help_report_a_problem ()
912 ReportProblemDialog* d = new ReportProblemDialog (this);
913 if (d->ShowModal () == wxID_OK) {
919 void update_checker_state_changed ()
921 UpdateChecker* uc = UpdateChecker::instance ();
923 bool const announce =
924 _update_news_requested ||
925 (uc->stable() && Config::instance()->check_for_updates()) ||
926 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
928 _update_news_requested = false;
934 if (uc->state() == UpdateChecker::YES) {
935 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
936 dialog->ShowModal ();
938 } else if (uc->state() == UpdateChecker::FAILED) {
939 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
941 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
944 _update_news_requested = false;
947 void config_changed (Config::Property prop)
949 /* Instantly save any config changes when using the player GUI */
951 Config::instance()->write_config();
952 } catch (FileError& e) {
953 if (prop != Config::HISTORY) {
957 _("Could not write to config file at %s. Your changes have not been saved."),
958 std_to_wx(e.file().string())
962 } catch (exception& e) {
965 _("Could not write to config file. Your changes have not been saved.")
969 update_from_config (prop);
972 void update_from_config (Config::Property prop)
974 for (int i = 0; i < _history_items; ++i) {
975 delete _file_menu->Remove (ID_file_history + i);
978 if (_history_separator) {
979 _file_menu->Remove (_history_separator);
981 delete _history_separator;
982 _history_separator = 0;
984 int pos = _history_position;
986 /* Clear out non-existant history items before we re-build the menu */
987 Config::instance()->clean_player_history ();
988 vector<boost::filesystem::path> history = Config::instance()->player_history ();
990 if (!history.empty ()) {
991 _history_separator = _file_menu->InsertSeparator (pos++);
994 for (size_t i = 0; i < history.size(); ++i) {
997 s = String::compose ("&%1 %2", i + 1, history[i].string());
999 s = history[i].string();
1001 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1004 _history_items = history.size ();
1006 if (prop == Config::PLAYER_DEBUG_LOG) {
1007 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1009 dcpomatic_log.reset (new FileLog(*p));
1011 dcpomatic_log.reset (new NullLog());
1013 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
1017 void set_menu_sensitivity ()
1019 _tools_verify->Enable (static_cast<bool>(_film));
1020 _file_add_ov->Enable (static_cast<bool>(_film));
1021 _file_add_kdm->Enable (static_cast<bool>(_film));
1022 _view_cpl->Enable (static_cast<bool>(_film));
1025 void start_stop_pressed ()
1027 if (_viewer->playing()) {
1034 void go_back_frame ()
1036 _viewer->seek_by (-_viewer->one_video_frame(), true);
1039 void go_forward_frame ()
1041 _viewer->seek_by (_viewer->one_video_frame(), true);
1044 void go_seconds (int s)
1046 _viewer->seek_by (DCPTime::from_seconds(s), true);
1051 _viewer->seek (DCPTime(), true);
1056 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
1059 wxFrame* _dual_screen;
1060 bool _update_news_requested;
1061 PlayerInformation* _info;
1062 Config::PlayerMode _mode;
1063 wxPreferencesEditor* _config_dialog;
1064 wxPanel* _overall_panel;
1066 wxMenuItem* _view_cpl;
1069 int _history_position;
1070 wxMenuItem* _history_separator;
1071 shared_ptr<FilmViewer> _viewer;
1072 Controls* _controls;
1073 SystemInformationDialog* _system_information_dialog;
1074 boost::shared_ptr<Film> _film;
1075 boost::signals2::scoped_connection _config_changed_connection;
1076 boost::signals2::scoped_connection _examine_job_connection;
1077 wxMenuItem* _file_add_ov;
1078 wxMenuItem* _file_add_kdm;
1079 wxMenuItem* _tools_verify;
1080 wxMenuItem* _view_full_screen;
1081 wxMenuItem* _view_dual_screen;
1082 PlayerStressTester _stress;
1085 static const wxCmdLineEntryDesc command_line_description[] = {
1086 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1087 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1088 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1089 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1092 class PlayServer : public Server
1095 explicit PlayServer (DOMFrame* frame)
1096 : Server (PLAYER_PLAY_PORT)
1100 void handle (shared_ptr<Socket> socket)
1103 int const length = socket->read_uint32 ();
1104 scoped_array<char> buffer (new char[length]);
1105 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1106 string s (buffer.get());
1107 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1108 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1119 * @brief The magic App class for wxWidgets.
1121 class App : public wxApp
1128 #ifdef DCPOMATIC_LINUX
1137 wxSplashScreen* splash = 0;
1139 wxInitAllImageHandlers ();
1141 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1142 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1144 splash = maybe_show_splash ();
1146 SetAppName (_("DCP-o-matic Player"));
1148 if (!wxApp::OnInit()) {
1152 #ifdef DCPOMATIC_LINUX
1153 unsetenv ("UBUNTU_MENUPROXY");
1156 #ifdef DCPOMATIC_OSX
1157 make_foreground_application ();
1160 dcpomatic_setup_path_encoding ();
1162 /* Enable i18n; this will create a Config object
1163 to look for a force-configured language. This Config
1164 object will be wrong, however, because dcpomatic_setup
1165 hasn't yet been called and there aren't any filters etc.
1168 dcpomatic_setup_i18n ();
1170 /* Set things up, including filters etc.
1171 which will now be internationalised correctly.
1175 /* Force the configuration to be re-loaded correctly next
1180 signal_manager = new wxSignalManager (this);
1182 _frame = new DOMFrame ();
1183 SetTopWindow (_frame);
1184 _frame->Maximize ();
1191 PlayServer* server = new PlayServer (_frame);
1192 new thread (boost::bind (&PlayServer::run, server));
1194 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1196 _frame->load_dcp (_dcp_to_load);
1197 } catch (exception& e) {
1198 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1204 _frame->load_stress_script (*_stress);
1205 } catch (exception& e) {
1206 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1210 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1212 if (Config::instance()->check_for_updates ()) {
1213 UpdateChecker::instance()->run ();
1216 catch (exception& e)
1221 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1227 void OnInitCmdLine (wxCmdLineParser& parser)
1229 parser.SetDesc (command_line_description);
1230 parser.SetSwitchChars (wxT ("-"));
1233 bool OnCmdLineParsed (wxCmdLineParser& parser)
1235 if (parser.GetParamCount() > 0) {
1236 _dcp_to_load = wx_to_std (parser.GetParam (0));
1240 if (parser.Found("c", &config)) {
1241 Config::override_path = wx_to_std (config);
1244 if (parser.Found("s", &stress)) {
1245 _stress = wx_to_std (stress);
1251 void report_exception ()
1255 } catch (FileError& e) {
1259 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1260 std_to_wx (e.what()),
1261 std_to_wx (e.file().string().c_str ())
1264 } catch (exception& e) {
1268 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1269 std_to_wx (e.what ())
1273 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1277 /* An unhandled exception has occurred inside the main event loop */
1278 bool OnExceptionInMainLoop ()
1280 report_exception ();
1281 /* This will terminate the program */
1285 void OnUnhandledException ()
1287 report_exception ();
1292 signal_manager->ui_idle ();
1295 void config_failed_to_load ()
1297 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1300 void config_warning (string m)
1302 message_dialog (_frame, std_to_wx (m));
1306 string _dcp_to_load;
1307 boost::optional<string> _stress;