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