51419a54dc9c5cf29b139f8ea5af79754e1084cb
[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         VideoView const * video_view () const {
57                 return _video_view;
58         }
59
60         void show_closed_captions ();
61
62         void set_film (boost::shared_ptr<Film>);
63         boost::shared_ptr<Film> film () const {
64                 return _film;
65         }
66
67         void seek (dcpomatic::DCPTime t, bool accurate);
68         void seek (boost::shared_ptr<Content> content, dcpomatic::ContentTime p, bool accurate);
69         void seek_by (dcpomatic::DCPTime by, bool accurate);
70         /** @return our `playhead' position; this may not lie exactly on a frame boundary */
71         dcpomatic::DCPTime position () const {
72                 return _video_position;
73         }
74         dcpomatic::DCPTime one_video_frame () const;
75
76         void start ();
77         bool stop ();
78         void suspend ();
79         void resume ();
80         bool playing () const {
81                 return _playing;
82         }
83
84         void set_coalesce_player_changes (bool c);
85         void set_dcp_decode_reduction (boost::optional<int> reduction);
86         boost::optional<int> dcp_decode_reduction () const;
87         void set_outline_content (bool o);
88         void set_eyes (Eyes e);
89         void set_pad_black (bool p);
90
91         void slow_refresh ();
92
93         int dropped () const {
94                 return _dropped;
95         }
96
97         int audio_callback (void* out, unsigned int frames);
98
99 #ifdef DCPOMATIC_VARIANT_SWAROOP
100         void set_background_image (bool b) {
101                 _background_image = b;
102                 refresh_view ();
103         }
104
105         bool background_image () const {
106                 return _background_image;
107         }
108 #endif
109
110         StateTimer const & state_timer () const {
111                 return _state_timer;
112         }
113
114         StateTimer& state_timer () {
115                 return _state_timer;
116         }
117
118         int gets () const {
119                 return _gets;
120         }
121
122         /* Some accessors that VideoView classes need */
123         dcp::Size out_size () const {
124                 return _out_size;
125         }
126         dcp::Size inter_size () const {
127                 return _inter_size;
128         }
129         Position<int> inter_position () const {
130                 return _inter_position;
131         }
132         bool outline_content () const {
133                 return _outline_content;
134         }
135         bool pad_black () const {
136                 return _pad_black;
137         }
138         boost::shared_ptr<Butler> butler () const {
139                 return _butler;
140         }
141
142         boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
143         boost::signals2::signal<void ()> PositionChanged;
144         boost::signals2::signal<void (dcpomatic::DCPTime)> Started;
145         boost::signals2::signal<void (dcpomatic::DCPTime)> Stopped;
146         /** While playing back we reached the end of the film (emitted from GUI thread) */
147         boost::signals2::signal<void ()> Finished;
148
149         boost::signals2::signal<bool ()> PlaybackPermitted;
150
151 private:
152
153         /* XXX_b: to remove */
154         friend class SimpleVideoView;
155
156         void video_view_sized ();
157         void calculate_sizes ();
158         void player_change (ChangeType type, int, bool);
159         void idle_handler ();
160         void request_idle_get ();
161         void film_change (ChangeType, Film::Property);
162         void recreate_butler ();
163         void config_changed (Config::Property);
164
165         dcpomatic::DCPTime time () const;
166         dcpomatic::DCPTime uncorrected_time () const;
167         Frame average_latency () const;
168
169         void refresh_view ();
170         bool quick_refresh ();
171
172         boost::shared_ptr<Film> _film;
173         boost::shared_ptr<Player> _player;
174
175         VideoView* _video_view;
176         bool _coalesce_player_changes;
177         std::list<int> _pending_player_changes;
178
179         dcpomatic::DCPTime _video_position;
180         Position<int> _inter_position;
181         dcp::Size _inter_size;
182
183         /** Size of our output (including padding if we have any) */
184         dcp::Size _out_size;
185
186         RtAudio _audio;
187         int _audio_channels;
188         unsigned int _audio_block_size;
189         bool _playing;
190         int _suspended;
191         boost::shared_ptr<Butler> _butler;
192
193         std::list<Frame> _latency_history;
194         /** Mutex to protect _latency_history */
195         mutable boost::mutex _latency_history_mutex;
196         int _latency_history_count;
197
198         int _dropped;
199         boost::optional<int> _dcp_decode_reduction;
200
201         ClosedCaptionsDialog* _closed_captions_dialog;
202
203         bool _outline_content;
204         Eyes _eyes;
205         /** true to pad the viewer panel with black, false to use
206             the normal window background colour.
207         */
208         bool _pad_black;
209
210 #ifdef DCPOMATIC_VARIANT_SWAROOP
211         bool _background_image;
212 #endif
213
214         StateTimer _state_timer;
215         int _gets;
216
217         /** true if an get() is required next time we are idle */
218         bool _idle_get;
219
220         boost::signals2::scoped_connection _config_changed_connection;
221 };