-
Notifications
You must be signed in to change notification settings - Fork 0
/
MXFDump.cpp
7114 lines (6254 loc) · 181 KB
/
MXFDump.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=---------------------------------------------------------------------=
//
// The contents of this file are subject to the AAF SDK Public Source
// License Agreement Version 2.0 (the "License"); You may not use this
// file except in compliance with the License. The License is available
// in AAFSDKPSL.TXT, or you may obtain a copy of the License from the
// Advanced Media Workflow Association, Inc., or its successor.
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
// the License for the specific language governing rights and limitations
// under the License. Refer to Section 3.3 of the License for proper use
// of this Exhibit.
//
// WARNING: Please contact the Advanced Media Workflow Association,
// Inc., for more information about any additional licenses to
// intellectual property covering the AAF Standard that may be required
// to create and distribute AAF compliant products.
// (http://www.amwa.tv/policies).
//
// Copyright Notices:
// The Original Code of this file is Copyright 1998-2009, licensor of the
// Advanced Media Workflow Association. All rights reserved.
//
// The Initial Developer of the Original Code of this file and the
// licensor of the Advanced Media Workflow Association is
// Avid Technology.
// All rights reserved.
//
//=---------------------------------------------------------------------=
// KLV/MXF file dumper.
//
// Tim Bingham - October 2002 - [email protected]
// This program is deliberately constructed as one file with no dependencies
// so that it can easily be ported to a new host. You'll be able to make some
// progress understanding an MXF file even if all you have is this source and
// a C++ compiler.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#if defined (_MSC_VER) && defined(_M_IX86) && defined(_WIN32)
#define MXF_COMPILER_MSC_INTEL_WINDOWS
#define MXF_OS_WINDOWS
#elif defined (_MSC_VER) && defined(_M_X64) && defined(_WIN32)
#define MXF_COMPILER_MSC_X64_WINDOWS
#define MXF_OS_WINDOWS
#elif defined(__GNUC__) && defined(__i386__) && defined(_WIN32)
#define MXF_COMPILER_GCC_INTEL_WINDOWS
#define MXF_OS_WINDOWS
#elif defined(__GNUC__) && defined(__i386__) && defined(__linux__)
#define MXF_COMPILER_GCC_INTEL_LINUX
#define MXF_OS_UNIX
#elif defined(__GNUC__) && defined(__x86_64__) && defined(__linux__)
#define MXF_COMPILER_GCC_X86_64_LINUX
#define MXF_OS_UNIX
#elif defined(__MWERKS__) && defined(__POWERPC__) && defined(macintosh)
#define MXF_COMPILER_MWERKS_PPC_MACOS
#define MXF_OS_MACOS
#elif defined(__MWERKS__) && defined(__MACH__)
#define MXF_COMPILER_MWERKS_PPC_MACOSX
#define MXF_OS_MACOSX
#elif defined(__GNUC__) && defined(__ppc__) && defined(__APPLE__)
#define MXF_COMPILER_GCC_PPC_MACOSX
#define MXF_OS_MACOSX
#elif defined(__GNUC__) && defined(__i386__) && defined(__APPLE__)
#define MXF_COMPILER_GCC_INTEL_MACOSX
#define MXF_OS_MACOSX
#elif defined(__GNUC__) && defined(__x86_64__) && defined(__APPLE__)
#define MXF_COMPILER_GCC_INTEL_X86_64_MACOSX
#define MXF_OS_MACOSX
#elif defined(__GNUC__) && defined(__powerpc__) && defined(__linux__)
#define MXF_COMPILER_GCC_PPC_LINUX
#define MXF_OS_UNIX
#elif defined(__GNUC__) && defined(__arm__) && defined(__linux__)
#define MXF_COMPILER_GCC_ARM_LINUX
#define MXF_OS_UNIX
#elif defined(__GNUC__) && defined(__aarch64__) && defined(__linux__)
#define MXF_COMPILER_GCC_AARCH64_LINUX
#define MXF_OS_UNIX
#elif defined(mips) && defined(sgi)
#define MXF_COMPILER_SGICC_MIPS_SGI
#define MXF_OS_UNIX
#elif defined(__GNUC__) && defined(__i386__) && defined(__FreeBSD__)
#define MXF_COMPILER_GCC_INTEL_FREEBSD
#define MXF_OS_UNIX
#elif defined(__GNUC__) && defined(__i386__) && defined(__CYGWIN__)
#define MXF_COMPILER_GCC_INTEL_CYGWIN
#define MXF_OS_UNIX
#elif defined(__GNUC__) && defined(__sparc__) && defined(__sun__)
#define MXF_COMPILER_GCC_SPARC_SUNOS
#define MXF_OS_UNIX
#elif defined(__GNUC__) && defined(__x86_64__) && defined(_WIN32)
#define MXF_COMPILER_GCC_INTEL_WINDOWS
#define MXF_OS_WINDOWS
#else
#error "Unknown compiler"
#endif
#if defined(MXF_OS_MACOS)
#define MXF_USE_CONSOLE
#endif
#if defined(MXF_USE_CONSOLE)
#include <console.h>
#endif
#if defined(MXF_COMPILER_MSC_INTEL_WINDOWS)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned int mxfUInt32;
typedef unsigned __int64 mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "u"
#define MXFPRIu64 "I64u"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "x"
#define MXFPRIx64 "I64x"
#elif defined(MXF_COMPILER_MSC_X64_WINDOWS)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned int mxfUInt32;
typedef unsigned __int64 mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "u"
#define MXFPRIu64 "I64u"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "x"
#define MXFPRIx64 "I64x"
#elif defined(MXF_COMPILER_GCC_INTEL_WINDOWS)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_INTEL_LINUX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_X86_64_LINUX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "u"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "x"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_MWERKS_PPC_MACOS)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_MWERKS_PPC_MACOSX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_PPC_MACOSX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_INTEL_MACOSX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_INTEL_X86_64_MACOSX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "u"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "x"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_PPC_LINUX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_ARM_LINUX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_AARCH64_LINUX)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_SGICC_MIPS_SGI)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_INTEL_FREEBSD)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_INTEL_CYGWIN)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#elif defined(MXF_COMPILER_GCC_SPARC_SUNOS)
typedef unsigned char mxfUInt08;
typedef unsigned short int mxfUInt16;
typedef unsigned long int mxfUInt32;
typedef unsigned long long int mxfUInt64;
#define MXFPRIu08 "u"
#define MXFPRIu16 "hu"
#define MXFPRIu32 "lu"
#define MXFPRIu64 "llu"
#define MXFPRIx08 "x"
#define MXFPRIx16 "hx"
#define MXFPRIx32 "lx"
#define MXFPRIx64 "llx"
#endif
#if defined(MXF_COMPILER_MSC_INTEL_WINDOWS)
// - 'identifier' : identifier was truncated to 'number' characters in
// the debug information
#pragma warning(disable:4786) // Gak !
#endif
#include <list>
#include <map>
typedef mxfUInt64 mxfLength;
typedef mxfUInt08 mxfByte;
struct mxfKey {
mxfByte octet0;
mxfByte octet1;
mxfByte octet2;
mxfByte octet3;
mxfByte octet4;
mxfByte octet5;
mxfByte octet6;
mxfByte octet7;
mxfByte octet8;
mxfByte octet9;
mxfByte octet10;
mxfByte octet11;
mxfByte octet12;
mxfByte octet13;
mxfByte octet14;
mxfByte octet15;
};
typedef mxfUInt16 mxfLocalKey;
struct aafUID {
mxfUInt32 Data1;
mxfUInt16 Data2;
mxfUInt16 Data3;
mxfUInt08 Data4[8];
};
struct mxfRational {
mxfUInt32 numerator;
mxfUInt32 denominator;
};
typedef enum ModeTag {
unspecifiedMode,
klvMode,
localSetMode,
mxfMode,
aafMode,
klvValidateMode,
setValidateMode,
mxfValidateMode,
aafValidateMode} Mode;
Mode mode = unspecifiedMode;
mxfKey nullMxfKey = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
bool reorder(void);
mxfUInt08 hostByteOrder(void);
// Primitives
#if defined(MXF_OS_WINDOWS)
#include <windows.h>
typedef HANDLE mxfFile;
#elif defined(MXF_OS_MACOSX) && defined(__i386__)
#include <CoreServices/CoreServices.h>
typedef SInt16 mxfFile;
#else
typedef FILE* mxfFile;
#endif
int mxfExitStatus(int status);
mxfFile openExistingRead(char* fileName);
void close(mxfFile infile);
void setPosition(mxfFile infile, const mxfUInt64 position);
mxfUInt64 position(mxfFile infile);
size_t read(mxfFile infile, void* buffer, size_t count);
mxfUInt64 size(mxfFile infile);
void skipBytes(const mxfUInt64 byteCount, mxfFile infile);
void readMxfUInt08(mxfByte& b, mxfFile infile);
void readMxfUInt16(mxfUInt16& i, mxfFile infile);
void readMxfUInt32(mxfUInt32& i, mxfFile infile);
void readMxfUInt64(mxfUInt64& i, mxfFile infile);
void readMxfRational(mxfRational& r, mxfFile infile);
void readMxfLabel(mxfKey& k, mxfFile infile);
void readMxfKey(mxfKey& k, mxfFile infile);
bool readOuterMxfKey(mxfKey& k, mxfFile infile);
int readBERLength(mxfUInt64& i, mxfUInt08& ll, mxfFile infile);
int readMxfLength(mxfLength& l, mxfUInt08& ll, mxfFile infile);
void readMxfLocalKey(mxfLocalKey& k, mxfFile infile);
void reorder(mxfUInt16& i);
void reorder(mxfUInt32& i);
void reorder(mxfUInt64& i);
void reorder(aafUID& u);
void printDecField(FILE* f, mxfUInt08& i);
void printDecField(FILE* f, mxfUInt16& i);
void printDecField(FILE* f, mxfUInt32& i);
void printDecField(FILE* f, mxfUInt64& i);
void printSignedDecField(FILE* f, mxfUInt08& i);
void printDecFieldPad(FILE* f, mxfUInt08& i);
void printDecFieldPad(FILE* f, mxfUInt16& i);
void printDecFieldPad(FILE* f, mxfUInt32& i);
void printDecFieldPad(FILE* f, mxfUInt64& i);
void printDec(FILE* f, mxfUInt08& i);
void printDec(FILE* f, mxfUInt16& i);
void printDec(FILE* f, mxfUInt32& i);
void printDec(FILE* f, mxfUInt64& i);
void printHexField(FILE* f, mxfUInt08& i);
void printHexField(FILE* f, mxfUInt16& i);
void printHexField(FILE* f, mxfUInt32& i);
void printHexField(FILE* f, mxfUInt64& i);
void printHexFieldPad(FILE* f, mxfUInt08& i);
void printHexFieldPad(FILE* f, mxfUInt16& i);
void printHexFieldPad(FILE* f, mxfUInt32& i);
void printHexFieldPad(FILE* f, mxfUInt64& i);
void printHex(FILE* f, mxfUInt08& i);
void printHex(FILE* f, mxfUInt16& i);
void printHex(FILE* f, mxfUInt32& i);
void printHex(FILE* f, mxfUInt64& i);
void printMxfKey(const mxfKey& k, FILE* f);
void printMxfLength(mxfLength& l, FILE* f);
void printMxfLocalKey(mxfLocalKey& k, FILE* f);
void printMxfUInt08(FILE* f, const char* label, mxfUInt08& i);
void printMxfUInt16(FILE* f, const char* label, mxfUInt16& i);
void printMxfUInt32(FILE* f, const char* label, mxfUInt32& i);
void printMxfUInt64(FILE* f, const char* label, mxfUInt64& i);
void printMxfRational(FILE* f, const char* label, mxfRational& r);
void printMxfKey(FILE* f, const char* label, mxfKey& k);
void dumpMxfUInt08(const char* label, mxfFile infile);
void dumpMxfUInt16(const char* label, mxfFile infile);
void dumpMxfUInt32(const char* label, mxfFile infile);
void dumpMxfUInt64(const char* label, mxfFile infile);
void dumpMxfRational(const char* label, mxfFile infile);
void dumpMxfBoolean(const char* label,
const char* trueLabel,
const char* falseLabel,
mxfFile infile);
void dumpMxfString(const char* label, mxfFile infile);
void dumpOptionalMxfString(const char* label, mxfFile infile);
void dumpMxfLabel(const char* label, mxfFile infile);
void dumpMxfOperationalPattern(const char* label, mxfFile infile);
void dumpMxfUInt08Array(const char* label, size_t count, mxfFile infile);
void printOperationalPattern(mxfKey& k, FILE* outfile);
void klvDumpFile(mxfFile infile);
void setDumpFile(mxfFile infile);
void mxfDumpFile(mxfFile infile);
void aafDumpFile(mxfFile infile);
bool lookupMXFKey(mxfKey& k, size_t& index);
bool lookupAAFKey(mxfKey& k, size_t& index);
bool findAAFKey(mxfKey& k, size_t& index, char** flag);
bool lookupMXFLocalKey(mxfLocalKey& k, size_t& index);
void checkLocalKeyTable(void);
bool lookupAAFLocalKey(mxfLocalKey& k, size_t& index);
void checkAAFLocalKeyTable(void);
const char* aafKeyName(const mxfKey& k);
const char* mxfKeyName(const mxfKey& k);
bool isEssenceElement(mxfKey& k);
bool isIndexSegment(mxfKey& k);
void checkKey(mxfKey& k);
bool isNullKey(const mxfKey& k);
bool isDark(mxfKey& k, Mode mode);
bool isFill(mxfKey& k);
bool isPartition(mxfKey& key);
bool isHeader(mxfKey& key);
bool isFooter(mxfKey& key);
bool isClosed(const mxfKey& key);
bool isComplete(const mxfKey& key);
bool isRandomIndex(const mxfKey& key);
bool isPrivateLabel(mxfKey& key);
void printPrivateLabelName(mxfKey& k, FILE* outfile);
void printPrivateLabel(mxfKey& k, FILE* outfile);
const char* keyName(const mxfKey& key);
void checkFill(const mxfKey& key,
mxfUInt64 keyPosition,
const mxfKey& previousKey);
void printFill(mxfKey& k, mxfLength& len, mxfFile infile);
void skipV(mxfLength length, mxfFile infile);
void checkPartitionLength(mxfUInt64& length);
// Size of the fixed portion of a partition
mxfUInt64 partitionFixedSize =
sizeof(mxfUInt16) + // Major Version
sizeof(mxfUInt16) + // Minor Version
sizeof(mxfUInt32) + // KAGSize
sizeof(mxfUInt64) + // ThisPartition
sizeof(mxfUInt64) + // PreviousPartition
sizeof(mxfUInt64) + // FooterPartition
sizeof(mxfUInt64) + // HeaderByteCount
sizeof(mxfUInt64) + // IndexByteCount
sizeof(mxfUInt32) + // IndexSID
sizeof(mxfUInt64) + // BodyOffset
sizeof(mxfUInt32) + // BodySID
sizeof(mxfKey) + // Operational pattern
sizeof(mxfUInt32) + // Essence container label count
sizeof(mxfUInt32); // Essence container label size
void print(const char* format, ...);
void vprint(const char* format, va_list ap);
void error(const char* format, ...);
void verror(const char* format, va_list ap);
void fatalError(const char* format, ...);
void warning(const char* format, ...);
void vwarning(const char* format, va_list ap);
void message(const char* format, ...);
void vmessage(const char* format, va_list ap);
const char* baseName(const char* fullName);
void setProgramName(const char* programName);
char* programName(void);
void mxfError(const char* format, ...);
void vmxfError(const char* format, va_list ap);
void mxfWarning(const char* format, ...);
void vmxfWarning(const char* format, va_list ap);
void mxfWarning(const mxfKey& key, mxfUInt64 keyPosition, const char* format, ...);
void vmxfWarning(const mxfKey& key,
mxfUInt64 keyPosition,
const char* format,
va_list ap);
void mxfError(const mxfKey& key, mxfUInt64 keyPosition, const char* format, ...);
void vmxfError(const mxfKey& key,
mxfUInt64 keyPosition,
const char* format,
va_list ap);
void printLocation(const mxfKey& key, mxfUInt64 keyPosition);
void print(const char* format, ...)
{
va_list ap;
va_start(ap, format);
vprint(format, ap);
va_end(ap);
}
void vprint(const char* format, va_list ap)
{
vfprintf(stderr, format, ap);
}
void error(const char* format, ...)
{
va_list ap;
va_start(ap, format);
verror(format, ap);
va_end(ap);
}
void verror(const char* format, va_list ap)
{
fprintf(stderr, "%s : Error : ", programName());
vfprintf(stderr, format, ap);
}
void fatalError(const char* format, ...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s : Error : ", programName());
vfprintf(stderr, format, ap);
exit(EXIT_FAILURE);
va_end(ap);
}
void warning(const char* format, ...)
{
va_list ap;
va_start(ap, format);
vwarning(format, ap);
va_end(ap);
}
void vwarning(const char* format, va_list ap)
{
fprintf(stderr, "%s : Warning : ", programName());
vfprintf(stderr, format, ap);
}
void message(const char* format, ...)
{
va_list ap;
va_start(ap, format);
vmessage(format, ap);
va_end(ap);
}
void vmessage(const char* format, va_list ap)
{
fprintf(stderr, "%s : ", programName());
vfprintf(stderr, format, ap);
}
char progName[FILENAME_MAX];
void setProgramName(const char* programName)
{
const char* base = baseName(programName);
const char* suffix = strrchr(base, '.');
size_t length;
if (suffix != 0) {
length = suffix - base;
} else {
length = strlen(base);
}
if (length >= FILENAME_MAX) {
length = FILENAME_MAX - 1;
}
strncpy(progName, base, length);
progName[length] = '\0';
}
char* programName(void)
{
return progName;
}
mxfUInt32 errors = 0;
void mxfError(const char* format, ...)
{
va_list ap;
va_start(ap, format);
vmxfError(format, ap);
va_end(ap);
}
void vmxfError(const char* format, va_list ap)
{
verror(format, ap);
errors = errors + 1;
if (errors >= 100) {
error("Too many errors (%" MXFPRIu32 ") encountered - giving up.\n", errors);
exit(mxfExitStatus(EXIT_FAILURE));
}
}
mxfUInt32 warnings = 0;
void mxfWarning(const char* format, ...)
{
va_list ap;
va_start(ap, format);
vmxfWarning(format, ap);
va_end(ap);
}
void vmxfWarning(const char* format, va_list ap)
{
vwarning(format, ap);
warnings = warnings + 1;
}
void mxfWarning(const mxfKey& key, mxfUInt64 keyPosition, const char* format, ...)
{
va_list ap;
va_start(ap, format);
vmxfWarning(key, keyPosition, format, ap);
va_end(ap);
}
void vmxfWarning(const mxfKey& key,
mxfUInt64 keyPosition,
const char* format,
va_list ap)
{
vmxfWarning(format, ap);
printLocation(key, keyPosition);
}
void mxfError(const mxfKey& key, mxfUInt64 keyPosition, const char* format, ...)
{
va_list ap;
va_start(ap, format);
vmxfError(key, keyPosition, format, ap);
va_end(ap);
}
void vmxfError(const mxfKey& key,
mxfUInt64 keyPosition,
const char* format, va_list ap)
{
vmxfError(format, ap);
printLocation(key, keyPosition);
}
void printLocation(const mxfKey& key, mxfUInt64 keyPosition)
{
const char *name = keyName(key);
print(" (following %s key at offset 0x%" MXFPRIx64 ").\n",
name,
keyPosition);
}
void missingProperty(const mxfKey& key,
mxfUInt64 keyPosition,
const char* label);
void missingProperty(const mxfKey& key,
mxfUInt64 keyPosition,
const char* label)
{
mxfError(key,
keyPosition,
"Required property \"%s\" missing",
label);
}
bool verbose = false;
bool debug = false;
mxfUInt64 keyPosition; // position/address of current key
mxfKey currentKey = nullMxfKey;
mxfKey previousKey = nullMxfKey;
mxfUInt64 primerPosition = 0;
mxfKey currentPartitionKey = nullMxfKey;
mxfKey previousPartitionKey = nullMxfKey;
bool inIndex = false;
mxfUInt32 indexSID = 0;
mxfKey indexLabel = nullMxfKey;
mxfUInt64 indexPosition = 0;
bool inEssence = false;
mxfUInt32 essenceSID = 0;
mxfKey essenceLabel = nullMxfKey;
mxfUInt64 essencePosition = 0;
mxfUInt64 fillStart = 0;
mxfUInt64 fillEnd = 0;
void markMetadataStart(mxfUInt64 primerKeyPosition);
void markMetadataEnd(mxfUInt64 endKeyPosition);
void markIndexStart(mxfUInt32 sid, mxfUInt64 indexKeyPosition);
void markIndexEnd(mxfUInt64 endKeyPosition);
void markEssenceSegmentStart(mxfUInt32 sid, mxfUInt64 essenceKeyPosition);
void markEssenceSegmentEnd(mxfUInt64 endKeyPosition);
void markFill(mxfUInt64 fillKeyPosition,
mxfUInt64 fillEndPosition);
void newSegment(bool isEssence,
mxfUInt32 sid,
mxfKey& label,
mxfUInt64 start,
mxfUInt64 size,
mxfUInt64 free);
void newEssenceSegment(mxfUInt32 sid,
mxfKey& label,
mxfUInt64 start,
mxfUInt64 size,
mxfUInt64 free);
void newIndexSegment(mxfUInt32 sid,
mxfKey& label,
mxfUInt64 start,
mxfUInt64 size,
mxfUInt64 free);
// Frame wrapped essence
bool frames = false; // if true, treat essence as frame wrapped.
bool iFlag = false; // if true, only print maxFrames frames
mxfUInt32 maxFrames = 0;
// Frame index tables
bool cFlag = true; // if true, only print maxIndex entries
mxfUInt32 maxIndex = 0;
// Essence elements
bool lFlag = false; // if true, limit/no-limit specified on command line
bool limitBytes = false; // if true, only print limit bytes
mxfUInt32 limit = 0;
mxfUInt32 runInLimit = 64 * 1024;
// Help
bool hFlag = false;
#if defined(MXF_OS_WINDOWS)
mxfFile openExistingRead(char* fileName)
{
HANDLE result = CreateFile(fileName,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
0,
0);
if (result == INVALID_HANDLE_VALUE) {
result = 0;
}
return result;
}
void close(mxfFile infile)
{
BOOL result = CloseHandle(infile);
if (!result) {
fatalError("CloseHandle() failed.\n");
}
}
void setPosition(mxfFile infile, const mxfUInt64 position)
{
LARGE_INTEGER li;
li.QuadPart = position;
li.LowPart = SetFilePointer(infile, li.LowPart, &li.HighPart, FILE_BEGIN);
if ((li.LowPart == INVALID_SET_FILE_POINTER) && GetLastError() != NO_ERROR) {
fatalError("SetFilePointer() failed.\n");
}
}
size_t read(mxfFile infile, void* buffer, size_t count)
{
DWORD bytesRead;
BOOL result = ReadFile(infile, buffer, count, &bytesRead, 0);
if (!result) {
fatalError("ReadFile() failed.\n");
}
return bytesRead;
}
mxfUInt64 position(mxfFile infile)
{
mxfUInt64 result;
LARGE_INTEGER li;
li.QuadPart = 0;
li.LowPart = SetFilePointer(infile, li.LowPart, &li.HighPart, FILE_CURRENT);
if ((li.LowPart == INVALID_SET_FILE_POINTER) && GetLastError() != NO_ERROR) {
fatalError("SetFilePointer() failed.\n");
}
result = li.QuadPart;
return result;
}
mxfUInt64 size(mxfFile infile)
{
mxfUInt64 result;
ULARGE_INTEGER li;
li.LowPart = GetFileSize(infile, &li.HighPart);
if ((li.LowPart == INVALID_FILE_SIZE) && GetLastError() != NO_ERROR) {
fatalError("GetFileSize() failed.\n");
}
result = li.QuadPart;
return result;
}
#elif defined(MXF_OS_MACOSX) && defined(__i386__)
mxfFile openExistingRead(char* fileName)
{
const UInt8* name = reinterpret_cast<UInt8*>(fileName);
FSRef fref;
OSErr status = FSPathMakeRef(name, &fref, 0);
if (status != noErr) {
fatalError("FSPathMakeRef() failed (%d).\n", status);
}
HFSUniStr255 fkName;
status = FSGetDataForkName(&fkName);
if (status != noErr) {
fatalError("FSGetDataForkName() failed (%d).\n", status);
}
SInt16 result;
status = FSOpenFork(&fref, fkName.length, fkName.unicode, fsRdPerm, &result);
if (status != noErr) {
fatalError("FSOpenFork() failed (%d).\n", status);
}
return result;
}
void close(mxfFile infile)
{
OSErr status = FSCloseFork(infile);
if (status != noErr) {
fatalError("FSCloseFork() failed (%d).\n", status);
}
}
void setPosition(mxfFile infile, const mxfUInt64 position)
{
SInt64 pos = position;
OSErr status = FSSetForkPosition(infile, fsFromStart, pos);
if (status != noErr) {
fatalError("FSSetForkPosition() failed (%d).\n", status);
}
}
size_t read(mxfFile infile, void* buffer, size_t count)
{
ByteCount bytesRead;
OSErr status = FSReadFork(infile, fsAtMark, 0, count, buffer, &bytesRead);
if ((status != eofErr) && (status != noErr)) {
fatalError("FSReadFork() failed (%d).\n", status);
}
return bytesRead;
}
mxfUInt64 position(mxfFile infile)