Put Time types in dcpomatic namespace.
[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 "lib/film.h"
26 #include "lib/config.h"
27 #include "lib/player_text.h"
28 #include "lib/timer.h"
29 #include <RtAudio.h>
30 #include <wx/wx.h>
31
32 class wxToggleButton;
33 class FFmpegPlayer;
34 class Image;
35 class RGBPlusAlphaImage;
36 class PlayerVideo;
37 class Player;
38 class Butler;
39 class ClosedCaptionsDialog;
40
41 /** @class FilmViewer
42  *  @brief A wx widget to view a Film.
43  */
44 class FilmViewer
45 {
46 public:
47         FilmViewer (wxWindow *);
48         ~FilmViewer ();
49
50         /** @return the panel showing the film's video */
51         wxPanel* panel () const {
52                 return _panel;
53         }
54
55         void show_closed_captions ();
56
57         void set_film (boost::shared_ptr<Film>);
58         boost::shared_ptr<Film> film () const {
59                 return _film;
60         }
61
62         void seek (dcpomatic::DCPTime t, bool accurate);
63         void seek (boost::shared_ptr<Content> content, dcpomatic::ContentTime p, bool accurate);
64         void seek_by (dcpomatic::DCPTime by, bool accurate);
65         /** @return our `playhead' position; this may not lie exactly on a frame boundary */
66         dcpomatic::DCPTime position () const {
67                 return _video_position;
68         }
69         dcpomatic::DCPTime one_video_frame () const;
70
71         void start ();
72         bool stop ();
73         bool playing () const {
74                 return _playing;
75         }
76
77         void set_coalesce_player_changes (bool c);
78         void set_dcp_decode_reduction (boost::optional<int> reduction);
79         boost::optional<int> dcp_decode_reduction () const;
80         void set_outline_content (bool o);
81         void set_eyes (Eyes e);
82         void set_pad_black (bool p);
83
84         void slow_refresh ();
85
86         int dropped () const {
87                 return _dropped;
88         }
89
90         int audio_callback (void* out, unsigned int frames);
91
92 #ifdef DCPOMATIC_VARIANT_SWAROOP
93         void set_background_image (bool b) {
94                 _background_image = b;
95                 refresh_panel ();
96         }
97 #endif
98
99         StateTimer const & state_timer () const {
100                 return _state_timer;
101         }
102
103         int gets () const {
104                 return _gets;
105         }
106
107         boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
108         boost::signals2::signal<void ()> PositionChanged;
109         boost::signals2::signal<void (dcpomatic::DCPTime)> Started;
110         boost::signals2::signal<void (dcpomatic::DCPTime)> Stopped;
111         /** While playing back we reached the end of the film (emitted from GUI thread) */
112         boost::signals2::signal<void ()> Finished;
113
114         boost::signals2::signal<bool ()> PlaybackPermitted;
115
116 private:
117         void paint_panel ();
118         void panel_sized (wxSizeEvent &);
119         void timer ();
120         void calculate_sizes ();
121         void player_change (ChangeType type, int, bool);
122         void get ();
123         void display_player_video ();
124         void film_change (ChangeType, Film::Property);
125         void recreate_butler ();
126         void config_changed (Config::Property);
127         bool maybe_draw_background_image (wxPaintDC& dc);
128
129         dcpomatic::DCPTime time () const;
130         dcpomatic::DCPTime uncorrected_time () const;
131         Frame average_latency () const;
132
133         void refresh_panel ();
134         bool quick_refresh ();
135
136         boost::shared_ptr<Film> _film;
137         boost::shared_ptr<Player> _player;
138
139         /** The area that we put our image in */
140         wxPanel* _panel;
141         wxTimer _timer;
142         bool _coalesce_player_changes;
143         std::list<int> _pending_player_changes;
144
145         std::pair<boost::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> _player_video;
146         boost::shared_ptr<const Image> _frame;
147         dcpomatic::DCPTime _video_position;
148         Position<int> _inter_position;
149         dcp::Size _inter_size;
150
151         /** Size of our output (including padding if we have any) */
152         dcp::Size _out_size;
153         /** Size of the panel that we have available */
154         dcp::Size _panel_size;
155
156         RtAudio _audio;
157         int _audio_channels;
158         unsigned int _audio_block_size;
159         bool _playing;
160         boost::shared_ptr<Butler> _butler;
161
162         std::list<Frame> _latency_history;
163         /** Mutex to protect _latency_history */
164         mutable boost::mutex _latency_history_mutex;
165         int _latency_history_count;
166
167         int _dropped;
168         boost::optional<int> _dcp_decode_reduction;
169
170         ClosedCaptionsDialog* _closed_captions_dialog;
171
172         bool _outline_content;
173         Eyes _eyes;
174         /** true to pad the viewer panel with black, false to use
175             the normal window background colour.
176         */
177         bool _pad_black;
178
179 #ifdef DCPOMATIC_VARIANT_SWAROOP
180         bool _in_watermark;
181         int _watermark_x;
182         int _watermark_y;
183         bool _background_image;
184 #endif
185
186         StateTimer _state_timer;
187         int _gets;
188
189         boost::signals2::scoped_connection _config_changed_connection;
190 };