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.
24 #include <boost/filesystem.hpp>
27 #include "sound_asset.h"
28 #include "picture_asset.h"
33 using namespace boost;
34 using namespace libdcp;
37 * @param d Directory to write files to.
39 DCP::DCP (string d, string n, ContentType c, int fps, int length)
49 struct tm* tm = localtime (&now);
50 strftime (buffer, 64, "%Y-%m-%dT%I:%M:%S+00:00", tm);
51 _date = string (buffer);
55 DCP::add_sound_asset (list<string> const & files)
60 _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (files, p.string(), _fps, _length)));
64 DCP::add_picture_asset (list<string> const & files, int w, int h)
69 _assets.push_back (shared_ptr<PictureAsset> (new PictureAsset (files, p.string(), _fps, _length, w, h)));
72 /** Write the required XML files to the directory that was
73 * passed into the constructor.
76 DCP::write_xml () const
78 string cpl_uuid = make_uuid ();
79 string cpl_path = write_cpl (cpl_uuid);
80 int cpl_length = filesystem::file_size (cpl_path);
81 string cpl_digest = make_digest (cpl_path);
83 string pkl_uuid = make_uuid ();
84 string pkl_path = write_pkl (pkl_uuid, cpl_uuid, cpl_digest, cpl_length);
87 write_assetmap (cpl_uuid, cpl_length, pkl_uuid, filesystem::file_size (pkl_path));
90 /** Write the CPL file.
91 * @param cpl_uuid UUID to use.
92 * @return CPL pathname.
95 DCP::write_cpl (string cpl_uuid) const
100 s << cpl_uuid << "_cpl.xml";
102 ofstream cpl (p.string().c_str());
104 cpl << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
105 << "<CompositionPlaylist xmlns=\"http://www.smpte-ra.org/schemas/429-7/2006/CPL\">\n"
106 << " <Id>urn:uuid:" << cpl_uuid << "</Id>\n"
107 << " <AnnotationText>" << _name << "</AnnotationText>\n"
108 << " <IssueDate>" << _date << "</IssueDate>\n"
109 << " <Creator>libdcp " << Tags::instance()->creator << "</Creator>\n"
110 << " <ContentTitleText>" << _name << "</ContentTitleText>\n"
111 << " <ContentKind>" << _content_type << "</ContentKind>\n"
112 << " <ContentVersion>\n"
113 << " <Id>urn:uri:" << cpl_uuid << "_" << _date << "</Id>\n"
114 << " <LabelText>" << cpl_uuid << "_" << _date << "</LabelText>\n"
115 << " </ContentVersion>\n"
116 << " <RatingList/>\n"
120 << " <Id>urn:uuid:" << make_uuid() << "</Id>\n"
123 for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
124 (*i)->write_to_cpl (cpl);
127 cpl << " </AssetList>\n"
130 << "</CompositionPlaylist>\n";
135 /** Write the PKL file.
136 * @param pkl_uuid UUID to use.
137 * @param cpl_uuid UUID of the CPL file.
138 * @param cpl_digest SHA digest of the CPL file.
139 * @param cpl_length Length of the CPL file in bytes.
142 DCP::write_pkl (string pkl_uuid, string cpl_uuid, string cpl_digest, int cpl_length) const
147 s << pkl_uuid << "_pkl.xml";
149 ofstream pkl (p.string().c_str());
151 pkl << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
152 << "<PackingList xmlns=\"http://www.smpte-ra.org/schemas/429-8/2007/PKL\">\n"
153 << " <Id>urn:uuid:" << pkl_uuid << "</Id>\n"
154 << " <AnnotationText>" << _name << "</AnnotationText>\n"
155 << " <IssueDate>" << _date << "</IssueDate>\n"
156 << " <Issuer>" << Tags::instance()->issuer << "</Issuer>\n"
157 << " <Creator>" << Tags::instance()->creator << "</Creator>\n"
160 for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
161 (*i)->write_to_pkl (pkl);
165 << " <Id>urn:uuid" << cpl_uuid << "</Id>\n"
166 << " <Hash>" << cpl_digest << "</Hash>\n"
167 << " <Size>" << cpl_length << "</Size>\n"
168 << " <Type>text/xml</Type>\n"
171 pkl << " </AssetList>\n"
172 << "</PackingList>\n";
178 DCP::write_volindex () const
183 ofstream vi (p.string().c_str());
185 vi << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
186 << "<VolumeIndex xmlns=\"http://www.smpte-ra.org/schemas/429-9/2007/AM\">\n"
187 << " <Index>1</Index>\n"
188 << "</VolumeIndex>\n";
192 DCP::write_assetmap (string cpl_uuid, int cpl_length, string pkl_uuid, int pkl_length) const
197 ofstream am (p.string().c_str());
199 am << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
200 << "<AssetMap xmlns=\"http://www.smpte-ra.org/schemas/429-9/2007/AM\">\n"
201 << " <Id>urn:uuid:" << make_uuid() << "</Id>\n"
202 << " <Creator>" << Tags::instance()->creator << "</Creator>\n"
203 << " <VolumeCount>1</VolumeCount>\n"
204 << " <IssueDate>" << _date << "</IssueDate>\n"
205 << " <Issuer>" << Tags::instance()->issuer << "</Issuer>\n"
209 << " <Id>urn:uuid:" << pkl_uuid << "</Id>\n"
210 << " <PackingList>true</PackingList>\n"
213 << " <Path>" << pkl_uuid << "_pkl.xml</Path>\n"
214 << " <VolumeIndex>1</VolumeIndex>\n"
215 << " <Offset>0</Offset>\n"
216 << " <Length>" << pkl_length << "</Length>\n"
222 << " <Id>urn:uuid:" << cpl_uuid << "</Id>\n"
225 << " <Path>" << cpl_uuid << "_cpl.xml</Path>\n"
226 << " <VolumeIndex>1</VolumeIndex>\n"
227 << " <Offset>0</Offset>\n"
228 << " <Length>" << cpl_length << "</Length>\n"
233 for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
234 (*i)->write_to_assetmap (am);
237 am << " </AssetList>\n"
243 DCP::content_type_string (ContentType t)
255 return "transitional";
262 case PUBLIC_SERVICE_ANNOUNCEMENT:
265 return "advertisement";