summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-07-24 10:32:52 +0100
committerCarl Hetherington <cth@carlh.net>2013-07-24 10:32:52 +0100
commit49a51ff9778f3b72ee962d3e8bd9cf71944f3c2b (patch)
tree2b916b15eabd8132bbc80b00e4a4f09edfd9eb92 /src/lib
parent084d5155d410eef68f87635876e136b224db91dc (diff)
Rename Content::_file to path and support md5sums of directories.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/analyse_audio_job.cc2
-rw-r--r--src/lib/content.cc16
-rw-r--r--src/lib/content.h9
-rw-r--r--src/lib/ffmpeg.cc4
-rw-r--r--src/lib/ffmpeg_content.cc2
-rw-r--r--src/lib/sndfile_content.cc2
-rw-r--r--src/lib/sndfile_decoder.cc2
-rw-r--r--src/lib/still_image_content.cc2
-rw-r--r--src/lib/still_image_decoder.cc2
-rw-r--r--src/lib/still_image_examiner.cc2
-rw-r--r--src/lib/util.cc38
-rw-r--r--src/lib/util.h1
12 files changed, 64 insertions, 18 deletions
diff --git a/src/lib/analyse_audio_job.cc b/src/lib/analyse_audio_job.cc
index 3902ec537..df67b37d6 100644
--- a/src/lib/analyse_audio_job.cc
+++ b/src/lib/analyse_audio_job.cc
@@ -50,7 +50,7 @@ AnalyseAudioJob::name () const
return "";
}
- return String::compose (_("Analyse audio of %1"), content->file().filename());
+ return String::compose (_("Analyse audio of %1"), content->path());
}
void
diff --git a/src/lib/content.cc b/src/lib/content.cc
index 0db93d5e3..372be3020 100644
--- a/src/lib/content.cc
+++ b/src/lib/content.cc
@@ -43,7 +43,7 @@ Content::Content (shared_ptr<const Film> f, Time s)
Content::Content (shared_ptr<const Film> f, boost::filesystem::path p)
: _film (f)
- , _file (p)
+ , _path (p)
, _start (0)
, _change_signals_frequent (false)
{
@@ -54,7 +54,7 @@ Content::Content (shared_ptr<const Film> f, shared_ptr<const cxml::Node> node)
: _film (f)
, _change_signals_frequent (false)
{
- _file = node->string_child ("File");
+ _path = node->string_child ("Path");
_digest = node->string_child ("Digest");
_start = node->number_child<Time> ("Start");
}
@@ -63,7 +63,7 @@ void
Content::as_xml (xmlpp::Node* node) const
{
boost::mutex::scoped_lock lm (_mutex);
- node->add_child("File")->add_child_text (_file.string());
+ node->add_child("Path")->add_child_text (_path.string());
node->add_child("Digest")->add_child_text (_digest);
node->add_child("Start")->add_child_text (lexical_cast<string> (_start));
}
@@ -71,7 +71,13 @@ Content::as_xml (xmlpp::Node* node) const
void
Content::examine (shared_ptr<Job>)
{
- string const d = md5_digest (_file);
+ string d;
+ if (boost::filesystem::is_regular_file (_path)) {
+ d = md5_digest (_path);
+ } else {
+ d = md5_digest_directory (_path);
+ }
+
boost::mutex::scoped_lock lm (_mutex);
_digest = d;
}
@@ -113,5 +119,5 @@ Content::clone () const
string
Content::technical_summary () const
{
- return String::compose ("%1 %2 %3", file(), digest(), start());
+ return String::compose ("%1 %2 %3", path(), digest(), start());
}
diff --git a/src/lib/content.h b/src/lib/content.h
index 33af0a624..78b80e254 100644
--- a/src/lib/content.h
+++ b/src/lib/content.h
@@ -59,12 +59,12 @@ public:
boost::shared_ptr<Content> clone () const;
- boost::filesystem::path file () const {
+ boost::filesystem::path path () const {
boost::mutex::scoped_lock lm (_mutex);
- return _file;
+ return _path;
}
- /** @return MD5 digest of the content's file */
+ /** @return MD5 digest of the content's file(s) */
std::string digest () const {
boost::mutex::scoped_lock lm (_mutex);
return _digest;
@@ -94,7 +94,8 @@ protected:
mutable boost::mutex _mutex;
private:
- boost::filesystem::path _file;
+ /** Path of a file or a directory containing files */
+ boost::filesystem::path _path;
std::string _digest;
Time _start;
bool _change_signals_frequent;
diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc
index 77bf75018..c97b79a71 100644
--- a/src/lib/ffmpeg.cc
+++ b/src/lib/ffmpeg.cc
@@ -68,8 +68,8 @@ FFmpeg::setup_general ()
{
av_register_all ();
- if (avformat_open_input (&_format_context, _ffmpeg_content->file().string().c_str(), 0, 0) < 0) {
- throw OpenFileError (_ffmpeg_content->file().string ());
+ if (avformat_open_input (&_format_context, _ffmpeg_content->path().string().c_str(), 0, 0) < 0) {
+ throw OpenFileError (_ffmpeg_content->path().string ());
}
if (avformat_find_stream_info (_format_context, 0) < 0) {
diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc
index 00499cf13..901cb53cf 100644
--- a/src/lib/ffmpeg_content.cc
+++ b/src/lib/ffmpeg_content.cc
@@ -166,7 +166,7 @@ FFmpegContent::examine (shared_ptr<Job> job)
string
FFmpegContent::summary () const
{
- return String::compose (_("%1 [movie]"), file().filename().string());
+ return String::compose (_("%1 [movie]"), path());
}
string
diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc
index ee55ede91..713b80dcb 100644
--- a/src/lib/sndfile_content.cc
+++ b/src/lib/sndfile_content.cc
@@ -55,7 +55,7 @@ SndfileContent::SndfileContent (shared_ptr<const Film> f, shared_ptr<const cxml:
string
SndfileContent::summary () const
{
- return String::compose (_("%1 [audio]"), file().filename().string());
+ return String::compose (_("%1 [audio]"), path().filename().string());
}
string
diff --git a/src/lib/sndfile_decoder.cc b/src/lib/sndfile_decoder.cc
index bfa163c6c..1fc1ecaf2 100644
--- a/src/lib/sndfile_decoder.cc
+++ b/src/lib/sndfile_decoder.cc
@@ -40,7 +40,7 @@ SndfileDecoder::SndfileDecoder (shared_ptr<const Film> f, shared_ptr<const Sndfi
, _deinterleave_buffer (0)
{
_info.format = 0;
- _sndfile = sf_open (_sndfile_content->file().string().c_str(), SFM_READ, &_info);
+ _sndfile = sf_open (_sndfile_content->path().string().c_str(), SFM_READ, &_info);
if (!_sndfile) {
throw DecodeError (_("could not open audio file for reading"));
}
diff --git a/src/lib/still_image_content.cc b/src/lib/still_image_content.cc
index 804a5c0f6..e829e205d 100644
--- a/src/lib/still_image_content.cc
+++ b/src/lib/still_image_content.cc
@@ -48,7 +48,7 @@ StillImageContent::StillImageContent (shared_ptr<const Film> f, shared_ptr<const
string
StillImageContent::summary () const
{
- return String::compose (_("%1 [still]"), file().filename().string());
+ return String::compose (_("%1 [still]"), path());
}
string
diff --git a/src/lib/still_image_decoder.cc b/src/lib/still_image_decoder.cc
index 10e34427b..1dd684639 100644
--- a/src/lib/still_image_decoder.cc
+++ b/src/lib/still_image_decoder.cc
@@ -52,7 +52,7 @@ StillImageDecoder::pass ()
return;
}
- Magick::Image* magick_image = new Magick::Image (_still_image_content->file().string ());
+ Magick::Image* magick_image = new Magick::Image (_still_image_content->path().string ());
_video_size = libdcp::Size (magick_image->columns(), magick_image->rows());
_image.reset (new Image (PIX_FMT_RGB24, _video_size.get(), false));
diff --git a/src/lib/still_image_examiner.cc b/src/lib/still_image_examiner.cc
index 07848d7b9..5f45d6365 100644
--- a/src/lib/still_image_examiner.cc
+++ b/src/lib/still_image_examiner.cc
@@ -33,7 +33,7 @@ StillImageExaminer::StillImageExaminer (shared_ptr<const Film> f, shared_ptr<con
, _film (f)
{
using namespace MagickCore;
- Magick::Image* image = new Magick::Image (_still_image_content->file().string());
+ Magick::Image* image = new Magick::Image (_still_image_content->path().string());
_video_size = libdcp::Size (image->columns(), image->rows());
delete image;
}
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 7e7e579a4..affbe3b00 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -407,6 +407,44 @@ md5_digest (boost::filesystem::path file)
return s.str ();
}
+string
+md5_digest_directory (boost::filesystem::path directory)
+{
+ int const buffer_size = 64 * 1024;
+ char buffer[buffer_size];
+
+ MD5_CTX md5_context;
+ MD5_Init (&md5_context);
+
+ for (boost::filesystem::directory_iterator i(directory); i != boost::filesystem::directory_iterator(); ++i) {
+ ifstream f (i->path().string().c_str(), std::ios::binary);
+ if (!f.good ()) {
+ throw OpenFileError (i->path().string());
+ }
+
+ f.seekg (0, std::ios::end);
+ int bytes = f.tellg ();
+ f.seekg (0, std::ios::beg);
+
+ while (bytes > 0) {
+ int const t = min (bytes, buffer_size);
+ f.read (buffer, t);
+ MD5_Update (&md5_context, buffer, t);
+ bytes -= t;
+ }
+ }
+
+ 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 ();
+}
+
static bool
about_equal (float a, float b)
{
diff --git a/src/lib/util.h b/src/lib/util.h
index 4888a023f..65fb3d0dd 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -63,6 +63,7 @@ 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 (boost::filesystem::path);
+extern std::string md5_digest_directory (boost::filesystem::path);
extern std::string md5_digest (void const *, int);
extern void ensure_ui_thread ();
extern std::string audio_channel_name (int);