Header guards.
[libdcp.git] / tools / dcpdiff.cc
index 9dd488edc74147588233224198239390284a341e..b361b93a35a1771b8f8c3b0a8065a5e528f1635c 100644 (file)
@@ -1,52 +1,83 @@
+#include <iostream>
+#include <boost/filesystem.hpp>
 #include <getopt.h>
 #include "dcp.h"
+#include "exceptions.h"
 
 using namespace std;
+using namespace boost;
 using namespace libdcp;
 
+static bool verbose = false;
+
 static void
 help (string n)
 {
        cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\n"
-            << "  -b, --bitwise      bitwise check\n"
-            << "  -v, --version      show libdcp version\n"
-            << "  -h, --help         show this help\n"
+            << "  -V, --version        show libdcp version\n"
+            << "  -h, --help           show this help\n"
+            << "  -v, --verbose        be verbose\n"
+            << "  -n, --names          allow differing MXF names\n"
+            << "  -m, --mean-pixel     maximum allowed mean pixel error (default 5)\n"
+            << "  -s, --std-dev-pixel  maximum allowed standard deviation of pixel error (default 5)\n"
             << "\n"
             << "The <DCP>s are the DCP directories to compare.\n"
-            << "Default is to compare metadata and content ignoring timestamps\n"
-            << "and differing UUIDs.  Pass -b to perform a bitwise comparison.\n";
+            << "Comparison is of metadata and content, ignoring timestamps\n"
+            << "and differing UUIDs.\n";
+}
+
+void
+note (NoteType t, string n)
+{
+       if (t == ERROR || verbose) {
+               cout << " " << n << "\n";
+       }
 }
 
 int
 main (int argc, char* argv[])
 {
-       bool bitwise = false;
+       EqualityOptions options;
+       options.max_mean_pixel_error = 5;
+       options.max_std_dev_pixel_error = 5;
        
        int option_index = 0;
        while (1) {
                static struct option long_options[] = {
-                       { "bitwise", no_argument, 0, 'b'},
-                       { "version", no_argument, 0, 'v'},
+                       { "version", no_argument, 0, 'V'},
                        { "help", no_argument, 0, 'h'},
+                       { "verbose", no_argument, 0, 'v'},
+                       { "names", no_argument, 0, 'n'},
+                       { "mean-pixel", required_argument, 0, 'm'},
+                       { "std-dev-pixel", required_argument, 0, 's'},
                        { 0, 0, 0, 0 }
                };
 
-               int c = getopt_long (argc, argv, "bvh", long_options, &option_index);
+               int c = getopt_long (argc, argv, "Vhvnm:s:", long_options, &option_index);
 
                if (c == -1) {
                        break;
                }
 
                switch (c) {
-               case 'b':
-                       bitwise = true;
-                       break;
-               case 'v':
+               case 'V':
                        cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
                        exit (EXIT_SUCCESS);
                case 'h':
                        help (argv[0]);
                        exit (EXIT_SUCCESS);
+               case 'v':
+                       verbose = true;
+                       break;
+               case 'n':
+                       options.mxf_names_can_differ = true;
+                       break;
+               case 'm':
+                       options.max_mean_pixel_error = atof (optarg);
+                       break;
+               case 's':
+                       options.max_std_dev_pixel_error = atof (optarg);
+                       break;
                }
        }
 
@@ -55,22 +86,41 @@ main (int argc, char* argv[])
                exit (EXIT_FAILURE);
        }
 
-       DCP a (argv[optind]);
-       DCP b (argv[optind + 1]);
+       if (!filesystem::exists (argv[optind])) {
+               cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
+               exit (EXIT_FAILURE);
+       }
 
-       EqualityFlags flags = EqualityFlags (LIBDCP_METADATA | MXF_INSPECT);
-       if (bitwise) {
-               flags = EqualityFlags (flags | MXF_BITWISE);
+       if (!filesystem::exists (argv[optind + 1])) {
+               cerr << argv[0] << ": DCP " << argv[optind + 1] << " not found.\n";
+               exit (EXIT_FAILURE);
        }
 
-       list<string> notes = a.equals (b, flags);
-       if (notes.empty ()) {
-               cout << "DCPs identical\n";
-               exit (EXIT_SUCCESS);
+       DCP* a = 0;
+       try {
+               a = new DCP (argv[optind]);
+               a->read ();
+       } catch (FileError& e) {
+               cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
+               exit (EXIT_FAILURE);
        }
 
-       for (list<string>::iterator i = notes.begin(); i != notes.end(); ++i) {
-               cout << "  " << *i << "\n";
+       DCP* b = 0;
+       try {
+               b = new DCP (argv[optind + 1]);
+               b->read ();
+       } catch (FileError& e) {
+               cerr << "Could not read DCP " << argv[optind + 1] << "; " << e.what() << " " << e.filename() << "\n";
+               exit (EXIT_FAILURE);
+       }
+
+       /* I think this is just below the LSB at 16-bits (ie the 8th most significant bit at 24-bit) */
+       options.max_audio_sample_error = 255;
+
+       bool const equals = a->equals (*b, options, boost::bind (note, _1, _2));
+
+       if (equals) {
+               exit (EXIT_SUCCESS);
        }
 
        exit (EXIT_FAILURE);