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"
28 #include <boost/thread/mutex.hpp>
29 #include <boost/weak_ptr.hpp>
30 #include <boost/enable_shared_from_this.hpp>
37 class VideoContentProperty
40 static int const VIDEO_SIZE;
41 static int const VIDEO_FRAME_RATE;
42 static int const VIDEO_FRAME_TYPE;
43 static int const VIDEO_CROP;
44 static int const VIDEO_SCALE;
45 static int const COLOUR_CONVERSION;
46 static int const VIDEO_FADE_IN;
47 static int const VIDEO_FADE_OUT;
50 class VideoContent : public boost::enable_shared_from_this<VideoContent>
53 VideoContent (Content* parent, boost::shared_ptr<const Film>);
54 VideoContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
55 VideoContent (Content* parent, boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
57 void as_xml (xmlpp::Node *) const;
58 std::string technical_summary () const;
59 std::string identifier () const;
61 void set_default_colour_conversion ();
63 Frame video_length () const {
64 boost::mutex::scoped_lock lm (_mutex);
68 Frame video_length_after_3d_combine () const {
69 boost::mutex::scoped_lock lm (_mutex);
70 if (_video_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
71 return _video_length / 2;
77 dcp::Size video_size () const {
78 boost::mutex::scoped_lock lm (_mutex);
82 double video_frame_rate () const;
84 /** @return true if this content has a specific video frame rate, false
85 * if it should use the DCP's rate.
87 bool has_own_video_frame_rate () const {
88 boost::mutex::scoped_lock lm (_mutex);
89 return static_cast<bool>(_video_frame_rate);
92 void set_video_frame_type (VideoFrameType);
93 void set_video_frame_rate (double);
95 void set_left_crop (int);
96 void set_right_crop (int);
97 void set_top_crop (int);
98 void set_bottom_crop (int);
100 void set_scale (VideoContentScale);
101 void unset_colour_conversion ();
102 void set_colour_conversion (ColourConversion);
104 void set_fade_in (Frame);
105 void set_fade_out (Frame);
107 VideoFrameType video_frame_type () const {
108 boost::mutex::scoped_lock lm (_mutex);
109 return _video_frame_type;
113 boost::mutex::scoped_lock lm (_mutex);
117 int left_crop () const {
118 boost::mutex::scoped_lock lm (_mutex);
122 int right_crop () const {
123 boost::mutex::scoped_lock lm (_mutex);
127 int top_crop () const {
128 boost::mutex::scoped_lock lm (_mutex);
132 int bottom_crop () const {
133 boost::mutex::scoped_lock lm (_mutex);
137 /** @return Description of how to scale this content (if indeed it should be scaled) */
138 VideoContentScale scale () const {
139 boost::mutex::scoped_lock lm (_mutex);
143 boost::optional<ColourConversion> colour_conversion () const {
144 boost::mutex::scoped_lock lm (_mutex);
145 return _colour_conversion;
148 boost::optional<double> sample_aspect_ratio () const {
149 boost::mutex::scoped_lock lm (_mutex);
150 return _sample_aspect_ratio;
154 boost::mutex::scoped_lock lm (_mutex);
158 Frame fade_in () const {
159 boost::mutex::scoped_lock lm (_mutex);
163 Frame fade_out () const {
164 boost::mutex::scoped_lock lm (_mutex);
168 dcp::Size video_size_after_3d_split () const;
169 dcp::Size video_size_after_crop () const;
171 ContentTime dcp_time_to_content_time (DCPTime) const;
173 boost::optional<double> fade (Frame) const;
175 void scale_and_crop_to_fit_width ();
176 void scale_and_crop_to_fit_height ();
178 std::string processing_description () const;
180 void set_video_length (Frame);
182 void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
183 void add_properties (std::list<UserProperty> &) const;
188 boost::weak_ptr<const Film> _film;
189 mutable boost::mutex _mutex;
191 /** Video frame rate, or not set if this content should use the DCP's frame rate */
192 boost::optional<double> _video_frame_rate;
193 boost::optional<ColourConversion> _colour_conversion;
195 friend struct ffmpeg_pts_offset_test;
196 friend struct best_dcp_frame_rate_test_single;
197 friend struct best_dcp_frame_rate_test_double;
198 friend struct audio_sampling_rate_test;
200 void setup_default_colour_conversion ();
202 dcp::Size _video_size;
203 VideoFrameType _video_frame_type;
205 VideoContentScale _scale;
206 /** Sample aspect ratio obtained from the content file's header,
209 boost::optional<double> _sample_aspect_ratio;