2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
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.
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.
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.
21 #include "exceptions.h"
25 #include <boost/optional.hpp>
26 #include <boost/shared_ptr.hpp>
27 #include <boost/filesystem.hpp>
35 using boost::shared_ptr;
36 using boost::optional;
37 using boost::dynamic_pointer_cast;
40 static bool verbose = false;
45 cerr << "Syntax: " << n << " [OPTION] <DCP> <DCP>\n"
46 << " -V, --version show libdcp version\n"
47 << " -h, --help show this help\n"
48 << " -v, --verbose be verbose\n"
49 << " --cpl-annotation-texts allow differing CPL annotation texts\n"
50 << " --reel-annotation-texts allow differing reel annotation texts\n"
51 << " -m, --mean-pixel maximum allowed mean pixel error (default 5)\n"
52 << " -s, --std-dev-pixel maximum allowed standard deviation of pixel error (default 5)\n"
53 << " --key hexadecimal key to use to decrypt MXFs\n"
54 << " -k, --keep-going carry on in the event of errors, if possible\n"
55 << " --ignore-missing-assets ignore missing asset files\n"
57 << "The <DCP>s are the DCP directories to compare.\n"
58 << "Comparison is of metadata and content, ignoring timestamps\n"
59 << "and differing UUIDs.\n";
63 note (NoteType t, string n)
65 if (t == DCP_ERROR || verbose) {
66 cout << " " << n << "\n";
71 load_dcp (boost::filesystem::path path, bool keep_going, bool ignore_missing_assets, optional<string> key)
76 DCP::ReadErrors errors;
77 dcp->read (keep_going, &errors);
78 filter_errors (errors, ignore_missing_assets);
79 for (DCP::ReadErrors::const_iterator i = errors.begin(); i != errors.end(); ++i) {
80 cerr << (*i)->what() << "\n";
84 list<shared_ptr<Asset> > assets = dcp->assets ();
85 for (list<shared_ptr<Asset> >::const_iterator i = assets.begin(); i != assets.end(); ++i) {
86 shared_ptr<MXF> mxf = dynamic_pointer_cast<MXF> (*i);
88 mxf->set_key (Key (key.get ()));
93 } catch (FileError& e) {
94 cerr << "Could not read DCP " << path.string() << "; " << e.what() << " " << e.filename() << "\n";
102 main (int argc, char* argv[])
104 EqualityOptions options;
105 options.max_mean_pixel_error = 5;
106 options.max_std_dev_pixel_error = 5;
107 options.reel_hashes_can_differ = true;
108 options.reel_annotation_texts_can_differ = false;
109 bool keep_going = false;
110 bool ignore_missing_assets = false;
111 optional<string> key;
113 int option_index = 0;
115 static struct option long_options[] = {
116 { "version", no_argument, 0, 'V'},
117 { "help", no_argument, 0, 'h'},
118 { "verbose", no_argument, 0, 'v'},
119 { "mean-pixel", required_argument, 0, 'm'},
120 { "std-dev-pixel", required_argument, 0, 's'},
121 { "keep-going", no_argument, 0, 'k'},
122 /* From here we're using random capital letters for the short option */
123 { "ignore-missing-assets", no_argument, 0, 'A'},
124 { "cpl-annotation-texts", no_argument, 0, 'C'},
125 { "key", required_argument, 0, 'D'},
126 { "reel-annotation-texts", no_argument, 0, 'E'},
130 int c = getopt_long (argc, argv, "Vhvm:s:kACD:E", long_options, &option_index);
138 cout << "dcpdiff version " << LIBDCP_VERSION << "\n";
147 options.max_mean_pixel_error = atof (optarg);
150 options.max_std_dev_pixel_error = atof (optarg);
156 ignore_missing_assets = true;
160 options.cpl_annotation_texts_can_differ = true;
163 key = string (optarg);
166 options.reel_annotation_texts_can_differ = true;
171 if (argc <= optind || argc > (optind + 2)) {
176 if (!boost::filesystem::exists (argv[optind])) {
177 cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n";
181 if (!boost::filesystem::exists (argv[optind + 1])) {
182 cerr << argv[0] << ": DCP " << argv[optind + 1] << " not found.\n";
186 DCP* a = load_dcp (argv[optind], keep_going, ignore_missing_assets, key);
187 DCP* b = load_dcp (argv[optind + 1], keep_going, ignore_missing_assets, key);
189 /* I think this is just below the LSB at 16-bits (ie the 8th most significant bit at 24-bit) */
190 options.max_audio_sample_error = 255;
192 bool const equals = a->equals (*b, options, boost::bind (note, _1, _2));
194 exit (equals ? EXIT_SUCCESS : EXIT_FAILURE);