/* Copyright (C) 2012 Carl Hetherington 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 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, 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. */ /** @file src/dcp.cc * @brief A class to create a DCP. */ #include #include #include #include #include #include "dcp.h" #include "asset.h" #include "sound_asset.h" #include "picture_asset.h" #include "util.h" #include "metadata.h" using namespace std; using namespace boost; using namespace libdcp; DCP::DCP (string directory, string name, ContentType content_type, int fps, int length) : _directory (directory) , _name (name) , _content_type (content_type) , _fps (fps) , _length (length) { } void DCP::add_sound_asset (vector const & files) { filesystem::path p; p /= _directory; p /= "audio.mxf"; _assets.push_back (shared_ptr (new SoundAsset (files, p.string(), &Progress, _fps, _length))); } void DCP::add_sound_asset (sigc::slot get_path, int channels) { filesystem::path p; p /= _directory; p /= "audio.mxf"; _assets.push_back (shared_ptr (new SoundAsset (get_path, p.string(), &Progress, _fps, _length, channels))); } void DCP::add_picture_asset (vector const & files, int width, int height) { filesystem::path p; p /= _directory; p /= "video.mxf"; _assets.push_back (shared_ptr (new PictureAsset (files, p.string(), &Progress, _fps, _length, width, height))); } void DCP::add_picture_asset (sigc::slot get_path, int width, int height) { filesystem::path p; p /= _directory; p /= "video.mxf"; _assets.push_back (shared_ptr (new PictureAsset (get_path, p.string(), &Progress, _fps, _length, width, height))); } void DCP::write_xml () const { string cpl_uuid = make_uuid (); string cpl_path = write_cpl (cpl_uuid); int cpl_length = filesystem::file_size (cpl_path); string cpl_digest = make_digest (cpl_path, 0); string pkl_uuid = make_uuid (); string pkl_path = write_pkl (pkl_uuid, cpl_uuid, cpl_digest, cpl_length); write_volindex (); write_assetmap (cpl_uuid, cpl_length, pkl_uuid, filesystem::file_size (pkl_path)); } string DCP::write_cpl (string cpl_uuid) const { filesystem::path p; p /= _directory; stringstream s; s << cpl_uuid << "_cpl.xml"; p /= s.str(); ofstream cpl (p.string().c_str()); cpl << "\n" << "\n" << " urn:uuid:" << cpl_uuid << "\n" << " " << _name << "\n" << " " << Metadata::instance()->issue_date << "\n" << " " << Metadata::instance()->creator << "\n" << " " << _name << "\n" << " " << content_type_string (_content_type) << "\n" << " \n" << " urn:uri:" << cpl_uuid << "_" << Metadata::instance()->issue_date << "\n" << " " << cpl_uuid << "_" << Metadata::instance()->issue_date << "\n" << " \n" << " \n" << " \n"; cpl << " \n" << " urn:uuid:" << make_uuid() << "\n" << " \n"; for (list >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) { (*i)->write_to_cpl (cpl); } cpl << " \n" << " \n" << " \n" << "\n"; return p.string (); } std::string DCP::write_pkl (string pkl_uuid, string cpl_uuid, string cpl_digest, int cpl_length) const { filesystem::path p; p /= _directory; stringstream s; s << pkl_uuid << "_pkl.xml"; p /= s.str(); ofstream pkl (p.string().c_str()); pkl << "\n" << "\n" << " urn:uuid:" << pkl_uuid << "\n" << " " << _name << "\n" << " " << Metadata::instance()->issue_date << "\n" << " " << Metadata::instance()->issuer << "\n" << " " << Metadata::instance()->creator << "\n" << " \n"; for (list >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) { (*i)->write_to_pkl (pkl); } pkl << " \n" << " urn:uuid:" << cpl_uuid << "\n" << " " << cpl_digest << "\n" << " " << cpl_length << "\n" << " text/xml\n" << " \n"; pkl << " \n" << "\n"; return p.string (); } void DCP::write_volindex () const { filesystem::path p; p /= _directory; p /= "VOLINDEX.xml"; ofstream vi (p.string().c_str()); vi << "\n" << "\n" << " 1\n" << "\n"; } void DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_length) const { filesystem::path p; p /= _directory; p /= "ASSETMAP.xml"; ofstream am (p.string().c_str()); am << "\n" << "\n" << " urn:uuid:" << make_uuid() << "\n" << " " << Metadata::instance()->creator << "\n" << " 1\n" << " " << Metadata::instance()->issue_date << "\n" << " " << Metadata::instance()->issuer << "\n" << " \n"; am << " \n" << " urn:uuid:" << pkl_uuid << "\n" << " true\n" << " \n" << " \n" << " " << pkl_uuid << "_pkl.xml\n" << " 1\n" << " 0\n" << " " << pkl_length << "\n" << " \n" << " \n" << " \n"; am << " \n" << " urn:uuid:" << cpl_uuid << "\n" << " \n" << " \n" << " " << cpl_uuid << "_cpl.xml\n" << " 1\n" << " 0\n" << " " << cpl_length << "\n" << " \n" << " \n" << " \n"; for (list >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) { (*i)->write_to_assetmap (am); } am << " \n" << "\n"; } string DCP::content_type_string (ContentType type) { switch (type) { case FEATURE: return "feature"; case SHORT: return "short"; case TRAILER: return "trailer"; case TEST: return "test"; case TRANSITIONAL: return "transitional"; case RATING: return "rating"; case TEASER: return "teaser"; case POLICY: return "policy"; case PUBLIC_SERVICE_ANNOUNCEMENT: return "psa"; case ADVERTISEMENT: return "advertisement"; } assert (false); }