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"
28 int const VideoContentProperty::VIDEO_SIZE = 0;
29 int const VideoContentProperty::VIDEO_FRAME_RATE = 1;
30 int const VideoContentProperty::VIDEO_CROP = 2;
31 int const VideoContentProperty::VIDEO_RATIO = 3;
34 using std::stringstream;
35 using std::setprecision;
36 using boost::shared_ptr;
37 using boost::lexical_cast;
38 using boost::optional;
40 VideoContent::VideoContent (shared_ptr<const Film> f, Time s, ContentVideoFrame len)
43 , _video_frame_rate (0)
44 , _ratio (Ratio::from_id ("185"))
49 VideoContent::VideoContent (shared_ptr<const Film> f, boost::filesystem::path p)
52 , _video_frame_rate (0)
53 , _ratio (Ratio::from_id ("185"))
58 VideoContent::VideoContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
61 _video_length = node->number_child<ContentVideoFrame> ("VideoLength");
62 _video_size.width = node->number_child<int> ("VideoWidth");
63 _video_size.height = node->number_child<int> ("VideoHeight");
64 _video_frame_rate = node->number_child<float> ("VideoFrameRate");
65 _crop.left = node->number_child<int> ("LeftCrop");
66 _crop.right = node->number_child<int> ("RightCrop");
67 _crop.top = node->number_child<int> ("TopCrop");
68 _crop.bottom = node->number_child<int> ("BottomCrop");
69 optional<string> r = node->optional_string_child ("Ratio");
71 _ratio = Ratio::from_id (r.get ());
75 VideoContent::VideoContent (VideoContent const & o)
77 , _video_length (o._video_length)
78 , _video_size (o._video_size)
79 , _video_frame_rate (o._video_frame_rate)
86 VideoContent::as_xml (xmlpp::Node* node) const
88 boost::mutex::scoped_lock lm (_mutex);
89 node->add_child("VideoLength")->add_child_text (lexical_cast<string> (_video_length));
90 node->add_child("VideoWidth")->add_child_text (lexical_cast<string> (_video_size.width));
91 node->add_child("VideoHeight")->add_child_text (lexical_cast<string> (_video_size.height));
92 node->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
93 node->add_child("LeftCrop")->add_child_text (boost::lexical_cast<string> (_crop.left));
94 node->add_child("RightCrop")->add_child_text (boost::lexical_cast<string> (_crop.right));
95 node->add_child("TopCrop")->add_child_text (boost::lexical_cast<string> (_crop.top));
96 node->add_child("BottomCrop")->add_child_text (boost::lexical_cast<string> (_crop.bottom));
98 node->add_child("Ratio")->add_child_text (_ratio->id ());
103 VideoContent::take_from_video_examiner (shared_ptr<VideoExaminer> d)
105 /* These examiner calls could call other content methods which take a lock on the mutex */
106 libdcp::Size const vs = d->video_size ();
107 float const vfr = d->video_frame_rate ();
110 boost::mutex::scoped_lock lm (_mutex);
112 _video_frame_rate = vfr;
115 signal_changed (VideoContentProperty::VIDEO_SIZE);
116 signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
121 VideoContent::information () const
123 if (video_size().width == 0 || video_size().height == 0) {
129 s << String::compose (
130 _("%1x%2 pixels (%3:1)"),
133 setprecision (3), float (video_size().width) / video_size().height
140 VideoContent::set_crop (Crop c)
143 boost::mutex::scoped_lock lm (_mutex);
146 signal_changed (VideoContentProperty::VIDEO_CROP);
150 VideoContent::set_left_crop (int c)
153 boost::mutex::scoped_lock lm (_mutex);
155 if (_crop.left == c) {
162 signal_changed (VideoContentProperty::VIDEO_CROP);
166 VideoContent::set_right_crop (int c)
169 boost::mutex::scoped_lock lm (_mutex);
170 if (_crop.right == c) {
177 signal_changed (VideoContentProperty::VIDEO_CROP);
181 VideoContent::set_top_crop (int c)
184 boost::mutex::scoped_lock lm (_mutex);
185 if (_crop.top == c) {
192 signal_changed (VideoContentProperty::VIDEO_CROP);
196 VideoContent::set_bottom_crop (int c)
199 boost::mutex::scoped_lock lm (_mutex);
200 if (_crop.bottom == c) {
207 signal_changed (VideoContentProperty::VIDEO_CROP);
211 VideoContent::set_ratio (Ratio const * r)
214 boost::mutex::scoped_lock lm (_mutex);
222 signal_changed (VideoContentProperty::VIDEO_RATIO);