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