summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dcp_time.cc11
-rw-r--r--src/mxf_asset.cc41
-rw-r--r--src/mxf_asset.h15
-rw-r--r--src/picture_asset.cc23
-rw-r--r--src/picture_asset.h12
-rw-r--r--src/sound_asset.cc12
-rw-r--r--src/sound_asset.h8
7 files changed, 94 insertions, 28 deletions
diff --git a/src/dcp_time.cc b/src/dcp_time.cc
index c9cd751a..c5a7affd 100644
--- a/src/dcp_time.cc
+++ b/src/dcp_time.cc
@@ -39,9 +39,14 @@ Time::Time (int frame, int frames_per_second)
, s (0)
, t (0)
{
- float sec_float = float (frame) / frames_per_second;
- t = (int (floor (sec_float * 1000)) % 1000) / 4;
- s = floor (sec_float);
+ set (double (frame) / frames_per_second);
+}
+
+void
+Time::set (double ss)
+{
+ t = (int (round (ss * 1000)) % 1000) / 4;
+ s = floor (ss);
if (s > 60) {
m = s / 60;
diff --git a/src/mxf_asset.cc b/src/mxf_asset.cc
index 95412d0c..d229331b 100644
--- a/src/mxf_asset.cc
+++ b/src/mxf_asset.cc
@@ -25,10 +25,12 @@
#include <fstream>
#include <boost/filesystem.hpp>
#include "AS_DCP.h"
+#include "KM_prng.h"
#include "KM_util.h"
#include "mxf_asset.h"
#include "util.h"
#include "metadata.h"
+#include "exceptions.h"
using std::string;
using std::list;
@@ -36,14 +38,40 @@ using boost::shared_ptr;
using boost::dynamic_pointer_cast;
using namespace libdcp;
-MXFAsset::MXFAsset (string directory, string file_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length)
+MXFAsset::MXFAsset (string directory, string file_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length, bool encrypted)
: Asset (directory, file_name)
, _progress (progress)
, _fps (fps)
, _entry_point (entry_point)
, _length (length)
+ , _encrypted (encrypted)
+ , _encryption_context (0)
{
-
+ if (_encrypted) {
+ _key_id = make_uuid ();
+ uint8_t key_buffer[ASDCP::KeyLen];
+ Kumu::FortunaRNG rng;
+ rng.FillRandom (key_buffer, ASDCP::KeyLen);
+ char key_string[ASDCP::KeyLen * 4];
+ Kumu::bin2hex (key_buffer, ASDCP::KeyLen, key_string, ASDCP::KeyLen * 4);
+ _key_value = key_string;
+
+ _encryption_context = new ASDCP::AESEncContext;
+ if (ASDCP_FAILURE (_encryption_context->InitKey (key_buffer))) {
+ throw MiscError ("could not set up encryption context");
+ }
+
+ uint8_t cbc_buffer[ASDCP::CBC_BLOCK_SIZE];
+
+ if (ASDCP_FAILURE (_encryption_context->SetIVec (rng.FillRandom (cbc_buffer, ASDCP::CBC_BLOCK_SIZE)))) {
+ throw MiscError ("could not set up CBC initialization vector");
+ }
+ }
+}
+
+MXFAsset::~MXFAsset ()
+{
+ delete _encryption_context;
}
void
@@ -57,6 +85,15 @@ MXFAsset::fill_writer_info (ASDCP::WriterInfo* writer_info) const
unsigned int c;
Kumu::hex2bin (_uuid.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c);
assert (c == Kumu::UUID_Length);
+
+ if (_encrypted) {
+ Kumu::GenRandomUUID (writer_info->ContextID);
+ writer_info->EncryptedEssence = true;
+
+ unsigned int c;
+ Kumu::hex2bin (_key_id.c_str(), writer_info->CryptographicKeyID, Kumu::UUID_Length, &c);
+ assert (c == Kumu::UUID_Length);
+ }
}
bool
diff --git a/src/mxf_asset.h b/src/mxf_asset.h
index 03f2aa6b..e45ab2d7 100644
--- a/src/mxf_asset.h
+++ b/src/mxf_asset.h
@@ -23,6 +23,10 @@
#include <boost/signals2.hpp>
#include "asset.h"
+namespace ASDCP {
+ class AESEncContext;
+}
+
namespace libdcp
{
@@ -36,8 +40,13 @@ public:
* @param fps Frames per second.
* @param entry_point The entry point of this MXF; ie the first frame that should be used.
* @param length Length in frames.
+ * @param encrypted true if the MXF should be encrypted.
*/
- MXFAsset (std::string directory, std::string file_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length);
+ MXFAsset (
+ std::string directory, std::string file_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length, bool encrypted
+ );
+
+ ~MXFAsset ();
virtual bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
@@ -56,6 +65,10 @@ protected:
int _entry_point;
/** Length in frames */
int _length;
+ bool _encrypted;
+ ASDCP::AESEncContext* _encryption_context;
+ std::string _key_value;
+ std::string _key_id;
};
}
diff --git a/src/picture_asset.cc b/src/picture_asset.cc
index ef5d40d4..f2c489e7 100644
--- a/src/picture_asset.cc
+++ b/src/picture_asset.cc
@@ -46,8 +46,8 @@ 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 entry_point, int length)
- : MXFAsset (directory, mxf_name, progress, fps, entry_point, length)
+PictureAsset::PictureAsset (string directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length, bool encrypted)
+ : MXFAsset (directory, mxf_name, progress, fps, entry_point, length, encrypted)
, _width (0)
, _height (0)
{
@@ -138,8 +138,9 @@ MonoPictureAsset::MonoPictureAsset (
int fps,
int length,
int width,
- int height)
- : PictureAsset (directory, mxf_name, progress, fps, 0, length)
+ int height,
+ bool encrypted)
+ : PictureAsset (directory, mxf_name, progress, fps, 0, length, encrypted)
{
_width = width;
_height = height;
@@ -154,8 +155,9 @@ MonoPictureAsset::MonoPictureAsset (
int fps,
int length,
int width,
- int height)
- : PictureAsset (directory, mxf_name, progress, fps, 0, length)
+ int height,
+ bool encrypted)
+ : PictureAsset (directory, mxf_name, progress, fps, 0, length, encrypted)
{
_width = width;
_height = height;
@@ -163,7 +165,7 @@ MonoPictureAsset::MonoPictureAsset (
}
MonoPictureAsset::MonoPictureAsset (string directory, string mxf_name, int fps, int entry_point, int length)
- : PictureAsset (directory, mxf_name, 0, fps, entry_point, length)
+ : PictureAsset (directory, mxf_name, 0, fps, entry_point, length, false)
{
ASDCP::JP2K::MXFReader reader;
if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
@@ -194,7 +196,7 @@ MonoPictureAsset::construct (boost::function<string (int)> get_path)
ASDCP::WriterInfo writer_info;
fill_writer_info (&writer_info);
-
+
ASDCP::JP2K::MXFWriter mxf_writer;
if (ASDCP_FAILURE (mxf_writer.OpenWrite (path().string().c_str(), writer_info, picture_desc))) {
throw MXFFileError ("could not open MXF file for writing", path().string());
@@ -208,8 +210,7 @@ MonoPictureAsset::construct (boost::function<string (int)> get_path)
throw FileError ("could not open JPEG2000 file for reading", path);
}
- /* XXX: passing 0 to WriteFrame ok? */
- if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
+ if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, _encryption_context, 0))) {
throw MiscError ("error in writing video MXF");
}
@@ -363,7 +364,7 @@ PictureAsset::frame_buffer_equals (
StereoPictureAsset::StereoPictureAsset (string directory, string mxf_name, int fps, int entry_point, int length)
- : PictureAsset (directory, mxf_name, 0, fps, entry_point, length)
+ : PictureAsset (directory, mxf_name, 0, fps, entry_point, length, false)
{
ASDCP::JP2K::MXFSReader reader;
if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
diff --git a/src/picture_asset.h b/src/picture_asset.h
index 08eb338a..53c62223 100644
--- a/src/picture_asset.h
+++ b/src/picture_asset.h
@@ -34,7 +34,9 @@ class StereoPictureFrame;
class PictureAsset : public MXFAsset
{
public:
- PictureAsset (std::string directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length);
+ PictureAsset (
+ std::string directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length, bool encrypted
+ );
/** Write details of this asset to a CPL stream.
* @param s Stream.
@@ -78,6 +80,7 @@ public:
* @param length Length in frames.
* @param width Width of images in pixels.
* @param height Height of images in pixels.
+ * @param encrypted true if asset should be encrypted.
*/
MonoPictureAsset (
std::vector<std::string> const & files,
@@ -87,7 +90,8 @@ public:
int fps,
int length,
int width,
- int height
+ int height,
+ bool encrypted
);
/** Construct a PictureAsset, generating the MXF from the JPEG2000 files.
@@ -100,6 +104,7 @@ public:
* @param length Length in frames.
* @param width Width of images in pixels.
* @param height Height of images in pixels.
+ * @param encrypted true if asset should be encrypted.
*/
MonoPictureAsset (
boost::function<std::string (int)> get_path,
@@ -109,7 +114,8 @@ public:
int fps,
int length,
int width,
- int height
+ int height,
+ bool encrypted
);
MonoPictureAsset (std::string directory, std::string mxf_name, int fps, int entry_point, int length);
diff --git a/src/sound_asset.cc b/src/sound_asset.cc
index e987239a..5e52da8e 100644
--- a/src/sound_asset.cc
+++ b/src/sound_asset.cc
@@ -42,9 +42,9 @@ using boost::lexical_cast;
using namespace libdcp;
SoundAsset::SoundAsset (
- vector<string> const & files, string directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int length
+ vector<string> const & files, string directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int length, bool encrypted
)
- : MXFAsset (directory, mxf_name, progress, fps, 0, length)
+ : MXFAsset (directory, mxf_name, progress, fps, 0, length, encrypted)
, _channels (files.size ())
, _sampling_rate (0)
{
@@ -56,9 +56,9 @@ SoundAsset::SoundAsset (
string directory,
string mxf_name,
boost::signals2::signal<void (float)>* progress,
- int fps, int length, int channels
+ int fps, int length, int channels, bool encrypted
)
- : MXFAsset (directory, mxf_name, progress, fps, 0, length)
+ : MXFAsset (directory, mxf_name, progress, fps, 0, length, encrypted)
, _channels (channels)
, _sampling_rate (0)
{
@@ -66,7 +66,7 @@ SoundAsset::SoundAsset (
}
SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int entry_point, int length)
- : MXFAsset (directory, mxf_name, 0, fps, entry_point, length)
+ : MXFAsset (directory, mxf_name, 0, fps, entry_point, length, false)
, _channels (0)
{
ASDCP::PCM::MXFReader reader;
@@ -176,7 +176,7 @@ SoundAsset::construct (boost::function<string (Channel)> get_path)
offset += sample_size;
}
- if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, 0, 0))) {
+ if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, _encryption_context, 0))) {
throw MiscError ("could not write audio MXF frame");
}
diff --git a/src/sound_asset.h b/src/sound_asset.h
index 3189c067..4633b9a7 100644
--- a/src/sound_asset.h
+++ b/src/sound_asset.h
@@ -44,6 +44,7 @@ public:
* @param progress Signal to inform of progress.
* @param fps Frames per second.
* @param length Length in frames.
+ * @param encrypted true if asset should be encrypted.
*/
SoundAsset (
std::vector<std::string> const & files,
@@ -51,7 +52,8 @@ public:
std::string mxf_name,
boost::signals2::signal<void (float)>* progress,
int fps,
- int length
+ int length,
+ bool encrypted
);
/** Construct a SoundAsset, generating the MXF from some WAV files.
@@ -63,6 +65,7 @@ public:
* @param fps Frames per second.
* @param length Length in frames.
* @param channels Number of audio channels.
+ * @param encrypted true if asset should be encrypted.
*/
SoundAsset (
boost::function<std::string (Channel)> get_path,
@@ -71,7 +74,8 @@ public:
boost::signals2::signal<void (float)>* progress,
int fps,
int length,
- int channels
+ int channels,
+ bool encrypted
);
SoundAsset (