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