X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fdcp.cc;h=c0fe70f64ad4d0a99d2503c9f03d7b12a40edca2;hb=bb06c37abbe900a1f0f86d428e9068a96682c188;hp=1114656251db1f6eb8f200e58b59cc17b8b056c1;hpb=043d382cb7360f35e97b9057045c6a255b905443;p=libdcp.git diff --git a/src/dcp.cc b/src/dcp.cc index 11146562..c0fe70f6 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -1,20 +1,34 @@ /* Copyright (C) 2012-2015 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of libdcp. + + libdcp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + libdcp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - + along with libdcp. If not, see . + + In addition, as a special exception, the copyright holders give + permission to link the code of portions of this program with the + OpenSSL library under certain conditions as described in each + individual source file, and distribute linked combinations + including the two. + + You must obey the GNU General Public License in all respects + for all of the code used other than OpenSSL. If you modify + file(s) with this exception, you may extend this exception to your + version of the file(s), but you are not obligated to do so. If you + do not wish to do so, delete this exception statement from your + version. If you delete this exception statement from all source + files in the program, then also delete it here. */ /** @file src/dcp.cc @@ -36,27 +50,25 @@ #include "cpl.h" #include "certificate_chain.h" #include "compose.hpp" -#include "AS_DCP.h" #include "decrypted_kdm.h" #include "decrypted_kdm_key.h" #include "dcp_assert.h" #include "reel_asset.h" #include "font_asset.h" +#include #include #include #include #include #include #include -#include using std::string; using std::list; +using std::vector; using std::cout; -using std::ostream; using std::make_pair; using std::map; -using std::cout; using std::cerr; using std::exception; using boost::shared_ptr; @@ -68,7 +80,7 @@ static string const assetmap_interop_ns = "http://www.digicine.com/PROTO-ASDCP-A static string const assetmap_smpte_ns = "http://www.smpte-ra.org/schemas/429-9/2007/AM"; static string const pkl_interop_ns = "http://www.digicine.com/PROTO-ASDCP-PKL-20040311#"; static string const pkl_smpte_ns = "http://www.smpte-ra.org/schemas/429-8/2007/PKL"; -static string const volindex_interop_ns = "http://www.digicine.com/PROTO-ASDCP-AM-20040311#"; +static string const volindex_interop_ns = "http://www.digicine.com/PROTO-ASDCP-VL-20040311#"; static string const volindex_smpte_ns = "http://www.smpte-ra.org/schemas/429-9/2007/AM"; DCP::DCP (boost::filesystem::path directory) @@ -211,7 +223,7 @@ DCP::read (bool keep_going, ReadErrors* errors, bool ignore_incorrect_picture_mx other_assets.push_back (shared_ptr (new SMPTESubtitleAsset (path))); break; default: - throw DCPReadError ("Unknown MXF essence type"); + throw DCPReadError (String::compose ("Unknown MXF essence type %1 in %2", int(type), path.string())); } } else if (boost::filesystem::extension (path) == ".ttf") { other_assets.push_back (shared_ptr (new FontAsset (i->first, path))); @@ -290,11 +302,12 @@ DCP::add (DecryptedKDM const & kdm) } } +/** @return full pathname of PKL file that was written */ boost::filesystem::path -DCP::write_pkl (Standard standard, string pkl_uuid, XMLMetadata metadata, shared_ptr signer) const +DCP::write_pkl (string file, Standard standard, string pkl_uuid, XMLMetadata metadata, shared_ptr signer) const { boost::filesystem::path p = _directory; - p /= String::compose ("pkl_%1.xml", pkl_uuid); + p /= file; xmlpp::Document doc; xmlpp::Element* pkl; @@ -309,11 +322,7 @@ DCP::write_pkl (Standard standard, string pkl_uuid, XMLMetadata metadata, shared } pkl->add_child("Id")->add_child_text ("urn:uuid:" + pkl_uuid); - - /* XXX: this is a bit of a hack */ - DCP_ASSERT (cpls().size() > 0); - pkl->add_child("AnnotationText")->add_child_text (cpls().front()->annotation_text ()); - + pkl->add_child("AnnotationText")->add_child_text (metadata.annotation_text); pkl->add_child("IssueDate")->add_child_text (metadata.issue_date); pkl->add_child("Issuer")->add_child_text (metadata.issuer); pkl->add_child("Creator")->add_child_text (metadata.creator); @@ -368,7 +377,7 @@ DCP::write_volindex (Standard standard) const } void -DCP::write_assetmap (Standard standard, string pkl_uuid, int pkl_length, XMLMetadata metadata) const +DCP::write_assetmap (Standard standard, string pkl_uuid, boost::filesystem::path pkl_path, XMLMetadata metadata) const { boost::filesystem::path p = _directory; @@ -398,7 +407,7 @@ DCP::write_assetmap (Standard standard, string pkl_uuid, int pkl_length, XMLMeta } root->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid()); - root->add_child("AnnotationText")->add_child_text ("Created by " + metadata.creator); + root->add_child("AnnotationText")->add_child_text (metadata.annotation_text); switch (standard) { case INTEROP: @@ -424,10 +433,10 @@ DCP::write_assetmap (Standard standard, string pkl_uuid, int pkl_length, XMLMeta asset->add_child("PackingList")->add_child_text ("true"); xmlpp::Node* chunk_list = asset->add_child ("ChunkList"); xmlpp::Node* chunk = chunk_list->add_child ("Chunk"); - chunk->add_child("Path")->add_child_text ("pkl_" + pkl_uuid + ".xml"); + chunk->add_child("Path")->add_child_text (pkl_path.filename().string()); chunk->add_child("VolumeIndex")->add_child_text ("1"); chunk->add_child("Offset")->add_child_text ("0"); - chunk->add_child("Length")->add_child_text (raw_convert (pkl_length)); + chunk->add_child("Length")->add_child_text (raw_convert (boost::filesystem::file_size (pkl_path))); BOOST_FOREACH (shared_ptr i, assets ()) { i->write_to_assetmap (asset_list, _directory); @@ -446,19 +455,23 @@ void DCP::write_xml ( Standard standard, XMLMetadata metadata, - shared_ptr signer + shared_ptr signer, + NameFormat name_format ) { BOOST_FOREACH (shared_ptr i, cpls ()) { - string const filename = "cpl_" + i->id() + ".xml"; - i->write_xml (_directory / filename, standard, signer); + NameFormat::Map values; + values['t'] = "cpl"; + i->write_xml (_directory / (name_format.get(values, "_" + i->id() + ".xml")), standard, signer); } string const pkl_uuid = make_uuid (); - boost::filesystem::path const pkl_path = write_pkl (standard, pkl_uuid, metadata, signer); + NameFormat::Map values; + values['t'] = "pkl"; + boost::filesystem::path const pkl_path = write_pkl (name_format.get(values, "_" + pkl_uuid + ".xml"), standard, pkl_uuid, metadata, signer); write_volindex (standard); - write_assetmap (standard, pkl_uuid, boost::filesystem::file_size (pkl_path), metadata); + write_assetmap (standard, pkl_uuid, pkl_path, metadata); } list > @@ -467,14 +480,20 @@ DCP::cpls () const return _cpls; } -/** @return All assets (including CPLs) */ +/** @param ignore_unresolved true to silently ignore unresolved assets, otherwise + * an exception is thrown if they are found. + * @return All assets (including CPLs). + */ list > -DCP::assets () const +DCP::assets (bool ignore_unresolved) const { list > assets; BOOST_FOREACH (shared_ptr i, cpls ()) { assets.push_back (i); BOOST_FOREACH (shared_ptr j, i->reel_assets ()) { + if (ignore_unresolved && !j->asset_ref().resolved()) { + continue; + } shared_ptr o = j->asset_ref().asset (); assets.push_back (o); /* More Interop special-casing */ @@ -487,3 +506,16 @@ DCP::assets () const return assets; } + +/** Given a list of files that make up 1 or more DCPs, return the DCP directories */ +vector +DCP::directories_from_files (vector files) +{ + vector d; + BOOST_FOREACH (boost::filesystem::path i, files) { + if (i.filename() == "ASSETMAP" || i.filename() == "ASSETMAP.xml") { + d.push_back (i.parent_path ()); + } + } + return d; +}