2 Copyright (C) 2017-2021 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/about_dialog.h"
22 #include "wx/film_viewer.h"
23 #include "wx/nag_dialog.h"
24 #include "wx/player_config_dialog.h"
25 #include "wx/player_information.h"
26 #include "wx/player_stress_tester.h"
27 #include "wx/playlist_controls.h"
28 #include "wx/report_problem_dialog.h"
29 #include "wx/standard_controls.h"
30 #include "wx/system_information_dialog.h"
31 #include "wx/timer_display.h"
32 #include "wx/update_dialog.h"
33 #include "wx/verify_dcp_dialog.h"
34 #include "wx/verify_dcp_progress_dialog.h"
35 #include "wx/wx_signal_manager.h"
36 #include "wx/wx_util.h"
37 #include "lib/compose.hpp"
38 #include "lib/config.h"
39 #include "lib/cross.h"
40 #include "lib/dcp_content.h"
41 #include "lib/dcpomatic_log.h"
42 #include "lib/dcpomatic_socket.h"
43 #include "lib/examine_content_job.h"
44 #include "lib/ffmpeg_content.h"
45 #include "lib/file_log.h"
47 #include "lib/image.h"
48 #include "lib/image_jpeg.h"
49 #include "lib/image_png.h"
50 #include "lib/internet.h"
52 #include "lib/job_manager.h"
53 #include "lib/null_log.h"
54 #include "lib/player.h"
55 #include "lib/player_video.h"
56 #include "lib/ratio.h"
57 #include "lib/scoped_temporary.h"
58 #include "lib/server.h"
59 #include "lib/text_content.h"
60 #include "lib/update_checker.h"
62 #include "lib/verify_dcp_job.h"
63 #include "lib/video_content.h"
66 #include <dcp/exceptions.h>
67 #include <dcp/search.h>
68 #include <dcp/raw_convert.h>
69 #include <wx/cmdline.h>
70 #include <wx/display.h>
71 #include <wx/preferences.h>
72 #include <wx/progdlg.h>
73 #include <wx/splash.h>
74 #include <wx/stdpaths.h>
79 #include <boost/bind/bind.hpp>
80 #include <boost/algorithm/string.hpp>
90 using std::dynamic_pointer_cast;
93 using std::make_shared;
94 using std::shared_ptr;
98 using boost::scoped_array;
99 using boost::optional;
102 #if BOOST_VERSION >= 106100
103 using namespace boost::placeholders;
105 using dcp::raw_convert;
106 using namespace dcpomatic;
114 /* Allow spare IDs after _history for the recent files list */
117 /* Allow spare IDs for CPLs */
118 ID_view_full_screen = 200,
120 ID_view_closed_captions,
121 ID_view_scale_appropriate,
124 ID_view_scale_quarter,
125 ID_help_report_a_problem,
127 ID_tools_check_for_updates,
129 ID_tools_system_information,
130 /* IDs for shortcuts (with no associated menu item) */
134 ID_go_back_small_amount,
135 ID_go_forward_small_amount,
136 ID_go_back_medium_amount,
137 ID_go_forward_medium_amount,
138 ID_go_back_large_amount,
139 ID_go_forward_large_amount,
144 class DOMFrame : public wxFrame
148 : wxFrame (nullptr, -1, _("DCP-o-matic Player"))
149 , _mode (Config::instance()->player_mode())
150 , _main_sizer (new wxBoxSizer(wxVERTICAL))
152 dcpomatic_log = make_shared<NullLog>();
154 #if defined(DCPOMATIC_WINDOWS)
155 maybe_open_console ();
156 cout << "DCP-o-matic Player is starting." << "\n";
159 auto bar = new wxMenuBar;
161 set_menu_sensitivity ();
164 #ifdef DCPOMATIC_WINDOWS
165 SetIcon (wxIcon (std_to_wx ("id")));
168 _config_changed_connection = Config::instance()->Changed.connect (boost::bind (&DOMFrame::config_changed, this, _1));
169 update_from_config (Config::PLAYER_DEBUG_LOG);
171 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_open, this), ID_file_open);
172 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_ov, this), ID_file_add_ov);
173 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_add_kdm, this), ID_file_add_kdm);
174 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_save_frame, this), ID_file_save_frame);
175 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_history, this, _1), ID_file_history, ID_file_history + HISTORY_SIZE);
176 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_close, this), ID_file_close);
177 Bind (wxEVT_MENU, boost::bind (&DOMFrame::file_exit, this), wxID_EXIT);
178 Bind (wxEVT_MENU, boost::bind (&DOMFrame::edit_preferences, this), wxID_PREFERENCES);
179 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_full_screen, this), ID_view_full_screen);
180 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_dual_screen, this), ID_view_dual_screen);
181 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_closed_captions, this), ID_view_closed_captions);
182 Bind (wxEVT_MENU, boost::bind (&DOMFrame::view_cpl, this, _1), ID_view_cpl, ID_view_cpl + MAX_CPLS);
183 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(0)), ID_view_scale_full);
184 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(1)), ID_view_scale_half);
185 Bind (wxEVT_MENU, boost::bind (&DOMFrame::set_decode_reduction, this, optional<int>(2)), ID_view_scale_quarter);
186 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_about, this), wxID_ABOUT);
187 Bind (wxEVT_MENU, boost::bind (&DOMFrame::help_report_a_problem, this), ID_help_report_a_problem);
188 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_verify, this), ID_tools_verify);
189 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_check_for_updates, this), ID_tools_check_for_updates);
190 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_timing, this), ID_tools_timing);
191 Bind (wxEVT_MENU, boost::bind (&DOMFrame::tools_system_information, this), ID_tools_system_information);
193 /* Use a panel as the only child of the Frame so that we avoid
194 the dark-grey background on Windows.
196 _overall_panel = new wxPanel (this, wxID_ANY);
198 _viewer = make_shared<FilmViewer>(_overall_panel);
199 if (Config::instance()->player_mode() == Config::PLAYER_MODE_DUAL) {
200 auto pc = new PlaylistControls (_overall_panel, _viewer);
202 pc->ResetFilm.connect (bind(&DOMFrame::reset_film_weak, this, _1));
204 _controls = new StandardControls (_overall_panel, _viewer, false);
206 _viewer->set_dcp_decode_reduction (Config::instance()->decode_reduction ());
207 _viewer->set_optimise_for_j2k (true);
208 _viewer->PlaybackPermitted.connect (bind(&DOMFrame::playback_permitted, this));
209 _viewer->TooManyDropped.connect (bind(&DOMFrame::too_many_frames_dropped, this));
210 _info = new PlayerInformation (_overall_panel, _viewer);
211 setup_main_sizer (Config::instance()->player_mode());
213 int accelerators = 12;
215 int accelerators = 11;
218 _stress.setup (this, _controls);
220 std::vector<wxAcceleratorEntry> accel(accelerators);
221 accel[0].Set(wxACCEL_NORMAL, WXK_SPACE, ID_start_stop);
222 accel[1].Set(wxACCEL_NORMAL, WXK_LEFT, ID_go_back_frame);
223 accel[2].Set(wxACCEL_NORMAL, WXK_RIGHT, ID_go_forward_frame);
224 accel[3].Set(wxACCEL_SHIFT, WXK_LEFT, ID_go_back_small_amount);
225 accel[4].Set(wxACCEL_SHIFT, WXK_RIGHT, ID_go_forward_small_amount);
226 accel[5].Set(wxACCEL_CTRL, WXK_LEFT, ID_go_back_medium_amount);
227 accel[6].Set(wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_medium_amount);
228 accel[7].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_LEFT, ID_go_back_large_amount);
229 accel[8].Set(wxACCEL_SHIFT | wxACCEL_CTRL, WXK_RIGHT, ID_go_forward_large_amount);
230 accel[9].Set(wxACCEL_NORMAL, WXK_HOME, ID_go_to_start);
231 accel[10].Set(wxACCEL_NORMAL, WXK_END, ID_go_to_end);
233 accel[11].Set(wxACCEL_CTRL, static_cast<int>('W'), ID_file_close);
235 wxAcceleratorTable accel_table (accelerators, accel.data());
236 SetAcceleratorTable (accel_table);
238 Bind (wxEVT_MENU, boost::bind(&DOMFrame::start_stop_pressed, this), ID_start_stop);
239 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_back_frame, this), ID_go_back_frame);
240 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_forward_frame, this), ID_go_forward_frame);
241 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -60), ID_go_back_small_amount);
242 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 60), ID_go_forward_small_amount);
243 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -600), ID_go_back_medium_amount);
244 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 600), ID_go_forward_medium_amount);
245 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, -3600), ID_go_back_large_amount);
246 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_seconds, this, 3600), ID_go_forward_large_amount);
247 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_start, this), ID_go_to_start);
248 Bind (wxEVT_MENU, boost::bind(&DOMFrame::go_to_end, this), ID_go_to_end);
252 UpdateChecker::instance()->StateChanged.connect (boost::bind(&DOMFrame::update_checker_state_changed, this));
255 _stress.LoadDCP.connect (boost::bind(&DOMFrame::load_dcp, this, _1));
260 /* It's important that this is stopped before our frame starts destroying its children,
261 * otherwise UI elements that it depends on will disappear from under it.
266 void setup_main_sizer (Config::PlayerMode mode)
268 _main_sizer->Detach (_viewer->panel());
269 _main_sizer->Detach (_controls);
270 _main_sizer->Detach (_info);
271 if (mode != Config::PLAYER_MODE_DUAL) {
272 _main_sizer->Add (_viewer->panel(), 1, wxEXPAND);
274 _main_sizer->Add (_controls, mode == Config::PLAYER_MODE_DUAL ? 1 : 0, wxEXPAND | wxALL, 6);
275 _main_sizer->Add (_info, 0, wxEXPAND | wxALL, 6);
276 _overall_panel->SetSizer (_main_sizer);
277 _overall_panel->Layout ();
280 bool playback_permitted ()
282 if (!_film || !Config::instance()->respect_kdm_validity_periods()) {
287 for (auto i: _film->content()) {
288 auto d = dynamic_pointer_cast<DCPContent>(i);
289 if (d && !d->kdm_timing_window_valid()) {
295 error_dialog (this, _("The KDM does not allow playback of this content at this time."));
302 void too_many_frames_dropped ()
304 if (!Config::instance()->nagged(Config::NAG_TOO_MANY_DROPPED_FRAMES)) {
308 NagDialog::maybe_nag (
310 Config::NAG_TOO_MANY_DROPPED_FRAMES,
311 _(wxS("The player is dropping a lot of frames, so playback may not be accurate.\n\n"
312 "<b>This does not necessarily mean that the DCP you are playing is defective!</b>\n\n"
313 "You may be able to improve player performance by:\n"
314 "• choosing 'decode at half resolution' or 'decode at quarter resolution' from the View menu\n"
315 "• using a more powerful computer.\n"
320 void set_decode_reduction (optional<int> reduction)
322 _viewer->set_dcp_decode_reduction (reduction);
323 _info->triggered_update ();
324 Config::instance()->set_decode_reduction (reduction);
327 void load_dcp (boost::filesystem::path dir)
329 DCPOMATIC_ASSERT (_film);
333 _stress.set_suspended (true);
335 auto dcp = make_shared<DCPContent>(dir);
336 auto job = make_shared<ExamineContentJob>(_film, dcp);
337 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
338 JobManager::instance()->add (job);
339 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
340 if (!ok || !report_errors_from_last_job(this)) {
343 Config::instance()->add_to_player_history (dir);
344 } catch (ProjectFolderError &) {
347 wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())),
349 "This looks like a DCP-o-matic project folder, which cannot be loaded into the player. "
350 "Choose the DCP directory inside the DCP-o-matic project folder if that's what you want to play."
353 } catch (dcp::ReadError& e) {
354 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
355 } catch (DCPError& e) {
356 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
360 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
362 auto job = weak_job.lock ();
363 if (!job || !job->finished_ok()) {
367 auto content = weak_content.lock ();
372 _film->add_content (content);
373 _stress.set_suspended (false);
376 void reset_film_weak (weak_ptr<Film> weak_film)
378 auto film = weak_film.lock ();
384 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
387 _film->set_tolerant (true);
388 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
389 _viewer->set_film (_film);
390 _controls->set_film (_film);
391 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
392 _info->triggered_update ();
395 void film_changed (ChangeType type, Film::Property property)
397 if (type != ChangeType::DONE || property != Film::Property::CONTENT) {
401 if (_viewer->playing ()) {
405 /* Start off as Flat */
406 _film->set_container (Ratio::from_id("185"));
408 for (auto i: _film->content()) {
409 auto dcp = dynamic_pointer_cast<DCPContent>(i);
411 for (auto j: i->text) {
416 auto const r = Ratio::nearest_from_ratio(i->video->size().ratio());
417 if (r->id() == "239") {
418 /* Any scope content means we use scope */
419 _film->set_container(r);
423 /* Any 3D content means we use 3D mode */
424 if (i->video && i->video->frame_type() != VideoFrameType::TWO_D) {
425 _film->set_three_d (true);
429 _viewer->seek (DCPTime(), true);
430 _info->triggered_update ();
432 set_menu_sensitivity ();
434 auto old = _cpl_menu->GetMenuItems();
435 for (auto const& i: old) {
436 _cpl_menu->Remove (i);
439 if (_film->content().size() == 1) {
440 /* Offer a CPL menu */
441 auto first = dynamic_pointer_cast<DCPContent>(_film->content().front());
443 int id = ID_view_cpl;
444 for (auto i: dcp::find_and_resolve_cpls(first->directories(), true)) {
445 auto j = _cpl_menu->AppendRadioItem(
447 wxString::Format("%s (%s)", std_to_wx(i->annotation_text().get_value_or("")).data(), std_to_wx(i->id()).data())
449 j->Check(!first->cpl() || i->id() == *first->cpl());
456 void load_stress_script (boost::filesystem::path path)
458 _stress.load_script (path);
463 void examine_content ()
465 DCPOMATIC_ASSERT (_film);
466 auto dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
467 DCPOMATIC_ASSERT (dcp);
468 dcp->examine (_film, shared_ptr<Job>());
470 /* Examining content re-creates the TextContent objects, so we must re-enable them */
471 for (auto i: dcp->text) {
476 bool report_errors_from_last_job (wxWindow* parent) const
478 auto jm = JobManager::instance ();
480 DCPOMATIC_ASSERT (!jm->get().empty());
482 auto last = jm->get().back();
483 if (last->finished_in_error()) {
484 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()));
491 void setup_menu (wxMenuBar* m)
493 _file_menu = new wxMenu;
494 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
495 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
496 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
497 _file_menu->AppendSeparator ();
498 _file_save_frame = _file_menu->Append (ID_file_save_frame, _("&Save frame to file...\tCtrl-S"));
500 _history_position = _file_menu->GetMenuItems().GetCount();
502 _file_menu->AppendSeparator ();
503 _file_menu->Append (ID_file_close, _("&Close"));
504 _file_menu->AppendSeparator ();
507 _file_menu->Append (wxID_EXIT, _("&Exit"));
509 _file_menu->Append (wxID_EXIT, _("&Quit"));
513 auto prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
515 auto edit = new wxMenu;
516 auto prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
519 prefs->Enable (Config::instance()->have_write_permission());
521 _cpl_menu = new wxMenu;
523 auto view = new wxMenu;
524 auto c = Config::instance()->decode_reduction();
525 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
526 view->AppendSeparator();
527 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
528 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
530 view->AppendSeparator();
531 view->Append(ID_view_closed_captions, _("Closed captions..."));
532 view->AppendSeparator();
533 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
534 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
535 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
536 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
538 auto tools = new wxMenu;
539 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP..."));
540 tools->AppendSeparator ();
541 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
542 tools->Append (ID_tools_timing, _("Timing..."));
543 tools->Append (ID_tools_system_information, _("System information..."));
545 auto help = new wxMenu;
547 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
549 help->Append (wxID_ABOUT, _("About"));
551 help->Append (ID_help_report_a_problem, _("Report a problem..."));
553 m->Append (_file_menu, _("&File"));
555 m->Append (edit, _("&Edit"));
557 m->Append (view, _("&View"));
558 m->Append (tools, _("&Tools"));
559 m->Append (help, _("&Help"));
564 auto d = wxStandardPaths::Get().GetDocumentsDir();
565 if (Config::instance()->last_player_load_directory()) {
566 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
569 auto c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
574 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
575 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
582 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
584 Config::instance()->set_last_player_load_directory (dcp.parent_path());
592 auto c = new wxDirDialog (
594 _("Select DCP to open as OV"),
595 wxStandardPaths::Get().GetDocumentsDir(),
596 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
602 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
603 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
610 DCPOMATIC_ASSERT (_film);
611 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
612 DCPOMATIC_ASSERT (dcp);
613 dcp->add_ov (wx_to_std(c->GetPath()));
614 JobManager::instance()->add(make_shared<ExamineContentJob>(_film, dcp));
615 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
616 if (!ok || !report_errors_from_last_job(this)) {
619 for (auto i: dcp->text) {
623 auto const r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
625 _film->set_container(r);
631 _info->triggered_update ();
636 auto d = new wxFileDialog (this, _("Select KDM"));
638 if (d->ShowModal() == wxID_OK) {
639 DCPOMATIC_ASSERT (_film);
640 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
641 DCPOMATIC_ASSERT (dcp);
644 _viewer->set_coalesce_player_changes (true);
645 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
647 _viewer->set_coalesce_player_changes (false);
649 } catch (exception& e) {
650 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
657 _info->triggered_update ();
660 void file_save_frame ()
662 wxFileDialog dialog (this, _("Save frame to file"), "", "", "PNG files (*.png)|*.png|JPEG files (*.jpg,*.jpeg)|*.jpg,*.jpeg", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
663 if (dialog.ShowModal() == wxID_CANCEL) {
667 auto path = boost::filesystem::path (wx_to_std(dialog.GetPath()));
669 auto player = make_shared<Player>(_film, Image::Alignment::PADDED);
670 player->seek (_viewer->position(), true);
673 player->Video.connect ([path, &done, this](shared_ptr<PlayerVideo> video, DCPTime) {
674 auto ext = boost::algorithm::to_lower_copy(path.extension().string());
676 auto image = video->image(boost::bind(PlayerVideo::force, AV_PIX_FMT_RGBA), VideoRange::FULL, false);
677 image_as_png(image).write(path);
678 } else if (ext == ".jpg" || ext == ".jpeg") {
679 auto image = video->image(boost::bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, false);
680 image_as_jpeg(image, 80).write(path);
682 error_dialog (this, _(wxString::Format("Unrecognised file extension %s (use .jpg, .jpeg or .png)", std_to_wx(ext))));
688 while (!done && tries_left >= 0) {
693 DCPOMATIC_ASSERT (tries_left >= 0);
696 void file_history (wxCommandEvent& event)
698 auto history = Config::instance()->player_history ();
699 int n = event.GetId() - ID_file_history;
700 if (n >= 0 && n < static_cast<int> (history.size ())) {
702 load_dcp (history[n]);
703 } catch (exception& e) {
704 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
712 _info->triggered_update ();
713 set_menu_sensitivity ();
721 void edit_preferences ()
723 if (!Config::instance()->have_write_permission()) {
727 if (!_config_dialog) {
728 _config_dialog = create_player_config_dialog ();
730 _config_dialog->Show (this);
733 void view_cpl (wxCommandEvent& ev)
735 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
736 DCPOMATIC_ASSERT (dcp);
737 auto cpls = dcp::find_and_resolve_cpls (dcp->directories(), true);
738 int id = ev.GetId() - ID_view_cpl;
739 DCPOMATIC_ASSERT (id >= 0);
740 DCPOMATIC_ASSERT (id < int(cpls.size()));
741 auto i = cpls.begin();
747 _viewer->set_coalesce_player_changes (true);
748 dcp->set_cpl ((*i)->id());
750 _viewer->set_coalesce_player_changes (false);
752 _info->triggered_update ();
755 void view_full_screen ()
757 if (_mode == Config::PLAYER_MODE_FULL) {
758 _mode = Config::PLAYER_MODE_WINDOW;
760 _mode = Config::PLAYER_MODE_FULL;
766 void view_dual_screen ()
768 if (_mode == Config::PLAYER_MODE_DUAL) {
769 _mode = Config::PLAYER_MODE_WINDOW;
771 _mode = Config::PLAYER_MODE_DUAL;
779 if (_view_full_screen) {
780 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
782 if (_view_dual_screen) {
783 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
789 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
790 _info->Show (_mode != Config::PLAYER_MODE_FULL);
791 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
792 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
793 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
795 if (_mode == Config::PLAYER_MODE_DUAL) {
796 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
797 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
798 _dual_screen->ShowFullScreen (true);
799 _viewer->panel()->Reparent (_dual_screen);
800 _dual_screen->Show ();
801 if (wxDisplay::GetCount() > 1) {
802 switch (Config::instance()->image_display()) {
804 _dual_screen->Move (0, 0);
805 Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
808 _dual_screen->Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
809 // (0, 0) doesn't seem to work for some strange reason
816 _viewer->panel()->Reparent (_overall_panel);
817 _dual_screen->Destroy ();
822 setup_main_sizer (_mode);
825 void view_closed_captions ()
827 _viewer->show_closed_captions ();
832 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
833 DCPOMATIC_ASSERT (dcp);
835 auto job = make_shared<VerifyDCPJob>(dcp->directories());
836 auto progress = new VerifyDCPProgressDialog(this, _("DCP-o-matic Player"));
837 bool const completed = progress->run (job);
838 progress->Destroy ();
843 auto d = new VerifyDCPDialog (this, job);
848 void tools_check_for_updates ()
850 UpdateChecker::instance()->run ();
851 _update_news_requested = true;
856 auto d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
861 void tools_system_information ()
863 if (!_system_information_dialog) {
864 _system_information_dialog = new SystemInformationDialog (this, _viewer);
867 _system_information_dialog->Show ();
872 auto d = new AboutDialog (this);
877 void help_report_a_problem ()
879 auto d = new ReportProblemDialog (this);
880 if (d->ShowModal () == wxID_OK) {
886 void update_checker_state_changed ()
888 auto uc = UpdateChecker::instance ();
890 bool const announce =
891 _update_news_requested ||
892 (uc->stable() && Config::instance()->check_for_updates()) ||
893 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
895 _update_news_requested = false;
901 if (uc->state() == UpdateChecker::State::YES) {
902 auto dialog = new UpdateDialog (this, uc->stable (), uc->test ());
903 dialog->ShowModal ();
905 } else if (uc->state() == UpdateChecker::State::FAILED) {
906 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
908 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
911 _update_news_requested = false;
914 void config_changed (Config::Property prop)
916 /* Instantly save any config changes when using the player GUI */
918 Config::instance()->write_config();
919 } catch (FileError& e) {
920 if (prop != Config::HISTORY) {
924 _("Could not write to config file at %s. Your changes have not been saved."),
925 std_to_wx(e.file().string())
929 } catch (exception& e) {
932 _("Could not write to config file. Your changes have not been saved.")
936 update_from_config (prop);
939 void update_from_config (Config::Property prop)
941 for (int i = 0; i < _history_items; ++i) {
942 delete _file_menu->Remove (ID_file_history + i);
945 if (_history_separator) {
946 _file_menu->Remove (_history_separator);
948 delete _history_separator;
949 _history_separator = nullptr;
951 int pos = _history_position;
953 /* Clear out non-existant history items before we re-build the menu */
954 Config::instance()->clean_player_history ();
955 auto history = Config::instance()->player_history ();
957 if (!history.empty ()) {
958 _history_separator = _file_menu->InsertSeparator (pos++);
961 for (size_t i = 0; i < history.size(); ++i) {
964 s = String::compose ("&%1 %2", i + 1, history[i].string());
966 s = history[i].string();
968 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
971 _history_items = history.size ();
973 if (prop == Config::PLAYER_DEBUG_LOG) {
974 auto p = Config::instance()->player_debug_log_file();
976 dcpomatic_log = make_shared<FileLog>(*p);
978 dcpomatic_log = make_shared<NullLog>();
980 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
984 void set_menu_sensitivity ()
986 _tools_verify->Enable (static_cast<bool>(_film));
987 _file_add_ov->Enable (static_cast<bool>(_film));
988 _file_add_kdm->Enable (static_cast<bool>(_film));
989 _file_save_frame->Enable (static_cast<bool>(_film));
990 _view_cpl->Enable (static_cast<bool>(_film));
993 void start_stop_pressed ()
995 if (_viewer->playing()) {
1002 void go_back_frame ()
1004 _viewer->seek_by (-_viewer->one_video_frame(), true);
1007 void go_forward_frame ()
1009 _viewer->seek_by (_viewer->one_video_frame(), true);
1012 void go_seconds (int s)
1014 _viewer->seek_by (DCPTime::from_seconds(s), true);
1019 _viewer->seek (DCPTime(), true);
1024 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
1027 wxFrame* _dual_screen = nullptr;
1028 bool _update_news_requested = false;
1029 PlayerInformation* _info = nullptr;
1030 Config::PlayerMode _mode;
1031 wxPreferencesEditor* _config_dialog = nullptr;
1032 wxPanel* _overall_panel = nullptr;
1033 wxMenu* _file_menu = nullptr;
1034 wxMenuItem* _view_cpl = nullptr;
1035 wxMenu* _cpl_menu = nullptr;
1036 int _history_items = 0;
1037 int _history_position = 0;
1038 wxMenuItem* _history_separator = nullptr;
1039 shared_ptr<FilmViewer> _viewer;
1040 Controls* _controls;
1041 SystemInformationDialog* _system_information_dialog = nullptr;
1042 std::shared_ptr<Film> _film;
1043 boost::signals2::scoped_connection _config_changed_connection;
1044 boost::signals2::scoped_connection _examine_job_connection;
1045 wxMenuItem* _file_add_ov = nullptr;
1046 wxMenuItem* _file_add_kdm = nullptr;
1047 wxMenuItem* _file_save_frame = nullptr;
1048 wxMenuItem* _tools_verify = nullptr;
1049 wxMenuItem* _view_full_screen = nullptr;
1050 wxMenuItem* _view_dual_screen = nullptr;
1051 wxSizer* _main_sizer = nullptr;
1052 PlayerStressTester _stress;
1055 static const wxCmdLineEntryDesc command_line_description[] = {
1056 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1057 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1058 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1059 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1062 class PlayServer : public Server
1065 explicit PlayServer (DOMFrame* frame)
1066 : Server (PLAYER_PLAY_PORT)
1070 void handle (shared_ptr<Socket> socket)
1073 int const length = socket->read_uint32 ();
1074 scoped_array<char> buffer (new char[length]);
1075 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1076 string s (buffer.get());
1077 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1078 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1089 * @brief The magic App class for wxWidgets.
1091 class App : public wxApp
1097 #ifdef DCPOMATIC_LINUX
1106 wxSplashScreen* splash = nullptr;
1108 wxInitAllImageHandlers ();
1110 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1111 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1113 splash = maybe_show_splash ();
1115 SetAppName (_("DCP-o-matic Player"));
1117 if (!wxApp::OnInit()) {
1121 #ifdef DCPOMATIC_LINUX
1122 unsetenv ("UBUNTU_MENUPROXY");
1125 #ifdef DCPOMATIC_OSX
1126 make_foreground_application ();
1129 dcpomatic_setup_path_encoding ();
1131 /* Enable i18n; this will create a Config object
1132 to look for a force-configured language. This Config
1133 object will be wrong, however, because dcpomatic_setup
1134 hasn't yet been called and there aren't any filters etc.
1137 dcpomatic_setup_i18n ();
1139 /* Set things up, including filters etc.
1140 which will now be internationalised correctly.
1144 /* Force the configuration to be re-loaded correctly next
1149 signal_manager = new wxSignalManager (this);
1151 _frame = new DOMFrame ();
1152 SetTopWindow (_frame);
1153 _frame->Maximize ();
1161 auto server = new PlayServer (_frame);
1162 new thread (boost::bind (&PlayServer::run, server));
1163 } catch (std::exception& e) {
1164 /* This is not the end of the world; probably a failure to bind the server socket
1165 * because there's already another player running.
1167 LOG_DEBUG_PLAYER ("Failed to start play server (%1)", e.what());
1170 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1172 _frame->load_dcp (_dcp_to_load);
1173 } catch (exception& e) {
1174 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1180 _frame->load_stress_script (*_stress);
1181 } catch (exception& e) {
1182 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1186 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1188 if (Config::instance()->check_for_updates ()) {
1189 UpdateChecker::instance()->run ();
1192 catch (exception& e)
1197 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1203 void OnInitCmdLine (wxCmdLineParser& parser)
1205 parser.SetDesc (command_line_description);
1206 parser.SetSwitchChars (wxT ("-"));
1209 bool OnCmdLineParsed (wxCmdLineParser& parser)
1211 if (parser.GetParamCount() > 0) {
1212 _dcp_to_load = wx_to_std (parser.GetParam (0));
1216 if (parser.Found("c", &config)) {
1217 Config::override_path = wx_to_std (config);
1220 if (parser.Found("s", &stress)) {
1221 _stress = wx_to_std (stress);
1227 void report_exception ()
1231 } catch (FileError& e) {
1235 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1236 std_to_wx (e.what()),
1237 std_to_wx (e.file().string().c_str ())
1240 } catch (exception& e) {
1244 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1245 std_to_wx (e.what ())
1249 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1253 /* An unhandled exception has occurred inside the main event loop */
1254 bool OnExceptionInMainLoop ()
1256 report_exception ();
1257 /* This will terminate the program */
1261 void OnUnhandledException ()
1263 report_exception ();
1268 signal_manager->ui_idle ();
1271 void config_failed_to_load ()
1273 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1276 void config_warning (string m)
1278 message_dialog (_frame, std_to_wx (m));
1281 DOMFrame* _frame = nullptr;
1282 string _dcp_to_load;
1283 boost::optional<string> _stress;