2 Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 #ifndef DCPOMATIC_VIDEO_CONTENT_H
22 #define DCPOMATIC_VIDEO_CONTENT_H
24 #include "colour_conversion.h"
25 #include "dcpomatic_time.h"
26 #include "user_property.h"
28 #include "content_part.h"
29 #include <boost/thread/mutex.hpp>
36 class VideoContentProperty
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;
52 class VideoContent : public ContentPart, public std::enable_shared_from_this<VideoContent>
55 explicit VideoContent (Content* parent);
56 VideoContent (Content* parent, cxml::ConstNodePtr, int);
57 VideoContent (Content* parent, std::vector<std::shared_ptr<Content> >);
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);
64 Frame length () const {
65 boost::mutex::scoped_lock lm (_mutex);
69 Frame length_after_3d_combine () const {
70 boost::mutex::scoped_lock lm (_mutex);
71 if (_frame_type == VideoFrameType::THREE_D_ALTERNATE) {
78 dcp::Size size () const {
79 boost::mutex::scoped_lock lm (_mutex);
83 void set_frame_type (VideoFrameType);
85 void set_left_crop (int);
86 void set_right_crop (int);
87 void set_top_crop (int);
88 void set_bottom_crop (int);
90 void set_custom_ratio (boost::optional<float> ratio);
91 void set_custom_size (boost::optional<dcp::Size> size);
93 void unset_colour_conversion ();
94 void set_colour_conversion (ColourConversion);
96 void set_fade_in (Frame);
97 void set_fade_out (Frame);
99 void set_range (VideoRange);
102 VideoFrameType frame_type () const {
103 boost::mutex::scoped_lock lm (_mutex);
108 boost::mutex::scoped_lock lm (_mutex);
112 int left_crop () const {
113 boost::mutex::scoped_lock lm (_mutex);
117 int right_crop () const {
118 boost::mutex::scoped_lock lm (_mutex);
122 int top_crop () const {
123 boost::mutex::scoped_lock lm (_mutex);
127 int bottom_crop () const {
128 boost::mutex::scoped_lock lm (_mutex);
133 boost::optional<float> custom_ratio () const {
134 boost::mutex::scoped_lock lm (_mutex);
135 return _custom_ratio;
139 boost::optional<dcp::Size> custom_size () const {
140 boost::mutex::scoped_lock lm (_mutex);
145 boost::optional<ColourConversion> colour_conversion () const {
146 boost::mutex::scoped_lock lm (_mutex);
147 return _colour_conversion;
150 boost::optional<double> sample_aspect_ratio () const {
151 boost::mutex::scoped_lock lm (_mutex);
152 return _sample_aspect_ratio;
156 boost::mutex::scoped_lock lm (_mutex);
160 Frame fade_in () const {
161 boost::mutex::scoped_lock lm (_mutex);
165 Frame fade_out () const {
166 boost::mutex::scoped_lock lm (_mutex);
170 VideoRange range () const {
171 boost::mutex::scoped_lock lm (_mutex);
176 boost::mutex::scoped_lock lm (_mutex);
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);
185 boost::optional<double> fade (std::shared_ptr<const Film> film, Frame) const;
187 std::string processing_description (std::shared_ptr<const Film> film);
189 void set_length (Frame);
191 void take_from_examiner (std::shared_ptr<VideoExaminer>);
192 void add_properties (std::list<UserProperty> &) const;
194 void modify_position (std::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
195 void modify_trim_start (dcpomatic::ContentTime& pos) const;
197 static std::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtr, int);
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;
209 void setup_default_colour_conversion ();
213 boost::optional<ColourConversion> _colour_conversion;
215 VideoFrameType _frame_type;
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
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;
229 /** fade in time in content frames */
231 /** fade out time in content frames */