From 15137597824b263c875bd427f7d121eae28d45a6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 28 Jan 2014 16:00:16 +0000 Subject: Various fixes. --- src/asset.cc | 20 ++++++++++++++++--- src/asset.h | 7 ++----- src/dcp.cc | 3 ++- src/mono_picture_mxf_writer.cc | 1 + src/picture_mxf.h | 14 ++++++++++++- src/picture_mxf_writer_common.cc | 3 +++ src/stereo_picture_mxf_writer.cc | 1 + src/util.cc | 23 +++++++++++++++++++++ src/util.h | 3 ++- test/dcp_test.cc | 6 ++++-- test/util_test.cc | 43 ++++++++++++++++++++++++++++++++++++++++ 11 files changed, 111 insertions(+), 13 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 #include @@ -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 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 (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 other, EqualityOptions, functionadd_child("Length")->add_child_text (lexical_cast (pkl_length)); for (list >::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 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

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 +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 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 #include #include +#include #include #include #include @@ -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 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); diff --git a/test/dcp_test.cc b/test/dcp_test.cc index 38c9a3fd..af5a79f5 100644 --- a/test/dcp_test.cc +++ b/test/dcp_test.cc @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE (dcp_test) shared_ptr mp (new dcp::MonoPictureMXF (dcp::Fraction (24, 1))); mp->set_progress (&d.Progress); mp->set_metadata (mxf_meta); - shared_ptr picture_writer = mp->start_write ("build/test/DCP/bar/video.mxf", dcp::SMPTE, false); + shared_ptr picture_writer = mp->start_write ("build/test/foo/video.mxf", dcp::SMPTE, false); dcp::File j2c ("test/data/32x32_red_square.j2c"); for (int i = 0; i < 24; ++i) { picture_writer->write (j2c.data (), j2c.size ()); @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE (dcp_test) shared_ptr ms (new dcp::SoundMXF (dcp::Fraction (24, 1), 48000, 1)); ms->set_progress (&d.Progress); ms->set_metadata (mxf_meta); - shared_ptr sound_writer = ms->start_write ("build/test/DCP/bar/audio.mxf", dcp::SMPTE); + shared_ptr sound_writer = ms->start_write ("build/test/foo/audio.mxf", dcp::SMPTE); SF_INFO info; info.format = 0; @@ -100,6 +100,8 @@ BOOST_AUTO_TEST_CASE (dcp_test) )); d.add (cpl); + d.add (mp); + d.add (ms); d.write_xml (dcp::SMPTE, xml_meta); diff --git a/test/util_test.cc b/test/util_test.cc index 74a3e920..15f22f57 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -70,3 +70,46 @@ BOOST_AUTO_TEST_CASE (content_kind_test) BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("psa"), dcp::PUBLIC_SERVICE_ANNOUNCEMENT); BOOST_CHECK_EQUAL (dcp::content_kind_from_string ("advertisement"), dcp::ADVERTISEMENT); } + +BOOST_AUTO_TEST_CASE (relative_to_root_test) +{ + { + boost::filesystem::path root = "a"; + root /= "b"; + + boost::filesystem::path file = "a"; + file /= "b"; + file /= "c"; + + boost::optional rel = dcp::relative_to_root (root, file); + BOOST_CHECK (rel); + BOOST_CHECK_EQUAL (rel.get(), boost::filesystem::path ("c")); + } + + { + boost::filesystem::path root = "a"; + root /= "b"; + root /= "c"; + + boost::filesystem::path file = "a"; + file /= "b"; + + boost::optional rel = dcp::relative_to_root (root, file); + BOOST_CHECK (!rel); + } + + { + boost::filesystem::path root = "a"; + + boost::filesystem::path file = "a"; + file /= "b"; + file /= "c"; + + boost::optional rel = dcp::relative_to_root (root, file); + BOOST_CHECK (rel); + + boost::filesystem::path check = "b"; + check /= "c"; + BOOST_CHECK_EQUAL (rel.get(), check); + } +} -- cgit v1.2.3