Rename SafeStringStream -> locked_stringstream. Bump deps for removal of stringstream.
[dcpomatic.git] / src / lib / video_content.h
1 /*
2     Copyright (C) 2013-2016 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 };
50
51 class VideoContent : public ContentPart, public boost::enable_shared_from_this<VideoContent>
52 {
53 public:
54         VideoContent (Content* parent);
55         VideoContent (Content* parent, std::vector<boost::shared_ptr<Content> >);
56
57         void as_xml (xmlpp::Node *) const;
58         std::string technical_summary () const;
59         std::string identifier () const;
60
61         Frame length () const {
62                 boost::mutex::scoped_lock lm (_mutex);
63                 return _length;
64         }
65
66         Frame length_after_3d_combine () const {
67                 boost::mutex::scoped_lock lm (_mutex);
68                 if (_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
69                         return _length / 2;
70                 }
71
72                 return _length;
73         }
74
75         dcp::Size size () const {
76                 boost::mutex::scoped_lock lm (_mutex);
77                 return _size;
78         }
79
80         void set_frame_type (VideoFrameType);
81
82         void set_left_crop (int);
83         void set_right_crop (int);
84         void set_top_crop (int);
85         void set_bottom_crop (int);
86
87         void set_scale (VideoContentScale);
88         void unset_colour_conversion ();
89         void set_colour_conversion (ColourConversion);
90
91         void set_fade_in (Frame);
92         void set_fade_out (Frame);
93
94         VideoFrameType frame_type () const {
95                 boost::mutex::scoped_lock lm (_mutex);
96                 return _frame_type;
97         }
98
99         Crop crop () const {
100                 boost::mutex::scoped_lock lm (_mutex);
101                 return _crop;
102         }
103
104         int left_crop () const {
105                 boost::mutex::scoped_lock lm (_mutex);
106                 return _crop.left;
107         }
108
109         int right_crop () const {
110                 boost::mutex::scoped_lock lm (_mutex);
111                 return _crop.right;
112         }
113
114         int top_crop () const {
115                 boost::mutex::scoped_lock lm (_mutex);
116                 return _crop.top;
117         }
118
119         int bottom_crop () const {
120                 boost::mutex::scoped_lock lm (_mutex);
121                 return _crop.bottom;
122         }
123
124         /** @return Description of how to scale this content (if indeed it should be scaled) */
125         VideoContentScale scale () const {
126                 boost::mutex::scoped_lock lm (_mutex);
127                 return _scale;
128         }
129
130         boost::optional<ColourConversion> colour_conversion () const {
131                 boost::mutex::scoped_lock lm (_mutex);
132                 return _colour_conversion;
133         }
134
135         boost::optional<double> sample_aspect_ratio () const {
136                 boost::mutex::scoped_lock lm (_mutex);
137                 return _sample_aspect_ratio;
138         }
139
140         bool yuv () const {
141                 boost::mutex::scoped_lock lm (_mutex);
142                 return _yuv;
143         }
144
145         Frame fade_in () const {
146                 boost::mutex::scoped_lock lm (_mutex);
147                 return _fade_in;
148         }
149
150         Frame fade_out () const {
151                 boost::mutex::scoped_lock lm (_mutex);
152                 return _fade_out;
153         }
154
155         dcp::Size size_after_3d_split () const;
156         dcp::Size size_after_crop () const;
157
158         boost::optional<double> fade (Frame) const;
159
160         void scale_and_crop_to_fit_width ();
161         void scale_and_crop_to_fit_height ();
162
163         std::string processing_description () const;
164
165         void set_length (Frame);
166
167         void take_from_examiner (boost::shared_ptr<VideoExaminer>);
168         void add_properties (std::list<UserProperty> &) const;
169
170         static boost::shared_ptr<VideoContent> from_xml (Content* parent, cxml::ConstNodePtr, int);
171
172 private:
173
174         friend struct ffmpeg_pts_offset_test;
175         friend struct best_dcp_frame_rate_test_single;
176         friend struct best_dcp_frame_rate_test_double;
177         friend struct audio_sampling_rate_test;
178
179         VideoContent (Content* parent, cxml::ConstNodePtr, int);
180         void setup_default_colour_conversion ();
181
182         Frame _length;
183         boost::optional<ColourConversion> _colour_conversion;
184         dcp::Size _size;
185         VideoFrameType _frame_type;
186         Crop _crop;
187         VideoContentScale _scale;
188         /** Sample aspect ratio obtained from the content file's header, if there is one */
189         boost::optional<double> _sample_aspect_ratio;
190         bool _yuv;
191         Frame _fade_in;
192         Frame _fade_out;
193 };
194
195 #endif