Merge remote-tracking branch 'origin/master' into 2.0
[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 };
40
41 class VideoContent : public virtual Content
42 {
43 public:
44         typedef int Frame;
45
46         VideoContent (boost::shared_ptr<const Film>);
47         VideoContent (boost::shared_ptr<const Film>, DCPTime, ContentTime);
48         VideoContent (boost::shared_ptr<const Film>, boost::filesystem::path);
49         VideoContent (boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
50         VideoContent (boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
51
52         void as_xml (xmlpp::Node *) const;
53         std::string technical_summary () const;
54         virtual std::string information () const;
55         virtual std::string identifier () const;
56
57         ContentTime video_length () const {
58                 boost::mutex::scoped_lock lm (_mutex);
59                 return _video_length;
60         }
61
62         ContentTime video_length_after_3d_combine () const {
63                 boost::mutex::scoped_lock lm (_mutex);
64                 if (_video_frame_type == VIDEO_FRAME_TYPE_3D_ALTERNATE) {
65                         return ContentTime (_video_length.get() / 2);
66                 }
67                 
68                 return _video_length;
69         }
70
71         dcp::Size video_size () const {
72                 boost::mutex::scoped_lock lm (_mutex);
73                 return _video_size;
74         }
75         
76         float video_frame_rate () const {
77                 boost::mutex::scoped_lock lm (_mutex);
78                 return _video_frame_rate;
79         }
80
81         void set_video_frame_type (VideoFrameType);
82         void set_video_frame_rate (float);
83
84         void set_left_crop (int);
85         void set_right_crop (int);
86         void set_top_crop (int);
87         void set_bottom_crop (int);
88
89         void set_scale (VideoContentScale);
90         void set_colour_conversion (ColourConversion);
91         
92         VideoFrameType video_frame_type () const {
93                 boost::mutex::scoped_lock lm (_mutex);
94                 return _video_frame_type;
95         }
96
97         Crop crop () const {
98                 boost::mutex::scoped_lock lm (_mutex);
99                 return _crop;
100         }
101
102         int left_crop () const {
103                 boost::mutex::scoped_lock lm (_mutex);
104                 return _crop.left;
105         }
106
107         int right_crop () const {
108                 boost::mutex::scoped_lock lm (_mutex);
109                 return _crop.right;
110         }
111
112         int top_crop () const {
113                 boost::mutex::scoped_lock lm (_mutex);
114                 return _crop.top;
115         }
116
117         int bottom_crop () const {
118                 boost::mutex::scoped_lock lm (_mutex);
119                 return _crop.bottom;
120         }
121
122         /** @return Description of how to scale this content (if indeed it should be scaled) */
123         VideoContentScale scale () const {
124                 boost::mutex::scoped_lock lm (_mutex);
125                 return _scale;
126         }
127
128         ColourConversion colour_conversion () const {
129                 boost::mutex::scoped_lock lm (_mutex);
130                 return _colour_conversion;
131         }
132
133         dcp::Size video_size_after_3d_split () const;
134         dcp::Size video_size_after_crop () const;
135
136         ContentTime dcp_time_to_content_time (DCPTime) const;
137
138         void scale_and_crop_to_fit_width ();
139         void scale_and_crop_to_fit_height ();
140
141 protected:
142         void take_from_video_examiner (boost::shared_ptr<VideoExaminer>);
143
144         ContentTime _video_length;
145         float _video_frame_rate;
146
147 private:
148         friend struct ffmpeg_pts_offset_test;
149         friend struct best_dcp_frame_rate_test_single;
150         friend struct best_dcp_frame_rate_test_double;
151         friend struct audio_sampling_rate_test;
152
153         void setup_default_colour_conversion ();
154         
155         dcp::Size _video_size;
156         VideoFrameType _video_frame_type;
157         Crop _crop;
158         VideoContentScale _scale;
159         ColourConversion _colour_conversion;
160 };
161
162 #endif