Optimise the feel of some GUI functions by doing the seek after
[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         bool playing () const {
79                 return _playing;
80         }
81
82         void set_coalesce_player_changes (bool c);
83         void set_dcp_decode_reduction (boost::optional<int> reduction);
84         boost::optional<int> dcp_decode_reduction () const;
85         void set_outline_content (bool o);
86         void set_eyes (Eyes e);
87         void set_pad_black (bool p);
88
89         void slow_refresh ();
90
91         int dropped () const {
92                 return _dropped;
93         }
94
95         int audio_callback (void* out, unsigned int frames);
96
97 #ifdef DCPOMATIC_VARIANT_SWAROOP
98         void set_background_image (bool b) {
99                 _background_image = b;
100                 refresh_view ();
101         }
102
103         bool background_image () const {
104                 return _background_image;
105         }
106 #endif
107
108         StateTimer const & state_timer () const {
109                 return _state_timer;
110         }
111
112         StateTimer& state_timer () {
113                 return _state_timer;
114         }
115
116         int gets () const {
117                 return _gets;
118         }
119
120         /* Some accessors that VideoView classes need */
121         dcp::Size out_size () const {
122                 return _out_size;
123         }
124         dcp::Size inter_size () const {
125                 return _inter_size;
126         }
127         Position<int> inter_position () const {
128                 return _inter_position;
129         }
130         bool outline_content () const {
131                 return _outline_content;
132         }
133         bool pad_black () const {
134                 return _pad_black;
135         }
136         dcpomatic::DCPTime video_position () const {
137                 return _video_position;
138         }
139
140         boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
141         boost::signals2::signal<void ()> PositionChanged;
142         boost::signals2::signal<void (dcpomatic::DCPTime)> Started;
143         boost::signals2::signal<void (dcpomatic::DCPTime)> Stopped;
144         /** While playing back we reached the end of the film (emitted from GUI thread) */
145         boost::signals2::signal<void ()> Finished;
146
147         boost::signals2::signal<bool ()> PlaybackPermitted;
148
149 private:
150         void video_view_sized ();
151         void timer ();
152         void calculate_sizes ();
153         void player_change (ChangeType type, int, bool);
154         void get (bool lazy);
155         void display_player_video ();
156         void film_change (ChangeType, Film::Property);
157         void recreate_butler ();
158         void config_changed (Config::Property);
159
160         dcpomatic::DCPTime time () const;
161         dcpomatic::DCPTime uncorrected_time () const;
162         Frame average_latency () const;
163
164         void refresh_view ();
165         bool quick_refresh ();
166
167         boost::shared_ptr<Film> _film;
168         boost::shared_ptr<Player> _player;
169
170         VideoView* _video_view;
171         wxTimer _timer;
172         bool _coalesce_player_changes;
173         std::list<int> _pending_player_changes;
174
175         std::pair<boost::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> _player_video;
176         dcpomatic::DCPTime _video_position;
177         Position<int> _inter_position;
178         dcp::Size _inter_size;
179
180         /** Size of our output (including padding if we have any) */
181         dcp::Size _out_size;
182
183         RtAudio _audio;
184         int _audio_channels;
185         unsigned int _audio_block_size;
186         bool _playing;
187         boost::shared_ptr<Butler> _butler;
188
189         std::list<Frame> _latency_history;
190         /** Mutex to protect _latency_history */
191         mutable boost::mutex _latency_history_mutex;
192         int _latency_history_count;
193
194         int _dropped;
195         boost::optional<int> _dcp_decode_reduction;
196
197         ClosedCaptionsDialog* _closed_captions_dialog;
198
199         bool _outline_content;
200         Eyes _eyes;
201         /** true to pad the viewer panel with black, false to use
202             the normal window background colour.
203         */
204         bool _pad_black;
205
206 #ifdef DCPOMATIC_VARIANT_SWAROOP
207         bool _background_image;
208 #endif
209
210         StateTimer _state_timer;
211         int _gets;
212
213         boost::signals2::scoped_connection _config_changed_connection;
214 };