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 = reel->add_child(name);
46 out->add_child("Id")->add_child_text("urn:uuid:" + asset->id());
47 if (reel_asset->annotation_text()) {
48 out->add_child("AnnotationText")->add_child_text(reel_asset->annotation_text().get());
50 if (asset->key_id()) {
51 out->add_child("KeyId")->add_child_text("urn:uuid:" + asset->key_id().get());
52 out->add_child("Key")->add_child_text(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 root->add_child("InteropMode")->add_child_text(cpl->standard() == dcp::Standard::INTEROP ? "true" : "false");
68 auto composition = root->add_child("CompositionList")->add_child("Composition");
69 composition->add_child("Id")->add_child_text("urn:uuid:" + cpl->id());
70 composition->add_child("AnnotationText")->add_child_text(cpl->annotation_text().get_value_or(""));
71 composition->add_child("ContentTitleText")->add_child_text(cpl->content_title_text());
72 auto reel_list = composition->add_child("ReelList");
73 for (auto in_reel: cpl->reels()) {
74 auto out_reel = reel_list->add_child("Reel");
75 out_reel->add_child("Id")->add_child_text("urn:uuid:" + in_reel->id());
76 out_reel->add_child("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());