diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-06-08 23:28:17 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-06-08 23:28:17 +0100 |
| commit | 6425742f95a4c2e539061b29016a4a5bd10ac9ae (patch) | |
| tree | 9dd986f6ca187071811b7b94f3e5dc4e08c71988 /src | |
| parent | 635c3ae7aee1cad4b871fcf0ddf02a8be1cdce78 (diff) | |
| parent | 9e871b60fc7430650f239cfd9291ab65cb5aeba8 (diff) | |
Merge branch '1.0' of ssh://main.carlh.net/home/carl/git/libdcp into 1.0
Diffstat (limited to 'src')
| -rw-r--r-- | src/dcp.cc | 52 | ||||
| -rw-r--r-- | src/dcp.h | 12 | ||||
| -rw-r--r-- | src/interop_subtitle_asset.cc | 5 | ||||
| -rw-r--r-- | src/interop_subtitle_asset.h | 2 | ||||
| -rw-r--r-- | src/load_font_node.h | 2 | ||||
| -rw-r--r-- | src/local_time.cc | 22 | ||||
| -rw-r--r-- | src/local_time.h | 6 | ||||
| -rw-r--r-- | src/mxf.cc | 7 | ||||
| -rw-r--r-- | src/reel_asset.h | 7 | ||||
| -rw-r--r-- | src/smpte_subtitle_asset.cc | 15 | ||||
| -rw-r--r-- | src/smpte_subtitle_asset.h | 22 | ||||
| -rw-r--r-- | src/types.cc | 7 | ||||
| -rw-r--r-- | src/types.h | 1 |
13 files changed, 127 insertions, 33 deletions
@@ -39,6 +39,7 @@ #include "decrypted_kdm.h" #include "decrypted_kdm_key.h" #include "dcp_assert.h" +#include "reel_asset.h" #include <xmlsec/xmldsig.h> #include <xmlsec/app.h> #include <libxml++/libxml++.h> @@ -114,6 +115,12 @@ DCP::read (bool keep_going, ReadErrors* errors) /* XXX: I think we should be looking at the PKL here to decide type, not the extension of the file. */ + + /* Make a list of non-CPL assets so that we can resolve the references + from the CPL. + */ + list<shared_ptr<Asset> > other_assets; + for (map<string, boost::filesystem::path>::const_iterator i = paths.begin(); i != paths.end(); ++i) { boost::filesystem::path path = _directory / i->second; @@ -122,7 +129,7 @@ DCP::read (bool keep_going, ReadErrors* errors) continue; } - if (boost::algorithm::ends_with (path.string(), ".xml")) { + if (boost::filesystem::extension (path) == ".xml") { xmlpp::DomParser* p = new xmlpp::DomParser; try { p->parse_file (path.string()); @@ -135,11 +142,11 @@ DCP::read (bool keep_going, ReadErrors* errors) delete p; if (root == "CompositionPlaylist") { - _assets.push_back (shared_ptr<CPL> (new CPL (path))); + _cpls.push_back (shared_ptr<CPL> (new CPL (path))); } else if (root == "DCSubtitle") { - _assets.push_back (shared_ptr<InteropSubtitleAsset> (new InteropSubtitleAsset (path))); + other_assets.push_back (shared_ptr<InteropSubtitleAsset> (new InteropSubtitleAsset (path))); } - } else if (boost::algorithm::ends_with (path.string(), ".mxf")) { + } else if (boost::filesystem::extension (path) == ".mxf") { ASDCP::EssenceType_t type; if (ASDCP::EssenceType (path.string().c_str(), type) != ASDCP::RESULT_OK) { throw DCPReadError ("Could not find essence type"); @@ -149,26 +156,26 @@ DCP::read (bool keep_going, ReadErrors* errors) case ASDCP::ESS_MPEG2_VES: throw DCPReadError ("MPEG2 video essences are not supported"); case ASDCP::ESS_JPEG_2000: - _assets.push_back (shared_ptr<MonoPictureAsset> (new MonoPictureAsset (path))); + other_assets.push_back (shared_ptr<MonoPictureAsset> (new MonoPictureAsset (path))); break; case ASDCP::ESS_PCM_24b_48k: case ASDCP::ESS_PCM_24b_96k: - _assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (path))); + other_assets.push_back (shared_ptr<SoundAsset> (new SoundAsset (path))); break; case ASDCP::ESS_JPEG_2000_S: - _assets.push_back (shared_ptr<StereoPictureAsset> (new StereoPictureAsset (path))); + other_assets.push_back (shared_ptr<StereoPictureAsset> (new StereoPictureAsset (path))); break; case ASDCP::ESS_TIMED_TEXT: - _assets.push_back (shared_ptr<SMPTESubtitleAsset> (new SMPTESubtitleAsset (path))); + other_assets.push_back (shared_ptr<SMPTESubtitleAsset> (new SMPTESubtitleAsset (path))); break; default: throw DCPReadError ("Unknown MXF essence type"); - } + } } } BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) { - i->resolve_refs (list_of_type<Asset, Object> (assets ())); + i->resolve_refs (list_of_type<Asset, Object> (other_assets)); } } @@ -200,9 +207,9 @@ DCP::equals (DCP const & other, EqualityOptions opt, NoteHandler note) const } void -DCP::add (boost::shared_ptr<Asset> asset) +DCP::add (boost::shared_ptr<CPL> cpl) { - _assets.push_back (asset); + _cpls.push_back (cpl); } bool @@ -260,7 +267,7 @@ DCP::write_pkl (Standard standard, string pkl_uuid, XMLMetadata metadata, shared pkl->add_child("Creator")->add_child_text (metadata.creator); xmlpp::Element* asset_list = pkl->add_child("AssetList"); - BOOST_FOREACH (shared_ptr<Asset> i, _assets) { + BOOST_FOREACH (shared_ptr<Asset> i, assets ()) { i->write_to_pkl (asset_list, standard); } @@ -370,7 +377,7 @@ DCP::write_assetmap (Standard standard, string pkl_uuid, int pkl_length, XMLMeta chunk->add_child("Offset")->add_child_text ("0"); chunk->add_child("Length")->add_child_text (raw_convert<string> (pkl_length)); - BOOST_FOREACH (shared_ptr<Asset> i, _assets) { + BOOST_FOREACH (shared_ptr<Asset> i, assets ()) { i->write_to_assetmap (asset_list, _directory); } @@ -405,5 +412,20 @@ DCP::write_xml ( list<shared_ptr<CPL> > DCP::cpls () const { - return list_of_type<Asset, CPL> (_assets); + return _cpls; +} + +/** @return All assest (including CPLs) */ +list<shared_ptr<Asset> > +DCP::assets () const +{ + list<shared_ptr<Asset> > assets; + BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) { + assets.push_back (i); + BOOST_FOREACH (shared_ptr<const ReelAsset> j, i->reel_assets ()) { + assets.push_back (j->asset_ref().object ()); + } + } + + return assets; } @@ -82,14 +82,10 @@ public: */ bool equals (DCP const & other, EqualityOptions options, NoteHandler note) const; - void add (boost::shared_ptr<Asset> asset); + void add (boost::shared_ptr<CPL> cpl); std::list<boost::shared_ptr<CPL> > cpls () const; - - /** @return All this DCP's assets (note that CPLs are assets) */ - std::list<boost::shared_ptr<Asset> > assets () const { - return _assets; - } + std::list<boost::shared_ptr<Asset> > assets () const; bool encrypted () const; @@ -123,8 +119,8 @@ private: /** the directory that we are writing to */ boost::filesystem::path _directory; - /** the assets that make up this DCP */ - std::list<boost::shared_ptr<Asset> > _assets; + /** the CPLs that make up this DCP */ + std::list<boost::shared_ptr<CPL> > _cpls; }; } diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 96ccb68a..231dda16 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -56,10 +56,9 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file) parse_subtitles (xml, font_nodes); } -InteropSubtitleAsset::InteropSubtitleAsset (string movie_title, string language) - : _movie_title (movie_title) +InteropSubtitleAsset::InteropSubtitleAsset () { - _language = language; + } Glib::ustring diff --git a/src/interop_subtitle_asset.h b/src/interop_subtitle_asset.h index 56350421..378bacc7 100644 --- a/src/interop_subtitle_asset.h +++ b/src/interop_subtitle_asset.h @@ -36,7 +36,7 @@ class InteropLoadFontNode; class InteropSubtitleAsset : public SubtitleAsset { public: - InteropSubtitleAsset (std::string movie_title, std::string language); + InteropSubtitleAsset (); InteropSubtitleAsset (boost::filesystem::path file); bool equals ( diff --git a/src/load_font_node.h b/src/load_font_node.h index 58e5920a..3ff70497 100644 --- a/src/load_font_node.h +++ b/src/load_font_node.h @@ -35,6 +35,8 @@ public: LoadFontNode (std::string id_) : id (id_) {} + + virtual ~LoadFontNode () {} std::string id; }; diff --git a/src/local_time.cc b/src/local_time.cc index 32e8e093..09729543 100644 --- a/src/local_time.cc +++ b/src/local_time.cc @@ -29,6 +29,7 @@ #include <cstdio> using std::string; +using std::ostream; using boost::lexical_cast; using namespace dcp; @@ -156,3 +157,24 @@ LocalTime::time_of_day (bool with_millisecond) const } return buffer; } + +bool +LocalTime::operator== (LocalTime const & other) const +{ + return _year == other._year && _month == other._month && _day == other._day && + _hour == other._hour && _second == other._second && _millisecond == other._millisecond && + _tz_hour == other._tz_hour && _tz_minute == other._tz_minute; +} + +bool +LocalTime::operator!= (LocalTime const & other) const +{ + return !(*this == other); +} + +ostream& +dcp::operator<< (ostream& s, LocalTime const & t) +{ + s << t.as_string (); + return s; +} diff --git a/src/local_time.h b/src/local_time.h index b1751f8b..5112307c 100644 --- a/src/local_time.h +++ b/src/local_time.h @@ -51,6 +51,9 @@ public: std::string date () const; std::string time_of_day (bool with_millisecond = false) const; + bool operator== (LocalTime const & other) const; + bool operator!= (LocalTime const & other) const; + private: friend class ::local_time_test; @@ -69,6 +72,9 @@ private: int _tz_minute; ///< minutes by which this time is offset from UTC }; +std::ostream& +operator<< (std::ostream& s, LocalTime const & t); + } #endif @@ -36,6 +36,7 @@ #include <iostream> using std::string; +using std::cout; using std::list; using std::pair; using boost::shared_ptr; @@ -105,8 +106,10 @@ MXF::read_writer_info (ASDCP::WriterInfo const & info) { char buffer[64]; - Kumu::bin2UUIDhex (info.CryptographicKeyID, ASDCP::UUIDlen, buffer, sizeof (buffer)); - _key_id = buffer; + if (info.EncryptedEssence) { + Kumu::bin2UUIDhex (info.CryptographicKeyID, ASDCP::UUIDlen, buffer, sizeof (buffer)); + _key_id = buffer; + } _metadata.read (info); diff --git a/src/reel_asset.h b/src/reel_asset.h index 47bae675..e9704acd 100644 --- a/src/reel_asset.h +++ b/src/reel_asset.h @@ -59,10 +59,15 @@ public: virtual bool equals (boost::shared_ptr<const ReelAsset>, EqualityOptions, NoteHandler) const; /** @return a Ref to our actual asset */ - Ref<Asset>& asset_ref () { + Ref<Asset> const & asset_ref () const { return _asset_ref; } + /** @return a Ref to our actual asset */ + Ref<Asset>& asset_ref () { + return _asset_ref; + } + int64_t entry_point () const { return _entry_point; } diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index eef28e51..69e2712f 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -43,6 +43,12 @@ using boost::split; using boost::is_any_of; using namespace dcp; +SMPTESubtitleAsset::SMPTESubtitleAsset () + : _time_code_rate (0) +{ + +} + /** Construct a SMPTESubtitleAsset by reading an XML or MXF file. * @param file Filename. * @param mxf true if file is an MXF, false if it is XML. @@ -177,16 +183,19 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const memcpy (descriptor.AssetID, writer_info.AssetUUID, ASDCP::UUIDlen); descriptor.ContainerDuration = latest_subtitle_out().as_editable_units (_edit_rate.numerator / _edit_rate.denominator); - /* XXX: fonts into descriptor? */ + /* XXX: should write fonts into the file somehow */ ASDCP::TimedText::MXFWriter writer; - Kumu::Result_t r = writer.OpenWrite (p.string().c_str(), writer_info, descriptor); + ASDCP::Result_t r = writer.OpenWrite (p.string().c_str(), writer_info, descriptor); if (ASDCP_FAILURE (r)) { boost::throw_exception (FileError ("could not open subtitle MXF for writing", p.string(), r)); } /* XXX: no encryption */ - writer.WriteTimedTextResource (xml_as_string ()); + r = writer.WriteTimedTextResource (xml_as_string ()); + if (ASDCP_FAILURE (r)) { + boost::throw_exception (MXFFileError ("could not write XML to timed text resource", p.string(), r)); + } writer.Finalize (); diff --git a/src/smpte_subtitle_asset.h b/src/smpte_subtitle_asset.h index c796e1d4..3fb2571a 100644 --- a/src/smpte_subtitle_asset.h +++ b/src/smpte_subtitle_asset.h @@ -36,6 +36,8 @@ class SMPTELoadFontNode; class SMPTESubtitleAsset : public SubtitleAsset, public MXF { public: + SMPTESubtitleAsset (); + /** @param file File name * @param mxf true if `file' is a MXF, or false if it is an XML file. */ @@ -52,6 +54,22 @@ public: Glib::ustring xml_as_string () const; void write (boost::filesystem::path path) const; + void set_content_title_text (std::string t) { + _content_title_text = t; + } + + void set_language (std::string l) { + _language = l; + } + + void set_edit_rate (Fraction e) { + _edit_rate = e; + } + + void set_time_code_rate (int t) { + _time_code_rate = t; + } + /** @return title of the film that these subtitles are for, * to be presented to the user. */ @@ -74,6 +92,10 @@ public: return _issue_date; } + boost::optional<int> reel_number () const { + return _reel_number; + } + Fraction edit_rate () const { return _edit_rate; } diff --git a/src/types.cc b/src/types.cc index 37666701..f32d90bd 100644 --- a/src/types.cc +++ b/src/types.cc @@ -62,6 +62,13 @@ dcp::operator!= (Fraction const & a, Fraction const & b) return (a.numerator != b.numerator || a.denominator != b.denominator); } +ostream& +dcp::operator<< (ostream& s, Fraction const & f) +{ + s << f.numerator << "/" << f.denominator; + return s; +} + /** Construct a Colour, initialising it to black. */ Colour::Colour () : r (0) diff --git a/src/types.h b/src/types.h index 16908952..f364572b 100644 --- a/src/types.h +++ b/src/types.h @@ -147,6 +147,7 @@ public: extern bool operator== (Fraction const & a, Fraction const & b); extern bool operator!= (Fraction const & a, Fraction const & b); +extern std::ostream& operator<< (std::ostream& s, Fraction const & f); /** @struct EqualityOptions * @brief A class to describe what "equality" means for a particular test. |
