A few more fixes; set up Playlist as required.
[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 VideoContent::VideoContent (VideoContent const & o)
30         : Content (o)
31         , _video_length (o._video_length)
32         , _video_size (o._video_size)
33         , _video_frame_rate (o._video_frame_rate)
34 {
35
36 }
37
38 void
39 VideoContent::as_xml (xmlpp::Node* node) const
40 {
41         boost::mutex::scoped_lock lm (_mutex);
42         node->add_child("VideoLength")->add_child_text (lexical_cast<string> (_video_length));
43         node->add_child("VideoWidth")->add_child_text (lexical_cast<string> (_video_size.width));
44         node->add_child("VideoHeight")->add_child_text (lexical_cast<string> (_video_size.height));
45         node->add_child("VideoFrameRate")->add_child_text (lexical_cast<string> (_video_frame_rate));
46 }
47
48 void
49 VideoContent::take_from_video_decoder (shared_ptr<VideoDecoder> d)
50 {
51         /* These decoder calls could call other content methods which take a lock on the mutex */
52         libdcp::Size const vs = d->native_size ();
53         float const vfr = d->frames_per_second ();
54         
55         {
56                 boost::mutex::scoped_lock lm (_mutex);
57                 _video_size = vs;
58                 _video_frame_rate = vfr;
59         }
60         
61         Changed (VideoContentProperty::VIDEO_SIZE);
62         Changed (VideoContentProperty::VIDEO_FRAME_RATE);
63 }