rebase() would round up and so it was possible for ticks to go out of range.
[libdcp.git] / src / reel_asset.cc
index c2d9824c18bd56538e9717f600abb8ca6b23f8c4..f96ee2c08b6aca83a416ab5232a0d09e7f02e274 100644 (file)
 
     You should have received a copy of the GNU General Public License
     along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
+
+    In addition, as a special exception, the copyright holders give
+    permission to link the code of portions of this program with the
+    OpenSSL library under certain conditions as described in each
+    individual source file, and distribute linked combinations
+    including the two.
+
+    You must obey the GNU General Public License in all respects
+    for all of the code used other than OpenSSL.  If you modify
+    file(s) with this exception, you may extend this exception to your
+    version of the file(s), but you are not obligated to do so.  If you
+    do not wish to do so, delete this exception statement from your
+    version.  If you delete this exception statement from all source
+    files in the program, then also delete it here.
 */
 
 /** @file  src/reel_asset.cc
 #include "compose.hpp"
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
-#include <iostream>
 
 using std::pair;
-using std::cout;
 using std::string;
-using std::stringstream;
 using std::make_pair;
 using boost::shared_ptr;
 using namespace dcp;
@@ -63,7 +74,9 @@ ReelAsset::ReelAsset (shared_ptr<Asset> asset, Fraction edit_rate, int64_t intri
        , _hash (asset->hash ())
 {
        /* default _annotation_text to the leaf name of our file */
-        _annotation_text = asset->file().leaf().string ();
+       if (asset->file ()) {
+               _annotation_text = asset->file()->leaf().string ();
+       }
 }
 
 ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node)
@@ -74,7 +87,7 @@ ReelAsset::ReelAsset (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->optional_string_child ("Hash").get_value_or (""))
+       , _hash (node->optional_string_child ("Hash"))
 {
 
 }
@@ -82,18 +95,24 @@ ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node)
 void
 ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
 {
+        xmlpp::Element* a = node->add_child (cpl_node_name (standard));
         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);
         }
+        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));
-       a->add_child("Hash")->add_child_text (_asset_ref.asset()->hash ());
+       if (_hash) {
+               a->add_child("Hash")->add_child_text (_hash.get());
+       }
 }
 
 pair<string, string>
@@ -102,17 +121,22 @@ ReelAsset::cpl_node_attribute (Standard) const
        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
 {
        if (_annotation_text != other->_annotation_text) {
-               stringstream s;
-               s << "Reel: annotation texts differ (" << _annotation_text << " vs " << other->_annotation_text << ")\n";
+               string const s = "Reel: annotation texts differ (" + _annotation_text + " vs " + other->_annotation_text + ")\n";
                if (!opt.reel_annotation_texts_can_differ) {
-                       note (DCP_ERROR, s.str ());
+                       note (DCP_ERROR, s);
                        return false;
                } else {
-                       note (DCP_NOTE, s.str ());
+                       note (DCP_NOTE, s);
                }
        }