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;
31 using std::stringstream;
32 using std::setprecision;
33 using boost::shared_ptr;
34 using boost::lexical_cast;
36 VideoContent::VideoContent (boost::filesystem::path f)
43 VideoContent::VideoContent (shared_ptr<const cxml::Node> node)
46 _video_length = node->number_child<ContentVideoFrame> ("VideoLength");
47 _video_size.width = node->number_child<int> ("VideoWidth");
48 _video_size.height = node->number_child<int> ("VideoHeight");
49 _video_frame_rate = node->number_child<float> ("VideoFrameRate");
52 VideoContent::VideoContent (VideoContent const & o)
54 , _video_length (o._video_length)
55 , _video_size (o._video_size)
56 , _video_frame_rate (o._video_frame_rate)
62 VideoContent::as_xml (xmlpp::Node* node) const
64 boost::mutex::scoped_lock lm (_mutex);
65 node->add_child("VideoLength")->add_child_text (lexical_cast<string> (_video_length));
66 node->add_child("VideoWidth")->add_child_text (lexical_cast<string> (_video_size.width));
67 node->add_child("VideoHeight")->add_child_text (lexical_cast<string> (_video_size.height));
68 node->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
72 VideoContent::take_from_video_decoder (shared_ptr<VideoDecoder> d)
74 /* These decoder calls could call other content methods which take a lock on the mutex */
75 libdcp::Size const vs = d->native_size ();
76 float const vfr = d->frames_per_second ();
79 boost::mutex::scoped_lock lm (_mutex);
81 _video_frame_rate = vfr;
84 Changed (VideoContentProperty::VIDEO_SIZE);
85 Changed (VideoContentProperty::VIDEO_FRAME_RATE);
90 VideoContent::information () const
94 s << String::compose (
95 _("%1x%2 pixels (%3:1)"),
98 setprecision (3), float (video_size().width) / video_size().height