2 Copyright (C) 2013-2014 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
24 #include "colour_conversion.h"
29 class VideoContentProperty
32 static int const VIDEO_SIZE;
33 static int const VIDEO_FRAME_RATE;
34 static int const VIDEO_FRAME_TYPE;
35 static int const VIDEO_CROP;
36 static int const VIDEO_SCALE;
37 static int const COLOUR_CONVERSION;
40 class VideoContentScale
44 VideoContentScale (Ratio const *);
45 VideoContentScale (bool);
46 VideoContentScale (boost::shared_ptr<cxml::Node>);
48 libdcp::Size size (boost::shared_ptr<const VideoContent>, libdcp::Size, libdcp::Size) const;
49 std::string id () const;
50 std::string name () const;
51 void as_xml (xmlpp::Node *) const;
53 Ratio const * ratio () const {
61 static void setup_scales ();
62 static std::vector<VideoContentScale> all () {
67 /** a ratio to stretch the content to, or 0 for no stretch */
69 /** true if we want to scale the content */
72 static std::vector<VideoContentScale> _scales;
75 bool operator== (VideoContentScale const & a, VideoContentScale const & b);
76 bool operator!= (VideoContentScale const & a, VideoContentScale const & b);
78 class VideoContent : public virtual Content
83 VideoContent (boost::shared_ptr<const Film>);
84 VideoContent (boost::shared_ptr<const Film>, Time, VideoContent::Frame);
85 VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path);
86 VideoContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>, int);
87 VideoContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
89 void as_xml (xmlpp::Node *) const;
90 std::string technical_summary () const;
91 virtual std::string information () const;
92 virtual std::string identifier () const;
94 VideoContent::Frame video_length () const {
95 boost::mutex::scoped_lock lm (_mutex);
99 VideoContent::Frame video_length_after_3d_combine () const {
100 boost::mutex::scoped_lock lm (_mutex);
101 if (_video_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
102 return _video_length / 2;
105 return _video_length;
108 libdcp::Size video_size () const {
109 boost::mutex::scoped_lock lm (_mutex);
113 float video_frame_rate () const {
114 boost::mutex::scoped_lock lm (_mutex);
115 return _video_frame_rate;
118 float original_video_frame_rate () const {
119 boost::mutex::scoped_lock lm (_mutex);
120 return _original_video_frame_rate;
123 void set_video_frame_type (VideoFrameType);
124 void set_video_frame_rate (float);
126 void set_left_crop (int);
127 void set_right_crop (int);
128 void set_top_crop (int);
129 void set_bottom_crop (int);
131 void set_scale (VideoContentScale);
132 void set_colour_conversion (ColourConversion);
134 VideoFrameType video_frame_type () const {
135 boost::mutex::scoped_lock lm (_mutex);
136 return _video_frame_type;
140 boost::mutex::scoped_lock lm (_mutex);
144 int left_crop () const {
145 boost::mutex::scoped_lock lm (_mutex);
149 int right_crop () const {
150 boost::mutex::scoped_lock lm (_mutex);
154 int top_crop () const {
155 boost::mutex::scoped_lock lm (_mutex);
159 int bottom_crop () const {
160 boost::mutex::scoped_lock lm (_mutex);
164 /** @return Description of how to scale this content (if indeed it should be scaled) */
165 VideoContentScale scale () const {
166 boost::mutex::scoped_lock lm (_mutex);
170 ColourConversion colour_conversion () const {
171 boost::mutex::scoped_lock lm (_mutex);
172 return _colour_conversion;
175 libdcp::Size video_size_after_3d_split () const;
176 libdcp::Size video_size_after_crop () const;
178 VideoContent::Frame time_to_content_video_frames (Time) const;
180 void scale_and_crop_to_fit_width ();
181 void scale_and_crop_to_fit_height ();
184 void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
186 VideoContent::Frame _video_length;
187 float _original_video_frame_rate;
188 float _video_frame_rate;
191 friend class ffmpeg_pts_offset_test;
192 friend class best_dcp_frame_rate_test_single;
193 friend class best_dcp_frame_rate_test_double;
194 friend class audio_sampling_rate_test;
196 void setup_default_colour_conversion ();
198 libdcp::Size _video_size;
199 VideoFrameType _video_frame_type;
201 VideoContentScale _scale;
202 ColourConversion _colour_conversion;