2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * @brief A class to create a DCP.
28 #include <boost/filesystem.hpp>
31 #include "sound_asset.h"
32 #include "picture_asset.h"
37 using namespace boost;
38 using namespace libdcp;
40 DCP::DCP (string directory, string name, ContentType content_type, int fps, int length)
41 : _directory (directory)
43 , _content_type (content_type)
51 DCP::add_sound_asset (vector<string> const & files)
56 _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (files, p.string(), &Progress, _fps, _length)));
60 DCP::add_sound_asset (sigc::slot<string, Channel> get_path, int channels)
65 _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (get_path, p.string(), &Progress, _fps, _length, channels)));
69 DCP::add_picture_asset (vector<string> const & files, int width, int height)
74 _assets.push_back (shared_ptr<PictureAsset> (new PictureAsset (files, p.string(), &Progress, _fps, _length, width, height)));
78 DCP::add_picture_asset (sigc::slot<string, int> get_path, int width, int height)
83 _assets.push_back (shared_ptr<PictureAsset> (new PictureAsset (get_path, p.string(), &Progress, _fps, _length, width, height)));
87 DCP::write_xml () const
89 string cpl_uuid = make_uuid ();
90 string cpl_path = write_cpl (cpl_uuid);
91 int cpl_length = filesystem::file_size (cpl_path);
92 string cpl_digest = make_digest (cpl_path, 0);
94 string pkl_uuid = make_uuid ();
95 string pkl_path = write_pkl (pkl_uuid, cpl_uuid, cpl_digest, cpl_length);
98 write_assetmap (cpl_uuid, cpl_length, pkl_uuid, filesystem::file_size (pkl_path));
102 DCP::write_cpl (string cpl_uuid) const
107 s << cpl_uuid << "_cpl.xml";
109 ofstream cpl (p.string().c_str());
111 cpl << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
112 << "<CompositionPlaylist xmlns=\"http://www.smpte-ra.org/schemas/429-7/2006/CPL\">\n"
113 << " <Id>urn:uuid:" << cpl_uuid << "</Id>\n"
114 << " <AnnotationText>" << _name << "</AnnotationText>\n"
115 << " <IssueDate>" << Metadata::instance()->issue_date << "</IssueDate>\n"
116 << " <Creator>" << Metadata::instance()->creator << "</Creator>\n"
117 << " <ContentTitleText>" << _name << "</ContentTitleText>\n"
118 << " <ContentKind>" << content_type_string (_content_type) << "</ContentKind>\n"
119 << " <ContentVersion>\n"
120 << " <Id>urn:uri:" << cpl_uuid << "_" << Metadata::instance()->issue_date << "</Id>\n"
121 << " <LabelText>" << cpl_uuid << "_" << Metadata::instance()->issue_date << "</LabelText>\n"
122 << " </ContentVersion>\n"
123 << " <RatingList/>\n"
127 << " <Id>urn:uuid:" << make_uuid() << "</Id>\n"
130 for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
131 (*i)->write_to_cpl (cpl);
134 cpl << " </AssetList>\n"
137 << "</CompositionPlaylist>\n";
143 DCP::write_pkl (string pkl_uuid, string cpl_uuid, string cpl_digest, int cpl_length) const
148 s << pkl_uuid << "_pkl.xml";
150 ofstream pkl (p.string().c_str());
152 pkl << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
153 << "<PackingList xmlns=\"http://www.smpte-ra.org/schemas/429-8/2007/PKL\">\n"
154 << " <Id>urn:uuid:" << pkl_uuid << "</Id>\n"
155 << " <AnnotationText>" << _name << "</AnnotationText>\n"
156 << " <IssueDate>" << Metadata::instance()->issue_date << "</IssueDate>\n"
157 << " <Issuer>" << Metadata::instance()->issuer << "</Issuer>\n"
158 << " <Creator>" << Metadata::instance()->creator << "</Creator>\n"
161 for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
162 (*i)->write_to_pkl (pkl);
166 << " <Id>urn:uuid:" << cpl_uuid << "</Id>\n"
167 << " <Hash>" << cpl_digest << "</Hash>\n"
168 << " <Size>" << cpl_length << "</Size>\n"
169 << " <Type>text/xml</Type>\n"
172 pkl << " </AssetList>\n"
173 << "</PackingList>\n";
179 DCP::write_volindex () const
184 ofstream vi (p.string().c_str());
186 vi << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
187 << "<VolumeIndex xmlns=\"http://www.smpte-ra.org/schemas/429-9/2007/AM\">\n"
188 << " <Index>1</Index>\n"
189 << "</VolumeIndex>\n";
193 DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_length) const
198 ofstream am (p.string().c_str());
200 am << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
201 << "<AssetMap xmlns=\"http://www.smpte-ra.org/schemas/429-9/2007/AM\">\n"
202 << " <Id>urn:uuid:" << make_uuid() << "</Id>\n"
203 << " <Creator>" << Metadata::instance()->creator << "</Creator>\n"
204 << " <VolumeCount>1</VolumeCount>\n"
205 << " <IssueDate>" << Metadata::instance()->issue_date << "</IssueDate>\n"
206 << " <Issuer>" << Metadata::instance()->issuer << "</Issuer>\n"
210 << " <Id>urn:uuid:" << pkl_uuid << "</Id>\n"
211 << " <PackingList>true</PackingList>\n"
214 << " <Path>" << pkl_uuid << "_pkl.xml</Path>\n"
215 << " <VolumeIndex>1</VolumeIndex>\n"
216 << " <Offset>0</Offset>\n"
217 << " <Length>" << pkl_length << "</Length>\n"
223 << " <Id>urn:uuid:" << cpl_uuid << "</Id>\n"
226 << " <Path>" << cpl_uuid << "_cpl.xml</Path>\n"
227 << " <VolumeIndex>1</VolumeIndex>\n"
228 << " <Offset>0</Offset>\n"
229 << " <Length>" << cpl_length << "</Length>\n"
234 for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
235 (*i)->write_to_assetmap (am);
238 am << " </AssetList>\n"
243 DCP::content_type_string (ContentType type)
255 return "transitional";
262 case PUBLIC_SERVICE_ANNOUNCEMENT:
265 return "advertisement";