Supporters update.
[dcpomatic.git] / src / wx / film_viewer.h
1 /*
2     Copyright (C) 2012-2021 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
22 /** @file  src/film_viewer.h
23  *  @brief FilmViewer class.
24  */
25
26
27 #include "video_view.h"
28 #include "lib/config.h"
29 #include "lib/film_property.h"
30 #include "lib/player_text.h"
31 #include "lib/signaller.h"
32 #include "lib/timer.h"
33 #include <dcp/warnings.h>
34 LIBDCP_DISABLE_WARNINGS
35 #include <RtAudio.h>
36 #include <wx/wx.h>
37 LIBDCP_ENABLE_WARNINGS
38 #include <vector>
39
40
41 class Butler;
42 class ClosedCaptionsDialog;
43 class FFmpegPlayer;
44 class Image;
45 class Player;
46 class PlayerVideo;
47 class RGBPlusAlphaImage;
48 class wxToggleButton;
49
50
51 /** @class FilmViewer
52  *  @brief A wx widget to view a Film.
53  */
54 class FilmViewer : public Signaller
55 {
56 public:
57         FilmViewer (wxWindow *);
58         ~FilmViewer ();
59
60         /** @return the window showing the film's video */
61         wxWindow* panel () const {
62                 return _video_view->get();
63         }
64
65         std::shared_ptr<const VideoView> video_view () const {
66                 return _video_view;
67         }
68
69         void show_closed_captions ();
70
71         void set_film (std::shared_ptr<Film>);
72         std::shared_ptr<Film> film () const {
73                 return _film;
74         }
75
76         void seek (dcpomatic::DCPTime t, bool accurate);
77         void seek (std::shared_ptr<Content> content, dcpomatic::ContentTime p, bool accurate);
78         void seek_by (dcpomatic::DCPTime by, bool accurate);
79         /** @return our `playhead' position; this may not lie exactly on a frame boundary */
80         dcpomatic::DCPTime position () const {
81                 return _video_view->position();
82         }
83         boost::optional<dcpomatic::ContentTime> position_in_content (std::shared_ptr<const Content> content) const;
84         dcpomatic::DCPTime one_video_frame () const;
85
86         void start ();
87         bool stop ();
88         void suspend ();
89         void resume ();
90
91         bool playing () const {
92                 return _playing;
93         }
94
95         void set_coalesce_player_changes (bool c);
96         void set_dcp_decode_reduction (boost::optional<int> reduction);
97         boost::optional<int> dcp_decode_reduction () const;
98         void set_outline_content (bool o);
99         void set_outline_subtitles (boost::optional<dcpomatic::Rect<double>>);
100         void set_eyes (Eyes e);
101         void set_pad_black (bool p);
102         void set_optimise_for_j2k (bool o);
103         void set_crop_guess (dcpomatic::Rect<float> crop);
104         void unset_crop_guess ();
105
106         void slow_refresh ();
107
108         dcpomatic::DCPTime time () const;
109         boost::optional<dcpomatic::DCPTime> audio_time () const;
110
111         int dropped () const;
112         int errored () const;
113         int gets () const;
114
115         int audio_callback (void* out, unsigned int frames);
116
117         StateTimer const & state_timer () const {
118                 return _video_view->state_timer ();
119         }
120
121         /* Some accessors and utility methods that VideoView classes need */
122         bool outline_content () const {
123                 return _outline_content;
124         }
125         boost::optional<dcpomatic::Rect<double>> outline_subtitles () const {
126                 return _outline_subtitles;
127         }
128         bool pad_black () const {
129                 return _pad_black;
130         }
131         std::shared_ptr<Butler> butler () const {
132                 return _butler;
133         }
134         ClosedCaptionsDialog* closed_captions_dialog () const {
135                 return _closed_captions_dialog;
136         }
137         void finished ();
138         void image_changed (std::shared_ptr<PlayerVideo> video);
139         boost::optional<dcpomatic::Rect<float>> crop_guess () const {
140                 return _crop_guess;
141         }
142
143         bool pending_idle_get () const {
144                 return _idle_get;
145         }
146
147         boost::signals2::signal<void (std::shared_ptr<PlayerVideo>)> ImageChanged;
148         boost::signals2::signal<void ()> Started;
149         boost::signals2::signal<void ()> Stopped;
150         /** While playing back we reached the end of the film (emitted from GUI thread) */
151         boost::signals2::signal<void ()> Finished;
152         /** Emitted from the GUI thread when a lot of frames are being dropped */
153         boost::signals2::signal<void()> TooManyDropped;
154
155         boost::signals2::signal<bool ()> PlaybackPermitted;
156
157 private:
158
159         void video_view_sized ();
160         void calculate_sizes ();
161         void player_change (ChangeType type, int, bool);
162         void player_change (std::vector<int> properties);
163         void idle_handler ();
164         void request_idle_display_next_frame ();
165         void film_change(ChangeType, FilmProperty);
166         void destroy_butler();
167         void create_butler();
168         void destroy_and_maybe_create_butler();
169         void config_changed (Config::Property);
170         void film_length_change ();
171         void ui_finished ();
172         void start_audio_stream_if_open ();
173
174 #if (RTAUDIO_VERSION_MAJOR >= 6)
175         void rtaudio_error_callback(std::string const& error);
176         mutable boost::mutex _last_rtaudio_error_mutex;
177         std::string _last_rtaudio_error;
178         std::string last_rtaudio_error() const;
179 #endif
180
181         dcpomatic::DCPTime uncorrected_time () const;
182         Frame average_latency () const;
183
184         bool quick_refresh ();
185
186         std::shared_ptr<Film> _film;
187         boost::optional<Player> _player;
188
189         std::shared_ptr<VideoView> _video_view;
190         bool _coalesce_player_changes = false;
191         std::vector<int> _pending_player_changes;
192
193         RtAudio _audio;
194         int _audio_channels = 0;
195         unsigned int _audio_block_size = 1024;
196         bool _playing = false;
197         int _suspended = 0;
198         std::shared_ptr<Butler> _butler;
199
200         std::list<Frame> _latency_history;
201         /** Mutex to protect _latency_history */
202         mutable boost::mutex _latency_history_mutex;
203         int _latency_history_count = 0;
204
205         boost::optional<int> _dcp_decode_reduction;
206
207         /** true to assume that this viewer is only being used for JPEG2000 sources
208          *  so it can optimise accordingly.
209          */
210         bool _optimise_for_j2k = false;
211
212         ClosedCaptionsDialog* _closed_captions_dialog = nullptr;
213
214         bool _outline_content = false;
215         boost::optional<dcpomatic::Rect<double>> _outline_subtitles;
216         /** true to pad the viewer panel with black, false to use
217             the normal window background colour.
218         */
219         bool _pad_black = false;
220
221         /** true if an get() is required next time we are idle */
222         bool _idle_get = false;
223
224         boost::optional<dcpomatic::Rect<float>> _crop_guess;
225
226         boost::signals2::scoped_connection _config_changed_connection;
227 };