+ meta->add_child("Id")->add_child_text("urn:uuid:" + make_uuid());
+
+ 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) {
+ fctt->add_child_text (*_full_content_title_text);
+ }
+ if (_full_content_title_text_language) {
+ fctt->set_attribute("language", *_full_content_title_text_language);
+ }
+
+ if (_release_territory) {
+ meta->add_child("ReleaseTerritory", "meta")->add_child_text(*_release_territory);
+ }
+
+ if (_version_number) {
+ xmlpp::Element* vn = meta->add_child("VersionNumber", "meta");
+ vn->add_child_text(raw_convert<string>(*_version_number));
+ if (_status) {
+ vn->set_attribute("status", status_to_string(*_status));
+ }
+ }
+
+ if (_chain) {
+ meta->add_child("Chain", "meta")->add_child_text(*_chain);
+ }
+
+ if (_distributor) {
+ meta->add_child("Distributor", "meta")->add_child_text(*_distributor);
+ }
+
+ if (_facility) {
+ meta->add_child("Facility", "meta")->add_child_text(*_facility);
+ }
+
+ if (_content_versions.size() > 1) {
+ xmlpp::Element* vc = meta->add_child("AlternateContentVersionList", "meta");
+ for (size_t i = 1; i < _content_versions.size(); ++i) {
+ _content_versions[i].as_xml (vc);
+ }
+ }
+
+ if (_luminance) {
+ _luminance->as_xml (meta, "meta");
+ }
+
+ meta->add_child("MainSoundConfiguration", "meta")->add_child_text(*_main_sound_configuration);
+ meta->add_child("MainSoundSampleRate", "meta")->add_child_text(raw_convert<string>(*_main_sound_sample_rate) + " 1");
+
+ auto stored = meta->add_child("MainPictureStoredArea", "meta");
+ stored->add_child("Width", "meta")->add_child_text(raw_convert<string>(_main_picture_stored_area->width));
+ stored->add_child("Height", "meta")->add_child_text(raw_convert<string>(_main_picture_stored_area->height));
+
+ auto active = meta->add_child("MainPictureActiveArea", "meta");
+ active->add_child("Width", "meta")->add_child_text(raw_convert<string>(_main_picture_active_area->width));
+ active->add_child("Height", "meta")->add_child_text(raw_convert<string>(_main_picture_active_area->height));
+
+ optional<string> first_subtitle_language;
+ for (auto i: _reels) {
+ if (i->main_subtitle()) {
+ first_subtitle_language = i->main_subtitle()->language();
+ if (first_subtitle_language) {
+ break;
+ }
+ }
+ }
+
+ if (first_subtitle_language || !_additional_subtitle_languages.empty()) {
+ string lang;
+ if (first_subtitle_language) {
+ lang = *first_subtitle_language;
+ }
+ for (auto const& i: _additional_subtitle_languages) {
+ if (!lang.empty()) {
+ lang += " ";
+ }
+ lang += i;
+ }
+ meta->add_child("MainSubtitleLanguageList", "meta")->add_child_text(lang);
+ }
+
+ /* SMPTE Bv2.1 8.6.3 */
+ auto extension = meta->add_child("ExtensionMetadataList", "meta")->add_child("ExtensionMetadata", "meta");
+ extension->set_attribute("scope", "http://isdcf.com/ns/cplmd/app");
+ extension->add_child("Name", "meta")->add_child_text("Application");
+ auto property = extension->add_child("PropertyList", "meta")->add_child("Property", "meta");
+ property->add_child("Name", "meta")->add_child_text("DCP Constraints Profile");
+ property->add_child("Value", "meta")->add_child_text("SMPTE-RDD-52:2020-Bv2.1");
+
+ if (_reels.front()->main_sound()) {
+ auto asset = _reels.front()->main_sound()->asset();
+ if (asset) {
+ auto reader = asset->start_read ();
+ ASDCP::MXF::SoundfieldGroupLabelSubDescriptor* soundfield;
+ ASDCP::Result_t r = reader->reader()->OP1aHeader().GetMDObjectByType(
+ asdcp_smpte_dict->ul(ASDCP::MDD_SoundfieldGroupLabelSubDescriptor),
+ reinterpret_cast<ASDCP::MXF::InterchangeObject**>(&soundfield)
+ );
+ if (KM_SUCCESS(r)) {
+ auto mca_subs = meta->add_child("mca:MCASubDescriptors");
+ mca_subs->set_namespace_declaration (mca_sub_descriptors_ns, "mca");
+ mca_subs->set_namespace_declaration (smpte_395_ns, "r0");
+ mca_subs->set_namespace_declaration (smpte_335_ns, "r1");
+ auto sf = mca_subs->add_child("SoundfieldGroupLabelSubDescriptor", "r0");
+ char buffer[64];
+ soundfield->InstanceUID.EncodeString(buffer, sizeof(buffer));
+ sf->add_child("InstanceID", "r1")->add_child_text("urn:uuid:" + string(buffer));
+ soundfield->MCALabelDictionaryID.EncodeString(buffer, sizeof(buffer));
+ sf->add_child("MCALabelDictionaryID", "r1")->add_child_text("urn:smpte:ul:" + string(buffer));
+ soundfield->MCALinkID.EncodeString(buffer, sizeof(buffer));
+ sf->add_child("MCALinkID", "r1")->add_child_text("urn:uuid:" + string(buffer));
+ soundfield->MCATagSymbol.EncodeString(buffer, sizeof(buffer));
+ sf->add_child("MCATagSymbol", "r1")->add_child_text(buffer);
+ if (!soundfield->MCATagName.empty()) {
+ soundfield->MCATagName.get().EncodeString(buffer, sizeof(buffer));
+ sf->add_child("MCATagName", "r1")->add_child_text(buffer);
+ }
+ if (!soundfield->RFC5646SpokenLanguage.empty()) {
+ soundfield->RFC5646SpokenLanguage.get().EncodeString(buffer, sizeof(buffer));
+ sf->add_child("RFC5646SpokenLanguage", "r1")->add_child_text(buffer);
+ }
+
+ list<ASDCP::MXF::InterchangeObject*> channels;
+ auto r = reader->reader()->OP1aHeader().GetMDObjectsByType(
+ asdcp_smpte_dict->ul(ASDCP::MDD_AudioChannelLabelSubDescriptor),
+ channels
+ );
+
+ for (auto i: channels) {
+ auto channel = reinterpret_cast<ASDCP::MXF::AudioChannelLabelSubDescriptor*>(i);
+ auto ch = mca_subs->add_child("AudioChannelLabelSubDescriptor", "r0");
+ channel->InstanceUID.EncodeString(buffer, sizeof(buffer));
+ ch->add_child("InstanceID", "r1")->add_child_text("urn:uuid:" + string(buffer));
+ channel->MCALabelDictionaryID.EncodeString(buffer, sizeof(buffer));
+ ch->add_child("MCALabelDictionaryID", "r1")->add_child_text("urn:smpte:ul:" + string(buffer));
+ channel->MCALinkID.EncodeString(buffer, sizeof(buffer));
+ ch->add_child("MCALinkID", "r1")->add_child_text("urn:uuid:" + string(buffer));
+ channel->MCATagSymbol.EncodeString(buffer, sizeof(buffer));
+ ch->add_child("MCATagSymbol", "r1")->add_child_text(buffer);
+ if (!channel->MCATagName.empty()) {
+ channel->MCATagName.get().EncodeString(buffer, sizeof(buffer));
+ ch->add_child("MCATagName", "r1")->add_child_text(buffer);
+ }
+ if (!channel->MCAChannelID.empty()) {
+ ch->add_child("MCAChannelID", "r1")->add_child_text(raw_convert<string>(channel->MCAChannelID.get()));
+ }
+ if (!channel->RFC5646SpokenLanguage.empty()) {
+ channel->RFC5646SpokenLanguage.get().EncodeString(buffer, sizeof(buffer));
+ ch->add_child("RFC5646SpokenLanguage", "r1")->add_child_text(buffer);
+ }
+ if (!channel->SoundfieldGroupLinkID.empty()) {
+ channel->SoundfieldGroupLinkID.get().EncodeString(buffer, sizeof(buffer));
+ ch->add_child("SoundfieldGroupLinkID", "r1")->add_child_text("urn:uuid:" + string(buffer));
+ }
+ }
+ }
+ }
+ }
+}
+
+
+template <class T>
+void
+add_file_assets (vector<shared_ptr<T>>& assets, vector<shared_ptr<Reel>> reels)
+{
+ for (auto i: reels) {