+ /* Read all the assets from the asset map */
+ /* XXX: I think we should be looking at the PKL here to decide type, not
+ the extension of the file.
+ */
+
+ /* Make a list of non-CPL assets so that we can resolve the references
+ from the CPLs.
+ */
+ list<shared_ptr<Asset> > other_assets;
+
+ for (map<string, boost::filesystem::path>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
+ boost::filesystem::path path = _directory / i->second;
+
+ if (!boost::filesystem::exists (path)) {
+ survivable_error (keep_going, errors, MissingAssetError (path));
+ continue;
+ }
+
+ if (boost::filesystem::extension (path) == ".xml") {
+ xmlpp::DomParser* p = new xmlpp::DomParser;
+ try {
+ p->parse_file (path.string());
+ } catch (std::exception& e) {
+ delete p;
+ throw DCPReadError(String::compose("XML error in %1", path.string()), e.what());
+ }
+
+ string const root = p->get_document()->get_root_node()->get_name ();
+ delete p;
+
+ if (root == "CompositionPlaylist") {
+ shared_ptr<CPL> cpl (new CPL (path));
+ if (_standard && cpl->standard() && cpl->standard().get() != _standard.get()) {
+ survivable_error (keep_going, errors, MismatchedStandardError ());
+ }
+ _cpls.push_back (cpl);
+ } else if (root == "DCSubtitle") {
+ if (_standard && _standard.get() == SMPTE) {
+ survivable_error (keep_going, errors, MismatchedStandardError ());
+ }
+ other_assets.push_back (shared_ptr<InteropSubtitleAsset> (new InteropSubtitleAsset (path)));
+ }
+ } else if (boost::filesystem::extension (path) == ".mxf") {
+
+ /* XXX: asdcplib does not appear to support discovery of read MXFs standard
+ (Interop / SMPTE)
+ */
+
+ ASDCP::EssenceType_t type;
+ if (ASDCP::EssenceType (path.string().c_str(), type) != ASDCP::RESULT_OK) {
+ throw DCPReadError ("Could not find essence type");
+ }
+ switch (type) {
+ case ASDCP::ESS_UNKNOWN:
+ case ASDCP::ESS_MPEG2_VES:
+ throw DCPReadError ("MPEG2 video essences are not supported");
+ case ASDCP::ESS_JPEG_2000:
+ try {
+ other_assets.push_back (shared_ptr<MonoPictureAsset> (new MonoPictureAsset (path)));
+ } catch (dcp::MXFFileError& e) {
+ if (ignore_incorrect_picture_mxf_type && e.number() == ASDCP::RESULT_SFORMAT) {
+ /* Tried to load it as mono but the error says it's stereo; try that instead */
+ other_assets.push_back (shared_ptr<StereoPictureAsset> (new StereoPictureAsset (path)));
+ } else {
+ throw;
+ }
+ }
+ break;
+ case ASDCP::ESS_PCM_24b_48k:
+ case ASDCP::ESS_PCM_24b_96k:
+ other_assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (path)));
+ break;
+ case ASDCP::ESS_JPEG_2000_S:
+ other_assets.push_back (shared_ptr<StereoPictureAsset> (new StereoPictureAsset (path)));
+ break;
+ case ASDCP::ESS_TIMED_TEXT:
+ other_assets.push_back (shared_ptr<SMPTESubtitleAsset> (new SMPTESubtitleAsset (path)));
+ break;
+ case ASDCP::ESS_DCDATA_DOLBY_ATMOS:
+ other_assets.push_back (shared_ptr<AtmosAsset> (new AtmosAsset (path)));
+ break;
+ default:
+ 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<FontAsset> (new FontAsset (i->first, path)));
+ }
+ }
+
+ BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+ i->resolve_refs (other_assets);
+ }
+}
+
+void
+DCP::resolve_refs (list<shared_ptr<Asset> > assets)
+{
+ BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+ i->resolve_refs (assets);
+ }
+}
+
+bool
+DCP::equals (DCP const & other, EqualityOptions opt, NoteHandler note) const
+{
+ list<shared_ptr<CPL> > a = cpls ();
+ list<shared_ptr<CPL> > b = other.cpls ();
+
+ if (a.size() != b.size()) {
+ note (DCP_ERROR, String::compose ("CPL counts differ: %1 vs %2", a.size(), b.size()));
+ return false;
+ }
+
+ bool r = true;
+
+ BOOST_FOREACH (shared_ptr<CPL> i, a) {
+ list<shared_ptr<CPL> >::const_iterator j = b.begin ();
+ while (j != b.end() && !(*j)->equals (i, opt, note)) {
+ ++j;
+ }
+
+ if (j == b.end ()) {
+ r = false;
+ }
+ }
+
+ return r;
+}
+
+void
+DCP::add (boost::shared_ptr<CPL> cpl)
+{
+ _cpls.push_back (cpl);
+}
+
+bool
+DCP::encrypted () const
+{
+ BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+ if (i->encrypted ()) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/** Add a KDM to decrypt this DCP. This method must be called after DCP::read()
+ * or the KDM you specify will be ignored.
+ * @param kdm KDM to use.
+ */
+void
+DCP::add (DecryptedKDM const & kdm)
+{
+ list<DecryptedKDMKey> keys = kdm.keys ();
+
+ BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+ BOOST_FOREACH (DecryptedKDMKey const & j, kdm.keys ()) {
+ if (j.cpl_id() == i->id()) {
+ i->add (kdm);
+ }
+ }
+ }