2 Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef DCPOMATIC_VIDEO_CONTENT_H
21 #define DCPOMATIC_VIDEO_CONTENT_H
23 #include "colour_conversion.h"
24 #include "video_content_scale.h"
25 #include "dcpomatic_time.h"
26 #include "user_property.h"
27 #include <boost/thread/mutex.hpp>
28 #include <boost/weak_ptr.hpp>
34 class VideoContentProperty
37 static int const VIDEO_SIZE;
38 static int const VIDEO_FRAME_RATE;
39 static int const VIDEO_FRAME_TYPE;
40 static int const VIDEO_CROP;
41 static int const VIDEO_SCALE;
42 static int const COLOUR_CONVERSION;
43 static int const VIDEO_FADE_IN;
44 static int const VIDEO_FADE_OUT;
50 VideoContent (boost::shared_ptr<const Film>);
51 VideoContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
52 VideoContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
54 void as_xml (xmlpp::Node *) const;
55 std::string technical_summary () const;
56 std::string identifier () const;
58 void set_default_colour_conversion ();
60 Frame video_length () const {
61 boost::mutex::scoped_lock lm (_mutex);
65 Frame video_length_after_3d_combine () const {
66 boost::mutex::scoped_lock lm (_mutex);
67 if (_video_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
68 return _video_length / 2;
74 dcp::Size video_size () const {
75 boost::mutex::scoped_lock lm (_mutex);
79 double video_frame_rate () const;
81 /** @return true if this content has a specific video frame rate, false
82 * if it should use the DCP's rate.
84 bool has_own_video_frame_rate () const {
85 boost::mutex::scoped_lock lm (_mutex);
86 return static_cast<bool>(_video_frame_rate);
89 void set_video_frame_type (VideoFrameType);
90 void set_video_frame_rate (double);
92 void set_left_crop (int);
93 void set_right_crop (int);
94 void set_top_crop (int);
95 void set_bottom_crop (int);
97 void set_scale (VideoContentScale);
98 void unset_colour_conversion ();
99 void set_colour_conversion (ColourConversion);
101 void set_fade_in (Frame);
102 void set_fade_out (Frame);
104 VideoFrameType video_frame_type () const {
105 boost::mutex::scoped_lock lm (_mutex);
106 return _video_frame_type;
110 boost::mutex::scoped_lock lm (_mutex);
114 int left_crop () const {
115 boost::mutex::scoped_lock lm (_mutex);
119 int right_crop () const {
120 boost::mutex::scoped_lock lm (_mutex);
124 int top_crop () const {
125 boost::mutex::scoped_lock lm (_mutex);
129 int bottom_crop () const {
130 boost::mutex::scoped_lock lm (_mutex);
134 /** @return Description of how to scale this content (if indeed it should be scaled) */
135 VideoContentScale scale () const {
136 boost::mutex::scoped_lock lm (_mutex);
140 boost::optional<ColourConversion> colour_conversion () const {
141 boost::mutex::scoped_lock lm (_mutex);
142 return _colour_conversion;
145 boost::optional<double> sample_aspect_ratio () const {
146 boost::mutex::scoped_lock lm (_mutex);
147 return _sample_aspect_ratio;
151 boost::mutex::scoped_lock lm (_mutex);
155 Frame fade_in () const {
156 boost::mutex::scoped_lock lm (_mutex);
160 Frame fade_out () const {
161 boost::mutex::scoped_lock lm (_mutex);
165 dcp::Size video_size_after_3d_split () const;
166 dcp::Size video_size_after_crop () const;
168 ContentTime dcp_time_to_content_time (DCPTime) const;
170 boost::optional<double> fade (Frame) const;
172 void scale_and_crop_to_fit_width ();
173 void scale_and_crop_to_fit_height ();
175 std::string processing_description () const;
178 void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
179 void add_properties (std::list<UserProperty> &) const;
181 boost::weak_ptr<const Film> _film;
182 mutable boost::mutex _mutex;
184 /** Video frame rate, or not set if this content should use the DCP's frame rate */
185 boost::optional<double> _video_frame_rate;
186 boost::optional<ColourConversion> _colour_conversion;
188 friend struct ffmpeg_pts_offset_test;
189 friend struct best_dcp_frame_rate_test_single;
190 friend struct best_dcp_frame_rate_test_double;
191 friend struct audio_sampling_rate_test;
193 void setup_default_colour_conversion ();
195 dcp::Size _video_size;
196 VideoFrameType _video_frame_type;
198 VideoContentScale _scale;
199 /** Sample aspect ratio obtained from the content file's header,
202 boost::optional<double> _sample_aspect_ratio;