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