2 Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "dcp_digest_file.h"
26 #include <dcp/reel_picture_asset.h>
27 #include <dcp/reel_sound_asset.h>
28 #include <dcp/reel_subtitle_asset.h>
29 #include <dcp/reel_smpte_subtitle_asset.h>
30 #include <dcp/warnings.h>
31 LIBDCP_DISABLE_WARNINGS
32 #include <libxml++/libxml++.h>
33 LIBDCP_ENABLE_WARNINGS
36 using std::dynamic_pointer_cast;
37 using std::shared_ptr;
41 template <class R, class A>
42 void add_asset(string film_key, shared_ptr<R> reel_asset, shared_ptr<A> asset, xmlpp::Element* reel, string name)
45 auto out = cxml::add_child(reel, name);
46 cxml::add_text_child(out, "Id", "urn:uuid:" + asset->id());
47 if (reel_asset->annotation_text()) {
48 cxml::add_text_child(out, "AnnotationText", reel_asset->annotation_text().get());
50 if (asset->key_id()) {
51 cxml::add_text_child(out, "KeyId", "urn:uuid:" + asset->key_id().get());
52 cxml::add_text_child(out, "Key", asset->key() ? asset->key()->hex() : film_key);
59 write_dcp_digest_file (
60 boost::filesystem::path path,
61 shared_ptr<dcp::CPL> cpl,
66 auto root = doc.create_root_node("FHG_DCP_DIGEST", "http://www.fhg.de/2009/04/02/dcpdig");
67 cxml::add_text_child(root, "InteropMode", cpl->standard() == dcp::Standard::INTEROP ? "true" : "false");
68 auto composition = cxml::add_child(cxml::add_child(root, "CompositionList"), "Composition");
69 cxml::add_text_child(composition, "Id", "urn:uuid:" + cpl->id());
70 cxml::add_text_child(composition, "AnnotationText", cpl->annotation_text().get_value_or(""));
71 cxml::add_text_child(composition, "ContentTitleText", cpl->content_title_text());
72 auto reel_list = cxml::add_child(composition, "ReelList");
73 for (auto in_reel: cpl->reels()) {
74 auto out_reel = cxml::add_child(reel_list, "Reel");
75 cxml::add_text_child(out_reel, "Id", "urn:uuid:" + in_reel->id());
76 cxml::add_child(out_reel, "AnnotationText");
77 if (in_reel->main_picture()) {
78 add_asset(film_key, in_reel->main_picture(), in_reel->main_picture()->asset(), out_reel, "MainPicture");
80 if (in_reel->main_sound()) {
81 add_asset(film_key, in_reel->main_sound(), in_reel->main_sound()->asset(), out_reel, "MainSound");
83 if (auto smpte_sub = dynamic_pointer_cast<dcp::ReelSMPTESubtitleAsset>(in_reel->main_subtitle())) {
84 add_asset(film_key, smpte_sub, smpte_sub->smpte_asset(), out_reel, "MainSubtitle");
87 doc.write_to_file_formatted(path.string());