2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
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.
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.
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.
21 #include <libcxml/cxml.h>
22 #include "video_content.h"
23 #include "video_examiner.h"
25 #include "compose.hpp"
29 int const VideoContentProperty::VIDEO_SIZE = 0;
30 int const VideoContentProperty::VIDEO_FRAME_RATE = 1;
31 int const VideoContentProperty::VIDEO_FRAME_TYPE = 2;
32 int const VideoContentProperty::VIDEO_CROP = 3;
33 int const VideoContentProperty::VIDEO_RATIO = 4;
36 using std::stringstream;
37 using std::setprecision;
39 using boost::shared_ptr;
40 using boost::lexical_cast;
41 using boost::optional;
43 VideoContent::VideoContent (shared_ptr<const Film> f, Time s, VideoContent::Frame len)
46 , _video_frame_rate (0)
47 , _video_frame_type (VIDEO_FRAME_TYPE_2D)
48 , _ratio (Ratio::from_id ("185"))
53 VideoContent::VideoContent (shared_ptr<const Film> f, boost::filesystem::path p)
56 , _video_frame_rate (0)
57 , _video_frame_type (VIDEO_FRAME_TYPE_2D)
58 , _ratio (Ratio::from_id ("185"))
63 VideoContent::VideoContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
66 _video_length = node->number_child<VideoContent::Frame> ("VideoLength");
67 _video_size.width = node->number_child<int> ("VideoWidth");
68 _video_size.height = node->number_child<int> ("VideoHeight");
69 _video_frame_rate = node->number_child<float> ("VideoFrameRate");
70 _video_frame_type = static_cast<VideoFrameType> (node->number_child<int> ("VideoFrameType"));
71 _crop.left = node->number_child<int> ("LeftCrop");
72 _crop.right = node->number_child<int> ("RightCrop");
73 _crop.top = node->number_child<int> ("TopCrop");
74 _crop.bottom = node->number_child<int> ("BottomCrop");
75 optional<string> r = node->optional_string_child ("Ratio");
77 _ratio = Ratio::from_id (r.get ());
82 VideoContent::as_xml (xmlpp::Node* node) const
84 boost::mutex::scoped_lock lm (_mutex);
85 node->add_child("VideoLength")->add_child_text (lexical_cast<string> (_video_length));
86 node->add_child("VideoWidth")->add_child_text (lexical_cast<string> (_video_size.width));
87 node->add_child("VideoHeight")->add_child_text (lexical_cast<string> (_video_size.height));
88 node->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
89 node->add_child("VideoFrameType")->add_child_text (lexical_cast<string> (static_cast<int> (_video_frame_type)));
90 node->add_child("LeftCrop")->add_child_text (boost::lexical_cast<string> (_crop.left));
91 node->add_child("RightCrop")->add_child_text (boost::lexical_cast<string> (_crop.right));
92 node->add_child("TopCrop")->add_child_text (boost::lexical_cast<string> (_crop.top));
93 node->add_child("BottomCrop")->add_child_text (boost::lexical_cast<string> (_crop.bottom));
95 node->add_child("Ratio")->add_child_text (_ratio->id ());
100 VideoContent::take_from_video_examiner (shared_ptr<VideoExaminer> d)
102 /* These examiner calls could call other content methods which take a lock on the mutex */
103 libdcp::Size const vs = d->video_size ();
104 float const vfr = d->video_frame_rate ();
107 boost::mutex::scoped_lock lm (_mutex);
109 _video_frame_rate = vfr;
112 signal_changed (VideoContentProperty::VIDEO_SIZE);
113 signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
118 VideoContent::information () const
120 if (video_size().width == 0 || video_size().height == 0) {
126 s << String::compose (
127 _("%1x%2 pixels (%3:1)"),
130 setprecision (3), float (video_size().width) / video_size().height
137 VideoContent::set_left_crop (int c)
140 boost::mutex::scoped_lock lm (_mutex);
142 if (_crop.left == c) {
149 signal_changed (VideoContentProperty::VIDEO_CROP);
153 VideoContent::set_right_crop (int c)
156 boost::mutex::scoped_lock lm (_mutex);
157 if (_crop.right == c) {
164 signal_changed (VideoContentProperty::VIDEO_CROP);
168 VideoContent::set_top_crop (int c)
171 boost::mutex::scoped_lock lm (_mutex);
172 if (_crop.top == c) {
179 signal_changed (VideoContentProperty::VIDEO_CROP);
183 VideoContent::set_bottom_crop (int c)
186 boost::mutex::scoped_lock lm (_mutex);
187 if (_crop.bottom == c) {
194 signal_changed (VideoContentProperty::VIDEO_CROP);
198 VideoContent::set_ratio (Ratio const * r)
201 boost::mutex::scoped_lock lm (_mutex);
209 signal_changed (VideoContentProperty::VIDEO_RATIO);
212 /** @return string which includes everything about how this content looks */
214 VideoContent::identifier () const
217 s << Content::digest()
218 << "_" << crop().left
219 << "_" << crop().right
221 << "_" << crop().bottom;
224 s << "_" << ratio()->id ();
231 VideoContent::set_video_frame_type (VideoFrameType t)
234 boost::mutex::scoped_lock lm (_mutex);
235 _video_frame_type = t;
238 signal_changed (VideoContentProperty::VIDEO_FRAME_TYPE);
242 VideoContent::technical_summary () const
244 return String::compose ("video: length %1, size %2x%3, rate %4", video_length(), video_size().width, video_size().height, video_frame_rate());
248 VideoContent::video_size_after_3d_split () const
250 libdcp::Size const s = video_size ();
251 switch (video_frame_type ()) {
252 case VIDEO_FRAME_TYPE_2D:
254 case VIDEO_FRAME_TYPE_3D_LEFT_RIGHT:
255 return libdcp::Size (s.width / 2, s.height);