Merge branch 'master' into content-rework-take5
[dcpomatic.git] / src / lib / video_content.cc
1 #include <libcxml/cxml.h>
2 #include "video_content.h"
3 #include "video_decoder.h"
4
5 int const VideoContentProperty::VIDEO_LENGTH = 0;
6 int const VideoContentProperty::VIDEO_SIZE = 1;
7 int const VideoContentProperty::VIDEO_FRAME_RATE = 2;
8
9 using std::string;
10 using boost::shared_ptr;
11 using boost::lexical_cast;
12
13 VideoContent::VideoContent (boost::filesystem::path f)
14         : Content (f)
15         , _video_length (0)
16 {
17
18 }
19
20 VideoContent::VideoContent (shared_ptr<const cxml::Node> node)
21         : Content (node)
22 {
23         _video_length = node->number_child<ContentVideoFrame> ("VideoLength");
24         _video_size.width = node->number_child<int> ("VideoWidth");
25         _video_size.height = node->number_child<int> ("VideoHeight");
26         _video_frame_rate = node->number_child<float> ("VideoFrameRate");
27 }
28
29 void
30 VideoContent::as_xml (xmlpp::Node* node) const
31 {
32         boost::mutex::scoped_lock lm (_mutex);
33         node->add_child("VideoLength")->add_child_text (lexical_cast<string> (_video_length));
34         node->add_child("VideoWidth")->add_child_text (lexical_cast<string> (_video_size.width));
35         node->add_child("VideoHeight")->add_child_text (lexical_cast<string> (_video_size.height));
36         node->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
37 }
38
39 void
40 VideoContent::take_from_video_decoder (shared_ptr<VideoDecoder> d)
41 {
42         {
43                 boost::mutex::scoped_lock lm (_mutex);
44                 _video_size = d->native_size ();
45                 _video_frame_rate = d->frames_per_second ();
46         }
47         
48         Changed (VideoContentProperty::VIDEO_SIZE);
49         Changed (VideoContentProperty::VIDEO_FRAME_RATE);
50 }