Various probably quite untidy progress on KDMs.
[libdcp.git] / src / asset.cc
index 2101e4bbf78b63fc22d6b4ee120fbb382e53f540..62fdddf6ef312918e2e3d40ba6e3f42c0dad66e5 100644 (file)
 
 */
 
+/** @file  src/asset.cc
+ *  @brief Parent class for assets of DCPs.
+ */
+
+#include <iostream>
+#include <fstream>
 #include <boost/filesystem.hpp>
-#include <AS_DCP.h>
-#include <KM_util.h>
+#include <boost/lexical_cast.hpp>
+#include <libxml++/nodes/element.h>
+#include "AS_DCP.h"
+#include "KM_util.h"
 #include "asset.h"
 #include "util.h"
-#include "tags.h"
+#include "metadata.h"
 
 using namespace std;
 using namespace boost;
 using namespace libdcp;
 
-/** Construct an Asset.
- *  @param p Pathname of MXF file.
- *  @param fps Frames per second.
- *  @param len Length in frames.
- */
-
-Asset::Asset (string p, int fps, int len)
-       : _mxf_path (p)
-       , _fps (fps)
-       , _length (len)
+Asset::Asset (string directory, string file_name)
+       : _directory (directory)
+       , _file_name (file_name)
        , _uuid (make_uuid ())
 {
-       
+       if (_file_name.empty ()) {
+               _file_name = _uuid + ".xml";
+       }
 }
 
 void
-Asset::write_to_pkl (ostream& s) const
+Asset::write_to_pkl (xmlpp::Element* p) const
 {
-       s << "      <Id>urn:uuid:" << _uuid << "</Id>\n"
-         << "      <AnnotationText>" << filesystem::path(_mxf_path).filename() << "</AnnotationText>\n"
-         << "      <Hash>" << _digest << "</Hash>\n"
-         << "      <Size>" << filesystem::file_size(_mxf_path) << "</Size>\n"
-         << "      <Type>application/mxf</Type>\n";
+       xmlpp::Element* asset = p->add_child("Asset");
+       asset->add_child("Id")->add_child_text("urn:uuid:" + _uuid);
+       asset->add_child("AnnotationText")->add_child_text (_file_name);
+       asset->add_child("Hash")->add_child_text (digest());
+       asset->add_child("Size")->add_child_text (boost::lexical_cast<string> (filesystem::file_size(path())));
+       asset->add_child("Type")->add_child_text ("application/mxf");
 }
 
 void
@@ -60,22 +64,31 @@ Asset::write_to_assetmap (ostream& s) const
          << "      <Id>urn:uuid:" << _uuid << "</Id>\n"
          << "      <ChunkList>\n"
          << "        <Chunk>\n"
-         << "          <Path>" << filesystem::path(_mxf_path).filename() << "</Path>\n"
+         << "          <Path>" << _file_name << "</Path>\n"
          << "          <VolumeIndex>1</VolumeIndex>\n"
          << "          <Offset>0</Offset>\n"
-         << "          <Length>" << filesystem::file_size(_mxf_path) << "</Length>\n"
+         << "          <Length>" << filesystem::file_size(path()) << "</Length>\n"
          << "        </Chunk>\n"
          << "      </ChunkList>\n"
          << "    </Asset>\n";
 }
 
-void
-Asset::fill_writer_info (ASDCP::WriterInfo* writer_info) const
+filesystem::path
+Asset::path () const
 {
-       writer_info->ProductVersion = Tags::instance()->product_version;
-       writer_info->CompanyName = Tags::instance()->company_name;
-       writer_info->ProductName = Tags::instance()->product_name.c_str();
+       filesystem::path p;
+       p /= _directory;
+       p /= _file_name;
+       return p;
+}
+
+string
+Asset::digest () const
+{
+       if (_digest.empty ()) {
+               _digest = make_digest (path().string(), 0);
+       }
 
-       writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
-       Kumu::GenRandomUUID (writer_info->AssetUUID);
+       return _digest;
 }
+