c0821510ceb54d56b2be333f2e3f77e8c70eb0be
[dcpomatic.git] / src / wx / player_information.cc
1 /*
2     Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "player_information.h"
22 #include "wx_util.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"
29 #include "lib/film.h"
30
31 using std::cout;
32 using std::string;
33 using boost::shared_ptr;
34 using boost::weak_ptr;
35 using boost::dynamic_pointer_cast;
36 using boost::optional;
37
38 /* This should be even */
39 static int const dcp_lines = 6;
40
41 PlayerInformation::PlayerInformation (wxWindow* parent, weak_ptr<FilmViewer> viewer)
42         : wxPanel (parent)
43         , _viewer (viewer)
44         , _sizer (new wxBoxSizer (wxHORIZONTAL))
45 {
46         wxFont title_font (*wxNORMAL_FONT);
47         title_font.SetWeight (wxFONTWEIGHT_BOLD);
48
49         _dcp = new wxStaticText*[dcp_lines];
50
51         DCPOMATIC_ASSERT ((dcp_lines % 2) == 0);
52
53         {
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);
58                 }
59                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
60         }
61
62         {
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);
67                 }
68                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
69         }
70
71         {
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);
77         }
78
79         SetSizerAndFit (_sizer);
80
81         triggered_update ();
82
83         Bind (wxEVT_TIMER, boost::bind (&PlayerInformation::periodic_update, this));
84         _timer.reset (new wxTimer (this));
85         _timer->Start (500);
86 }
87
88 void
89 PlayerInformation::periodic_update ()
90 {
91         shared_ptr<FilmViewer> fv = _viewer.lock ();
92         if (fv) {
93                 checked_set (_dropped, wxString::Format(_("Dropped frames: %d"), fv->dropped()));
94         }
95 }
96
97 void
98 PlayerInformation::triggered_update ()
99 {
100         shared_ptr<FilmViewer> fv = _viewer.lock ();
101         if (!fv) {
102                 return;
103         }
104
105         shared_ptr<DCPContent> dcp;
106         if (fv->film()) {
107                 ContentList content = fv->film()->content();
108                 if (content.size() == 1) {
109                         dcp = dynamic_pointer_cast<DCPContent>(content.front());
110                 }
111         }
112
113         if (!dcp) {
114                 checked_set (_dcp[0], _("No DCP loaded."));
115                 for (int r = 1; r < dcp_lines; ++r) {
116                         checked_set (_dcp[r], wxT(""));
117                 }
118                 checked_set (_decode_resolution, wxT(""));
119                 return;
120         }
121
122         int r = 0;
123         checked_set (_dcp[r++], std_to_wx(dcp->name()));
124
125         if (dcp->needs_assets()) {
126                 checked_set (_dcp[r], _("Needs OV"));
127                 return;
128         }
129
130         if (dcp->needs_kdm()) {
131                 checked_set (_dcp[r], _("Needs KDM"));
132                 return;
133         }
134
135         DCPOMATIC_ASSERT (dcp->video);
136
137         checked_set (_dcp[r++], wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));
138         if (dcp->video_frame_rate()) {
139                 checked_set (_dcp[r++], wxString::Format(_("Frame rate: %d"), (int) lrint(*dcp->video_frame_rate())));
140         }
141         if (dcp->audio && !dcp->audio->streams().empty()) {
142                 checked_set (_dcp[r++], wxString::Format(_("Audio channels: %d"), dcp->audio->streams().front()->channels()));
143         }
144         if (!dcp->text.empty()) {
145                 checked_set (_dcp[r++], _("Subtitles: yes"));
146         } else {
147                 checked_set (_dcp[r++], _("Subtitles: no"));
148         }
149
150         optional<double> vfr;
151         vfr = dcp->video_frame_rate ();
152         DCPOMATIC_ASSERT (vfr);
153
154         string const len = String::compose(
155                 wx_to_std(_("Length: %1 (%2 frames)")),
156                 time_to_hmsf(dcp->full_length(), lrint(*vfr)),
157                 dcp->full_length().frames_round(*vfr)
158                 );
159
160         checked_set (_dcp[r++], std_to_wx(len));
161
162         dcp::Size decode = dcp->video->size();
163         optional<int> reduction = fv->dcp_decode_reduction();
164         if (reduction) {
165                 decode.width /= pow(2, *reduction);
166                 decode.height /= pow(2, *reduction);
167         }
168
169         checked_set (_decode_resolution, wxString::Format(_("Decode resolution: %dx%d"), decode.width, decode.height));
170
171         DCPOMATIC_ASSERT(r <= dcp_lines);
172
173         _sizer->Layout ();
174 }