Fix alignment.
[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/exception_store.h"
28 #include "lib/signaller.h"
29 #include "lib/timer.h"
30 #include "lib/types.h"
31 #include <boost/signals2.hpp>
32 #include <boost/thread.hpp>
33
34
35 class Image;
36 class wxWindow;
37 class FilmViewer;
38 class Player;
39 class PlayerVideo;
40
41
42 class VideoView : public ExceptionStore, public Signaller
43 {
44 public:
45         VideoView (FilmViewer* viewer);
46         virtual ~VideoView () {}
47
48         VideoView (VideoView const&) = delete;
49         VideoView& operator= (VideoView const&) = delete;
50
51         /** @return the thing displaying the image */
52         virtual wxWindow* get () const = 0;
53         /** Re-make and display the image from the current _player_video */
54         virtual void update () = 0;
55         /** Called when playback starts */
56         virtual void start ();
57         /** Called when playback stops */
58         virtual void stop () {}
59
60         enum NextFrameResult {
61                 FAIL,
62                 AGAIN,
63                 SUCCESS
64         };
65
66         /** Get the next frame and display it; used after seek */
67         virtual NextFrameResult display_next_frame (bool) = 0;
68
69         void clear ();
70         bool reset_metadata (std::shared_ptr<const Film> film, dcp::Size player_video_container_size);
71
72         /** Emitted from the GUI thread when our display changes in size */
73         boost::signals2::signal<void()> Sized;
74         /** Emitted from the GUI thread when a lot of frames are being dropped */
75         boost::signals2::signal<void()> TooManyDropped;
76
77
78         /* Accessors for FilmViewer */
79
80         int dropped () const {
81                 boost::mutex::scoped_lock lm (_mutex);
82                 return _dropped;
83         }
84
85         int errored () const {
86                 boost::mutex::scoped_lock lm (_mutex);
87                 return _errored;
88         }
89
90         int gets () const {
91                 boost::mutex::scoped_lock lm (_mutex);
92                 return _gets;
93         }
94
95         StateTimer const & state_timer () const {
96                 return _state_timer;
97         }
98
99         dcpomatic::DCPTime position () const {
100                 boost::mutex::scoped_lock lm (_mutex);
101                 return _player_video.second;
102         }
103
104
105         /* Setters for FilmViewer so it can tell us our state and
106          * we can then use (thread) safely.
107          */
108
109         void set_video_frame_rate (int r) {
110                 boost::mutex::scoped_lock lm (_mutex);
111                 _video_frame_rate = r;
112         }
113
114         void set_length (dcpomatic::DCPTime len) {
115                 boost::mutex::scoped_lock lm (_mutex);
116                 _length = len;
117         }
118
119         void set_eyes (Eyes eyes) {
120                 boost::mutex::scoped_lock lm (_mutex);
121                 _eyes = eyes;
122         }
123
124         void set_three_d (bool t) {
125                 boost::mutex::scoped_lock lm (_mutex);
126                 _three_d = t;
127         }
128
129 protected:
130         NextFrameResult get_next_frame (bool non_blocking);
131         boost::optional<int> time_until_next_frame () const;
132         dcpomatic::DCPTime one_video_frame () const;
133
134         int video_frame_rate () const {
135                 boost::mutex::scoped_lock lm (_mutex);
136                 return _video_frame_rate;
137         }
138
139         dcpomatic::DCPTime length () const {
140                 boost::mutex::scoped_lock lm (_mutex);
141                 return _length;
142         }
143
144         std::pair<std::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> player_video () const {
145                 boost::mutex::scoped_lock lm (_mutex);
146                 return _player_video;
147         }
148
149         void add_dropped ();
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         struct timeval _dropped_check_period_start;
173         int _errored = 0;
174         int _gets = 0;
175 };
176
177
178 #endif