2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 /** @file src/film_viewer.h
23 * @brief FilmViewer class.
27 #include "optimisation.h"
28 #include "video_view.h"
29 #include "lib/change_signaller.h"
30 #include "lib/config.h"
31 #include "lib/film_property.h"
32 #include "lib/player.h"
33 #include "lib/player_text.h"
34 #include "lib/signaller.h"
35 #include "lib/timer.h"
36 #include <dcp/warnings.h>
37 LIBDCP_DISABLE_WARNINGS
40 LIBDCP_ENABLE_WARNINGS
45 class ClosedCaptionsDialog;
51 class RGBPlusAlphaImage;
52 class SignLanguageDialog;
57 * @brief A wx widget to view a Film.
59 class FilmViewer : public Signaller
62 FilmViewer (wxWindow *);
65 /** @return the window showing the film's video */
66 wxWindow* panel(VideoType type) const {
67 return _video_view[type]->get();
70 std::shared_ptr<const VideoView> video_view(VideoType type) const {
71 return _video_view[type];
74 void show_closed_captions ();
75 void show_sign_language();
77 void set_film (std::shared_ptr<Film>);
78 std::shared_ptr<Film> film () const {
82 /** @return The DCP that we are playing back, if that's the only content in
85 std::shared_ptr<DCPContent> dcp() const;
87 void seek (dcpomatic::DCPTime t, bool accurate);
88 void seek (std::shared_ptr<Content> content, dcpomatic::ContentTime p, bool accurate);
89 void seek_by (dcpomatic::DCPTime by, bool accurate);
90 /** @return our `playhead' position; this may not lie exactly on a frame boundary */
91 dcpomatic::DCPTime position () const {
92 return _video_view[VideoType::MAIN]->position();
94 boost::optional<dcpomatic::ContentTime> position_in_content (std::shared_ptr<const Content> content) const;
95 dcpomatic::DCPTime one_video_frame () const;
102 bool playing () const {
106 void set_coalesce_player_changes (bool c);
107 void set_dcp_decode_reduction (boost::optional<int> reduction);
108 boost::optional<int> dcp_decode_reduction () const;
109 void set_outline_content (bool o);
110 void set_outline_subtitles (boost::optional<dcpomatic::Rect<double>>);
111 void set_eyes (Eyes e);
112 void set_pad_black (bool p);
113 void set_optimisation(Optimisation o);
114 void set_crop_guess (dcpomatic::Rect<float> crop);
115 void unset_crop_guess ();
117 void slow_refresh ();
119 dcpomatic::DCPTime time () const;
120 boost::optional<dcpomatic::DCPTime> audio_time () const;
122 int dropped () const;
123 int errored () const;
126 int audio_callback (void* out, unsigned int frames);
128 StateTimer const & state_timer () const {
129 return _video_view[VideoType::MAIN]->state_timer();
132 /* Some accessors and utility methods that VideoView classes need */
133 bool outline_content(VideoType type) const {
134 return type == VideoType::MAIN && _outline_content;
136 boost::optional<dcpomatic::Rect<double>> outline_subtitles(VideoType type) const;
137 bool pad_black () const {
140 std::shared_ptr<Butler> butler () const {
143 ClosedCaptionsDialog* closed_captions_dialog () const {
144 return _closed_captions_dialog;
147 void image_changed (std::shared_ptr<PlayerVideo> video);
148 boost::optional<dcpomatic::Rect<float>> crop_guess(VideoType type) const;
150 bool pending_idle_get () const {
154 boost::signals2::signal<void (std::shared_ptr<PlayerVideo>)> ImageChanged;
155 boost::signals2::signal<void ()> Started;
156 boost::signals2::signal<void ()> Stopped;
157 /** While playing back we reached the end of the film (emitted from GUI thread) */
158 boost::signals2::signal<void ()> Finished;
159 /** Emitted from the GUI thread when a lot of frames are being dropped */
160 boost::signals2::signal<void()> TooManyDropped;
162 boost::signals2::signal<bool ()> PlaybackPermitted;
166 void video_view_sized(VideoType type);
167 void calculate_sizes ();
168 void player_change (ChangeType type, int, bool);
169 void player_change (std::vector<int> properties);
170 void idle_handler ();
171 void request_idle_display_next_frame ();
172 void film_change(ChangeType, FilmProperty);
173 void destroy_butler();
174 void create_butler();
175 void destroy_and_maybe_create_butler();
176 void config_changed (Config::Property);
177 void film_length_change ();
179 void start_audio_stream_if_open ();
181 #if (RTAUDIO_VERSION_MAJOR >= 6)
182 void rtaudio_error_callback(std::string const& error);
183 mutable boost::mutex _last_rtaudio_error_mutex;
184 std::string _last_rtaudio_error;
185 std::string last_rtaudio_error() const;
188 dcpomatic::DCPTime uncorrected_time () const;
189 Frame average_latency () const;
191 bool quick_refresh ();
193 std::shared_ptr<Film> _film;
194 boost::optional<Player> _player;
196 EnumIndexedVector<std::shared_ptr<VideoView>, VideoType> _video_view;
197 bool _coalesce_player_changes = false;
198 std::vector<int> _pending_player_changes;
201 int _audio_channels = 0;
202 unsigned int _audio_block_size = 1024;
203 bool _playing = false;
205 std::shared_ptr<Butler> _butler;
207 std::list<Frame> _latency_history;
208 /** Mutex to protect _latency_history */
209 mutable boost::mutex _latency_history_mutex;
210 int _latency_history_count = 0;
212 boost::optional<int> _dcp_decode_reduction;
214 Optimisation _optimisation = Optimisation::NONE;
216 ClosedCaptionsDialog* _closed_captions_dialog = nullptr;
217 SignLanguageDialog* _sign_language_dialog = nullptr;
219 bool _outline_content = false;
220 boost::optional<dcpomatic::Rect<double>> _outline_subtitles;
221 /** true to pad the viewer panel with black, false to use
222 the normal window background colour.
224 bool _pad_black = false;
226 /** true if an get() is required next time we are idle */
227 bool _idle_get = false;
229 boost::optional<dcpomatic::Rect<float>> _crop_guess;
231 boost::signals2::scoped_connection _config_changed_connection;