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 "lib/cross.h"
38 #include "lib/config.h"
40 #include "lib/internet.h"
41 #include "lib/update_checker.h"
42 #include "lib/compose.hpp"
43 #include "lib/dcp_content.h"
44 #include "lib/job_manager.h"
47 #include "lib/null_log.h"
48 #include "lib/video_content.h"
49 #include "lib/text_content.h"
50 #include "lib/ratio.h"
51 #include "lib/verify_dcp_job.h"
52 #include "lib/dcp_examiner.h"
53 #include "lib/examine_content_job.h"
54 #include "lib/server.h"
55 #include "lib/dcpomatic_socket.h"
56 #include "lib/scoped_temporary.h"
57 #include "lib/monitor_checker.h"
58 #include "lib/lock_file_checker.h"
59 #include "lib/ffmpeg_content.h"
60 #include "lib/dcpomatic_log.h"
61 #include "lib/file_log.h"
63 #include <dcp/raw_convert.h>
64 #include <dcp/exceptions.h>
66 #include <wx/stdpaths.h>
67 #include <wx/splash.h>
68 #include <wx/cmdline.h>
69 #include <wx/preferences.h>
70 #include <wx/progdlg.h>
71 #include <wx/display.h>
76 #include <ApplicationServices/ApplicationServices.h>
78 #include <boost/bind.hpp>
79 #include <boost/algorithm/string.hpp>
93 using boost::shared_ptr;
94 using boost::weak_ptr;
95 using boost::scoped_array;
96 using boost::optional;
97 using boost::dynamic_pointer_cast;
100 using dcp::raw_convert;
101 using namespace dcpomatic;
103 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
104 /* Interval to check what to do next with the stress checker, in milliseconds */
105 #define STRESS_TEST_CHECK_INTERVAL 20
124 boost::split (bits, line, boost::is_any_of(" "));
125 if (bits[0] == "O") {
126 if (bits.size() != 2) {
130 string_param = bits[1];
131 } else if (bits[0] == "P") {
133 } else if (bits[0] == "W") {
134 if (bits.size() != 2) {
138 int_param = raw_convert<int>(bits[1]);
139 } else if (bits[0] == "S") {
141 } else if (bits[0] == "K") {
142 if (bits.size() != 2) {
146 int_param = raw_convert<int>(bits[1]);
161 /* Allow spare IDs after _history for the recent files list */
164 /* Allow spare IDs for CPLs */
165 ID_view_full_screen = 200,
167 ID_view_closed_captions,
168 ID_view_scale_appropriate,
171 ID_view_scale_quarter,
172 ID_help_report_a_problem,
174 ID_tools_check_for_updates,
176 ID_tools_system_information,
177 /* IDs for shortcuts (with no associated menu item) */
183 class DOMFrame : public wxFrame
187 : wxFrame (0, -1, _("DCP-o-matic Player"))
189 , _update_news_requested (false)
191 , _mode (Config::instance()->player_mode())
195 , _history_position (0)
196 , _history_separator (0)
197 , _system_information_dialog (0)
198 , _view_full_screen (0)
199 , _view_dual_screen (0)
200 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
202 , _stress_suspended (false)
205 dcpomatic_log.reset (new NullLog());
207 #if defined(DCPOMATIC_WINDOWS)
208 maybe_open_console ();
209 cout << "DCP-o-matic Player is starting." << "\n";
212 wxMenuBar* bar = new wxMenuBar;
214 set_menu_sensitivity ();
217 #ifdef DCPOMATIC_WINDOWS
218 SetIcon (wxIcon (std_to_wx ("id")));
221 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
222 update_from_config (Config::PLAYER_DEBUG_LOG);
224 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
225 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
226 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
227 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
228 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
229 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
230 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
231 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
232 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
233 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
234 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
235 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
236 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
237 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
238 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
239 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
240 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
241 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
242 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
243 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
245 /* Use a panel as the only child of the Frame so that we avoid
246 the dark-grey background on Windows.
248 _overall_panel = new wxPanel (this, wxID_ANY);
250 _viewer.reset (new FilmViewer (_overall_panel));
251 #ifdef DCPOMATIC_VARIANT_SWAROOP
252 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
254 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
256 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
257 PlaylistControls* pc = new PlaylistControls (_overall_panel, _viewer);
259 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
261 _controls = new StandardControls (_overall_panel, _viewer, false);
264 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
265 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
266 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
267 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
268 _info = new PlayerInformation (_overall_panel, _viewer);
269 setup_main_sizer (Config::instance()->player_mode());
271 int accelerators = 4;
273 int accelerators = 3;
276 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
277 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
278 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
279 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
281 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
283 wxAcceleratorTable accel_table (accelerators, accel);
284 SetAcceleratorTable (accel_table);
287 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
288 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
289 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
293 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
294 #ifdef DCPOMATIC_VARIANT_SWAROOP
295 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
296 MonitorChecker::instance()->run ();
297 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
298 LockFileChecker::instance()->run ();
302 #ifdef DCPOMATIC_VARIANT_SWAROOP
303 sc->check_restart ();
307 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
308 void stress (boost::filesystem::path script_file)
310 Bind (wxEVT_TIMER, boost::bind(&DOMFrame::check_commands, this));
311 _timer.Start(STRESS_TEST_CHECK_INTERVAL);
312 vector<string> lines;
313 string const script = dcp::file_to_string(script_file);
314 boost::split (lines, script, boost::is_any_of("\n"));
315 BOOST_FOREACH (string i, lines) {
316 _commands.push_back (Command(i));
318 _current_command = _commands.begin();
321 void check_commands ()
323 if (_stress_suspended) {
327 if (_current_command == _commands.end()) {
329 cout << "ST: finished.\n";
333 switch (_current_command->type) {
335 load_dcp (_current_command->string_param);
339 cout << "ST: play\n";
344 /* int_param here is the number of milliseconds to wait */
345 if (_wait_remaining) {
346 _wait_remaining = *_wait_remaining - STRESS_TEST_CHECK_INTERVAL;
347 if (_wait_remaining < 0) {
348 cout << "ST: wait done.\n";
349 _wait_remaining = optional<int>();
353 _wait_remaining = _current_command->int_param;
354 cout << "ST: waiting for " << *_wait_remaining << ".\n";
358 cout << "ST: stop\n";
366 /* int_param here is a number between 0 and 4095, corresponding to the possible slider positions */
367 cout << "ST: seek to " << _current_command->int_param << "\n";
368 _controls->seek (_current_command->int_param);
375 #ifdef DCPOMATIC_VARIANT_SWAROOP
376 void monitor_checker_state_changed ()
378 if (!MonitorChecker::instance()->ok()) {
380 error_dialog (this, _("The required display devices are not connected correctly."));
384 void lock_checker_state_changed ()
386 if (!LockFileChecker::instance()->ok()) {
388 error_dialog (this, _("The lock file is not present."));
393 void setup_main_sizer (Config::PlayerMode mode)
395 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
396 if (mode != Config::PLAYER_MODE_DUAL) {
397 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
399 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
400 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
401 _overall_panel->SetSizer (main_sizer);
402 _overall_panel->Layout ();
405 bool playback_permitted ()
407 #ifdef DCPOMATIC_VARIANT_SWAROOP
408 if (!MonitorChecker::instance()->ok()) {
409 error_dialog (this, _("The required display devices are not connected correctly."));
412 if (!LockFileChecker::instance()->ok()) {
413 error_dialog (this, _("The lock file is not present."));
417 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
422 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
423 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
424 if (d && !d->kdm_timing_window_valid()) {
429 #ifdef DCPOMATIC_VARIANT_SWAROOP
430 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
431 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
432 if (c && !c->kdm_timing_window_valid()) {
439 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
445 void playback_started (DCPTime time)
447 /* XXX: this only logs the first piece of content; probably should be each piece? */
448 if (_film->content().empty()) {
452 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
454 DCPExaminer ex (dcp, true);
455 shared_ptr<dcp::CPL> playing_cpl;
456 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
457 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
461 DCPOMATIC_ASSERT (playing_cpl);
465 "playback-started %s %s %s",
466 time.timecode(_film->video_frame_rate()).c_str(),
467 dcp->directories().front().string().c_str(),
468 playing_cpl->annotation_text().c_str()
473 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
477 "playback-started %s %s",
478 time.timecode(_film->video_frame_rate()).c_str(),
479 ffmpeg->path(0).string().c_str()
485 void playback_stopped (DCPTime time)
487 #ifdef DCPOMATIC_VARIANT_SWAROOP
489 boost::filesystem::remove (Config::path("position"));
495 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
498 void set_decode_reduction (optional<int> reduction)
500 _viewer->set_dcp_decode_reduction (reduction);
501 _info->triggered_update ();
502 Config::instance()->set_decode_reduction (reduction);
505 void load_dcp (boost::filesystem::path dir)
507 DCPOMATIC_ASSERT (_film);
511 _stress_suspended = true;
512 shared_ptr<DCPContent> dcp (new DCPContent(dir));
513 shared_ptr<Job> job (new ExamineContentJob(_film, dcp));
514 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
515 JobManager::instance()->add (job);
516 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
517 if (!ok || !report_errors_from_last_job(this)) {
520 #ifndef DCPOMATIC_VARIANT_SWAROOP
521 Config::instance()->add_to_player_history (dir);
523 } catch (dcp::DCPReadError& e) {
524 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
528 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
530 shared_ptr<Job> job = weak_job.lock ();
531 if (!job || !job->finished_ok()) {
535 shared_ptr<Content> content = weak_content.lock ();
540 _film->add_content (content);
541 _stress_suspended = false;
544 void reset_film_weak (weak_ptr<Film> weak_film)
546 shared_ptr<Film> film = weak_film.lock ();
552 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
555 _film->set_tolerant (true);
556 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
557 _viewer->set_film (_film);
558 _controls->set_film (_film);
559 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
560 _info->triggered_update ();
563 void film_changed (ChangeType type, Film::Property property)
565 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
569 if (_viewer->playing ()) {
573 /* Start off as Flat */
574 _film->set_container (Ratio::from_id("185"));
576 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
577 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
579 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
584 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
585 if (r->id() == "239") {
586 /* Any scope content means we use scope */
587 _film->set_container(r);
591 /* Any 3D content means we use 3D mode */
592 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
593 _film->set_three_d (true);
597 _viewer->seek (DCPTime(), true);
598 _info->triggered_update ();
600 set_menu_sensitivity ();
602 wxMenuItemList old = _cpl_menu->GetMenuItems();
603 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
604 _cpl_menu->Remove (*i);
607 if (_film->content().size() == 1) {
608 /* Offer a CPL menu */
609 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
611 DCPExaminer ex (first, true);
612 int id = ID_view_cpl;
613 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
614 wxMenuItem* j = _cpl_menu->AppendRadioItem(
616 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
618 j->Check(!first->cpl() || i->id() == *first->cpl());
627 bool report_errors_from_last_job (wxWindow* parent) const
629 JobManager* jm = JobManager::instance ();
631 DCPOMATIC_ASSERT (!jm->get().empty());
633 shared_ptr<Job> last = jm->get().back();
634 if (last->finished_in_error()) {
635 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()));
642 void setup_menu (wxMenuBar* m)
644 _file_menu = new wxMenu;
645 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
646 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
647 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
649 _history_position = _file_menu->GetMenuItems().GetCount();
651 _file_menu->AppendSeparator ();
652 _file_menu->Append (ID_file_close, _("&Close"));
653 _file_menu->AppendSeparator ();
656 _file_menu->Append (wxID_EXIT, _("&Exit"));
658 _file_menu->Append (wxID_EXIT, _("&Quit"));
662 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
664 wxMenu* edit = new wxMenu;
665 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
668 prefs->Enable (Config::instance()->have_write_permission());
670 _cpl_menu = new wxMenu;
672 wxMenu* view = new wxMenu;
673 optional<int> c = Config::instance()->decode_reduction();
674 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
675 view->AppendSeparator();
676 #ifndef DCPOMATIC_VARIANT_SWAROOP
677 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
678 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
681 view->AppendSeparator();
682 view->Append(ID_view_closed_captions, _("Closed captions..."));
683 view->AppendSeparator();
684 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
685 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
686 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
687 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
689 wxMenu* tools = new wxMenu;
690 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
691 tools->AppendSeparator ();
692 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
693 tools->Append (ID_tools_timing, _("Timing..."));
694 tools->Append (ID_tools_system_information, _("System information..."));
696 wxMenu* help = new wxMenu;
698 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
700 help->Append (wxID_ABOUT, _("About"));
702 help->Append (ID_help_report_a_problem, _("Report a problem..."));
704 m->Append (_file_menu, _("&File"));
706 m->Append (edit, _("&Edit"));
708 m->Append (view, _("&View"));
709 m->Append (tools, _("&Tools"));
710 m->Append (help, _("&Help"));
715 wxString d = wxStandardPaths::Get().GetDocumentsDir();
716 if (Config::instance()->last_player_load_directory()) {
717 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
720 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
725 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
726 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
733 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
735 Config::instance()->set_last_player_load_directory (dcp.parent_path());
743 wxDirDialog* c = new wxDirDialog (
745 _("Select DCP to open as OV"),
746 wxStandardPaths::Get().GetDocumentsDir(),
747 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
753 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
754 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
761 DCPOMATIC_ASSERT (_film);
762 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
763 DCPOMATIC_ASSERT (dcp);
764 dcp->add_ov (wx_to_std(c->GetPath()));
765 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
766 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
767 if (!ok || !report_errors_from_last_job(this)) {
770 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
774 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
776 _film->set_container(r);
782 _info->triggered_update ();
787 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
789 if (d->ShowModal() == wxID_OK) {
790 DCPOMATIC_ASSERT (_film);
791 #ifdef DCPOMATIC_VARIANT_SWAROOP
792 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
795 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
796 } catch (exception& e) {
797 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
803 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
804 #ifndef DCPOMATIC_VARIANT_SWAROOP
805 DCPOMATIC_ASSERT (dcp);
809 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
810 dcp->examine (_film, shared_ptr<Job>());
812 } catch (exception& e) {
813 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
820 _info->triggered_update ();
823 void file_history (wxCommandEvent& event)
825 vector<boost::filesystem::path> history = Config::instance()->player_history ();
826 int n = event.GetId() - ID_file_history;
827 if (n >= 0 && n < static_cast<int> (history.size ())) {
829 load_dcp (history[n]);
830 } catch (exception& e) {
831 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
839 _info->triggered_update ();
840 set_menu_sensitivity ();
848 void edit_preferences ()
850 if (!Config::instance()->have_write_permission()) {
854 if (!_config_dialog) {
855 _config_dialog = create_player_config_dialog ();
857 _config_dialog->Show (this);
860 void view_cpl (wxCommandEvent& ev)
862 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
863 DCPOMATIC_ASSERT (dcp);
864 DCPExaminer ex (dcp, true);
865 int id = ev.GetId() - ID_view_cpl;
866 DCPOMATIC_ASSERT (id >= 0);
867 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
868 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
869 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
875 dcp->set_cpl ((*i)->id());
876 dcp->examine (_film, shared_ptr<Job>());
879 void view_full_screen ()
881 if (_mode == Config::PLAYER_MODE_FULL) {
882 _mode = Config::PLAYER_MODE_WINDOW;
884 _mode = Config::PLAYER_MODE_FULL;
890 void view_dual_screen ()
892 if (_mode == Config::PLAYER_MODE_DUAL) {
893 _mode = Config::PLAYER_MODE_WINDOW;
895 _mode = Config::PLAYER_MODE_DUAL;
903 if (_view_full_screen) {
904 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
906 if (_view_dual_screen) {
907 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
913 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
914 _info->Show (_mode != Config::PLAYER_MODE_FULL);
915 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
916 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
917 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
919 if (_mode == Config::PLAYER_MODE_DUAL) {
920 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
921 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
922 _dual_screen->ShowFullScreen (true);
923 _viewer->panel()->Reparent (_dual_screen);
924 _dual_screen->Show ();
925 if (wxDisplay::GetCount() > 1) {
926 switch (Config::instance()->image_display()) {
928 _dual_screen->Move (0, 0);
929 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
932 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
933 // (0, 0) doesn't seem to work for some strange reason
940 _viewer->panel()->Reparent (_overall_panel);
941 _dual_screen->Destroy ();
946 setup_main_sizer (_mode);
949 void view_closed_captions ()
951 _viewer->show_closed_captions ();
956 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
957 DCPOMATIC_ASSERT (dcp);
959 JobManager* jm = JobManager::instance ();
960 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
961 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
966 DCPOMATIC_ASSERT (!jm->get().empty());
967 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
968 DCPOMATIC_ASSERT (last);
970 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
975 void tools_check_for_updates ()
977 UpdateChecker::instance()->run ();
978 _update_news_requested = true;
983 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
988 void tools_system_information ()
990 if (!_system_information_dialog) {
991 _system_information_dialog = new SystemInformationDialog (this, _viewer);
994 _system_information_dialog->Show ();
999 AboutDialog* d = new AboutDialog (this);
1004 void help_report_a_problem ()
1006 ReportProblemDialog* d = new ReportProblemDialog (this);
1007 if (d->ShowModal () == wxID_OK) {
1013 void update_checker_state_changed ()
1015 UpdateChecker* uc = UpdateChecker::instance ();
1017 bool const announce =
1018 _update_news_requested ||
1019 (uc->stable() && Config::instance()->check_for_updates()) ||
1020 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
1022 _update_news_requested = false;
1028 if (uc->state() == UpdateChecker::YES) {
1029 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
1030 dialog->ShowModal ();
1032 } else if (uc->state() == UpdateChecker::FAILED) {
1033 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
1035 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
1038 _update_news_requested = false;
1041 void config_changed (Config::Property prop)
1043 /* Instantly save any config changes when using the player GUI */
1045 Config::instance()->write_config();
1046 } catch (FileError& e) {
1047 if (prop != Config::HISTORY) {
1051 _("Could not write to config file at %s. Your changes have not been saved."),
1052 std_to_wx(e.file().string())
1056 } catch (exception& e) {
1059 _("Could not write to config file. Your changes have not been saved.")
1063 update_from_config (prop);
1066 void update_from_config (Config::Property prop)
1068 for (int i = 0; i < _history_items; ++i) {
1069 delete _file_menu->Remove (ID_file_history + i);
1072 if (_history_separator) {
1073 _file_menu->Remove (_history_separator);
1075 delete _history_separator;
1076 _history_separator = 0;
1078 int pos = _history_position;
1080 /* Clear out non-existant history items before we re-build the menu */
1081 Config::instance()->clean_player_history ();
1082 vector<boost::filesystem::path> history = Config::instance()->player_history ();
1084 if (!history.empty ()) {
1085 _history_separator = _file_menu->InsertSeparator (pos++);
1088 for (size_t i = 0; i < history.size(); ++i) {
1091 s = String::compose ("&%1 %2", i + 1, history[i].string());
1093 s = history[i].string();
1095 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1098 _history_items = history.size ();
1100 if (prop == Config::PLAYER_DEBUG_LOG) {
1101 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1103 dcpomatic_log.reset (new FileLog(*p));
1105 dcpomatic_log.reset (new NullLog());
1107 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
1111 void set_menu_sensitivity ()
1113 _tools_verify->Enable (static_cast<bool>(_film));
1114 _file_add_ov->Enable (static_cast<bool>(_film));
1115 _file_add_kdm->Enable (static_cast<bool>(_film));
1116 _view_cpl->Enable (static_cast<bool>(_film));
1119 void start_stop_pressed ()
1121 if (_viewer->playing()) {
1130 _viewer->seek_by (-_viewer->one_video_frame(), true);
1133 void forward_frame ()
1135 _viewer->seek_by (_viewer->one_video_frame(), true);
1140 wxFrame* _dual_screen;
1141 bool _update_news_requested;
1142 PlayerInformation* _info;
1143 Config::PlayerMode _mode;
1144 wxPreferencesEditor* _config_dialog;
1145 wxPanel* _overall_panel;
1147 wxMenuItem* _view_cpl;
1150 int _history_position;
1151 wxMenuItem* _history_separator;
1152 shared_ptr<FilmViewer> _viewer;
1153 Controls* _controls;
1154 SystemInformationDialog* _system_information_dialog;
1155 boost::shared_ptr<Film> _film;
1156 boost::signals2::scoped_connection _config_changed_connection;
1157 boost::signals2::scoped_connection _examine_job_connection;
1158 wxMenuItem* _file_add_ov;
1159 wxMenuItem* _file_add_kdm;
1160 wxMenuItem* _tools_verify;
1161 wxMenuItem* _view_full_screen;
1162 wxMenuItem* _view_dual_screen;
1163 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1165 list<Command> _commands;
1166 list<Command>::const_iterator _current_command;
1167 /** Remaining time that the script must wait, in milliseconds */
1168 optional<int> _wait_remaining;
1169 bool _stress_suspended;
1173 static const wxCmdLineEntryDesc command_line_description[] = {
1174 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1175 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1176 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1177 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1179 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1182 class PlayServer : public Server
1185 explicit PlayServer (DOMFrame* frame)
1186 : Server (PLAYER_PLAY_PORT)
1190 void handle (shared_ptr<Socket> socket)
1193 int const length = socket->read_uint32 ();
1194 scoped_array<char> buffer (new char[length]);
1195 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1196 string s (buffer.get());
1197 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1198 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1209 * @brief The magic App class for wxWidgets.
1211 class App : public wxApp
1218 #ifdef DCPOMATIC_LINUX
1227 wxSplashScreen* splash = 0;
1229 wxInitAllImageHandlers ();
1231 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1232 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1234 splash = maybe_show_splash ();
1236 SetAppName (_("DCP-o-matic Player"));
1238 if (!wxApp::OnInit()) {
1242 #ifdef DCPOMATIC_LINUX
1243 unsetenv ("UBUNTU_MENUPROXY");
1247 ProcessSerialNumber serial;
1248 GetCurrentProcess (&serial);
1249 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1252 dcpomatic_setup_path_encoding ();
1254 /* Enable i18n; this will create a Config object
1255 to look for a force-configured language. This Config
1256 object will be wrong, however, because dcpomatic_setup
1257 hasn't yet been called and there aren't any filters etc.
1260 dcpomatic_setup_i18n ();
1262 /* Set things up, including filters etc.
1263 which will now be internationalised correctly.
1267 /* Force the configuration to be re-loaded correctly next
1272 signal_manager = new wxSignalManager (this);
1274 _frame = new DOMFrame ();
1275 SetTopWindow (_frame);
1276 _frame->Maximize ();
1283 PlayServer* server = new PlayServer (_frame);
1284 new thread (boost::bind (&PlayServer::run, server));
1286 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1288 _frame->load_dcp (_dcp_to_load);
1289 } catch (exception& e) {
1290 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1294 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1297 _frame->stress (_stress.get());
1298 } catch (exception& e) {
1299 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1304 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1306 if (Config::instance()->check_for_updates ()) {
1307 UpdateChecker::instance()->run ();
1310 catch (exception& e)
1315 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1321 void OnInitCmdLine (wxCmdLineParser& parser)
1323 parser.SetDesc (command_line_description);
1324 parser.SetSwitchChars (wxT ("-"));
1327 bool OnCmdLineParsed (wxCmdLineParser& parser)
1329 if (parser.GetParamCount() > 0) {
1330 _dcp_to_load = wx_to_std (parser.GetParam (0));
1334 if (parser.Found("c", &config)) {
1335 Config::override_path = wx_to_std (config);
1337 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1339 if (parser.Found("s", &stress)) {
1340 _stress = wx_to_std (stress);
1347 void report_exception ()
1351 } catch (FileError& e) {
1355 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1356 std_to_wx (e.what()),
1357 std_to_wx (e.file().string().c_str ())
1360 } catch (exception& e) {
1364 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1365 std_to_wx (e.what ())
1369 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1373 /* An unhandled exception has occurred inside the main event loop */
1374 bool OnExceptionInMainLoop ()
1376 report_exception ();
1377 /* This will terminate the program */
1381 void OnUnhandledException ()
1383 report_exception ();
1388 signal_manager->ui_idle ();
1391 void config_failed_to_load ()
1393 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1396 void config_warning (string m)
1398 message_dialog (_frame, std_to_wx (m));
1402 string _dcp_to_load;
1403 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1404 boost::optional<string> _stress;