diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-09-25 17:19:59 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-09-25 17:19:59 +0100 |
| commit | e563727ee7b72881ee163db9b777559c8ceb5074 (patch) | |
| tree | 691966d59ee49912c6c020f67759ee13ece0a925 /src | |
| parent | 43465aa4037cec6d351a842a6624a50685d6c127 (diff) | |
Add round-trip KDM test. Fix various bugs in KDM generation. Some string -> path.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset.cc | 2 | ||||
| -rw-r--r-- | src/asset.h | 4 | ||||
| -rw-r--r-- | src/kdm.cc | 18 | ||||
| -rw-r--r-- | src/kdm.h | 2 | ||||
| -rw-r--r-- | src/mxf_asset.cc | 4 | ||||
| -rw-r--r-- | src/mxf_asset.h | 4 | ||||
| -rw-r--r-- | src/picture_asset.cc | 30 | ||||
| -rw-r--r-- | src/picture_asset.h | 24 | ||||
| -rw-r--r-- | src/sound_asset.cc | 20 | ||||
| -rw-r--r-- | src/sound_asset.h | 16 |
10 files changed, 68 insertions, 56 deletions
diff --git a/src/asset.cc b/src/asset.cc index 06b87953..6e4901b5 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -37,7 +37,7 @@ using namespace std; using namespace boost; using namespace libdcp; -Asset::Asset (string directory, string file_name, int edit_rate, int intrinsic_duration) +Asset::Asset (boost::filesystem::path directory, string file_name, int edit_rate, int intrinsic_duration) : _directory (directory) , _file_name (file_name) , _uuid (make_uuid ()) diff --git a/src/asset.h b/src/asset.h index c6ff7e83..940ed548 100644 --- a/src/asset.h +++ b/src/asset.h @@ -53,7 +53,7 @@ public: * @param directory Directory where our XML or MXF file is. * @param file_name Name of our file within directory, or empty to make one up based on UUID. */ - Asset (std::string directory, std::string file_name = "", int edit_rate = 0, int intrinsic_duration = 0); + Asset (boost::filesystem::path directory, std::string file_name = "", int edit_rate = 0, int intrinsic_duration = 0); virtual ~Asset() {} @@ -130,7 +130,7 @@ protected: std::string digest () const; /** Directory that our MXF or XML file is in */ - std::string _directory; + boost::filesystem::path _directory; /** Name of our MXF or XML file */ std::string _file_name; /** Our UUID */ @@ -133,7 +133,10 @@ KDM::KDM ( shared_ptr<const MXFAsset> mxf = boost::dynamic_pointer_cast<const MXFAsset> (*i); if (mxf) { xml_kdm->authenticated_private.encrypted_keys.push_back ( - KDMKey (signer, cpl->id (), mxf->key_id (), not_valid_before, not_valid_after, mxf->key().get()).encrypted_base64 (recipient_cert) + KDMKey ( + signer, cpl->id (), mxf->key_type (), mxf->key_id (), + not_valid_before, not_valid_after, mxf->key().get() + ).encrypted_base64 (recipient_cert) ); } } @@ -161,8 +164,11 @@ KDM::as_xml () const return doc->write_to_string_formatted ("UTF-8"); } -KDMKey::KDMKey (shared_ptr<const Signer> signer, string cpl_id, string key_id, boost::posix_time::ptime from, boost::posix_time::ptime until, Key key) +KDMKey::KDMKey ( + shared_ptr<const Signer> signer, string cpl_id, string key_type, string key_id, boost::posix_time::ptime from, boost::posix_time::ptime until, Key key + ) : _cpl_id (cpl_id) + , _key_type (key_type) , _key_id (key_id) , _not_valid_before (ptime_to_string (from)) , _not_valid_after (ptime_to_string (until)) @@ -234,6 +240,10 @@ KDMKey::operator= (KDMKey const & other) string KDMKey::encrypted_base64 (shared_ptr<const Certificate> recipient_cert) const { + assert (_key_type.length() == 4); + assert (_not_valid_before.length() == 25); + assert (_not_valid_after.length() == 25); + /* XXX: SMPTE only */ uint8_t block[138]; uint8_t* p = block; @@ -252,14 +262,14 @@ KDMKey::encrypted_base64 (shared_ptr<const Certificate> recipient_cert) const /* Encrypt using the projector's public key */ RSA* rsa = recipient_cert->public_key (); unsigned char encrypted[RSA_size(rsa)]; - int const encrypted_len = RSA_public_encrypt (138, block, encrypted, rsa, RSA_PKCS1_OAEP_PADDING); + int const encrypted_len = RSA_public_encrypt (p - block, block, encrypted, rsa, RSA_PKCS1_OAEP_PADDING); if (encrypted_len == -1) { throw MiscError (String::compose ("Could not encrypt KDM (%1)", ERR_error_string (ERR_get_error(), 0))); } /* Lazy overallocation */ char out[encrypted_len * 2]; - return Kumu::base64encode (block, 138, out, 138 * 2); + return Kumu::base64encode (encrypted, encrypted_len, out, encrypted_len * 2); } string @@ -46,7 +46,7 @@ public: KDMKey ( boost::shared_ptr<const Signer> signer, - std::string cpl_id, std::string key_id, boost::posix_time::ptime from, boost::posix_time::ptime until, Key key + std::string cpl_id, std::string key_type, std::string key_id, boost::posix_time::ptime from, boost::posix_time::ptime until, Key key ); KDMKey (KDMKey const &); diff --git a/src/mxf_asset.cc b/src/mxf_asset.cc index 98770d86..956d38f9 100644 --- a/src/mxf_asset.cc +++ b/src/mxf_asset.cc @@ -43,7 +43,7 @@ using boost::lexical_cast; using boost::dynamic_pointer_cast; using namespace libdcp; -MXFAsset::MXFAsset (string directory, string file_name) +MXFAsset::MXFAsset (boost::filesystem::path directory, string file_name) : Asset (directory, file_name) , _progress (0) , _encryption_context (0) @@ -52,7 +52,7 @@ MXFAsset::MXFAsset (string directory, string file_name) } -MXFAsset::MXFAsset (string directory, string file_name, boost::signals2::signal<void (float)>* progress, int edit_rate, int intrinsic_duration) +MXFAsset::MXFAsset (boost::filesystem::path directory, string file_name, boost::signals2::signal<void (float)>* progress, int edit_rate, int intrinsic_duration) : Asset (directory, file_name, edit_rate, intrinsic_duration) , _progress (progress) , _encryption_context (0) diff --git a/src/mxf_asset.h b/src/mxf_asset.h index e351db57..e566c32c 100644 --- a/src/mxf_asset.h +++ b/src/mxf_asset.h @@ -44,7 +44,7 @@ public: * @param directory Directory where MXF file is. * @param file_name Name of MXF file. */ - MXFAsset (std::string directory, std::string file_name); + MXFAsset (boost::filesystem::path directory, std::string file_name); /** Construct an MXFAsset. * This class will not write anything to disk in this constructor, but subclasses may. @@ -56,7 +56,7 @@ public: * @param intrinsic_duration Duration of the whole asset in frames. */ MXFAsset ( - std::string directory, + boost::filesystem::path directory, std::string file_name, boost::signals2::signal<void (float)>* progress, int edit_rate, diff --git a/src/picture_asset.cc b/src/picture_asset.cc index bc38a3f9..78d7576d 100644 --- a/src/picture_asset.cc +++ b/src/picture_asset.cc @@ -54,14 +54,16 @@ using boost::dynamic_pointer_cast; using boost::lexical_cast; using namespace libdcp; -PictureAsset::PictureAsset (string directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int intrinsic_duration, Size size) +PictureAsset::PictureAsset ( + boost::filesystem::path directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int intrinsic_duration, Size size + ) : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration) , _size (size) { } -PictureAsset::PictureAsset (string directory, string mxf_name) +PictureAsset::PictureAsset (boost::filesystem::path directory, string mxf_name) : MXFAsset (directory, mxf_name) { @@ -189,8 +191,8 @@ PictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, boost: MonoPictureAsset::MonoPictureAsset ( - boost::function<string (int)> get_path, - string directory, + boost::function<boost::filesystem::path (int)> get_path, + boost::filesystem::path directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -205,8 +207,8 @@ MonoPictureAsset::MonoPictureAsset ( } MonoPictureAsset::MonoPictureAsset ( - vector<string> const & files, - string directory, + vector<boost::filesystem::path> const & files, + boost::filesystem::path directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -220,13 +222,13 @@ MonoPictureAsset::MonoPictureAsset ( construct (boost::bind (&MonoPictureAsset::path_from_list, this, _1, files), interop, metadata); } -MonoPictureAsset::MonoPictureAsset (string directory, string mxf_name, int fps, Size size) +MonoPictureAsset::MonoPictureAsset (boost::filesystem::path directory, string mxf_name, int fps, Size size) : PictureAsset (directory, mxf_name, 0, fps, 0, size) { } -MonoPictureAsset::MonoPictureAsset (string directory, string mxf_name) +MonoPictureAsset::MonoPictureAsset (boost::filesystem::path directory, string mxf_name) : PictureAsset (directory, mxf_name) { ASDCP::JP2K::MXFReader reader; @@ -247,7 +249,7 @@ MonoPictureAsset::MonoPictureAsset (string directory, string mxf_name) } void -MonoPictureAsset::construct (boost::function<string (int)> get_path, bool interop, MXFMetadata const & metadata) +MonoPictureAsset::construct (boost::function<boost::filesystem::path (int)> get_path, bool interop, MXFMetadata const & metadata) { ASDCP::JP2K::CodestreamParser j2k_parser; ASDCP::JP2K::FrameBuffer frame_buffer (4 * Kumu::Megabyte); @@ -269,7 +271,7 @@ MonoPictureAsset::construct (boost::function<string (int)> get_path, bool intero for (int i = 0; i < _intrinsic_duration; ++i) { - string const path = get_path (i); + boost::filesystem::path const path = get_path (i); if (ASDCP_FAILURE (j2k_parser.OpenReadFrame (path.c_str(), frame_buffer))) { boost::throw_exception (FileError ("could not open JPEG2000 file for reading", path)); @@ -289,8 +291,8 @@ MonoPictureAsset::construct (boost::function<string (int)> get_path, bool intero } } -string -MonoPictureAsset::path_from_list (int f, vector<string> const & files) const +boost::filesystem::path +MonoPictureAsset::path_from_list (int f, vector<boost::filesystem::path> const & files) const { return files[f]; } @@ -434,7 +436,7 @@ PictureAsset::frame_buffer_equals ( } -StereoPictureAsset::StereoPictureAsset (string directory, string mxf_name, int fps, int intrinsic_duration) +StereoPictureAsset::StereoPictureAsset (boost::filesystem::path directory, string mxf_name, int fps, int intrinsic_duration) : PictureAsset (directory, mxf_name, 0, fps, intrinsic_duration, Size (0, 0)) { ASDCP::JP2K::MXFSReader reader; @@ -470,7 +472,7 @@ PictureAsset::key_type () const return "MDIK"; } -StereoPictureAsset::StereoPictureAsset (string directory, string mxf_name, int fps, Size size) +StereoPictureAsset::StereoPictureAsset (boost::filesystem::path directory, string mxf_name, int fps, Size size) : PictureAsset (directory, mxf_name, 0, fps, 0, size) { diff --git a/src/picture_asset.h b/src/picture_asset.h index 398f8868..495c6647 100644 --- a/src/picture_asset.h +++ b/src/picture_asset.h @@ -46,7 +46,7 @@ public: * @param directory Directory where MXF file is. * @param mxf_name Name of MXF file. */ - PictureAsset (std::string directory, std::string mxf_name); + PictureAsset (boost::filesystem::path directory, std::string mxf_name); /** Construct a PictureAsset. * This class will not write anything to disk in this constructor, but subclasses may. @@ -59,7 +59,7 @@ public: * @param size Size of video frame images in pixels. */ PictureAsset ( - std::string directory, + boost::filesystem::path directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -113,8 +113,8 @@ public: * @param size Size of images in pixels. */ MonoPictureAsset ( - std::vector<std::string> const & files, - std::string directory, + std::vector<boost::filesystem::path> const & files, + boost::filesystem::path directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -136,8 +136,8 @@ public: * @param size Size of images in pixels. */ MonoPictureAsset ( - boost::function<std::string (int)> get_path, - std::string directory, + boost::function<boost::filesystem::path (int)> get_path, + boost::filesystem::path directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -151,7 +151,7 @@ public: * @param directory Directory that the MXF is in. * @param mxf_name The filename of the MXF within `directory'. */ - MonoPictureAsset (std::string directory, std::string mxf_name); + MonoPictureAsset (boost::filesystem::path directory, std::string mxf_name); /** Construct a MonoPictureAsset for progressive writing using * start_write() and a MonoPictureAssetWriter. @@ -161,7 +161,7 @@ public: * @param fps Video frames per second. * @param size Size in pixels that the picture frames will be. */ - MonoPictureAsset (std::string directory, std::string mxf_name, int fps, Size size); + MonoPictureAsset (boost::filesystem::path directory, std::string mxf_name, int fps, Size size); /** Start a progressive write to a MonoPictureAsset */ boost::shared_ptr<PictureAssetWriter> start_write (bool, bool, MXFMetadata const & metadata = MXFMetadata ()); @@ -170,8 +170,8 @@ public: bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, boost::function<void (NoteType, std::string)> note) const; private: - std::string path_from_list (int f, std::vector<std::string> const & files) const; - void construct (boost::function<std::string (int)>, bool, MXFMetadata const &); + boost::filesystem::path path_from_list (int f, std::vector<boost::filesystem::path> const & files) const; + void construct (boost::function<boost::filesystem::path (int)>, bool, MXFMetadata const &); std::string cpl_node_name () const; int edit_rate_factor () const; }; @@ -180,7 +180,7 @@ private: class StereoPictureAsset : public PictureAsset { public: - StereoPictureAsset (std::string directory, std::string mxf_name, int fps, int intrinsic_duration); + StereoPictureAsset (boost::filesystem::path directory, std::string mxf_name, int fps, int intrinsic_duration); /** Construct a StereoPictureAsset for progressive writing using * start_write() and a StereoPictureAssetWriter. @@ -190,7 +190,7 @@ public: * @param fps Video frames per second. * @param size Size in pixels that the picture frames will be. */ - StereoPictureAsset (std::string directory, std::string mxf_name, int fps, Size size); + StereoPictureAsset (boost::filesystem::path directory, std::string mxf_name, int fps, Size size); /** Start a progressive write to a StereoPictureAsset */ boost::shared_ptr<PictureAssetWriter> start_write (bool, bool, MXFMetadata const & metadata = MXFMetadata ()); diff --git a/src/sound_asset.cc b/src/sound_asset.cc index 026c44ef..984d8f0f 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -43,8 +43,8 @@ using boost::lexical_cast; using namespace libdcp; SoundAsset::SoundAsset ( - vector<string> const & files, - string directory, + vector<boost::filesystem::path> const & files, + boost::filesystem::path directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -62,8 +62,8 @@ SoundAsset::SoundAsset ( } SoundAsset::SoundAsset ( - boost::function<string (Channel)> get_path, - string directory, + boost::function<boost::filesystem::path (Channel)> get_path, + boost::filesystem::path directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -81,7 +81,7 @@ SoundAsset::SoundAsset ( construct (get_path, interop, metadata); } -SoundAsset::SoundAsset (string directory, string mxf_name) +SoundAsset::SoundAsset (boost::filesystem::path directory, string mxf_name) : MXFAsset (directory, mxf_name) , _channels (0) { @@ -102,7 +102,7 @@ SoundAsset::SoundAsset (string directory, string mxf_name) _intrinsic_duration = desc.ContainerDuration; } -SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int channels, int sampling_rate) +SoundAsset::SoundAsset (boost::filesystem::path directory, string mxf_name, int fps, int channels, int sampling_rate) : MXFAsset (directory, mxf_name, 0, fps, 0) , _channels (channels) , _sampling_rate (sampling_rate) @@ -110,8 +110,8 @@ SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int channels } -string -SoundAsset::path_from_channel (Channel channel, vector<string> const & files) +boost::filesystem::path +SoundAsset::path_from_channel (Channel channel, vector<boost::filesystem::path> const & files) { unsigned int const c = int (channel); assert (c < files.size ()); @@ -119,7 +119,7 @@ SoundAsset::path_from_channel (Channel channel, vector<string> const & files) } void -SoundAsset::construct (boost::function<string (Channel)> get_path, bool interop, MXFMetadata const & metadata) +SoundAsset::construct (boost::function<boost::filesystem::path (Channel)> get_path, bool interop, MXFMetadata const & metadata) { ASDCP::Rational asdcp_edit_rate (_edit_rate, 1); @@ -154,7 +154,7 @@ SoundAsset::construct (boost::function<string (Channel)> get_path, bool interop, for (int i = 0; i < _channels; ++i) { - string const path = get_path (channels[i]); + boost::filesystem::path const path = get_path (channels[i]); if (ASDCP_FAILURE (pcm_parser_channel[i].OpenRead (path.c_str(), asdcp_edit_rate))) { boost::throw_exception (FileError ("could not open WAV file for reading", path)); diff --git a/src/sound_asset.h b/src/sound_asset.h index 339e67f8..1d2a4755 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -82,8 +82,8 @@ public: * Note that this is different to entry_point in that the asset will contain no data before start_frame. */ SoundAsset ( - std::vector<std::string> const & files, - std::string directory, + std::vector<boost::filesystem::path> const & files, + boost::filesystem::path directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -103,8 +103,8 @@ public: * @param channels Number of audio channels. */ SoundAsset ( - boost::function<std::string (Channel)> get_path, - std::string directory, + boost::function<boost::filesystem::path (Channel)> get_path, + boost::filesystem::path directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, @@ -115,12 +115,12 @@ public: ); SoundAsset ( - std::string directory, + boost::filesystem::path directory, std::string mxf_name ); SoundAsset ( - std::string directory, + boost::filesystem::path directory, std::string mxf_name, int fps, int channels, @@ -143,8 +143,8 @@ public: private: std::string key_type () const; - void construct (boost::function<std::string (Channel)> get_path, bool interop, MXFMetadata const &); - std::string path_from_channel (Channel channel, std::vector<std::string> const & files); + void construct (boost::function<boost::filesystem::path (Channel)> get_path, bool interop, MXFMetadata const &); + boost::filesystem::path path_from_channel (Channel channel, std::vector<boost::filesystem::path> const & files); std::string cpl_node_name () const; /** Number of channels in the asset */ |
