Rename MD5Digester -> Digester.
authorCarl Hetherington <cth@carlh.net>
Mon, 13 Jun 2016 11:17:47 +0000 (12:17 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 13 Jun 2016 11:17:47 +0000 (12:17 +0100)
19 files changed:
src/lib/audio_mapping.cc
src/lib/colour_conversion.cc
src/lib/content.cc
src/lib/digester.cc [new file with mode: 0644]
src/lib/digester.h [new file with mode: 0644]
src/lib/ffmpeg.cc
src/lib/ffmpeg_decoder.cc
src/lib/film.cc
src/lib/image.cc
src/lib/md5_digester.cc [deleted file]
src/lib/md5_digester.h [deleted file]
src/lib/playlist.cc
src/lib/reel_writer.cc
src/lib/util.cc
src/lib/util.h
src/lib/writer.cc
src/lib/wscript
test/data
test/util_test.cc

index 3a402a11de507a3815b5fba438b2b7196ec9045a..b436d757988a3e054657d627b6d9258fde308380 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "audio_mapping.h"
 #include "util.h"
 
 #include "audio_mapping.h"
 #include "util.h"
-#include "md5_digester.h"
+#include "digester.h"
 #include "raw_convert.h"
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
 #include "raw_convert.h"
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
@@ -147,7 +147,7 @@ AudioMapping::as_xml (xmlpp::Node* node) const
 string
 AudioMapping::digest () const
 {
 string
 AudioMapping::digest () const
 {
-       MD5Digester digester;
+       Digester digester;
        digester.add (_input_channels);
        digester.add (_output_channels);
        for (int i = 0; i < _input_channels; ++i) {
        digester.add (_input_channels);
        digester.add (_output_channels);
        for (int i = 0; i < _input_channels; ++i) {
index eb114e7a4cd5d3b2a410380738ebc4bf93622eae..f17964ddccb0521cdcf9df31aa45832503ec2d9b 100644 (file)
@@ -21,7 +21,7 @@
 #include "config.h"
 #include "colour_conversion.h"
 #include "util.h"
 #include "config.h"
 #include "colour_conversion.h"
 #include "util.h"
-#include "md5_digester.h"
+#include "digester.h"
 #include "raw_convert.h"
 #include <dcp/chromaticity.h>
 #include <dcp/colour_matrix.h>
 #include "raw_convert.h"
 #include <dcp/chromaticity.h>
 #include <dcp/colour_matrix.h>
@@ -187,7 +187,7 @@ ColourConversion::preset () const
 string
 ColourConversion::identifier () const
 {
 string
 ColourConversion::identifier () const
 {
-       MD5Digester digester;
+       Digester digester;
 
        if (dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in)) {
                shared_ptr<const dcp::GammaTransferFunction> tf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in);
 
        if (dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in)) {
                shared_ptr<const dcp::GammaTransferFunction> tf = dynamic_pointer_cast<const dcp::GammaTransferFunction> (_in);
index b8e7f8ad2910623e8736334b46ad98b8845a61e2..b64e68c4b1739e0dec621877349971815ff93f49 100644 (file)
@@ -161,10 +161,10 @@ Content::examine (shared_ptr<Job> job)
        lm.unlock ();
 
        /* Some content files are very big, so we use a poor man's
        lm.unlock ();
 
        /* Some content files are very big, so we use a poor man's
-          digest here: a MD5 of the first and last 1e6 bytes with the
+          digest here: a digest of the first and last 1e6 bytes with the
           size of the first file tacked on the end as a string.
        */
           size of the first file tacked on the end as a string.
        */
-       string const d = md5_digest_head_tail (p, 1000000) + raw_convert<string> (boost::filesystem::file_size (p.front ()));
+       string const d = digest_head_tail (p, 1000000) + raw_convert<string> (boost::filesystem::file_size (p.front ()));
 
        lm.lock ();
        _digest = d;
 
        lm.lock ();
        _digest = d;
diff --git a/src/lib/digester.cc b/src/lib/digester.cc
new file mode 100644 (file)
index 0000000..2d25d41
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+    Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <iomanip>
+#include <openssl/md5.h>
+#include "digester.h"
+#include "safe_stringstream.h"
+
+using std::string;
+using std::hex;
+using std::setfill;
+using std::setw;
+
+Digester::Digester ()
+{
+       MD5_Init (&_context);
+}
+
+Digester::~Digester ()
+{
+       get ();
+}
+
+void
+Digester::add (void const * data, size_t size)
+{
+       MD5_Update (&_context, data, size);
+}
+
+void
+Digester::add (string const & s)
+{
+       add (s.c_str (), s.length ());
+}
+
+string
+Digester::get () const
+{
+       if (!_digest) {
+               unsigned char digest[MD5_DIGEST_LENGTH];
+               MD5_Final (digest, &_context);
+
+               SafeStringStream 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/digester.h b/src/lib/digester.h
new file mode 100644 (file)
index 0000000..92eb5fa
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+    Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic 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.
+
+    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <openssl/md5.h>
+#include <boost/noncopyable.hpp>
+#include <boost/optional.hpp>
+#include <string>
+
+class Digester : public boost::noncopyable
+{
+public:
+       Digester ();
+       ~Digester ();
+
+       void add (void const * data, size_t size);
+
+       template <class T>
+       void add (T data) {
+               add (&data, sizeof (T));
+       }
+
+       void add (std::string const & s);
+
+       std::string get () const;
+
+private:
+       mutable MD5_CTX _context;
+       mutable boost::optional<std::string> _digest;
+};
index 490189c128fbf512c54c1ba1312aa528c3c0f0bd..342b9a9990438ba39e383c710c9dd3bac7d36cb4 100644 (file)
@@ -27,7 +27,7 @@
 #include "log.h"
 #include "ffmpeg_subtitle_stream.h"
 #include "ffmpeg_audio_stream.h"
 #include "log.h"
 #include "ffmpeg_subtitle_stream.h"
 #include "ffmpeg_audio_stream.h"
-#include "md5_digester.h"
+#include "digester.h"
 #include "compose.hpp"
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include "compose.hpp"
 extern "C" {
 #include <libavcodec/avcodec.h>
@@ -269,7 +269,7 @@ FFmpeg::subtitle_period (AVSubtitle const & sub)
 string
 FFmpeg::subtitle_id (AVSubtitle const & sub)
 {
 string
 FFmpeg::subtitle_id (AVSubtitle const & sub)
 {
-       MD5Digester digester;
+       Digester digester;
        digester.add (sub.pts);
        for (unsigned int i = 0; i < sub.num_rects; ++i) {
                AVSubtitleRect* rect = sub.rects[i];
        digester.add (sub.pts);
        for (unsigned int i = 0; i < sub.num_rects; ++i) {
                AVSubtitleRect* rect = sub.rects[i];
index 28c638998de6a850b2478b9346434de7efe537f7..df6b7416b35a2fc521846ed91ec490e6faaef45d 100644 (file)
@@ -37,7 +37,6 @@
 #include "raw_image_proxy.h"
 #include "video_decoder.h"
 #include "film.h"
 #include "raw_image_proxy.h"
 #include "video_decoder.h"
 #include "film.h"
-#include "md5_digester.h"
 #include "audio_decoder.h"
 #include "compose.hpp"
 #include "subtitle_content.h"
 #include "audio_decoder.h"
 #include "compose.hpp"
 #include "subtitle_content.h"
index c8dfdfe63b6d87d46fd7a602713b66f04ed01c32..db8da56b49e3ec748f54caf8ee49dd8ebc5269b3 100644 (file)
@@ -42,7 +42,7 @@
 #include "environment_info.h"
 #include "raw_convert.h"
 #include "audio_processor.h"
 #include "environment_info.h"
 #include "raw_convert.h"
 #include "audio_processor.h"
-#include "md5_digester.h"
+#include "digester.h"
 #include "compose.hpp"
 #include "screen.h"
 #include "audio_content.h"
 #include "compose.hpp"
 #include "screen.h"
 #include "audio_content.h"
@@ -247,7 +247,7 @@ Film::audio_analysis_path (shared_ptr<const Playlist> playlist) const
 {
        boost::filesystem::path p = dir ("analysis");
 
 {
        boost::filesystem::path p = dir ("analysis");
 
-       MD5Digester digester;
+       Digester digester;
        BOOST_FOREACH (shared_ptr<Content> i, playlist->content ()) {
                if (!i->audio) {
                        continue;
        BOOST_FOREACH (shared_ptr<Content> i, playlist->content ()) {
                if (!i->audio) {
                        continue;
index 2a413c83efa118375d73ff179e33e67e549115c5..71a3a5bccd9b174b5ffea94f7eecbac250265952 100644 (file)
@@ -27,7 +27,6 @@
 #include "timer.h"
 #include "rect.h"
 #include "util.h"
 #include "timer.h"
 #include "rect.h"
 #include "util.h"
-#include "md5_digester.h"
 #include "dcpomatic_socket.h"
 extern "C" {
 #include <libswscale/swscale.h>
 #include "dcpomatic_socket.h"
 extern "C" {
 #include <libswscale/swscale.h>
diff --git a/src/lib/md5_digester.cc b/src/lib/md5_digester.cc
deleted file mode 100644 (file)
index e265d18..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
-
-    This file is part of DCP-o-matic.
-
-    DCP-o-matic 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.
-
-    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include <iomanip>
-#include <openssl/md5.h>
-#include "md5_digester.h"
-#include "safe_stringstream.h"
-
-using std::string;
-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);
-}
-
-void
-MD5Digester::add (string const & s)
-{
-       add (s.c_str (), s.length ());
-}
-
-string
-MD5Digester::get () const
-{
-       if (!_digest) {
-               unsigned char digest[MD5_DIGEST_LENGTH];
-               MD5_Final (digest, &_context);
-
-               SafeStringStream 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
deleted file mode 100644 (file)
index 98b4d3b..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
-
-    This file is part of DCP-o-matic.
-
-    DCP-o-matic 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.
-
-    DCP-o-matic 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 DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include <openssl/md5.h>
-#include <boost/noncopyable.hpp>
-#include <boost/optional.hpp>
-#include <string>
-
-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));
-       }
-
-       void add (std::string const & s);
-
-       std::string get () const;
-
-private:
-       mutable MD5_CTX _context;
-       mutable boost::optional<std::string> _digest;
-};
index ab78fe0c463f0a2a662129757b61adac8b7ad5a5..739c5a20b3d0317f506786ce8dbc4fd544a91bab 100644 (file)
@@ -29,7 +29,7 @@
 #include "job.h"
 #include "config.h"
 #include "util.h"
 #include "job.h"
 #include "config.h"
 #include "util.h"
-#include "md5_digester.h"
+#include "digester.h"
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
 #include <boost/shared_ptr.hpp>
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
 #include <boost/shared_ptr.hpp>
@@ -154,7 +154,7 @@ Playlist::video_identifier () const
                }
        }
 
                }
        }
 
-       MD5Digester digester;
+       Digester digester;
        digester.add (t.c_str(), t.length());
        return digester.get ();
 }
        digester.add (t.c_str(), t.length());
        return digester.get ();
 }
index bc0013ff130ec7230f324f80563114f7f131f8f5..e6533d2cc292ca0e9c49f8da78a41f0604b5a276 100644 (file)
@@ -23,7 +23,7 @@
 #include "cross.h"
 #include "job.h"
 #include "log.h"
 #include "cross.h"
 #include "job.h"
 #include "log.h"
-#include "md5_digester.h"
+#include "digester.h"
 #include "font.h"
 #include "compose.hpp"
 #include "audio_buffers.h"
 #include "font.h"
 #include "compose.hpp"
 #include "audio_buffers.h"
@@ -505,7 +505,7 @@ ReelWriter::existing_picture_frame_ok (FILE* asset_file, FILE* info_file) const
                LOG_GENERAL ("Existing frame %1 is incomplete", _first_nonexistant_frame);
                ok = false;
        } else {
                LOG_GENERAL ("Existing frame %1 is incomplete", _first_nonexistant_frame);
                ok = false;
        } else {
-               MD5Digester digester;
+               Digester digester;
                digester.add (data.data().get(), data.size());
                LOG_GENERAL ("Hash %1 vs %2", digester.get(), info.hash);
                if (digester.get() != info.hash) {
                digester.add (data.data().get(), data.size());
                LOG_GENERAL ("Hash %1 vs %2", digester.get(), info.hash);
                if (digester.get() != info.hash) {
index 784aacf4e0232ee01555bfa6f9163c94217be7cb..92b3b22fd1cd72096e96d5dece3e23bea23d20b5 100644 (file)
@@ -33,7 +33,7 @@
 #include "cross.h"
 #include "video_content.h"
 #include "rect.h"
 #include "cross.h"
 #include "video_content.h"
 #include "rect.h"
-#include "md5_digester.h"
+#include "digester.h"
 #include "audio_processor.h"
 #include "safe_stringstream.h"
 #include "compose.hpp"
 #include "audio_processor.h"
 #include "safe_stringstream.h"
 #include "compose.hpp"
@@ -405,10 +405,10 @@ dcpomatic_setup_gettext_i18n (string lang)
 
 /** Compute a digest of the first and last `size' bytes of a set of files. */
 string
 
 /** Compute a digest of the first and last `size' bytes of a set of files. */
 string
-md5_digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
+digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
 {
        boost::scoped_array<char> buffer (new char[size]);
 {
        boost::scoped_array<char> buffer (new char[size]);
-       MD5Digester digester;
+       Digester digester;
 
        /* Head */
        boost::uintmax_t to_do = size;
 
        /* Head */
        boost::uintmax_t to_do = size;
index f6306c9712528fb04b0e6f3b8f019048b6ef5ba5..c94d0fc9f4a97e3cda6cf47e9827e76ea9d05b0a 100644 (file)
@@ -60,7 +60,7 @@ extern double seconds (struct timeval);
 extern void dcpomatic_setup ();
 extern void dcpomatic_setup_path_encoding ();
 extern void dcpomatic_setup_gettext_i18n (std::string);
 extern void dcpomatic_setup ();
 extern void dcpomatic_setup_path_encoding ();
 extern void dcpomatic_setup_gettext_i18n (std::string);
-extern std::string md5_digest_head_tail (std::vector<boost::filesystem::path>, boost::uintmax_t size);
+extern std::string digest_head_tail (std::vector<boost::filesystem::path>, boost::uintmax_t size);
 extern void ensure_ui_thread ();
 extern std::string audio_channel_name (int);
 extern bool valid_image_file (boost::filesystem::path);
 extern void ensure_ui_thread ();
 extern std::string audio_channel_name (int);
 extern bool valid_image_file (boost::filesystem::path);
index 4a99b079306f6c226ce3cc1b886852ded75e7e95..efd43a25b8e52971a5baf421889d9d96bfc18626 100644 (file)
@@ -30,7 +30,6 @@
 #include "job.h"
 #include "cross.h"
 #include "audio_buffers.h"
 #include "job.h"
 #include "cross.h"
 #include "audio_buffers.h"
-#include "md5_digester.h"
 #include "version.h"
 #include "font.h"
 #include "util.h"
 #include "version.h"
 #include "font.h"
 #include "util.h"
index 658abb98715a67609eb66f232e6aadc86833015f..fcbccf2b7cbbe59c7c5fbc0785533722e29d965c 100644 (file)
@@ -56,6 +56,7 @@ sources = """
           dcpomatic_socket.cc
           dcpomatic_time.cc
           decoder_factory.cc
           dcpomatic_socket.cc
           dcpomatic_time.cc
           decoder_factory.cc
+          digester.cc
           dolby_cp750.cc
           emailer.cc
           encoder.cc
           dolby_cp750.cc
           emailer.cc
           encoder.cc
@@ -95,7 +96,6 @@ sources = """
           log.cc
           log_entry.cc
           magick_image_proxy.cc
           log.cc
           log_entry.cc
           magick_image_proxy.cc
-          md5_digester.cc
           mid_side_decoder.cc
           overlaps.cc
           player.cc
           mid_side_decoder.cc
           overlaps.cc
           player.cc
index 6d7ca26d1c1d7daa4e48b6fdc7ff6ff31911c4a4..e0f35822bc59088e8107f2024ca7068d11f97b11 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 6d7ca26d1c1d7daa4e48b6fdc7ff6ff31911c4a4
+Subproject commit e0f35822bc59088e8107f2024ca7068d11f97b11
index 7f296659e97c15b62308154bc2c58cbdef440632..0cbb5acd36ad8d9d535ae4f38bf4b07080ce48f0 100644 (file)
@@ -31,25 +31,25 @@ using std::string;
 using std::vector;
 using boost::shared_ptr;
 
 using std::vector;
 using boost::shared_ptr;
 
-BOOST_AUTO_TEST_CASE (md5_digest_test)
+BOOST_AUTO_TEST_CASE (digest_test)
 {
        vector<boost::filesystem::path> p;
 {
        vector<boost::filesystem::path> p;
-       p.push_back ("test/data/md5.test");
-       BOOST_CHECK_EQUAL (md5_digest_head_tail (p, 1024), "57497ef84a0487f2bb0939a1f5703912");
+       p.push_back ("test/data/digest.test");
+       BOOST_CHECK_EQUAL (digest_head_tail (p, 1024), "57497ef84a0487f2bb0939a1f5703912");
 
 
-       p.push_back ("test/data/md5.test2");
-       BOOST_CHECK_EQUAL (md5_digest_head_tail (p, 1024), "5a3a89857b931755ae728a518224a05c");
+       p.push_back ("test/data/digest.test2");
+       BOOST_CHECK_EQUAL (digest_head_tail (p, 1024), "5a3a89857b931755ae728a518224a05c");
 
        p.clear ();
 
        p.clear ();
-       p.push_back ("test/data/md5.test3");
-       p.push_back ("test/data/md5.test");
-       p.push_back ("test/data/md5.test2");
-       p.push_back ("test/data/md5.test4");
-       BOOST_CHECK_EQUAL (md5_digest_head_tail (p, 1024), "52ccf111e4e72b58bb7b2aaa6bd45ea5");
+       p.push_back ("test/data/digest.test3");
+       p.push_back ("test/data/digest.test");
+       p.push_back ("test/data/digest.test2");
+       p.push_back ("test/data/digest.test4");
+       BOOST_CHECK_EQUAL (digest_head_tail (p, 1024), "52ccf111e4e72b58bb7b2aaa6bd45ea5");
 
        p.clear ();
        p.push_back ("foobar");
 
        p.clear ();
        p.push_back ("foobar");
-       BOOST_CHECK_THROW (md5_digest_head_tail (p, 1024), OpenFileError);
+       BOOST_CHECK_THROW (digest_head_tail (p, 1024), OpenFileError);
 }
 
 /* Straightforward test of DCPTime::round_up */
 }
 
 /* Straightforward test of DCPTime::round_up */