forked from duiniuluantanqin/mp4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
private.h
694 lines (566 loc) · 12.4 KB
/
private.h
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
#ifndef PRIVATE_H
#define PRIVATE_H
/* ================================= structures */
#define HEADER_LENGTH 8
#define MAXTRACKS 4
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
#endif
#include "sizes.h"
#include "win32.h"
typedef struct
{
float values[9];
} quicktime_matrix_t;
typedef struct
{
int version;
long flags;
unsigned long creation_time;
unsigned long modification_time;
int track_id;
long reserved1;
long duration;
char reserved2[8];
int layer;
int alternate_group;
float volume;
long reserved3;
quicktime_matrix_t matrix;
float track_width;
float track_height;
int is_video;
int is_audio;
int is_hint;
} quicktime_tkhd_t;
typedef struct
{
long seed;
long flags;
long size;
short int *alpha;
short int *red;
short int *green;
short int *blue;
} quicktime_ctab_t;
/* ===================== sample table ======================== // */
/* sample description */
typedef struct
{
int motion_jpeg_quantization_table;
} quicktime_mjqt_t;
typedef struct
{
int motion_jpeg_huffman_table;
} quicktime_mjht_t;
typedef struct
{
int timeScale;
} quicktime_tims_t;
typedef struct
{
int version;
long flags;
int decoderConfigLen;
u_char* decoderConfig;
} quicktime_esds_t;
typedef struct
{
char data[2048];
int data_size;
} quicktime_avcc_t;
typedef struct
{
char format[4];
char reserved[6];
int data_reference;
/* common to audio and video */
int version;
int revision;
char vendor[4];
/* video description */
long temporal_quality;
long spatial_quality;
int width;
int height;
float dpi_horizontal;
float dpi_vertical;
long data_size;
int frames_per_sample;
char compressor_name[32];
int depth;
int ctab_id;
quicktime_ctab_t ctab;
float gamma;
int fields; /* 0, 1, or 2 */
int field_dominance; /* 0 - unknown 1 - top first 2 - bottom first */
quicktime_mjqt_t mjqt;
quicktime_mjht_t mjht;
/* audio description */
int channels;
int sample_size;
int compression_id;
int packet_size;
float sample_rate;
/* hint description */
int maxPktSize;
quicktime_tims_t tims;
/* MP4 elementary stream descriptor */
quicktime_esds_t esds;
quicktime_avcc_t avcc;
} quicktime_stsd_table_t;
typedef struct
{
int version;
long flags;
long total_entries;
quicktime_stsd_table_t *table;
} quicktime_stsd_t;
/* time to sample */
typedef struct
{
long sample_count;
long sample_duration;
} quicktime_stts_table_t;
typedef struct
{
int version;
long flags;
long total_entries;
long entries_allocated;
quicktime_stts_table_t *table;
} quicktime_stts_t;
/* sync sample */
typedef struct
{
long sample;
} quicktime_stss_table_t;
typedef struct
{
int version;
long flags;
long total_entries;
long entries_allocated;
quicktime_stss_table_t *table;
} quicktime_stss_t;
/* sample to chunk */
typedef struct
{
long chunk;
long samples;
long id;
} quicktime_stsc_table_t;
typedef struct
{
int version;
long flags;
long total_entries;
long entries_allocated;
quicktime_stsc_table_t *table;
} quicktime_stsc_t;
/* sample size */
typedef struct
{
long size;
} quicktime_stsz_table_t;
typedef struct
{
int version;
long flags;
long sample_size;
long total_entries;
long entries_allocated; /* used by the library for allocating a table */
quicktime_stsz_table_t *table;
} quicktime_stsz_t;
/* chunk offset */
typedef struct
{
long offset;
} quicktime_stco_table_t;
typedef struct
{
int version;
long flags;
long total_entries;
long entries_allocated; /* used by the library for allocating a table */
quicktime_stco_table_t *table;
} quicktime_stco_t;
/* composition time to sample */
typedef struct
{
long sample_count;
long sample_offset;
} quicktime_ctts_table_t;
typedef struct
{
int version;
long flags;
long total_entries;
long entries_allocated;
quicktime_ctts_table_t *table;
} quicktime_ctts_t;
/* sample table */
typedef struct
{
int version;
long flags;
quicktime_stsd_t stsd;
quicktime_stts_t stts;
quicktime_stss_t stss;
quicktime_stsc_t stsc;
quicktime_stsz_t stsz;
quicktime_stco_t stco;
quicktime_ctts_t ctts;
} quicktime_stbl_t;
/* data reference */
typedef struct
{
long size;
char type[4];
int version;
long flags;
char *data_reference;
} quicktime_dref_table_t;
typedef struct
{
int version;
long flags;
long total_entries;
quicktime_dref_table_t *table;
} quicktime_dref_t;
/* data information */
typedef struct
{
quicktime_dref_t dref;
} quicktime_dinf_t;
/* video media header */
typedef struct
{
int version;
long flags;
int graphics_mode;
int opcolor[3];
} quicktime_vmhd_t;
/* sound media header */
typedef struct
{
int version;
long flags;
int balance;
int reserved;
} quicktime_smhd_t;
/* generic media handler */
typedef struct
{
int version;
long flags;
int graphics_mode;
int opcolor[3];
int balance;
int reserved;
} quicktime_gmin_t;
typedef struct
{
quicktime_gmin_t gmin;
} quicktime_gmhd_t;
/* hint media handler */
typedef struct
{
int version;
long flags;
int maxPDUsize;
int avgPDUsize;
long maxbitrate;
long avgbitrate;
long slidingavgbitrate;
} quicktime_hmhd_t;
/* handler reference */
typedef struct
{
int version;
long flags;
char component_type[4];
char component_subtype[4];
long component_manufacturer;
long component_flags;
long component_flag_mask;
char component_name[256];
} quicktime_hdlr_t;
/* media information */
typedef struct
{
int is_video;
int is_audio;
int is_hint;
quicktime_vmhd_t vmhd;
quicktime_smhd_t smhd;
quicktime_gmhd_t gmhd;
quicktime_hmhd_t hmhd;
quicktime_stbl_t stbl;
quicktime_hdlr_t hdlr;
quicktime_dinf_t dinf;
} quicktime_minf_t;
/* media header */
typedef struct
{
int version;
long flags;
unsigned long creation_time;
unsigned long modification_time;
long time_scale;
long duration;
int language;
int quality;
} quicktime_mdhd_t;
/* media */
typedef struct
{
quicktime_mdhd_t mdhd;
quicktime_minf_t minf;
quicktime_hdlr_t hdlr;
} quicktime_mdia_t;
/* hint */
typedef struct
{
int numTracks;
long trackIds[MAXTRACKS];
void* traks[MAXTRACKS];
} quicktime_hint_t;
/* tref */
typedef struct
{
quicktime_hint_t hint;
} quicktime_tref_t;
/* edit list */
typedef struct
{
long duration;
long time;
float rate;
} quicktime_elst_table_t;
typedef struct
{
int version;
long flags;
long total_entries;
quicktime_elst_table_t *table;
} quicktime_elst_t;
typedef struct
{
quicktime_elst_t elst;
} quicktime_edts_t;
typedef struct
{
u_int64_t numBytes; /* bytes sent including 12 byte RTP hdrs */
} quicktime_trpy_t;
typedef struct
{
u_int64_t numPackets; /* packets sent */
} quicktime_nump_t;
typedef struct
{
u_int64_t numBytes; /* bytes sent of just payload data */
} quicktime_tpyl_t;
typedef struct
{
u_int32_t granularity;
u_int32_t maxBitRate;
} quicktime_maxr_t;
typedef struct
{
u_int64_t numBytes; /* bytes sent from media data */
} quicktime_dmed_t;
typedef struct
{
u_int64_t numBytes; /* bytes of immediate data */
} quicktime_dimm_t;
typedef struct
{
u_int64_t numBytes; /* bytes of repeated data */
} quicktime_drep_t;
typedef struct
{
int32_t milliSecs; /* min relative xmit time */
} quicktime_tmin_t;
typedef struct
{
int32_t milliSecs; /* max relative xmit time */
} quicktime_tmax_t;
typedef struct
{
u_int32_t numBytes; /* largest packet size */
} quicktime_pmax_t;
typedef struct
{
u_int32_t milliSecs; /* longest packet duration */
} quicktime_dmax_t;
typedef struct
{
u_int32_t payloadNumber; /* RTP payload number */
char rtpMapString[256]; /* TBD make this dynamically sized */
} quicktime_payt_t;
typedef struct
{
quicktime_trpy_t trpy;
quicktime_nump_t nump;
quicktime_tpyl_t tpyl;
quicktime_maxr_t maxr; /* TBD there can be multiple such atoms */
quicktime_dmed_t dmed;
quicktime_dimm_t dimm;
quicktime_drep_t drep;
quicktime_tmin_t tmin;
quicktime_tmax_t tmax;
quicktime_pmax_t pmax;
quicktime_dmax_t dmax;
quicktime_payt_t payt;
} quicktime_hinf_t;
typedef struct
{
char* string;
} quicktime_sdp_t;
typedef struct
{
char* string;
} quicktime_rtp_t;
typedef struct
{
quicktime_sdp_t sdp;
} quicktime_hint_hnti_t;
typedef struct
{
quicktime_rtp_t rtp;
} quicktime_hnti_t;
typedef struct
{
/* TBD name */
quicktime_hinf_t hinf;
quicktime_hint_hnti_t hnti;
} quicktime_hint_udta_t;
typedef struct
{
quicktime_tkhd_t tkhd;
quicktime_mdia_t mdia;
quicktime_edts_t edts;
quicktime_tref_t tref;
quicktime_hint_udta_t hint_udta;
} quicktime_trak_t;
typedef struct
{
int version;
long flags;
int audioProfileId;
int videoProfileId;
} quicktime_iods_t;
typedef struct
{
int version;
long flags;
unsigned long creation_time;
unsigned long modification_time;
long time_scale;
long duration;
float preferred_rate;
float preferred_volume;
char reserved[10];
quicktime_matrix_t matrix;
long preview_time;
long preview_duration;
long poster_time;
long selection_time;
long selection_duration;
long current_time;
long next_track_id;
} quicktime_mvhd_t;
typedef struct
{
quicktime_hnti_t hnti;
} quicktime_udta_t;
typedef struct
{
int total_tracks;
quicktime_mvhd_t mvhd;
quicktime_iods_t iods;
quicktime_trak_t *trak[MAXTRACKS];
quicktime_udta_t udta;
quicktime_ctab_t ctab;
} quicktime_moov_t;
typedef struct
{
long start;
long size;
} quicktime_mdat_t;
typedef struct
{
long start; /* byte start in file */
long end; /* byte endpoint in file */
long size; /* byte size for writing */
char type[4];
} quicktime_atom_t;
/* table of pointers to every track */
typedef struct
{
quicktime_trak_t *track; /* real quicktime track corresponding to this table */
int channels; /* number of audio channels in the track */
long current_position; /* current sample in output file */
long current_chunk; /* current chunk in output file */
void *codec;
/* Array of hint tracks for this audio track */
int totalHintTracks;
quicktime_trak_t *hintTracks[MAXTRACKS];
long hintPositions[MAXTRACKS];
} quicktime_audio_map_t;
typedef struct
{
quicktime_trak_t *track;
long current_position;
long current_chunk;
/* Array of pointers to frames of raw data when caching frames. */
unsigned char **frame_cache;
long frames_cached;
void *codec;
/* Array of hint tracks for this video track */
int totalHintTracks;
quicktime_trak_t *hintTracks[MAXTRACKS];
long hintPositions[MAXTRACKS];
} quicktime_video_map_t;
/* file descriptor passed to all routines */
typedef struct
{
FILE *stream;
long total_length;
quicktime_mdat_t mdat;
quicktime_moov_t moov;
int rd;
int wr;
/* mapping of audio channels to movie tracks */
/* one audio map entry exists for each channel */
int total_atracks;
quicktime_audio_map_t *atracks;
/* mapping of video tracks to movie tracks */
int total_vtracks;
quicktime_video_map_t *vtracks;
int total_hint_tracks;
/* for beginning and ending frame writes where the user wants to write the */
/* file descriptor directly */
long offset;
/* I/O */
long file_position; /* Current position of file descriptor */
/* Read ahead buffer */
long preload_size; /* Enables preload when nonzero. */
char *preload_buffer;
long preload_start; /* Start of preload_buffer in file */
long preload_end; /* End of preload buffer in file */
long preload_ptr; /* Offset of preload_start in preload_buffer */
/* Parameters for frame currently being decoded */
int do_scaling;
int in_x, in_y, in_w, in_h, out_w, out_h;
int color_model;
/* Cached value for quicktime_video_frame */
long last_frame;
long last_start;
int last_stts_index;
} quicktime_t;
#endif