Allow content parts to not be preset in XML.
authorCarl Hetherington <cth@carlh.net>
Tue, 10 May 2016 12:22:35 +0000 (13:22 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 18 May 2016 10:50:29 +0000 (11:50 +0100)
12 files changed:
src/lib/audio_content.cc
src/lib/audio_content.h
src/lib/dcp_content.cc
src/lib/dcp_subtitle_content.cc
src/lib/ffmpeg_content.cc
src/lib/image_content.cc
src/lib/sndfile_content.cc
src/lib/subtitle_content.cc
src/lib/subtitle_content.h
src/lib/text_subtitle_content.cc
src/lib/video_content.cc
src/lib/video_content.h

index a0c9950a680abf7ed930b8db60cfdf721019c58f..540279a95b862e980d66d00f664ac8d48bd79b72 100644 (file)
@@ -56,6 +56,16 @@ AudioContent::AudioContent (Content* parent, shared_ptr<const Film> film)
 
 }
 
+shared_ptr<AudioContent>
+AudioContent::from_xml (Content* parent, shared_ptr<const Film> film, cxml::ConstNodePtr node)
+{
+       if (!node->optional_number_child<double> ("AudioGain")) {
+               return shared_ptr<AudioContent> ();
+       }
+
+       return shared_ptr<AudioContent> (new AudioContent (parent, film, node));
+}
+
 AudioContent::AudioContent (Content* parent, shared_ptr<const Film> film, cxml::ConstNodePtr node)
        : ContentPart (parent, film)
 {
index 7de0742a51067fdfc061f6e66c1d1f9c401a42f3..e196e15c208e6573441c8c3de736c1d31089e4a3 100644 (file)
@@ -43,7 +43,6 @@ class AudioContent : public ContentPart
 {
 public:
        AudioContent (Content* parent, boost::shared_ptr<const Film>);
-       AudioContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr);
        AudioContent (Content* parent, boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
 
        void as_xml (xmlpp::Node *) const;
@@ -82,8 +81,12 @@ public:
 
        void add_properties (std::list<UserProperty> &) const;
 
+       static boost::shared_ptr<AudioContent> from_xml (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr);
+
 private:
 
+       AudioContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr);
+
        /** Gain to apply to audio in dB */
        double _gain;
        /** Delay to apply to audio (positive moves audio later) in milliseconds */
index 6a6f6efc51013e068dfdfc6db896691c45d1a8d3..2cd7e576f2f63d4f7fa27e1b85e45fd192bcae0b 100644 (file)
@@ -72,9 +72,10 @@ 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))
@@ -83,10 +84,6 @@ DCPContent::DCPContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, in
 
        _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"));
@@ -179,7 +176,6 @@ DCPContent::as_xml (xmlpp::Node* node) const
 
        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 ());
