2 Copyright (C) 2018-2019 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
38 #include "reel_picture_asset.h"
39 #include "reel_sound_asset.h"
40 #include "exceptions.h"
41 #include "compose.hpp"
42 #include <boost/foreach.hpp>
51 using boost::shared_ptr;
52 using boost::optional;
53 using boost::function;
59 RESULT_CPL_PKL_DIFFER,
64 verify_asset (shared_ptr<DCP> dcp, shared_ptr<ReelMXF> reel_mxf, function<void (float)> progress)
66 string const actual_hash = reel_mxf->asset_ref()->hash(progress);
68 list<shared_ptr<PKL> > pkls = dcp->pkls();
69 /* We've read this DCP in so it must have at least one PKL */
70 DCP_ASSERT (!pkls.empty());
72 shared_ptr<Asset> asset = reel_mxf->asset_ref().asset();
74 optional<string> pkl_hash;
75 BOOST_FOREACH (shared_ptr<PKL> i, pkls) {
76 pkl_hash = i->hash (reel_mxf->asset_ref()->id());
82 DCP_ASSERT (pkl_hash);
84 optional<string> cpl_hash = reel_mxf->hash();
85 if (cpl_hash && *cpl_hash != *pkl_hash) {
86 return RESULT_CPL_PKL_DIFFER;
89 if (actual_hash != *pkl_hash) {
96 list<VerificationNote>
97 dcp::verify (vector<boost::filesystem::path> directories, function<void (string, optional<boost::filesystem::path>)> stage, function<void (float)> progress)
99 list<VerificationNote> notes;
101 list<shared_ptr<DCP> > dcps;
102 BOOST_FOREACH (boost::filesystem::path i, directories) {
103 dcps.push_back (shared_ptr<DCP> (new DCP (i)));
106 BOOST_FOREACH (shared_ptr<DCP> dcp, dcps) {
107 stage ("Checking DCP", dcp->directory());
108 DCP::ReadErrors errors;
110 dcp->read (true, &errors);
111 } catch (DCPReadError& e) {
112 notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::GENERAL_READ, string(e.what())));
113 } catch (XMLError& e) {
114 notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::GENERAL_READ, string(e.what())));
117 BOOST_FOREACH (shared_ptr<DCPReadError> i, errors) {
118 notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::GENERAL_READ, string(i->what())));
121 BOOST_FOREACH (shared_ptr<CPL> cpl, dcp->cpls()) {
122 stage ("Checking CPL", cpl->file());
124 /* Check that the CPL's hash corresponds to the PKL */
125 BOOST_FOREACH (shared_ptr<PKL> i, dcp->pkls()) {
126 optional<string> h = i->hash(cpl->id());
127 if (h && make_digest(Data(*cpl->file())) != *h) {
128 notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::CPL_HASH_INCORRECT));
132 BOOST_FOREACH (shared_ptr<Reel> reel, cpl->reels()) {
133 stage ("Checking reel", optional<boost::filesystem::path>());
134 if (reel->main_picture()) {
135 /* Check reel stuff */
136 Fraction const frame_rate = reel->main_picture()->frame_rate();
137 if (frame_rate.denominator != 1 ||
138 (frame_rate.numerator != 24 &&
139 frame_rate.numerator != 25 &&
140 frame_rate.numerator != 30 &&
141 frame_rate.numerator != 48 &&
142 frame_rate.numerator != 50 &&
143 frame_rate.numerator != 60 &&
144 frame_rate.numerator != 96)) {
145 notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::INVALID_PICTURE_FRAME_RATE));
148 if (reel->main_picture()->asset_ref().resolved()) {
149 stage ("Checking picture asset hash", reel->main_picture()->asset()->file());
150 Result const r = verify_asset (dcp, reel->main_picture(), progress);
155 VerificationNote::VERIFY_ERROR, VerificationNote::PICTURE_HASH_INCORRECT, *reel->main_picture()->asset()->file()
159 case RESULT_CPL_PKL_DIFFER:
160 notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::PKL_CPL_PICTURE_HASHES_DISAGREE));
167 if (reel->main_sound() && reel->main_sound()->asset_ref().resolved()) {
168 stage ("Checking sound asset hash", reel->main_sound()->asset()->file());
169 Result const r = verify_asset (dcp, reel->main_sound(), progress);
174 VerificationNote::VERIFY_ERROR, VerificationNote::SOUND_HASH_INCORRECT, *reel->main_sound()->asset()->file()
178 case RESULT_CPL_PKL_DIFFER:
179 notes.push_back (VerificationNote (VerificationNote::VERIFY_ERROR, VerificationNote::PKL_CPL_SOUND_HASHES_DISAGREE));