Fix up SimpleVideoView.
[dcpomatic.git] / src / wx / film_viewer.h
1 /*
2     Copyright (C) 2012-2019 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 /** @file  src/film_viewer.h
22  *  @brief FilmViewer class.
23  */
24
25 #include "video_view.h"
26 #include "lib/film.h"
27 #include "lib/config.h"
28 #include "lib/player_text.h"
29 #include "lib/timer.h"
30 #include <RtAudio.h>
31 #include <wx/wx.h>
32
33 class wxToggleButton;
34 class FFmpegPlayer;
35 class Image;
36 class RGBPlusAlphaImage;
37 class PlayerVideo;
38 class Player;
39 class Butler;
40 class ClosedCaptionsDialog;
41
42 /** @class FilmViewer
43  *  @brief A wx widget to view a Film.
44  */
45 class FilmViewer
46 {
47 public:
48         FilmViewer (wxWindow *);
49         ~FilmViewer ();
50
51         /** @return the window showing the film's video */
52         wxWindow* panel () const {
53                 return _video_view->get();
54         }
55
56         void show_closed_captions ();
57
58         void set_film (boost::shared_ptr<Film>);
59         boost::shared_ptr<Film> film () const {
60                 return _film;
61         }
62
63         void seek (dcpomatic::DCPTime t, bool accurate);
64         void seek (boost::shared_ptr<Content> content, dcpomatic::ContentTime p, bool accurate);
65         void seek_by (dcpomatic::DCPTime by, bool accurate);
66         /** @return our `playhead' position; this may not lie exactly on a frame boundary */
67         dcpomatic::DCPTime position () const {
68                 return _video_position;
69         }
70         dcpomatic::DCPTime one_video_frame () const;
71
72         void start ();
73         bool stop ();
74         bool playing () const {
75                 return _playing;
76         }
77
78         void set_coalesce_player_changes (bool c);
79         void set_dcp_decode_reduction (boost::optional<int> reduction);
80         boost::optional<int> dcp_decode_reduction () const;
81         void set_outline_content (bool o);
82         void set_eyes (Eyes e);
83         void set_pad_black (bool p);
84
85         void slow_refresh ();
86
87         int dropped () const {
88                 return _dropped;
89         }
90
91         int audio_callback (void* out, unsigned int frames);
92
93 #ifdef DCPOMATIC_VARIANT_SWAROOP
94         void set_background_image (bool b) {
95                 _background_image = b;
96                 refresh_panel ();
97         }
98 #endif
99
100         StateTimer const & state_timer () const {
101                 return _state_timer;
102         }
103
104         int gets () const {
105                 return _gets;
106         }
107
108         /* Some accessors that VideoView classes need */
109         dcp::Size out_size () const {
110                 return _out_size;
111         }
112         dcp::Size inter_size () const {
113                 return _inter_size;
114         }
115         Position<int> inter_position () const {
116                 return _inter_position;
117         }
118         bool outline_content () const {
119                 return _outline_content;
120         }
121         bool pad_black () const {
122                 return _pad_black;
123         }
124
125         boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
126         boost::signals2::signal<void ()> PositionChanged;
127         boost::signals2::signal<void (dcpomatic::DCPTime)> Started;
128         boost::signals2::signal<void (dcpomatic::DCPTime)> Stopped;
129         /** While playing back we reached the end of the film (emitted from GUI thread) */
130         boost::signals2::signal<void ()> Finished;
131
132         boost::signals2::signal<bool ()> PlaybackPermitted;
133
134 private:
135         void video_view_sized ();
136         void timer ();
137         void calculate_sizes ();
138         void player_change (ChangeType type, int, bool);
139         void get ();
140         void display_player_video ();
141         void film_change (ChangeType, Film::Property);
142         void recreate_butler ();
143         void config_changed (Config::Property);
144         bool maybe_draw_background_image (wxPaintDC& dc);
145
146         dcpomatic::DCPTime time () const;
147         dcpomatic::DCPTime uncorrected_time () const;
148         Frame average_latency () const;
149
150         void refresh_view ();
151         bool quick_refresh ();
152
153         boost::shared_ptr<Film> _film;
154         boost::shared_ptr<Player> _player;
155
156         VideoView* _video_view;
157         wxTimer _timer;
158         bool _coalesce_player_changes;
159         std::list<int> _pending_player_changes;
160
161         std::pair<boost::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> _player_video;
162         boost::shared_ptr<const Image> _frame;
163         dcpomatic::DCPTime _video_position;
164         Position<int> _inter_position;
165         dcp::Size _inter_size;
166
167         /** Size of our output (including padding if we have any) */
168         dcp::Size _out_size;
169
170         RtAudio _audio;
171         int _audio_channels;
172         unsigned int _audio_block_size;
173         bool _playing;
174         boost::shared_ptr<Butler> _butler;
175
176         std::list<Frame> _latency_history;
177         /** Mutex to protect _latency_history */
178         mutable boost::mutex _latency_history_mutex;
179         int _latency_history_count;
180
181         int _dropped;
182         boost::optional<int> _dcp_decode_reduction;
183
184         ClosedCaptionsDialog* _closed_captions_dialog;
185
186         bool _outline_content;
187         Eyes _eyes;
188         /** true to pad the viewer panel with black, false to use
189             the normal window background colour.
190         */
191         bool _pad_black;
192
193 #ifdef DCPOMATIC_VARIANT_SWAROOP
194         bool _in_watermark;
195         int _watermark_x;
196         int _watermark_y;
197         bool _background_image;
198 #endif
199
200         StateTimer _state_timer;
201         int _gets;
202
203         boost::signals2::scoped_connection _config_changed_connection;
204 };