-
Notifications
You must be signed in to change notification settings - Fork 4
/
mp4tree.c
1895 lines (1624 loc) · 57.5 KB
/
mp4tree.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <ctype.h>
#include <inttypes.h>
#include "common.h"
#include "mp4tree.h"
#include "atom-desc.h"
#include "nal.h"
#include "options.h"
/*
******************************************************************************
* Defines *
******************************************************************************
*/
#define array_len(_a) (sizeof(_a)/sizeof(_a[0]))
/*
******************************************************************************
* Types *
******************************************************************************
*/
typedef struct mp4tree_box_map_struct
{
char type[4];
mp4tree_parse_func func;
} mp4tree_box_map_t;
static struct mp4_data
{
// Simplified - could differ per track
int per_sample_iv_size;
int constant_iv_size;
} g_mp4_data;
static mp4tree_parse_func mdat_printer = NULL;
/*
******************************************************************************
* Function declarations *
******************************************************************************
*/
static mp4tree_parse_func
mp4tree_box_printer_get(const uint8_t *p);
/*
******************************************************************************
* Utility functions *
******************************************************************************
*/
static inline const uint8_t *
mp4tree_get_box_type(const uint8_t * p)
{
return p + 4;
}
void
mp4tree_hexdump(
const uint8_t * p,
size_t len,
int depth)
{
size_t i;
size_t truncated_len = 0;
// String templates to keep pretty alignment
const char * empty_hex = " ";
const char * empty_txt = " ";
char hex_buf[1024];
char txt_buf[1024];
sprintf(hex_buf, "%s", empty_hex);
sprintf(txt_buf, "%s", empty_txt);
if (len > g_options.truncate)
{
truncated_len = len - g_options.truncate;
len = g_options.truncate;
}
size_t line_pos = 0;
for (i = 0; i < len; i++)
{
line_pos = i & 0x0f;
// Print hex output to temporary buffer...
char hex[4];
sprintf(hex, "%02x ", p[i]);
// ...and use strncpy to avoid null-termination
strncpy(&hex_buf[line_pos*3], hex, 3);
if (isprint(p[i]))
{
// A printable character
txt_buf[line_pos] = p[i];
}
else
{
// Replace non-printable characters with a dot.
txt_buf[line_pos] = '.';
}
if (i % 16 == 0)
{
printf("%s %.4zx ", indent(depth, 0), i);
}
if (line_pos == 15)
{
printf("%s |%s|\n", hex_buf, txt_buf);
sprintf(hex_buf, "%s", empty_hex);
sprintf(txt_buf, "%s", empty_txt);
}
}
if (line_pos != 15)
{
printf("%s |%s|\n", hex_buf, txt_buf);
}
if (truncated_len)
{
printf("%s ... %zu bytes truncated\n",
indent(depth, 0), truncated_len);
}
}
/*
******************************************************************************
* Box printers *
******************************************************************************
*/
static void
mp4tree_table_print(
const char * name,
const char * header,
const uint8_t * p,
int esize,
int width,
int num,
int depth)
{
int i;
int j;
int offset = 0;
printf("%s %s:\n", indent(depth, 0), name);
printf("%s %s\n", indent(depth, 0), header);
for (i = 0; i < num; i++)
{
printf("%s %3d:", indent(depth, 0), i+1);
for (j = 0; j < width; j++)
{
printf(" %6u", get_u32(p + offset));
offset += esize;
}
printf("\n");
}
}
static const char *
mp4tree_hexstr(
const uint8_t * p,
size_t len)
{
static char buffer[128];
int n = 0;
size_t i;
if (len > g_options.truncate)
len = g_options.truncate;
for (i = 0; i < len; i++)
{
n += snprintf(buffer + n, sizeof(buffer) - n, " %.2x", p[i]);
}
return buffer;
}
static void
mp4tree_box_print(
const uint8_t * type,
size_t len,
int depth)
{
const char *desc;
printf("%s--- Length: %zu Type: %c%c%c%c\n",
indent(depth, 1), len,
type[0], type[1], type[2], type[3]);
desc = get_box_desc(type);
if (desc)
printf("%s Description: %s\n", indent(depth + 1, 0), desc);
}
static void
mp4tree_box_mdat_h264_print(
const uint8_t * p,
size_t len,
int depth)
{
const uint8_t * p_end = p + len;
while (p < p_end)
{
uint32_t nal_length = get_u32(p);
printf("%s--- Length %u Type: H264 NAL\n", indent(depth, 1), nal_length);
mp4tree_sei_h264_nal_print(p+4, nal_length, depth+1);
p += nal_length + 4;
}
}
static void
mp4tree_box_mdat_hevc_print(
const uint8_t * p,
size_t len,
int depth)
{
const uint8_t * p_end = p + len;
while (p < p_end)
{
uint32_t nal_length = get_u32(p);
p += 4;
printf("%s--- Length %u Type: HEVC NAL\n", indent(depth, 1), nal_length);
mp4tree_box_mdat_hevc_nal_print(p, nal_length, depth + 1);
p += nal_length;
}
}
static void
mp4tree_box_senc_print(
const uint8_t * p,
size_t len,
int depth)
{
const uint32_t flags = get_u24(p+1);
uint32_t sample_count = get_u32(p+4);
uint32_t i = 0;
uint32_t j = 0;
// aligned(8) class SampleEncryptionBox
// extends FullBox(‘senc’, version=0, flags)
// {
// unsigned int(32) sample_count;
// {
// unsigned int(Per_Sample_IV_Size*8) InitializationVector;
// if (flags & 0x000002)
// {
// unsigned int(16) subsample_count;
// {
// unsigned int(16) BytesOfClearData;
// unsigned int(32) BytesOfProtectedData;
// } [ subsample_count ]
// }
// }[ sample_count ]
// }
printf("%s Version: %u\n",indent(depth, 0), p[0]);
printf("%s Flags: 0x%.6x\n", indent(depth, 0), flags);
printf("%s Sample Count: %u\n", indent(depth, 0), sample_count);
p += 8;
// printf("%s Sample\n", indent(depth, 0), j);
for (i = 0; i < sample_count; i++)
{
printf("%s Sample: %3u\n", indent(depth, 1), i);
uint32_t iv_len = g_mp4_data.per_sample_iv_size;
if (iv_len)
{
printf("%s IV: %s\n",
indent(depth+1, 0), mp4tree_hexstr(p, iv_len));
p += iv_len;
}
if (flags & 0x000002)
{
uint32_t sub_sample_count = get_u16(p);
printf("%s Subsample Count: %u\n", indent(depth+1, 1), sub_sample_count);
p += 2;
printf("%s Subsample BytesOfClear BytesOfProtectedData\n", indent(depth+2, 0));
for (j = 0; j < sub_sample_count; j++)
{
printf("%s %9d %12u %20u\n",
indent(depth+2, 0), j, get_u16(p), get_u32(p+2));
p +=6;
}
}
}
}
static void
mp4tree_box_uuid_sample_encryption(
const uint8_t * p,
size_t len,
int depth)
{
const uint32_t flags = get_u24(p+1);
uint32_t num_entries = 0;
uint32_t i = 0;
uint8_t iv_size = 8;
printf("%s Name: Sample Encryption Box\n", indent(depth, 0));
printf("%s Version: %u\n",indent(depth, 0), p[0]);
printf("%s Flags: 0x%.6x\n", indent(depth, 0), flags);
p += 4;
if (flags & 1)
{
printf("%s AlgorithmID: 0x%.2x%.2x%.2x\n",indent(depth, 0),
p[0], p[1], p[2]);
printf("%s IV Sizes: %u\n", indent(depth, 0), p[3]);
printf("%s Key ID:\n", indent(depth, 0));
mp4tree_hexdump(p+4, 16, depth);
p += 20;
}
num_entries = get_u32(p);
p += 4;
printf("%s Num Entries: %u\n", indent(depth, 0), num_entries);
printf("%s Entry IV Entries\n",
indent(depth, 0));
for (i = 0; i < num_entries; i++)
{
if (iv_size)
{
printf("%s Entry: %3u\n",
indent(depth, 1), i);
printf("%s IV: %s\n",
indent(depth+1, 0), mp4tree_hexstr(p, 8));
p += iv_size;
}
if (flags & 2)
{
uint32_t j;
uint16_t num_sub_samples;
num_sub_samples = get_u16(p);
printf("%s Sub-Entries Count: %u\n", indent(depth+1, 1), num_sub_samples);
p += 2;
printf("%s Sub-Entry BytesOfClear BytesOfProtectedData\n", indent(depth+2, 0));
for (j = 0; j < num_sub_samples; j++)
{
printf("%s %9d %12u %20u\n",
indent(depth+2, 0), j, get_u16(p), get_u32(p+2));
p +=6;
}
}
}
}
/**
* @brief Print tfrf uuid box containing fragment forward references, see
* https://msdn.microsoft.com/en-us/library/ff469633.aspx
*/
static void
mp4tree_box_uuid_tfrf(
const uint8_t * p,
size_t len,
int depth)
{
const uint32_t flags = get_u24(p+1);
const uint8_t fragment_count = p[4];
unsigned int i = 0;
printf("%s Name: tfrf\n", indent(depth, 0));
printf("%s Version: %u\n",indent(depth, 0), p[0]);
printf("%s Flags: 0x%.6x\n", indent(depth, 0), flags);
printf("%s Fragment Count: %u\n", indent(depth, 0), fragment_count);
printf("%s Fragment Time Duration\n", indent(depth, 0));
for (i = 0; i < fragment_count; i++)
{
if (flags & 1)
{
printf("%s %u %16u %u\n",
indent(depth, 0), i, get_u32(p+5), get_u32(p+9));
}
else
{
printf("%s %u %16"PRIu64" %"PRIu64"\n",
indent(depth, 0), i, get_u64(p+5), get_u64(p+13));
}
}
}
static void
mp4tree_box_uuid_print(
const uint8_t * p,
size_t len,
int depth)
{
struct
{
const uint8_t uuid[16];
mp4tree_parse_func func;
} uuids[] =
{
{
{0xa2, 0x39, 0x4f, 0x52, 0x5a, 0x9b, 0x4f, 0x14,
0xa2, 0x44, 0x6c, 0x42, 0x7c, 0x64, 0x8d, 0xf4},
mp4tree_box_uuid_sample_encryption
},
{
{0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95,
0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f},
mp4tree_box_uuid_tfrf
}
/*
{
{0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2},
mp4tree_hexdump
}*/
};
int i;
for (i = 0; i < array_len(uuids); i++)
{
if ( memcmp(uuids[i].uuid, p, 16) == 0)
return uuids[i].func(p + 16, len - 16, depth);
}
return mp4tree_hexdump(p, len, depth);
}
#if 0
static void
mp4tree_box_stsd_avc1_print(
const uint8_t * p,
size_t len,
int depth)
{
/* Version
A 16-bit integer indicating the version number of the compressed data.
This is set to 0, unless a compressor has changed its data format.*/
printf("%s Version: %u\n", indent(depth, 0), get_u16(p));
/* Revision level
A 16-bit integer that must be set to 0. */
printf("%s Revision level: %u\n", indent(depth, 0), get_u16(p+2));
/* Vendor
A 32-bit integer that specifies the developer of the compressor that
generated the compressed data. Often this field contains 'appl' to
indicate Apple, Inc. */
printf("%s Vendor: %x\n", indent(depth, 0), get_u32(p+4));
/* Temporal quality
A 32-bit integer containing a value from 0 to 1023 indicating the degree
of temporal compression. */
printf("%s Temporal Quality: %u\n", indent(depth, 0), get_u32(p+8));
/* Spatial quality
A 32-bit integer containing a value from 0 to 1024 indicating the degree
of spatial compression.*/
printf("%s Spatial Quality: %u\n", indent(depth, 0), get_u32(p+12));
/* Width
A 16-bit integer that specifies the width of the source image in pixels.*/
printf("%s Width: %u\n", indent(depth, 0), get_u16(p+16));
/* Height
A 16-bit integer that specifies the height of the source image in pixels. */
printf("%s Heigth: %u\n", indent(depth, 0), get_u16(p+18));
/* Horizontal resolution
A 32-bit fixed-point number containing the horizontal resolution of the
image in pixels per inch. */
printf("%s Horizontal PPI: %u\n", indent(depth, 0), get_u32(p+20));
/* Vertical resolution
A 32-bit fixed-point number containing the vertical resolution of the
image in pixels per inch. */
printf("%s Vertical PPI: %u\n", indent(depth, 0), get_u32(p+24));
/* Data size
A 32-bit integer that must be set to 0. */
printf("%s Data Size: %u\n", indent(depth, 0), get_u32(p+28));
/* Frame count
A 16-bit integer that indicates how many frames of compressed data are
stored in each sample. Usually set to 1. */
printf("%s Frame Count: %u\n", indent(depth, 0), get_u16(p+32));
/* Compressor name
A 32-byte Pascal string containing the name of the compressor that
created the image, such as "jpeg". */
printf("%s Compressor: %x\n", indent(depth, 0), get_u32(p+34));
/* Depth
A 16-bit integer that indicates the pixel depth of the compressed image.
Values of 1, 2, 4, 8 ,16, 24, and 32 indicate the depth of color images.
The value 32 should be used only if the image contains an alpha channel.
Values of 34, 36, and 40 indicate 2-, 4-, and 8-bit grayscale,
respectively, for grayscale images. */
printf("%s Depth: %x\n", indent(depth, 0), get_u16(p+36));
/* Color table ID
A 16-bit integer that identifies which color table to use. If this
field is set to –1, the default color table should be used for the
specified depth. For all depths below 16 bits per pixel, this indicates
a standard Macintosh color table for the specified depth. Depths of 16,
24, and 32 have no color table. If the color table ID is set to 0, a
color table is contained within the sample description itself.
The color table immediately follows the color table ID field in the
sample description. See Color Table Atoms for a complete description of
a color table. */
printf("%s Color Table ID: %x\n", indent(depth, 0), get_u16(p+38));
mdat_printer = mp4tree_box_mdat_h264_print;
mp4tree_box_print((uint8_t *)"avc1", len, depth-1);
mp4tree_hexdump(p, len, depth);
}
#endif
static void
mp4tree_box_stsd_avcC_print(
const uint8_t * p,
size_t len,
int depth)
{
mp4tree_hexdump(p, len, depth);
mdat_printer = mp4tree_box_mdat_h264_print;
}
static void
mp4tree_box_stsd_hvcC_print(
const uint8_t * p,
size_t len,
int depth)
{
mp4tree_hexdump(p, len, depth);
mdat_printer = mp4tree_box_mdat_hevc_print;
}
static void
mp4tree_box_ctab_print(
const uint8_t * p,
size_t len,
int depth)
{
printf("%s Color Table Seed %x\n", indent(depth, 0), get_u32(p));
printf("%s Color Table Flags %u\n", indent(depth, 0), get_u16(p+4));
printf("%s Color Table Size %u\n", indent(depth, 0), get_u16(p+6));
}
#if 0
static void
mp4tree_box_stsd_hev1_print(
const uint8_t * p,
size_t len,
int depth)
{
// 6 bytes reserved to
p += 6;
printf("%s Data reference index: %u\n", indent(depth, 0), get_u16(p));
p += 2;
/* Version
A 16-bit integer indicating the version number of the compressed data.
This is set to 0, unless a compressor has changed its data format.*/
printf("%s Version: %u\n", indent(depth, 0), get_u16(p));
/* Revision level
A 16-bit integer that must be set to 0. */
printf("%s Revision level: %u\n", indent(depth, 0), get_u16(p+2));
/* Vendor
A 32-bit integer that specifies the developer of the compressor that
generated the compressed data. Often this field contains 'appl' to
indicate Apple, Inc. */
printf("%s Vendor: %x\n", indent(depth, 0), get_u32(p+4));
/* Temporal quality
A 32-bit integer containing a value from 0 to 1023 indicating the degree
of temporal compression. */
printf("%s Temporal Quality: %u\n", indent(depth, 0), get_u32(p+8));
/* Spatial quality
A 32-bit integer containing a value from 0 to 1024 indicating the degree
of spatial compression.*/
printf("%s Spatial Quality: %u\n", indent(depth, 0), get_u32(p+12));
/* Width
A 16-bit integer that specifies the width of the source image in pixels.*/
printf("%s Width: %u\n", indent(depth, 0), get_u16(p+16));
/* Height
A 16-bit integer that specifies the height of the source image in pixels. */
printf("%s Heigth: %u\n", indent(depth, 0), get_u16(p+18));
/* Horizontal resolution
A 32-bit fixed-point number containing the horizontal resolution of the
image in pixels per inch. */
printf("%s Horizontal PPI: %u\n", indent(depth, 0), get_u32(p+20));
/* Vertical resolution
A 32-bit fixed-point number containing the vertical resolution of the
image in pixels per inch. */
printf("%s Vertical PPI: %u\n", indent(depth, 0), get_u32(p+24));
/* Data size
A 32-bit integer that must be set to 0. */
printf("%s Data Size: %u\n", indent(depth, 0), get_u32(p+28));
/* Frame count
A 16-bit integer that indicates how many frames of compressed data are
stored in each sample. Usually set to 1. */
printf("%s Frame Count: %u\n", indent(depth, 0), get_u16(p+32));
/* Compressor name
A 32-byte Pascal string containing the name of the compressor that
created the image, such as "jpeg". */
printf("%s Compressor: %x\n", indent(depth, 0), get_u32(p+34));
/* Depth
A 16-bit integer that indicates the pixel depth of the compressed image.
Values of 1, 2, 4, 8 ,16, 24, and 32 indicate the depth of color images.
The value 32 should be used only if the image contains an alpha channel.
Values of 34, 36, and 40 indicate 2-, 4-, and 8-bit grayscale,
respectively, for grayscale images. */
printf("%s Depth: %x\n", indent(depth, 0), get_u16(p+36));
/* Color table ID
A 16-bit integer that identifies which color table to use. If this
field is set to –1, the default color table should be used for the
specified depth. For all depths below 16 bits per pixel, this indicates
a standard Macintosh color table for the specified depth. Depths of 16,
24, and 32 have no color table. If the color table ID is set to 0, a
color table is contained within the sample description itself.
The color table immediately follows the color table ID field in the
sample description. See Color Table Atoms for a complete description of
a color table. */
printf("%s Color Table ID: %x\n", indent(depth, 0), get_u16(p+38));
mp4tree_box_ctab_print(p + 40, len, depth);
// mp4tree_print(p + 40, len - 40, depth + 1);
// mp4tree_box_print((uint8_t *)"hvc1", len, depth-1);
mp4tree_hexdump(p + 48, len, depth);
mdat_printer = mp4tree_box_mdat_hevc_print;
}
#endif
static void
mp4tree_box_saio_print(
const uint8_t * p,
size_t len,
int depth)
{
/*
* aligned(8) class SampleAuxiliaryInformationOffsetsBox
* extends FullBox(‘saio’, version, flags)
* {
* if (flags & 1) {
* unsigned int(32) aux_info_type;
* unsigned int(32) aux_info_type_parameter;
* }
* unsigned int(32) entry_count;
* if ( version == 0 ) {
* unsigned int(32) offset[ entry_count ];
* }
* else {
* unsigned int(64) offset[ entry_count ];
* }
* }
*
*/
uint8_t version = p[0];
uint32_t flags = get_u24(p+1);
uint8_t entry_count = 0;
printf("%s Version: %u\n",indent(depth, 0), version);
printf("%s Flags: 0x%.6x\n", indent(depth, 0), flags);
p += 4;
if (flags & 1)
{
printf("%s Aux Info Type: %c%c%c%c\n",indent(depth, 0), p[0], p[1], p[2], p[3]);
printf("%s Aux Info Type Parameter: %u\n",indent(depth, 0), get_u32(p+4));
p += 8;
}
entry_count = get_u32(p);
p += 4;
if (version == 0)
{
int i = 0;
printf("%s Entry Offset\n", indent(depth, 0));
for (i = 0; i < entry_count; i++)
{
printf("%s %3d: %u\n", indent(depth, 0), i, get_u32(p));
p += 4;
}
}
else
{
int i = 0;
printf("%s Entry Offset\n", indent(depth, 0));
for (i = 0; i < entry_count; i++)
{
printf("%s %3d: %llu\n", indent(depth, 0), i, (long long unsigned) get_u64(p));
p += 8;
}
}
}
static void
mp4tree_box_saiz_print(
const uint8_t * p,
size_t len,
int depth)
{
/*
* aligned(8) class SampleAuxiliaryInformationSizesBox
* extends FullBox(‘saiz’, version = 0, flags)
* {
* if (flags & 1) {
* unsigned int(32) aux_info_type;
* unsigned int(32) aux_info_type_parameter;
* }
* unsigned int(8) default_sample_info_size;
* unsigned int(32) sample_count;
* if (default_sample_info_size == 0) {
* unsigned int(8) sample_info_size[ sample_count ];
* }
* }
*
**/
uint32_t flags = get_u24(p+1);
printf("%s Version: %u\n",indent(depth, 0), p[0]);
printf("%s Flags: 0x%.6x\n", indent(depth, 0), flags);
p += 4;
if (flags & 1)
{
printf("%s Aux Info Type: %c%c%c%c\n",indent(depth, 0), p[0], p[1], p[2], p[3]);
printf("%s Aux Info Type Parameter: %u\n",indent(depth, 0), get_u32(p+4));
p += 8;
}
uint8_t default_sample_info_size = p[0];
uint8_t sample_count = get_u32(p + 1);
printf("%s Default Sample Info Size: %u\n",indent(depth, 0), default_sample_info_size);
printf("%s Sample Count: %u\n",indent(depth, 0), sample_count);
p += 5;
if (default_sample_info_size == 0)
{
int i = 0;
printf("%s Sample Sample Info Size\n", indent(depth, 0));
for (i = 0; i < sample_count; i++)
{
printf("%s %3d: %.2u\n", indent(depth, 0), i, p[i]);
}
}
}
static void
mp4tree_box_btrt_print(
const uint8_t * p,
size_t len,
int depth)
{
printf("%s Version: %u\n",indent(depth, 0), p[0]);
mp4tree_hexdump(p, len, depth);
}
static void
mp4tree_box_frma_print(
const uint8_t * p,
size_t len,
int depth)
{
printf("%s Data Format: %c%c%c%c\n",indent(depth, 0), p[0], p[1], p[2], p[3]);
}
static void
mp4tree_box_tenc_print(
const uint8_t * p,
size_t len,
int depth)
{
uint32_t pos = 0;
uint32_t version = p[pos++];
uint32_t flags = get_u24(p + pos);
pos += 3;
printf("%s Version: %u\n",indent(depth, 0), version);
printf("%s Flags: 0x%.6x\n", indent(depth, 0), flags);
// One byte reserved
pos++;
if (version == 1)
{
uint32_t crypt_byte_block = (p[pos] & 0xf0) >> 4;
uint32_t skip_byte_block = p[pos] & 0x0f;
printf("%s default_crypt_byte_block: %u\n", indent(depth, 0), crypt_byte_block);
printf("%s default_skip_byte_block: %u\n", indent(depth, 0), skip_byte_block);
}
pos++;
uint32_t is_protected = p[pos++];
uint32_t per_sample_iv_size = p[pos++];
g_mp4_data.per_sample_iv_size = per_sample_iv_size;
printf("%s default_isProtected: %u\n", indent(depth, 0), is_protected);
printf("%s default_Per_Sample_IV_Size: %u\n", indent(depth, 0), per_sample_iv_size);
printf("%s default_KID: ", indent(depth, 0));
print_hex(p + pos, 16);
printf("\n");
pos += 16;
if (per_sample_iv_size == 0)
{
uint32_t constant_iv_size = p[pos++];
g_mp4_data.constant_iv_size = constant_iv_size;
printf("%s default_constant_IV_size: %u\n", indent(depth, 0), constant_iv_size);
printf("%s default_constant_IV: ", indent(depth, 0));
if (constant_iv_size <= 32)
{
print_hex(p + pos, constant_iv_size);
}
else
{
printf("?");
}
printf("\n");
}
}
static void
mp4tree_box_schm_print(
const uint8_t * p,
size_t len,
int depth)
{
uint32_t flags = get_u24(p+1);
printf("%s Version: %u\n",indent(depth, 0), p[0]);
printf("%s Flags: 0x%.6x\n", indent(depth, 0), flags);
printf("%s Scheme Type: %c%c%c%c\n",indent(depth, 0), p[4], p[5], p[6], p[7]);
printf("%s Scheme Version: %u\n", indent(depth, 0), get_u32(p+8));
if (flags & 0x1)
{
printf("%s Scheme URI: TODO\n", indent(depth, 0));
}
}
static void
mp4tree_box_stsd_sample_audio_print(
const uint8_t * p,
size_t len,
int depth)
{
/* General sample decription */
printf("%s Reserved: %.2x%.2x%.2x%.2x%.2x%.2x\n",
indent(depth, 0), p[0], p[1], p[2], p[3], p[4], p[5]);
printf("%s Data reference index: %u\n", indent(depth, 0), get_u16(p+6));
p += 8;
/*
* Version
* A 16-bit integer that holds the sample description version (currently 0 or 1).
*
* Revision level
* A 16-bit integer that must be set to 0.
*
* Vendor
* A 32-bit integer that must be set to 0.
*
* Number of channels
* A 16-bit integer that indicates the number of sound channels
* used by the sound sample. Set to 1 for monaural sounds, 2 for stereo sounds.
* Higher numbers of channels are not supported.
*
* Sample size (bits)
* A 16-bit integer that specifies the number of bits in each uncompressed
* sound sample. Allowable values are 8 or 16. Formats using more than 16
* bits per sample set this field to 16 and use sound description version 1.
*
* Compression ID
* A 16-bit integer that must be set to 0 for version 0 sound descriptions.
* This may be set to –2 for some version 1 sound descriptions; see Redefined Sample Tables.
*
* Packet size
* A 16-bit integer that must be set to 0.
*
* Sample rate
* A 32-bit unsigned fixed-point number (16.16) that indicates the rate at
* which the sound samples were obtained. The integer portion of this number
* should match the media’s time scale. Many older version 0 files have values
* of 22254.5454 or 11127.2727, but most files have integer values,
* such as 44100. Sample rates greater than 2^16 are not supported.
*
* Version 0 of the sound description format assumes uncompressed audio in 'raw ' or 'twos' format, 1 or 2 channels, 8 or 16 bits per sample, and a compression ID of 0.
*
*
*/
uint16_t version = get_u16(p);
printf("%s Version: %u\n", indent(depth, 0), version);
printf("%s Revision level: %u\n", indent(depth, 0), get_u16(p+2));
printf("%s Vendor: %x\n", indent(depth, 0), get_u32(p+4));
printf("%s Number of Channels: %u\n", indent(depth, 0), get_u16(p+8));
printf("%s Sample Size: %u\n", indent(depth, 0), get_u16(p+10));
printf("%s Compression ID: %u\n", indent(depth, 0), get_u16(p+12));
printf("%s Packet Size: %u\n", indent(depth, 0), get_u16(p+14));
printf("%s Sample Rate: %u\n", indent(depth, 0), get_u32(p+16));
if (version == 0)
{
mp4tree_print(p+20, len - 28, depth);
}
}
static void
mp4tree_box_stsd_sample_video_print(
const uint8_t * p,
size_t len,
int depth)
{
/* General sample decription */
printf("%s Reserved: %.2x%.2x%.2x%.2x%.2x%.2x\n",
indent(depth, 0), p[0], p[1], p[2], p[3], p[4], p[5]);
printf("%s Data reference index: %u\n", indent(depth, 0), get_u16(p+6));
p += 8;
/* Video sample description */
/* Version
A 16-bit integer indicating the version number of the compressed data.
This is set to 0, unless a compressor has changed its data format.*/
printf("%s Version: %u\n", indent(depth, 0), get_u16(p));
/* Revision level
A 16-bit integer that must be set to 0. */
printf("%s Revision level: %u\n", indent(depth, 0), get_u16(p+2));
/* Vendor
A 32-bit integer that specifies the developer of the compressor that
generated the compressed data. Often this field contains 'appl' to
indicate Apple, Inc. */
printf("%s Vendor: %x\n", indent(depth, 0), get_u32(p+4));
/* Temporal quality
A 32-bit integer containing a value from 0 to 1023 indicating the degree
of temporal compression. */
printf("%s Temporal Quality: %u\n", indent(depth, 0), get_u32(p+8));
/* Spatial quality
A 32-bit integer containing a value from 0 to 1024 indicating the degree
of spatial compression.*/
printf("%s Spatial Quality: %u\n", indent(depth, 0), get_u32(p+12));