+ cxml::Document asset_map ("AssetMap");
+ asset_map.read_file (asset_map_file);
+ list<shared_ptr<cxml::Node> > asset_nodes = asset_map.node_child("AssetList")->node_children ("Asset");
+ map<string, boost::filesystem::path> paths;
+ BOOST_FOREACH (shared_ptr<cxml::Node> i, asset_nodes) {
+ if (i->node_child("ChunkList")->node_children("Chunk").size() != 1) {
+ boost::throw_exception (XMLError ("unsupported asset chunk count"));
+ }
+ string p = i->node_child("ChunkList")->node_child("Chunk")->string_child ("Path");
+ if (starts_with (p, "file://")) {
+ p = p.substr (7);
+ }
+ paths.insert (make_pair (remove_urn_uuid (i->string_child ("Id")), p));
+ }
+
+ /* 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;
+ continue;
+ }
+
+ string const root = p->get_document()->get_root_node()->get_name ();
+ delete p;
+
+ if (root == "CompositionPlaylist") {
+ _cpls.push_back (shared_ptr<CPL> (new CPL (path)));
+ } else if (root == "DCSubtitle") {
+ other_assets.push_back (shared_ptr<InteropSubtitleAsset> (new InteropSubtitleAsset (path)));
+ }
+ } else if (boost::filesystem::extension (path) == ".mxf") {
+ 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;
+ default:
+ throw DCPReadError ("Unknown MXF essence type");
+ }
+ } 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);
+ }