Some OS X build fixes.
[libdcp.git] / src / reel_asset.cc
index 5fa59fc2f02364898da5ef4a9175cea0dc91fb5b..037a39780e55a4a5f43eee630da1955ce77611a6 100644 (file)
@@ -17,6 +17,7 @@
 
 */
 
+#include "raw_convert.h"
 #include "reel_asset.h"
 #include "content.h"
 #include "compose.hpp"
@@ -24,9 +25,9 @@
 
 using std::pair;
 using std::string;
+using std::stringstream;
 using std::make_pair;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using namespace dcp;
 
 ReelAsset::ReelAsset ()
@@ -40,19 +41,26 @@ ReelAsset::ReelAsset ()
 
 }
 
-ReelAsset::ReelAsset (boost::shared_ptr<Content> content, int64_t entry_point)
+/** Construct a ReelAsset.
+ *  @param content Content that this asset refers to.
+ *  @param edit_rate Edit rate for the content.
+ *  @param intrinsic_duration Intrinsic duration of this content.
+ *  @param entry_point Entry point to use in that content.
+ */
+ReelAsset::ReelAsset (shared_ptr<Content> content, Fraction edit_rate, int64_t intrinsic_duration, int64_t entry_point)
        : Object (content->id ())
        , _content (content)
-       , _edit_rate (content->edit_rate ())
-       , _intrinsic_duration (content->intrinsic_duration ())
+       , _edit_rate (edit_rate)
+       , _intrinsic_duration (intrinsic_duration)
        , _entry_point (entry_point)
-       , _duration (_intrinsic_duration - _entry_point)
+       , _duration (intrinsic_duration - entry_point)
        , _hash (make_digest (content->file (), 0))
 {
-
+       /* default _annotation_text to the leaf name of our file */
+        _annotation_text = content->file().leaf().string ();
 }
 
-ReelAsset::ReelAsset (boost::shared_ptr<const cxml::Node> node)
+ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node)
        : Object (node->string_child ("Id"))
        , _content (_id)
        , _annotation_text (node->optional_string_child ("AnnotationText").get_value_or (""))
@@ -60,23 +68,18 @@ ReelAsset::ReelAsset (boost::shared_ptr<const cxml::Node> node)
        , _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->string_child ("Hash"))
-       , _key_id (node->optional_string_child ("KeyId").get_value_or (""))
+       , _hash (node->optional_string_child ("Hash").get_value_or (""))
 {
        if (_id.length() > 9) {
                _id = _id.substr (9);
                _content.set_id (_id);
        }
-       
-       if (_key_id.length() > 9) {
-               _key_id = _key_id.substr (9);
-       }
 }
 
 void
-ReelAsset::write_to_cpl (xmlpp::Node* node, Standard) const
+ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
 {
-        pair<string, string> const attr = cpl_node_attribute ();
+        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);
@@ -84,16 +87,60 @@ ReelAsset::write_to_cpl (xmlpp::Node* node, Standard) const
         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 (lexical_cast<string> (_intrinsic_duration));
-        a->add_child("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point));
-        a->add_child("Duration")->add_child_text (lexical_cast<string> (_duration));
-        if (!_key_id.empty ()) {
-                a->add_child("KeyId")->add_child_text ("urn:uuid:" + _key_id);
-        }
+        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));
+       a->add_child("Hash")->add_child_text (_content.object()->hash ());
 }
 
 pair<string, string>
-ReelAsset::cpl_node_attribute () const
+ReelAsset::cpl_node_attribute (Standard) const
 {
        return make_pair ("", "");
 }
+
+bool
+ReelAsset::equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, NoteHandler note) const
+{
+       if (_annotation_text != other->_annotation_text) {
+               stringstream s;
+               s << "Reel: annotation texts differ (" << _annotation_text << " vs " << other->_annotation_text << ")\n";
+               note (DCP_ERROR, s.str ());
+               return false;
+       }
+
+       if (_edit_rate != other->_edit_rate) {
+               note (DCP_ERROR, "Reel: edit rates differ");
+               return false;
+       }
+
+       if (_intrinsic_duration != other->_intrinsic_duration) {
+               note (DCP_ERROR, String::compose ("Reel: intrinsic durations differ (%1 vs %2)", _intrinsic_duration, other->_intrinsic_duration));
+               return false;
+       }
+
+       if (_entry_point != other->_entry_point) {
+               note (DCP_ERROR, "Reel: entry points differ");
+               return false;
+       }
+
+       if (_duration != other->_duration) {
+               note (DCP_ERROR, "Reel: durations differ");
+               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");
+               }
+       }
+
+       if (_content.resolved () && other->_content.resolved ()) {
+               return _content->equals (other->_content.object (), opt, note);
+       }
+
+       return true;
+}