Fix alignment.
[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/film.h"
29 #include "lib/config.h"
30 #include "lib/player_text.h"
31 #include "lib/timer.h"
32 #include "lib/signaller.h"
33 #include "lib/warnings.h"
34 #include <RtAudio.h>
35 DCPOMATIC_DISABLE_WARNINGS
36 #include <wx/wx.h>
37 DCPOMATIC_ENABLE_WARNINGS
38 #include <vector>
39
40
41 class wxToggleButton;
42 class FFmpegPlayer;
43 class Image;
44 class RGBPlusAlphaImage;
45 class PlayerVideo;
46 class Player;
47 class Butler;
48 class ClosedCaptionsDialog;
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         VideoView const * 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         dcpomatic::DCPTime one_video_frame () const;
84
85         void start ();
86         bool stop ();
87         void suspend ();
88         void resume ();
89
90         bool playing () const {
91                 return _playing;
92         }
93
94         void set_coalesce_player_changes (bool c);
95         void set_dcp_decode_reduction (boost::optional<int> reduction);
96         boost::optional<int> dcp_decode_reduction () const;
97         void set_outline_content (bool o);
98         void set_outline_subtitles (boost::optional<dcpomatic::Rect<double>>);
99         void set_eyes (Eyes e);
100         void set_pad_black (bool p);
101
102         void slow_refresh ();
103
104         dcpomatic::DCPTime time () const;
105         boost::optional<dcpomatic::DCPTime> audio_time () const;
106
107         int dropped () const;
108         int errored () const;
109         int gets () const;
110
111         int audio_callback (void* out, unsigned int frames);
112
113         StateTimer const & state_timer () const {
114                 return _video_view->state_timer ();
115         }
116
117         /* Some accessors and utility methods that VideoView classes need */
118         dcp::Size out_size () const {
119                 return _out_size;
120         }
121         bool outline_content () const {
122                 return _outline_content;
123         }
124         boost::optional<dcpomatic::Rect<double>> outline_subtitles () const {
125                 return _outline_subtitles;
126         }
127         bool pad_black () const {
128                 return _pad_black;
129         }
130         std::shared_ptr<Butler> butler () const {
131                 return _butler;
132         }
133         ClosedCaptionsDialog* closed_captions_dialog () const {
134                 return _closed_captions_dialog;
135         }
136         void finished ();
137         void image_changed (std::shared_ptr<PlayerVideo> video);
138
139         bool pending_idle_get () const {
140                 return _idle_get;
141         }
142
143         boost::signals2::signal<void (std::shared_ptr<PlayerVideo>)> ImageChanged;
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         void video_view_sized ();
154         void calculate_sizes ();
155         void player_change (ChangeType type, int, bool);
156         void player_change (std::vector<int> properties);
157         void idle_handler ();
158         void request_idle_display_next_frame ();
159         void film_change (ChangeType, Film::Property);
160         void recreate_butler ();
161         void config_changed (Config::Property);
162         void film_length_change ();
163         void ui_finished ();
164         void too_many_frames_dropped ();
165
166         dcpomatic::DCPTime uncorrected_time () const;
167         Frame average_latency () const;
168
169         bool quick_refresh ();
170
171         std::shared_ptr<Film> _film;
172         std::shared_ptr<Player> _player;
173
174         VideoView* _video_view = nullptr;
175         bool _coalesce_player_changes = false;
176         std::vector<int> _pending_player_changes;
177
178         /** Size of our output (including padding if we have any) */
179         dcp::Size _out_size;
180
181         RtAudio _audio;
182         int _audio_channels = 0;
183         unsigned int _audio_block_size = 1024;
184         bool _playing = false;
185         int _suspended = 0;
186         std::shared_ptr<Butler> _butler;
187
188         std::list<Frame> _latency_history;
189         /** Mutex to protect _latency_history */
190         mutable boost::mutex _latency_history_mutex;
191         int _latency_history_count = 0;
192
193         boost::optional<int> _dcp_decode_reduction;
194
195         ClosedCaptionsDialog* _closed_captions_dialog = nullptr;
196
197         bool _outline_content = false;
198         boost::optional<dcpomatic::Rect<double>> _outline_subtitles;
199         /** true to pad the viewer panel with black, false to use
200             the normal window background colour.
201         */
202         bool _pad_black = false;
203
204         /** true if an get() is required next time we are idle */
205         bool _idle_get = false;
206
207         boost::signals2::scoped_connection _config_changed_connection;
208 };