Try to give basic progress indication on dcpdiff.
[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 libdcp;
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"
21              << "The <DCP>s are the DCP directories to compare.\n"
22              << "Comparison is of metadata and content, ignoring timestamps\n"
23              << "and differing UUIDs.\n";
24 }
25
26 void
27 note (NoteType t, string n)
28 {
29         if (t == ERROR || (t == PROGRESS && verbose)) {
30                 cout << " " << n << "\n";
31         }
32 }
33
34 int
35 main (int argc, char* argv[])
36 {
37         EqualityOptions options;
38         
39         int option_index = 0;
40         while (1) {
41                 static struct option long_options[] = {
42                         { "version", no_argument, 0, 'V'},
43                         { "help", no_argument, 0, 'h'},
44                         { "verbose", no_argument, 0, 'v'},
45                         { 0, 0, 0, 0 }
46                 };
47
48                 int c = getopt_long (argc, argv, "Vhv", long_options, &option_index);
49
50                 if (c == -1) {
51                         break;
52                 }
53
54                 switch (c) {
55                 case 'V':
56                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
57                         exit (EXIT_SUCCESS);
58                 case 'h':
59                         help (argv[0]);
60                         exit (EXIT_SUCCESS);
61                 case 'v':
62                         verbose = true;
63                         break;
64                 }
65         }
66
67         if (argc <= optind || argc > (optind + 2)) {
68                 help (argv[0]);
69                 exit (EXIT_FAILURE);
70         }
71
72         if (!filesystem::exists (argv[optind])) {
73                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
74                 exit (EXIT_FAILURE);
75         }
76
77         if (!filesystem::exists (argv[optind + 1])) {
78                 cerr << argv[0] << ": DCP " << argv[optind + 1] << " not found.\n";
79                 exit (EXIT_FAILURE);
80         }
81
82         DCP* a = 0;
83         try {
84                 a = new DCP (argv[optind]);
85                 a->read ();
86         } catch (FileError& e) {
87                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
88                 exit (EXIT_FAILURE);
89         }
90
91         DCP* b = 0;
92         try {
93                 b = new DCP (argv[optind + 1]);
94                 b->read ();
95         } catch (FileError& e) {
96                 cerr << "Could not read DCP " << argv[optind + 1] << "; " << e.what() << " " << e.filename() << "\n";
97                 exit (EXIT_FAILURE);
98         }
99
100         options.max_mean_pixel_error = 5;
101         options.max_std_dev_pixel_error = 5;
102         /* I think this is just below the LSB at 16-bits (ie the 8th most significant bit at 24-bit) */
103         options.max_audio_sample_error = 255;
104
105         bool const equals = a->equals (*b, options, boost::bind (note, _1, _2));
106
107         if (equals) {
108                 exit (EXIT_SUCCESS);
109         }
110
111         exit (EXIT_FAILURE);
112 }