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