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