2 Copyright (C) 2017-2019 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/swaroop_controls.h"
32 #include "wx/timer_display.h"
33 #include "wx/system_information_dialog.h"
34 #include "lib/cross.h"
35 #include "lib/config.h"
37 #include "lib/internet.h"
38 #include "lib/update_checker.h"
39 #include "lib/compose.hpp"
40 #include "lib/dcp_content.h"
41 #include "lib/job_manager.h"
44 #include "lib/null_log.h"
45 #include "lib/video_content.h"
46 #include "lib/text_content.h"
47 #include "lib/ratio.h"
48 #include "lib/verify_dcp_job.h"
49 #include "lib/dcp_examiner.h"
50 #include "lib/examine_content_job.h"
51 #include "lib/server.h"
52 #include "lib/dcpomatic_socket.h"
53 #include "lib/scoped_temporary.h"
54 #include "lib/monitor_checker.h"
55 #include "lib/lock_file_checker.h"
56 #include "lib/ffmpeg_content.h"
57 #include "lib/dcpomatic_log.h"
58 #include "lib/file_log.h"
60 #include <dcp/raw_convert.h>
61 #include <dcp/exceptions.h>
63 #include <wx/stdpaths.h>
64 #include <wx/splash.h>
65 #include <wx/cmdline.h>
66 #include <wx/preferences.h>
67 #include <wx/progdlg.h>
68 #include <wx/display.h>
73 #include <ApplicationServices/ApplicationServices.h>
75 #include <boost/bind.hpp>
76 #include <boost/algorithm/string.hpp>
90 using boost::shared_ptr;
91 using boost::weak_ptr;
92 using boost::scoped_array;
93 using boost::optional;
94 using boost::dynamic_pointer_cast;
97 using dcp::raw_convert;
98 using namespace dcpomatic;
100 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
101 #define STRESS_TEST_CHECK_INTERVAL 20
120 boost::split (bits, line, boost::is_any_of(" "));
121 if (bits[0] == "O") {
122 if (bits.size() != 2) {
126 string_param = bits[1];
127 } else if (bits[0] == "P") {
129 } else if (bits[0] == "W") {
130 if (bits.size() != 2) {
134 int_param = raw_convert<int>(bits[1]);
135 } else if (bits[0] == "S") {
137 } else if (bits[0] == "K") {
138 if (bits.size() != 2) {
142 int_param = raw_convert<int>(bits[1]);
157 /* Allow spare IDs after _history for the recent files list */
160 /* Allow spare IDs for CPLs */
161 ID_view_full_screen = 200,
163 ID_view_closed_captions,
164 ID_view_scale_appropriate,
167 ID_view_scale_quarter,
168 ID_help_report_a_problem,
170 ID_tools_check_for_updates,
172 ID_tools_system_information,
173 /* IDs for shortcuts (with no associated menu item) */
179 class DOMFrame : public wxFrame
183 : wxFrame (0, -1, _("DCP-o-matic Player"))
185 , _update_news_requested (false)
187 , _mode (Config::instance()->player_mode())
191 , _history_position (0)
192 , _history_separator (0)
193 , _system_information_dialog (0)
194 , _view_full_screen (0)
195 , _view_dual_screen (0)
196 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
200 dcpomatic_log.reset (new NullLog());
202 #if defined(DCPOMATIC_WINDOWS)
203 maybe_open_console ();
204 cout << "DCP-o-matic Player is starting." << "\n";
207 wxMenuBar* bar = new wxMenuBar;
209 set_menu_sensitivity ();
212 #ifdef DCPOMATIC_WINDOWS
213 SetIcon (wxIcon (std_to_wx ("id")));
216 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
217 update_from_config (Config::PLAYER_DEBUG_LOG);
219 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
220 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
221 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
222 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
223 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
224 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
225 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
226 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
227 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
228 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
229 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
230 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
231 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
232 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
233 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
234 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
235 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
236 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
237 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
238 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
240 /* Use a panel as the only child of the Frame so that we avoid
241 the dark-grey background on Windows.
243 _overall_panel = new wxPanel (this, wxID_ANY);
245 _viewer.reset (new FilmViewer (_overall_panel));
246 #ifdef DCPOMATIC_VARIANT_SWAROOP
247 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
249 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
251 _controls = new StandardControls (_overall_panel, _viewer, false);
253 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
254 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
255 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
256 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
257 _info = new PlayerInformation (_overall_panel, _viewer);
258 setup_main_sizer (Config::instance()->player_mode());
260 int accelerators = 4;
262 int accelerators = 3;
265 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
266 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
267 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
268 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
270 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
272 wxAcceleratorTable accel_table (accelerators, accel);
273 SetAcceleratorTable (accel_table);
276 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
277 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
278 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
282 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
283 #ifdef DCPOMATIC_VARIANT_SWAROOP
284 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
285 MonitorChecker::instance()->run ();
286 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
287 LockFileChecker::instance()->run ();
291 #ifdef DCPOMATIC_VARIANT_SWAROOP
292 sc->check_restart ();
296 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
297 void stress (boost::filesystem::path script_file)
299 Bind (wxEVT_TIMER, boost::bind(&DOMFrame::check_commands, this));
300 _timer.Start(STRESS_TEST_CHECK_INTERVAL);
301 vector<string> lines;
302 string const script = dcp::file_to_string(script_file);
303 boost::split (lines, script, boost::is_any_of("\n"));
304 BOOST_FOREACH (string i, lines) {
305 _commands.push_back (Command(i));
307 _current_command = _commands.begin();
310 void check_commands ()
312 if (_current_command == _commands.end()) {
314 cout << "ST: finished.\n";
318 switch (_current_command->type) {
320 cout << "ST: load " << _current_command->string_param << "\n";
321 load_dcp (_current_command->string_param);
325 cout << "ST: play\n";
330 if (_wait_remaining) {
331 _wait_remaining = *_wait_remaining - STRESS_TEST_CHECK_INTERVAL;
332 if (_wait_remaining < 0) {
333 cout << "ST: wait done.\n";
334 _wait_remaining = optional<int>();
338 _wait_remaining = _current_command->int_param;
339 cout << "ST: waiting for " << *_wait_remaining << ".\n";
343 cout << "ST: stop\n";
351 /* int_param here is a number between 0 and 4095, corresponding to the possible slider positions */
352 cout << "ST: seek to " << _current_command->int_param << "\n";
353 _controls->seek (_current_command->int_param);
360 #ifdef DCPOMATIC_VARIANT_SWAROOP
361 void monitor_checker_state_changed ()
363 if (!MonitorChecker::instance()->ok()) {
365 error_dialog (this, _("The required display devices are not connected correctly."));
369 void lock_checker_state_changed ()
371 if (!LockFileChecker::instance()->ok()) {
373 error_dialog (this, _("The lock file is not present."));
378 void setup_main_sizer (Config::PlayerMode mode)
380 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
381 if (mode != Config::PLAYER_MODE_DUAL) {
382 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
384 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
385 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
386 _overall_panel->SetSizer (main_sizer);
387 _overall_panel->Layout ();
390 bool playback_permitted ()
392 #ifdef DCPOMATIC_VARIANT_SWAROOP
393 if (!MonitorChecker::instance()->ok()) {
394 error_dialog (this, _("The required display devices are not connected correctly."));
397 if (!LockFileChecker::instance()->ok()) {
398 error_dialog (this, _("The lock file is not present."));
402 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
407 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
408 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
409 if (d && !d->kdm_timing_window_valid()) {
414 #ifdef DCPOMATIC_VARIANT_SWAROOP
415 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
416 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
417 if (c && !c->kdm_timing_window_valid()) {
424 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
430 void playback_started (DCPTime time)
432 /* XXX: this only logs the first piece of content; probably should be each piece? */
433 if (_film->content().empty()) {
437 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
439 DCPExaminer ex (dcp, true);
440 shared_ptr<dcp::CPL> playing_cpl;
441 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
442 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
446 DCPOMATIC_ASSERT (playing_cpl);
450 "playback-started %s %s %s",
451 time.timecode(_film->video_frame_rate()).c_str(),
452 dcp->directories().front().string().c_str(),
453 playing_cpl->annotation_text().c_str()
458 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
462 "playback-started %s %s",
463 time.timecode(_film->video_frame_rate()).c_str(),
464 ffmpeg->path(0).string().c_str()
470 void playback_stopped (DCPTime time)
472 #ifdef DCPOMATIC_VARIANT_SWAROOP
474 boost::filesystem::remove (Config::path("position"));
480 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
483 void set_decode_reduction (optional<int> reduction)
485 _viewer->set_dcp_decode_reduction (reduction);
486 _info->triggered_update ();
487 Config::instance()->set_decode_reduction (reduction);
490 void load_dcp (boost::filesystem::path dir)
492 DCPOMATIC_ASSERT (_film);
496 shared_ptr<DCPContent> dcp (new DCPContent(dir));
497 _film->examine_and_add_content (dcp, true);
498 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
499 if (!ok || !report_errors_from_last_job(this)) {
502 #ifndef DCPOMATIC_VARIANT_SWAROOP
503 Config::instance()->add_to_player_history (dir);
505 } catch (dcp::DCPReadError& e) {
506 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
510 void reset_film_weak (weak_ptr<Film> weak_film)
512 shared_ptr<Film> film = weak_film.lock ();
518 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
521 _film->set_tolerant (true);
522 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
523 _viewer->set_film (_film);
524 _controls->set_film (_film);
525 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
526 _info->triggered_update ();
529 void film_changed (ChangeType type, Film::Property property)
531 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
535 if (_viewer->playing ()) {
539 /* Start off as Flat */
540 _film->set_container (Ratio::from_id("185"));
542 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
543 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
545 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
550 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
551 if (r->id() == "239") {
552 /* Any scope content means we use scope */
553 _film->set_container(r);
557 /* Any 3D content means we use 3D mode */
558 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
559 _film->set_three_d (true);
563 _viewer->seek (DCPTime(), true);
564 _info->triggered_update ();
566 set_menu_sensitivity ();
568 wxMenuItemList old = _cpl_menu->GetMenuItems();
569 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
570 _cpl_menu->Remove (*i);
573 if (_film->content().size() == 1) {
574 /* Offer a CPL menu */
575 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
577 DCPExaminer ex (first, true);
578 int id = ID_view_cpl;
579 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
580 wxMenuItem* j = _cpl_menu->AppendRadioItem(
582 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
584 j->Check(!first->cpl() || i->id() == *first->cpl());
593 bool report_errors_from_last_job (wxWindow* parent) const
595 JobManager* jm = JobManager::instance ();
597 DCPOMATIC_ASSERT (!jm->get().empty());
599 shared_ptr<Job> last = jm->get().back();
600 if (last->finished_in_error()) {
601 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()));
608 void setup_menu (wxMenuBar* m)
610 _file_menu = new wxMenu;
611 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
612 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
613 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
615 _history_position = _file_menu->GetMenuItems().GetCount();
617 _file_menu->AppendSeparator ();
618 _file_menu->Append (ID_file_close, _("&Close"));
619 _file_menu->AppendSeparator ();
622 _file_menu->Append (wxID_EXIT, _("&Exit"));
624 _file_menu->Append (wxID_EXIT, _("&Quit"));
628 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
630 wxMenu* edit = new wxMenu;
631 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
634 prefs->Enable (Config::instance()->have_write_permission());
636 _cpl_menu = new wxMenu;
638 wxMenu* view = new wxMenu;
639 optional<int> c = Config::instance()->decode_reduction();
640 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
641 view->AppendSeparator();
642 #ifndef DCPOMATIC_VARIANT_SWAROOP
643 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
644 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
647 view->AppendSeparator();
648 view->Append(ID_view_closed_captions, _("Closed captions..."));
649 view->AppendSeparator();
650 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
651 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
652 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
653 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
655 wxMenu* tools = new wxMenu;
656 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
657 tools->AppendSeparator ();
658 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
659 tools->Append (ID_tools_timing, _("Timing..."));
660 tools->Append (ID_tools_system_information, _("System information..."));
662 wxMenu* help = new wxMenu;
664 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
666 help->Append (wxID_ABOUT, _("About"));
668 help->Append (ID_help_report_a_problem, _("Report a problem..."));
670 m->Append (_file_menu, _("&File"));
672 m->Append (edit, _("&Edit"));
674 m->Append (view, _("&View"));
675 m->Append (tools, _("&Tools"));
676 m->Append (help, _("&Help"));
681 wxString d = wxStandardPaths::Get().GetDocumentsDir();
682 if (Config::instance()->last_player_load_directory()) {
683 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
686 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
691 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
692 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
699 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
701 Config::instance()->set_last_player_load_directory (dcp.parent_path());
709 wxDirDialog* c = new wxDirDialog (
711 _("Select DCP to open as OV"),
712 wxStandardPaths::Get().GetDocumentsDir(),
713 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
719 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
720 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
727 DCPOMATIC_ASSERT (_film);
728 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
729 DCPOMATIC_ASSERT (dcp);
730 dcp->add_ov (wx_to_std(c->GetPath()));
731 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
732 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
733 if (!ok || !report_errors_from_last_job(this)) {
736 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
740 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
742 _film->set_container(r);
748 _info->triggered_update ();
753 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
755 if (d->ShowModal() == wxID_OK) {
756 DCPOMATIC_ASSERT (_film);
757 #ifdef DCPOMATIC_VARIANT_SWAROOP
758 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
761 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
762 } catch (exception& e) {
763 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
769 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
770 #ifndef DCPOMATIC_VARIANT_SWAROOP
771 DCPOMATIC_ASSERT (dcp);
775 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
776 dcp->examine (_film, shared_ptr<Job>());
778 } catch (exception& e) {
779 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
786 _info->triggered_update ();
789 void file_history (wxCommandEvent& event)
791 vector<boost::filesystem::path> history = Config::instance()->player_history ();
792 int n = event.GetId() - ID_file_history;
793 if (n >= 0 && n < static_cast<int> (history.size ())) {
795 load_dcp (history[n]);
796 } catch (exception& e) {
797 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
805 _info->triggered_update ();
806 set_menu_sensitivity ();
814 void edit_preferences ()
816 if (!Config::instance()->have_write_permission()) {
820 if (!_config_dialog) {
821 _config_dialog = create_player_config_dialog ();
823 _config_dialog->Show (this);
826 void view_cpl (wxCommandEvent& ev)
828 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
829 DCPOMATIC_ASSERT (dcp);
830 DCPExaminer ex (dcp, true);
831 int id = ev.GetId() - ID_view_cpl;
832 DCPOMATIC_ASSERT (id >= 0);
833 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
834 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
835 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
841 dcp->set_cpl ((*i)->id());
842 dcp->examine (_film, shared_ptr<Job>());
845 void view_full_screen ()
847 if (_mode == Config::PLAYER_MODE_FULL) {
848 _mode = Config::PLAYER_MODE_WINDOW;
850 _mode = Config::PLAYER_MODE_FULL;
856 void view_dual_screen ()
858 if (_mode == Config::PLAYER_MODE_DUAL) {
859 _mode = Config::PLAYER_MODE_WINDOW;
861 _mode = Config::PLAYER_MODE_DUAL;
869 if (_view_full_screen) {
870 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
872 if (_view_dual_screen) {
873 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
879 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
880 _info->Show (_mode != Config::PLAYER_MODE_FULL);
881 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
882 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
883 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
885 if (_mode == Config::PLAYER_MODE_DUAL) {
886 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
887 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
888 _dual_screen->ShowFullScreen (true);
889 _viewer->panel()->Reparent (_dual_screen);
890 _dual_screen->Show ();
891 if (wxDisplay::GetCount() > 1) {
892 switch (Config::instance()->image_display()) {
894 _dual_screen->Move (0, 0);
895 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
898 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
899 // (0, 0) doesn't seem to work for some strange reason
906 _viewer->panel()->Reparent (_overall_panel);
907 _dual_screen->Destroy ();
912 setup_main_sizer (_mode);
915 void view_closed_captions ()
917 _viewer->show_closed_captions ();
922 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
923 DCPOMATIC_ASSERT (dcp);
925 JobManager* jm = JobManager::instance ();
926 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
927 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
932 DCPOMATIC_ASSERT (!jm->get().empty());
933 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
934 DCPOMATIC_ASSERT (last);
936 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
941 void tools_check_for_updates ()
943 UpdateChecker::instance()->run ();
944 _update_news_requested = true;
949 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
954 void tools_system_information ()
956 if (!_system_information_dialog) {
957 _system_information_dialog = new SystemInformationDialog (this, _viewer);
960 _system_information_dialog->Show ();
965 AboutDialog* d = new AboutDialog (this);
970 void help_report_a_problem ()
972 ReportProblemDialog* d = new ReportProblemDialog (this);
973 if (d->ShowModal () == wxID_OK) {
979 void update_checker_state_changed ()
981 UpdateChecker* uc = UpdateChecker::instance ();
983 bool const announce =
984 _update_news_requested ||
985 (uc->stable() && Config::instance()->check_for_updates()) ||
986 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
988 _update_news_requested = false;
994 if (uc->state() == UpdateChecker::YES) {
995 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
996 dialog->ShowModal ();
998 } else if (uc->state() == UpdateChecker::FAILED) {
999 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
1001 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
1004 _update_news_requested = false;
1007 void config_changed (Config::Property prop)
1009 /* Instantly save any config changes when using the player GUI */
1011 Config::instance()->write_config();
1012 } catch (FileError& e) {
1013 if (prop != Config::HISTORY) {
1017 _("Could not write to config file at %s. Your changes have not been saved."),
1018 std_to_wx(e.file().string())
1022 } catch (exception& e) {
1025 _("Could not write to config file. Your changes have not been saved.")
1029 update_from_config (prop);
1032 void update_from_config (Config::Property prop)
1034 for (int i = 0; i < _history_items; ++i) {
1035 delete _file_menu->Remove (ID_file_history + i);
1038 if (_history_separator) {
1039 _file_menu->Remove (_history_separator);
1041 delete _history_separator;
1042 _history_separator = 0;
1044 int pos = _history_position;
1046 /* Clear out non-existant history items before we re-build the menu */
1047 Config::instance()->clean_player_history ();
1048 vector<boost::filesystem::path> history = Config::instance()->player_history ();
1050 if (!history.empty ()) {
1051 _history_separator = _file_menu->InsertSeparator (pos++);
1054 for (size_t i = 0; i < history.size(); ++i) {
1057 s = String::compose ("&%1 %2", i + 1, history[i].string());
1059 s = history[i].string();
1061 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1064 _history_items = history.size ();
1066 if (prop == Config::PLAYER_DEBUG_LOG) {
1067 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1069 dcpomatic_log.reset (new FileLog(*p));
1071 dcpomatic_log.reset (new NullLog());
1073 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
1077 void set_menu_sensitivity ()
1079 _tools_verify->Enable (static_cast<bool>(_film));
1080 _file_add_ov->Enable (static_cast<bool>(_film));
1081 _file_add_kdm->Enable (static_cast<bool>(_film));
1082 _view_cpl->Enable (static_cast<bool>(_film));
1085 void start_stop_pressed ()
1087 if (_viewer->playing()) {
1096 _viewer->seek_by (-_viewer->one_video_frame(), true);
1099 void forward_frame ()
1101 _viewer->seek_by (_viewer->one_video_frame(), true);
1106 wxFrame* _dual_screen;
1107 bool _update_news_requested;
1108 PlayerInformation* _info;
1109 Config::PlayerMode _mode;
1110 wxPreferencesEditor* _config_dialog;
1111 wxPanel* _overall_panel;
1113 wxMenuItem* _view_cpl;
1116 int _history_position;
1117 wxMenuItem* _history_separator;
1118 shared_ptr<FilmViewer> _viewer;
1119 Controls* _controls;
1120 SystemInformationDialog* _system_information_dialog;
1121 boost::shared_ptr<Film> _film;
1122 boost::signals2::scoped_connection _config_changed_connection;
1123 wxMenuItem* _file_add_ov;
1124 wxMenuItem* _file_add_kdm;
1125 wxMenuItem* _tools_verify;
1126 wxMenuItem* _view_full_screen;
1127 wxMenuItem* _view_dual_screen;
1128 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1130 list<Command> _commands;
1131 list<Command>::const_iterator _current_command;
1132 optional<int> _wait_remaining;
1136 static const wxCmdLineEntryDesc command_line_description[] = {
1137 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1138 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1139 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1140 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1142 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1145 class PlayServer : public Server
1148 explicit PlayServer (DOMFrame* frame)
1149 : Server (PLAYER_PLAY_PORT)
1153 void handle (shared_ptr<Socket> socket)
1156 int const length = socket->read_uint32 ();
1157 scoped_array<char> buffer (new char[length]);
1158 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1159 string s (buffer.get());
1160 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1161 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1172 * @brief The magic App class for wxWidgets.
1174 class App : public wxApp
1181 #ifdef DCPOMATIC_LINUX
1190 wxSplashScreen* splash = 0;
1192 wxInitAllImageHandlers ();
1194 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1195 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1197 splash = maybe_show_splash ();
1199 SetAppName (_("DCP-o-matic Player"));
1201 if (!wxApp::OnInit()) {
1205 #ifdef DCPOMATIC_LINUX
1206 unsetenv ("UBUNTU_MENUPROXY");
1210 ProcessSerialNumber serial;
1211 GetCurrentProcess (&serial);
1212 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1215 dcpomatic_setup_path_encoding ();
1217 /* Enable i18n; this will create a Config object
1218 to look for a force-configured language. This Config
1219 object will be wrong, however, because dcpomatic_setup
1220 hasn't yet been called and there aren't any filters etc.
1223 dcpomatic_setup_i18n ();
1225 /* Set things up, including filters etc.
1226 which will now be internationalised correctly.
1230 /* Force the configuration to be re-loaded correctly next
1235 signal_manager = new wxSignalManager (this);
1237 _frame = new DOMFrame ();
1238 SetTopWindow (_frame);
1239 _frame->Maximize ();
1246 PlayServer* server = new PlayServer (_frame);
1247 new thread (boost::bind (&PlayServer::run, server));
1249 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1251 _frame->load_dcp (_dcp_to_load);
1252 } catch (exception& e) {
1253 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1257 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1260 _frame->stress (_stress.get());
1261 } catch (exception& e) {
1262 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1267 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1269 if (Config::instance()->check_for_updates ()) {
1270 UpdateChecker::instance()->run ();
1273 catch (exception& e)
1278 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1284 void OnInitCmdLine (wxCmdLineParser& parser)
1286 parser.SetDesc (command_line_description);
1287 parser.SetSwitchChars (wxT ("-"));
1290 bool OnCmdLineParsed (wxCmdLineParser& parser)
1292 if (parser.GetParamCount() > 0) {
1293 _dcp_to_load = wx_to_std (parser.GetParam (0));
1297 if (parser.Found("c", &config)) {
1298 Config::override_path = wx_to_std (config);
1300 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1302 if (parser.Found("s", &stress)) {
1303 _stress = wx_to_std (stress);
1310 void report_exception ()
1314 } catch (FileError& e) {
1318 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1319 std_to_wx (e.what()),
1320 std_to_wx (e.file().string().c_str ())
1323 } catch (exception& e) {
1327 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1328 std_to_wx (e.what ())
1332 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1336 /* An unhandled exception has occurred inside the main event loop */
1337 bool OnExceptionInMainLoop ()
1339 report_exception ();
1340 /* This will terminate the program */
1344 void OnUnhandledException ()
1346 report_exception ();
1351 signal_manager->ui_idle ();
1354 void config_failed_to_load ()
1356 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1359 void config_warning (string m)
1361 message_dialog (_frame, std_to_wx (m));
1365 string _dcp_to_load;
1366 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1367 boost::optional<string> _stress;