index a6beacb0d728beb21acc3350e4d0555defe2b9d5..0702237f371a39f618e2e2bc99b8df94712104a6 100644 (file)
@@ -45,7 +45,7 @@ DCPSubtitleContent::DCPSubtitleContent (shared_ptr<const Film> film, cxml::Const
        : Content (film, node)
        , _length (node->number_child<ContentTime::Type> ("Length"))
 {
-       subtitle.reset (new SubtitleContent (this, film, node, version));
+       subtitle = SubtitleContent::from_xml (this, film, node, version);
 }
 
 void
index f249a1c35da1bf47ce53545fccf1311eed0aa79c..a8206b13e05cdf0fa1ee7415027b714825a51f83 100644 (file)
@@ -74,9 +74,9 @@ FFmpegContent::FFmpegContent (shared_ptr<const Film> film, boost::filesystem::pa
 FFmpegContent::FFmpegContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version, list<string>& notes)
        : Content (film, node)
 {
-       video.reset (new VideoContent (this, film, node, version));
-       audio.reset (new AudioContent (this, film, node));
-       subtitle.reset (new SubtitleContent (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);
 
        list<cxml::NodePtr> c = node->node_children ("SubtitleStream");
        for (list<cxml::NodePtr>::const_iterator i = c.begin(); i != c.end(); ++i) {
index 57212c589155e699d93a5528d7a02dd5d294dbb4..15c20d8741b1ca4004c8b12600560762831d4f96 100644 (file)
@@ -66,7 +66,7 @@ ImageContent::ImageContent (shared_ptr<const Film> film, boost::filesystem::path
 ImageContent::ImageContent (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);
 }
 
 string
index 2b28ba8b4cf0688c86b688a85ee55e7e8a00f611..7c204e9eb125a486691f66abd4e600d71d46c5bd 100644 (file)
@@ -48,7 +48,7 @@ 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 = AudioContent::from_xml (this, film, node);
        audio->set_stream (
                AudioStreamPtr (
                        new AudioStream (node->number_child<int> ("AudioFrameRate"), AudioMapping (node->node_child ("AudioMapping"), version)))
index 228376c343a33dcfd7cde79ba513163a02815f94..89953b0e5d5c791c1db7fcd2aa94aff61fa6c3a1 100644 (file)
@@ -66,6 +66,16 @@ SubtitleContent::SubtitleContent (Content* parent, shared_ptr<const Film> film)
 
 }
 
+shared_ptr<SubtitleContent>
+SubtitleContent::from_xml (Content* parent, shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
+{
+       if (!node->optional_number_child<double>("SubtitleXOffset") && !node->optional_number_child<double>("SubtitleOffset")) {
+               return shared_ptr<SubtitleContent> ();
+       }
+
+       return shared_ptr<SubtitleContent> (new SubtitleContent (parent, film, node, version));
+}
+
 SubtitleContent::SubtitleContent (Content* parent, shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
        : ContentPart (parent, film)
        , _use (false)
index 09cc92709b2a9a125efec4eff62ae7b83bded7a1..db22863394840b65f382da8241f76b4cdac11e3b 100644 (file)
@@ -47,7 +47,6 @@ class SubtitleContent : public ContentPart
 {
 public:
        SubtitleContent (Content* parent, boost::shared_ptr<const Film>);
-       SubtitleContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int version);
        SubtitleContent (Content* parent, boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
 
        void as_xml (xmlpp::Node *) const;
@@ -129,12 +128,16 @@ public:
                return _outline_colour;
        }
 
+       static boost::shared_ptr<SubtitleContent> from_xml (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int version);
+
 protected:
        /** subtitle language (e.g. "German") or empty if it is not known */
        std::string _language;
 
 private:
        friend struct ffmpeg_pts_offset_test;
+
+       SubtitleContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int version);
        void font_changed ();
        void connect_to_fonts ();
 
index c7be4c19b8d1bd4a7b29bf1278079548d7802c03..74e785ff7cc104b8cb7185ed0b4d80070a415ec3 100644 (file)
@@ -45,7 +45,7 @@ TextSubtitleContent::TextSubtitleContent (shared_ptr<const Film> film, cxml::Con
        : Content (film, node)
        , _length (node->number_child<ContentTime::Type> ("Length"))
 {
-       subtitle.reset (new SubtitleContent (this, film, node, version));
+       subtitle = SubtitleContent::from_xml (this, film, node, version);
 }
 
 void
index ff5a4cb17a1a976e1a0106e509da3777c4195309..75d94510ad3d97a7e1ab9e5ce61d96fc9c8f9124 100644 (file)
@@ -75,6 +75,16 @@ VideoContent::VideoContent (Content* parent, shared_ptr<const Film> film)
 
 }
 
+shared_ptr<VideoContent>
+VideoContent::from_xml (Content* parent, shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
+{
+       if (!node->optional_number_child<int> ("VideoWidth")) {
+               return shared_ptr<VideoContent> ();
+       }
+
+       return shared_ptr<VideoContent> (new VideoContent (parent, film, node, version));
+}
+
 VideoContent::VideoContent (Content* parent, shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
        : ContentPart (parent, film)
 {
index 03ffb0fa83098a45d290313291347d20881fe168..ef54a6be4657c322731a235a550e7265c12dae27 100644 (file)
@@ -51,7 +51,6 @@ class VideoContent : public ContentPart, public boost::enable_shared_from_this<V
 {
 public:
        VideoContent (Content* parent, boost::shared_ptr<const Film>);
-       VideoContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
        VideoContent (Content* parent, boost::shared_ptr<const Film>, std::vector<boost::shared_ptr<Content> >);
 
        void as_xml (xmlpp::Node *) const;
@@ -167,6 +166,8 @@ public:
        void take_from_examiner (boost::shared_ptr<VideoExaminer>);
        void add_properties (std::list<UserProperty> &) const;
 
+       static boost::shared_ptr<VideoContent> from_xml (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
+
 private:
 
        friend struct ffmpeg_pts_offset_test;
@@ -174,6 +175,7 @@ private:
        friend struct best_dcp_frame_rate_test_double;
        friend struct audio_sampling_rate_test;
 
+       VideoContent (Content* parent, boost::shared_ptr<const Film>, cxml::ConstNodePtr, int);
        void setup_default_colour_conversion ();
 
        Frame _length;