Add ContentVersion class.
authorCarl Hetherington <cth@carlh.net>
Wed, 26 Aug 2020 21:02:10 +0000 (23:02 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 20 Sep 2020 17:30:46 +0000 (19:30 +0200)
src/cpl.cc
src/cpl.h
src/types.cc
src/types.h
test/dcp_test.cc
test/encryption_test.cc
test/write_subtitle_test.cc

index 4e6bacc94a69c97cbfb22e1569cf89202eb33bb9..ac442333f2f44ac673accdfdefe931a866167f02 100644 (file)
@@ -75,8 +75,8 @@ CPL::CPL (string annotation_text, ContentKind content_kind)
           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 ();
+       _content_version.id = "urn:uuid:" + uuid;
+       _content_version.label_text = uuid + LocalTime().as_string ();
 }
 
 /** Construct a CPL object from a XML file */
@@ -104,8 +104,8 @@ 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");
+               _content_version.id = content_version->optional_string_child("Id").get_value_or("");
+               _content_version.label_text = content_version->string_child("LabelText");
                content_version->done ();
        } else if (_standard == SMPTE) {
                /* ContentVersion is required in SMPTE */
@@ -158,11 +158,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));
-       {
-               xmlpp::Node* cv = root->add_child ("ContentVersion");
-               cv->add_child ("Id")->add_child_text (_content_version_id);
-               cv->add_child ("LabelText")->add_child_text (_content_version_label_text);
-       }
+       _content_version.as_xml (root);
+
        xmlpp::Element* rating_list = root->add_child("RatingList");
        BOOST_FOREACH (Rating i, _ratings) {
                i.as_xml (rating_list->add_child("Rating"));
index eebb3aaf06d99fe5e3f13dbc1128c3057110e6dd..1132952a65d1c16699885a7d82af4b2b81799fb4 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -104,14 +104,9 @@ public:
                _content_title_text = ct;
        }
 
