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