Missing includes.
[libdcp.git] / tools / dcpdiff.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21 #include <boost/filesystem.hpp>
22 #include <getopt.h>
23 #include "dcp.h"
24 #include "exceptions.h"
25
26 using namespace std;
27 using namespace boost;
28 using namespace libdcp;
29
30 static bool verbose = false;
31
32 static void
33 help (string n)
34 {
35         cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\n"
36              << "  -V, --version        show libdcp version\n"
37              << "  -h, --help           show this help\n"
38              << "  -v, --verbose        be verbose\n"
39              << "  -n, --mxf-names      allow differing MXF names\n"
40              << "      --cpl-names      allow differing CPL names\n"
41              << "  -m, --mean-pixel     maximum allowed mean pixel error (default 5)\n"
42              << "  -s, --std-dev-pixel  maximum allowed standard deviation of pixel error (default 5)\n"
43              << "\n"
44              << "The <DCP>s are the DCP directories to compare.\n"
45              << "Comparison is of metadata and content, ignoring timestamps\n"
46              << "and differing UUIDs.\n";
47 }
48
49 void
50 note (NoteType t, string n)
51 {
52         if (t == ERROR || verbose) {
53                 cout << " " << n << "\n";
54         }
55 }
56
57 int
58 main (int argc, char* argv[])
59 {
60         EqualityOptions options;
61         options.max_mean_pixel_error = 5;
62         options.max_std_dev_pixel_error = 5;
63         
64         int option_index = 0;
65         while (1) {
66                 static struct option long_options[] = {
67                         { "version", no_argument, 0, 'V'},
68                         { "help", no_argument, 0, 'h'},
69                         { "verbose", no_argument, 0, 'v'},
70                         { "mxf-names", no_argument, 0, 'n'},
71                         { "mean-pixel", required_argument, 0, 'm'},
72                         { "std-dev-pixel", required_argument, 0, 's'},
73                         /* From here we're using random capital letters for the short option */
74                         { "cpl-names", no_argument, 0, 'A'},
75                         { 0, 0, 0, 0 }
76                 };
77
78                 int c = getopt_long (argc, argv, "Vhvnm:s:A", long_options, &option_index);
79
80                 if (c == -1) {
81                         break;
82                 }
83
84                 switch (c) {
85                 case 'V':
86                         cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
87                         exit (EXIT_SUCCESS);
88                 case 'h':
89                         help (argv[0]);
90                         exit (EXIT_SUCCESS);
91                 case 'v':
92                         verbose = true;
93                         break;
94                 case 'n':
95                         options.mxf_names_can_differ = true;
96                         break;
97                 case 'm':
98                         options.max_mean_pixel_error = atof (optarg);
99                         break;
100                 case 's':
101                         options.max_std_dev_pixel_error = atof (optarg);
102                         break;
103                 case 'A':
104                         options.cpl_names_can_differ = true;
105                         break;
106                 }
107         }
108
109         if (argc <= optind || argc > (optind + 2)) {
110                 help (argv[0]);
111                 exit (EXIT_FAILURE);
112         }
113
114         if (!filesystem::exists (argv[optind])) {
115                 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
116                 exit (EXIT_FAILURE);
117         }
118
119         if (!filesystem::exists (argv[optind + 1])) {
120                 cerr << argv[0] << ": DCP " << argv[optind + 1] << " not found.\n";
121                 exit (EXIT_FAILURE);
122         }
123
124         DCP* a = 0;
125         try {
126                 a = new DCP (argv[optind]);
127                 a->read ();
128         } catch (FileError& e) {
129                 cerr << "Could not read DCP " << argv[optind] << "; " << e.what() << " " << e.filename() << "\n";
130                 exit (EXIT_FAILURE);
131         }
132
133         DCP* b = 0;
134         try {
135                 b = new DCP (argv[optind + 1]);
136                 b->read ();
137         } catch (FileError& e) {
138                 cerr << "Could not read DCP " << argv[optind + 1] << "; " << e.what() << " " << e.filename() << "\n";
139                 exit (EXIT_FAILURE);
140         }
141
142         /* I think this is just below the LSB at 16-bits (ie the 8th most significant bit at 24-bit) */
143         options.max_audio_sample_error = 255;
144
145         bool const equals = a->equals (*b, options, boost::bind (note, _1, _2));
146
147         if (equals) {
148                 exit (EXIT_SUCCESS);
149         }
150
151         exit (EXIT_FAILURE);
152 }