More enum class additions.
[dcpomatic.git] / src / lib / video_content.h
1 /*
2     Copyright (C) 2013-2020 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 #ifndef DCPOMATIC_VIDEO_CONTENT_H
22 #define DCPOMATIC_VIDEO_CONTENT_H
23
24 #include "colour_conversion.h"
25 #include "dcpomatic_time.h"
26 #include "user_property.h"
27 #include "types.h"
28 #include "content_part.h"
29 #include <boost/thread/mutex.hpp>
30
31 class VideoExaminer;
32 class Ratio;
33 class Film;
34 class Content;
35
36 class VideoContentProperty
37 {
38 public:
39         static int const USE;
40         static int const SIZE;
41         static int const FRAME_TYPE;
42         static int const CROP;
43         static int const SCALE;
44         static int const COLOUR_CONVERSION;
45         static int const FADE_IN;
46         static int const FADE_OUT;
47         static int const RANGE;
48         static int const CUSTOM_RATIO;
49         static int const CUSTOM_SIZE;
50 };
51
52 class VideoContent : public ContentPart, public std::enable_shared_from_this<VideoContent>
53 {
54 public:
55         explicit VideoContent (Content* parent);
56         VideoContent (Content* parent, cxml::ConstNodePtr, int);
57         VideoContent (Content* parent, std::vector<std::shared_ptr<Content> >);
58
59         void as_xml (xmlpp::Node *) const;
60         std::string technical_summary () const;
61         std::string identifier () const;
62         void take_settings_from (std::shared_ptr<const VideoContent> c);
63
64         Frame length () const {
65                 boost::mutex::scoped_lock lm (_mutex);
66                 return _length;
67         }
68
69         Frame length_after_3d_combine () const {
70                 boost::mutex::scoped_lock lm (_mutex);
71                 if (_frame_type == VideoFrameType::THREE_D_ALTERNATE) {
72                         return _length / 2;
73                 }
74
75                 return _length;
76         }
77
78         dcp::Size size () const {
79                 boost::mutex::scoped_lock lm (_mutex);
80                 return _size;
81         }
82
83         void set_frame_type (VideoFrameType);
84
85         void set_left_crop (int);
86         void set_right_crop (int);
87         void set_top_crop (int);
88         void set_bottom_crop (int);
89
90         void set_custom_ratio (boost::optional<float> ratio);
91         void set_custom_size (boost::optional<dcp::Size> size);
92
93         void unset_colour_conversion ();
94         void set_colour_conversion (ColourConversion);
95
96         void set_fade_in (Frame);
97         void set_fade_out (Frame);
98
99         void set_range (VideoRange);
100         void set_use (bool);
101
102         VideoFrameType frame_type () const {
103                 boost::mutex::scoped_lock lm (_mutex);
104                 return _frame_type;
105         }
106
107         Crop crop () const {
108                 boost::mutex::scoped_lock lm (_mutex);
109                 return _crop;
110         }
111
112         int left_crop () const {
113                 boost::mutex::scoped_lock lm (_mutex);
114                 return _crop.left;
115         }
116
117         int right_crop () const {
118                 boost::mutex::scoped_lock lm (_mutex);
119                 return _crop.right;
120         }
121
122         int top_crop () const {
123                 boost::mutex::scoped_lock lm (_mutex);
124                 return _crop.top;
125         }
126
127         int bottom_crop () const {
128                 boost::mutex::scoped_lock lm (_mutex);
129                 return _crop.bottom;
130         }
131
132
133         boost::optional<float> custom_ratio () const {
134                 boost::mutex::scoped_lock lm (_mutex);
135                 return _custom_ratio;
136         }
137
138
139         boost::optional<dcp::Size> custom_size () const {
140                 boost::mutex::scoped_lock lm (_mutex);
141                 return _custom_size;
142         }
143
144
145         boost::optional<ColourConversion> colour_conversion () const {
146                 boost::mutex::scoped_lock lm (_mutex);
147                 return _colour_conversion;
148         }
149
150         boost::optional<double> sample_aspect_ratio () const {
151                 boost::mutex::scoped_lock lm (_mutex);
152                 return _sample_aspect_ratio;
153         }
154
155         bool yuv () const {
156                 boost::mutex::scoped_lock lm (_mutex);
157                 return _yuv;
158         }
159
160         Frame fade_in () const {
161                 boost::mutex::scoped_lock lm (_mutex);
162                 return _fade_in;
163         }
164
165         Frame fade_out () const {
166                 boost::mutex::scoped_lock lm (_mutex);
167                 return _fade_out;
168         }
169
170         VideoRange range () const {
171                 boost::mutex::scoped_lock lm (_mutex);
172                 return _range;
173         }
174
175         bool use () const {
176                 boost::mutex::scoped_lock lm (_mutex);
177                 return _use;
178         }
179
180         /* XXX: names for these? */
181         dcp::Size size_after_3d_split () const;
182         dcp::Size size_after_crop () const;
183         dcp::Size scaled_size (dcp::Size container_size);
184
185         boost::optional<double> fade (std::shared_ptr<const Film> film, Frame) const;
186
187         std::string processing_description (std::shared_ptr<const Film> film);
188
189         void set_length (Frame);
190
191         void take_from_examiner (std::shared_ptr<VideoExaminer>);
192         void add_properties (std::list<UserProperty> &) const;
193
194         void modify_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
195         void modify_trim_start (dcpomatic::ContentTime& pos) const;
196
197         static std::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtr, int);
198
199 private:
200
201         friend struct ffmpeg_pts_offset_test;
202         friend struct best_dcp_frame_rate_test_single;
203         friend struct best_dcp_frame_rate_test_double;
204         friend struct audio_sampling_rate_test;
205         friend struct scaled_size_test1;
206         friend struct scaled_size_test2;
207         friend struct scaled_size_legacy_test;
208
209         void setup_default_colour_conversion ();
210
211         bool _use;
212         Frame _length;
213         boost::optional<ColourConversion> _colour_conversion;
214         dcp::Size _size;
215         VideoFrameType _frame_type;
216         Crop _crop;
217         /** ratio to scale cropped image to (or none to guess); i.e. if set, scale to _custom_ratio:1 */
218         boost::optional<float> _custom_ratio;
219         /** size to scale cropped image to; only used if _custom_ratio is none */
220         boost::optional<dcp::Size> _custom_size;
221         /** ratio obtained from an older metadata file; will be used to set up
222          *  _custom_{ratio,size} (or not, if not required) on the first call to
223          *  scaled_size()
224          */
225         boost::optional<float> _legacy_ratio;
226         /** Sample aspect ratio obtained from the content file's header, if there is one */
227         boost::optional<double> _sample_aspect_ratio;
228         bool _yuv;
229         /** fade in time in content frames */
230         Frame _fade_in;
231         /** fade out time in content frames */
232         Frame _fade_out;
233         VideoRange _range;
234 };
235
236 #endif