From: Carl Hetherington Date: Mon, 13 Jun 2016 11:17:47 +0000 (+0100) Subject: Rename MD5Digester -> Digester. X-Git-Tag: v2.8.10~33 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=a306df9145d16046e51e8b7ff5222e341e98fdbd Rename MD5Digester -> Digester. --- diff --git a/src/lib/audio_mapping.cc b/src/lib/audio_mapping.cc index 3a402a11d..b436d7579 100644 --- a/src/lib/audio_mapping.cc +++ b/src/lib/audio_mapping.cc @@ -20,7 +20,7 @@ #include "audio_mapping.h" #include "util.h" -#include "md5_digester.h" +#include "digester.h" #include "raw_convert.h" #include #include @@ -147,7 +147,7 @@ AudioMapping::as_xml (xmlpp::Node* node) 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) { diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc index eb114e7a4..f17964ddc 100644 --- a/src/lib/colour_conversion.cc +++ b/src/lib/colour_conversion.cc @@ -21,7 +21,7 @@ #include "config.h" #include "colour_conversion.h" #include "util.h" -#include "md5_digester.h" +#include "digester.h" #include "raw_convert.h" #include #include @@ -187,7 +187,7 @@ ColourConversion::preset () const string ColourConversion::identifier () const { - MD5Digester digester; + Digester digester; if (dynamic_pointer_cast (_in)) { shared_ptr tf = dynamic_pointer_cast (_in); diff --git a/src/lib/content.cc b/src/lib/content.cc index b8e7f8ad2..b64e68c4b 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -161,10 +161,10 @@ Content::examine (shared_ptr job) 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. */ - string const d = md5_digest_head_tail (p, 1000000) + raw_convert (boost::filesystem::file_size (p.front ())); + string const d = digest_head_tail (p, 1000000) + raw_convert (boost::filesystem::file_size (p.front ())); lm.lock (); _digest = d; diff --git a/src/lib/digester.cc b/src/lib/digester.cc new file mode 100644 index 000000000..2d25d41d1 --- /dev/null +++ b/src/lib/digester.cc @@ -0,0 +1,69 @@ +/* + Copyright (C) 2014-2016 Carl Hetherington + + 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 . + +*/ + +#include +#include +#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 index 000000000..92eb5faa3 --- /dev/null +++ b/src/lib/digester.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2014-2016 Carl Hetherington + + 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 . + +*/ + +#include +#include +#include +#include + +class Digester : public boost::noncopyable +{ +public: + Digester (); + ~Digester (); + + void add (void const * data, size_t size); + + template + 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 _digest; +}; diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index 490189c12..342b9a999 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -27,7 +27,7 @@ #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 @@ -269,7 +269,7 @@ FFmpeg::subtitle_period (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]; diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 28c638998..df6b7416b 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -37,7 +37,6 @@ #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" diff --git a/src/lib/film.cc b/src/lib/film.cc index c8dfdfe63..db8da56b4 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -42,7 +42,7 @@ #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" @@ -247,7 +247,7 @@ Film::audio_analysis_path (shared_ptr playlist) const { boost::filesystem::path p = dir ("analysis"); - MD5Digester digester; + Digester digester; BOOST_FOREACH (shared_ptr i, playlist->content ()) { if (!i->audio) { continue; diff --git a/src/lib/image.cc b/src/lib/image.cc index 2a413c83e..71a3a5bcc 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -27,7 +27,6 @@ #include "timer.h" #include "rect.h" #include "util.h" -#include "md5_digester.h" #include "dcpomatic_socket.h" extern "C" { #include diff --git a/src/lib/md5_digester.cc b/src/lib/md5_digester.cc deleted file mode 100644 index e265d18eb..000000000 --- a/src/lib/md5_digester.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright (C) 2014 Carl Hetherington - - 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 . - -*/ - -#include -#include -#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 index 98b4d3b99..000000000 --- a/src/lib/md5_digester.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (C) 2014 Carl Hetherington - - 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 . - -*/ - -#include -#include -#include -#include - -class MD5Digester : public boost::noncopyable -{ -public: - MD5Digester (); - ~MD5Digester (); - - void add (void const * data, size_t size); - - template - 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 _digest; -}; diff --git a/src/lib/playlist.cc b/src/lib/playlist.cc index ab78fe0c4..739c5a20b 100644 --- a/src/lib/playlist.cc +++ b/src/lib/playlist.cc @@ -29,7 +29,7 @@ #include "job.h" #include "config.h" #include "util.h" -#include "md5_digester.h" +#include "digester.h" #include #include #include @@ -154,7 +154,7 @@ Playlist::video_identifier () const } } - MD5Digester digester; + Digester digester; digester.add (t.c_str(), t.length()); return digester.get (); } diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index bc0013ff1..e6533d2cc 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -23,7 +23,7 @@ #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" @@ -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 { - 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) { diff --git a/src/lib/util.cc b/src/lib/util.cc index 784aacf4e..92b3b22fd 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -33,7 +33,7 @@ #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" @@ -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 -md5_digest_head_tail (vector files, boost::uintmax_t size) +digest_head_tail (vector files, boost::uintmax_t size) { boost::scoped_array buffer (new char[size]); - MD5Digester digester; + Digester digester; /* Head */ boost::uintmax_t to_do = size; diff --git a/src/lib/util.h b/src/lib/util.h index f6306c971..c94d0fc9f 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -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 std::string md5_digest_head_tail (std::vector, boost::uintmax_t size); +extern std::string digest_head_tail (std::vector, boost::uintmax_t size); 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 4a99b0793..efd43a25b 100644 --- a/src/lib/writer.cc +++ b/src/lib/writer.cc @@ -30,7 +30,6 @@ #include "job.h" #include "cross.h" #include "audio_buffers.h" -#include "md5_digester.h" #include "version.h" #include "font.h" #include "util.h" diff --git a/src/lib/wscript b/src/lib/wscript index 658abb987..fcbccf2b7 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -56,6 +56,7 @@ sources = """ dcpomatic_socket.cc dcpomatic_time.cc decoder_factory.cc + digester.cc dolby_cp750.cc emailer.cc encoder.cc @@ -95,7 +96,6 @@ sources = """ log.cc log_entry.cc magick_image_proxy.cc - md5_digester.cc mid_side_decoder.cc overlaps.cc player.cc diff --git a/test/data b/test/data index 6d7ca26d1..e0f35822b 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit 6d7ca26d1c1d7daa4e48b6fdc7ff6ff31911c4a4 +Subproject commit e0f35822bc59088e8107f2024ca7068d11f97b11 diff --git a/test/util_test.cc b/test/util_test.cc index 7f296659e..0cbb5acd3 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -31,25 +31,25 @@ using std::string; using std::vector; using boost::shared_ptr; -BOOST_AUTO_TEST_CASE (md5_digest_test) +BOOST_AUTO_TEST_CASE (digest_test) { vector 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.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"); - 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 */