2 Copyright (C) 2018-2021 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.
35 /** @file src/verify.h
36 * @brief dcp::verify() method and associated code
40 #ifndef LIBDCP_VERIFY_H
41 #define LIBDCP_VERIFY_H
44 #include <boost/any.hpp>
45 #include <boost/filesystem.hpp>
46 #include <boost/function.hpp>
47 #include <boost/optional.hpp>
53 /* Something in windows.h defines this */
60 class VerificationNote
65 BV21_ERROR, ///< may not always be considered an error, but violates a "shall" requirement of Bv2.1
69 /** Codes for errors or warnings from verifying DCPs.
71 * The names should (in general) answer the question "what is wrong?" with an answer that begins "There is a ..."
72 * e.g. "There is a INCORRECT_CPL_HASH"
73 * "There is a MISSING_ASSET"
75 * In general the pattern should be <negative-adjective> <noun>.
76 * Some <negative-adjective>s are:
78 * - INCORRECT: something, which could have any value, is wrong.
79 * - INVALID: something, which should only be one of a set of values, is not in the set, or some preformatted
80 * quantity (e.g. XML) is in the wrong format.
81 * - MISMATCHED: two things, which should be the same, are not.
82 * - EMPTY: something, which should have a value, has no value.
83 * - MISSING: something, which should be present, is not.
84 * - UNEXPECTED: something, which is present, should not be.
85 * - FAILED: some part of the verification failed in some serious way.
87 * Comments should clarify meaning and also say which of the optional fields (e.g. file)
88 * are filled in when this code is used.
91 // If you change the next line, also look in doc/manual/verifier.py in DCP-o-matic
92 // as it looks for it when compiling the manual. Also, in this enum:
93 // [...] will be taken as a reference to a section of Bv2.1
94 // _foo_ means foo should be written as a piece of code
96 /** A general error when reading the DCP
97 * note contains (probably technical) details
100 /** The hash of the CPL in the PKL does not agree with the CPL file
101 * note contains CPL ID
102 * file contains CPL filename
104 MISMATCHED_CPL_HASHES,
105 /** The frame rate given in a reel for the main picture is not 24, 25, 30, 48, 50 or 60
106 * note contains the invalid frame rate as "<numerator>/<denominator>"
108 INVALID_PICTURE_FRAME_RATE,
109 /** The hash of a main picture asset does not agree with the PKL file
110 * file contains the picture asset filename
112 INCORRECT_PICTURE_HASH,
113 /** The hash of a main picture is different in the CPL and PKL
114 * file contains the picture asset filename
116 MISMATCHED_PICTURE_HASHES,
117 /** The hash of a main sound asset does not agree with the PKL file
118 * file contains the sound asset filename
120 INCORRECT_SOUND_HASH,
121 /** The hash of a main sound is different in the CPL and PKL
122 * file contains the sound asset filename
124 MISMATCHED_SOUND_HASHES,
125 /** An assetmap's _<Path>_ entry is empty */
127 /** A file mentioned in an asset map cannot be found
128 * file contains the filename that is missing
131 /** The DCP contains both SMPTE and Interop-standard components */
133 /** Some XML fails to validate against its XSD/DTD
134 * note contains the (probably technical) details
135 * file contains the invalid filename
136 * line contains the line number
139 /** No _ASSETMAP_ or _ASSETMAP.xml_ was found */
141 /** An asset's _IntrinsicDuration_ is less than 1 second
142 * note contains asset ID
144 INVALID_INTRINSIC_DURATION,
145 /** An asset's _Duration_ is less than 1 second
146 * note contains asset ID
149 /** The JPEG2000 data in at least one picture frame is larger than the equivalent of 250Mbit/s
150 * file contains the picture asset filename
152 INVALID_PICTURE_FRAME_SIZE_IN_BYTES,
153 /** The JPEG2000 data in at least one picture frame is larger than the equivalent of 230Mbit/s
154 * file contains the picture asset filename
156 NEARLY_INVALID_PICTURE_FRAME_SIZE_IN_BYTES,
157 /** An asset that the CPL requires is not in this DCP; the DCP may be a VF
158 * note contains the asset ID
161 /** A stereoscopic asset has an MXF which is marked as being monoscopic
162 * file contains the asset filename
164 THREED_ASSET_MARKED_AS_TWOD,
165 /** DCP is Interop, not SMPTE [Bv2.1_6.1] */
167 /** A language or territory does not conform to RFC 5646 [Bv2.1_6.2.1]
168 * note contains the invalid language
171 /** A picture asset does not have one of the required Bv2.1 sizes (in pixels) [Bv2.1_7.1]
172 * note contains the incorrect size as "<width>x<height>"
173 * file contains the asset filename
175 INVALID_PICTURE_SIZE_IN_PIXELS,
176 /** A picture asset is 2K but is not at 24, 25 or 48 fps as required by Bv2.1 [Bv2.1_7.1]
177 * note contains the invalid frame rate as "<numerator>/<denominator>"
178 * file contains the asset filename
180 INVALID_PICTURE_FRAME_RATE_FOR_2K,
181 /** A picture asset is 4K but is not at 24fps as required by Bv2.1 [Bv2.1_7.1]
182 * note contains the invalid frame rate as "<numerator>/<denominator>"
183 * file contains the asset filename
185 INVALID_PICTURE_FRAME_RATE_FOR_4K,
186 /** A picture asset is 4K but is 3D which is not allowed by Bv2.1 [Bv2.1_7.1]
187 * note contains the invalid frame rate as "<numerator>/<denominator>"
188 * file contains the asset filename
190 INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D,
191 /** A closed caption's XML file is larger than 256KB [Bv2.1_7.2.1]
192 * note contains the invalid size in bytes
193 * file contains the asset filename
195 INVALID_CLOSED_CAPTION_XML_SIZE_IN_BYTES,
196 /** Any timed text asset's total files is larger than 115MB [Bv2.1_7.2.1]
197 * note contains the invalid size in bytes
198 * file contains the asset filename
200 INVALID_TIMED_TEXT_SIZE_IN_BYTES,
201 /** The total size of all a timed text asset's fonts is larger than 10MB [Bv2.1_7.2.1]
202 * note contains the invalid size in bytes
203 * file contains the asset filename
205 INVALID_TIMED_TEXT_FONT_SIZE_IN_BYTES,
206 /** Some SMPTE subtitle XML has no _<Language>_ tag [Bv2.1_7.2.2]
207 * file contains the asset filename
209 MISSING_SUBTITLE_LANGUAGE,
210 /** Not all subtitle assets specify the same _<Language>_ tag [Bv2.1_7.2.2] */
211 MISMATCHED_SUBTITLE_LANGUAGES,
212 /** Some SMPTE subtitle XML has no _<StartTime>_ tag [Bv2.1_7.2.3]
213 * file contains the asset filename
215 MISSING_SUBTITLE_START_TIME,
216 /** Some SMPTE subtitle XML has a non-zero _<StartTime>_ tag [Bv2.1_7.2.3]
217 * file contains the asset filename
219 INVALID_SUBTITLE_START_TIME,
220 /** The first subtitle or closed caption happens before 4s into the first reel [Bv2.1_7.2.4] */
221 INVALID_SUBTITLE_FIRST_TEXT_TIME,
222 /** At least one subtitle is less than the minimum of 15 frames suggested by [Bv2.1_7.2.5] */
223 INVALID_SUBTITLE_DURATION,
224 /** At least one pair of subtitles are separated by less than the the minimum of 2 frames suggested by [Bv2.1_7.2.5] */
225 INVALID_SUBTITLE_SPACING,
226 /** A subtitle lasts for longer than the reel which contains it */
227 SUBTITLE_OVERLAPS_REEL_BOUNDARY,
228 /** There are more than 3 subtitle lines in at least one place [Bv2.1_7.2.7] */
229 INVALID_SUBTITLE_LINE_COUNT,
230 /** There are more than 52 characters in at least one subtitle line [Bv2.1_7.2.7] */
231 NEARLY_INVALID_SUBTITLE_LINE_LENGTH,
232 /** There are more than 79 characters in at least one subtitle line [Bv2.1_7.2.7] */
233 INVALID_SUBTITLE_LINE_LENGTH,
234 /** There are more than 3 closed caption lines in at least one place [Bv2.1_7.2.6] */
235 INVALID_CLOSED_CAPTION_LINE_COUNT,
236 /** There are more than 32 characters in at least one closed caption line [Bv2.1_7.2.6] */
237 INVALID_CLOSED_CAPTION_LINE_LENGTH,
238 /** The audio sampling rate must be 48kHz [Bv2.1_7.3]
239 * note contains the invalid frame rate
240 * file contains the asset filename
242 INVALID_SOUND_FRAME_RATE,
243 /** The CPL has no _<AnnotationText>_ tag [Bv2.1_8.1]
244 * note contains the CPL ID
245 * file contains the CPL filename
247 MISSING_CPL_ANNOTATION_TEXT,
248 /** The _<AnnotationText>_ is not the same as the _<ContentTitleText>_ [Bv2.1_8.1]
249 * note contains the CPL ID
250 * file contains the CPL filename
252 MISMATCHED_CPL_ANNOTATION_TEXT,
253 /** At least one asset in a reel does not have the same duration as the others */
254 MISMATCHED_ASSET_DURATION,
255 /** If one reel has a _MainSubtitle_, all must have them */
256 MISSING_MAIN_SUBTITLE_FROM_SOME_REELS,
257 /** If one reel has at least one _ClosedCaption_, all reels must have the same number of _ClosedCaptions_ */
258 MISMATCHED_CLOSED_CAPTION_ASSET_COUNTS,
259 /** MainSubtitle in reels must have _<EntryPoint>_ [Bv2.1_8.3.2]
260 * note contains the asset ID
262 MISSING_SUBTITLE_ENTRY_POINT,
263 /** MainSubtitle _<EntryPoint>_ must be zero [Bv2.1_8.3.2]
264 * note contains the asset ID
266 INCORRECT_SUBTITLE_ENTRY_POINT,
267 /** Closed caption in reels must have _<EntryPoint>_ [Bv2.1_8.3.2]
268 * note contains the asset ID
270 MISSING_CLOSED_CAPTION_ENTRY_POINT,
271 /** Closed caption _MainSubtitle_ _<EntryPoint>_ must be zero [Bv2.1_8.3.2]
272 * note contains the asset ID
274 INCORRECT_CLOSED_CAPTION_ENTRY_POINT,
275 /** _<Hash>_ must be present for assets in CPLs
276 * note contains the asset ID
279 /** If _ContentKind_ is Feature there must be a FFEC marker */
280 MISSING_FFEC_IN_FEATURE,
281 /** If _ContentKind_ is Feature there must be a FFMC marker */
282 MISSING_FFMC_IN_FEATURE,
283 /** There should be a FFOC marker */
285 /** There should be a LFOC marker */
287 /** The FFOC marker should be 1
288 * note contains the incorrect value.
291 /** The LFOC marker should be the last frame in the reel
292 * note contains the incorrect value
295 /** There must be a _<CompositionMetadataAsset>_
296 * note contains the CPL ID
297 * file contains the CPL filename
299 MISSING_CPL_METADATA,
300 /** CPL metadata should contain _<VersionNumber>_ of 1, at least
301 * note contains the CPL ID
302 * file contains the CPL filename
304 MISSING_CPL_METADATA_VERSION_NUMBER,
305 /** There must be an _<ExtensionMetadata>_ in _<CompositionMetadataAsset>_ [Bv2.1_8.6.3]
306 * note contains the CPL ID
307 * file contains the CPL filename
309 MISSING_EXTENSION_METADATA,
310 /** _<ExtensionMetadata>_ does not have the correct form [Bv2.1_8.6.3]
311 * note contains details of what's wrong
312 * file contains the CPL filename
314 INVALID_EXTENSION_METADATA,
315 /** A CPL containing encrypted content is not signed [Bv2.1_8.7]
316 * note contains the CPL ID
317 * file contains the CPL filename
319 UNSIGNED_CPL_WITH_ENCRYPTED_CONTENT,
320 /** A PKL containing encrypted content is not signed [Bv2.1_8.7]
321 * note contains the PKL ID
322 * file contains the PKL filename
324 UNSIGNED_PKL_WITH_ENCRYPTED_CONTENT,
325 /** If a PKL has one CPL its _<ContentTitleText>_ must be the same as the PKL's _<AnnotationText>_
326 * note contains the PKL ID
327 * file contains the PKL filename
329 MISMATCHED_PKL_ANNOTATION_TEXT_WITH_CPL,
330 /** Some, but not all content, is encrypted */
332 /** General error during JPEG2000 codestream verification
333 * note contains details
335 INVALID_JPEG2000_CODESTREAM,
336 /** Invalid number of guard bits in a 2K JPEG2000 stream (should be 1) [Bv2.1_10.2.1]
337 * note contains the number of guard bits
339 INVALID_JPEG2000_GUARD_BITS_FOR_2K,
340 /** Invalid number of guard bits in a 4K JPEG2000 stream (should be 2) [Bv2.1_10.2.1]
341 * note contains the number of guard bits
343 INVALID_JPEG2000_GUARD_BITS_FOR_4K,
344 /** JPEG2000 tile size is not the same as the image size [Bv2.1_10.2.1] */
345 INVALID_JPEG2000_TILE_SIZE,
346 /** JPEG2000 code block width is not 32 [Bv2.1_10.2.1]
347 * note contains the code block width
349 INVALID_JPEG2000_CODE_BLOCK_WIDTH,
350 /** JPEG2000 code block height is not 32 [Bv2.1_10.2.1]
351 * note contains the code block height
353 INVALID_JPEG2000_CODE_BLOCK_HEIGHT,
354 /** There must be no POC markers in a 2K codestream [Bv2.1_10.2.1]
355 * note contains the number of POC markers found
357 INCORRECT_JPEG2000_POC_MARKER_COUNT_FOR_2K,
358 /** There must be exactly one POC marker in a 4K codestream [Bv2.1_10.2.1]
359 * note contains the number of POC markers found
361 INCORRECT_JPEG2000_POC_MARKER_COUNT_FOR_4K,
362 /** A POC marker has incorrect content [Bv2.1_10.2.1]
363 * note contains details
365 INCORRECT_JPEG2000_POC_MARKER,
366 /** A POC marker was found outside the main head [Bv2.1_10.2.1] */
367 INVALID_JPEG2000_POC_MARKER_LOCATION,
368 /** Invalid number of tile parts for 2K JPEG2000 stream (should be 3) [Bv2.1_10.2.1]
369 * note contains the number of tile parts
371 INVALID_JPEG2000_TILE_PARTS_FOR_2K,
372 /** Invalid number of tile parts for 4K JPEG2000 stream (should be 6) [Bv2.1_10.2.1]
373 * note contains the number of tile parts
375 INVALID_JPEG2000_TILE_PARTS_FOR_4K,
376 /** No TLM marker was found [Bv2.1_10.2.1] */
377 MISSING_JPEG200_TLM_MARKER,
378 /** The MXF _ResourceID_ of a timed text resource was not the same as that of the contained XML essence [Bv2.1_10.4.3] */
379 MISMATCHED_TIMED_TEXT_RESOURCE_ID,
380 /** The AssetID of a timed text MXF is the same as its _ResourceID_ or that of the contained XML essence [Bv2.1_10.4.2] */
381 INCORRECT_TIMED_TEXT_ASSET_ID,
382 /** The ContainerDuration of a timed text MXF is not the same as the _Duration_ in its reel [Bv2.1_10.4.3]
383 * note contains the reel duration, followed by a space, followed by the MXF duration
384 * file contains the asset filename
386 MISMATCHED_TIMED_TEXT_DURATION,
387 /** Something could not be verified because content is encrypted and no key is available */
388 MISSED_CHECK_OF_ENCRYPTED,
389 /** Some timed-text XML has an empty <_Text_> node */
391 /** Some closed captions do not have the same vertical alignment within a <_Subtitle_> node */
392 MISMATCHED_CLOSED_CAPTION_VALIGN,
393 /** Some closed captions are not listed in the XML in the order of their vertical position */
394 INCORRECT_CLOSED_CAPTION_ORDERING,
395 /** Some <MainMarkers> asset has an <EntryPoint> that should not be there */
396 UNEXPECTED_ENTRY_POINT,
397 /** Some <MainMarkers> asset has an <Duration> that should not be there */
399 /** A <ContentKind> has been specified with either no scope or the SMPTE 429-7 scope, but which is not one of those allowed */
400 INVALID_CONTENT_KIND,
401 /** Either the width or height of a <MainPictureActiveArea> in a CPL is either not an even number, or bigger than the corresponding asset dimension.
402 * note contains details of what is wrong
403 * file contains the CPL filename
405 INVALID_MAIN_PICTURE_ACTIVE_AREA,
406 /** A PKL has more than one asset with the same ID
407 * note contains the PKL ID
408 * file contains the PKL filename
410 DUPLICATE_ASSET_ID_IN_PKL,
411 /** An ASSETMAP has more than one asset with the same ID
412 * note contains the ASSETMAP ID
413 * file contains the ASSETMAP filename
415 DUPLICATE_ASSET_ID_IN_ASSETMAP,
416 /** An Interop subtitle asset has no subtitles.
417 * note contains the asset ID
418 * file contains the asset filename
421 /** A SMPTE subtitle asset as an <IssueDate> which is not of the form yyyy-mm-ddThh:mm:ss
422 * I can find no reference in a standard to this being required, but the Deluxe delivery
423 * specifications require it and their QC will fail DCPs that don't have it.
424 * note contains the incorrect <IssueDate>
426 INVALID_SUBTITLE_ISSUE_DATE,
427 /** The sound assets in the CPL do not have the same audio channel count.
428 * file contains the filename of the first asset to differ
430 MISMATCHED_SOUND_CHANNEL_COUNTS,
431 /** The CPL contains a MainSoundConfiguration tag which does not describe the number of
432 * channels in the audio assets.
433 * note contains details of what is wrong
434 * file contains the CPL filename
436 INVALID_MAIN_SOUND_CONFIGURATION,
437 /** An interop subtitle file has a <LoadFont> node which refers to a font file that is not found.
438 * note contains the <LoadFont> ID
441 /** A tile part in a JPEG2000 frame is too big.
442 * frame contains the frame index (counted from 0)
443 * component contains the component index (0, 1 or 2)
444 * size contains the invalid size in bytes.
446 INVALID_JPEG2000_TILE_PART_SIZE,
447 /** A subtitle XML root node has more than one namespace (xmlns) declaration.
448 * note contains the asset ID
450 INCORRECT_SUBTITLE_NAMESPACE_COUNT,
451 /** A subtitle or closed caption file has a <Font> tag which refers to a font that is not
452 * first introduced with a <LoadFont>.
453 * id contains the ID of the <Font> tag.
455 MISSING_LOAD_FONT_FOR_FONT,
456 /** A SMPTE subtitle asset has at least one <Text> element but no <LoadFont>
457 * id contains the ID of the subtitle asset.
462 VerificationNote (Type type, Code code)
467 VerificationNote (Type type, Code code, std::string note)
471 _data[Data::NOTE] = note;
474 VerificationNote (Type type, Code code, boost::filesystem::path file)
478 _data[Data::FILE] = file;
481 VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file)
485 _data[Data::NOTE] = note;
486 _data[Data::FILE] = file;
489 VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file, uint64_t line)
493 _data[Data::NOTE] = note;
494 _data[Data::FILE] = file;
495 _data[Data::LINE] = line;
508 NOTE, ///< further information about the error
509 FILE, ///< path of file containing the error
510 LINE, ///< error line number within the FILE
518 boost::optional<T> data(Data key) const
520 auto iter = _data.find(key);
521 if (iter == _data.end()) {
524 return boost::any_cast<T>(iter->second);
528 boost::optional<std::string> note () const {
529 return data<std::string>(Data::NOTE);
532 boost::optional<boost::filesystem::path> file () const {
533 return data<boost::filesystem::path>(Data::FILE);
536 boost::optional<uint64_t> line () const {
537 return data<uint64_t>(Data::LINE);
540 VerificationNote& set_frame(int frame) {
541 _data[Data::FRAME] = frame;
545 boost::optional<int> frame() const {
546 return data<int>(Data::FRAME);
549 VerificationNote& set_component(int component) {
550 _data[Data::COMPONENT] = component;
554 boost::optional<int> component() const {
555 return data<int>(Data::COMPONENT);
558 VerificationNote& set_size(int size) {
559 _data[Data::SIZE] = size;
563 boost::optional<int> size() const {
564 return data<int>(Data::SIZE);
567 VerificationNote& set_id(std::string id) {
568 _data[Data::ID] = id;
572 boost::optional<std::string> id() const {
573 return data<std::string>(Data::ID);
579 std::map<Data, boost::any> _data;
583 struct VerificationOptions
585 ///< If set, any assets larger than this number of bytes will not have their hashes checked
586 boost::optional<boost::uintmax_t> maximum_asset_size_for_hash_check;
587 ///< true to check asset hashes (except those which match maximum_asset_size_for_hash_check)
588 ///< false to check no asset hashes.
589 bool check_asset_hashes = true;
593 std::vector<VerificationNote> verify (
594 std::vector<boost::filesystem::path> directories,
595 boost::function<void (std::string, boost::optional<boost::filesystem::path>)> stage,
596 boost::function<void (float)> progress,
597 VerificationOptions options = {},
598 boost::optional<boost::filesystem::path> xsd_dtd_directory = boost::optional<boost::filesystem::path>()
601 std::string note_to_string (dcp::VerificationNote note);
603 bool operator== (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
604 bool operator< (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
606 std::ostream& operator<<(std::ostream& s, dcp::VerificationNote const& note);