Merge master.
[dcpomatic.git] / src / lib / video_content.h
1 /*
2     Copyright (C) 2013 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
26 class VideoExaminer;
27 class Ratio;
28
29 class VideoContentProperty
30 {
31 public:
32         static int const VIDEO_SIZE;
33         static int const VIDEO_FRAME_RATE;
34         static int const VIDEO_FRAME_TYPE;
35         static int const VIDEO_CROP;
36         static int const VIDEO_SCALE;
37         static int const COLOUR_CONVERSION;
38 };
39
40 class VideoContentScale
41 {
42 public:
43         VideoContentScale ();
44         VideoContentScale (Ratio const *);
45         VideoContentScale (bool);
46         VideoContentScale (boost::shared_ptr<cxml::Node>);
47
48         dcp::Size size (boost::shared_ptr<const VideoContent>, dcp::Size, dcp::Size) const;
49         std::string id () const;
50         std::string name () const;
51         void as_xml (xmlpp::Node *) const;
52
53         Ratio const * ratio () const {
54                 return _ratio;
55         }
56
57         bool scale () const {
58                 return _scale;
59         }
60
61         static void setup_scales ();
62         static std::vector<VideoContentScale> all () {
63                 return _scales;
64         }
65
66 private:
67         /** a ratio to stretch the content to, or 0 for no stretch */
68         Ratio const * _ratio;
69         /** true if we want to scale the content */
70         bool _scale;
71
72         static std::vector<VideoContentScale> _scales;
73 };
74
75 bool operator== (VideoContentScale const & a, VideoContentScale const & b);
76 bool operator!= (VideoContentScale const & a, VideoContentScale const & b);
77
78 class VideoContent : public virtual Content
79 {
80 public:
81         typedef int Frame;
82
83         VideoContent (boost::shared_ptr<const Film>);
84         VideoContent (boost::shared_ptr<const Film>, DCPTime, ContentTime);
85         VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path);
86         VideoContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>, int);
87         VideoContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
88
89         void as_xml (xmlpp::Node *) const;
90         std::string technical_summary () const;
91         virtual std::string information () const;
92         virtual std::string identifier () const;
93
94         ContentTime video_length () const {
95                 boost::mutex::scoped_lock lm (_mutex);
96                 return _video_length;
97         }
98
99         dcp::Size video_size () const {
100                 boost::mutex::scoped_lock lm (_mutex);
101                 return _video_size;
102         }
103         
104         float video_frame_rate () const {
105                 boost::mutex::scoped_lock lm (_mutex);
106                 return _video_frame_rate;
107         }
108
109         void set_video_frame_type (VideoFrameType);
110
111         void set_left_crop (int);
112         void set_right_crop (int);
113         void set_top_crop (int);
114         void set_bottom_crop (int);
115
116         void set_scale (VideoContentScale);
117         void set_colour_conversion (ColourConversion);
118         
119         VideoFrameType video_frame_type () const {
120                 boost::mutex::scoped_lock lm (_mutex);
121                 return _video_frame_type;
122         }
123
124         Crop crop () const {
125                 boost::mutex::scoped_lock lm (_mutex);
126                 return _crop;
127         }
128
129         int left_crop () const {
130                 boost::mutex::scoped_lock lm (_mutex);
131                 return _crop.left;
132         }
133
134         int right_crop () const {
135                 boost::mutex::scoped_lock lm (_mutex);
136                 return _crop.right;
137         }
138
139         int top_crop () const {
140                 boost::mutex::scoped_lock lm (_mutex);
141                 return _crop.top;
142         }
143
144         int bottom_crop () const {
145                 boost::mutex::scoped_lock lm (_mutex);
146                 return _crop.bottom;
147         }
148
149         /** @return Description of how to scale this content (if indeed it should be scaled) */
150         VideoContentScale scale () const {
151                 boost::mutex::scoped_lock lm (_mutex);
152                 return _scale;
153         }
154
155         ColourConversion colour_conversion () const {
156                 boost::mutex::scoped_lock lm (_mutex);
157                 return _colour_conversion;
158         }
159
160         dcp::Size video_size_after_3d_split () const;
161         dcp::Size video_size_after_crop () const;
162
163         ContentTime dcp_time_to_content_time (DCPTime) const;
164
165 protected:
166         void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
167
168         ContentTime _video_length;
169         float _video_frame_rate;
170
171 private:
172         friend class ffmpeg_pts_offset_test;
173         friend class best_dcp_frame_rate_test_single;
174         friend class best_dcp_frame_rate_test_double;
175         friend class audio_sampling_rate_test;
176
177         void setup_default_colour_conversion ();
178         
179         dcp::Size _video_size;
180         VideoFrameType _video_frame_type;
181         Crop _crop;
182         VideoContentScale _scale;
183         ColourConversion _colour_conversion;
184 };
185
186 #endif