From 3e3fa3f58b9ce62768ca8a977334ae1b5fe7da69 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 12 Sep 2012 10:54:39 +0100 Subject: Allow build using Ubuntu 12.04 repos. --- src/lib/wscript | 1 + 1 file changed, 1 insertion(+) (limited to 'src/lib/wscript') diff --git a/src/lib/wscript b/src/lib/wscript index b001fff2a..71a2b23f4 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -28,6 +28,7 @@ def build(bld): encoder.cc encoder_factory.cc examine_content_job.cc + ffmpeg_compatibility.cc ffmpeg_decoder.cc film.cc film_state.cc -- cgit v1.2.3 From 4fd257106009b2db170dafddece06ee3c190fceb Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 24 Sep 2012 23:49:53 +0100 Subject: Remove long-since disused hash debugging. --- src/lib/dcp_video_frame.cc | 30 ------------------------------ src/lib/dcp_video_frame.h | 4 ---- src/lib/image.cc | 32 +------------------------------- src/lib/image.h | 4 ---- src/lib/server.cc | 8 -------- src/lib/util.cc | 24 +++++++++++------------- src/lib/util.h | 4 +--- src/lib/wscript | 8 ++------ src/tools/servomatictest.cc | 9 --------- wscript | 2 -- 10 files changed, 15 insertions(+), 110 deletions(-) (limited to 'src/lib/wscript') diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc index d8af3462d..96c40358a 100644 --- a/src/lib/dcp_video_frame.cc +++ b/src/lib/dcp_video_frame.cc @@ -55,10 +55,6 @@ #include "image.h" #include "log.h" -#ifdef DEBUG_HASH -#include -#endif - using namespace std; using namespace boost; @@ -255,12 +251,6 @@ DCPVideoFrame::encode_locally () /* Set event manager to null (openjpeg 1.3 bug) */ _cinfo->event_mgr = 0; -#ifdef DEBUG_HASH - md5_data ("J2K in X frame " + lexical_cast (_frame), _image->comps[0].data, size * sizeof (int)); - md5_data ("J2K in Y frame " + lexical_cast (_frame), _image->comps[1].data, size * sizeof (int)); - md5_data ("J2K in Z frame " + lexical_cast (_frame), _image->comps[2].data, size * sizeof (int)); -#endif - /* Setup the encoder parameters using the current image and user parameters */ opj_setup_encoder (_cinfo, _parameters, _image); @@ -271,10 +261,6 @@ DCPVideoFrame::encode_locally () throw EncodeError ("jpeg2000 encoding failed"); } -#ifdef DEBUG_HASH - md5_data ("J2K out frame " + lexical_cast (_frame), _cio->buffer, cio_tell (_cio)); -#endif - { stringstream s; s << "Finished locally-encoded frame " << _frame; @@ -300,10 +286,6 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv) socket.connect (*endpoint_iterator, 30); -#ifdef DEBUG_HASH - _input->hash ("Input for remote encoding (before sending)"); -#endif - stringstream s; s << "encode " << _input->size().width << " " << _input->size().height << " " @@ -335,10 +317,6 @@ DCPVideoFrame::encode_remotely (ServerDescription const * serv) /* now read the rest */ socket.read_definite_and_consume (e->data(), e->size(), 30); -#ifdef DEBUG_HASH - e->hash ("Encoded image (after receiving)"); -#endif - { stringstream s; s << "Finished remotely-encoded frame " << _frame; @@ -382,14 +360,6 @@ EncodedData::send (shared_ptr socket) socket->write (_data, _size, 30); } -#ifdef DEBUG_HASH -void -EncodedData::hash (string n) const -{ - md5_data (n, _data, _size); -} -#endif - /** @param s Size of data in bytes */ RemotelyEncodedData::RemotelyEncodedData (int s) : EncodedData (new uint8_t[s], s) diff --git a/src/lib/dcp_video_frame.h b/src/lib/dcp_video_frame.h index da4e0c301..72f885e45 100644 --- a/src/lib/dcp_video_frame.h +++ b/src/lib/dcp_video_frame.h @@ -51,10 +51,6 @@ public: void send (boost::shared_ptr socket); void write (boost::shared_ptr, int); -#ifdef DEBUG_HASH - void hash (std::string) const; -#endif - /** @return data */ uint8_t* data () const { return _data; diff --git a/src/lib/image.cc b/src/lib/image.cc index f16bb9f77..89536da33 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -27,6 +27,7 @@ #include #include #include +#include extern "C" { #include #include @@ -39,10 +40,6 @@ extern "C" { #include "exceptions.h" #include "scaler.h" -#ifdef DEBUG_HASH -#include -#endif - using namespace std; using namespace boost; @@ -85,33 +82,6 @@ Image::components () const return 0; } -#ifdef DEBUG_HASH -/** Write a MD5 hash of the image's data to stdout. - * @param n Title to give the output. - */ -void -Image::hash (string n) const -{ - MHASH ht = mhash_init (MHASH_MD5); - if (ht == MHASH_FAILED) { - throw EncodeError ("could not create hash thread"); - } - - for (int i = 0; i < components(); ++i) { - mhash (ht, data()[i], line_size()[i] * lines(i)); - } - - uint8_t hash[16]; - mhash_deinit (ht, hash); - - printf ("%s: ", n.c_str ()); - for (int i = 0; i < int (mhash_get_block_size (MHASH_MD5)); ++i) { - printf ("%.2x", hash[i]); - } - printf ("\n"); -} -#endif - /** Scale this image to a given size and convert it to RGB. * @param out_size Output image size in pixels. * @param scaler Scaler to use. diff --git a/src/lib/image.h b/src/lib/image.h index 97ab1d5ff..0161d2b01 100644 --- a/src/lib/image.h +++ b/src/lib/image.h @@ -68,10 +68,6 @@ public: boost::shared_ptr scale_and_convert_to_rgb (Size, int, Scaler const *) const; boost::shared_ptr post_process (std::string) const; -#ifdef DEBUG_HASH - void hash (std::string) const; -#endif - void make_black (); PixelFormat pixel_format () const { diff --git a/src/lib/server.cc b/src/lib/server.cc index 8ca426049..f8c4425d9 100644 --- a/src/lib/server.cc +++ b/src/lib/server.cc @@ -124,17 +124,9 @@ Server::process (shared_ptr socket) socket->read_definite_and_consume (image->data()[i], image->line_size()[i] * image->lines(i), 30); } -#ifdef DEBUG_HASH - image->hash ("Image for encoding (as received by server)"); -#endif - DCPVideoFrame dcp_video_frame (image, out_size, padding, scaler, frame, frames_per_second, post_process, colour_lut_index, j2k_bandwidth, _log); shared_ptr encoded = dcp_video_frame.encode_locally (); encoded->send (socket); - -#ifdef DEBUG_HASH - encoded->hash ("Encoded image (as made by server and as sent back)"); -#endif return frame; } diff --git a/src/lib/util.cc b/src/lib/util.cc index 73222083a..c779268e2 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -40,6 +40,7 @@ #include #include #include +#include extern "C" { #include #include @@ -61,10 +62,6 @@ extern "C" { #include "player_manager.h" #endif -#ifdef DEBUG_HASH -#include -#endif - using namespace std; using namespace boost; @@ -347,9 +344,8 @@ split_at_spaces_considering_quotes (string s) return out; } -#ifdef DEBUG_HASH -void -md5_data (string title, void const * data, int size) +string +md5_hash (void const * data, int size) { MHASH ht = mhash_init (MHASH_MD5); if (ht == MHASH_FAILED) { @@ -360,14 +356,16 @@ md5_data (string title, void const * data, int size) uint8_t hash[16]; mhash_deinit (ht, hash); - - printf ("%s [%d]: ", title.c_str (), size); - for (int i = 0; i < int (mhash_get_block_size (MHASH_MD5)); ++i) { - printf ("%.2x", hash[i]); + + int const N = mhash_get_block_size (MHASH_MD5); + stringstream s; + s << hex << setfill('0') << setw(2); + for (int i = 0; i < N; ++i) { + s << ((int) hash[i]); } - printf ("\n"); + + return s.str (); } -#endif /** @param file File name. * @return MD5 digest of file's contents. diff --git a/src/lib/util.h b/src/lib/util.h index 63d492e60..03d04b852 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -52,9 +52,7 @@ enum ContentType { VIDEO }; -#ifdef DEBUG_HASH -extern void md5_data (std::string, void const *, int); -#endif +extern std::string md5_hash (void const *, int); /** @class Size * @brief Representation of the size of something */ diff --git a/src/lib/wscript b/src/lib/wscript index 71a2b23f4..26740a7e9 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -1,17 +1,13 @@ def configure(conf): - if conf.options.debug_hash: - conf.env.append_value('CXXFLAGS', '-DDEBUG_HASH') - conf.check_cc(msg = 'Checking for library libmhash', function_name = 'mhash_init', header_name = 'mhash.h', lib = 'mhash', uselib_store = 'MHASH') + conf.check_cc(msg = 'Checking for library libmhash', function_name = 'mhash_init', header_name = 'mhash.h', lib = 'mhash', uselib_store = 'MHASH') def build(bld): obj = bld(features = 'cxx cxxshlib') obj.name = 'libdvdomatic' obj.export_includes = ['.'] - obj.uselib = 'AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE SWRESAMPLE SNDFILE BOOST_FILESYSTEM BOOST_THREAD OPENJPEG POSTPROC TIFF SIGC++ MAGICK SSH DCP GLIB' + obj.uselib = 'AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE SWRESAMPLE SNDFILE BOOST_FILESYSTEM BOOST_THREAD OPENJPEG POSTPROC TIFF SIGC++ MAGICK SSH DCP GLIB MHASH' if bld.env.TARGET_WINDOWS: obj.uselib += ' WINSOCK2' - if bld.env.DEBUG_HASH: - obj.uselib += ' MHASH' obj.source = """ ab_transcode_job.cc ab_transcoder.cc diff --git a/src/tools/servomatictest.cc b/src/tools/servomatictest.cc index 0f37e73a5..d6804c981 100644 --- a/src/tools/servomatictest.cc +++ b/src/tools/servomatictest.cc @@ -47,12 +47,8 @@ process_video (shared_ptr image, int frame) shared_ptr local (new DCPVideoFrame (image, Size (1024, 1024), 0, Scaler::from_id ("bicubic"), frame, 24, "", 0, 250000000, &log_)); shared_ptr remote (new DCPVideoFrame (image, Size (1024, 1024), 0, Scaler::from_id ("bicubic"), frame, 24, "", 0, 250000000, &log_)); -#if defined(DEBUG_HASH) - cout << "Frame " << frame << ":\n"; -#else cout << "Frame " << frame << ": "; cout.flush (); -#endif shared_ptr local_encoded = local->encode_locally (); shared_ptr remote_encoded; @@ -64,11 +60,6 @@ process_video (shared_ptr image, int frame) remote_error = e.what (); } -#if defined(DEBUG_HASH) - cout << "Frame " << frame << ": "; - cout.flush (); -#endif - if (!remote_error.empty ()) { cout << "\033[0;31mnetwork problem: " << remote_error << "\033[0m\n"; return; diff --git a/wscript b/wscript index 71a89dfd3..69d68a35c 100644 --- a/wscript +++ b/wscript @@ -9,7 +9,6 @@ def options(opt): opt.load('compiler_cxx') opt.load('winres') - opt.add_option('--debug-hash', action='store_true', default = False, help = 'print hashes of data at various points') opt.add_option('--enable-debug', action='store_true', default = False, help = 'build with debugging information and without optimisation') opt.add_option('--disable-gui', action='store_true', default = False, help = 'disable building of GUI tools') opt.add_option('--disable-player', action='store_true', default = False, help = 'disable building of the player components') @@ -37,7 +36,6 @@ def configure(conf): boost_lib_suffix = '' boost_thread = 'boost_thread' - conf.env.DEBUG_HASH = conf.options.debug_hash conf.env.TARGET_WINDOWS = conf.options.target_windows conf.env.DISABLE_GUI = conf.options.disable_gui conf.env.DISABLE_PLAYER = conf.options.disable_player -- cgit v1.2.3 From 8b3f7c38278952dc97feba7d51ef39775608689b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 25 Sep 2012 00:27:14 +0100 Subject: Use openssl for all MD5-ing. --- src/lib/util.cc | 23 ++++++++--------------- src/lib/wscript | 5 +---- src/wscript | 1 - 3 files changed, 9 insertions(+), 20 deletions(-) (limited to 'src/lib/wscript') diff --git a/src/lib/util.cc b/src/lib/util.cc index c779268e2..935566440 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -40,7 +40,6 @@ #include #include #include -#include extern "C" { #include #include @@ -345,23 +344,17 @@ split_at_spaces_considering_quotes (string s) } string -md5_hash (void const * data, int size) +md5_digest (void const * data, int size) { - MHASH ht = mhash_init (MHASH_MD5); - if (ht == MHASH_FAILED) { - throw EncodeError ("could not create hash thread"); - } - - mhash (ht, data, 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); - uint8_t hash[16]; - mhash_deinit (ht, hash); - - int const N = mhash_get_block_size (MHASH_MD5); stringstream s; - s << hex << setfill('0') << setw(2); - for (int i = 0; i < N; ++i) { - s << ((int) hash[i]); + for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) { + s << hex << setfill('0') << setw(2) << ((int) digest[i]); } return s.str (); diff --git a/src/lib/wscript b/src/lib/wscript index 26740a7e9..803ffd9ee 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -1,11 +1,8 @@ -def configure(conf): - conf.check_cc(msg = 'Checking for library libmhash', function_name = 'mhash_init', header_name = 'mhash.h', lib = 'mhash', uselib_store = 'MHASH') - def build(bld): obj = bld(features = 'cxx cxxshlib') obj.name = 'libdvdomatic' obj.export_includes = ['.'] - obj.uselib = 'AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE SWRESAMPLE SNDFILE BOOST_FILESYSTEM BOOST_THREAD OPENJPEG POSTPROC TIFF SIGC++ MAGICK SSH DCP GLIB MHASH' + obj.uselib = 'AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE SWRESAMPLE SNDFILE BOOST_FILESYSTEM BOOST_THREAD OPENJPEG POSTPROC TIFF SIGC++ MAGICK SSH DCP GLIB' if bld.env.TARGET_WINDOWS: obj.uselib += ' WINSOCK2' obj.source = """ diff --git a/src/wscript b/src/wscript index 2ebeba210..3f17b3e6c 100644 --- a/src/wscript +++ b/src/wscript @@ -1,5 +1,4 @@ def configure(conf): - conf.recurse('lib') if not conf.env.DISABLE_GUI: conf.recurse('wx') -- cgit v1.2.3 From 82af50304f55a961cba6afefbfa7edd5440bfcc4 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 25 Sep 2012 01:20:58 +0100 Subject: Basic J2K hash checking. --- src/lib/check_hashes_job.cc | 79 +++++++++++++++++++++++++++++++++++++++++++++ src/lib/check_hashes_job.h | 33 +++++++++++++++++++ src/lib/dcp_video_frame.cc | 11 ++++++- src/lib/film.cc | 4 ++- src/lib/transcode_job.cc | 1 - src/lib/util.h | 3 +- src/lib/wscript | 1 + 7 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 src/lib/check_hashes_job.cc create mode 100644 src/lib/check_hashes_job.h (limited to 'src/lib/wscript') diff --git a/src/lib/check_hashes_job.cc b/src/lib/check_hashes_job.cc new file mode 100644 index 000000000..87eb40d14 --- /dev/null +++ b/src/lib/check_hashes_job.cc @@ -0,0 +1,79 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 +#include +#include +#include "check_hashes_job.h" +#include "film_state.h" +#include "options.h" +#include "log.h" + +using namespace std; +using namespace boost; + +CheckHashesJob::CheckHashesJob (shared_ptr s, shared_ptr o, Log* l) + : Job (s, o, l) + , _bad (0) +{ + +} + +string +CheckHashesJob::name () const +{ + stringstream s; + s << "Check hashes of " << _fs->name; + return s.str (); +} + +void +CheckHashesJob::run () +{ + _bad = 0; + + for (int i = 0; i < _fs->length; ++i) { + string const j2k_file = _opt->frame_out_path (i, false); + string const hash_file = j2k_file + ".md5"; + + ifstream ref (hash_file.c_str ()); + string hash; + ref >> hash; + + if (hash != md5_digest (j2k_file)) { + _log->log ("Frame " + lexical_cast (i) + " has wrong hash; deleting."); + filesystem::remove (j2k_file); + filesystem::remove (hash_file); + ++_bad; + } + + set_progress (float (i) / _fs->length); + } + + set_progress (1); + set_state (FINISHED_OK); +} + +string +CheckHashesJob::status () const +{ + stringstream s; + s << Job::status () << "; " << _bad << " bad frames found"; + return s.str (); +} diff --git a/src/lib/check_hashes_job.h b/src/lib/check_hashes_job.h new file mode 100644 index 000000000..b59cf031b --- /dev/null +++ b/src/lib/check_hashes_job.h @@ -0,0 +1,33 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 "job.h" + +class CheckHashesJob : public Job +{ +public: + CheckHashesJob (boost::shared_ptr s, boost::shared_ptr o, Log* l); + + std::string name () const; + void run (); + std::string status () const; + +private: + int _bad; +}; diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc index 96c40358a..da7133c4b 100644 --- a/src/lib/dcp_video_frame.cc +++ b/src/lib/dcp_video_frame.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -344,8 +345,16 @@ EncodedData::write (shared_ptr opt, int frame) fwrite (_data, 1, _size, f); fclose (f); + string const real_j2k = opt->frame_out_path (frame, false); + /* Rename the file from foo.j2c.tmp to foo.j2c now that it is complete */ - filesystem::rename (tmp_j2k, opt->frame_out_path (frame, false)); + filesystem::rename (tmp_j2k, real_j2k); + + /* Write a file containing the hash */ + string const hash = real_j2k + ".md5"; + ofstream h (hash.c_str()); + h << md5_digest (_data, _size) << "\n"; + h.close (); } /** Send this data to a socket. diff --git a/src/lib/film.cc b/src/lib/film.cc index d1334130e..583a15e19 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -48,6 +48,7 @@ #include "scaler.h" #include "decoder_factory.h" #include "config.h" +#include "check_hashes_job.h" using namespace std; using namespace boost; @@ -544,7 +545,8 @@ Film::make_dcp (bool transcode, int freq) JobManager::instance()->add (shared_ptr (new TranscodeJob (fs, o, log ()))); } } - + + JobManager::instance()->add (shared_ptr (new CheckHashesJob (fs, o, log ()))); JobManager::instance()->add (shared_ptr (new MakeDCPJob (fs, o, log ()))); } diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index c91058973..2de6e90ca 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -78,7 +78,6 @@ TranscodeJob::run () _log->log (s.str ()); throw; - } } diff --git a/src/lib/util.h b/src/lib/util.h index 03d04b852..bc5a00fc4 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -46,14 +46,13 @@ extern double seconds (struct timeval); extern void dvdomatic_setup (); extern std::vector split_at_spaces_considering_quotes (std::string); extern std::string md5_digest (std::string); +extern std::string md5_digest (void const *, int); enum ContentType { STILL, VIDEO }; -extern std::string md5_hash (void const *, int); - /** @class Size * @brief Representation of the size of something */ struct Size diff --git a/src/lib/wscript b/src/lib/wscript index 803ffd9ee..c809226ce 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -8,6 +8,7 @@ def build(bld): obj.source = """ ab_transcode_job.cc ab_transcoder.cc + check_hashes_job.cc config.cc copy_from_dvd_job.cc cross.cc -- cgit v1.2.3