summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-01-28 16:00:16 +0000
committerCarl Hetherington <cth@carlh.net>2014-01-28 16:00:16 +0000
commit15137597824b263c875bd427f7d121eae28d45a6 (patch)
treecb6dc61e13822c103ece293f875e85dab24823c0 /src
parent4126980a15f4f6bb981d0793bd37483456c5bc79 (diff)
Various fixes.
Diffstat (limited to 'src')
-rw-r--r--src/asset.cc20
-rw-r--r--src/asset.h7
-rw-r--r--src/dcp.cc3
-rw-r--r--src/mono_picture_mxf_writer.cc1
-rw-r--r--src/picture_mxf.h14
-rw-r--r--src/picture_mxf_writer_common.cc3
-rw-r--r--src/stereo_picture_mxf_writer.cc1
-rw-r--r--src/util.cc23
-rw-r--r--src/util.h3
9 files changed, 64 insertions, 11 deletions
diff --git a/src/asset.cc b/src/asset.cc
index 43db41e3..738fb019 100644
--- a/src/asset.cc
+++ b/src/asset.cc
@@ -23,6 +23,8 @@
#include "asset.h"
#include "util.h"
+#include "exceptions.h"
+#include "compose.hpp"
#include <libxml++/libxml++.h>
#include <boost/lexical_cast.hpp>
@@ -70,7 +72,7 @@ Asset::write_to_pkl (xmlpp::Node* node) const
}
void
-Asset::write_to_assetmap (xmlpp::Node* node) const
+Asset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const
{
assert (!_file.empty ());
@@ -78,7 +80,11 @@ Asset::write_to_assetmap (xmlpp::Node* node) const
asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
xmlpp::Node* chunk_list = asset->add_child ("ChunkList");
xmlpp::Node* chunk = chunk_list->add_child ("Chunk");
- chunk->add_child("Path")->add_child_text (_file.string ());
+ boost::optional<boost::filesystem::path> path = relative_to_root (root, _file);
+ if (!path) {
+ throw MiscError (String::compose ("Asset %1 is not within the directory %2", _file, root));
+ }
+ chunk->add_child("Path")->add_child_text (path.get().string ());
chunk->add_child("VolumeIndex")->add_child_text ("1");
chunk->add_child("Offset")->add_child_text ("0");
chunk->add_child("Length")->add_child_text (lexical_cast<string> (boost::filesystem::file_size (_file)));
@@ -89,7 +95,7 @@ Asset::hash () const
{
assert (!_file.empty ());
- if (!_hash.empty ()) {
+ if (_hash.empty ()) {
_hash = make_digest (_file, 0);
}
@@ -106,3 +112,11 @@ Asset::equals (boost::shared_ptr<const Asset> other, EqualityOptions, function<v
return true;
}
+
+void
+Asset::set_file (boost::filesystem::path file) const
+{
+ _file = boost::filesystem::absolute (file);
+ _hash.clear ();
+}
+
diff --git a/src/asset.h b/src/asset.h
index f9ec949f..bd172428 100644
--- a/src/asset.h
+++ b/src/asset.h
@@ -58,7 +58,7 @@ public:
/** Write details of the asset to a ASSETMAP.
* @param node Parent node.
*/
- void write_to_assetmap (xmlpp::Node* node) const;
+ void write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const;
/** Write details of the asset to a PKL AssetList node.
* @param node Parent node.
@@ -69,10 +69,7 @@ public:
return _file;
}
- void set_file (boost::filesystem::path file) const {
- _file = file;
- _hash.clear ();
- }
+ void set_file (boost::filesystem::path file) const;
/** @return the hash of this asset's file. It will be
* computed by this call if necessary.
diff --git a/src/dcp.cc b/src/dcp.cc
index e4a5678c..2588c654 100644
--- a/src/dcp.cc
+++ b/src/dcp.cc
@@ -61,6 +61,7 @@ DCP::DCP (boost::filesystem::path directory)
: _directory (directory)
{
boost::filesystem::create_directories (directory);
+ _directory = boost::filesystem::canonical (_directory);
}
void
@@ -314,7 +315,7 @@ DCP::write_assetmap (Standard standard, string pkl_uuid, int pkl_length, XMLMeta
chunk->add_child("Length")->add_child_text (lexical_cast<string> (pkl_length));
for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
- (*i)->write_to_assetmap (asset_list);
+ (*i)->write_to_assetmap (asset_list, _directory);
}
/* This must not be the _formatted version otherwise signature digests will be wrong */
diff --git a/src/mono_picture_mxf_writer.cc b/src/mono_picture_mxf_writer.cc
index d685cd69..b32a79f5 100644
--- a/src/mono_picture_mxf_writer.cc
+++ b/src/mono_picture_mxf_writer.cc
@@ -50,6 +50,7 @@ void
MonoPictureMXFWriter::start (uint8_t* data, int size)
{
dcp::start (this, _state, _standard, _picture_mxf, data, size);
+ _picture_mxf->set_frame_rate (_picture_mxf->edit_rate());
}
FrameInfo
diff --git a/src/picture_mxf.h b/src/picture_mxf.h
index e8040a4e..38a1819e 100644
--- a/src/picture_mxf.h
+++ b/src/picture_mxf.h
@@ -61,15 +61,27 @@ public:
return _size;
}
+ void set_size (Size s) {
+ _size = s;
+ }
+
Fraction frame_rate () const {
return _frame_rate;
}
+ void set_frame_rate (Fraction r) {
+ _frame_rate = r;
+ }
+
Fraction screen_aspect_ratio () const {
return _screen_aspect_ratio;
}
-protected:
+ void set_screen_aspect_ratio (Fraction r) {
+ _screen_aspect_ratio = r;
+ }
+
+protected:
bool frame_buffer_equals (
int frame, EqualityOptions opt, boost::function<void (NoteType, std::string)> note,
diff --git a/src/picture_mxf_writer_common.cc b/src/picture_mxf_writer_common.cc
index d2073f77..d8d1589b 100644
--- a/src/picture_mxf_writer_common.cc
+++ b/src/picture_mxf_writer_common.cc
@@ -43,6 +43,9 @@ void dcp::start (PictureMXFWriter* writer, shared_ptr<P> state, Standard standar
state->j2k_parser.FillPictureDescriptor (state->picture_descriptor);
state->picture_descriptor.EditRate = ASDCP::Rational (mxf->edit_rate().numerator, mxf->edit_rate().denominator);
+
+ mxf->set_size (Size (state->picture_descriptor.StoredWidth, state->picture_descriptor.StoredHeight));
+ mxf->set_screen_aspect_ratio (Fraction (state->picture_descriptor.AspectRatio.Numerator, state->picture_descriptor.AspectRatio.Denominator));
mxf->fill_writer_info (&state->writer_info, standard);
diff --git a/src/stereo_picture_mxf_writer.cc b/src/stereo_picture_mxf_writer.cc
index d7344894..4f98c60e 100644
--- a/src/stereo_picture_mxf_writer.cc
+++ b/src/stereo_picture_mxf_writer.cc
@@ -48,6 +48,7 @@ void
StereoPictureMXFWriter::start (uint8_t* data, int size)
{
dcp::start (this, _state, _standard, _picture_mxf, data, size);
+ _picture_mxf->set_frame_rate (Fraction (_picture_mxf->edit_rate().numerator * 2, _picture_mxf->edit_rate().denominator));
}
/** Write a frame for one eye. Frames must be written left, then right, then left etc.
diff --git a/src/util.cc b/src/util.cc
index e26e66be..4be026d2 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -384,3 +384,26 @@ dcp::fopen_boost (boost::filesystem::path p, string t)
return fopen (p.c_str(), t.c_str ());
#endif
}
+
+boost::optional<boost::filesystem::path>
+dcp::relative_to_root (boost::filesystem::path root, boost::filesystem::path file)
+{
+ boost::filesystem::path::const_iterator i = root.begin ();
+ boost::filesystem::path::const_iterator j = file.begin ();
+
+ while (i != root.end() && j != file.end() && *i == *j) {
+ ++i;
+ ++j;
+ }
+
+ if (i != root.end ()) {
+ return boost::optional<boost::filesystem::path> ();
+ }
+
+ boost::filesystem::path rel;
+ while (j != file.end ()) {
+ rel /= *j++;
+ }
+
+ return rel;
+}
diff --git a/src/util.h b/src/util.h
index e79c0a0b..8db838eb 100644
--- a/src/util.h
+++ b/src/util.h
@@ -29,6 +29,7 @@
#include <boost/function.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
+#include <boost/optional.hpp>
#include <openjpeg.h>
#include <string>
#include <stdint.h>
@@ -81,7 +82,7 @@ extern void add_signature_value (xmlpp::Element* parent, CertificateChain const
extern void add_signer (xmlpp::Element* parent, CertificateChain const & certificates, std::string const & ns);
extern int base64_decode (std::string const & in, unsigned char* out, int out_length);
-
+extern boost::optional<boost::filesystem::path> relative_to_root (boost::filesystem::path root, boost::filesystem::path file);
extern std::string tm_to_string (struct tm *);
extern std::string utc_offset_to_string (int);
extern std::string ptime_to_string (boost::posix_time::ptime);