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 #ifdef DCPOMATIC_VARIANT_SWAROOP
32 #include "wx/swaroop_controls.h"
34 #include "wx/timer_display.h"
35 #include "wx/system_information_dialog.h"
36 #include "lib/cross.h"
37 #include "lib/config.h"
39 #include "lib/internet.h"
40 #include "lib/update_checker.h"
41 #include "lib/compose.hpp"
42 #include "lib/dcp_content.h"
43 #include "lib/job_manager.h"
46 #include "lib/null_log.h"
47 #include "lib/video_content.h"
48 #include "lib/text_content.h"
49 #include "lib/ratio.h"
50 #include "lib/verify_dcp_job.h"
51 #include "lib/dcp_examiner.h"
52 #include "lib/examine_content_job.h"
53 #include "lib/server.h"
54 #include "lib/dcpomatic_socket.h"
55 #include "lib/scoped_temporary.h"
56 #include "lib/monitor_checker.h"
57 #include "lib/lock_file_checker.h"
58 #include "lib/ffmpeg_content.h"
59 #include "lib/dcpomatic_log.h"
60 #include "lib/file_log.h"
62 #include <dcp/raw_convert.h>
63 #include <dcp/exceptions.h>
65 #include <wx/stdpaths.h>
66 #include <wx/splash.h>
67 #include <wx/cmdline.h>
68 #include <wx/preferences.h>
69 #include <wx/progdlg.h>
70 #include <wx/display.h>
75 #include <ApplicationServices/ApplicationServices.h>
77 #include <boost/bind.hpp>
78 #include <boost/algorithm/string.hpp>
92 using boost::shared_ptr;
93 using boost::weak_ptr;
94 using boost::scoped_array;
95 using boost::optional;
96 using boost::dynamic_pointer_cast;
99 using dcp::raw_convert;
100 using namespace dcpomatic;
102 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
103 #define STRESS_TEST_CHECK_INTERVAL 20
122 boost::split (bits, line, boost::is_any_of(" "));
123 if (bits[0] == "O") {
124 if (bits.size() != 2) {
128 string_param = bits[1];
129 } else if (bits[0] == "P") {
131 } else if (bits[0] == "W") {
132 if (bits.size() != 2) {
136 int_param = raw_convert<int>(bits[1]);
137 } else if (bits[0] == "S") {
139 } else if (bits[0] == "K") {
140 if (bits.size() != 2) {
144 int_param = raw_convert<int>(bits[1]);
159 /* Allow spare IDs after _history for the recent files list */
162 /* Allow spare IDs for CPLs */
163 ID_view_full_screen = 200,
165 ID_view_closed_captions,
166 ID_view_scale_appropriate,
169 ID_view_scale_quarter,
170 ID_help_report_a_problem,
172 ID_tools_check_for_updates,
174 ID_tools_system_information,
175 /* IDs for shortcuts (with no associated menu item) */
181 class DOMFrame : public wxFrame
185 : wxFrame (0, -1, _("DCP-o-matic Player"))
187 , _update_news_requested (false)
189 , _mode (Config::instance()->player_mode())
193 , _history_position (0)
194 , _history_separator (0)
195 , _system_information_dialog (0)
196 , _view_full_screen (0)
197 , _view_dual_screen (0)
198 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
202 dcpomatic_log.reset (new NullLog());
204 #if defined(DCPOMATIC_WINDOWS)
205 maybe_open_console ();
206 cout << "DCP-o-matic Player is starting." << "\n";
209 wxMenuBar* bar = new wxMenuBar;
211 set_menu_sensitivity ();
214 #ifdef DCPOMATIC_WINDOWS
215 SetIcon (wxIcon (std_to_wx ("id")));
218 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
219 update_from_config (Config::PLAYER_DEBUG_LOG);
221 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
222 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
223 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
224 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
225 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
226 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
227 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
228 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
229 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
230 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
231 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
232 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
233 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
234 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
235 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
236 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
237 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
238 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
239 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
240 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
242 /* Use a panel as the only child of the Frame so that we avoid
243 the dark-grey background on Windows.
245 _overall_panel = new wxPanel (this, wxID_ANY);
247 _viewer.reset (new FilmViewer (_overall_panel));
248 #ifdef DCPOMATIC_VARIANT_SWAROOP
249 SwaroopControls* sc = new SwaroopControls (_overall_panel, _viewer);
251 sc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
253 _controls = new StandardControls (_overall_panel, _viewer, false);
255 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
256 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
257 _viewer->Started.connect (bind(&DOMFrame::playback_started, this, _1));
258 _viewer->Stopped.connect (bind(&DOMFrame::playback_stopped, this, _1));
259 _info = new PlayerInformation (_overall_panel, _viewer);
260 setup_main_sizer (Config::instance()->player_mode());
262 int accelerators = 4;
264 int accelerators = 3;
267 wxAcceleratorEntry* accel = new wxAcceleratorEntry[accelerators];
268 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
269 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_back_frame);
270 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_forward_frame);
272 accel[3].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
274 wxAcceleratorTable accel_table (accelerators, accel);
275 SetAcceleratorTable (accel_table);
278 Bind (wxEVT_MENU, boost::bind (&DOMFrame::start_stop_pressed, this), ID_start_stop);
279 Bind (wxEVT_MENU, boost::bind (&DOMFrame::back_frame, this), ID_back_frame);
280 Bind (wxEVT_MENU, boost::bind (&DOMFrame::forward_frame, this), ID_forward_frame);
284 UpdateChecker::instance()->StateChanged.connect (boost::bind (&DOMFrame::update_checker_state_changed, this));
285 #ifdef DCPOMATIC_VARIANT_SWAROOP
286 MonitorChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::monitor_checker_state_changed, this));
287 MonitorChecker::instance()->run ();
288 LockFileChecker::instance()->StateChanged.connect(boost::bind(&DOMFrame::lock_checker_state_changed, this));
289 LockFileChecker::instance()->run ();
293 #ifdef DCPOMATIC_VARIANT_SWAROOP
294 sc->check_restart ();
298 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
299 void stress (boost::filesystem::path script_file)
301 Bind (wxEVT_TIMER, boost::bind(&DOMFrame::check_commands, this));
302 _timer.Start(STRESS_TEST_CHECK_INTERVAL);
303 vector<string> lines;
304 string const script = dcp::file_to_string(script_file);
305 boost::split (lines, script, boost::is_any_of("\n"));
306 BOOST_FOREACH (string i, lines) {
307 _commands.push_back (Command(i));
309 _current_command = _commands.begin();
312 void check_commands ()
314 if (_current_command == _commands.end()) {
316 cout << "ST: finished.\n";
320 switch (_current_command->type) {
322 cout << "ST: load " << _current_command->string_param << "\n";
323 load_dcp (_current_command->string_param);
327 cout << "ST: play\n";
332 if (_wait_remaining) {
333 _wait_remaining = *_wait_remaining - STRESS_TEST_CHECK_INTERVAL;
334 if (_wait_remaining < 0) {
335 cout << "ST: wait done.\n";
336 _wait_remaining = optional<int>();
340 _wait_remaining = _current_command->int_param;
341 cout << "ST: waiting for " << *_wait_remaining << ".\n";
345 cout << "ST: stop\n";
353 /* int_param here is a number between 0 and 4095, corresponding to the possible slider positions */
354 cout << "ST: seek to " << _current_command->int_param << "\n";
355 _controls->seek (_current_command->int_param);
362 #ifdef DCPOMATIC_VARIANT_SWAROOP
363 void monitor_checker_state_changed ()
365 if (!MonitorChecker::instance()->ok()) {
367 error_dialog (this, _("The required display devices are not connected correctly."));
371 void lock_checker_state_changed ()
373 if (!LockFileChecker::instance()->ok()) {
375 error_dialog (this, _("The lock file is not present."));
380 void setup_main_sizer (Config::PlayerMode mode)
382 wxSizer* main_sizer = new wxBoxSizer (wxVERTICAL);
383 if (mode != Config::PLAYER_MODE_DUAL) {
384 main_sizer->Add (_viewer->panel(), 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
386 main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
387 main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
388 _overall_panel->SetSizer (main_sizer);
389 _overall_panel->Layout ();
392 bool playback_permitted ()
394 #ifdef DCPOMATIC_VARIANT_SWAROOP
395 if (!MonitorChecker::instance()->ok()) {
396 error_dialog (this, _("The required display devices are not connected correctly."));
399 if (!LockFileChecker::instance()->ok()) {
400 error_dialog (this, _("The lock file is not present."));
404 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
409 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
410 shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
411 if (d && !d->kdm_timing_window_valid()) {
416 #ifdef DCPOMATIC_VARIANT_SWAROOP
417 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
418 shared_ptr<FFmpegContent> c = dynamic_pointer_cast<FFmpegContent>(i);
419 if (c && !c->kdm_timing_window_valid()) {
426 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
432 void playback_started (DCPTime time)
434 /* XXX: this only logs the first piece of content; probably should be each piece? */
435 if (_film->content().empty()) {
439 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
441 DCPExaminer ex (dcp, true);
442 shared_ptr<dcp::CPL> playing_cpl;
443 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
444 if (!dcp->cpl() || i->id() == *dcp->cpl()) {
448 DCPOMATIC_ASSERT (playing_cpl);
452 "playback-started %s %s %s",
453 time.timecode(_film->video_frame_rate()).c_str(),
454 dcp->directories().front().string().c_str(),
455 playing_cpl->annotation_text().c_str()
460 shared_ptr<FFmpegContent> ffmpeg = dynamic_pointer_cast<FFmpegContent>(_film->content().front());
464 "playback-started %s %s",
465 time.timecode(_film->video_frame_rate()).c_str(),
466 ffmpeg->path(0).string().c_str()
472 void playback_stopped (DCPTime time)
474 #ifdef DCPOMATIC_VARIANT_SWAROOP
476 boost::filesystem::remove (Config::path("position"));
482 _controls->log (wxString::Format("playback-stopped %s", time.timecode(_film->video_frame_rate()).c_str()));
485 void set_decode_reduction (optional<int> reduction)
487 _viewer->set_dcp_decode_reduction (reduction);
488 _info->triggered_update ();
489 Config::instance()->set_decode_reduction (reduction);
492 void load_dcp (boost::filesystem::path dir)
494 DCPOMATIC_ASSERT (_film);
498 shared_ptr<DCPContent> dcp (new DCPContent(dir));
499 _film->examine_and_add_content (dcp, true);
500 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
501 if (!ok || !report_errors_from_last_job(this)) {
504 #ifndef DCPOMATIC_VARIANT_SWAROOP
505 Config::instance()->add_to_player_history (dir);
507 } catch (dcp::DCPReadError& e) {
508 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
512 void reset_film_weak (weak_ptr<Film> weak_film)
514 shared_ptr<Film> film = weak_film.lock ();
520 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
523 _film->set_tolerant (true);
524 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
525 _viewer->set_film (_film);
526 _controls->set_film (_film);
527 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
528 _info->triggered_update ();
531 void film_changed (ChangeType type, Film::Property property)
533 if (type != CHANGE_TYPE_DONE || property != Film::CONTENT) {
537 if (_viewer->playing ()) {
541 /* Start off as Flat */
542 _film->set_container (Ratio::from_id("185"));
544 BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
545 shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
547 BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
552 Ratio const * r = Ratio::nearest_from_ratio(i->video->size().ratio());
553 if (r->id() == "239") {
554 /* Any scope content means we use scope */
555 _film->set_container(r);
559 /* Any 3D content means we use 3D mode */
560 if (i->video && i->video->frame_type() != VIDEO_FRAME_TYPE_2D) {
561 _film->set_three_d (true);
565 _viewer->seek (DCPTime(), true);
566 _info->triggered_update ();
568 set_menu_sensitivity ();
570 wxMenuItemList old = _cpl_menu->GetMenuItems();
571 for (wxMenuItemList::iterator i = old.begin(); i != old.end(); ++i) {
572 _cpl_menu->Remove (*i);
575 if (_film->content().size() == 1) {
576 /* Offer a CPL menu */
577 shared_ptr<DCPContent> first = dynamic_pointer_cast<DCPContent>(_film->content().front());
579 DCPExaminer ex (first, true);
580 int id = ID_view_cpl;
581 BOOST_FOREACH (shared_ptr<dcp::CPL> i, ex.cpls()) {
582 wxMenuItem* j = _cpl_menu->AppendRadioItem(
584 wxString::Format("%s (%s)", std_to_wx(i->annotation_text()).data(), std_to_wx(i->id()).data())
586 j->Check(!first->cpl() || i->id() == *first->cpl());
595 bool report_errors_from_last_job (wxWindow* parent) const
597 JobManager* jm = JobManager::instance ();
599 DCPOMATIC_ASSERT (!jm->get().empty());
601 shared_ptr<Job> last = jm->get().back();
602 if (last->finished_in_error()) {
603 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()));
610 void setup_menu (wxMenuBar* m)
612 _file_menu = new wxMenu;
613 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
614 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
615 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
617 _history_position = _file_menu->GetMenuItems().GetCount();
619 _file_menu->AppendSeparator ();
620 _file_menu->Append (ID_file_close, _("&Close"));
621 _file_menu->AppendSeparator ();
624 _file_menu->Append (wxID_EXIT, _("&Exit"));
626 _file_menu->Append (wxID_EXIT, _("&Quit"));
630 wxMenuItem* prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
632 wxMenu* edit = new wxMenu;
633 wxMenuItem* prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
636 prefs->Enable (Config::instance()->have_write_permission());
638 _cpl_menu = new wxMenu;
640 wxMenu* view = new wxMenu;
641 optional<int> c = Config::instance()->decode_reduction();
642 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
643 view->AppendSeparator();
644 #ifndef DCPOMATIC_VARIANT_SWAROOP
645 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
646 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
649 view->AppendSeparator();
650 view->Append(ID_view_closed_captions, _("Closed captions..."));
651 view->AppendSeparator();
652 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
653 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
654 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
655 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
657 wxMenu* tools = new wxMenu;
658 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP"));
659 tools->AppendSeparator ();
660 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
661 tools->Append (ID_tools_timing, _("Timing..."));
662 tools->Append (ID_tools_system_information, _("System information..."));
664 wxMenu* help = new wxMenu;
666 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
668 help->Append (wxID_ABOUT, _("About"));
670 help->Append (ID_help_report_a_problem, _("Report a problem..."));
672 m->Append (_file_menu, _("&File"));
674 m->Append (edit, _("&Edit"));
676 m->Append (view, _("&View"));
677 m->Append (tools, _("&Tools"));
678 m->Append (help, _("&Help"));
683 wxString d = wxStandardPaths::Get().GetDocumentsDir();
684 if (Config::instance()->last_player_load_directory()) {
685 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
688 wxDirDialog* c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
693 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
694 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
701 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
703 Config::instance()->set_last_player_load_directory (dcp.parent_path());
711 wxDirDialog* c = new wxDirDialog (
713 _("Select DCP to open as OV"),
714 wxStandardPaths::Get().GetDocumentsDir(),
715 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
721 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
722 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
729 DCPOMATIC_ASSERT (_film);
730 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
731 DCPOMATIC_ASSERT (dcp);
732 dcp->add_ov (wx_to_std(c->GetPath()));
733 JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob (_film, dcp)));
734 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
735 if (!ok || !report_errors_from_last_job(this)) {
738 BOOST_FOREACH (shared_ptr<TextContent> i, dcp->text) {
742 Ratio const * r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
744 _film->set_container(r);
750 _info->triggered_update ();
755 wxFileDialog* d = new wxFileDialog (this, _("Select KDM"));
757 if (d->ShowModal() == wxID_OK) {
758 DCPOMATIC_ASSERT (_film);
759 #ifdef DCPOMATIC_VARIANT_SWAROOP
760 shared_ptr<FFmpegContent> ffmpeg = boost::dynamic_pointer_cast<FFmpegContent>(_film->content().front());
763 ffmpeg->add_kdm (EncryptedECinemaKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
764 } catch (exception& e) {
765 error_dialog (this, wxString::Format(_("Could not load KDM.")), std_to_wx(e.what()));
771 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
772 #ifndef DCPOMATIC_VARIANT_SWAROOP
773 DCPOMATIC_ASSERT (dcp);
777 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
778 dcp->examine (_film, shared_ptr<Job>());
780 } catch (exception& e) {
781 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
788 _info->triggered_update ();
791 void file_history (wxCommandEvent& event)
793 vector<boost::filesystem::path> history = Config::instance()->player_history ();
794 int n = event.GetId() - ID_file_history;
795 if (n >= 0 && n < static_cast<int> (history.size ())) {
797 load_dcp (history[n]);
798 } catch (exception& e) {
799 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
807 _info->triggered_update ();
808 set_menu_sensitivity ();
816 void edit_preferences ()
818 if (!Config::instance()->have_write_permission()) {
822 if (!_config_dialog) {
823 _config_dialog = create_player_config_dialog ();
825 _config_dialog->Show (this);
828 void view_cpl (wxCommandEvent& ev)
830 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
831 DCPOMATIC_ASSERT (dcp);
832 DCPExaminer ex (dcp, true);
833 int id = ev.GetId() - ID_view_cpl;
834 DCPOMATIC_ASSERT (id >= 0);
835 DCPOMATIC_ASSERT (id < int(ex.cpls().size()));
836 list<shared_ptr<dcp::CPL> > cpls = ex.cpls();
837 list<shared_ptr<dcp::CPL> >::iterator i = cpls.begin();
843 dcp->set_cpl ((*i)->id());
844 dcp->examine (_film, shared_ptr<Job>());
847 void view_full_screen ()
849 if (_mode == Config::PLAYER_MODE_FULL) {
850 _mode = Config::PLAYER_MODE_WINDOW;
852 _mode = Config::PLAYER_MODE_FULL;
858 void view_dual_screen ()
860 if (_mode == Config::PLAYER_MODE_DUAL) {
861 _mode = Config::PLAYER_MODE_WINDOW;
863 _mode = Config::PLAYER_MODE_DUAL;
871 if (_view_full_screen) {
872 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
874 if (_view_dual_screen) {
875 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
881 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
882 _info->Show (_mode != Config::PLAYER_MODE_FULL);
883 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
884 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
885 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
887 if (_mode == Config::PLAYER_MODE_DUAL) {
888 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
889 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
890 _dual_screen->ShowFullScreen (true);
891 _viewer->panel()->Reparent (_dual_screen);
892 _dual_screen->Show ();
893 if (wxDisplay::GetCount() > 1) {
894 switch (Config::instance()->image_display()) {
896 _dual_screen->Move (0, 0);
897 Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
900 _dual_screen->Move (wxDisplay(0).GetClientArea().GetWidth(), 0);
901 // (0, 0) doesn't seem to work for some strange reason
908 _viewer->panel()->Reparent (_overall_panel);
909 _dual_screen->Destroy ();
914 setup_main_sizer (_mode);
917 void view_closed_captions ()
919 _viewer->show_closed_captions ();
924 shared_ptr<DCPContent> dcp = boost::dynamic_pointer_cast<DCPContent>(_film->content().front());
925 DCPOMATIC_ASSERT (dcp);
927 JobManager* jm = JobManager::instance ();
928 jm->add (shared_ptr<Job> (new VerifyDCPJob (dcp->directories())));
929 bool const ok = display_progress (_("DCP-o-matic Player"), _("Verifying DCP"));
934 DCPOMATIC_ASSERT (!jm->get().empty());
935 shared_ptr<VerifyDCPJob> last = dynamic_pointer_cast<VerifyDCPJob> (jm->get().back());
936 DCPOMATIC_ASSERT (last);
938 VerifyDCPDialog* d = new VerifyDCPDialog (this, last);
943 void tools_check_for_updates ()
945 UpdateChecker::instance()->run ();
946 _update_news_requested = true;
951 TimerDisplay* d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
956 void tools_system_information ()
958 if (!_system_information_dialog) {
959 _system_information_dialog = new SystemInformationDialog (this, _viewer);
962 _system_information_dialog->Show ();
967 AboutDialog* d = new AboutDialog (this);
972 void help_report_a_problem ()
974 ReportProblemDialog* d = new ReportProblemDialog (this);
975 if (d->ShowModal () == wxID_OK) {
981 void update_checker_state_changed ()
983 UpdateChecker* uc = UpdateChecker::instance ();
985 bool const announce =
986 _update_news_requested ||
987 (uc->stable() && Config::instance()->check_for_updates()) ||
988 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
990 _update_news_requested = false;
996 if (uc->state() == UpdateChecker::YES) {
997 UpdateDialog* dialog = new UpdateDialog (this, uc->stable (), uc->test ());
998 dialog->ShowModal ();
1000 } else if (uc->state() == UpdateChecker::FAILED) {
1001 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
1003 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
1006 _update_news_requested = false;
1009 void config_changed (Config::Property prop)
1011 /* Instantly save any config changes when using the player GUI */
1013 Config::instance()->write_config();
1014 } catch (FileError& e) {
1015 if (prop != Config::HISTORY) {
1019 _("Could not write to config file at %s. Your changes have not been saved."),
1020 std_to_wx(e.file().string())
1024 } catch (exception& e) {
1027 _("Could not write to config file. Your changes have not been saved.")
1031 update_from_config (prop);
1034 void update_from_config (Config::Property prop)
1036 for (int i = 0; i < _history_items; ++i) {
1037 delete _file_menu->Remove (ID_file_history + i);
1040 if (_history_separator) {
1041 _file_menu->Remove (_history_separator);
1043 delete _history_separator;
1044 _history_separator = 0;
1046 int pos = _history_position;
1048 /* Clear out non-existant history items before we re-build the menu */
1049 Config::instance()->clean_player_history ();
1050 vector<boost::filesystem::path> history = Config::instance()->player_history ();
1052 if (!history.empty ()) {
1053 _history_separator = _file_menu->InsertSeparator (pos++);
1056 for (size_t i = 0; i < history.size(); ++i) {
1059 s = String::compose ("&%1 %2", i + 1, history[i].string());
1061 s = history[i].string();
1063 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
1066 _history_items = history.size ();
1068 if (prop == Config::PLAYER_DEBUG_LOG) {
1069 optional<boost::filesystem::path> p = Config::instance()->player_debug_log_file();
1071 dcpomatic_log.reset (new FileLog(*p));
1073 dcpomatic_log.reset (new NullLog());
1075 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_PLAYER);
1079 void set_menu_sensitivity ()
1081 _tools_verify->Enable (static_cast<bool>(_film));
1082 _file_add_ov->Enable (static_cast<bool>(_film));
1083 _file_add_kdm->Enable (static_cast<bool>(_film));
1084 _view_cpl->Enable (static_cast<bool>(_film));
1087 void start_stop_pressed ()
1089 if (_viewer->playing()) {
1098 _viewer->seek_by (-_viewer->one_video_frame(), true);
1101 void forward_frame ()
1103 _viewer->seek_by (_viewer->one_video_frame(), true);
1108 wxFrame* _dual_screen;
1109 bool _update_news_requested;
1110 PlayerInformation* _info;
1111 Config::PlayerMode _mode;
1112 wxPreferencesEditor* _config_dialog;
1113 wxPanel* _overall_panel;
1115 wxMenuItem* _view_cpl;
1118 int _history_position;
1119 wxMenuItem* _history_separator;
1120 shared_ptr<FilmViewer> _viewer;
1121 Controls* _controls;
1122 SystemInformationDialog* _system_information_dialog;
1123 boost::shared_ptr<Film> _film;
1124 boost::signals2::scoped_connection _config_changed_connection;
1125 wxMenuItem* _file_add_ov;
1126 wxMenuItem* _file_add_kdm;
1127 wxMenuItem* _tools_verify;
1128 wxMenuItem* _view_full_screen;
1129 wxMenuItem* _view_dual_screen;
1130 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1132 list<Command> _commands;
1133 list<Command>::const_iterator _current_command;
1134 optional<int> _wait_remaining;
1138 static const wxCmdLineEntryDesc command_line_description[] = {
1139 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1140 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1141 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1142 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1144 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1147 class PlayServer : public Server
1150 explicit PlayServer (DOMFrame* frame)
1151 : Server (PLAYER_PLAY_PORT)
1155 void handle (shared_ptr<Socket> socket)
1158 int const length = socket->read_uint32 ();
1159 scoped_array<char> buffer (new char[length]);
1160 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1161 string s (buffer.get());
1162 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1163 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1174 * @brief The magic App class for wxWidgets.
1176 class App : public wxApp
1183 #ifdef DCPOMATIC_LINUX
1192 wxSplashScreen* splash = 0;
1194 wxInitAllImageHandlers ();
1196 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1197 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1199 splash = maybe_show_splash ();
1201 SetAppName (_("DCP-o-matic Player"));
1203 if (!wxApp::OnInit()) {
1207 #ifdef DCPOMATIC_LINUX
1208 unsetenv ("UBUNTU_MENUPROXY");
1212 ProcessSerialNumber serial;
1213 GetCurrentProcess (&serial);
1214 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
1217 dcpomatic_setup_path_encoding ();
1219 /* Enable i18n; this will create a Config object
1220 to look for a force-configured language. This Config
1221 object will be wrong, however, because dcpomatic_setup
1222 hasn't yet been called and there aren't any filters etc.
1225 dcpomatic_setup_i18n ();
1227 /* Set things up, including filters etc.
1228 which will now be internationalised correctly.
1232 /* Force the configuration to be re-loaded correctly next
1237 signal_manager = new wxSignalManager (this);
1239 _frame = new DOMFrame ();
1240 SetTopWindow (_frame);
1241 _frame->Maximize ();
1248 PlayServer* server = new PlayServer (_frame);
1249 new thread (boost::bind (&PlayServer::run, server));
1251 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1253 _frame->load_dcp (_dcp_to_load);
1254 } catch (exception& e) {
1255 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1259 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1262 _frame->stress (_stress.get());
1263 } catch (exception& e) {
1264 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1269 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1271 if (Config::instance()->check_for_updates ()) {
1272 UpdateChecker::instance()->run ();
1275 catch (exception& e)
1280 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1286 void OnInitCmdLine (wxCmdLineParser& parser)
1288 parser.SetDesc (command_line_description);
1289 parser.SetSwitchChars (wxT ("-"));
1292 bool OnCmdLineParsed (wxCmdLineParser& parser)
1294 if (parser.GetParamCount() > 0) {
1295 _dcp_to_load = wx_to_std (parser.GetParam (0));
1299 if (parser.Found("c", &config)) {
1300 Config::override_path = wx_to_std (config);
1302 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1304 if (parser.Found("s", &stress)) {
1305 _stress = wx_to_std (stress);
1312 void report_exception ()
1316 } catch (FileError& e) {
1320 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1321 std_to_wx (e.what()),
1322 std_to_wx (e.file().string().c_str ())
1325 } catch (exception& e) {
1329 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1330 std_to_wx (e.what ())
1334 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1338 /* An unhandled exception has occurred inside the main event loop */
1339 bool OnExceptionInMainLoop ()
1341 report_exception ();
1342 /* This will terminate the program */
1346 void OnUnhandledException ()
1348 report_exception ();
1353 signal_manager->ui_idle ();
1356 void config_failed_to_load ()
1358 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1361 void config_warning (string m)
1363 message_dialog (_frame, std_to_wx (m));
1367 string _dcp_to_load;
1368 #ifdef DCPOMATIC_PLAYER_STRESS_TEST
1369 boost::optional<string> _stress;