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