summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-07-31 01:01:19 +0100
committerCarl Hetherington <cth@carlh.net>2012-07-31 01:01:19 +0100
commitda2f0d96f3c5ffa73bfecd9df613b23200e862f7 (patch)
tree326e054f9b2dc39e0d276e6bdf2a572dbf324ecc
parent4678bf06d71c8a18c489912dabf8aca312ab8b6b (diff)
Bitwise MXF comparison.
-rw-r--r--src/asset.cc43
-rw-r--r--src/asset.h3
-rw-r--r--src/dcp.cc21
-rw-r--r--src/dcp.h2
-rw-r--r--src/types.h5
-rw-r--r--tools/dcpdiff.cc4
6 files changed, 69 insertions, 9 deletions
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 <iostream>
+#include <fstream>
#include <boost/filesystem.hpp>
#include "AS_DCP.h"
#include "KM_util.h"
@@ -93,3 +94,45 @@ Asset::mxf_path () const
p /= _mxf_name;
return p;
}
+
+list<string>
+Asset::equals (Asset const & other, EqualityFlags flags) const
+{
+ list<string> 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 <string>
#include <sigc++/sigc++.h>
+#include "types.h"
namespace ASDCP {
class WriterInfo;
@@ -65,6 +66,8 @@ public:
*/
void write_to_assetmap (std::ostream& s) const;
+ std::list<std::string> 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<string>
-DCP::equals (DCP const & other, EqualityType type) const
+DCP::equals (DCP const & other, EqualityFlags flags) const
{
list<string> 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<shared_ptr<Asset> >::const_iterator a = _assets.begin ();
+ list<shared_ptr<Asset> >::const_iterator b = other._assets.begin ();
+
+ while (a != _assets.end ()) {
+ list<string> 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<std::string> equals (DCP const & other, EqualityType type) const;
+ std::list<std::string> 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
};
}
diff --git a/tools/dcpdiff.cc b/tools/dcpdiff.cc
index 840a1b3e..d1b49d05 100644
--- a/tools/dcpdiff.cc
+++ b/tools/dcpdiff.cc
@@ -49,9 +49,9 @@ main (int argc, char* argv[])
DCP a (argv[optind]);
DCP b (argv[optind + 1]);
- list<string> notes = a.equals (b, LIBDCP_METADATA);
+ list<string> notes = a.equals (b, EqualityFlags (LIBDCP_METADATA | MXF_BITWISE));
if (notes.empty ()) {
- cout << "DCPs identical by LIBDCP_METADATA\n";
+ cout << "DCPs identical\n";
exit (EXIT_SUCCESS);
}