Store audio length in AudioStream.
[dcpomatic.git] / src / lib / dcp_content.cc
index b77c22714a2a00c48b4509343bae7b86c03cedc7..83374fc3051759f815819cf8c71cb6bb0c57a672 100644 (file)
@@ -72,21 +72,22 @@ DCPContent::DCPContent (shared_ptr<const Film> film, boost::filesystem::path p)
 DCPContent::DCPContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
        : Content (film, node)
 {
-       video.reset (new VideoContent (this, film, node, version));
+       video = VideoContent::from_xml (this, film, node, version);
+       audio = AudioContent::from_xml (this, film, node);
+       subtitle = SubtitleContent::from_xml (this, film, node, version);
 
-       audio.reset (new AudioContent (this, film, node));
        audio->set_stream (
                AudioStreamPtr (
-                       new AudioStream (node->number_child<int> ("AudioFrameRate"), AudioMapping (node->node_child ("AudioMapping"), version))
+                       new AudioStream (
+                               node->number_child<int> ("AudioFrameRate"),
+                               node->number_child<Frame> ("AudioLength"),
+                               AudioMapping (node->node_child ("AudioMapping"), version)
+                               )
                        )
                );
 
        _name = node->string_child ("Name");
 
-       if (node->bool_child ("HasSubtitles")) {
-               subtitle.reset (new SubtitleContent (this, film, node, version));
-       }
-
        _encrypted = node->bool_child ("Encrypted");
        if (node->optional_node_child ("KDM")) {
                _kdm = dcp::EncryptedKDM (node->string_child ("KDM"));
@@ -124,7 +125,7 @@ DCPContent::examine (shared_ptr<Job> job)
        {
                boost::mutex::scoped_lock lm (_mutex);
 
-               AudioStreamPtr as (new AudioStream (examiner->audio_frame_rate(), examiner->audio_channels ()));
+               AudioStreamPtr as (new AudioStream (examiner->audio_frame_rate(), examiner->audio_length(), examiner->audio_channels()));
                audio->set_stream (as);
                AudioMapping m = as->mapping ();
                film()->make_audio_mapping_default (m);
@@ -169,15 +170,24 @@ DCPContent::as_xml (xmlpp::Node* node) const
        node->add_child("Type")->add_child_text ("DCP");
 
        Content::as_xml (node);
-       video->as_xml (node);
-       audio->as_xml (node);
-       node->add_child("AudioFrameRate")->add_child_text (raw_convert<string> (audio->stream()->frame_rate()));
-       audio->stream()->mapping().as_xml (node->add_child("AudioMapping"));
-       subtitle->as_xml (node);
+
+       if (video) {
+               video->as_xml (node);
+       }
+
+       if (audio) {
+               audio->as_xml (node);
+               node->add_child("AudioFrameRate")->add_child_text (raw_convert<string> (audio->stream()->frame_rate()));
+               node->add_child("AudioLength")->add_child_text (raw_convert<string> (audio->stream()->length()));
+               audio->stream()->mapping().as_xml (node->add_child("AudioMapping"));
+       }
+
+       if (subtitle) {
+               subtitle->as_xml (node);
+       }
 
        boost::mutex::scoped_lock lm (_mutex);
        node->add_child("Name")->add_child_text (_name);
-       node->add_child("HasSubtitles")->add_child_text (subtitle ? "1" : "0");
        node->add_child("Encrypted")->add_child_text (_encrypted ? "1" : "0");
        if (_kdm) {
                node->add_child("KDM")->add_child_text (_kdm->as_xml ());
@@ -191,7 +201,7 @@ DCPContent::as_xml (xmlpp::Node* node) const
 DCPTime
 DCPContent::full_length () const
 {
-       FrameRateChange const frc (video->frame_rate (), film()->video_frame_rate ());
+       FrameRateChange const frc (active_video_frame_rate (), film()->video_frame_rate ());
        return DCPTime::from_frames (llrint (video->length () * frc.factor ()), film()->video_frame_rate ());
 }
 
@@ -361,11 +371,3 @@ DCPContent::can_reference_subtitle (list<string>& why_not) const
        /* XXX: this needs to be fixed */
        return true;
 }
-
-void
-DCPContent::changed (int property)
-{
-       if (property == VideoContentProperty::FRAME_RATE && subtitle) {
-               subtitle->set_video_frame_rate (video->frame_rate ());
-       }
-}