summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-09-25 01:20:58 +0100
committerCarl Hetherington <cth@carlh.net>2012-09-25 01:20:58 +0100
commit82af50304f55a961cba6afefbfa7edd5440bfcc4 (patch)
tree7f637d5f9218a8a72752505d1467b75bdc934574 /src/lib
parent8b3f7c38278952dc97feba7d51ef39775608689b (diff)
Basic J2K hash checking.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/check_hashes_job.cc79
-rw-r--r--src/lib/check_hashes_job.h33
-rw-r--r--src/lib/dcp_video_frame.cc11
-rw-r--r--src/lib/film.cc4
-rw-r--r--src/lib/transcode_job.cc1
-rw-r--r--src/lib/util.h3
-rw-r--r--src/lib/wscript1
7 files changed, 127 insertions, 5 deletions
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 <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 <fstream>
+#include <boost/lexical_cast.hpp>
+#include <boost/filesystem.hpp>
+#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<const FilmState> s, shared_ptr<const Options> 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<string> (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 <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 "job.h"
+
+class CheckHashesJob : public Job
+{
+public:
+ CheckHashesJob (boost::shared_ptr<const FilmState> s, boost::shared_ptr<const Options> 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 <iomanip>
#include <sstream>
#include <iostream>
+#include <fstream>
#include <unistd.h>
#include <errno.h>
#include <boost/array.hpp>
@@ -344,8 +345,16 @@ EncodedData::write (shared_ptr<const Options> 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<Job> (new TranscodeJob (fs, o, log ())));
}
}
-
+
+ JobManager::instance()->add (shared_ptr<Job> (new CheckHashesJob (fs, o, log ())));
JobManager::instance()->add (shared_ptr<Job> (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<std::string> 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