Get ccaps by asking the Player, rather than by listening to its emissions,
[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 A wx widget to view `thumbnails' of a Film.
23  */
24
25 #include "lib/film.h"
26 #include "lib/config.h"
27 #include "lib/player_caption.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 preview of a Film.
42  */
43 class FilmViewer : public wxPanel
44 {
45 public:
46         FilmViewer (wxWindow *, bool outline_content = true, bool jump_to_selected = true);
47         ~FilmViewer ();
48
49         void set_film (boost::shared_ptr<Film>);
50         boost::shared_ptr<Film> film () const {
51                 return _film;
52         }
53
54         /** @return our `playhead' position; this may not lie exactly on a frame boundary */
55         DCPTime position () const {
56                 return _video_position;
57         }
58
59         void set_position (DCPTime p);
60         void set_position (boost::shared_ptr<Content> content, ContentTime p);
61         void set_coalesce_player_changes (bool c);
62         void set_dcp_decode_reduction (boost::optional<int> reduction);
63         boost::optional<int> dcp_decode_reduction () const;
64
65         void slow_refresh ();
66         bool quick_refresh ();
67
68         int dropped () const {
69                 return _dropped;
70         }
71
72         void start ();
73         bool stop ();
74         bool playing () const {
75                 return _playing;
76         }
77
78         void back_frame ();
79         void forward_frame ();
80
81         int audio_callback (void* out, unsigned int frames);
82
83         void show_closed_captions ();
84
85         boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
86
87 private:
88         void paint_panel ();
89         void panel_sized (wxSizeEvent &);
90         void slider_moved (bool page);
91         void slider_released ();
92         void play_clicked ();
93         void timer ();
94         void calculate_sizes ();
95         void check_play_state ();
96         void active_jobs_changed (boost::optional<std::string>);
97         void rewind_clicked (wxMouseEvent &);
98         void back_clicked (wxKeyboardState& s);
99         void forward_clicked (wxKeyboardState &);
100         void player_changed (int, bool);
101         void update_position_label ();
102         void update_position_slider ();
103         void get ();
104         void display_player_video ();
105         void seek (DCPTime t, bool accurate);
106         void refresh_panel ();
107         void setup_sensitivity ();
108         void film_changed (Film::Property);
109         DCPTime nudge_amount (wxKeyboardState &);
110         void timecode_clicked ();
111         void frame_number_clicked ();
112         void go_to (DCPTime t);
113         void jump_to_selected_clicked ();
114         void recreate_butler ();
115         void config_changed (Config::Property);
116         DCPTime time () const;
117         Frame average_latency () const;
118         DCPTime one_video_frame () const;
119
120         boost::shared_ptr<Film> _film;
121         boost::shared_ptr<Player> _player;
122
123         wxSizer* _v_sizer;
124         /** The area that we put our image in */
125         wxPanel* _panel;
126         wxCheckBox* _outline_content;
127         wxChoice* _eye;
128         wxCheckBox* _jump_to_selected;
129         wxSlider* _slider;
130         wxButton* _rewind_button;
131         wxButton* _back_button;
132         wxButton* _forward_button;
133         wxStaticText* _frame_number;
134         wxStaticText* _timecode;
135         wxToggleButton* _play_button;
136         wxTimer _timer;
137         bool _coalesce_player_changes;
138         std::list<int> _pending_player_changes;
139         bool _slider_being_moved;
140         bool _was_running_before_slider;
141
142         std::pair<boost::shared_ptr<PlayerVideo>, DCPTime> _player_video;
143         boost::shared_ptr<const Image> _frame;
144         DCPTime _video_position;
145         Position<int> _inter_position;
146         dcp::Size _inter_size;
147
148         /** Size of our output (including padding if we have any) */
149         dcp::Size _out_size;
150         /** Size of the panel that we have available */
151         dcp::Size _panel_size;
152
153         RtAudio _audio;
154         int _audio_channels;
155         unsigned int _audio_block_size;
156         bool _playing;
157         boost::shared_ptr<Butler> _butler;
158
159         std::list<Frame> _latency_history;
160         /** Mutex to protect _latency_history */
161         mutable boost::mutex _latency_history_mutex;
162         int _latency_history_count;
163
164         int _dropped;
165         boost::optional<int> _dcp_decode_reduction;
166
167         ClosedCaptionsDialog* _closed_captions_dialog;
168
169         boost::signals2::scoped_connection _config_changed_connection;
170 };