Rename video/audio/subtitle part methods.
[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 "types.h"
28 #include "content_part.h"
29 #include <boost/thread/mutex.hpp>
30 #include <boost/weak_ptr.hpp>
31 #include <boost/enable_shared_from_this.hpp>
32
33 class VideoExaminer;
34 class Ratio;
35 class Film;
36 class Content;
37
38 class VideoContentProperty
39 {
40 public:
41         static int const SIZE;
42         static int const FRAME_RATE;
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 };
50
51 class VideoContent : public ContentPart, public boost::enable_shared_from_this<VideoContent>
52 {
53 public:
54         VideoContent (Content* parent, boost::shared_ptr<const Film>);
55         VideoContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
56         VideoContent (Content* parent, boost::shared_ptr<const Film>, 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
62         Frame length () const {
63                 boost::mutex::scoped_lock lm (_mutex);
64                 return _length;
65         }
66
67         Frame length_after_3d_combine () const {
68                 boost::mutex::scoped_lock lm (_mutex);
69                 if (_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
70                         return _length / 2;
71                 }
72
73                 return _length;
74         }
75
76         dcp::Size size () const {
77                 boost::mutex::scoped_lock lm (_mutex);
78                 return _size;
79         }
80
81         double frame_rate () const;
82
83         /** @return true if this content has a specific video frame rate, false
84          *  if it should use the DCP's rate.
85          */
86         bool has_own_frame_rate () const {
87                 boost::mutex::scoped_lock lm (_mutex);
88                 return static_cast<bool>(_frame_rate);
89         }
90
91         void set_frame_type (VideoFrameType);
92         void set_frame_rate (double);
93
94         void set_left_crop (int);
95         void set_right_crop (int);
96         void set_top_crop (int);
97         void set_bottom_crop (int);
98
99         void set_scale (VideoContentScale);
100         void unset_colour_conversion ();
101         void set_colour_conversion (ColourConversion);
102
103         void set_fade_in (Frame);
104         void set_fade_out (Frame);
105
106         VideoFrameType frame_type () const {
107                 boost::mutex::scoped_lock lm (_mutex);
108                 return _frame_type;
109         }
110
111         Crop crop () const {
112                 boost::mutex::scoped_lock lm (_mutex);
113                 return _crop;
114         }
115
116         int left_crop () const {
117                 boost::mutex::scoped_lock lm (_mutex);
118                 return _crop.left;
119         }
120
121         int right_crop () const {
122                 boost::mutex::scoped_lock lm (_mutex);
123                 return _crop.right;
124         }
125
126         int top_crop () const {
127                 boost::mutex::scoped_lock lm (_mutex);
128                 return _crop.top;
129         }
130
131         int bottom_crop () const {
132                 boost::mutex::scoped_lock lm (_mutex);
133                 return _crop.bottom;
134         }
135
136         /** @return Description of how to scale this content (if indeed it should be scaled) */
137         VideoContentScale scale () const {
138                 boost::mutex::scoped_lock lm (_mutex);
139                 return _scale;
140         }
141
142         boost::optional<ColourConversion> colour_conversion () const {
143                 boost::mutex::scoped_lock lm (_mutex);
144                 return _colour_conversion;
145         }
146
147         boost::optional<double> sample_aspect_ratio () const {
148                 boost::mutex::scoped_lock lm (_mutex);
149                 return _sample_aspect_ratio;
150         }
151
152         bool yuv () const {
153                 boost::mutex::scoped_lock lm (_mutex);
154                 return _yuv;
155         }
156
157         Frame fade_in () const {
158                 boost::mutex::scoped_lock lm (_mutex);
159                 return _fade_in;
160         }
161
162         Frame fade_out () const {
163                 boost::mutex::scoped_lock lm (_mutex);
164                 return _fade_out;
165         }
166
167         dcp::Size size_after_3d_split () const;
168         dcp::Size size_after_crop () 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         void set_length (Frame);
178
179         void take_from_examiner (boost::shared_ptr<VideoExaminer>);
180         void add_properties (std::list<UserProperty> &) const;
181
182 private:
183
184         friend struct ffmpeg_pts_offset_test;
185         friend struct best_dcp_frame_rate_test_single;
186         friend struct best_dcp_frame_rate_test_double;
187         friend struct audio_sampling_rate_test;
188
189         void setup_default_colour_conversion ();
190
191         Frame _length;
192         /** Video frame rate, or not set if this content should use the DCP's frame rate */
193         boost::optional<double> _frame_rate;
194         boost::optional<ColourConversion> _colour_conversion;
195         dcp::Size _size;
196         VideoFrameType _frame_type;
197         Crop _crop;
198         VideoContentScale _scale;
199         /** Sample aspect ratio obtained from the content file's header, if there is one */
200         boost::optional<double> _sample_aspect_ratio;
201         bool _yuv;
202         Frame _fade_in;
203         Frame _fade_out;
204 };
205
206 #endif