Basic ability to set video range (JPEG/MPEG) at least for YUV content. May not work...
[dcpomatic.git] / src / lib / video_content.h
1 /*
2     Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #ifndef DCPOMATIC_VIDEO_CONTENT_H
22 #define DCPOMATIC_VIDEO_CONTENT_H
23
24 #include "colour_conversion.h"
25 #include "video_content_scale.h"
26 #include "dcpomatic_time.h"
27 #include "user_property.h"
28 #include "types.h"
29 #include "content_part.h"
30 #include <boost/thread/mutex.hpp>
31 #include <boost/weak_ptr.hpp>
32 #include <boost/enable_shared_from_this.hpp>
33
34 class VideoExaminer;
35 class Ratio;
36 class Film;
37 class Content;
38
39 class VideoContentProperty
40 {
41 public:
42         static int const SIZE;
43         static int const FRAME_TYPE;
44         static int const CROP;
45         static int const SCALE;
46         static int const COLOUR_CONVERSION;
47         static int const FADE_IN;
48         static int const FADE_OUT;
49         static int const RANGE;
50 };
51
52 class VideoContent : public ContentPart, public boost::enable_shared_from_this<VideoContent>
53 {
54 public:
55         explicit VideoContent (Content* parent);
56         VideoContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
57
58         void as_xml (xmlpp::Node *) const;
59         std::string technical_summary () const;
60         std::string identifier () const;
61         void take_settings_from (boost::shared_ptr<const VideoContent> c);
62
63         Frame length () const {
64                 boost::mutex::scoped_lock lm (_mutex);
65                 return _length;
66         }
67
68         Frame length_after_3d_combine () const {
69                 boost::mutex::scoped_lock lm (_mutex);
70                 if (_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
71                         return _length / 2;
72                 }
73
74                 return _length;
75         }
76
77         dcp::Size size () const {
78                 boost::mutex::scoped_lock lm (_mutex);
79                 return _size;
80         }
81
82         void set_frame_type (VideoFrameType);
83
84         void set_left_crop (int);
85         void set_right_crop (int);
86         void set_top_crop (int);
87         void set_bottom_crop (int);
88
89         void set_scale (VideoContentScale);
90         void unset_colour_conversion ();
91         void set_colour_conversion (ColourConversion);
92
93         void set_fade_in (Frame);
94         void set_fade_out (Frame);
95
96         void set_range (VideoRange);
97
98         VideoFrameType frame_type () const {
99                 boost::mutex::scoped_lock lm (_mutex);
100                 return _frame_type;
101         }
102
103         Crop crop () const {
104                 boost::mutex::scoped_lock lm (_mutex);
105                 return _crop;
106         }
107
108         int left_crop () const {
109                 boost::mutex::scoped_lock lm (_mutex);
110                 return _crop.left;
111         }
112
113         int right_crop () const {
114                 boost::mutex::scoped_lock lm (_mutex);
115                 return _crop.right;
116         }
117
118         int top_crop () const {
119                 boost::mutex::scoped_lock lm (_mutex);
120                 return _crop.top;
121         }
122
123         int bottom_crop () const {
124                 boost::mutex::scoped_lock lm (_mutex);
125                 return _crop.bottom;
126         }
127
128         /** @return Description of how to scale this content (if indeed it should be scaled) */
129         VideoContentScale scale () const {
130                 boost::mutex::scoped_lock lm (_mutex);
131                 return _scale;
132         }
133
134         boost::optional<ColourConversion> colour_conversion () const {
135                 boost::mutex::scoped_lock lm (_mutex);
136                 return _colour_conversion;
137         }
138
139         boost::optional<double> sample_aspect_ratio () const {
140                 boost::mutex::scoped_lock lm (_mutex);
141                 return _sample_aspect_ratio;
142         }
143
144         bool yuv () const {
145                 boost::mutex::scoped_lock lm (_mutex);
146                 return _yuv;
147         }
148
149         Frame fade_in () const {
150                 boost::mutex::scoped_lock lm (_mutex);
151                 return _fade_in;
152         }
153
154         Frame fade_out () const {
155                 boost::mutex::scoped_lock lm (_mutex);
156                 return _fade_out;
157         }
158
159         VideoRange range () const {
160                 boost::mutex::scoped_lock lm (_mutex);
161                 return _range;
162         }
163
164         dcp::Size size_after_3d_split () const;
165         dcp::Size size_after_crop () const;
166
167         boost::optional<double> fade (boost::shared_ptr<const Film> film, Frame) const;
168
169         void scale_and_crop_to_fit_width (boost::shared_ptr<const Film> film);
170         void scale_and_crop_to_fit_height (boost::shared_ptr<const Film> film);
171
172         std::string processing_description (boost::shared_ptr<const Film> film) const;
173
174         void set_length (Frame);
175
176         void take_from_examiner (boost::shared_ptr<VideoExaminer>);
177         void add_properties (std::list<UserProperty> &) const;
178
179         void modify_position (boost::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
180         void modify_trim_start (dcpomatic::ContentTime& pos) const;
181
182         static boost::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtr, int);
183
184 private:
185
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;
190
191         VideoContent (Content* parent, cxml::ConstNodePtr, int);
192         void setup_default_colour_conversion ();
193
194         Frame _length;
195         boost::optional<ColourConversion> _colour_conversion;
196         dcp::Size _size;
197         VideoFrameType _frame_type;
198         Crop _crop;
199         VideoContentScale _scale;
200         /** Sample aspect ratio obtained from the content file's header, if there is one */
201         boost::optional<double> _sample_aspect_ratio;
202         bool _yuv;
203         Frame _fade_in;
204         Frame _fade_out;
205         VideoRange _range;
206 };
207
208 #endif