C++11 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 SCALE;
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, int);
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_left_crop (int);
93         void set_right_crop (int);
94         void set_top_crop (int);
95         void set_bottom_crop (int);
96
97         void set_custom_ratio (boost::optional<float> ratio);
98         void set_custom_size (boost::optional<dcp::Size> size);
99
100         void unset_colour_conversion ();
101         void set_colour_conversion (ColourConversion);
102
103         void set_fade_in (Frame);
104         void set_fade_out (Frame);
105
106         void set_range (VideoRange);
107         void set_use (bool);
108
109         void set_burnt_subtitle_language (boost::optional<dcp::LanguageTag> language);
110
111         VideoFrameType frame_type () const {
112                 boost::mutex::scoped_lock lm (_mutex);
113                 return _frame_type;
114         }
115
116         Crop crop () const {
117                 boost::mutex::scoped_lock lm (_mutex);
118                 return _crop;
119         }
120
121         int left_crop () const {
122                 boost::mutex::scoped_lock lm (_mutex);
123                 return _crop.left;
124         }
125
126         int right_crop () const {
127                 boost::mutex::scoped_lock lm (_mutex);
128                 return _crop.right;
129         }
130
131         int top_crop () const {
132                 boost::mutex::scoped_lock lm (_mutex);
133                 return _crop.top;
134         }
135
136         int bottom_crop () const {
137                 boost::mutex::scoped_lock lm (_mutex);
138                 return _crop.bottom;
139         }
140
141
142         boost::optional<float> custom_ratio () const {
143                 boost::mutex::scoped_lock lm (_mutex);
144                 return _custom_ratio;
145         }
146
147
148         boost::optional<dcp::Size> custom_size () const {
149                 boost::mutex::scoped_lock lm (_mutex);
150                 return _custom_size;
151         }
152
153
154         boost::optional<ColourConversion> colour_conversion () const {
155                 boost::mutex::scoped_lock lm (_mutex);
156                 return _colour_conversion;
157         }
158
159         boost::optional<double> sample_aspect_ratio () const {
160                 boost::mutex::scoped_lock lm (_mutex);
161                 return _sample_aspect_ratio;
162         }
163
164         bool yuv () const {
165                 boost::mutex::scoped_lock lm (_mutex);
166                 return _yuv;
167         }
168
169         Frame fade_in () const {
170                 boost::mutex::scoped_lock lm (_mutex);
171                 return _fade_in;
172         }
173
174         Frame fade_out () const {
175                 boost::mutex::scoped_lock lm (_mutex);
176                 return _fade_out;
177         }
178
179         VideoRange range () const {
180                 boost::mutex::scoped_lock lm (_mutex);
181                 return _range;
182         }
183
184         bool use () const {
185                 boost::mutex::scoped_lock lm (_mutex);
186                 return _use;
187         }
188
189         boost::optional<dcp::LanguageTag> burnt_subtitle_language () const {
190                 boost::mutex::scoped_lock lm (_mutex);
191                 return _burnt_subtitle_language;
192         }
193
194
195         /* XXX: names for these? */
196         dcp::Size size_after_3d_split () const;
197         dcp::Size size_after_crop () const;
198         dcp::Size scaled_size (dcp::Size container_size);
199
200         boost::optional<double> fade (std::shared_ptr<const Film> film, Frame) const;
201
202         std::string processing_description (std::shared_ptr<const Film> film);
203
204         void set_length (Frame);
205
206         void take_from_examiner (std::shared_ptr<VideoExaminer>);
207         void add_properties (std::list<UserProperty> &) const;
208
209         void modify_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
210         void modify_trim_start (dcpomatic::ContentTime& pos) const;
211
212         static std::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtr, int);
213
214 private:
215
216         friend struct ffmpeg_pts_offset_test;
217         friend struct best_dcp_frame_rate_test_single;
218         friend struct best_dcp_frame_rate_test_double;
219         friend struct audio_sampling_rate_test;
220         friend struct scaled_size_test1;
221         friend struct scaled_size_test2;
222         friend struct scaled_size_legacy_test;
223
224         void setup_default_colour_conversion ();
225
226         bool _use;
227         Frame _length;
228         boost::optional<ColourConversion> _colour_conversion;
229         dcp::Size _size;
230         VideoFrameType _frame_type;
231         Crop _crop;
232         /** ratio to scale cropped image to (or none to guess); i.e. if set, scale to _custom_ratio:1 */
233         boost::optional<float> _custom_ratio;
234         /** size to scale cropped image to; only used if _custom_ratio is none */
235         boost::optional<dcp::Size> _custom_size;
236         /** ratio obtained from an older metadata file; will be used to set up
237          *  _custom_{ratio,size} (or not, if not required) on the first call to
238          *  scaled_size()
239          */
240         boost::optional<float> _legacy_ratio;
241         /** Sample aspect ratio obtained from the content file's header, if there is one */
242         boost::optional<double> _sample_aspect_ratio;
243         bool _yuv;
244         /** fade in time in content frames */
245         Frame _fade_in;
246         /** fade out time in content frames */
247         Frame _fade_out;
248         VideoRange _range;
249         boost::optional<dcp::LanguageTag> _burnt_subtitle_language;
250 };
251
252
253 #endif