Remove unnecessary Film variable in ContentPart.
[dcpomatic.git] / src / lib / dcp_content.cc
index 7a2d350de6b85e574953c0262d2cf55025b05cdc..b28e91dd5cb30d74bf964ae827efa771bb378124 100644 (file)
@@ -62,8 +62,8 @@ DCPContent::DCPContent (shared_ptr<const Film> film, boost::filesystem::path p)
        , _reference_audio (false)
        , _reference_subtitle (false)
 {
-       video.reset (new VideoContent (this, film));
-       audio.reset (new AudioContent (this, film));
+       video.reset (new VideoContent (this));
+       audio.reset (new AudioContent (this));
 
        read_directory (p);
        set_default_colour_conversion ();
@@ -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, node, version);
+       audio = AudioContent::from_xml (this, node);
+       subtitle = SubtitleContent::from_xml (this, 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);
@@ -137,7 +138,7 @@ DCPContent::examine (shared_ptr<Job> job)
                boost::mutex::scoped_lock lm (_mutex);
                _name = examiner->name ();
                if (examiner->has_subtitles ()) {
-                       subtitle.reset (new SubtitleContent (this, film()));
+                       subtitle.reset (new SubtitleContent (this));
                }
                _encrypted = examiner->encrypted ();
                _kdm_valid = examiner->kdm_valid ();
@@ -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 ());
 }
 
@@ -199,8 +209,11 @@ string
 DCPContent::identifier () const
 {
        SafeStringStream s;
-       s << Content::identifier() << "_" << video->identifier() << "_" << subtitle->identifier () << " "
-         << (_reference_video ? "1" : "0")
+       s << Content::identifier() << "_" << video->identifier() << "_";
+       if (subtitle) {
+               s << subtitle->identifier () << " ";
+       }
+       s << (_reference_video ? "1" : "0")
          << (_reference_subtitle ? "1" : "0");
        return s.str ();
 }
@@ -358,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 ());
-       }
-}