Support DCP digest files (#2109).
authorCarl Hetherington <cth@carlh.net>
Wed, 3 Nov 2021 17:19:58 +0000 (18:19 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 20 Apr 2022 19:23:54 +0000 (21:23 +0200)
src/lib/dcp_digest_file.cc [new file with mode: 0644]
src/lib/dcp_digest_file.h [new file with mode: 0644]
src/lib/dcp_transcode_job.cc
src/lib/wscript
test/dcp_digest_file_test.cc [new file with mode: 0644]
test/wscript

diff --git a/src/lib/dcp_digest_file.cc b/src/lib/dcp_digest_file.cc
new file mode 100644 (file)
index 0000000..b178e3d
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+    Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "dcp_digest_file.h"
+#include "warnings.h"
+#include <dcp/cpl.h>
+#include <dcp/mxf.h>
+#include <dcp/reel.h>
+#include <dcp/reel_picture_asset.h>
+#include <dcp/reel_sound_asset.h>
+#include <dcp/reel_subtitle_asset.h>
+#include <dcp/reel_smpte_subtitle_asset.h>
+DCPOMATIC_DISABLE_WARNINGS
+#include <libxml++/libxml++.h>
+DCPOMATIC_ENABLE_WARNINGS
+
+
+using std::dynamic_pointer_cast;
+using std::shared_ptr;
+using std::string;
+
+
+template <class R, class A>
+void add_asset(string key, shared_ptr<R> reel_asset, shared_ptr<A> asset, xmlpp::Element* reel, string name)
+{
+       if (asset) {
+               auto out = reel->add_child(name);
+               out->add_child("Id")->add_child_text("urn:uuid:" + asset->id());
+               if (reel_asset->annotation_text()) {
+                       out->add_child("AnnotationText")->add_child_text(reel_asset->annotation_text().get());
+               }
+               if (asset->key_id()) {
+                       out->add_child("KeyId")->add_child_text("urn:uuid:" + asset->key_id().get());
+                       out->add_child("Key")->add_child_text(key);
+               }
+       }
+};
+
+
+void
+write_dcp_digest_file (
+       boost::filesystem::path path,
+       shared_ptr<dcp::CPL> cpl,
+       string key
+       )
+{
+       xmlpp::Document doc;
+       auto root = doc.create_root_node("FHG_DCP_DIGEST", "http://www.fhg.de/2009/04/02/dcpdig");
+       root->add_child("InteropMode")->add_child_text(cpl->standard() == dcp::Standard::INTEROP ? "true" : "false");
+       auto composition = root->add_child("CompositionList")->add_child("Composition");
+       composition->add_child("Id")->add_child_text("urn:uuid:" + cpl->id());
+       composition->add_child("AnnotationText")->add_child_text(cpl->annotation_text().get_value_or(""));
+       composition->add_child("ContentTitleText")->add_child_text(cpl->content_title_text());
+       auto reel_list = composition->add_child("ReelList");
+       for (auto in_reel: cpl->reels()) {
+               auto out_reel = reel_list->add_child("Reel");
+               out_reel->add_child("Id")->add_child_text("urn:uuid:" + in_reel->id());
+               out_reel->add_child("AnnotationText");
+               if (in_reel->main_picture()) {
+                       add_asset(key, in_reel->main_picture(), in_reel->main_picture()->asset(), out_reel, "MainPicture");
+               }
+               if (in_reel->main_sound()) {
+                       add_asset(key, in_reel->main_sound(), in_reel->main_sound()->asset(), out_reel, "MainSound");
+               }
+               if (auto smpte_sub = dynamic_pointer_cast<dcp::ReelSMPTESubtitleAsset>(in_reel->main_subtitle())) {
+                       add_asset(key, smpte_sub, smpte_sub->smpte_asset(), out_reel, "MainSubtitle");
+               }
+       }
+       doc.write_to_file_formatted(path.string());
+}
+
diff --git a/src/lib/dcp_digest_file.h b/src/lib/dcp_digest_file.h
new file mode 100644 (file)
index 0000000..2a3b165
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+    Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include <dcp/dcp.h>
+#include <boost/filesystem.hpp>
+
+
+extern void write_dcp_digest_file (boost::filesystem::path filename, std::shared_ptr<dcp::CPL> cpl, std::string key);
+
index e9ff4f4e0a77393370564157a527c719c700a8e9..ae3f3f8377b82f10d2daad2148c49bb7968fe99a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2021-2022 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 
 #include "config.h"
+#include "dcp_content.h"
+#include "dcp_digest_file.h"
 #include "dcp_transcode_job.h"
 #include "film.h"
 #include "job_manager.h"
 #include "upload_job.h"
+#include <dcp/cpl.h>
+#include <dcp/search.h>
 
 
 using std::make_shared;
@@ -43,4 +47,12 @@ DCPTranscodeJob::post_transcode ()
        if (Config::instance()->upload_after_make_dcp()) {
                JobManager::instance()->add(make_shared<UploadJob>(_film));
        }
+
+       dcp::DCP dcp(_film->dir(_film->dcp_name()));
+       dcp.read();
+
+       for (auto cpl: dcp.cpls()) {
+               write_dcp_digest_file (_film->file(cpl->annotation_text().get_value_or(cpl->id()) + ".dcpdig"), cpl, _film->key().hex());
+       }
 }
+
index 86b7561be84d8b4f67d0ec9765ed016b76705d59..b3428f20b1fda6e5f78a54f00e38e717e15fb32c 100644 (file)
@@ -67,6 +67,7 @@ sources = """
           dcp_decoder.cc
           dcp_encoder.cc
           dcp_examiner.cc
+          dcp_digest_file.cc
           dcp_subtitle.cc
           dcp_subtitle_content.cc
           dcp_subtitle_decoder.cc
diff --git a/test/dcp_digest_file_test.cc b/test/dcp_digest_file_test.cc
new file mode 100644 (file)
index 0000000..85928b6
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+    Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "lib/content_factory.h"
+#include "lib/dcp_digest_file.h"
+#include "lib/film.h"
+#include "test.h"
+#include <dcp/dcp.h>
+#include <boost/test/unit_test.hpp>
+
+
+BOOST_AUTO_TEST_CASE (dcp_digest_file_test)
+{
+       dcp::DCP dcp("test/data/dcp_digest_test_dcp");
+       dcp.read ();
+       BOOST_REQUIRE_EQUAL (dcp.cpls().size(), 1U);
+
+       write_dcp_digest_file ("build/test/digest.xml", dcp.cpls()[0], "e684e49e89182e907dabe5d9b3bd81ba");
+
+       check_xml ("test/data/digest.xml", "build/test/digest.xml", {});
+}
+
index c59c0f6baff94df420cdb86655fd30694142cc38..223f70b80e6983f4fc36bdbf0d95c54dbaeb8245 100644 (file)
@@ -68,6 +68,7 @@ def build(bld):
                  crypto_test.cc
                  dcpomatic_time_test.cc
                  dcp_decoder_test.cc
+                 dcp_digest_file_test.cc
                  dcp_metadata_test.cc
                  dcp_playback_test.cc
                  dcp_subtitle_test.cc