Innocuous build fixes.
[dcpomatic.git] / src / lib / video_content.h
1 /*
2     Copyright (C) 2013-2016 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 "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>
29
30 class VideoExaminer;
31 class Ratio;
32 class Film;
33
34 class VideoContentProperty
35 {
36 public:
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;
45 };
46
47 class VideoContent
48 {
49 public:
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> >);
53
54         void as_xml (xmlpp::Node *) const;
55         std::string technical_summary () const;
56         std::string identifier () const;
57
58         void set_default_colour_conversion ();
59
60         Frame video_length () const {
61                 boost::mutex::scoped_lock lm (_mutex);
62                 return _video_length;
63         }
64
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;
69                 }
70
71                 return _video_length;
72         }
73
74         dcp::Size video_size () const {
75                 boost::mutex::scoped_lock lm (_mutex);
76                 return _video_size;
77         }
78
79         double video_frame_rate () const;
80
81         /** @return true if this content has a specific video frame rate, false
82          *  if it should use the DCP's rate.
83          */
84         bool has_own_video_frame_rate () const {
85                 boost::mutex::scoped_lock lm (_mutex);
86                 return static_cast<bool>(_video_frame_rate);
87         }
88
89         void set_video_frame_type (VideoFrameType);
90         void set_video_frame_rate (double);
91
92         void set_left_crop (int);
93         void set_right_crop (int);
94         void set_top_crop (int);
95         void set_bottom_crop (int);
96
97         void set_scale (VideoContentScale);
98         void unset_colour_conversion ();
99         void set_colour_conversion (ColourConversion);
100
101         void set_fade_in (Frame);
102         void set_fade_out (Frame);
103
104         VideoFrameType video_frame_type () const {
105                 boost::mutex::scoped_lock lm (_mutex);
106                 return _video_frame_type;
107         }
108
109         Crop crop () const {
110                 boost::mutex::scoped_lock lm (_mutex);
111                 return _crop;
112         }
113
114         int left_crop () const {
115                 boost::mutex::scoped_lock lm (_mutex);
116                 return _crop.left;
117         }
118
119         int right_crop () const {
120                 boost::mutex::scoped_lock lm (_mutex);
121                 return _crop.right;
122         }
123
124         int top_crop () const {
125                 boost::mutex::scoped_lock lm (_mutex);
126                 return _crop.top;
127         }
128
129         int bottom_crop () const {
130                 boost::mutex::scoped_lock lm (_mutex);
131                 return _crop.bottom;
132         }
133
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);
137                 return _scale;
138         }
139
140         boost::optional<ColourConversion> colour_conversion () const {
141                 boost::mutex::scoped_lock lm (_mutex);
142                 return _colour_conversion;
143         }
144
145         boost::optional<double> sample_aspect_ratio () const {
146                 boost::mutex::scoped_lock lm (_mutex);
147                 return _sample_aspect_ratio;
148         }
149
150         bool yuv () const {
151                 boost::mutex::scoped_lock lm (_mutex);
152                 return _yuv;
153         }
154
155         Frame fade_in () const {
156                 boost::mutex::scoped_lock lm (_mutex);
157                 return _fade_in;
158         }
159
160         Frame fade_out () const {
161                 boost::mutex::scoped_lock lm (_mutex);
162                 return _fade_out;
163         }
164
165         dcp::Size video_size_after_3d_split () const;
166         dcp::Size video_size_after_crop () const;
167
168         ContentTime dcp_time_to_content_time (DCPTime) const;
169
170         boost::optional<double> fade (Frame) const;
171
172         void scale_and_crop_to_fit_width ();
173         void scale_and_crop_to_fit_height ();
174
175         std::string processing_description () const;
176
177 private:
178         void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
179         void add_properties (std::list<UserProperty> &) const;
180
181         boost::weak_ptr<const Film> _film;
182         mutable boost::mutex _mutex;
183         Frame _video_length;
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;
187
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;
192
193         void setup_default_colour_conversion ();
194
195         dcp::Size _video_size;
196         VideoFrameType _video_frame_type;
197         Crop _crop;
198         VideoContentScale _scale;
199         /** Sample aspect ratio obtained from the content file's header,
200             if there is one.
201         */
202         boost::optional<double> _sample_aspect_ratio;
203         bool _yuv;
204         Frame _fade_in;
205         Frame _fade_out;
206 };
207
208 #endif