2 Copyright (C) 2017-2018 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 "player_information.h"
23 #include "film_viewer.h"
24 #include "lib/playlist.h"
25 #include "lib/compose.hpp"
26 #include "lib/video_content.h"
27 #include "lib/audio_content.h"
28 #include "lib/dcp_content.h"
33 using boost::shared_ptr;
34 using boost::weak_ptr;
35 using boost::dynamic_pointer_cast;
36 using boost::optional;
38 /* This should be even */
39 static int const dcp_lines = 6;
41 PlayerInformation::PlayerInformation (wxWindow* parent, weak_ptr<FilmViewer> viewer)
44 , _sizer (new wxBoxSizer (wxHORIZONTAL))
46 wxFont title_font (*wxNORMAL_FONT);
47 title_font.SetWeight (wxFONTWEIGHT_BOLD);
49 _dcp = new wxStaticText*[dcp_lines];
51 DCPOMATIC_ASSERT ((dcp_lines % 2) == 0);
54 wxSizer* s = new wxBoxSizer (wxVERTICAL);
55 add_label_to_sizer(s, this, _("DCP"), false, 0)->SetFont(title_font);
56 for (int i = 0; i < dcp_lines / 2; ++i) {
57 _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
59 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
63 wxSizer* s = new wxBoxSizer (wxVERTICAL);
64 add_label_to_sizer(s, this, wxT(" "), false, 0);
65 for (int i = dcp_lines / 2; i < dcp_lines; ++i) {
66 _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
68 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
72 wxSizer* s = new wxBoxSizer (wxVERTICAL);
73 add_label_to_sizer(s, this, _("Performance"), false, 0)->SetFont(title_font);
74 _dropped = add_label_to_sizer(s, this, wxT(""), false, 0);
75 _decode_resolution = add_label_to_sizer(s, this, wxT(""), false, 0);
76 _sizer->Add (s, 2, wxEXPAND | wxALL, 6);
79 SetSizerAndFit (_sizer);
83 Bind (wxEVT_TIMER, boost::bind (&PlayerInformation::periodic_update, this));
84 _timer.reset (new wxTimer (this));
89 PlayerInformation::periodic_update ()
91 shared_ptr<FilmViewer> fv = _viewer.lock ();
93 wxString s = wxString::Format(_("Dropped frames: %d"), fv->dropped() + fv->errored());
94 if (fv->errored() == 1) {
95 s += wxString::Format(_(" (%d error)"), fv->errored());
96 } else if (fv->errored() > 1) {
97 s += wxString::Format(_(" (%d errors)"), fv->errored());
99 checked_set (_dropped, s);
104 PlayerInformation::triggered_update ()
106 shared_ptr<FilmViewer> fv = _viewer.lock ();
111 shared_ptr<DCPContent> dcp;
113 ContentList content = fv->film()->content();
114 if (content.size() == 1) {
115 dcp = dynamic_pointer_cast<DCPContent>(content.front());
120 checked_set (_dcp[0], _("No DCP loaded."));
121 for (int r = 1; r < dcp_lines; ++r) {
122 checked_set (_dcp[r], wxT(""));
124 checked_set (_decode_resolution, wxT(""));
129 checked_set (_dcp[r++], std_to_wx(dcp->name()));
131 if (dcp->needs_assets()) {
132 checked_set (_dcp[r], _("Needs OV"));
136 if (dcp->needs_kdm()) {
137 checked_set (_dcp[r], _("Needs KDM"));
141 DCPOMATIC_ASSERT (dcp->video);
143 checked_set (_dcp[r++], wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));
144 if (dcp->video_frame_rate()) {
145 checked_set (_dcp[r++], wxString::Format(_("Frame rate: %d"), (int) lrint(*dcp->video_frame_rate())));
147 if (dcp->audio && !dcp->audio->streams().empty()) {
148 checked_set (_dcp[r++], wxString::Format(_("Audio channels: %d"), dcp->audio->streams().front()->channels()));
150 if (!dcp->text.empty()) {
151 checked_set (_dcp[r++], _("Subtitles: yes"));
153 checked_set (_dcp[r++], _("Subtitles: no"));
156 optional<double> vfr;
157 vfr = dcp->video_frame_rate ();
158 DCPOMATIC_ASSERT (vfr);
160 string const len = String::compose(
161 wx_to_std(_("Length: %1 (%2 frames)")),
162 time_to_hmsf(dcp->full_length(fv->film()), lrint(*vfr)),
163 dcp->full_length(fv->film()).frames_round(*vfr)
166 checked_set (_dcp[r++], std_to_wx(len));
168 dcp::Size decode = dcp->video->size();
169 optional<int> reduction = fv->dcp_decode_reduction();
171 decode.width /= pow(2, *reduction);
172 decode.height /= pow(2, *reduction);
175 checked_set (_decode_resolution, wxString::Format(_("Decode resolution: %dx%d"), decode.width, decode.height));
177 DCPOMATIC_ASSERT(r <= dcp_lines);