C++11 tidying.
[dcpomatic.git] / src / wx / video_view.h
1 /*
2     Copyright (C) 2019-2021 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
22 #ifndef DCPOMATIC_VIDEO_VIEW_H
23 #define DCPOMATIC_VIDEO_VIEW_H
24
25
26 #include "lib/dcpomatic_time.h"
27 #include "lib/timer.h"
28 #include "lib/types.h"
29 #include "lib/exception_store.h"
30 #include <boost/signals2.hpp>
31 #include <boost/thread.hpp>
32
33
34 class Image;
35 class wxWindow;
36 class FilmViewer;
37 class Player;
38 class PlayerVideo;
39
40
41 class VideoView : public ExceptionStore
42 {
43 public:
44         VideoView (FilmViewer* viewer);
45         virtual ~VideoView () {}
46
47         VideoView (VideoView const&) = delete;
48         VideoView& operator= (VideoView const&) = delete;
49
50         /** @return the thing displaying the image */
51         virtual wxWindow* get () const = 0;
52         /** Re-make and display the image from the current _player_video */
53         virtual void update () = 0;
54         /** Called when playback starts */
55         virtual void start ();
56         /** Called when playback stops */
57         virtual void stop () {}
58
59         enum NextFrameResult {
60                 FAIL,
61                 AGAIN,
62                 SUCCESS
63         };
64
65         /** Get the next frame and display it; used after seek */
66         virtual NextFrameResult display_next_frame (bool) = 0;
67
68         void clear ();
69         bool reset_metadata (std::shared_ptr<const Film> film, dcp::Size player_video_container_size);
70
71         /** Emitted from the GUI thread when our display changes in size */
72         boost::signals2::signal<void()> Sized;
73
74
75         /* Accessors for FilmViewer */
76
77         int dropped () const {
78                 boost::mutex::scoped_lock lm (_mutex);
79                 return _dropped;
80         }
81
82         int errored () const {
83                 boost::mutex::scoped_lock lm (_mutex);
84                 return _errored;
85         }
86
87         int gets () const {
88                 boost::mutex::scoped_lock lm (_mutex);
89                 return _gets;
90         }
91
92         StateTimer const & state_timer () const {
93                 return _state_timer;
94         }
95
96         dcpomatic::DCPTime position () const {
97                 boost::mutex::scoped_lock lm (_mutex);
98                 return _player_video.second;
99         }
100
101
102         /* Setters for FilmViewer so it can tell us our state and
103          * we can then use (thread) safely.
104          */
105
106         void set_video_frame_rate (int r) {
107                 boost::mutex::scoped_lock lm (_mutex);
108                 _video_frame_rate = r;
109         }
110
111         void set_length (dcpomatic::DCPTime len) {
112                 boost::mutex::scoped_lock lm (_mutex);
113                 _length = len;
114         }
115
116         void set_eyes (Eyes eyes) {
117                 boost::mutex::scoped_lock lm (_mutex);
118                 _eyes = eyes;
119         }
120
121         void set_three_d (bool t) {
122                 boost::mutex::scoped_lock lm (_mutex);
123                 _three_d = t;
124         }
125
126 protected:
127         NextFrameResult get_next_frame (bool non_blocking);
128         boost::optional<int> time_until_next_frame () const;
129         dcpomatic::DCPTime one_video_frame () const;
130
131         int video_frame_rate () const {
132                 boost::mutex::scoped_lock lm (_mutex);
133                 return _video_frame_rate;
134         }
135
136         dcpomatic::DCPTime length () const {
137                 boost::mutex::scoped_lock lm (_mutex);
138                 return _length;
139         }
140
141         std::pair<std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> player_video () const {
142                 boost::mutex::scoped_lock lm (_mutex);
143                 return _player_video;
144         }
145
146         void add_dropped () {
147                 boost::mutex::scoped_lock lm (_mutex);
148                 ++_dropped;
149         }
150
151         void add_get () {
152                 boost::mutex::scoped_lock lm (_mutex);
153                 ++_gets;
154         }
155
156         FilmViewer* _viewer;
157
158         StateTimer _state_timer;
159
160 private:
161         /** Mutex protecting all the state in this class */
162         mutable boost::mutex _mutex;
163
164         std::pair<std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> _player_video;
165         int _video_frame_rate = 0;
166         /** length of the film we are playing, or 0 if there is none */
167         dcpomatic::DCPTime _length;
168         Eyes _eyes = Eyes::LEFT;
169         bool _three_d = false;
170
171         int _dropped = 0;
172         int _errored = 0;
173         int _gets = 0;
174 };
175
176
177 #endif