Remove debug code.
[libdcp.git] / tools / dcpdiff.cc
1 #include <iostream>
2 #include <boost/filesystem.hpp>
3 #include <getopt.h>
4 #include "dcp.h"
5 #include "exceptions.h"
6
7 using namespace std;
8 using namespace boost;
9 using namespace dcp;
10
11 static bool verbose = false;
12
13 static void
14 help (string n)
15 {
16         cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\n"
17              << "  -V, --version        show libdcp version\n"
18              << "  -h, --help           show this help\n"
19              << "  -v, --verbose        be verbose\n"
20              << "  -n, --names          allow differing MXF names\n"
21              << "  -m, --mean-pixel     maximum allowed mean pixel error (default 5)\n"
22              << "  -s, --std-dev-pixel  maximum allowed standard deviation of pixel error (default 5)\n"
23              << "\n"
24              << "The <DCP>s are the DCP directories to compare.\n"
25              << "Comparison is of metadata and content, ignoring timestamps\n"
26              << "and differing UUIDs.\n";
27 }
28
29 void
30 note (NoteType t, string n)
31 {
32         if (t == ERROR || verbose) {
33                 cout << " " << n << "\n";
34         }
35 }
36
37 int
38 main (int argc, char* argv[])
39 {
40         EqualityOptions options;
41         options.max_mean_pixel_error = 5;
42         options.max_std_dev_pixel_error = 5;
43         
44         int option_index = 0;
45         while (1) {
46                 static struct option long_options[] = {
47                         { "version", no_argument, 0, 'V'},
48                         { "help", no_argument, 0, 'h'},
49                         { "verbose", no_argument, 0, 'v'},
50                         { "names", no_argument, 0, 'n'},
51                         { "mean-pixel", required_argument, 0, 'm'},
52                         { "std-dev-pixel", required_argument, 0, 's'},
53                         { 0, 0, 0, 0 }
54                 };
55
56                 int c = getopt_long (argc, argv, "Vhvnm:s:", long_options, &option_index);
57
58                 if (c == -1) {
59                         break;
60                 }
61
62                 switch (c) {
63                 case 'V':
64                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
65                         exit (EXIT_SUCCESS);
66                 case 'h':
67                         help (argv[0]);
68                         exit (EXIT_SUCCESS);
69                 case 'v':
70                         verbose = true;
71                         break;
72                 case 'n':
73                         options.mxf_names_can_differ = true;
74                         break;
75                 case 'm':
76                         options.max_mean_pixel_error = atof (optarg);
77                         break;
78                 case 's':
79                         options.max_std_dev_pixel_error = atof (optarg);
80                         break;
81                 }
82         }
83
84         if (argc <= optind || argc > (optind + 2)) {
85                 help (argv[0]);
86                 exit (EXIT_FAILURE);
87         }
88
89         if (!filesystem::exists (argv[optind])) {
90                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
91                 exit (EXIT_FAILURE);
92         }
93
94         if (!filesystem::exists (argv[optind + 1])) {
95                 cerr << argv[0] << ": DCP " << argv[optind + 1] << " not found.\n";
96                 exit (EXIT_FAILURE);
97         }
98
99         DCP* a = 0;
100         try {
101                 a = new DCP (argv[optind]);
102                 a->read ();
103         } catch (FileError& e) {
104                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
105                 exit (EXIT_FAILURE);
106         }
107
108         DCP* b = 0;
109         try {
110                 b = new DCP (argv[optind + 1]);
111                 b->read ();
112         } catch (FileError& e) {
113                 cerr << "Could not read DCP " << argv[optind + 1] << "; " << e.what() << " " << e.filename() << "\n";
114                 exit (EXIT_FAILURE);
115         }
116
117         /* I think this is just below the LSB at 16-bits (ie the 8th most significant bit at 24-bit) */
118         options.max_audio_sample_error = 255;
119
120         bool const equals = a->equals (*b, options, boost::bind (note, _1, _2));
121
122         if (equals) {
123                 exit (EXIT_SUCCESS);
124         }
125
126         exit (EXIT_FAILURE);
127 }