/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
using std::ofstream;
using std::ostream;
using std::list;
+using std::pair;
+using std::make_pair;
using boost::shared_ptr;
using boost::lexical_cast;
+using boost::optional;
using namespace libdcp;
CPL::CPL (string directory, string name, ContentKind content_kind, int length, int frames_per_second)
/** Construct a CPL object from a XML file.
* @param directory The directory containing this CPL's DCP.
* @param file The CPL XML filename.
- * @param asset_map The corresponding asset map.
+ * @param asset_maps AssetMaps to look for assets in.
* @param require_mxfs true to throw an exception if a required MXF file does not exist.
*/
-CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMap> asset_map, bool require_mxfs)
+CPL::CPL (string directory, string file, list<PathAssetMap> asset_maps, bool require_mxfs)
: _directory (directory)
, _content_kind (FEATURE)
, _length (0)
/* Trim urn:uuid: off the front */
_id = cpl->id.substr (9);
- for (list<shared_ptr<libdcp::parse::Reel> >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) {
+ for (list<shared_ptr<parse::Reel> >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) {
shared_ptr<parse::Picture> p;
if (!(*i)->asset_list->main_stereoscopic_picture && p->edit_rate == p->frame_rate) {
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
+
try {
picture.reset (new MonoPictureAsset (
- _directory,
- asset_map->asset_from_id (p->id)->chunks.front()->path
+ asset.first,
+ asset.second->chunks.front()->path
)
);
} else {
try {
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
+
picture.reset (new StereoPictureAsset (
- _directory,
- asset_map->asset_from_id (p->id)->chunks.front()->path,
+ asset.first,
+ asset.second->chunks.front()->path,
_fps,
p->duration
)
if ((*i)->asset_list->main_sound) {
try {
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_sound->id);
+
sound.reset (new SoundAsset (
- _directory,
- asset_map->asset_from_id ((*i)->asset_list->main_sound->id)->chunks.front()->path
+ asset.first,
+ asset.second->chunks.front()->path
)
);
if ((*i)->asset_list->main_subtitle) {
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_subtitle->id);
+
subtitle.reset (new SubtitleAsset (
- _directory,
- asset_map->asset_from_id ((*i)->asset_list->main_subtitle->id)->chunks.front()->path
+ asset.first,
+ asset.second->chunks.front()->path
)
);
}
void
-CPL::write_xml (XMLMetadata const & metadata, shared_ptr<Encryption> crypt) const
+CPL::write_xml (bool interop, XMLMetadata const & metadata, shared_ptr<Encryption> crypt) const
{
boost::filesystem::path p;
p /= _directory;
p /= s.str();
xmlpp::Document doc;
- xmlpp::Element* root = doc.create_root_node ("CompositionPlaylist", "http://www.smpte-ra.org/schemas/429-7/2006/CPL");
+ xmlpp::Element* root;
+ if (interop) {
+ root = doc.create_root_node ("CompositionPlaylist", "http://www.digicine.com/PROTO-ASDCP-CPL-20040511#");
+ } else {
+ root = doc.create_root_node ("CompositionPlaylist", "http://www.smpte-ra.org/schemas/429-7/2006/CPL");
+ }
if (crypt) {
root->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "dsig");
root->add_child("Id")->add_child_text ("urn:uuid:" + _id);
root->add_child("AnnotationText")->add_child_text (_name);
root->add_child("IssueDate")->add_child_text (metadata.issue_date);
+ root->add_child("Issuer")->add_child_text (metadata.issuer);
root->add_child("Creator")->add_child_text (metadata.creator);
root->add_child("ContentTitleText")->add_child_text (_name);
root->add_child("ContentKind")->add_child_text (content_kind_to_string (_content_kind));
}
root->add_child("RatingList");
- xmlpp::Node* reel_list = root->add_child ("ReelList");
+ xmlpp::Element* reel_list = root->add_child ("ReelList");
for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
- (*i)->write_to_cpl (reel_list);
+ (*i)->write_to_cpl (reel_list, interop);
}
if (crypt) {
- sign (root, crypt->certificates, crypt->signer_key);
+ sign (root, crypt->certificates, crypt->signer_key, interop);
}
doc.write_to_file_formatted (p.string (), "UTF-8");
- _digest = make_digest (p.string ());
+ _digest = make_digest (p.string (), 0);
_length = boost::filesystem::file_size (p.string ());
}
if (_length != other._length) {
stringstream s;
- s << "lengths differ (" << _length << " cf " << other._length << ")";
note (ERROR, String::compose ("lengths differ (%1 vs %2)", _length, other._length));
- return false;
}
if (_reels.size() != other._reels.size()) {
shared_ptr<const Certificate> recipient_cert,
boost::posix_time::ptime from,
boost::posix_time::ptime until,
+ bool interop,
MXFMetadata const & mxf_metadata,
XMLMetadata const & xml_metadata
) const
xmlAddID (0, doc->cobj(), (const xmlChar *) "ID_AuthenticatedPublic", authenticated_public->get_attribute("Id")->cobj());
authenticated_public->add_child("MessageId")->add_child_text ("urn:uuid:" + make_uuid());
+ /* XXX: this should probably be different if interop == true */
authenticated_public->add_child("MessageType")->add_child_text ("http://www.smpte-ra.org/430-1/2006/KDM#kdm-key-type");
authenticated_public->add_child("AnnotationText")->add_child_text (mxf_metadata.product_name);
authenticated_public->add_child("IssueDate")->add_child_text (xml_metadata.issue_date);
{
xmlpp::Element* signer = authenticated_public->add_child("Signer");
- signer->add_child("X509IssuerName", "ds")->add_child_text (recipient_cert->issuer());
- signer->add_child("X509SerialNumber", "ds")->add_child_text (recipient_cert->serial());
+ signer->add_child("X509IssuerName", "ds")->add_child_text (certificates.leaf()->issuer());
+ signer->add_child("X509SerialNumber", "ds")->add_child_text (certificates.leaf()->serial());
}
{
signed_info->add_child("CanonicalizationMethod", "ds")->set_attribute(
"Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
);
- signed_info->add_child("SignatureMethod", "ds")->set_attribute(
- "Algorithm", "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
- );
+
+ if (interop) {
+ signed_info->add_child("SignatureMethod", "ds")->set_attribute(
+ "Algorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
+ );
+ } else {
+ signed_info->add_child("SignatureMethod", "ds")->set_attribute(
+ "Algorithm", "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
+ );
+ }
+
{
xmlpp::Element* reference = signed_info->add_child("Reference", "ds");
reference->set_attribute("URI", "#ID_AuthenticatedPublic");
(*i)->add_kdm (kdm);
}
}
+
+pair<string, shared_ptr<const parse::AssetMapAsset> >
+CPL::asset_from_id (list<PathAssetMap> asset_maps, string id) const
+{
+ for (list<PathAssetMap>::const_iterator i = asset_maps.begin(); i != asset_maps.end(); ++i) {
+ shared_ptr<parse::AssetMapAsset> a = i->second->asset_from_id (id);
+ if (a) {
+ return make_pair (i->first, a);
+ }
+ }
+
+ return make_pair ("", shared_ptr<const parse::AssetMapAsset> ());
+}