Some allowances for video/audio/subtitle possibly being null.
[dcpomatic.git] / src / lib / sndfile_content.cc
index 2b28ba8b4cf0688c86b688a85ee55e7e8a00f611..bf5f3af5bbd22775b0a2ef4a9134ae6bfaf2a031 100644 (file)
@@ -48,21 +48,29 @@ SndfileContent::SndfileContent (shared_ptr<const Film> film, cxml::ConstNodePtr
        : Content (film, node)
        , _audio_length (node->number_child<Frame> ("AudioLength"))
 {
-       audio.reset (new AudioContent (this, film, node));
-       audio->set_stream (
-               AudioStreamPtr (
-                       new AudioStream (node->number_child<int> ("AudioFrameRate"), AudioMapping (node->node_child ("AudioMapping"), version)))
-               );
+       audio = AudioContent::from_xml (this, film, node);
+
+       if (audio) {
+               audio->set_stream (
+                       AudioStreamPtr (
+                               new AudioStream (node->number_child<int> ("AudioFrameRate"), AudioMapping (node->node_child ("AudioMapping"), version)))
+                       );
+       }
 }
 
 void
 SndfileContent::as_xml (xmlpp::Node* node) const
 {
        node->add_child("Type")->add_child_text ("Sndfile");
+
        Content::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 (audio) {
+               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"));
+       }
+
        node->add_child("AudioLength")->add_child_text (raw_convert<string> (audio_length ()));
 }