From da2f0d96f3c5ffa73bfecd9df613b23200e862f7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 31 Jul 2012 01:01:19 +0100 Subject: Bitwise MXF comparison. --- src/asset.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ src/asset.h | 3 +++ src/dcp.cc | 21 +++++++++++++++++---- src/dcp.h | 2 +- src/types.h | 5 +++-- 5 files changed, 67 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/asset.cc b/src/asset.cc index 740dc592..86bd54c5 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -22,6 +22,7 @@ */ #include +#include #include #include "AS_DCP.h" #include "KM_util.h" @@ -93,3 +94,45 @@ Asset::mxf_path () const p /= _mxf_name; return p; } + +list +Asset::equals (Asset const & other, EqualityFlags flags) const +{ + list notes; + + switch (flags) { + case LIBDCP_METADATA: + break; + case MXF_BITWISE: + if (filesystem::file_size (mxf_path()) != filesystem::file_size (other.mxf_path())) { + notes.push_back (mxf_path().string() + " and " + other.mxf_path().string() + " sizes differ"); + return notes; + } + + ifstream a (mxf_path().c_str(), ios::binary); + ifstream b (other.mxf_path().c_str(), ios::binary); + + int buffer_size = 65536; + char abuffer[buffer_size]; + char bbuffer[buffer_size]; + + int n = filesystem::file_size (mxf_path ()); + + while (n) { + int const t = min (n, buffer_size); + a.read (abuffer, t); + b.read (bbuffer, t); + + for (int i = 0; i < t; ++i) { + if (abuffer[i] != bbuffer[i]) { + notes.push_back (mxf_path().string() + " and " + other.mxf_path().string() + " content differs"); + return notes; + } + } + + n -= t; + } + } + + return notes; +} diff --git a/src/asset.h b/src/asset.h index 62b7b4ac..7fb0ece2 100644 --- a/src/asset.h +++ b/src/asset.h @@ -26,6 +26,7 @@ #include #include +#include "types.h" namespace ASDCP { class WriterInfo; @@ -65,6 +66,8 @@ public: */ void write_to_assetmap (std::ostream& s) const; + std::list equals (Asset const & other, EqualityFlags flags) const; + protected: /** Fill in a ADSCP::WriteInfo struct. * @param w struct to fill in. diff --git a/src/dcp.cc b/src/dcp.cc index dc895e11..ed63170f 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -305,12 +305,11 @@ DCP::DCP (string directory) } list -DCP::equals (DCP const & other, EqualityType type) const +DCP::equals (DCP const & other, EqualityFlags flags) const { list notes; - switch (type) { - case LIBDCP_METADATA: + if (flags & LIBDCP_METADATA) { if (_name != other._name) { notes.push_back ("names differ"); } @@ -323,10 +322,24 @@ DCP::equals (DCP const & other, EqualityType type) const if (_length != other._length) { notes.push_back ("lengths differ"); } + } + + if (flags & LIBDCP_METADATA || flags & MXF_BITWISE) { if (_assets.size() != other._assets.size()) { notes.push_back ("asset counts differ"); } - break; + } + + if (flags & MXF_BITWISE) { + list >::const_iterator a = _assets.begin (); + list >::const_iterator b = other._assets.begin (); + + while (a != _assets.end ()) { + list n = (*a)->equals (*b->get(), MXF_BITWISE); + notes.merge (n); + ++a; + ++b; + } } return notes; diff --git a/src/dcp.h b/src/dcp.h index 6ab57bcb..bc829fe9 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -106,7 +106,7 @@ public: return _length; } - std::list equals (DCP const & other, EqualityType type) const; + std::list equals (DCP const & other, EqualityFlags flags) const; /** Emitted with a parameter between 0 and 1 to indicate progress * for long jobs. diff --git a/src/types.h b/src/types.h index 5cd76ff4..ad14094d 100644 --- a/src/types.h +++ b/src/types.h @@ -62,8 +62,9 @@ public: int denominator; }; -enum EqualityType { - LIBDCP_METADATA +enum EqualityFlags { + LIBDCP_METADATA = 0x1, + MXF_BITWISE = 0x2 }; } -- cgit v1.2.3