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) 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         Ratio const * _ratio;
68         bool _scale;
69
70         static std::vector<VideoContentScale> _scales;
71 };
72
73 bool operator== (VideoContentScale const & a, VideoContentScale const & b);
74 bool operator!= (VideoContentScale const & a, VideoContentScale const & b);
75
76 class VideoContent : public virtual Content
77 {
78 public:
79         typedef int Frame;
80
81         VideoContent (boost::shared_ptr<const Film>);
82         VideoContent (boost::shared_ptr<const Film>, DCPTime, ContentTime);
83         VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path);
84         VideoContent (boost::shared_ptr<const Film>, boost::shared_ptr<const cxml::Node>, int);
85         VideoContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
86
87         void as_xml (xmlpp::Node *) const;
88         std::string technical_summary () const;
89         virtual std::string information () const;
90         virtual std::string identifier () const;
91
92         ContentTime video_length () const {
93                 boost::mutex::scoped_lock lm (_mutex);
94                 return _video_length;
95         }
96
97         dcp::Size video_size () const {
98                 boost::mutex::scoped_lock lm (_mutex);
99                 return _video_size;
100         }
101         
102         float video_frame_rate () const {
103                 boost::mutex::scoped_lock lm (_mutex);
104                 return _video_frame_rate;
105         }
106
107         void set_video_frame_type (VideoFrameType);
108
109         void set_left_crop (int);
110         void set_right_crop (int);
111         void set_top_crop (int);
112         void set_bottom_crop (int);
113
114         void set_scale (VideoContentScale);
115         void set_colour_conversion (ColourConversion);
116         
117         VideoFrameType video_frame_type () const {
118                 boost::mutex::scoped_lock lm (_mutex);
119                 return _video_frame_type;
120         }
121
122         Crop crop () const {
123                 boost::mutex::scoped_lock lm (_mutex);
124                 return _crop;
125         }
126
127         int left_crop () const {
128                 boost::mutex::scoped_lock lm (_mutex);
129                 return _crop.left;
130         }
131
132         int right_crop () const {
133                 boost::mutex::scoped_lock lm (_mutex);
134                 return _crop.right;
135         }
136
137         int top_crop () const {
138                 boost::mutex::scoped_lock lm (_mutex);
139                 return _crop.top;
140         }
141
142         int bottom_crop () const {
143                 boost::mutex::scoped_lock lm (_mutex);
144                 return _crop.bottom;
145         }
146
147         /** @return Description of how to scale this content (if indeed it should be scaled) */
148         VideoContentScale scale () const {
149                 boost::mutex::scoped_lock lm (_mutex);
150                 return _scale;
151         }
152
153         ColourConversion colour_conversion () const {
154                 boost::mutex::scoped_lock lm (_mutex);
155                 return _colour_conversion;
156         }
157
158         dcp::Size video_size_after_3d_split () const;
159         dcp::Size video_size_after_crop () const;
160
161         ContentTime dcp_time_to_content_time (DCPTime) const;
162
163 protected:
164         void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
165
166         ContentTime _video_length;
167         float _video_frame_rate;
168
169 private:
170         friend class ffmpeg_pts_offset_test;
171         friend class best_dcp_frame_rate_test_single;
172         friend class best_dcp_frame_rate_test_double;
173         friend class audio_sampling_rate_test;
174
175         void setup_default_colour_conversion ();
176         
177         dcp::Size _video_size;
178         VideoFrameType _video_frame_type;
179         Crop _crop;
180         VideoContentScale _scale;
181         ColourConversion _colour_conversion;
182 };
183
184 #endif