Bv2.1 7.2.3: Check that subtitle <StartTime> exists and is 0.
[libdcp.git] / src / asset.cc
index 1a3bd363e30e284e8d9b2ef429910246bf2db38d..49ec72519108a4546f557821efa156506c8d956a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
 #include "exceptions.h"
 #include "dcp_assert.h"
 #include "compose.hpp"
+#include "pkl.h"
 #include <libxml++/libxml++.h>
 #include <boost/algorithm/string.hpp>
 
 using std::string;
 using boost::function;
+using std::shared_ptr;
 using boost::optional;
 using namespace dcp;
 
@@ -76,13 +78,13 @@ Asset::Asset (string id, boost::filesystem::path file)
 }
 
 void
-Asset::write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard standard) const
+Asset::add_to_pkl (shared_ptr<PKL> pkl, boost::filesystem::path root) const
 {
-       DCP_ASSERT (!_file.empty ());
+       DCP_ASSERT (_file);
 
        optional<boost::filesystem::path> path = relative_to_root (
                boost::filesystem::canonical (root),
-               boost::filesystem::canonical (_file)
+               boost::filesystem::canonical (_file.get())
                );
 
        if (!path) {
@@ -92,22 +94,22 @@ Asset::write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard s
                return;
        }
 
-       xmlpp::Node* asset = node->add_child ("Asset");
-       asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
-       asset->add_child("AnnotationText")->add_child_text (_id);
-       asset->add_child("Hash")->add_child_text (hash ());
-       asset->add_child("Size")->add_child_text (raw_convert<string> (boost::filesystem::file_size (_file)));
-       asset->add_child("Type")->add_child_text (pkl_type (standard));
+       pkl->add_asset (_id, _id, hash(), boost::filesystem::file_size (_file.get()), pkl_type (pkl->standard()));
 }
 
 void
 Asset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const
 {
-       DCP_ASSERT (!_file.empty ());
+       DCP_ASSERT (_file);
+       write_file_to_assetmap (node, root, _file.get(), _id);
+}
 
+void
+Asset::write_file_to_assetmap (xmlpp::Node* node, boost::filesystem::path root, boost::filesystem::path file, string id)
+{
        optional<boost::filesystem::path> path = relative_to_root (
                boost::filesystem::canonical (root),
-               boost::filesystem::canonical (_file)
+               boost::filesystem::canonical (file)
                );
 
        if (!path) {
@@ -118,30 +120,30 @@ Asset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const
        }
 
        xmlpp::Node* asset = node->add_child ("Asset");
-       asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
+       asset->add_child("Id")->add_child_text ("urn:uuid:" + id);
        xmlpp::Node* chunk_list = asset->add_child ("ChunkList");
        xmlpp::Node* chunk = chunk_list->add_child ("Chunk");
 
        chunk->add_child("Path")->add_child_text (path.get().generic_string());
        chunk->add_child("VolumeIndex")->add_child_text ("1");
        chunk->add_child("Offset")->add_child_text ("0");
-       chunk->add_child("Length")->add_child_text (raw_convert<string> (boost::filesystem::file_size (_file)));
+       chunk->add_child("Length")->add_child_text (raw_convert<string> (boost::filesystem::file_size (file)));
 }
 
 string
 Asset::hash (function<void (float)> progress) const
 {
-       DCP_ASSERT (!_file.empty ());
+       DCP_ASSERT (_file);
 
        if (!_hash) {
-               _hash = make_digest (_file, progress);
+               _hash = make_digest (_file.get(), progress);
        }
 
        return _hash.get();
 }
 
 bool
-Asset::equals (boost::shared_ptr<const Asset> other, EqualityOptions, NoteHandler note) const
+Asset::equals (std::shared_ptr<const Asset> other, EqualityOptions, NoteHandler note) const
 {
        if (_hash != other->_hash) {
                note (DCP_ERROR, "Asset: hashes differ");