summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-06-03 14:30:42 +0100
committerCarl Hetherington <cth@carlh.net>2014-06-03 14:30:42 +0100
commitc5b3d91fab31fde4c21e1cc5bb5adb1d6d26fcca (patch)
treea88349c4c4e6e8304d92161529a5ca3dc5271a7b /src/lib
parentfd26b3243015824bebe8ec41c6b4a0d81748e81a (diff)
Include audio mapping in the digest used to distinguish different
audio analyses so that the analyses are re-computed when the mapping changes. Reported-by: Matthias Damm
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_content.cc2
-rw-r--r--src/lib/audio_mapping.cc18
-rw-r--r--src/lib/audio_mapping.h2
-rw-r--r--src/lib/colour_conversion.cc20
-rw-r--r--src/lib/dcp_video_frame.cc16
-rw-r--r--src/lib/image.cc17
-rw-r--r--src/lib/md5_digester.cc63
-rw-r--r--src/lib/md5_digester.h43
-rw-r--r--src/lib/playlist.cc5
-rw-r--r--src/lib/util.cc34
-rw-r--r--src/lib/util.h1
-rw-r--r--src/lib/writer.cc8
-rw-r--r--src/lib/wscript1
13 files changed, 154 insertions, 76 deletions
diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc
index 1896c4d5c..dbca6652c 100644
--- a/src/lib/audio_content.cc
+++ b/src/lib/audio_content.cc
@@ -139,7 +139,7 @@ AudioContent::audio_analysis_path () const
}
boost::filesystem::path p = film->audio_analysis_dir ();
- p /= digest ();
+ p /= digest() + "_" + audio_mapping().digest();
return p;
}
diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc
index b1810c973..e35c1ae94 100644
--- a/src/lib/audio_mapping.cc
+++ b/src/lib/audio_mapping.cc
@@ -22,6 +22,7 @@
#include <libdcp/raw_convert.h>
#include "audio_mapping.h"
#include "util.h"
+#include "md5_digester.h"
using std::list;
using std::cout;
@@ -126,3 +127,20 @@ AudioMapping::as_xml (xmlpp::Node* node) const
}
}
}
+
+/** @return a string which is unique for a given AudioMapping configuration, for
+ * differentiation between different AudioMappings.
+ */
+string
+AudioMapping::digest () const
+{
+ MD5Digester digester;
+ digester.add (_content_channels);
+ for (int i = 0; i < _content_channels; ++i) {
+ for (int j = 0; j < MAX_DCP_AUDIO_CHANNELS; ++j) {
+ digester.add (_gain[i][j]);
+ }
+ }
+
+ return digester.get ();
+}
diff --git a/src/lib/audio_mapping.h b/src/lib/audio_mapping.h
index 26087bfff..b0b75ac06 100644
--- a/src/lib/audio_mapping.h
+++ b/src/lib/audio_mapping.h
@@ -56,6 +56,8 @@ public:
int content_channels () const {
return _content_channels;
}
+
+ std::string digest () const;
private:
void setup (int);
diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc
index 5f17f9184..f8675900e 100644
--- a/src/lib/colour_conversion.cc
+++ b/src/lib/colour_conversion.cc
@@ -24,6 +24,7 @@
#include "config.h"
#include "colour_conversion.h"
#include "util.h"
+#include "md5_digester.h"
#include "i18n.h"
@@ -121,21 +122,18 @@ ColourConversion::preset () const
string
ColourConversion::identifier () const
{
- double numbers[12];
-
- int n = 0;
- numbers[n++] = input_gamma;
- numbers[n++] = input_gamma_linearised;
+ MD5Digester digester;
+
+ digester.add (input_gamma);
+ digester.add (input_gamma_linearised);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
- numbers[n++] = matrix (i, j);
+ digester.add (matrix (i, j));
}
}
- numbers[n++] = output_gamma;
-
- assert (n == 12);
-
- return md5_digest (numbers, 12 * sizeof (double));
+ digester.add (output_gamma);
+
+ return digester.get ();
}
PresetColourConversion::PresetColourConversion ()
diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc
index 6cf987648..09b909696 100644
--- a/src/lib/dcp_video_frame.cc
+++ b/src/lib/dcp_video_frame.cc
@@ -42,7 +42,6 @@
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/filesystem.hpp>
-#include <openssl/md5.h>
#include <libdcp/rec709_linearised_gamma_lut.h>
#include <libdcp/srgb_linearised_gamma_lut.h>
#include <libdcp/gamma_lut.h>
@@ -134,21 +133,6 @@ DCPVideoFrame::encode_locally ()
matrix
);
- {
- MD5_CTX md5_context;
- MD5_Init (&md5_context);
- MD5_Update (&md5_context, xyz->data(0), 1998 * 1080 * 4);
- MD5_Update (&md5_context, xyz->data(1), 1998 * 1080 * 4);
- MD5_Update (&md5_context, xyz->data(2), 1998 * 1080 * 4);
- unsigned char digest[MD5_DIGEST_LENGTH];
- MD5_Final (digest, &md5_context);
-
- stringstream s;
- for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
- s << std::hex << std::setfill('0') << std::setw(2) << ((int) digest[i]);
- }
- }
-
/* Set the max image and component sizes based on frame_rate */
int max_cs_len = ((float) _j2k_bandwidth) / 8 / _frames_per_second;
if (_frame->eyes() == EYES_LEFT || _frame->eyes() == EYES_RIGHT) {
diff --git a/src/lib/image.cc b/src/lib/image.cc
index e8622eba4..8a8fb1c7b 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -22,7 +22,6 @@
*/
#include <iostream>
-#include <openssl/md5.h>
extern "C" {
#include <libswscale/swscale.h>
#include <libavutil/pixfmt.h>
@@ -31,6 +30,7 @@ extern "C" {
#include "image.h"
#include "exceptions.h"
#include "scaler.h"
+#include "md5_digester.h"
#include "i18n.h"
@@ -629,21 +629,12 @@ Image::aligned () const
string
Image::digest () const
{
- MD5_CTX md5_context;
- MD5_Init (&md5_context);
+ MD5Digester digester;
for (int i = 0; i < components(); ++i) {
- MD5_Update (&md5_context, data()[i], line_size()[i]);
- }
-
- unsigned char digest[MD5_DIGEST_LENGTH];
- MD5_Final (digest, &md5_context);
-
- stringstream s;
- for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
- s << std::hex << std::setfill('0') << std::setw(2) << ((int) digest[i]);
+ digester.add (data()[i], line_size()[i]);
}
- return s.str ();
+ return digester.get ();
}
diff --git a/src/lib/md5_digester.cc b/src/lib/md5_digester.cc
new file mode 100644
index 000000000..1244209bd
--- /dev/null
+++ b/src/lib/md5_digester.cc
@@ -0,0 +1,63 @@
+/*
+ Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <iomanip>
+#include <sstream>
+#include <openssl/md5.h>
+#include "md5_digester.h"
+
+using std::string;
+using std::stringstream;
+using std::hex;
+using std::setfill;
+using std::setw;
+
+MD5Digester::MD5Digester ()
+{
+ MD5_Init (&_context);
+}
+
+MD5Digester::~MD5Digester ()
+{
+ get ();
+}
+
+void
+MD5Digester::add (void const * data, size_t size)
+{
+ MD5_Update (&_context, data, size);
+}
+
+string
+MD5Digester::get () const
+{
+ if (!_digest) {
+ unsigned char digest[MD5_DIGEST_LENGTH];
+ MD5_Final (digest, &_context);
+
+ stringstream s;
+ for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
+ s << hex << setfill('0') << setw(2) << ((int) digest[i]);
+ }
+
+ _digest = s.str ();
+ }
+
+ return _digest.get ();
+}
diff --git a/src/lib/md5_digester.h b/src/lib/md5_digester.h
new file mode 100644
index 000000000..d5b6a9c4c
--- /dev/null
+++ b/src/lib/md5_digester.h
@@ -0,0 +1,43 @@
+/*
+ Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <string>
+#include <boost/noncopyable.hpp>
+#include <boost/optional.hpp>
+#include <openssl/md5.h>
+
+class MD5Digester : public boost::noncopyable
+{
+public:
+ MD5Digester ();
+ ~MD5Digester ();
+
+ void add (void const * data, size_t size);
+
+ template <class T>
+ void add (T data) {
+ add (&data, sizeof (T));
+ }
+
+ std::string get () const;
+
+private:
+ mutable MD5_CTX _context;
+ mutable boost::optional<std::string> _digest;
+};
diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc
index eb9a49d30..1f00d4d67 100644
--- a/src/lib/playlist.cc
+++ b/src/lib/playlist.cc
@@ -30,6 +30,7 @@
#include "job.h"
#include "config.h"
#include "util.h"
+#include "md5_digester.h"
#include "i18n.h"
@@ -113,7 +114,9 @@ Playlist::video_identifier () const
}
}
- return md5_digest (t.c_str(), t.length());
+ MD5Digester digester;
+ digester.add (t.c_str(), t.length());
+ return digester.get ();
}
/** @param node <Playlist> node */
diff --git a/src/lib/util.cc b/src/lib/util.cc
index a5111b7dc..e81165365 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -44,7 +44,6 @@
#endif
#include <glib.h>
#include <openjpeg.h>
-#include <openssl/md5.h>
#include <magick/MagickCore.h>
#include <magick/version.h>
#include <libdcp/version.h>
@@ -70,6 +69,7 @@ extern "C" {
#include "job.h"
#include "cross.h"
#include "video_content.h"
+#include "md5_digester.h"
#ifdef DCPOMATIC_WINDOWS
#include "stack.hpp"
#endif
@@ -424,23 +424,6 @@ split_at_spaces_considering_quotes (string s)
return out;
}
-string
-md5_digest (void const * data, int size)
-{
- MD5_CTX md5_context;
- MD5_Init (&md5_context);
- MD5_Update (&md5_context, data, size);
- unsigned char digest[MD5_DIGEST_LENGTH];
- MD5_Final (digest, &md5_context);
-
- stringstream s;
- for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
- s << std::hex << std::setfill('0') << std::setw(2) << ((int) digest[i]);
- }
-
- return s.str ();
-}
-
/** @param job Optional job for which to report progress */
string
md5_digest (vector<boost::filesystem::path> files, shared_ptr<Job> job)
@@ -448,8 +431,7 @@ md5_digest (vector<boost::filesystem::path> files, shared_ptr<Job> job)
boost::uintmax_t const buffer_size = 64 * 1024;
char buffer[buffer_size];
- MD5_CTX md5_context;
- MD5_Init (&md5_context);
+ MD5Digester digester;
vector<int64_t> sizes;
for (size_t i = 0; i < files.size(); ++i) {
@@ -468,7 +450,7 @@ md5_digest (vector<boost::filesystem::path> files, shared_ptr<Job> job)
while (remaining > 0) {
int const t = min (remaining, buffer_size);
fread (buffer, 1, t, f);
- MD5_Update (&md5_context, buffer, t);
+ digester.add (buffer, t);
remaining -= t;
if (job) {
@@ -479,15 +461,7 @@ md5_digest (vector<boost::filesystem::path> files, shared_ptr<Job> job)
fclose (f);
}
- unsigned char digest[MD5_DIGEST_LENGTH];
- MD5_Final (digest, &md5_context);
-
- stringstream s;
- for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
- s << std::hex << std::setfill('0') << std::setw(2) << ((int) digest[i]);
- }
-
- return s.str ();
+ return digester.get ();
}
static bool
diff --git a/src/lib/util.h b/src/lib/util.h
index 5ca9f74c8..5d93456df 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -62,7 +62,6 @@ extern void dcpomatic_setup ();
extern void dcpomatic_setup_gettext_i18n (std::string);
extern std::vector<std::string> split_at_spaces_considering_quotes (std::string);
extern std::string md5_digest (std::vector<boost::filesystem::path>, boost::shared_ptr<Job>);
-extern std::string md5_digest (void const *, int);
extern void ensure_ui_thread ();
extern std::string audio_channel_name (int);
extern bool valid_image_file (boost::filesystem::path);
diff --git a/src/lib/writer.cc b/src/lib/writer.cc
index b175843ed..2ed55a276 100644
--- a/src/lib/writer.cc
+++ b/src/lib/writer.cc
@@ -37,6 +37,7 @@
#include "config.h"
#include "job.h"
#include "cross.h"
+#include "md5_digester.h"
#include "i18n.h"
@@ -524,9 +525,10 @@ Writer::check_existing_picture_mxf_frame (FILE* mxf, int f, Eyes eyes)
LOG_GENERAL ("Existing frame %1 is incomplete", f);
return false;
}
-
- string const existing_hash = md5_digest (data.data(), data.size());
- if (existing_hash != info.hash) {
+
+ MD5Digester digester;
+ digester.add (data.data(), data.size());
+ if (digester.get() != info.hash) {
LOG_GENERAL ("Existing frame %1 failed hash check", f);
return false;
}
diff --git a/src/lib/wscript b/src/lib/wscript
index 72e149879..f932a142d 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -41,6 +41,7 @@ sources = """
kdm.cc
json_server.cc
log.cc
+ md5_digester.cc
piece.cc
player.cc
player_video_frame.cc