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/>.
22 #include "player_information.h"
24 #include "film_viewer.h"
25 #include "lib/playlist.h"
26 #include "lib/compose.hpp"
27 #include "lib/video_content.h"
28 #include "lib/audio_content.h"
29 #include "lib/dcp_content.h"
34 using std::dynamic_pointer_cast;
35 using std::shared_ptr;
38 using boost::optional;
41 /* This should be even */
42 static int const dcp_lines = 6;
45 PlayerInformation::PlayerInformation(wxWindow* parent, FilmViewer const& viewer)
48 , _sizer (new wxBoxSizer (wxHORIZONTAL))
50 wxFont title_font (*wxNORMAL_FONT);
51 title_font.SetWeight (wxFONTWEIGHT_BOLD);
53 _dcp = new wxStaticText*[dcp_lines];
55 DCPOMATIC_ASSERT ((dcp_lines % 2) == 0);
58 auto s = new wxBoxSizer (wxVERTICAL);
59 add_label_to_sizer(s, this, _("DCP"), false, 0)->SetFont(title_font);
60 for (int i = 0; i < dcp_lines / 2; ++i) {
61 _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
63 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
67 auto s = new wxBoxSizer (wxVERTICAL);
68 add_label_to_sizer(s, this, wxT(" "), false, 0);
69 for (int i = dcp_lines / 2; i < dcp_lines; ++i) {
70 _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
72 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
76 _kdm_panel = new wxPanel(this, wxID_ANY);
77 auto s = new wxBoxSizer(wxVERTICAL);
78 add_label_to_sizer(s, _kdm_panel, _("KDM"), false, 0)->SetFont(title_font);
79 auto g = new wxGridBagSizer(0, DCPOMATIC_SIZER_GAP);
80 add_label_to_sizer(g, _kdm_panel, _("Valid from"), true, wxGBPosition(0, 0));
81 _kdm_from = add_label_to_sizer(g, _kdm_panel, wxT(""), false, wxGBPosition(0, 1));
82 add_label_to_sizer(g, _kdm_panel, _("Valid to"), true, wxGBPosition(1, 0));
83 _kdm_to = add_label_to_sizer(g, _kdm_panel, wxT(""), false, wxGBPosition(1, 1));
84 s->Add(g, 1, wxEXPAND | wxLEFT, DCPOMATIC_SIZER_GAP);
85 _kdm_panel->SetSizer(s);
86 _sizer->Add(_kdm_panel, 1, wxEXPAND | wxALL, 6);
90 auto s = new wxBoxSizer (wxVERTICAL);
91 add_label_to_sizer(s, this, _("Performance"), false, 0)->SetFont(title_font);
92 _dropped = add_label_to_sizer(s, this, wxT(""), false, 0);
93 _decode_resolution = add_label_to_sizer(s, this, wxT(""), false, 0);
94 _sizer->Add (s, 2, wxEXPAND | wxALL, 6);
97 SetSizerAndFit (_sizer);
101 Bind (wxEVT_TIMER, boost::bind (&PlayerInformation::periodic_update, this));
102 _timer.reset (new wxTimer (this));
108 PlayerInformation::periodic_update ()
110 auto s = wxString::Format(_("Dropped frames: %d"), _viewer.dropped() + _viewer.errored());
111 if (_viewer.errored() == 1) {
112 s += wxString::Format(_(" (%d error)"), _viewer.errored());
113 } else if (_viewer.errored() > 1) {
114 s += wxString::Format(_(" (%d errors)"), _viewer.errored());
116 checked_set (_dropped, s);
121 PlayerInformation::triggered_update ()
123 shared_ptr<DCPContent> dcp;
124 if (_viewer.film()) {
125 auto content = _viewer.film()->content();
126 if (content.size() == 1) {
127 dcp = dynamic_pointer_cast<DCPContent>(content.front());
132 checked_set (_dcp[0], _("No DCP loaded."));
133 for (int r = 1; r < dcp_lines; ++r) {
134 checked_set (_dcp[r], wxT(""));
136 checked_set (_decode_resolution, wxT(""));
142 checked_set(_dcp[r], std_to_wx(dcp->name()));
144 for (auto directory: dcp->directories()) {
145 tooltip += std_to_wx(directory.string()) + "\n";
147 if (!tooltip.empty()) {
148 _dcp[r]->SetToolTip(tooltip.substr(0, tooltip.length() - 1));
152 if (dcp->needs_assets()) {
153 checked_set (_dcp[r], _("Needs OV"));
157 if (dcp->needs_kdm()) {
158 checked_set (_dcp[r], _("Needs KDM"));
162 DCPOMATIC_ASSERT (dcp->video);
164 checked_set (_dcp[r++], wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));
165 if (dcp->video_frame_rate()) {
166 checked_set (_dcp[r++], wxString::Format(_("Frame rate: %d"), (int) lrint(*dcp->video_frame_rate())));
168 if (dcp->audio && !dcp->audio->streams().empty()) {
169 checked_set (_dcp[r++], wxString::Format(_("Audio channels: %d"), dcp->audio->streams().front()->channels()));
171 if (!dcp->text.empty()) {
172 checked_set (_dcp[r++], _("Subtitles: yes"));
174 checked_set (_dcp[r++], _("Subtitles: no"));
177 optional<double> vfr;
178 vfr = dcp->video_frame_rate ();
179 DCPOMATIC_ASSERT (vfr);
181 auto const len = String::compose(
182 wx_to_std(_("Length: %1 (%2 frames)")),
183 time_to_hmsf(dcp->full_length(_viewer.film()), lrint(*vfr)),
184 dcp->full_length(_viewer.film()).frames_round(*vfr)
187 checked_set (_dcp[r++], std_to_wx(len));
189 auto decode = dcp->video->size();
190 auto reduction = _viewer.dcp_decode_reduction();
192 decode.width /= pow(2, *reduction);
193 decode.height /= pow(2, *reduction);
196 checked_set (_decode_resolution, wxString::Format(_("Decode resolution: %dx%d"), decode.width, decode.height));
198 DCPOMATIC_ASSERT(r <= dcp_lines);
200 if (dcp->encrypted() && dcp->kdm()) {
202 auto const kdm = *dcp->kdm();
203 auto const before = kdm.not_valid_before();
204 checked_set(_kdm_from, wxString::Format(_("%s %s"), std_to_wx(before.date()), std_to_wx(before.time_of_day(true, false))));
205 auto const after = kdm.not_valid_after();
206 checked_set(_kdm_to, wxString::Format(_("%s %s"), std_to_wx(after.date()), std_to_wx(after.time_of_day(true, false))));