7bfe4217c5f934cc77ac8725003363ea0727bcd4
[libdcp.git] / src / verify.h
1 /*
2     Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
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.
10
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.
15
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/>.
18
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
23     including the two.
24
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.
32 */
33
34
35 /** @file  src/verify.h
36  *  @brief dcp::verify() method and associated code
37  */
38
39
40 #ifndef LIBDCP_VERIFY_H
41 #define LIBDCP_VERIFY_H
42
43
44 #include "decrypted_kdm.h"
45 #include <boost/any.hpp>
46 #include <boost/filesystem.hpp>
47 #include <boost/function.hpp>
48 #include <boost/optional.hpp>
49 #include <map>
50 #include <string>
51 #include <vector>
52
53
54 /* windows.h defines this but we want to use it */
55 #undef ERROR
56
57
58 namespace dcp {
59
60
61 class VerificationNote
62 {
63 public:
64         enum class Type {
65                 ERROR,
66                 BV21_ERROR, ///< may not always be considered an error, but violates a "shall" requirement of Bv2.1
67                 WARNING
68         };
69
70         /** Codes for errors or warnings from verifying DCPs.
71          *
72          *  The names should (in general) answer the question "what is wrong?" with an answer that begins "There is a ..."
73          *  e.g. "There is a INCORRECT_CPL_HASH"
74          *       "There is a MISSING_ASSET"
75          *
76          *  In general the pattern should be <negative-adjective> <noun>.
77          *  Some <negative-adjective>s are:
78          *
79          *  - INCORRECT: something, which could have any value, is wrong.
80          *  - INVALID: something, which should only be one of a set of values, is not in the set, or some preformatted
81          *             quantity (e.g. XML) is in the wrong format.
82          *  - MISMATCHED: two things, which should be the same, are not.
83          *  - EMPTY: something, which should have a value, has no value.
84          *  - MISSING: something, which should be present, is not.
85          *  - UNEXPECTED: something, which is present, should not be.
86          *  - FAILED: some part of the verification failed in some serious way.
87          *
88          *  Comments should clarify meaning and also say which of the optional fields (e.g. file)
89          *  are filled in when this code is used.
90          */
91
92         // If you change the next line, also look in doc/manual/verifier.py in DCP-o-matic
93         // as it looks for it when compiling the manual.  Also, in this enum:
94         //   [...]  will be taken as a reference to a section of Bv2.1
95         //   _foo_  means foo should be written as a piece of code
96         enum class Code {
97                 /** A general error when reading the DCP
98                  *  note contains (probably technical) details
99                  */
100                 FAILED_READ,
101                 /** The hash of the CPL in the PKL does not agree with the CPL file
102                  *  note contains CPL ID
103                  *  file contains CPL filename
104                  */
105                 MISMATCHED_CPL_HASHES,
106                 /** The frame rate given in a reel for the main picture is not 24, 25, 30, 48, 50 or 60
107                  *  note contains the invalid frame rate as "<numerator>/<denominator>"
108                  */
109                 INVALID_PICTURE_FRAME_RATE,
110                 /** The hash of a main picture asset does not agree with the PKL file
111                  *  file contains the picture asset filename
112                  */
113                 INCORRECT_PICTURE_HASH,
114                 /** The hash of a main picture is different in the CPL and PKL
115                  *  file contains the picture asset filename
116                  */
117                 MISMATCHED_PICTURE_HASHES,
118                 /** The hash of a main sound asset does not agree with the PKL file
119                  *  file contains the sound asset filename
120                  */
121                 INCORRECT_SOUND_HASH,
122                 /** The hash of a main sound is different in the CPL and PKL
123                  *  file contains the sound asset filename
124                  */
125                 MISMATCHED_SOUND_HASHES,
126                 /** An assetmap's _<Path>_ entry is empty */
127                 EMPTY_ASSET_PATH,
128                 /** A file mentioned in an asset map cannot be found
129                  *  file contains the filename that is missing
130                  */
131                 MISSING_ASSET,
132                 /** The DCP contains both SMPTE and Interop-standard components */
133                 MISMATCHED_STANDARD,
134                 /** Some XML fails to validate against its XSD/DTD
135                  *  note contains the (probably technical) details
136                  *  file contains the invalid filename
137                  *  line contains the line number
138                  */
139                 INVALID_XML,
140                 /** No _ASSETMAP_ or _ASSETMAP.xml_ was found */
141                 MISSING_ASSETMAP,
142                 /** An asset's _IntrinsicDuration_ is less than 1 second
143                  *  note contains asset ID
144                  */
145                 INVALID_INTRINSIC_DURATION,
146                 /** An asset's _Duration_ is less than 1 second
147                  *  note contains asset ID
148                  */
149                 INVALID_DURATION,
150                 /** The JPEG2000 data in at least one picture frame is larger than the equivalent of 250Mbit/s
151                  *  file contains the picture asset filename
152                  */
153                 INVALID_PICTURE_FRAME_SIZE_IN_BYTES,
154                 /** The JPEG2000 data in at least one picture frame is larger than the equivalent of 230Mbit/s
155                  *  file contains the picture asset filename
156                  */
157                 NEARLY_INVALID_PICTURE_FRAME_SIZE_IN_BYTES,
158                 /** An asset that the CPL requires is not in this DCP; the DCP may be a VF
159                  *  note contains the asset ID
160                  */
161                 EXTERNAL_ASSET,
162                 /** A stereoscopic asset has an MXF which is marked as being monoscopic
163                  *  file contains the asset filename
164                  */
165                 THREED_ASSET_MARKED_AS_TWOD,
166                 /** DCP is Interop, not SMPTE [Bv2.1_6.1] */
167                 INVALID_STANDARD,
168                 /** A language or territory does not conform to RFC 5646 [Bv2.1_6.2.1]
169                  *  note contains the invalid language
170                  */
171                 INVALID_LANGUAGE,
172                 /** A picture asset does not have one of the required Bv2.1 sizes (in pixels) [Bv2.1_7.1]
173                  *  note contains the incorrect size as "<width>x<height>"
174                  *  file contains the asset filename
175                  */
176                 INVALID_PICTURE_SIZE_IN_PIXELS,
177                 /** A picture asset is 2K but is not at 24, 25 or 48 fps as required by Bv2.1 [Bv2.1_7.1]
178                  *  note contains the invalid frame rate as "<numerator>/<denominator>"
179                  *  file contains the asset filename
180                  */
181                 INVALID_PICTURE_FRAME_RATE_FOR_2K,
182                 /** A picture asset is 4K but is not at 24fps as required by Bv2.1 [Bv2.1_7.1]
183                  *  note contains the invalid frame rate as "<numerator>/<denominator>"
184                  *  file contains the asset filename
185                  */
186                 INVALID_PICTURE_FRAME_RATE_FOR_4K,
187                 /** A picture asset is 4K but is 3D which is not allowed by Bv2.1 [Bv2.1_7.1]
188                  *  note contains the invalid frame rate as "<numerator>/<denominator>"
189                  *  file contains the asset filename
190                  */
191                 INVALID_PICTURE_ASSET_RESOLUTION_FOR_3D,
192                 /** A closed caption's XML file is larger than 256KB [Bv2.1_7.2.1]
193                  *  note contains the invalid size in bytes
194                  *  file contains the asset filename
195                  */
196                 INVALID_CLOSED_CAPTION_XML_SIZE_IN_BYTES,
197                 /** Any timed text asset's total files is larger than 115MB [Bv2.1_7.2.1]
198                  *  note contains the invalid size in bytes
199                  *  file contains the asset filename
200                  */
201                 INVALID_TIMED_TEXT_SIZE_IN_BYTES,
202                 /** The total size of all a timed text asset's fonts is larger than 10MB [Bv2.1_7.2.1]
203                  *  note contains the invalid size in bytes
204                  *  file contains the asset filename
205                  */
206                 INVALID_TIMED_TEXT_FONT_SIZE_IN_BYTES,
207                 /** Some SMPTE subtitle XML has no _<Language>_ tag [Bv2.1_7.2.2]
208                  *  file contains the asset filename
209                  */
210                 MISSING_SUBTITLE_LANGUAGE,
211                 /** Not all subtitle assets specify the same _<Language>_ tag [Bv2.1_7.2.2] */
212                 MISMATCHED_SUBTITLE_LANGUAGES,
213                 /** Some SMPTE subtitle XML has no _<StartTime>_ tag [Bv2.1_7.2.3]
214                  *  file contains the asset filename
215                  */
216                 MISSING_SUBTITLE_START_TIME,
217                 /** Some SMPTE subtitle XML has a non-zero _<StartTime>_ tag [Bv2.1_7.2.3]
218                  *  file contains the asset filename
219                  */
220                 INVALID_SUBTITLE_START_TIME,
221                 /** The first subtitle or closed caption happens before 4s into the first reel [Bv2.1_7.2.4] */
222                 INVALID_SUBTITLE_FIRST_TEXT_TIME,
223                 /** At least one subtitle is less than the minimum of 15 frames suggested by [Bv2.1_7.2.5] */
224                 INVALID_SUBTITLE_DURATION,
225                 /** At least one pair of subtitles are separated by less than the the minimum of 2 frames suggested by [Bv2.1_7.2.5] */
226                 INVALID_SUBTITLE_SPACING,
227                 /** A subtitle lasts for longer than the reel which contains it */
228                 SUBTITLE_OVERLAPS_REEL_BOUNDARY,
229                 /** There are more than 3 subtitle lines in at least one place [Bv2.1_7.2.7] */
230                 INVALID_SUBTITLE_LINE_COUNT,
231                 /** There are more than 52 characters in at least one subtitle line [Bv2.1_7.2.7] */
232                 NEARLY_INVALID_SUBTITLE_LINE_LENGTH,
233                 /** There are more than 79 characters in at least one subtitle line [Bv2.1_7.2.7] */
234                 INVALID_SUBTITLE_LINE_LENGTH,
235                 /** There are more than 3 closed caption lines in at least one place [Bv2.1_7.2.6] */
236                 INVALID_CLOSED_CAPTION_LINE_COUNT,
237                 /** There are more than 32 characters in at least one closed caption line [Bv2.1_7.2.6] */
238                 INVALID_CLOSED_CAPTION_LINE_LENGTH,
239                 /** The audio sampling rate must be 48kHz [Bv2.1_7.3]
240                  *  note contains the invalid frame rate
241                  *  file contains the asset filename
242                  */
243                 INVALID_SOUND_FRAME_RATE,
244                 /** The CPL has no _<AnnotationText>_ tag [Bv2.1_8.1]
245                  *  note contains the CPL ID
246                  *  file contains the CPL filename
247                  */
248                 MISSING_CPL_ANNOTATION_TEXT,
249                 /** The _<AnnotationText>_ is not the same as the _<ContentTitleText>_ [Bv2.1_8.1]
250                  *  note contains the CPL ID
251                  *  file contains the CPL filename
252                  */
253                 MISMATCHED_CPL_ANNOTATION_TEXT,
254                 /** At least one asset in a reel does not have the same duration as the others */
255                 MISMATCHED_ASSET_DURATION,
256                 /** If one reel has a _MainSubtitle_, all must have them */
257                 MISSING_MAIN_SUBTITLE_FROM_SOME_REELS,
258                 /** If one reel has at least one _ClosedCaption_, all reels must have the same number of _ClosedCaptions_ */
259                 MISMATCHED_CLOSED_CAPTION_ASSET_COUNTS,
260                 /** MainSubtitle in reels must have _<EntryPoint>_ [Bv2.1_8.3.2]
261                  *  note contains the asset ID
262                  */
263                 MISSING_SUBTITLE_ENTRY_POINT,
264                 /** MainSubtitle _<EntryPoint>_ must be zero [Bv2.1_8.3.2]
265                  *  note contains the asset ID
266                  */
267                 INCORRECT_SUBTITLE_ENTRY_POINT,
268                 /** Closed caption in reels must have _<EntryPoint>_ [Bv2.1_8.3.2]
269                  *  note contains the asset ID
270                  */
271                 MISSING_CLOSED_CAPTION_ENTRY_POINT,
272                 /** Closed caption _MainSubtitle_ _<EntryPoint>_ must be zero [Bv2.1_8.3.2]
273                  *  note contains the asset ID
274                  */
275                 INCORRECT_CLOSED_CAPTION_ENTRY_POINT,
276                 /** _<Hash>_ must be present for assets in CPLs
277                  * note contains the asset ID
278                  */
279                 MISSING_HASH,
280                 /** If _ContentKind_ is Feature there must be a FFEC marker */
281                 MISSING_FFEC_IN_FEATURE,
282                 /** If _ContentKind_ is Feature there must be a FFMC marker */
283                 MISSING_FFMC_IN_FEATURE,
284                 /** There should be a FFOC marker */
285                 MISSING_FFOC,
286                 /** There should be a LFOC marker */
287                 MISSING_LFOC,
288                 /** The FFOC marker should be 1
289                  *  note contains the incorrect value.
290                  */
291                 INCORRECT_FFOC,
292                 /** The LFOC marker should be the last frame in the reel
293                  *  note contains the incorrect value
294                  */
295                 INCORRECT_LFOC,
296                 /** There must be a _<CompositionMetadataAsset>_
297                  *  note contains the CPL ID
298                  *  file contains the CPL filename
299                  */
300                 MISSING_CPL_METADATA,
301                 /** CPL metadata should contain _<VersionNumber>_ of 1, at least
302                  *  note contains the CPL ID
303                  *  file contains the CPL filename
304                  */
305                 MISSING_CPL_METADATA_VERSION_NUMBER,
306                 /** There must be an _<ExtensionMetadata>_ in _<CompositionMetadataAsset>_ [Bv2.1_8.6.3]
307                  *  note contains the CPL ID
308                  *  file contains the CPL filename
309                  */
310                 MISSING_EXTENSION_METADATA,
311                 /** _<ExtensionMetadata>_ does not have the correct form [Bv2.1_8.6.3]
312                  *  note contains details of what's wrong
313                  *  file contains the CPL filename
314                  */
315                 INVALID_EXTENSION_METADATA,
316                 /** A CPL containing encrypted content is not signed [Bv2.1_8.7]
317                  *  note contains the CPL ID
318                  *  file contains the CPL filename
319                  */
320                 UNSIGNED_CPL_WITH_ENCRYPTED_CONTENT,
321                 /** A PKL containing encrypted content is not signed [Bv2.1_8.7]
322                  *  note contains the PKL ID
323                  *  file contains the PKL filename
324                  */
325                 UNSIGNED_PKL_WITH_ENCRYPTED_CONTENT,
326                 /** If a PKL has one CPL its _<ContentTitleText>_ must be the same as the PKL's _<AnnotationText>_
327                  *  note contains the PKL ID
328                  *  file contains the PKL filename
329                  */
330                 MISMATCHED_PKL_ANNOTATION_TEXT_WITH_CPL,
331                 /** Some, but not all content, is encrypted */
332                 PARTIALLY_ENCRYPTED,
333                 /** General error during JPEG2000 codestream verification
334                  *  frame contains the frame index (counted from 0)
335                  *  note contains details
336                  */
337                 INVALID_JPEG2000_CODESTREAM,
338                 /** Invalid number of guard bits in a 2K JPEG2000 stream (should be 1) [Bv2.1_10.2.1]
339                  *  note contains the number of guard bits
340                  */
341                 INVALID_JPEG2000_GUARD_BITS_FOR_2K,
342                 /** Invalid number of guard bits in a 4K JPEG2000 stream (should be 2) [Bv2.1_10.2.1]
343                  *  note contains the number of guard bits
344                  */
345                 INVALID_JPEG2000_GUARD_BITS_FOR_4K,
346                 /** JPEG2000 tile size is not the same as the image size [Bv2.1_10.2.1] */
347                 INVALID_JPEG2000_TILE_SIZE,
348                 /** JPEG2000 code block width is not 32 [Bv2.1_10.2.1]
349                  *  note contains the code block width
350                  */
351                 INVALID_JPEG2000_CODE_BLOCK_WIDTH,
352                 /** JPEG2000 code block height is not 32 [Bv2.1_10.2.1]
353                  *  note contains the code block height
354                  */
355                 INVALID_JPEG2000_CODE_BLOCK_HEIGHT,
356                 /** There must be no POC markers in a 2K codestream [Bv2.1_10.2.1]
357                  *  note contains the number of POC markers found
358                  */
359                 INCORRECT_JPEG2000_POC_MARKER_COUNT_FOR_2K,
360                 /** There must be exactly one POC marker in a 4K codestream [Bv2.1_10.2.1]
361                  *  note contains the number of POC markers found
362                  */
363                 INCORRECT_JPEG2000_POC_MARKER_COUNT_FOR_4K,
364                 /** A POC marker has incorrect content [Bv2.1_10.2.1]
365                  *  note contains details
366                  */
367                 INCORRECT_JPEG2000_POC_MARKER,
368                 /** A POC marker was found outside the main head [Bv2.1_10.2.1] */
369                 INVALID_JPEG2000_POC_MARKER_LOCATION,
370                 /** Invalid number of tile parts for 2K JPEG2000 stream (should be 3) [Bv2.1_10.2.1]
371                  *  note contains the number of tile parts
372                  */
373                 INVALID_JPEG2000_TILE_PARTS_FOR_2K,
374                 /** Invalid number of tile parts for 4K JPEG2000 stream (should be 6) [Bv2.1_10.2.1]
375                  *  note contains the number of tile parts
376                  */
377                 INVALID_JPEG2000_TILE_PARTS_FOR_4K,
378                 /** No TLM marker was found [Bv2.1_10.2.1] */
379                 MISSING_JPEG200_TLM_MARKER,
380                 /** The MXF _ResourceID_ of a timed text resource was not the same as that of the contained XML essence [Bv2.1_10.4.3] */
381                 MISMATCHED_TIMED_TEXT_RESOURCE_ID,
382                 /** 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] */
383                 INCORRECT_TIMED_TEXT_ASSET_ID,
384                 /** The ContainerDuration of a timed text MXF is not the same as the _Duration_ in its reel [Bv2.1_10.4.3]
385                  *  note contains the reel duration, followed by a space, followed by the MXF duration
386                  *  file contains the asset filename
387                  */
388                 MISMATCHED_TIMED_TEXT_DURATION,
389                 /** Something could not be verified because content is encrypted and no key is available */
390                 MISSED_CHECK_OF_ENCRYPTED,
391                 /** Some timed-text XML has an empty <_Text_> node */
392                 EMPTY_TEXT,
393                 /** Some closed captions do not have the same vertical alignment within a <_Subtitle_> node */
394                 MISMATCHED_CLOSED_CAPTION_VALIGN,
395                 /** Some closed captions are not listed in the XML in the order of their vertical position */
396                 INCORRECT_CLOSED_CAPTION_ORDERING,
397                 /** Some <MainMarkers> asset has an <EntryPoint> that should not be there */
398                 UNEXPECTED_ENTRY_POINT,
399                 /** Some <MainMarkers> asset has an <Duration> that should not be there */
400                 UNEXPECTED_DURATION,
401                 /** A <ContentKind> has been specified with either no scope or the SMPTE 429-7 scope, but which is not one of those allowed */
402                 INVALID_CONTENT_KIND,
403                 /** Either the width or height of a <MainPictureActiveArea> in a CPL is either not an even number, or bigger than the corresponding asset dimension.
404                  *  note contains details of what is wrong
405                  *  file contains the CPL filename
406                  */
407                 INVALID_MAIN_PICTURE_ACTIVE_AREA,
408                 /** A PKL has more than one asset with the same ID
409                  *  note contains the PKL ID
410                  *  file contains the PKL filename
411                  */
412                 DUPLICATE_ASSET_ID_IN_PKL,
413                 /** An ASSETMAP has more than one asset with the same ID
414                  *  note contains the ASSETMAP ID
415                  *  file contains the ASSETMAP filename
416                  */
417                 DUPLICATE_ASSET_ID_IN_ASSETMAP,
418                 /** An Interop subtitle asset has no subtitles
419                  *  note contains the asset ID
420                  *  file contains the asset filename
421                  */
422                 MISSING_SUBTITLE,
423                 /** A SMPTE subtitle asset as an <IssueDate> which is not of the form yyyy-mm-ddThh:mm:ss
424                  *  I can find no reference in a standard to this being required, but the Deluxe delivery
425                  *  specifications require it and their QC will fail DCPs that don't have it.
426                  *  note contains the incorrect <IssueDate>
427                  */
428                 INVALID_SUBTITLE_ISSUE_DATE,
429                 /** The sound assets in the CPL do not have the same audio channel count.
430                  *  file contains the filename of the first asset to differ
431                  */
432                 MISMATCHED_SOUND_CHANNEL_COUNTS,
433                 /** The CPL contains a MainSoundConfiguration tag which does not describe the number of
434                  *  channels in the audio assets.
435                  *  note contains details of what is wrong
436                  *  file contains the CPL filename
437                  */
438                 INVALID_MAIN_SOUND_CONFIGURATION,
439                 /** An interop subtitle file has a <LoadFont> node which refers to a font file that is not found.
440                  *  note contains the <LoadFont> ID
441                  */
442                 MISSING_FONT,
443                 /** A tile part in a JPEG2000 frame is too big.
444                  *  frame contains the frame index (counted from 0)
445                  *  component contains the component index (0, 1 or 2)
446                  *  size contains the invalid size in bytes.
447                  */
448                 INVALID_JPEG2000_TILE_PART_SIZE,
449                 /** A subtitle XML root node has more than one namespace (xmlns) declaration.
450                  *  note contains the asset ID
451                  */
452                 INCORRECT_SUBTITLE_NAMESPACE_COUNT,
453                 /** A subtitle or closed caption file has a <Font> tag which refers to a font that is not
454                  *  first introduced with a <LoadFont>.
455                  *  id contains the ID of the <Font> tag.
456                  */
457                 MISSING_LOAD_FONT_FOR_FONT,
458                 /** A SMPTE subtitle asset has at least one <Text> element but no <LoadFont>
459                  *  id contains the ID of the subtitle asset.
460                  */
461                 MISSING_LOAD_FONT,
462                 /** An ID in an asset map does not match the ID obtained from reading the actual file.
463                  *  id contains the ID from the asset map.
464                  *  other_id contains the ID from the file.
465                  */
466                 MISMATCHED_ASSET_MAP_ID,
467                 /** The <LabelText> inside a <ContentVersion> is empty
468                  *  note contains the CPL ID
469                  *  file contains the CPL filename
470                  */
471                 EMPTY_CONTENT_VERSION_LABEL_TEXT,
472         };
473
474         VerificationNote (Type type, Code code)
475                 : _type (type)
476                 , _code (code)
477         {}
478
479         VerificationNote (Type type, Code code, std::string note)
480                 : _type (type)
481                 , _code (code)
482         {
483                 _data[Data::NOTE] = note;
484         }
485
486         VerificationNote (Type type, Code code, boost::filesystem::path file)
487                 : _type (type)
488                 , _code (code)
489         {
490                 _data[Data::FILE] = file;
491         }
492
493         VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file)
494                 : _type (type)
495                 , _code (code)
496         {
497                 _data[Data::NOTE] = note;
498                 _data[Data::FILE] = file;
499         }
500
501         VerificationNote (Type type, Code code, std::string note, boost::filesystem::path file, uint64_t line)
502                 : _type (type)
503                 , _code (code)
504         {
505                 _data[Data::NOTE] = note;
506                 _data[Data::FILE] = file;
507                 _data[Data::LINE] = line;
508         }
509
510         Type type () const {
511                 return _type;
512         }
513
514         Code code () const {
515                 return _code;
516         }
517
518 private:
519         enum class Data {
520                 NOTE,  ///< further information about the error
521                 FILE,  ///< path of file containing the error
522                 LINE,  ///< error line number within the FILE
523                 FRAME,
524                 COMPONENT,
525                 SIZE,
526                 ID,
527                 OTHER_ID,
528                 FRAME_RATE
529         };
530
531         template <class T>
532         boost::optional<T> data(Data key) const
533         {
534                 auto iter = _data.find(key);
535                 if (iter == _data.end()) {
536                         return {};
537                 }
538                 return boost::any_cast<T>(iter->second);
539         }
540
541 public:
542         boost::optional<std::string> note () const {
543                 return data<std::string>(Data::NOTE);
544         }
545
546         boost::optional<boost::filesystem::path> file () const {
547                 return data<boost::filesystem::path>(Data::FILE);
548         }
549
550         boost::optional<uint64_t> line () const {
551                 return data<uint64_t>(Data::LINE);
552         }
553
554         VerificationNote& set_frame(int frame) {
555                 _data[Data::FRAME] = frame;
556                 return *this;
557         }
558
559         boost::optional<int> frame() const {
560                 return data<int>(Data::FRAME);
561         }
562
563         VerificationNote& set_component(int component) {
564                 _data[Data::COMPONENT] = component;
565                 return *this;
566         }
567
568         boost::optional<int> component() const {
569                 return data<int>(Data::COMPONENT);
570         }
571
572         VerificationNote& set_size(int size) {
573                 _data[Data::SIZE] = size;
574                 return *this;
575         }
576
577         boost::optional<int> size() const {
578                 return data<int>(Data::SIZE);
579         }
580
581         VerificationNote& set_id(std::string id) {
582                 _data[Data::ID] = id;
583                 return *this;
584         }
585
586         boost::optional<std::string> id() const {
587                 return data<std::string>(Data::ID);
588         }
589
590         VerificationNote& set_other_id(std::string other_id) {
591                 _data[Data::OTHER_ID] = other_id;
592                 return *this;
593         }
594
595         boost::optional<std::string> other_id() const {
596                 return data<std::string>(Data::OTHER_ID);
597         }
598
599         VerificationNote& set_frame_rate(int frame_rate) {
600                 _data[Data::FRAME_RATE] = frame_rate;
601                 return *this;
602         }
603
604         boost::optional<int> frame_rate() const {
605                 return data<int>(Data::FRAME_RATE);
606         }
607
608 private:
609         Type _type;
610         Code _code;
611         std::map<Data, boost::any> _data;
612 };
613
614
615 struct VerificationOptions
616 {
617         ///< If set, any assets larger than this number of bytes will not have their hashes checked
618         boost::optional<boost::uintmax_t> maximum_asset_size_for_hash_check;
619         ///< true to check asset hashes (except those which match maximum_asset_size_for_hash_check)
620         ///< false to check no asset hashes.
621         bool check_asset_hashes = true;
622 };
623
624
625 std::vector<VerificationNote> verify (
626         std::vector<boost::filesystem::path> directories,
627         std::vector<dcp::DecryptedKDM> kdms,
628         boost::function<void (std::string, boost::optional<boost::filesystem::path>)> stage,
629         boost::function<void (float)> progress,
630         VerificationOptions options = {},
631         boost::optional<boost::filesystem::path> xsd_dtd_directory = boost::optional<boost::filesystem::path>()
632         );
633
634 std::string note_to_string (dcp::VerificationNote note);
635
636 bool operator== (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
637 bool operator< (dcp::VerificationNote const& a, dcp::VerificationNote const& b);
638
639 std::ostream& operator<<(std::ostream& s, dcp::VerificationNote const& note);
640
641
642 }
643
644
645 #endif