Another macOS std::list boost::thread SNAFU.
[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 USE;
43         static int const SIZE;
44         static int const FRAME_TYPE;
45         static int const CROP;
46         static int const SCALE;
47         static int const COLOUR_CONVERSION;
48         static int const FADE_IN;
49         static int const FADE_OUT;
50         static int const RANGE;
51 };
52
53 class VideoContent : public ContentPart, public boost::enable_shared_from_this<VideoContent>
54 {
55 public:
56         explicit VideoContent (Content* parent);
57         VideoContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
58
59         void as_xml (xmlpp::Node *) const;
60         std::string technical_summary () const;
61         std::string identifier () const;
62         void take_settings_from (boost::shared_ptr<const VideoContent> c);
63
64         Frame length () const {
65                 boost::mutex::scoped_lock lm (_mutex);
66                 return _length;
67         }
68
69         Frame length_after_3d_combine () const {
70                 boost::mutex::scoped_lock lm (_mutex);
71                 if (_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
72                         return _length / 2;
73                 }
74
75                 return _length;
76         }
77
78         dcp::Size size () const {
79                 boost::mutex::scoped_lock lm (_mutex);
80                 return _size;
81         }
82
83         void set_frame_type (VideoFrameType);
84
85         void set_left_crop (int);
86         void set_right_crop (int);
87         void set_top_crop (int);
88         void set_bottom_crop (int);
89
90         void set_scale (VideoContentScale);
91         void unset_colour_conversion ();
92         void set_colour_conversion (ColourConversion);
93
94         void set_fade_in (Frame);
95         void set_fade_out (Frame);
96
97         void set_range (VideoRange);
98         void set_use (bool);
99
100         VideoFrameType frame_type () const {
101                 boost::mutex::scoped_lock lm (_mutex);
102                 return _frame_type;
103         }
104
105         Crop crop () const {
106                 boost::mutex::scoped_lock lm (_mutex);
107                 return _crop;
108         }
109
110         int left_crop () const {
111                 boost::mutex::scoped_lock lm (_mutex);
112                 return _crop.left;
113         }
114
115         int right_crop () const {
116                 boost::mutex::scoped_lock lm (_mutex);
117                 return _crop.right;
118         }
119
120         int top_crop () const {
121                 boost::mutex::scoped_lock lm (_mutex);
122                 return _crop.top;
123         }
124
125         int bottom_crop () const {
126                 boost::mutex::scoped_lock lm (_mutex);
127                 return _crop.bottom;
128         }
129
130         /** @return Description of how to scale this content (if indeed it should be scaled) */
131         VideoContentScale scale () const {
132                 boost::mutex::scoped_lock lm (_mutex);
133                 return _scale;
134         }
135
136         boost::optional<ColourConversion> colour_conversion () const {
137                 boost::mutex::scoped_lock lm (_mutex);
138                 return _colour_conversion;
139         }
140
141         boost::optional<double> sample_aspect_ratio () const {
142                 boost::mutex::scoped_lock lm (_mutex);
143                 return _sample_aspect_ratio;
144         }
145
146         bool yuv () const {
147                 boost::mutex::scoped_lock lm (_mutex);
148                 return _yuv;
149         }
150
151         Frame fade_in () const {
152                 boost::mutex::scoped_lock lm (_mutex);
153                 return _fade_in;
154         }
155
156         Frame fade_out () const {
157                 boost::mutex::scoped_lock lm (_mutex);
158                 return _fade_out;
159         }
160
161         VideoRange range () const {
162                 boost::mutex::scoped_lock lm (_mutex);
163                 return _range;
164         }
165
166         bool use () const {
167                 boost::mutex::scoped_lock lm (_mutex);
168                 return _use;
169         }
170
171         dcp::Size size_after_3d_split () const;
172         dcp::Size size_after_crop () const;
173
174         boost::optional<double> fade (boost::shared_ptr<const Film> film, Frame) const;
175
176         void scale_and_crop_to_fit_width (boost::shared_ptr<const Film> film);
177         void scale_and_crop_to_fit_height (boost::shared_ptr<const Film> film);
178
179         std::string processing_description (boost::shared_ptr<const Film> film) const;
180
181         void set_length (Frame);
182
183         void take_from_examiner (boost::shared_ptr<VideoExaminer>);
184         void add_properties (std::list<UserProperty> &) const;
185
186         void modify_position (boost::shared_ptr<const Film> film, dcpomatic::DCPTime& pos) const;
187         void modify_trim_start (dcpomatic::ContentTime& pos) const;
188
189         static boost::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtr, int);
190
191 private:
192
193         friend struct ffmpeg_pts_offset_test;
194         friend struct best_dcp_frame_rate_test_single;
195         friend struct best_dcp_frame_rate_test_double;
196         friend struct audio_sampling_rate_test;
197
198         VideoContent (Content* parent, cxml::ConstNodePtr, int);
199         void setup_default_colour_conversion ();
200
201         bool _use;
202         Frame _length;
203         boost::optional<ColourConversion> _colour_conversion;
204         dcp::Size _size;
205         VideoFrameType _frame_type;
206         Crop _crop;
207         VideoContentScale _scale;
208         /** Sample aspect ratio obtained from the content file's header, if there is one */
209         boost::optional<double> _sample_aspect_ratio;
210         bool _yuv;
211         /** fade in time in content frames */
212         Frame _fade_in;
213         /** fade out time in content frames */
214         Frame _fade_out;
215         VideoRange _range;
216 };
217
218 #endif