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/filesystem.hpp>
45 #include <boost/function.hpp>
46 #include <boost/optional.hpp>
51 /* Something in windows.h defines this */
58 class VerificationNote
63 BV21_ERROR, ///< may not always be considered an error, but violates a "shall" requirement of Bv2.1
67 /** Codes for errors or warnings from verifying DCPs.
69 * The names should (in general) answer the question "what is wrong?" with an answer that begins "There is a ..."
70 * e.g. "There is a INCORRECT_CPL_HASH"
71 * "There is a MISSING_ASSET"
73 * In general the pattern should be <negative-adjective> <noun>.
74 * Some <negative-adjective>s are:
76 * - INCORRECT: something, which could have any value, is wrong.
77 * - INVALID: something, which should only be one of a set of values, is not in the set, or some preformatted
78 * quantity (e.g. XML) is in the wrong format.
79 * - MISMATCHED: two things, which should be the same, are not.
80 * - EMPTY: something, which should have a value, has no value.
81 * - MISSING: something, which should be present, is not.
82 * - UNEXPECTED: something, which is present, should not be.
83 * - FAILED: some part of the verification failed in some serious way.
85 * Comments should clarify meaning and also say which of the optional fields (e.g. file)
86 * are filled in when this code is used.
89 // If you change the next line, also look in doc/manual/verifier.py in DCP-o-matic
90 // as it looks for it when compiling the manual. Also, in this enum:
91 // [...] will be taken as a reference to a section of Bv2.1
92 // _foo_ means foo should be written as a piece of code
94 /** A general error when reading the DCP
95 * note contains (probably technical) details
98 /** The hash of the CPL in the PKL does not agree with the CPL file
99 * note contains CPL ID
100 * file contains CPL filename
102 MISMATCHED_CPL_HASHES,
103 /** The frame rate given in a reel for the main picture is not 24, 25, 30, 48, 50 or 60
104 * note contains the invalid frame rate as "<numerator>/<denominator>"
106 INVALID_PICTURE_FRAME_RATE,
107 /** The hash of a main picture asset does not agree with the PKL file
108 * file contains the picture asset filename
110 INCORRECT_PICTURE_HASH,
111 /** The hash of a main picture is different in the CPL and PKL
112 * file contains the picture asset filename
114 MISMATCHED_PICTURE_HASHES,
115 /** The hash of a main sound asset does not agree with the PKL file
116 * file contains the sound asset filename
118 INCORRECT_SOUND_HASH,
119 /** The hash of a main sound is different in the CPL and PKL
120 * file contains the sound asset filename
122 MISMATCHED_SOUND_HASHES,
123 /** An assetmap's _<Path>_ entry is empty */
125 /** A file mentioned in an asset map cannot be found
126 * file contains the filename that is missing
129 /** The DCP contains both SMPTE and Interop-standard components */
131 /** Some XML fails to validate against its XSD/DTD
132 * note contains the (probably technical) details
133 * file contains the invalid filename
134 * line contains the line number
137 /** No _ASSETMAP_ or _ASSETMAP.xml_ was found */
139 /** An asset's _IntrinsicDuration_ is less than 1 second
140 * note contains asset ID
142 INVALID_INTRINSIC_DURATION,
143 /** An asset's _Duration_ is less than 1 second
144 * note contains asset ID
147 /** The JPEG2000 data in at least one picture frame is larger than the equivalent of 250Mbit/s
148 * file contains the picture asset filename
150 INVALID_PICTURE_FRAME_SIZE_IN_BYTES,
151 /** The JPEG2000 data in at least one picture frame is larger than the equivalent of 230Mbit/s
152 * file contains the picture asset filename
154 NEARLY_INVALID_PICTURE_FRAME_SIZE_IN_BYTES,
155 /** An asset that the CPL requires is not in this DCP; the DCP may be a VF
156 * note contains the asset ID
159 /** A stereoscopic asset has an MXF which is marked as being monoscopic
160 * file contains the asset filename
162 THREED_ASSET_MARKED_AS_TWOD,
163 /** DCP is Interop, not SMPTE [Bv2.1_6.1] */
165 /** A language or territory does not conform to RFC 5646 [Bv2.1_6.2.1]
166 * note contains the invalid language
169 /** A picture asset does not have one of the required Bv2.1 sizes (in pixels) [Bv2.1_7.1]
170 * note contains the incorrect size as "<width>x<height>"
171 * file contains the asset filename
173 INVALID_PICTURE_SIZE_IN_PIXELS,
174 /** A picture asset is 2K but is not at 24, 25 or 48 fps as required by Bv2.1 [Bv2.1_7.1]
175 * note contains the invalid frame rate as "<numerator>/<denominator>"
176 * file contains the asset filename
178 INVALID_PICTURE_FRAME_RATE_FOR_2K,
179 /** A picture asset is 4K but is not at 24fps as required by Bv2.1 [Bv2.1_7.1]
180 * note contains the invalid frame rate as "<numerator>/<denominator>"
181 * file contains the asset filename
183 INVALID_PICTURE_FRAME_RATE_FOR_4K,
184 /** A picture asset is 4K but is 3D which is not allowed by Bv2.1 [Bv2.1_7.1]
185 * note contains the invalid frame rate as "<numerator>/<denominator>"
186 * file contains the asset filename
188 INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D,
189 /** A closed caption's XML file is larger than 256KB [Bv2.1_7.2.1]
190 * note contains the invalid size in bytes
191 * file contains the asset filename
193 INVALID_CLOSED_CAPTION_XML_SIZE_IN_BYTES,
194 /** Any timed text asset's total files is larger than 115MB [Bv2.1_7.2.1]
195 * note contains the invalid size in bytes
196 * file contains the asset filename
198 INVALID_TIMED_TEXT_SIZE_IN_BYTES,
199 /** The total size of all a timed text asset's fonts is larger than 10MB [Bv2.1_7.2.1]
200 * note contains the invalid size in bytes
201 * file contains the asset filename
203 INVALID_TIMED_TEXT_FONT_SIZE_IN_BYTES,
204 /** Some SMPTE subtitle XML has no _<Language>_ tag [Bv2.1_7.2.2]
205 * file contains the asset filename
207 MISSING_SUBTITLE_LANGUAGE,
208 /** Not all subtitle assets specify the same _<Language>_ tag [Bv2.1_7.2.2] */
209 MISMATCHED_SUBTITLE_LANGUAGES,
210 /** Some SMPTE subtitle XML has no _<StartTime>_ tag [Bv2.1_7.2.3]
211 * file contains the asset filename
213 MISSING_SUBTITLE_START_TIME,
214 /** Some SMPTE subtitle XML has a non-zero _<StartTime>_ tag [Bv2.1_7.2.3]
215 * file contains the asset filename
217 INVALID_SUBTITLE_START_TIME,
218 /** The first subtitle or closed caption happens before 4s into the first reel [Bv2.1_7.2.4] */
219 INVALID_SUBTITLE_FIRST_TEXT_TIME,
220 /** At least one subtitle is less than the minimum of 15 frames suggested by [Bv2.1_7.2.5] */
221 INVALID_SUBTITLE_DURATION,
222 /** At least one pair of subtitles are separated by less than the the minimum of 2 frames suggested by [Bv2.1_7.2.5] */
223 INVALID_SUBTITLE_SPACING,
224 /** A subtitle lasts for longer than the reel which contains it */
225 SUBTITLE_OVERLAPS_REEL_BOUNDARY,
226 /** There are more than 3 subtitle lines in at least one place [Bv2.1_7.2.7] */
227 INVALID_SUBTITLE_LINE_COUNT,
228 /** There are more than 52 characters in at least one subtitle line [Bv2.1_7.2.7] */
229 NEARLY_INVALID_SUBTITLE_LINE_LENGTH,
230 /** There are more than 79 characters in at least one subtitle line [Bv2.1_7.2.7] */
231 INVALID_SUBTITLE_LINE_LENGTH,
232 /** There are more than 3 closed caption lines in at least one place [Bv2.1_7.2.6] */
233 INVALID_CLOSED_CAPTION_LINE_COUNT,
234 /** There are more than 32 characters in at least one closed caption line [Bv2.1_7.2.6] */
235 INVALID_CLOSED_CAPTION_LINE_LENGTH,
236 /** The audio sampling rate must be 48kHz [Bv2.1_7.3]
237 * note contains the invalid frame rate
238 * file contains the asset filename
240 INVALID_SOUND_FRAME_RATE,
241 /** The CPL has no _<AnnotationText>_ tag [Bv2.1_8.1]
242 * note contains the CPL ID
243 * file contains the CPL filename
245 MISSING_CPL_ANNOTATION_TEXT,
246 /** The _<AnnotationText>_ is not the same as the _<ContentTitleText>_ [Bv2.1_8.1]
247 * note contains the CPL ID
248 * file contains the CPL filename
250 MISMATCHED_CPL_ANNOTATION_TEXT,
251 /** At least one asset in a reel does not have the same duration as the others */
252 MISMATCHED_ASSET_DURATION,
253 /** If one reel has a _MainSubtitle_, all must have them */
254 MISSING_MAIN_SUBTITLE_FROM_SOME_REELS,
255 /** If one reel has at least one _ClosedCaption_, all reels must have the same number of _ClosedCaptions_ */
256 MISMATCHED_CLOSED_CAPTION_ASSET_COUNTS,
257 /** MainSubtitle in reels must have _<EntryPoint>_ [Bv2.1_8.3.2]
258 * note contains the asset ID
260 MISSING_SUBTITLE_ENTRY_POINT,
261 /** MainSubtitle _<EntryPoint>_ must be zero [Bv2.1_8.3.2]
262 * note contains the asset ID
264 INCORRECT_SUBTITLE_ENTRY_POINT,
265 /** Closed caption in reels must have _<EntryPoint>_ [Bv2.1_8.3.2]
266 * note contains the asset ID
268 MISSING_CLOSED_CAPTION_ENTRY_POINT,
269 /** Closed caption _MainSubtitle_ _<EntryPoint>_ must be zero [Bv2.1_8.3.2]
270 * note contains the asset ID
272 INCORRECT_CLOSED_CAPTION_ENTRY_POINT,
273 /** _<Hash>_ must be present for assets in CPLs
274 * note contains the asset ID
277 /** If _ContentKind_ is Feature there must be a FFEC marker */
278 MISSING_FFEC_IN_FEATURE,
279 /** If _ContentKind_ is Feature there must be a FFMC marker */
280 MISSING_FFMC_IN_FEATURE,
281 /** There should be a FFOC marker */
283 /** There should be a LFOC marker */
285 /** The FFOC marker should be 1
286 * note contains the incorrect value.
289 /** The LFOC marker should be the last frame in the reel
290 * note contains the incorrect value
293 /** There must be a _<CompositionMetadataAsset>_
294 * note contains the CPL ID
295 * file contains the CPL filename
297 MISSING_CPL_METADATA,
298 /** CPL metadata should contain _<VersionNumber>_ of 1, at least
299 * note contains the CPL ID
300 * file contains the CPL filename
302 MISSING_CPL_METADATA_VERSION_NUMBER,
303 /** There must be an _<ExtensionMetadata>_ in _<CompositionMetadataAsset>_ [Bv2.1_8.6.3]
304 * note contains the CPL ID
305 * file contains the CPL filename
307 MISSING_EXTENSION_METADATA,
308 /** _<ExtensionMetadata>_ does not have the correct form [Bv2.1_8.6.3]
309 * note contains details of what's wrong
310 * file contains the CPL filename
312 INVALID_EXTENSION_METADATA,
313 /** A CPL containing encrypted content is not signed [Bv2.1_8.7]
314 * note contains the CPL ID
315 * file contains the CPL filename
317 UNSIGNED_CPL_WITH_ENCRYPTED_CONTENT,
318 /** A PKL containing encrypted content is not signed [Bv2.1_8.7]
319 * note contains the PKL ID
320 * file contains the PKL filename
322 UNSIGNED_PKL_WITH_ENCRYPTED_CONTENT,
323 /** If a PKL has one CPL its _<ContentTitleText>_ must be the same as the PKL's _<AnnotationText>_
324 * note contains the PKL ID
325 * file contains the PKL filename
327 MISMATCHED_PKL_ANNOTATION_TEXT_WITH_CPL,
328 /** Some, but not all content, is encrypted */
330 /** General error during JPEG2000 codestream verification
331 * note contains details
333 INVALID_JPEG2000_CODESTREAM,
334 /** Invalid number of guard bits in a 2K JPEG2000 stream (should be 1) [Bv2.1_10.2.1]
335 * note contains the number of guard bits
337 INVALID_JPEG2000_GUARD_BITS_FOR_2K,
338 /** Invalid number of guard bits in a 4K JPEG2000 stream (should be 2) [Bv2.1_10.2.1]
339 * note contains the number of guard bits
341 INVALID_JPEG2000_GUARD_BITS_FOR_4K,
342 /** JPEG2000 tile size is not the same as the image size [Bv2.1_10.2.1] */
343 INVALID_JPEG2000_TILE_SIZE,
344 /** JPEG2000 code block width is not 32 [Bv2.1_10.2.1]
345 * note contains the code block width
347 INVALID_JPEG2000_CODE_BLOCK_WIDTH,
348 /** JPEG2000 code block height is not 32 [Bv2.1_10.2.1]
349 * note contains the code block height
351 INVALID_JPEG2000_CODE_BLOCK_HEIGHT,
352 /** There must be no POC markers in a 2K codestream [Bv2.1_10.2.1]
353 * note contains the number of POC markers found
355 INCORRECT_JPEG2000_POC_MARKER_COUNT_FOR_2K,
356 /** There must be exactly one POC marker in a 4K codestream [Bv2.1_10.2.1]
357 * note contains the number of POC markers found
359 INCORRECT_JPEG2000_POC_MARKER_COUNT_FOR_4K,
360 /** A POC marker has incorrect content [Bv2.1_10.2.1]
361 * note contains details
363 INCORRECT_JPEG2000_POC_MARKER,
364 /** A POC marker was found outside the main head [Bv2.1_10.2.1] */
365 INVALID_JPEG2000_POC_MARKER_LOCATION,
366 /** Invalid number of tile parts for 2K JPEG2000 stream (should be 3) [Bv2.1_10.2.1]
367 * note contains the number of tile parts
369 INVALID_JPEG2000_TILE_PARTS_FOR_2K,
370 /** Invalid number of tile parts for 4K JPEG2000 stream (should be 6) [Bv2.1_10.2.1]
371 * note contains the number of tile parts
373 INVALID_JPEG2000_TILE_PARTS_FOR_4K,
374 /** No TLM marker was found [Bv2.1_10.2.1] */
375 MISSING_JPEG200_TLM_MARKER,
376 /** The MXF _ResourceID_ of a timed text resource was not the same as that of the contained XML essence [Bv2.1_10.4.3] */
377 MISMATCHED_TIMED_TEXT_RESOURCE_ID,
378 /** 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] */
379 INCORRECT_TIMED_TEXT_ASSET_ID,
380 /** The ContainerDuration of a timed text MXF is not the same as the _Duration_ in its reel [Bv2.1_10.4.3]
381 * note contains the reel duration, followed by a space, followed by the MXF duration
382 * file contains the asset filename
384 MISMATCHED_TIMED_TEXT_DURATION,
385 /** Something could not be verified because content is encrypted and no key is available */
386 MISSED_CHECK_OF_ENCRYPTED,
387 /** Some timed-text XML has an empty <_Text_> node */
389 /** Some closed captions do not have the same vertical alignment within a <_Subtitle_> node */
390 MISMATCHED_CLOSED_CAPTION_VALIGN,
391 /** Some closed captions are not listed in the XML in the order of their vertical position */
392 INCORRECT_CLOSED_CAPTION_ORDERING,
393 /** Some <MainMarkers> asset has an <EntryPoint> that should not be there */
394 UNEXPECTED_ENTRY_POINT,
395 /** Some <MainMarkers> asset has an <Duration> that should not be there */
397 /** A <ContentKind> has been specified with either no scope or the SMPTE 429-7 scope, but which is not one of those allowed */
398 INVALID_CONTENT_KIND,
399 /** Either the width or height of a <MainPictureActiveArea> in a CPL is either not an even number, or bigger than the corresponding asset dimension.
400 * note contains details of what is wrong
401 * file contains the CPL filename
403 INVALID_MAIN_PICTURE_ACTIVE_AREA,
404 /** A PKL has more than one asset with the same ID
405 * note contains the PKL ID
406 * file contains the PKL filename
408 DUPLICATE_ASSET_ID_IN_PKL,
409 /** An ASSETMAP has more than one asset with the same ID
410 * note contains the ASSETMAP ID
411 * file contains the ASSETMAP filename
413 DUPLICATE_ASSET_ID_IN_ASSETMAP,
414 /** An Interop subtitle asset has no subtitles.
415 * note contains the asset ID
416 * file contains the asset filename
419 /** A SMPTE subtitle asset as an <IssueDate> which is not of the form yyyy-mm-ddThh:mm:ss
420 * I can find no reference in a standard to this being required, but the Deluxe delivery
421 * specifications require it and their QC will fail DCPs that don't have it.
422 * note contains the incorrect <IssueDate>
424 INVALID_SUBTITLE_ISSUE_DATE
427 VerificationNote (Type type, Code code)
432 VerificationNote (Type type, Code code, std::string note)
438 VerificationNote (Type type, Code code, boost::filesystem::path file)
444 VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file)
451 VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file, uint64_t line)
467 boost::optional<std::string> note () const {
471 boost::optional<boost::filesystem::path> file () const {
475 boost::optional<uint64_t> line () const {
482 /** Further information about the error, if applicable */
483 boost::optional<std::string> _note;
484 /** Path of file containing the error, if applicable */
485 boost::optional<boost::filesystem::path> _file;
486 /** Error line number within _file, if applicable */
487 boost::optional<uint64_t> _line;
491 struct VerificationOptions
493 ///< If set, any assets larger than this number of bytes will not have their hashes checked
494 boost::optional<boost::uintmax_t> maximum_asset_size_for_hash_check;
495 ///< true to check asset hashes (except those which match maximum_asset_size_for_hash_check)
496 ///< false to check no asset hashes.
497 bool check_asset_hashes = true;
501 std::vector<VerificationNote> verify (
502 std::vector<boost::filesystem::path> directories,
503 boost::function<void (std::string, boost::optional<boost::filesystem::path>)> stage,
504 boost::function<void (float)> progress,
505 VerificationOptions options = {},
506 boost::optional<boost::filesystem::path> xsd_dtd_directory = boost::optional<boost::filesystem::path>()
509 std::string note_to_string (dcp::VerificationNote note);
511 bool operator== (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
512 bool operator< (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
514 std::ostream& operator<<(std::ostream& s, dcp::VerificationNote const& note);