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.
20 #include <libcxml/cxml.h>
21 #include "video_content.h"
22 #include "video_decoder.h"
26 int const VideoContentProperty::VIDEO_LENGTH = 0;
27 int const VideoContentProperty::VIDEO_SIZE = 1;
28 int const VideoContentProperty::VIDEO_FRAME_RATE = 2;
29 int const VideoContentProperty::VIDEO_CROP = 3;
32 using std::stringstream;
33 using std::setprecision;
34 using boost::shared_ptr;
35 using boost::lexical_cast;
37 VideoContent::VideoContent (shared_ptr<const Film> f, Time s, ContentVideoFrame len)
44 VideoContent::VideoContent (shared_ptr<const Film> f, boost::filesystem::path p)
51 VideoContent::VideoContent (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
54 _video_length = node->number_child<ContentVideoFrame> ("VideoLength");
55 _video_size.width = node->number_child<int> ("VideoWidth");
56 _video_size.height = node->number_child<int> ("VideoHeight");
57 _video_frame_rate = node->number_child<float> ("VideoFrameRate");
58 _crop.left = node->number_child<int> ("LeftCrop");
59 _crop.right = node->number_child<int> ("RightCrop");
60 _crop.top = node->number_child<int> ("TopCrop");
61 _crop.bottom = node->number_child<int> ("BottomCrop");
64 VideoContent::VideoContent (VideoContent const & o)
66 , _video_length (o._video_length)
67 , _video_size (o._video_size)
68 , _video_frame_rate (o._video_frame_rate)
74 VideoContent::as_xml (xmlpp::Node* node) const
76 boost::mutex::scoped_lock lm (_mutex);
77 node->add_child("VideoLength")->add_child_text (lexical_cast<string> (_video_length));
78 node->add_child("VideoWidth")->add_child_text (lexical_cast<string> (_video_size.width));
79 node->add_child("VideoHeight")->add_child_text (lexical_cast<string> (_video_size.height));
80 node->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
81 node->add_child("LeftCrop")->add_child_text (boost::lexical_cast<string> (_crop.left));
82 node->add_child("RightCrop")->add_child_text (boost::lexical_cast<string> (_crop.right));
83 node->add_child("TopCrop")->add_child_text (boost::lexical_cast<string> (_crop.top));
84 node->add_child("BottomCrop")->add_child_text (boost::lexical_cast<string> (_crop.bottom));
88 VideoContent::take_from_video_decoder (shared_ptr<VideoDecoder> d)
90 /* These decoder calls could call other content methods which take a lock on the mutex */
91 libdcp::Size const vs = d->video_size ();
92 float const vfr = d->video_frame_rate ();
95 boost::mutex::scoped_lock lm (_mutex);
97 _video_frame_rate = vfr;
100 signal_changed (VideoContentProperty::VIDEO_SIZE);
101 signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
106 VideoContent::information () const
108 if (video_size().width == 0 || video_size().height == 0) {
114 s << String::compose (
115 _("%1x%2 pixels (%3:1)"),
118 setprecision (3), float (video_size().width) / video_size().height
125 VideoContent::set_crop (Crop c)
128 boost::mutex::scoped_lock lm (_mutex);
131 signal_changed (VideoContentProperty::VIDEO_CROP);
135 VideoContent::set_left_crop (int c)
138 boost::mutex::scoped_lock lm (_mutex);
140 if (_crop.left == c) {
147 signal_changed (VideoContentProperty::VIDEO_CROP);
151 VideoContent::set_right_crop (int c)
154 boost::mutex::scoped_lock lm (_mutex);
155 if (_crop.right == c) {
162 signal_changed (VideoContentProperty::VIDEO_CROP);
166 VideoContent::set_top_crop (int c)
169 boost::mutex::scoped_lock lm (_mutex);
170 if (_crop.top == c) {
177 signal_changed (VideoContentProperty::VIDEO_CROP);
181 VideoContent::set_bottom_crop (int c)
184 boost::mutex::scoped_lock lm (_mutex);
185 if (_crop.bottom == c) {
192 signal_changed (VideoContentProperty::VIDEO_CROP);