Merge master.
[dcpomatic.git] / src / lib / video_content.h
1 /*
2     Copyright (C) 2013-2014 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 "content.h"
24 #include "colour_conversion.h"
25 #include "video_content_scale.h"
26
27 class VideoExaminer;
28 class Ratio;
29
30 class VideoContentProperty
31 {
32 public:
33         static int const VIDEO_SIZE;
34         static int const VIDEO_FRAME_RATE;
35         static int const VIDEO_FRAME_TYPE;
36         static int const VIDEO_CROP;
37         static int const VIDEO_SCALE;
38         static int const COLOUR_CONVERSION;
39         static int const VIDEO_FADE_IN;
40         static int const VIDEO_FADE_OUT;
41 };
42
43 class VideoContent : public virtual Content
44 {
45 public:
46         typedef int Frame;
47
48         VideoContent (boost::shared_ptr<const Film>);
49         VideoContent (boost::shared_ptr<const Film>, DCPTime, ContentTime);
50         VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path);
51         VideoContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
52         VideoContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
53
54         void as_xml (xmlpp::Node *) const;
55         std::string technical_summary () const;
56         virtual std::string information () const;
57         virtual std::string identifier () const;
58
59         ContentTime video_length () const {
60                 boost::mutex::scoped_lock lm (_mutex);
61                 return _video_length;
62         }
63
64         ContentTime video_length_after_3d_combine () const {
65                 boost::mutex::scoped_lock lm (_mutex);
66                 if (_video_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
67                         return ContentTime (_video_length.get() / 2);
68                 }
69                 
70                 return _video_length;
71         }
72
73         dcp::Size video_size () const {
74                 boost::mutex::scoped_lock lm (_mutex);
75                 return _video_size;
76         }
77         
78         float video_frame_rate () const {
79                 boost::mutex::scoped_lock lm (_mutex);
80                 return _video_frame_rate;
81         }
82
83         void set_video_frame_type (VideoFrameType);
84         void set_video_frame_rate (float);
85
86         void set_left_crop (int);
87         void set_right_crop (int);
88         void set_top_crop (int);
89         void set_bottom_crop (int);
90
91         void set_scale (VideoContentScale);
92         void unset_colour_conversion ();
93         void set_colour_conversion (ColourConversion);
94         void set_default_colour_conversion ();
95
96         void set_fade_in (ContentTime);
97         void set_fade_out (ContentTime);
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         ContentTime fade_in () const {
141                 boost::mutex::scoped_lock lm (_mutex);
142                 return _fade_in;
143         }
144
145         ContentTime fade_out () const {
146                 boost::mutex::scoped_lock lm (_mutex);
147                 return _fade_out;
148         }
149         
150         dcp::Size video_size_after_3d_split () const;
151         dcp::Size video_size_after_crop () const;
152
153         ContentTime dcp_time_to_content_time (DCPTime) const;
154
155         boost::optional<float> fade (VideoFrame) const;
156
157         void scale_and_crop_to_fit_width ();
158         void scale_and_crop_to_fit_height ();
159
160 protected:
161         void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
162
163         ContentTime _video_length;
164         float _video_frame_rate;
165
166 private:
167         friend struct ffmpeg_pts_offset_test;
168         friend struct best_dcp_frame_rate_test_single;
169         friend struct best_dcp_frame_rate_test_double;
170         friend struct audio_sampling_rate_test;
171
172         void setup_default_colour_conversion ();
173         
174         dcp::Size _video_size;
175         VideoFrameType _video_frame_type;
176         Crop _crop;
177         VideoContentScale _scale;
178         boost::optional<ColourConversion> _colour_conversion;
179         ContentTime _fade_in;
180         ContentTime _fade_out;
181 };
182
183 #endif