-       /** @return contents of the &lt;Id&gt; node within &lt;ContentVersion&gt; */
-       void set_content_version_id (std::string id) {
-               _content_version_id = id;
-       }
-
-       /** @return contents of the &lt;LabelText&gt; node within &lt;ContentVersion&gt; */
-       void set_content_version_label_text (std::string text) {
-               _content_version_label_text = text;
+       /** Set the contents of the ContentVersion tag */
+       void set_content_version (ContentVersion v) {
+               _content_version = v;
        }
 
        /** @return the type of the content, used by media servers
@@ -155,8 +150,8 @@ public:
                _ratings = r;
        }
 
-       std::string content_version_label_text () const {
-               return _content_version_label_text;
+       ContentVersion content_version () const {
+               return _content_version;
        }
 
        static std::string static_pkl_type (Standard standard);
@@ -172,8 +167,7 @@ private:
        std::string _annotation_text;
        std::string _content_title_text;            ///< &lt;ContentTitleText&gt;
        ContentKind _content_kind;                  ///< &lt;ContentKind&gt;
-       std::string _content_version_id;            ///< &lt;Id&gt; in &lt;ContentVersion&gt;
-       std::string _content_version_label_text;    ///< &lt;LabelText&gt; in &lt;ContentVersion&gt;
+       ContentVersion _content_version;            ///< &lt;ContentVersion&gt;
        std::list<boost::shared_ptr<Reel> > _reels;
        std::list<Rating> _ratings;
 
index b329396d92b84aa1b7f5ee903c5f9469fd5546d2..746b6f6a81e234385225cbec68891448dc478132 100644 (file)
@@ -462,3 +462,13 @@ dcp::operator<< (ostream& s, Rating const & r)
        s << r.agency << " " << r.label;
        return s;
 }
+
+
+void
+ContentVersion::as_xml (xmlpp::Element* parent) const
+{
+       xmlpp::Node* cv = parent->add_child("ContentVersion");
+       cv->add_child("Id")->add_child_text(id);
+       cv->add_child("LabelText")->add_child_text(label_text);
+}
+
index c600b790ae2da4f30cac817c46d0a3a4219b3862..7b2faa7ce766e22d144fa41200f6e5bc39baa972 100644 (file)
@@ -322,6 +322,23 @@ public:
 extern bool operator== (Rating const & a, Rating const & b);
 extern std::ostream& operator<< (std::ostream& s, Rating const & r);
 
+
+class ContentVersion
+{
+public:
+       ContentVersion () {}
+
+       ContentVersion (std::string id_, std::string label_text_)
+               : id (id_)
+               , label_text (label_text_)
+       {}
+
+       void as_xml (xmlpp::Element* parent) const;
+
+       std::string id;
+       std::string label_text;
+};
+
 }
 
 #endif
index d21ba318ec5e950a25fdfe1f474a893ffa8150ec..a6efe02477f22f589a8759a096b70ceaba3dc42f 100644 (file)
@@ -83,8 +83,9 @@ BOOST_AUTO_TEST_CASE (dcp_test2)
        boost::filesystem::create_directories ("build/test/DCP/dcp_test2");
        dcp::DCP d ("build/test/DCP/dcp_test2");
        shared_ptr<dcp::CPL> cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE));
-       cpl->set_content_version_id ("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
-       cpl->set_content_version_label_text ("81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
+       cpl->set_content_version (
+               dcp::ContentVersion("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00", "81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00")
+               );
        cpl->set_issuer ("OpenDCP 0.0.25");
        cpl->set_creator ("OpenDCP 0.0.25");
        cpl->set_issue_date ("2012-07-17T04:45:18+00:00");
@@ -181,8 +182,9 @@ BOOST_AUTO_TEST_CASE (dcp_test5)
        boost::filesystem::create_directories ("build/test/DCP/dcp_test5");
        dcp::DCP d ("build/test/DCP/dcp_test5");
        shared_ptr<dcp::CPL> cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE));
-       cpl->set_content_version_id ("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
-       cpl->set_content_version_label_text ("81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
+       cpl->set_content_version (
+               dcp::ContentVersion("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00", "81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00")
+               );
        cpl->set_issuer ("OpenDCP 0.0.25");
        cpl->set_creator ("OpenDCP 0.0.25");
        cpl->set_issue_date ("2012-07-17T04:45:18+00:00");
index 913bd206154232de57e967b95fd88f638e0ac22f..c452c07bc3df71f60078abe4b9749b13b30d068c 100644 (file)
@@ -125,8 +125,9 @@ BOOST_AUTO_TEST_CASE (encryption_test)
                                                 shared_ptr<dcp::ReelSoundAsset> (new dcp::ReelSoundAsset (ms, 0)),
                                                 shared_ptr<dcp::ReelSubtitleAsset> ()
                                                 )));
-       cpl->set_content_version_id ("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
-       cpl->set_content_version_label_text ("81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00");
+       cpl->set_content_version (
+               dcp::ContentVersion("urn:uri:81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00", "81fb54df-e1bf-4647-8788-ea7ba154375b_2012-07-17T04:45:18+00:00")
+               );
        cpl->set_annotation_text ("A Test DCP");
        cpl->set_issuer ("OpenDCP 0.0.25");
        cpl->set_creator ("OpenDCP 0.0.25");
index 808df31b081fdf070691ee03ecb715a1e4b4fc4f..0a6e6a8286d5c75f3a4506613eb281639b10b95f 100644 (file)
@@ -372,7 +372,9 @@ BOOST_AUTO_TEST_CASE (write_interop_subtitle_test3)
        cpl->set_creator (creator);
        cpl->set_issue_date (issue_date);
        cpl->set_annotation_text (annotation_text);
-       cpl->set_content_version_label_text ("foo");
+       dcp::ContentVersion cv = cpl->content_version ();
+       cv.label_text = "foo";
+       cpl->set_content_version (cv);
 
        dcp::DCP dcp ("build/test/write_interop_subtitle_test3");
        dcp.add (cpl);