Various improvements to the content properties dialogue (including #791).
[dcpomatic.git] / src / lib / video_content.h
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef DCPOMATIC_VIDEO_CONTENT_H
21 #define DCPOMATIC_VIDEO_CONTENT_H
22
23 #include "content.h"
24 #include "colour_conversion.h"
25 #include "video_content_scale.h"
26
27 class VideoExaminer;
28 class Ratio;
29
30 class VideoContentProperty
31 {
32 public:
33         static int const VIDEO_SIZE;
34         static int const VIDEO_FRAME_RATE;
35         static int const VIDEO_FRAME_TYPE;
36         static int const VIDEO_CROP;
37         static int const VIDEO_SCALE;
38         static int const COLOUR_CONVERSION;
39         static int const VIDEO_FADE_IN;
40         static int const VIDEO_FADE_OUT;
41 };
42
43 class VideoContent : public virtual Content
44 {
45 public:
46         VideoContent (boost::shared_ptr<const Film>);
47         VideoContent (boost::shared_ptr<const Film>, DCPTime, Frame);
48         VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path);
49         VideoContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
50         VideoContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
51
52         void as_xml (xmlpp::Node *) const;
53         std::string technical_summary () const;
54         virtual std::string identifier () const;
55
56         virtual void set_default_colour_conversion ();
57
58         Frame video_length () const {
59                 boost::mutex::scoped_lock lm (_mutex);
60                 return _video_length;
61         }
62
63         Frame video_length_after_3d_combine () const {
64                 boost::mutex::scoped_lock lm (_mutex);
65                 if (_video_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
66                         return _video_length / 2;
67                 }
68
69                 return _video_length;
70         }
71
72         dcp::Size video_size () const {
73                 boost::mutex::scoped_lock lm (_mutex);
74                 return _video_size;
75         }
76
77         double video_frame_rate () const;
78
79         /** @return true if this content has a specific video frame rate, false
80          *  if it should use the DCP's rate.
81          */
82         bool has_own_video_frame_rate () const {
83                 boost::mutex::scoped_lock lm (_mutex);
84                 return static_cast<bool>(_video_frame_rate);
85         }
86
87         void set_video_frame_type (VideoFrameType);
88         void set_video_frame_rate (double);
89
90         void set_left_crop (int);
91         void set_right_crop (int);
92         void set_top_crop (int);
93         void set_bottom_crop (int);
94
95         void set_scale (VideoContentScale);
96         void unset_colour_conversion ();
97         void set_colour_conversion (ColourConversion);
98
99         void set_fade_in (Frame);
100         void set_fade_out (Frame);
101
102         VideoFrameType video_frame_type () const {
103                 boost::mutex::scoped_lock lm (_mutex);
104                 return _video_frame_type;
105         }
106
107         Crop crop () const {
108                 boost::mutex::scoped_lock lm (_mutex);
109                 return _crop;
110         }
111
112         int left_crop () const {
113                 boost::mutex::scoped_lock lm (_mutex);
114                 return _crop.left;
115         }
116
117         int right_crop () const {
118                 boost::mutex::scoped_lock lm (_mutex);
119                 return _crop.right;
120         }
121
122         int top_crop () const {
123                 boost::mutex::scoped_lock lm (_mutex);
124                 return _crop.top;
125         }
126
127         int bottom_crop () const {
128                 boost::mutex::scoped_lock lm (_mutex);
129                 return _crop.bottom;
130         }
131
132         /** @return Description of how to scale this content (if indeed it should be scaled) */
133         VideoContentScale scale () const {
134                 boost::mutex::scoped_lock lm (_mutex);
135                 return _scale;
136         }
137
138         boost::optional<ColourConversion> colour_conversion () const {
139                 boost::mutex::scoped_lock lm (_mutex);
140                 return _colour_conversion;
141         }
142
143         boost::optional<double> sample_aspect_ratio () const {
144                 boost::mutex::scoped_lock lm (_mutex);
145                 return _sample_aspect_ratio;
146         }
147
148         bool yuv () const {
149                 boost::mutex::scoped_lock lm (_mutex);
150                 return _yuv;
151         }
152
153         Frame fade_in () const {
154                 boost::mutex::scoped_lock lm (_mutex);
155                 return _fade_in;
156         }
157
158         Frame fade_out () const {
159                 boost::mutex::scoped_lock lm (_mutex);
160                 return _fade_out;
161         }
162
163         dcp::Size video_size_after_3d_split () const;
164         dcp::Size video_size_after_crop () const;
165
166         ContentTime dcp_time_to_content_time (DCPTime) const;
167
168         boost::optional<double> fade (Frame) const;
169
170         void scale_and_crop_to_fit_width ();
171         void scale_and_crop_to_fit_height ();
172
173         std::string processing_description () const;
174
175 protected:
176         void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
177         void add_properties (std::list<UserProperty> &) const;
178
179         Frame _video_length;
180         /** Video frame rate, or not set if this content should use the DCP's frame rate */
181         boost::optional<double> _video_frame_rate;
182         boost::optional<ColourConversion> _colour_conversion;
183
184 private:
185         friend struct ffmpeg_pts_offset_test;
186         friend struct best_dcp_frame_rate_test_single;
187         friend struct best_dcp_frame_rate_test_double;
188         friend struct audio_sampling_rate_test;
189
190         void setup_default_colour_conversion ();
191
192         dcp::Size _video_size;
193         VideoFrameType _video_frame_type;
194         Crop _crop;
195         VideoContentScale _scale;
196         /** Sample aspect ratio obtained from the content file's header,
197             if there is one.
198         */
199         boost::optional<double> _sample_aspect_ratio;
200         bool _yuv;
201         Frame _fade_in;
202         Frame _fade_out;
203 };
204
205 #endif