Store audio length in AudioStream.
[dcpomatic.git] / src / lib / dcp_content.cc
index 6a6f6efc51013e068dfdfc6db896691c45d1a8d3..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,17 +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"));
+
+       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 ());