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"
27 #include <dcp/reel_picture_asset.h>
28 #include <dcp/reel_sound_asset.h>
29 #include <dcp/reel_subtitle_asset.h>
30 #include <dcp/reel_smpte_subtitle_asset.h>
31 DCPOMATIC_DISABLE_WARNINGS
32 #include <libxml++/libxml++.h>
33 DCPOMATIC_ENABLE_WARNINGS
36 using std::dynamic_pointer_cast;
37 using std::shared_ptr;
41 template <class R, class A>
42 void add_asset(string 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 out->add_child("AnnotationText")->add_child_text(reel_asset->annotation_text());
48 if (asset->key_id()) {
49 out->add_child("KeyId")->add_child_text("urn:uuid:" + asset->key_id().get());
50 out->add_child("Key")->add_child_text(key);
57 write_dcp_digest_file (
58 boost::filesystem::path path,
59 shared_ptr<dcp::CPL> cpl,
64 auto root = doc.create_root_node("FHG_DCP_DIGEST", "http://www.fhg.de/2009/04/02/dcpdig");
65 root->add_child("InteropMode")->add_child_text(cpl->standard() == dcp::Standard::INTEROP ? "true" : "false");
66 auto composition = root->add_child("CompositionList")->add_child("Composition");
67 composition->add_child("Id")->add_child_text("urn:uuid:" + cpl->id());
68 composition->add_child("AnnotationText")->add_child_text(cpl->annotation_text().get_value_or(""));
69 composition->add_child("ContentTitleText")->add_child_text(cpl->content_title_text());
70 auto reel_list = composition->add_child("ReelList");
71 for (auto in_reel: cpl->reels()) {
72 auto out_reel = reel_list->add_child("Reel");
73 out_reel->add_child("Id")->add_child_text("urn:uuid:" + in_reel->id());
74 out_reel->add_child("AnnotationText");
75 if (in_reel->main_picture()) {
76 add_asset(key, in_reel->main_picture(), in_reel->main_picture()->asset(), out_reel, "MainPicture");
78 if (in_reel->main_sound()) {
79 add_asset(key, in_reel->main_sound(), in_reel->main_sound()->asset(), out_reel, "MainSound");
81 if (auto smpte_sub = dynamic_pointer_cast<dcp::ReelSMPTESubtitleAsset>(in_reel->main_subtitle())) {
82 add_asset(key, smpte_sub, smpte_sub->smpte_asset(), out_reel, "MainSubtitle");
85 doc.write_to_file_formatted(path.string());