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