summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-08-29 14:24:09 +0100
committerCarl Hetherington <cth@carlh.net>2013-08-29 14:24:09 +0100
commite3f4b24468b39701030025f83f18d85c5c4e0844 (patch)
tree509e98315491593aab707e127ed26b65d59681be /src
parentd697e7bedb1e42f5167c92fd9ab363f496d718f5 (diff)
Optional progress reporting when making MXF hashes.
Diffstat (limited to 'src')
-rw-r--r--src/asset.cc12
-rw-r--r--src/asset.h8
-rw-r--r--src/cpl.cc2
-rw-r--r--src/util.cc17
-rw-r--r--src/util.h3
5 files changed, 36 insertions, 6 deletions
diff --git a/src/asset.cc b/src/asset.cc
index fb21580e..06b87953 100644
--- a/src/asset.cc
+++ b/src/asset.cc
@@ -88,12 +88,22 @@ string
Asset::digest () const
{
if (_digest.empty ()) {
- _digest = make_digest (path().string());
+ _digest = make_digest (path().string(), 0);
}
return _digest;
}
+void
+Asset::compute_digest (boost::function<void (float)> progress)
+{
+ if (!_digest.empty ()) {
+ return;
+ }
+
+ _digest = make_digest (path().string(), &progress);
+}
+
bool
Asset::equals (shared_ptr<const Asset> other, EqualityOptions, boost::function<void (NoteType, string)> note) const
{
diff --git a/src/asset.h b/src/asset.h
index 44d088a3..c6ff7e83 100644
--- a/src/asset.h
+++ b/src/asset.h
@@ -73,6 +73,14 @@ public:
*/
void write_to_assetmap (xmlpp::Node *) const;
+ /** Compute the digest for this asset. Calling this is optional: if
+ * it is not called, the digest will be computed when required. However,
+ * calling this method allows the caller to see the progress of the
+ * computation, which can be long for large assets.
+ * @param Called with progress between 0 and 1.
+ */
+ void compute_digest (boost::function<void (float)> progress);
+
std::string uuid () const {
return _uuid;
}
diff --git a/src/cpl.cc b/src/cpl.cc
index e4f36fed..561cc989 100644
--- a/src/cpl.cc
+++ b/src/cpl.cc
@@ -252,7 +252,7 @@ CPL::write_xml (bool interop, XMLMetadata const & metadata, shared_ptr<Encryptio
doc.write_to_file_formatted (p.string (), "UTF-8");
- _digest = make_digest (p.string ());
+ _digest = make_digest (p.string (), 0);
_length = boost::filesystem::file_size (p.string ());
}
diff --git a/src/util.cc b/src/util.cc
index 875693bf..d7b4f980 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -70,10 +70,12 @@ libdcp::make_uuid ()
/** Create a digest for a file.
* @param filename File name.
+ * @param progress Pointer to a progress reporting function, or 0. The function will be called
+ * with a progress value between 0 and 1.
* @return Digest.
*/
string
-libdcp::make_digest (string filename)
+libdcp::make_digest (string filename, boost::function<void (float)>* progress)
{
Kumu::FileReader reader;
if (ASDCP_FAILURE (reader.OpenRead (filename.c_str ()))) {
@@ -82,8 +84,12 @@ libdcp::make_digest (string filename)
SHA_CTX sha;
SHA1_Init (&sha);
-
- Kumu::ByteString read_buffer (65536);
+
+ int const buffer_size = 65536;
+ Kumu::ByteString read_buffer (buffer_size);
+
+ Kumu::fsize_t done = 0;
+ Kumu::fsize_t const size = reader.Size ();
while (1) {
ui32_t read = 0;
Kumu::Result_t r = reader.Read (read_buffer.Data(), read_buffer.Capacity(), &read);
@@ -95,6 +101,11 @@ libdcp::make_digest (string filename)
}
SHA1_Update (&sha, read_buffer.Data(), read);
+
+ if (progress) {
+ (*progress) (float (done) / size);
+ done += read;
+ }
}
byte_t byte_buffer[20];
diff --git a/src/util.h b/src/util.h
index 9153dbda..586d197f 100644
--- a/src/util.h
+++ b/src/util.h
@@ -27,6 +27,7 @@
#include <string>
#include <stdint.h>
#include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
#include <openjpeg.h>
#include "types.h"
@@ -60,7 +61,7 @@ extern bool operator== (Size const & a, Size const & b);
extern bool operator!= (Size const & a, Size const & b);
extern std::string make_uuid ();
-extern std::string make_digest (std::string filename);
+extern std::string make_digest (std::string filename, boost::function<void (float)> *);
extern std::string content_kind_to_string (ContentKind kind);
extern ContentKind content_kind_from_string (std::string kind);
extern bool empty_or_white_space (std::string s);