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);
334 auto dcp = make_shared<DCPContent>(dir);
335 auto job = make_shared<ExamineContentJob>(_film, dcp);
336 _examine_job_connection = job->Finished.connect(bind(&DOMFrame::add_dcp_to_film, this, weak_ptr<Job>(job), weak_ptr<Content>(dcp)));
337 JobManager::instance()->add (job);
338 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
339 if (!ok || !report_errors_from_last_job(this)) {
342 Config::instance()->add_to_player_history (dir);
343 } catch (ProjectFolderError &) {
346 wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())),
348 "This looks like a DCP-o-matic project folder, which cannot be loaded into the player. "
349 "Choose the DCP directory inside the DCP-o-matic project folder if that's what you want to play."
352 } catch (dcp::ReadError& e) {
353 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
354 } catch (DCPError& e) {
355 error_dialog (this, wxString::Format(_("Could not load a DCP from %s"), std_to_wx(dir.string())), std_to_wx(e.what()));
359 void add_dcp_to_film (weak_ptr<Job> weak_job, weak_ptr<Content> weak_content)
361 auto job = weak_job.lock ();
362 if (!job || !job->finished_ok()) {
366 auto content = weak_content.lock ();
371 _film->add_content (content);
372 _stress.set_suspended (false);
375 void reset_film_weak (weak_ptr<Film> weak_film)
377 auto film = weak_film.lock ();
383 void reset_film (shared_ptr<Film> film = shared_ptr<Film>(new Film(optional<boost::filesystem::path>())))
386 _film->set_tolerant (true);
387 _film->set_audio_channels (MAX_DCP_AUDIO_CHANNELS);
388 _viewer->set_film (_film);
389 _controls->set_film (_film);
390 _film->Change.connect (bind(&DOMFrame::film_changed, this, _1, _2));
391 _info->triggered_update ();
394 void film_changed (ChangeType type, Film::Property property)
396 if (type != ChangeType::DONE || property != Film::Property::CONTENT) {
400 if (_viewer->playing ()) {
404 /* Start off as Flat */
405 _film->set_container (Ratio::from_id("185"));
407 for (auto i: _film->content()) {
408 auto dcp = dynamic_pointer_cast<DCPContent>(i);
410 for (auto j: i->text) {
415 auto const r = Ratio::nearest_from_ratio(i->video->size().ratio());
416 if (r->id() == "239") {
417 /* Any scope content means we use scope */
418 _film->set_container(r);
422 /* Any 3D content means we use 3D mode */
423 if (i->video && i->video->frame_type() != VideoFrameType::TWO_D) {
424 _film->set_three_d (true);
428 _viewer->seek (DCPTime(), true);
429 _info->triggered_update ();
431 set_menu_sensitivity ();
433 auto old = _cpl_menu->GetMenuItems();
434 for (auto const& i: old) {
435 _cpl_menu->Remove (i);
438 if (_film->content().size() == 1) {
439 /* Offer a CPL menu */
440 auto first = dynamic_pointer_cast<DCPContent>(_film->content().front());
442 int id = ID_view_cpl;
443 for (auto i: dcp::find_and_resolve_cpls(first->directories(), true)) {
444 auto j = _cpl_menu->AppendRadioItem(
446 wxString::Format("%s (%s)", std_to_wx(i->annotation_text().get_value_or("")).data(), std_to_wx(i->id()).data())
448 j->Check(!first->cpl() || i->id() == *first->cpl());
455 void load_stress_script (boost::filesystem::path path)
457 _stress.load_script (path);
462 void examine_content ()
464 DCPOMATIC_ASSERT (_film);
465 auto dcp = dynamic_pointer_cast<DCPContent>(_film->content().front());
466 DCPOMATIC_ASSERT (dcp);
467 dcp->examine (_film, shared_ptr<Job>());
469 /* Examining content re-creates the TextContent objects, so we must re-enable them */
470 for (auto i: dcp->text) {
475 bool report_errors_from_last_job (wxWindow* parent) const
477 auto jm = JobManager::instance ();
479 DCPOMATIC_ASSERT (!jm->get().empty());
481 auto last = jm->get().back();
482 if (last->finished_in_error()) {
483 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()));
490 void setup_menu (wxMenuBar* m)
492 _file_menu = new wxMenu;
493 _file_menu->Append (ID_file_open, _("&Open...\tCtrl-O"));
494 _file_add_ov = _file_menu->Append (ID_file_add_ov, _("&Add OV..."));
495 _file_add_kdm = _file_menu->Append (ID_file_add_kdm, _("Add &KDM..."));
496 _file_menu->AppendSeparator ();
497 _file_save_frame = _file_menu->Append (ID_file_save_frame, _("&Save frame to file...\tCtrl-S"));
499 _history_position = _file_menu->GetMenuItems().GetCount();
501 _file_menu->AppendSeparator ();
502 _file_menu->Append (ID_file_close, _("&Close"));
503 _file_menu->AppendSeparator ();
506 _file_menu->Append (wxID_EXIT, _("&Exit"));
508 _file_menu->Append (wxID_EXIT, _("&Quit"));
512 auto prefs = _file_menu->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
514 auto edit = new wxMenu;
515 auto prefs = edit->Append (wxID_PREFERENCES, _("&Preferences...\tCtrl-P"));
518 prefs->Enable (Config::instance()->have_write_permission());
520 _cpl_menu = new wxMenu;
522 auto view = new wxMenu;
523 auto c = Config::instance()->decode_reduction();
524 _view_cpl = view->Append(ID_view_cpl, _("CPL"), _cpl_menu);
525 view->AppendSeparator();
526 _view_full_screen = view->AppendCheckItem(ID_view_full_screen, _("Full screen\tF11"));
527 _view_dual_screen = view->AppendCheckItem(ID_view_dual_screen, _("Dual screen\tShift+F11"));
529 view->AppendSeparator();
530 view->Append(ID_view_closed_captions, _("Closed captions..."));
531 view->AppendSeparator();
532 view->AppendRadioItem(ID_view_scale_appropriate, _("Set decode resolution to match display"))->Check(!static_cast<bool>(c));
533 view->AppendRadioItem(ID_view_scale_full, _("Decode at full resolution"))->Check(c && c.get() == 0);
534 view->AppendRadioItem(ID_view_scale_half, _("Decode at half resolution"))->Check(c && c.get() == 1);
535 view->AppendRadioItem(ID_view_scale_quarter, _("Decode at quarter resolution"))->Check(c && c.get() == 2);
537 auto tools = new wxMenu;
538 _tools_verify = tools->Append (ID_tools_verify, _("Verify DCP..."));
539 tools->AppendSeparator ();
540 tools->Append (ID_tools_check_for_updates, _("Check for updates"));
541 tools->Append (ID_tools_timing, _("Timing..."));
542 tools->Append (ID_tools_system_information, _("System information..."));
544 auto help = new wxMenu;
546 help->Append (wxID_ABOUT, _("About DCP-o-matic"));
548 help->Append (wxID_ABOUT, _("About"));
550 help->Append (ID_help_report_a_problem, _("Report a problem..."));
552 m->Append (_file_menu, _("&File"));
554 m->Append (edit, _("&Edit"));
556 m->Append (view, _("&View"));
557 m->Append (tools, _("&Tools"));
558 m->Append (help, _("&Help"));
563 auto d = wxStandardPaths::Get().GetDocumentsDir();
564 if (Config::instance()->last_player_load_directory()) {
565 d = std_to_wx (Config::instance()->last_player_load_directory()->string());
568 auto c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
573 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
574 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
581 boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
583 Config::instance()->set_last_player_load_directory (dcp.parent_path());
591 auto c = new wxDirDialog (
593 _("Select DCP to open as OV"),
594 wxStandardPaths::Get().GetDocumentsDir(),
595 wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
601 if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
602 error_dialog (this, _("You did not select a folder. Make sure that you select a folder before clicking Open."));
609 DCPOMATIC_ASSERT (_film);
610 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
611 DCPOMATIC_ASSERT (dcp);
612 dcp->add_ov (wx_to_std(c->GetPath()));
613 JobManager::instance()->add(make_shared<ExamineContentJob>(_film, dcp));
614 bool const ok = display_progress (_("DCP-o-matic Player"), _("Loading content"));
615 if (!ok || !report_errors_from_last_job(this)) {
618 for (auto i: dcp->text) {
622 auto const r = Ratio::nearest_from_ratio(dcp->video->size().ratio());
624 _film->set_container(r);
630 _info->triggered_update ();
635 auto d = new wxFileDialog (this, _("Select KDM"));
637 if (d->ShowModal() == wxID_OK) {
638 DCPOMATIC_ASSERT (_film);
639 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
640 DCPOMATIC_ASSERT (dcp);
643 _viewer->set_coalesce_player_changes (true);
644 dcp->add_kdm (dcp::EncryptedKDM(dcp::file_to_string(wx_to_std(d->GetPath()), MAX_KDM_SIZE)));
646 _viewer->set_coalesce_player_changes (false);
648 } catch (exception& e) {
649 error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
656 _info->triggered_update ();
659 void file_save_frame ()
661 wxFileDialog dialog (this, _("Save frame to file"), "", "", "PNG files (*.png)|*.png|JPEG files (*.jpg,*.jpeg)|*.jpg,*.jpeg", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
662 if (dialog.ShowModal() == wxID_CANCEL) {
666 auto path = boost::filesystem::path (wx_to_std(dialog.GetPath()));
668 auto player = make_shared<Player>(_film, Image::Alignment::PADDED);
669 player->seek (_viewer->position(), true);
672 player->Video.connect ([path, &done, this](shared_ptr<PlayerVideo> video, DCPTime) {
673 auto ext = boost::algorithm::to_lower_copy(path.extension().string());
675 auto image = video->image(boost::bind(PlayerVideo::force, AV_PIX_FMT_RGBA), VideoRange::FULL, false);
676 image_as_png(image).write(path);
677 } else if (ext == ".jpg" || ext == ".jpeg") {
678 auto image = video->image(boost::bind(PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, false);
679 image_as_jpeg(image, 80).write(path);
681 error_dialog (this, _(wxString::Format("Unrecognised file extension %s (use .jpg, .jpeg or .png)", std_to_wx(ext))));
687 while (!done && tries_left >= 0) {
692 DCPOMATIC_ASSERT (tries_left >= 0);
695 void file_history (wxCommandEvent& event)
697 auto history = Config::instance()->player_history ();
698 int n = event.GetId() - ID_file_history;
699 if (n >= 0 && n < static_cast<int> (history.size ())) {
701 load_dcp (history[n]);
702 } catch (exception& e) {
703 error_dialog (0, std_to_wx(String::compose(wx_to_std(_("Could not load DCP %1.")), history[n])), std_to_wx(e.what()));
711 _info->triggered_update ();
712 set_menu_sensitivity ();
720 void edit_preferences ()
722 if (!Config::instance()->have_write_permission()) {
726 if (!_config_dialog) {
727 _config_dialog = create_player_config_dialog ();
729 _config_dialog->Show (this);
732 void view_cpl (wxCommandEvent& ev)
734 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
735 DCPOMATIC_ASSERT (dcp);
736 auto cpls = dcp::find_and_resolve_cpls (dcp->directories(), true);
737 int id = ev.GetId() - ID_view_cpl;
738 DCPOMATIC_ASSERT (id >= 0);
739 DCPOMATIC_ASSERT (id < int(cpls.size()));
740 auto i = cpls.begin();
746 _viewer->set_coalesce_player_changes (true);
747 dcp->set_cpl ((*i)->id());
749 _viewer->set_coalesce_player_changes (false);
751 _info->triggered_update ();
754 void view_full_screen ()
756 if (_mode == Config::PLAYER_MODE_FULL) {
757 _mode = Config::PLAYER_MODE_WINDOW;
759 _mode = Config::PLAYER_MODE_FULL;
765 void view_dual_screen ()
767 if (_mode == Config::PLAYER_MODE_DUAL) {
768 _mode = Config::PLAYER_MODE_WINDOW;
770 _mode = Config::PLAYER_MODE_DUAL;
778 if (_view_full_screen) {
779 _view_full_screen->Check (_mode == Config::PLAYER_MODE_FULL);
781 if (_view_dual_screen) {
782 _view_dual_screen->Check (_mode == Config::PLAYER_MODE_DUAL);
788 _controls->Show (_mode != Config::PLAYER_MODE_FULL);
789 _info->Show (_mode != Config::PLAYER_MODE_FULL);
790 _overall_panel->SetBackgroundColour (_mode == Config::PLAYER_MODE_FULL ? wxColour(0, 0, 0) : wxNullColour);
791 ShowFullScreen (_mode == Config::PLAYER_MODE_FULL);
792 _viewer->set_pad_black (_mode != Config::PLAYER_MODE_WINDOW);
794 if (_mode == Config::PLAYER_MODE_DUAL) {
795 _dual_screen = new wxFrame (this, wxID_ANY, wxT(""));
796 _dual_screen->SetBackgroundColour (wxColour(0, 0, 0));
797 _dual_screen->ShowFullScreen (true);
798 _viewer->panel()->Reparent (_dual_screen);
799 _dual_screen->Show ();
800 if (wxDisplay::GetCount() > 1) {
801 switch (Config::instance()->image_display()) {
803 _dual_screen->Move (0, 0);
804 Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
807 _dual_screen->Move (wxDisplay(0U).GetClientArea().GetWidth(), 0);
808 // (0, 0) doesn't seem to work for some strange reason
815 _viewer->panel()->Reparent (_overall_panel);
816 _dual_screen->Destroy ();
821 setup_main_sizer (_mode);
824 void view_closed_captions ()
826 _viewer->show_closed_captions ();
831 auto dcp = std::dynamic_pointer_cast<DCPContent>(_film->content().front());
832 DCPOMATIC_ASSERT (dcp);
834 auto job = make_shared<VerifyDCPJob>(dcp->directories());
835 auto progress = new VerifyDCPProgressDialog(this, _("DCP-o-matic Player"));
836 bool const completed = progress->run (job);
837 progress->Destroy ();
842 auto d = new VerifyDCPDialog (this, job);
847 void tools_check_for_updates ()
849 UpdateChecker::instance()->run ();
850 _update_news_requested = true;
855 auto d = new TimerDisplay (this, _viewer->state_timer(), _viewer->gets());
860 void tools_system_information ()
862 if (!_system_information_dialog) {
863 _system_information_dialog = new SystemInformationDialog (this, _viewer);
866 _system_information_dialog->Show ();
871 auto d = new AboutDialog (this);
876 void help_report_a_problem ()
878 auto d = new ReportProblemDialog (this);
879 if (d->ShowModal () == wxID_OK) {
885 void update_checker_state_changed ()
887 auto uc = UpdateChecker::instance ();
889 bool const announce =
890 _update_news_requested ||
891 (uc->stable() && Config::instance()->check_for_updates()) ||
892 (uc->test() && Config::instance()->check_for_updates() && Config::instance()->check_for_test_updates());
894 _update_news_requested = false;
900 if (uc->state() == UpdateChecker::State::YES) {
901 auto dialog = new UpdateDialog (this, uc->stable (), uc->test ());
902 dialog->ShowModal ();
904 } else if (uc->state() == UpdateChecker::State::FAILED) {
905 error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
907 error_dialog (this, _("There are no new versions of DCP-o-matic available."));
910 _update_news_requested = false;
913 void config_changed (Config::Property prop)
915 /* Instantly save any config changes when using the player GUI */
917 Config::instance()->write_config();
918 } catch (FileError& e) {
919 if (prop != Config::HISTORY) {
923 _("Could not write to config file at %s. Your changes have not been saved."),
924 std_to_wx(e.file().string())
928 } catch (exception& e) {
931 _("Could not write to config file. Your changes have not been saved.")
935 update_from_config (prop);
938 void update_from_config (Config::Property prop)
940 for (int i = 0; i < _history_items; ++i) {
941 delete _file_menu->Remove (ID_file_history + i);
944 if (_history_separator) {
945 _file_menu->Remove (_history_separator);
947 delete _history_separator;
948 _history_separator = nullptr;
950 int pos = _history_position;
952 /* Clear out non-existant history items before we re-build the menu */
953 Config::instance()->clean_player_history ();
954 auto history = Config::instance()->player_history ();
956 if (!history.empty ()) {
957 _history_separator = _file_menu->InsertSeparator (pos++);
960 for (size_t i = 0; i < history.size(); ++i) {
963 s = String::compose ("&%1 %2", i + 1, history[i].string());
965 s = history[i].string();
967 _file_menu->Insert (pos++, ID_file_history + i, std_to_wx (s));
970 _history_items = history.size ();
972 if (prop == Config::PLAYER_DEBUG_LOG) {
973 auto p = Config::instance()->player_debug_log_file();
975 dcpomatic_log = make_shared<FileLog>(*p);
977 dcpomatic_log = make_shared<NullLog>();
979 dcpomatic_log->set_types (LogEntry::TYPE_GENERAL | LogEntry::TYPE_WARNING | LogEntry::TYPE_ERROR | LogEntry::TYPE_DEBUG_VIDEO_VIEW);
983 void set_menu_sensitivity ()
985 _tools_verify->Enable (static_cast<bool>(_film));
986 _file_add_ov->Enable (static_cast<bool>(_film));
987 _file_add_kdm->Enable (static_cast<bool>(_film));
988 _file_save_frame->Enable (static_cast<bool>(_film));
989 _view_cpl->Enable (static_cast<bool>(_film));
992 void start_stop_pressed ()
994 if (_viewer->playing()) {
1001 void go_back_frame ()
1003 _viewer->seek_by (-_viewer->one_video_frame(), true);
1006 void go_forward_frame ()
1008 _viewer->seek_by (_viewer->one_video_frame(), true);
1011 void go_seconds (int s)
1013 _viewer->seek_by (DCPTime::from_seconds(s), true);
1018 _viewer->seek (DCPTime(), true);
1023 _viewer->seek (_film->length() - _viewer->one_video_frame(), true);
1026 wxFrame* _dual_screen = nullptr;
1027 bool _update_news_requested = false;
1028 PlayerInformation* _info = nullptr;
1029 Config::PlayerMode _mode;
1030 wxPreferencesEditor* _config_dialog = nullptr;
1031 wxPanel* _overall_panel = nullptr;
1032 wxMenu* _file_menu = nullptr;
1033 wxMenuItem* _view_cpl = nullptr;
1034 wxMenu* _cpl_menu = nullptr;
1035 int _history_items = 0;
1036 int _history_position = 0;
1037 wxMenuItem* _history_separator = nullptr;
1038 shared_ptr<FilmViewer> _viewer;
1039 Controls* _controls;
1040 SystemInformationDialog* _system_information_dialog = nullptr;
1041 std::shared_ptr<Film> _film;
1042 boost::signals2::scoped_connection _config_changed_connection;
1043 boost::signals2::scoped_connection _examine_job_connection;
1044 wxMenuItem* _file_add_ov = nullptr;
1045 wxMenuItem* _file_add_kdm = nullptr;
1046 wxMenuItem* _file_save_frame = nullptr;
1047 wxMenuItem* _tools_verify = nullptr;
1048 wxMenuItem* _view_full_screen = nullptr;
1049 wxMenuItem* _view_dual_screen = nullptr;
1050 wxSizer* _main_sizer = nullptr;
1051 PlayerStressTester _stress;
1054 static const wxCmdLineEntryDesc command_line_description[] = {
1055 { wxCMD_LINE_PARAM, 0, 0, "DCP to load or create", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1056 { wxCMD_LINE_OPTION, "c", "config", "Directory containing config.xml", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1057 { wxCMD_LINE_OPTION, "s", "stress", "File containing description of stress test", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL },
1058 { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
1061 class PlayServer : public Server
1064 explicit PlayServer (DOMFrame* frame)
1065 : Server (PLAYER_PLAY_PORT)
1069 void handle (shared_ptr<Socket> socket)
1072 int const length = socket->read_uint32 ();
1073 scoped_array<char> buffer (new char[length]);
1074 socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
1075 string s (buffer.get());
1076 signal_manager->when_idle (bind (&DOMFrame::load_dcp, _frame, s));
1077 socket->write (reinterpret_cast<uint8_t const *> ("OK"), 3);
1088 * @brief The magic App class for wxWidgets.
1090 class App : public wxApp
1096 #ifdef DCPOMATIC_LINUX
1105 wxSplashScreen* splash = nullptr;
1107 wxInitAllImageHandlers ();
1109 Config::FailedToLoad.connect (boost::bind (&App::config_failed_to_load, this));
1110 Config::Warning.connect (boost::bind (&App::config_warning, this, _1));
1112 splash = maybe_show_splash ();
1114 SetAppName (_("DCP-o-matic Player"));
1116 if (!wxApp::OnInit()) {
1120 #ifdef DCPOMATIC_LINUX
1121 unsetenv ("UBUNTU_MENUPROXY");
1124 #ifdef DCPOMATIC_OSX
1125 make_foreground_application ();
1128 dcpomatic_setup_path_encoding ();
1130 /* Enable i18n; this will create a Config object
1131 to look for a force-configured language. This Config
1132 object will be wrong, however, because dcpomatic_setup
1133 hasn't yet been called and there aren't any filters etc.
1136 dcpomatic_setup_i18n ();
1138 /* Set things up, including filters etc.
1139 which will now be internationalised correctly.
1143 /* Force the configuration to be re-loaded correctly next
1148 signal_manager = new wxSignalManager (this);
1150 _frame = new DOMFrame ();
1151 SetTopWindow (_frame);
1152 _frame->Maximize ();
1160 auto server = new PlayServer (_frame);
1161 new thread (boost::bind (&PlayServer::run, server));
1162 } catch (std::exception& e) {
1163 /* This is not the end of the world; probably a failure to bind the server socket
1164 * because there's already another player running.
1166 LOG_DEBUG_PLAYER ("Failed to start play server (%1)", e.what());
1169 if (!_dcp_to_load.empty() && boost::filesystem::is_directory (_dcp_to_load)) {
1171 _frame->load_dcp (_dcp_to_load);
1172 } catch (exception& e) {
1173 error_dialog (0, std_to_wx (String::compose (wx_to_std (_("Could not load DCP %1.")), _dcp_to_load)), std_to_wx(e.what()));
1179 _frame->load_stress_script (*_stress);
1180 } catch (exception& e) {
1181 error_dialog (0, wxString::Format("Could not load stress test file %s", std_to_wx(*_stress)));
1185 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
1187 if (Config::instance()->check_for_updates ()) {
1188 UpdateChecker::instance()->run ();
1191 catch (exception& e)
1196 error_dialog (0, _("DCP-o-matic Player could not start."), std_to_wx(e.what()));
1202 void OnInitCmdLine (wxCmdLineParser& parser)
1204 parser.SetDesc (command_line_description);
1205 parser.SetSwitchChars (wxT ("-"));
1208 bool OnCmdLineParsed (wxCmdLineParser& parser)
1210 if (parser.GetParamCount() > 0) {
1211 _dcp_to_load = wx_to_std (parser.GetParam (0));
1215 if (parser.Found("c", &config)) {
1216 Config::override_path = wx_to_std (config);
1219 if (parser.Found("s", &stress)) {
1220 _stress = wx_to_std (stress);
1226 void report_exception ()
1230 } catch (FileError& e) {
1234 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
1235 std_to_wx (e.what()),
1236 std_to_wx (e.file().string().c_str ())
1239 } catch (exception& e) {
1243 _("An exception occurred: %s.\n\n") + REPORT_PROBLEM,
1244 std_to_wx (e.what ())
1248 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
1252 /* An unhandled exception has occurred inside the main event loop */
1253 bool OnExceptionInMainLoop ()
1255 report_exception ();
1256 /* This will terminate the program */
1260 void OnUnhandledException ()
1262 report_exception ();
1267 signal_manager->ui_idle ();
1270 void config_failed_to_load ()
1272 message_dialog (_frame, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create."));
1275 void config_warning (string m)
1277 message_dialog (_frame, std_to_wx (m));
1280 DOMFrame* _frame = nullptr;
1281 string _dcp_to_load;
1282 boost::optional<string> _stress;