Pass through CompositionMetadataAsset correctly.
authorCarl Hetherington <cth@carlh.net>
Tue, 1 Jun 2021 22:33:01 +0000 (00:33 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 1 Jun 2021 22:33:01 +0000 (00:33 +0200)
We weren't saving Id, and were not quite handling FullContentText
correctly.

src/cpl.cc
src/cpl.h
test/combine_test.cc

index 0eb25052afa4de6d4a1ebb22f5c0348aa978dfb7..20d22b6596c256beeee2203609901760edf1983d 100644 (file)
@@ -237,6 +237,8 @@ CPL::write_xml (boost::filesystem::path file, shared_ptr<const CertificateChain>
 void
 CPL::read_composition_metadata_asset (cxml::ConstNodePtr node)
 {
+       _cpl_metadata_id = remove_urn_uuid(node->string_child("Id"));
+
        auto fctt = node->node_child("FullContentTitleText");
        _full_content_title_text = fctt->content();
        _full_content_title_text_language = fctt->optional_string_attribute("language");
@@ -337,14 +339,14 @@ CPL::maybe_write_composition_metadata_asset (xmlpp::Element* node) const
        auto meta = node->add_child("meta:CompositionMetadataAsset");
        meta->set_namespace_declaration (cpl_metadata_ns, "meta");
 
-       meta->add_child("Id")->add_child_text("urn:uuid:" + make_uuid());
+       meta->add_child("Id")->add_child_text("urn:uuid:" + _cpl_metadata_id);
 
        auto mp = _reels.front()->main_picture();
        meta->add_child("EditRate")->add_child_text(mp->edit_rate().as_string());
        meta->add_child("IntrinsicDuration")->add_child_text(raw_convert<string>(mp->intrinsic_duration()));
 
        auto fctt = meta->add_child("FullContentTitleText", "meta");
-       if (_full_content_title_text) {
+       if (_full_content_title_text && !_full_content_title_text->empty()) {
                fctt->add_child_text (*_full_content_title_text);
        }
        if (_full_content_title_text_language) {
index 797c49d266ce6dc3598ef2d73d18e3d24c82e6c9..9c85dccd502fffafa7a454ef58e0e5b49b3692a1 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -323,6 +323,10 @@ private:
        ContentKind _content_kind;                  ///< &lt;ContentKind&gt;
        std::vector<ContentVersion> _content_versions;
        std::vector<Rating> _ratings;
+       /** ID for CompositionMetadataAsset tag; either a random one, ready for writing a new tag,
+        *  or the one read in from the existing CPL.
+        */
+       std::string _cpl_metadata_id = make_uuid();
        /** Human-readable name of the composition, without any metadata (i.e. no -FTR-EN-XX- etc.) */
        boost::optional<std::string> _full_content_title_text;
        boost::optional<std::string> _full_content_title_text_language;
index 0dcfd2d3f742737a30d9b6fae1a107a95379e6ed..e1512e41f55d1b7b20f9606df63de812ad024caf 100644 (file)
@@ -397,5 +397,21 @@ BOOST_AUTO_TEST_CASE (combine_two_dcps_with_duplicated_asset)
 }
 
 
+BOOST_AUTO_TEST_CASE (check_cpls_unchanged_after_combine)
+{
+       boost::filesystem::path in = "build/test/combine_one_dcp_with_composition_metadata_in";
+       boost::filesystem::path out = "build/test/combine_one_dcp_with_composition_metadata_out";
+       auto dcp = make_simple (in);
+       dcp->write_xml ();
+
+       dcp::combine ({in}, out);
+
+       BOOST_REQUIRE_EQUAL (dcp->cpls().size(), 1U);
+       auto cpl = dcp->cpls()[0]->file();
+       BOOST_REQUIRE (cpl);
+       check_file (*cpl, out / cpl->filename());
+}
+
+
 /* XXX: same CPL names */
 /* XXX: Interop PNG subs */