+ if (
+ !_main_sound_configuration ||
+ !_main_sound_sample_rate ||
+ !_main_picture_stored_area ||
+ !_main_picture_active_area ||
+ _reels.empty() ||
+ !_reels.front()->main_picture()) {
+ return;
+ }
+
+ xmlpp::Element* meta = node->add_child("meta:CompositionMetadataAsset");
+ meta->set_namespace_declaration (cpl_metadata_ns, "meta");
+
+ meta->add_child("Id")->add_child_text("urn:uuid:" + make_uuid());
+
+ shared_ptr<dcp::ReelPictureAsset> 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()));
+
+ xmlpp::Element* 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");
+
+ xmlpp::Element* 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));
+
+ xmlpp::Element* 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;
+ BOOST_FOREACH (shared_ptr<const Reel> 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;
+ }
+ BOOST_FOREACH (string const& i, _additional_subtitle_languages) {
+ if (!lang.empty()) {
+ lang += " ";
+ }
+ lang += i;
+ }
+ meta->add_child("MainSubtitleLanguageList")->add_child_text(lang);
+ }
+
+ if (_reels.front()->main_sound()) {
+ shared_ptr<const SoundAsset> asset = _reels.front()->main_sound()->asset();
+ if (asset) {
+ shared_ptr<SoundAssetReader> 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)) {
+ xmlpp::Element* 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");
+ xmlpp::Element* 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;
+ ASDCP::Result_t r = reader->reader()->OP1aHeader().GetMDObjectsByType(
+ asdcp_smpte_dict->ul(ASDCP::MDD_AudioChannelLabelSubDescriptor),
+ channels
+ );
+
+ BOOST_FOREACH (ASDCP::MXF::InterchangeObject* i, channels) {
+ ASDCP::MXF::AudioChannelLabelSubDescriptor* channel = reinterpret_cast<ASDCP::MXF::AudioChannelLabelSubDescriptor*>(i);
+ xmlpp::Element* 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));
+ }
+ }
+ }
+ }
+ }