2 Copyright (C) 2012-2014 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.
20 /** @file src/asset.cc
21 * @brief Parent class for assets of DCPs made up of MXF files.
24 #include "raw_convert.h"
31 #include "exceptions.h"
32 #include "compose.hpp"
33 #include <libxml++/nodes/element.h>
34 #include <boost/filesystem.hpp>
40 using boost::shared_ptr;
41 using boost::dynamic_pointer_cast;
44 MXF::MXF (Fraction edit_rate)
45 : _edit_rate (edit_rate)
46 , _intrinsic_duration (0)
47 , _encryption_context (0)
48 , _decryption_context (0)
50 /* _intrinsic_duration must be set up up by a subclass */
53 MXF::MXF (boost::filesystem::path file)
55 , _intrinsic_duration (0)
56 , _encryption_context (0)
57 , _decryption_context (0)
59 /* _edit_rate and _intrinsic_duration must be set up up by a subclass */
64 delete _encryption_context;
65 delete _decryption_context;
69 MXF::fill_writer_info (ASDCP::WriterInfo* writer_info, Standard standard)
71 writer_info->ProductVersion = _metadata.product_version;
72 writer_info->CompanyName = _metadata.company_name;
73 writer_info->ProductName = _metadata.product_name.c_str();
75 if (standard == INTEROP) {
76 writer_info->LabelSetType = ASDCP::LS_MXF_INTEROP;
78 writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
81 Kumu::hex2bin (_id.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c);
82 assert (c == Kumu::UUID_Length);
85 Kumu::GenRandomUUID (writer_info->ContextID);
86 writer_info->EncryptedEssence = true;
89 Kumu::hex2bin (_key_id.c_str(), writer_info->CryptographicKeyID, Kumu::UUID_Length, &c);
90 assert (c == Kumu::UUID_Length);
95 MXF::equals (shared_ptr<const Content> other, EqualityOptions opt, boost::function<void (NoteType, string)> note) const
97 if (!Content::equals (other, opt, note)) {
101 shared_ptr<const MXF> other_mxf = dynamic_pointer_cast<const MXF> (other);
103 note (DCP_ERROR, "comparing an MXF asset with a non-MXF asset");
107 if (_edit_rate != other_mxf->_edit_rate) {
108 note (DCP_ERROR, "content edit rates differ");
112 if (_intrinsic_duration != other_mxf->_intrinsic_duration) {
113 note (DCP_ERROR, "asset intrinsic durations differ");
117 if (_file != other_mxf->file ()) {
118 note (DCP_ERROR, "MXF names differ");
119 if (!opt.mxf_names_can_differ) {
127 /** Set the (private) key that will be used to encrypt or decrypt this MXF's content.
128 * This is the top-secret key that is distributed (itself encrypted) to cinemas
129 * via Key Delivery Messages (KDMs).
130 * @param key Key to use.
133 MXF::set_key (Key key)
137 if (_key_id.empty ()) {
138 /* No key ID so far; we now need one */
139 _key_id = make_uuid ();
142 _decryption_context = new ASDCP::AESDecContext;
143 if (ASDCP_FAILURE (_decryption_context->InitKey (_key->value ()))) {
144 throw MiscError ("could not set up decryption context");
147 _encryption_context = new ASDCP::AESEncContext;
148 if (ASDCP_FAILURE (_encryption_context->InitKey (_key->value ()))) {
149 throw MiscError ("could not set up encryption context");
152 uint8_t cbc_buffer[ASDCP::CBC_BLOCK_SIZE];
154 Kumu::FortunaRNG rng;
155 if (ASDCP_FAILURE (_encryption_context->SetIVec (rng.FillRandom (cbc_buffer, ASDCP::CBC_BLOCK_SIZE)))) {
156 throw MiscError ("could not set up CBC initialization vector");
161 MXF::read_writer_info (ASDCP::WriterInfo const & info)
164 Kumu::bin2UUIDhex (info.AssetUUID, ASDCP::UUIDlen, buffer, sizeof (buffer));
169 MXF::pkl_type (Standard standard) const
173 return String::compose ("application/x-smpte-mxf;asdcpKind=%1", asdcp_kind ());
175 return "application/mxf";