diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-03-18 00:29:47 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-03-18 00:29:47 +0000 |
| commit | 099cb53c7a1079b3d3b2bf0c1cf635673a0192fd (patch) | |
| tree | e56297d012812c24d63f512b71367420b228ee17 /src | |
| parent | e5ce888e953340ca94d506d710f90fec93540cd2 (diff) | |
Accept that <Duration> and <EntryPoint> are optional, and account for this in tests.
Also fix tests to reflect <AnnotationText> no longer being filled in with a default
value.
Diffstat (limited to 'src')
| -rw-r--r-- | src/reel.cc | 12 | ||||
| -rw-r--r-- | src/reel_asset.cc | 49 | ||||
| -rw-r--r-- | src/reel_asset.h | 16 |
3 files changed, 47 insertions, 30 deletions
diff --git a/src/reel.cc b/src/reel.cc index bda83531..0a9a4b63 100644 --- a/src/reel.cc +++ b/src/reel.cc @@ -328,22 +328,22 @@ Reel::duration () const int64_t d = 0; if (_main_picture) { - d = max (d, _main_picture->duration ()); + d = max (d, _main_picture->actual_duration()); } if (_main_sound) { - d = max (d, _main_sound->duration ()); + d = max (d, _main_sound->actual_duration()); } if (_main_subtitle) { - d = max (d, _main_subtitle->duration ()); + d = max (d, _main_subtitle->actual_duration()); } if (_main_markers) { - d = max (d, _main_markers->duration ()); + d = max (d, _main_markers->actual_duration()); } BOOST_FOREACH (shared_ptr<ReelClosedCaptionAsset> i, _closed_captions) { - d = max (d, i->duration()); + d = max (d, i->actual_duration()); } if (_atmos) { - d = max (d, _atmos->duration ()); + d = max (d, _atmos->actual_duration()); } return d; diff --git a/src/reel_asset.cc b/src/reel_asset.cc index caaf3eee..2457c079 100644 --- a/src/reel_asset.cc +++ b/src/reel_asset.cc @@ -68,10 +68,10 @@ ReelAsset::ReelAsset (string id, Fraction edit_rate, int64_t intrinsic_duration, ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node) : Object (remove_urn_uuid (node->string_child ("Id"))) , _intrinsic_duration (node->number_child<int64_t> ("IntrinsicDuration")) - , _duration (node->number_child<int64_t> ("Duration")) + , _duration (node->optional_number_child<int64_t>("Duration")) , _annotation_text (node->optional_string_child ("AnnotationText").get_value_or ("")) , _edit_rate (Fraction (node->string_child ("EditRate"))) - , _entry_point (node->number_child<int64_t> ("EntryPoint")) + , _entry_point (node->optional_number_child<int64_t>("EntryPoint")) { } @@ -79,21 +79,25 @@ ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node) xmlpp::Node* ReelAsset::write_to_cpl_base (xmlpp::Node* node, Standard standard, optional<string> hash) const { - xmlpp::Element* a = node->add_child (cpl_node_name (standard)); - pair<string, string> const attr = cpl_node_attribute (standard); - if (!attr.first.empty ()) { - a->set_attribute (attr.first, attr.second); - } - pair<string, string> const ns = cpl_node_namespace (standard); - if (!ns.first.empty ()) { - a->set_namespace_declaration (ns.first, ns.second); - } - a->add_child("Id")->add_child_text ("urn:uuid:" + _id); - a->add_child("AnnotationText")->add_child_text (_annotation_text); - a->add_child("EditRate")->add_child_text (String::compose ("%1 %2", _edit_rate.numerator, _edit_rate.denominator)); - a->add_child("IntrinsicDuration")->add_child_text (raw_convert<string> (_intrinsic_duration)); - a->add_child("EntryPoint")->add_child_text (raw_convert<string> (_entry_point)); - a->add_child("Duration")->add_child_text (raw_convert<string> (_duration)); + xmlpp::Element* a = node->add_child (cpl_node_name (standard)); + pair<string, string> const attr = cpl_node_attribute (standard); + if (!attr.first.empty ()) { + a->set_attribute (attr.first, attr.second); + } + pair<string, string> const ns = cpl_node_namespace (standard); + if (!ns.first.empty ()) { + a->set_namespace_declaration (ns.first, ns.second); + } + a->add_child("Id")->add_child_text ("urn:uuid:" + _id); + a->add_child("AnnotationText")->add_child_text (_annotation_text); + a->add_child("EditRate")->add_child_text (String::compose ("%1 %2", _edit_rate.numerator, _edit_rate.denominator)); + a->add_child("IntrinsicDuration")->add_child_text (raw_convert<string> (_intrinsic_duration)); + if (_entry_point) { + a->add_child("EntryPoint")->add_child_text(raw_convert<string>(*_entry_point)); + } + if (_duration) { + a->add_child("Duration")->add_child_text(raw_convert<string>(*_duration)); + } if (hash) { a->add_child("Hash")->add_child_text (hash.get()); } @@ -147,3 +151,14 @@ ReelAsset::asset_equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, return true; } + +/** @return <Duration>, or <IntrinsicDuration> - <EntryPoint> if <Duration> is not present */ +int64_t +ReelAsset::actual_duration () const +{ + if (_duration) { + return *_duration; + } + + return _intrinsic_duration - _entry_point.get_value_or(0); +} diff --git a/src/reel_asset.h b/src/reel_asset.h index 4092a97a..072d55fd 100644 --- a/src/reel_asset.h +++ b/src/reel_asset.h @@ -82,7 +82,7 @@ public: _entry_point = e; } - int64_t entry_point () const { + boost::optional<int64_t> entry_point () const { return _entry_point; } @@ -90,10 +90,12 @@ public: _duration = d; } - int64_t duration () const { + boost::optional<int64_t> duration () const { return _duration; } + int64_t actual_duration () const; + std::string annotation_text () const { return _annotation_text; } @@ -119,13 +121,13 @@ protected: xmlpp::Node* write_to_cpl_base (xmlpp::Node* node, Standard standard, boost::optional<std::string> hash) const; - int64_t _intrinsic_duration; ///< The <IntrinsicDuration> from the reel's entry for this asset - int64_t _duration; ///< The <Duration> from the reel's entry for this asset + int64_t _intrinsic_duration; ///< The <IntrinsicDuration> from the reel's entry for this asset + boost::optional<int64_t> _duration; ///< The <Duration> from the reel's entry for this asset, if present private: - std::string _annotation_text; ///< The <AnnotationText> from the reel's entry for this asset - Fraction _edit_rate; ///< The <EditRate> from the reel's entry for this asset - int64_t _entry_point; ///< The <EntryPoint> from the reel's entry for this asset + std::string _annotation_text; ///< The <AnnotationText> from the reel's entry for this asset + Fraction _edit_rate; ///< The <EditRate> from the reel's entry for this asset + boost::optional<int64_t> _entry_point; ///< The <EntryPoint> from the reel's entry for this asset }; } |
