r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / quicktime / qtprivate.h
blobcc8e7128de6c740f05a3bad393de94ef4485488c
1 #ifndef PRIVATE_H
2 #define PRIVATE_H
4 /* ================================= structures */
6 /* Version used internally. You need to query it with the C functions */
7 #define QUICKTIME_MAJOR 2
8 #define QUICKTIME_MINOR 0
9 #define QUICKTIME_RELEASE 0
12 #define HEADER_LENGTH 8
13 #define MAXTRACKS 1024
15 /* Crazy Mich R. Soft constants */
16 #define AVI_HASINDEX 0x00000010 // Index at end of file?
17 #define AVI_MUSTUSEINDEX 0x00000020
18 #define AVI_ISINTERLEAVED 0x00000100
19 #define AVI_TRUSTCKTYPE 0x00000800 // Use CKType to find key frames?
20 #define AVI_WASCAPTUREFILE 0x00010000
21 #define AVI_COPYRIGHTED 0x00020000
22 #define AVIF_WASCAPTUREFILE 0x00010000
23 #define AVI_KEYFRAME 0x10
24 #define AVI_INDEX_OF_CHUNKS 0x01
25 #define AVI_INDEX_OF_INDEXES 0x00
27 #define AVI_FRAME_RATE_BASE 10000
28 #define MAX_RIFFS 0x100
30 #include <stdio.h>
31 #include <stdint.h>
32 #include <stdlib.h>
37 #define FTELL ftello64
38 #define FSEEK fseeko64
41 // ffmpeg requires global variable initialization
42 // These are defined in mpeg4.c
43 extern int ffmpeg_initialized;
44 extern pthread_mutex_t ffmpeg_lock;
46 typedef struct
48 /* for AVI it's the end of the 8 byte header in the file */
49 /* for Quicktime it's the start of the 8 byte header in the file */
50 int64_t start;
51 int64_t end; /* byte endpoint in file */
52 int64_t size; /* byte size for writing */
53 int use_64; /* Use 64 bit header */
54 unsigned char type[4];
55 } quicktime_atom_t;
57 typedef struct
59 float values[9];
60 } quicktime_matrix_t;
63 typedef struct
65 int version;
66 long flags;
67 unsigned long creation_time;
68 unsigned long modification_time;
69 int track_id;
70 long reserved1;
71 long duration;
72 char reserved2[8];
73 int layer;
74 int alternate_group;
75 float volume;
76 long reserved3;
77 quicktime_matrix_t matrix;
78 float track_width;
79 float track_height;
80 } quicktime_tkhd_t;
83 typedef struct
85 long seed;
86 long flags;
87 long size;
88 short int *alpha;
89 short int *red;
90 short int *green;
91 short int *blue;
92 } quicktime_ctab_t;
96 /* ===================== sample table ======================== // */
100 /* sample description */
102 typedef struct
104 int motion_jpeg_quantization_table;
105 } quicktime_mjqt_t;
108 typedef struct
110 int motion_jpeg_huffman_table;
111 } quicktime_mjht_t;
114 typedef struct
116 char format[4];
117 char reserved[6];
118 int data_reference;
120 /* common to audio and video */
121 int version;
122 int revision;
123 char vendor[4];
125 /* video description */
126 long temporal_quality;
127 long spatial_quality;
128 int width;
129 int height;
130 float dpi_horizontal;
131 float dpi_vertical;
132 int64_t data_size;
133 int frames_per_sample;
134 char compressor_name[32];
135 int depth;
136 int ctab_id;
137 quicktime_ctab_t ctab;
138 float gamma;
139 /* 0, 1, or 2 */
140 int fields;
141 /* 0 - unknown 1 - top first 2 - bottom first */
142 int field_dominance;
143 quicktime_mjqt_t mjqt;
144 quicktime_mjht_t mjht;
146 /* audio description */
147 int channels;
148 int sample_size;
149 int compression_id;
150 int packet_size;
151 float sample_rate;
152 } quicktime_stsd_table_t;
155 typedef struct
157 int version;
158 long flags;
159 long total_entries;
160 quicktime_stsd_table_t *table;
161 } quicktime_stsd_t;
164 /* time to sample */
165 typedef struct
167 long sample_count;
168 long sample_duration;
169 } quicktime_stts_table_t;
171 typedef struct
173 int version;
174 long flags;
175 long total_entries;
176 quicktime_stts_table_t *table;
177 } quicktime_stts_t;
180 /* sync sample */
181 typedef struct
183 long sample;
184 } quicktime_stss_table_t;
186 typedef struct
188 int version;
189 long flags;
190 long total_entries;
191 long entries_allocated;
192 quicktime_stss_table_t *table;
193 } quicktime_stss_t;
196 /* sample to chunk */
197 typedef struct
199 long chunk;
200 long samples;
201 long id;
202 } quicktime_stsc_table_t;
204 typedef struct
206 int version;
207 long flags;
208 long total_entries;
210 long entries_allocated;
211 quicktime_stsc_table_t *table;
212 } quicktime_stsc_t;
215 /* sample size */
216 typedef struct
218 int64_t size;
219 } quicktime_stsz_table_t;
221 typedef struct
223 int version;
224 long flags;
225 int64_t sample_size;
226 long total_entries;
228 long entries_allocated; /* used by the library for allocating a table */
229 quicktime_stsz_table_t *table;
230 } quicktime_stsz_t;
233 /* chunk offset */
234 typedef struct
236 int64_t offset;
237 } quicktime_stco_table_t;
239 typedef struct
241 int version;
242 long flags;
243 long total_entries;
245 long entries_allocated; /* used by the library for allocating a table */
246 quicktime_stco_table_t *table;
247 } quicktime_stco_t;
250 /* sample table */
251 typedef struct
253 int version;
254 long flags;
255 quicktime_stsd_t stsd;
256 quicktime_stts_t stts;
257 quicktime_stss_t stss;
258 quicktime_stsc_t stsc;
259 quicktime_stsz_t stsz;
260 quicktime_stco_t stco;
261 } quicktime_stbl_t;
263 /* data reference */
265 typedef struct
267 int64_t size;
268 char type[4];
269 int version;
270 long flags;
271 char *data_reference;
272 } quicktime_dref_table_t;
274 typedef struct
276 int version;
277 long flags;
278 long total_entries;
279 quicktime_dref_table_t *table;
280 } quicktime_dref_t;
282 /* data information */
284 typedef struct
286 quicktime_dref_t dref;
287 } quicktime_dinf_t;
289 /* video media header */
291 typedef struct
293 int version;
294 long flags;
295 int graphics_mode;
296 int opcolor[3];
297 } quicktime_vmhd_t;
300 /* sound media header */
302 typedef struct
304 int version;
305 long flags;
306 int balance;
307 int reserved;
308 } quicktime_smhd_t;
310 /* handler reference */
312 typedef struct
314 int version;
315 long flags;
316 char component_type[4];
317 char component_subtype[4];
318 long component_manufacturer;
319 long component_flags;
320 long component_flag_mask;
321 char component_name[256];
322 } quicktime_hdlr_t;
324 /* media information */
326 typedef struct
328 int is_video;
329 int is_audio;
330 quicktime_vmhd_t vmhd;
331 quicktime_smhd_t smhd;
332 quicktime_stbl_t stbl;
333 quicktime_hdlr_t hdlr;
334 quicktime_dinf_t dinf;
335 } quicktime_minf_t;
338 /* media header */
340 typedef struct
342 int version;
343 long flags;
344 unsigned long creation_time;
345 unsigned long modification_time;
346 long time_scale;
347 long duration;
348 int language;
349 int quality;
350 } quicktime_mdhd_t;
353 /* media */
355 typedef struct
357 quicktime_mdhd_t mdhd;
358 quicktime_minf_t minf;
359 quicktime_hdlr_t hdlr;
360 } quicktime_mdia_t;
362 /* edit list */
363 typedef struct
365 long duration;
366 long time;
367 float rate;
368 } quicktime_elst_table_t;
370 typedef struct
372 int version;
373 long flags;
374 long total_entries;
376 quicktime_elst_table_t *table;
377 } quicktime_elst_t;
379 typedef struct
381 quicktime_elst_t elst;
382 } quicktime_edts_t;
387 typedef struct
389 quicktime_tkhd_t tkhd;
390 quicktime_mdia_t mdia;
391 quicktime_edts_t edts;
392 } quicktime_trak_t;
395 typedef struct
397 int version;
398 long flags;
399 unsigned long creation_time;
400 unsigned long modification_time;
401 long time_scale;
402 long duration;
403 float preferred_rate;
404 float preferred_volume;
405 char reserved[10];
406 quicktime_matrix_t matrix;
407 long preview_time;
408 long preview_duration;
409 long poster_time;
410 long selection_time;
411 long selection_duration;
412 long current_time;
413 long next_track_id;
414 } quicktime_mvhd_t;
416 typedef struct
418 char *copyright;
419 int copyright_len;
420 char *name;
421 int name_len;
422 char *info;
423 int info_len;
424 } quicktime_udta_t;
427 typedef struct
429 int total_tracks;
431 quicktime_mvhd_t mvhd;
432 quicktime_trak_t *trak[MAXTRACKS];
433 quicktime_udta_t udta;
434 quicktime_ctab_t ctab;
435 } quicktime_moov_t;
437 typedef struct
439 quicktime_atom_t atom;
440 } quicktime_mdat_t;
442 typedef struct
444 /* Offset of end of 8 byte chunk header relative to ix->base_offset */
445 int relative_offset;
446 /* size of data without 8 byte header */
447 int size;
448 } quicktime_ixtable_t;
450 typedef struct
452 quicktime_atom_t atom;
453 quicktime_ixtable_t *table;
454 int table_size;
455 int table_allocation;
456 int longs_per_entry;
457 int index_type;
458 /* ixtable relative_offset is relative to this */
459 int64_t base_offset;
460 /* ix atom title */
461 char tag[5];
462 /* corresponding chunk id */
463 char chunk_id[5];
464 } quicktime_ix_t;
467 typedef struct
469 quicktime_atom_t atom;
471 /* Partial index */
472 /* For writing only, there are multiple movi objects with multiple ix tables. */
473 /* This is not used for reading. Instead an ix_t object in indx_t is used. */
474 quicktime_ix_t *ix[MAXTRACKS];
475 } quicktime_movi_t;
477 typedef struct
479 /* Start of start of corresponding ix## header */
480 int64_t index_offset;
481 /* Size not including 8 byte header */
482 int index_size;
483 /* duration in "ticks" */
484 int duration;
486 /* Partial index for reading only. */
487 quicktime_ix_t *ix;
488 } quicktime_indxtable_t;
490 typedef struct
492 quicktime_atom_t atom;
493 int longs_per_entry;
494 int index_subtype;
495 int index_type;
496 /* corresponding chunk id: 00wb, 00dc */
497 char chunk_id[5];
499 /* Number of partial indexes here */
500 int table_size;
501 int table_allocation;
502 quicktime_indxtable_t *table;
503 } quicktime_indx_t;
505 typedef struct
507 quicktime_atom_t atom;
508 /* Super index for reading */
509 quicktime_indx_t indx;
510 /* AVI needs header placeholders before anything else is written */
511 int64_t length_offset;
512 int64_t samples_per_chunk_offset;
513 int64_t sample_size_offset;
514 /* Start of indx header for later writing */
515 int64_t indx_offset;
516 /* Size of JUNK without 8 byte header which is to be replaced by indx */
517 int64_t padding_size;
518 /* Tag for writer with NULL termination: 00wb, 00dc Not available in reader.*/
519 char tag[5];
520 /* Flags for reader. Not available in writer. */
521 int is_audio;
522 int is_video;
523 /* Notify reader the super indexes are valid */
524 int have_indx;
525 } quicktime_strl_t;
527 typedef struct
529 quicktime_atom_t atom;
530 int64_t frames_offset;
531 int64_t bitrate_offset;
532 /* Offsets to be written during file closure */
533 int64_t total_frames_offset;
535 /* AVI equivalent for each trak. Use file->moov.total_tracks */
536 /* Need it for super indexes during reading. */
537 quicktime_strl_t *strl[MAXTRACKS];
538 } quicktime_hdrl_t;
540 typedef struct
542 char tag[5];
543 uint32_t flags;
544 /* Start of 8 byte chunk header relative to start of the 'movi' string */
545 int32_t offset;
546 /* Size of chunk less the 8 byte header */
547 int32_t size;
548 } quicktime_idx1table_t;
550 typedef struct
552 quicktime_atom_t atom;
553 quicktime_idx1table_t *table;
554 int table_size;
555 int table_allocation;
556 } quicktime_idx1_t;
558 typedef struct
560 quicktime_atom_t atom;
561 quicktime_movi_t movi;
562 quicktime_hdrl_t hdrl;
564 /* Full index */
565 quicktime_idx1_t idx1;
566 /* Notify reader the idx1 table is valid */
567 int have_idx1;
568 int have_hdrl;
569 } quicktime_riff_t;
571 /* table of pointers to every track */
572 typedef struct
574 quicktime_trak_t *track; /* real quicktime track corresponding to this table */
575 int channels; /* number of audio channels in the track */
576 long current_position; /* current sample in output file */
577 long current_chunk; /* current chunk in output file */
579 void *codec;
580 } quicktime_audio_map_t;
582 typedef struct
584 quicktime_trak_t *track;
585 long current_position; /* current frame in output file */
586 long current_chunk; /* current chunk in output file */
588 void *codec;
589 } quicktime_video_map_t;
591 /* file descriptor passed to all routines */
592 typedef struct
594 FILE *stream;
595 int64_t total_length;
596 quicktime_mdat_t mdat;
597 quicktime_moov_t moov;
598 int rd;
599 int wr;
604 /* ASF section */
605 int use_asf;
610 /* AVI section */
611 int use_avi;
612 /* AVI tree */
613 quicktime_riff_t *riff[MAX_RIFFS];
614 int total_riffs;
620 /* for begining and ending frame writes where the user wants to write the */
621 /* file descriptor directly */
622 int64_t offset;
624 /* I/O */
625 /* Current position of virtual file descriptor */
626 int64_t file_position;
628 /* Work around a bug in glibc where ftello returns only 32 bits by maintaining */
629 /* our own position */
630 int64_t ftell_position;
632 /* Read ahead buffer */
633 int64_t preload_size; /* Enables preload when nonzero. */
634 char *preload_buffer;
635 int64_t preload_start; /* Start of preload_buffer in file */
636 int64_t preload_end; /* End of preload buffer in file */
637 int64_t preload_ptr; /* Offset of preload_start in preload_buffer */
639 /* Write ahead buffer */
640 /* Amount of data in presave buffer */
641 int64_t presave_size;
642 /* Next presave byte's position in file */
643 int64_t presave_position;
644 char *presave_buffer;
645 /* Presave doesn't matter a whole lot, so its size is fixed */
646 #define QUICKTIME_PRESAVE 0x100000
649 /* mapping of audio channels to movie tracks */
650 /* one audio map entry exists for each channel */
651 int total_atracks;
652 quicktime_audio_map_t *atracks;
654 /* mapping of video tracks to movie tracks */
655 int total_vtracks;
656 quicktime_video_map_t *vtracks;
658 /* Number of processors at our disposal */
659 int cpus;
661 /* Parameters for frame currently being decoded */
662 int do_scaling;
663 int in_x, in_y, in_w, in_h, out_w, out_h;
664 int color_model, row_span;
665 } quicktime_t;
668 /* Structure created in track_map to describe the codec */
669 typedef struct
671 int (*delete_vcodec)(quicktime_video_map_t *vtrack);
672 int (*delete_acodec)(quicktime_audio_map_t *atrack);
673 /* Decode a single frame */
674 int (*decode_video)(quicktime_t *file,
675 unsigned char **row_pointers,
676 int track);
677 /* Encode a single frame */
678 int (*encode_video)(quicktime_t *file,
679 unsigned char **row_pointers,
680 int track);
681 /* Decode a certain number of samples */
682 int (*decode_audio)(quicktime_t *file,
683 int16_t *output_i,
684 float *output_f,
685 long samples,
686 int track,
687 int channel);
688 /* Encode a chunk of audio */
689 int (*encode_audio)(quicktime_t *file,
690 int16_t **input_i,
691 float **input_f,
692 int track,
693 long samples);
694 int (*reads_colormodel)(quicktime_t *file,
695 int colormodel,
696 int track);
697 int (*writes_colormodel)(quicktime_t *file,
698 int colormodel,
699 int track);
701 int (*set_parameter)(quicktime_t *file,
702 int track,
703 char *key,
704 void *value);
705 void (*flush)(quicktime_t *file,
706 int track);
708 /* AVI codec ID for audio. AVI codec ID's are based on WAV files, by the way. */
709 int wav_id;
711 /* Pointer to static character code for identifying the codec. */
712 char *fourcc;
714 /* English title of codec. Optional. */
715 char *title;
717 /* English description of codec. Optional. */
718 char *desc;
720 /* Proprietary data for the codec to allocate and delete. */
721 void *priv;
722 } quicktime_codec_t;
726 /* Structure tabulated in plugin.c to search the codecs */
727 typedef struct
729 void (*init_vcodec)(quicktime_video_map_t *);
730 void (*init_acodec)(quicktime_audio_map_t *);
731 } quicktime_codectable_t;
736 #endif