#include <libxml++/libxml++.h>
using std::pair;
-using std::cout;
using std::string;
using std::make_pair;
using boost::shared_ptr;
+using boost::optional;
using namespace dcp;
-ReelAsset::ReelAsset ()
- : _asset_ref (_id)
- , _edit_rate (Fraction (24, 1))
- , _intrinsic_duration (0)
- , _entry_point (0)
- , _duration (0)
-{
-
-}
-
/** Construct a ReelAsset.
- * @param asset Asset that this ReelAsset refers to.
+ * @param id ID of this ReelAsset (which is that of the MXF, if there is one)
* @param edit_rate Edit rate for the asset.
* @param intrinsic_duration Intrinsic duration of this asset.
* @param entry_point Entry point to use in that asset.
*/
-ReelAsset::ReelAsset (shared_ptr<Asset> asset, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
- : Object (asset->id ())
- , _asset_ref (asset)
- , _edit_rate (edit_rate)
+ReelAsset::ReelAsset (string id, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
+ : Object (id)
, _intrinsic_duration (intrinsic_duration)
- , _entry_point (entry_point)
, _duration (intrinsic_duration - entry_point)
- , _hash (asset->hash ())
+ , _edit_rate (edit_rate)
+ , _entry_point (entry_point)
{
- /* default _annotation_text to the leaf name of our file */
- _annotation_text = asset->file().leaf().string ();
+
}
ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node)
: Object (remove_urn_uuid (node->string_child ("Id")))
- , _asset_ref (_id)
+ , _intrinsic_duration (node->number_child<int64_t> ("IntrinsicDuration"))
+ , _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")))
- , _intrinsic_duration (node->number_child<int64_t> ("IntrinsicDuration"))
- , _entry_point (node->number_child<int64_t> ("EntryPoint"))
- , _duration (node->number_child<int64_t> ("Duration"))
- , _hash (node->optional_string_child ("Hash"))
+ , _entry_point (node->optional_number_child<int64_t>("EntryPoint"))
{
}
-void
-ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
+xmlpp::Node*
+ReelAsset::write_to_cpl_base (xmlpp::Node* node, Standard standard, optional<string> hash) const
{
- pair<string, string> const attr = cpl_node_attribute (standard);
- xmlpp::Element* a = node->add_child (cpl_node_name ());
- if (!attr.first.empty ()) {
- a->set_attribute (attr.first, attr.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));
- if (_hash) {
- a->add_child("Hash")->add_child_text (_hash.get());
+ 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());
+ }
+ return a;
}
pair<string, string>
return make_pair ("", "");
}
+pair<string, string>
+ReelAsset::cpl_node_namespace (Standard) const
+{
+ return make_pair ("", "");
+}
+
bool
-ReelAsset::equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, NoteHandler note) const
+ReelAsset::asset_equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, NoteHandler note) const
{
if (_annotation_text != other->_annotation_text) {
string const s = "Reel: annotation texts differ (" + _annotation_text + " vs " + other->_annotation_text + ")\n";
return false;
}
- if (_hash != other->_hash) {
- if (!opt.reel_hashes_can_differ) {
- note (DCP_ERROR, "Reel: hashes differ");
- return false;
- } else {
- note (DCP_NOTE, "Reel: hashes differ");
- }
- }
+ return true;
+}
- if (_asset_ref.resolved () && other->_asset_ref.resolved ()) {
- return _asset_ref->equals (other->_asset_ref.asset(), opt, note);
+/** @return <Duration>, or <IntrinsicDuration> - <EntryPoint> if <Duration> is not present */
+int64_t
+ReelAsset::actual_duration () const
+{
+ if (_duration) {
+ return *_duration;
}
- return true;
+ return _intrinsic_duration - _entry_point.get_value_or(0);
}