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 (cxml::NodePtr);
48 dcp::Size size (boost::shared_ptr<const VideoContent>, dcp::Size, dcp::Size, int round) 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 () {
65 static VideoContentScale from_id (std::string id);
68 /** a ratio to stretch the content to, or 0 for no stretch */
70 /** true if we want to scale the content */
73 static std::vector<VideoContentScale> _scales;
76 bool operator== (VideoContentScale const & a, VideoContentScale const & b);
77 bool operator!= (VideoContentScale const & a, VideoContentScale const & b);
79 class VideoContent : public virtual Content
84 VideoContent (boost::shared_ptr<const Film>);
85 VideoContent (boost::shared_ptr<const Film>, DCPTime, ContentTime);
86 VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path);
87 VideoContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
88 VideoContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
90 void as_xml (xmlpp::Node *) const;
91 std::string technical_summary () const;
92 virtual std::string information () const;
93 virtual std::string identifier () const;
95 ContentTime video_length () const {
96 boost::mutex::scoped_lock lm (_mutex);
100 ContentTime video_length_after_3d_combine () const {
101 boost::mutex::scoped_lock lm (_mutex);
102 if (_video_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
103 return ContentTime (_video_length.get() / 2);
106 return _video_length;
109 dcp::Size video_size () const {
110 boost::mutex::scoped_lock lm (_mutex);
114 float video_frame_rate () const {
115 boost::mutex::scoped_lock lm (_mutex);
116 return _video_frame_rate;
119 void set_video_frame_type (VideoFrameType);
120 void set_video_frame_rate (float);
122 void set_left_crop (int);
123 void set_right_crop (int);
124 void set_top_crop (int);
125 void set_bottom_crop (int);
127 void set_scale (VideoContentScale);
128 void set_colour_conversion (ColourConversion);
130 VideoFrameType video_frame_type () const {
131 boost::mutex::scoped_lock lm (_mutex);
132 return _video_frame_type;
136 boost::mutex::scoped_lock lm (_mutex);
140 int left_crop () const {
141 boost::mutex::scoped_lock lm (_mutex);
145 int right_crop () const {
146 boost::mutex::scoped_lock lm (_mutex);
150 int top_crop () const {
151 boost::mutex::scoped_lock lm (_mutex);
155 int bottom_crop () const {
156 boost::mutex::scoped_lock lm (_mutex);
160 /** @return Description of how to scale this content (if indeed it should be scaled) */
161 VideoContentScale scale () const {
162 boost::mutex::scoped_lock lm (_mutex);
166 ColourConversion colour_conversion () const {
167 boost::mutex::scoped_lock lm (_mutex);
168 return _colour_conversion;
171 dcp::Size video_size_after_3d_split () const;
172 dcp::Size video_size_after_crop () const;
174 ContentTime dcp_time_to_content_time (DCPTime) const;
176 void scale_and_crop_to_fit_width ();
177 void scale_and_crop_to_fit_height ();
180 void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
182 ContentTime _video_length;
183 float _video_frame_rate;
186 friend struct ffmpeg_pts_offset_test;
187 friend struct best_dcp_frame_rate_test_single;
188 friend struct best_dcp_frame_rate_test_double;
189 friend struct audio_sampling_rate_test;
191 void setup_default_colour_conversion ();
193 dcp::Size _video_size;
194 VideoFrameType _video_frame_type;
196 VideoContentScale _scale;
197 ColourConversion _colour_conversion;