Bitwise MXF comparison.
authorCarl Hetherington <cth@carlh.net>
Tue, 31 Jul 2012 00:01:19 +0000 (01:01 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 31 Jul 2012 00:01:19 +0000 (01:01 +0100)
src/asset.cc
src/asset.h
src/dcp.cc
src/dcp.h
src/types.h
tools/dcpdiff.cc

index 740dc592335c6379f07824b6c896af8a1acd52b0..86bd54c56d700e21446d3c3a016f24011f8a440a 100644 (file)
@@ -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;
+}
index 62b7b4ac494745776910eec1ff608064a294ca8c..7fb0ece28d610ac15896bc7928ea496b6220c64f 100644 (file)
@@ -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.
index dc895e11c2eb5cd38f77de4d75eb291f013196e9..ed63170fb049c4d7565f7462d39318e327629fc0 100644 (file)
@@ -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;
index 6ab57bcb9152322248271b263373c5c0c5ef5e44..bc829fe96d1e69be5a837fc2ccdf8060b9edb95e 100644 (file)
--- 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.
index 5cd76ff4099c08f632e66a18941bd5399db99ece..ad14094dfb65b7f31d175ae36ed506db93e7b298 100644 (file)
@@ -62,8 +62,9 @@ public:
        int denominator;
 };
 
-enum EqualityType {
-       LIBDCP_METADATA
+enum EqualityFlags {
+       LIBDCP_METADATA = 0x1,
+       MXF_BITWISE = 0x2
 };
 
 }
index 840a1b3e0508fdce57f972c51bdfffdd443e5f7a..d1b49d05385332700c1a6c81dd9a2c8490cd3365 100644 (file)
@@ -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);
        }