Use a vector<ContentVersion> instead of just one, to support the
authorCarl Hetherington <cth@carlh.net>
Thu, 27 Aug 2020 22:05:46 +0000 (00:05 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 20 Sep 2020 17:30:46 +0000 (19:30 +0200)
new metadata.

src/cpl.cc
src/cpl.h
test/write_subtitle_test.cc

index ac442333f2f44ac673accdfdefe931a866167f02..6c5610d8e5a45f6bd7cdd2f09e7f39e757e721b3 100644 (file)
@@ -54,6 +54,7 @@ using std::list;
 using std::pair;
 using std::make_pair;
 using std::cout;
+using std::vector;
 using boost::shared_ptr;
 using boost::optional;
 using boost::dynamic_pointer_cast;
@@ -71,12 +72,9 @@ CPL::CPL (string annotation_text, ContentKind content_kind)
        , _content_title_text (annotation_text)
        , _content_kind (content_kind)
 {
-       /* default _content_version_id to a random ID and _content_version_label to
-          a random ID and the current time.
-       */
-       string const uuid = make_uuid();
-       _content_version.id = "urn:uuid:" + uuid;
-       _content_version.label_text = uuid + LocalTime().as_string ();
+       ContentVersion cv;
+       cv.label_text = cv.id + LocalTime().as_string();
+       _content_versions.push_back (cv);
 }
 
 /** Construct a CPL object from a XML file */
@@ -104,8 +102,13 @@ CPL::CPL (boost::filesystem::path file)
        _content_kind = content_kind_from_string (f.string_child ("ContentKind"));
        shared_ptr<cxml::Node> content_version = f.optional_node_child ("ContentVersion");
        if (content_version) {
-               _content_version.id = content_version->optional_string_child("Id").get_value_or("");
-               _content_version.label_text = content_version->string_child("LabelText");
+               /* XXX: SMPTE should insist that Id is present */
+               _content_versions.push_back (
+                       ContentVersion (
+                               content_version->optional_string_child("Id").get_value_or(""),
+                               content_version->string_child("LabelText")
+                               )
+                       );
                content_version->done ();
        } else if (_standard == SMPTE) {
                /* ContentVersion is required in SMPTE */
@@ -158,7 +161,8 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
        root->add_child("Creator")->add_child_text (_creator);
        root->add_child("ContentTitleText")->add_child_text (_content_title_text);
        root->add_child("ContentKind")->add_child_text (content_kind_to_string (_content_kind));
-       _content_version.as_xml (root);
+       DCP_ASSERT (!_content_versions.empty());
+       _content_versions[0].as_xml (root);
 
        xmlpp::Element* rating_list = root->add_child("RatingList");
        BOOST_FOREACH (Rating i, _ratings) {
@@ -333,3 +337,23 @@ CPL::duration () const
        }
        return d;
 }
+void
+CPL::set_content_versions (vector<ContentVersion> v)
+{
+       set<string> ids;
+       BOOST_FOREACH (ContentVersion i, v) {
+               if (!ids.insert(i.id).second) {
+                       throw DuplicateIdError ("Duplicate ID in ContentVersion list");
+               }
+       }
+
+       _content_versions = v;
+}
+
+
+ContentVersion
+CPL::content_version () const
+{
+       DCP_ASSERT (!_content_versions.empty());
+       return _content_versions[0];
+}
index b7055e5d7beebc94219f51205196cc8620626ace..ba1e81963c10d9872856462cc5193f162f93aba4 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -50,6 +50,7 @@
 #include <boost/optional.hpp>
 #include <boost/shared_ptr.hpp>
 #include <list>
+#include <vector>
 
 
 namespace dcp {
@@ -138,15 +139,19 @@ public:
                return _content_kind;
        }
 
-       ContentVersion content_version () const {
-               return _content_version;
+       ContentVersion content_version () const;
+
+       std::vector<ContentVersion> content_versions () const {
+               return _content_versions;
        }
 
-       /** Set the contents of the ContentVersion tag */
        void set_content_version (ContentVersion v) {
-               _content_version = v;
+               _content_versions.clear ();
+               _content_versions.push_back (v);
        }
 
+       void set_content_versions (std::vector<ContentVersion> v);
+
        std::list<Rating> ratings () const {
                return _ratings;
        }
@@ -172,8 +177,8 @@ private:
        std::string _annotation_text;
        std::string _content_title_text;            ///< &lt;ContentTitleText&gt;
        ContentKind _content_kind;                  ///< &lt;ContentKind&gt;
-       ContentVersion _content_version;            ///< &lt;ContentVersion&gt;
        std::list<Rating> _ratings;
+       std::vector<ContentVersion> _content_versions;
 
        std::list<boost::shared_ptr<Reel> > _reels;
 
index 0a6e6a8286d5c75f3a4506613eb281639b10b95f..b7d8119a5d22f7770033fcd9b6c032ee7db32ef6 100644 (file)
@@ -372,7 +372,7 @@ BOOST_AUTO_TEST_CASE (write_interop_subtitle_test3)
        cpl->set_creator (creator);
        cpl->set_issue_date (issue_date);
        cpl->set_annotation_text (annotation_text);
-       dcp::ContentVersion cv = cpl->content_version ();
+       dcp::ContentVersion cv = cpl->content_version();
        cv.label_text = "foo";
        cpl->set_content_version (cv);