r858: Merge 2.1:
[cinelerra_cv/ct.git] / quicktime / qtprivate.h
blob0b00cb15c597c6eb640174f972f9f310a7b916a0
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 1
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;
48 // Utility functions for vbr audio. This is accessed through quicktime_audio_map_t.
49 typedef struct
51 // End of the output buffer in the file in samples
52 int64_t buffer_end;
53 // Number of samples in output buffer before end
54 int buffer_size;
55 // Position in output buffer of buffer_end
56 int buffer_ptr;
57 // Output buffer, linear for each channel.
58 double **output_buffer;
59 // Copy of channel count for deletion
60 int channels;
61 // Input buffer for temporary compressed data
62 int input_size;
63 int input_allocation;
64 unsigned char *input_buffer;
65 // Entry in sample size table of next frame of audio to read
66 int sample_size_entry;
67 // Next sample/frame to read
68 int64_t sample;
69 } quicktime_vbr_t;
79 typedef struct
81 /* for AVI it's the end of the 8 byte header in the file */
82 /* for Quicktime it's the start of the 8 byte header in the file */
83 int64_t start;
84 int64_t end; /* byte endpoint in file */
85 int64_t size; /* byte size for writing */
86 int use_64; /* Use 64 bit header */
87 unsigned char type[5];
88 } quicktime_atom_t;
90 typedef struct
92 float values[9];
93 } quicktime_matrix_t;
96 typedef struct
98 int version;
99 long flags;
100 unsigned long creation_time;
101 unsigned long modification_time;
102 int track_id;
103 long reserved1;
104 long duration;
105 char reserved2[8];
106 int layer;
107 int alternate_group;
108 float volume;
109 long reserved3;
110 quicktime_matrix_t matrix;
111 float track_width;
112 float track_height;
113 } quicktime_tkhd_t;
116 typedef struct
118 long seed;
119 long flags;
120 long size;
121 short int *alpha;
122 short int *red;
123 short int *green;
124 short int *blue;
125 } quicktime_ctab_t;
129 /* ===================== sample table ======================== // */
133 /* sample description */
135 typedef struct
137 int motion_jpeg_quantization_table;
138 } quicktime_mjqt_t;
141 typedef struct
143 int motion_jpeg_huffman_table;
144 } quicktime_mjht_t;
147 typedef struct
149 char *mpeg4_header;
150 int mpeg4_header_size;
151 } quicktime_esds_t;
153 typedef struct
155 char *data;
156 int data_size;
157 } quicktime_avcc_t;
159 typedef struct
161 char format[4];
162 char reserved[6];
163 int data_reference;
165 /* common to audio and video */
166 int version;
167 int revision;
168 char vendor[4];
170 /* video description */
171 long temporal_quality;
172 long spatial_quality;
173 int width;
174 int height;
175 float dpi_horizontal;
176 float dpi_vertical;
177 int64_t data_size;
178 int frames_per_sample;
179 char compressor_name[32];
180 int depth;
181 int ctab_id;
182 quicktime_ctab_t ctab;
183 float gamma;
184 /* 0, 1, or 2 */
185 int fields;
186 /* 0 - unknown 1 - top first 2 - bottom first */
187 int field_dominance;
188 quicktime_mjqt_t mjqt;
189 quicktime_mjht_t mjht;
191 /* audio description */
192 int channels;
193 int sample_size;
194 int compression_id;
195 int packet_size;
196 float sample_rate;
198 /* Version 1 of audio description */
199 int samples_per_packet;
200 int bytes_per_packet;
201 int bytes_per_frame;
202 int bytes_per_sample;
204 quicktime_esds_t esds;
205 quicktime_avcc_t avcc;
207 int extradata_size;
208 char *extradata;
209 } quicktime_stsd_table_t;
212 typedef struct
214 int version;
215 long flags;
216 long total_entries;
217 quicktime_stsd_table_t *table;
218 } quicktime_stsd_t;
221 /* time to sample */
222 typedef struct
224 long sample_count;
225 long sample_duration;
226 } quicktime_stts_table_t;
228 typedef struct
230 int version;
231 long flags;
232 long total_entries;
233 int is_vbr;
234 quicktime_stts_table_t *table;
235 } quicktime_stts_t;
238 /* sync sample */
239 typedef struct
241 int64_t sample;
242 } quicktime_stss_table_t;
244 typedef struct
246 int version;
247 long flags;
248 long total_entries;
249 long entries_allocated;
250 quicktime_stss_table_t *table;
251 } quicktime_stss_t;
254 /* sample to chunk */
255 typedef struct
257 long chunk;
258 long samples;
259 long id;
260 } quicktime_stsc_table_t;
262 typedef struct
264 int version;
265 long flags;
266 long total_entries;
268 long entries_allocated;
269 quicktime_stsc_table_t *table;
270 } quicktime_stsc_t;
273 /* sample size */
274 typedef struct
276 int64_t size;
277 } quicktime_stsz_table_t;
279 typedef struct
281 int version;
282 long flags;
283 int64_t sample_size;
284 long total_entries;
286 long entries_allocated; /* used by the library for allocating a table */
287 quicktime_stsz_table_t *table;
288 } quicktime_stsz_t;
291 /* chunk offset */
292 typedef struct
294 int64_t offset;
295 } quicktime_stco_table_t;
297 typedef struct
299 int version;
300 long flags;
301 long total_entries;
303 long entries_allocated; /* used by the library for allocating a table */
304 quicktime_stco_table_t *table;
305 } quicktime_stco_t;
308 /* sample table */
309 typedef struct
311 int version;
312 long flags;
313 quicktime_stsd_t stsd;
314 quicktime_stts_t stts;
315 quicktime_stss_t stss;
316 quicktime_stsc_t stsc;
317 quicktime_stsz_t stsz;
318 quicktime_stco_t stco;
319 } quicktime_stbl_t;
321 /* data reference */
323 typedef struct
325 int64_t size;
326 char type[4];
327 int version;
328 long flags;
329 char *data_reference;
330 } quicktime_dref_table_t;
332 typedef struct
334 int version;
335 long flags;
336 long total_entries;
337 quicktime_dref_table_t *table;
338 } quicktime_dref_t;
340 /* data information */
342 typedef struct
344 quicktime_dref_t dref;
345 } quicktime_dinf_t;
347 /* video media header */
349 typedef struct
351 int version;
352 long flags;
353 int graphics_mode;
354 int opcolor[3];
355 } quicktime_vmhd_t;
358 /* sound media header */
360 typedef struct
362 int version;
363 long flags;
364 int balance;
365 int reserved;
366 } quicktime_smhd_t;
368 /* handler reference */
370 typedef struct
372 int version;
373 long flags;
374 char component_type[4];
375 char component_subtype[4];
376 long component_manufacturer;
377 long component_flags;
378 long component_flag_mask;
379 char component_name[256];
380 } quicktime_hdlr_t;
382 /* media information */
384 typedef struct
386 int is_video;
387 int is_audio;
388 quicktime_vmhd_t vmhd;
389 quicktime_smhd_t smhd;
390 quicktime_stbl_t stbl;
391 quicktime_hdlr_t hdlr;
392 quicktime_dinf_t dinf;
393 } quicktime_minf_t;
396 /* media header */
398 typedef struct
400 int version;
401 long flags;
402 unsigned long creation_time;
403 unsigned long modification_time;
404 long time_scale;
405 long duration;
406 int language;
407 int quality;
408 } quicktime_mdhd_t;
411 /* media */
413 typedef struct
415 quicktime_mdhd_t mdhd;
416 quicktime_minf_t minf;
417 quicktime_hdlr_t hdlr;
418 } quicktime_mdia_t;
420 /* edit list */
421 typedef struct
423 long duration;
424 long time;
425 float rate;
426 } quicktime_elst_table_t;
428 typedef struct
430 int version;
431 long flags;
432 long total_entries;
434 quicktime_elst_table_t *table;
435 } quicktime_elst_t;
437 typedef struct
439 quicktime_elst_t elst;
440 } quicktime_edts_t;
445 typedef struct
447 quicktime_tkhd_t tkhd;
448 quicktime_mdia_t mdia;
449 quicktime_edts_t edts;
450 } quicktime_trak_t;
453 typedef struct
455 int version;
456 long flags;
457 unsigned long creation_time;
458 unsigned long modification_time;
459 long time_scale;
460 long duration;
461 float preferred_rate;
462 float preferred_volume;
463 char reserved[10];
464 quicktime_matrix_t matrix;
465 long preview_time;
466 long preview_duration;
467 long poster_time;
468 long selection_time;
469 long selection_duration;
470 long current_time;
471 long next_track_id;
472 } quicktime_mvhd_t;
474 typedef struct
476 char *copyright;
477 int copyright_len;
478 char *name;
479 int name_len;
480 char *info;
481 int info_len;
482 char *require;
483 int require_len;
484 char *encoder;
485 int encoder_len;
486 } quicktime_udta_t;
489 typedef struct
491 int total_tracks;
493 quicktime_mvhd_t mvhd;
494 quicktime_trak_t *trak[MAXTRACKS];
495 quicktime_udta_t udta;
496 quicktime_ctab_t ctab;
497 } quicktime_moov_t;
499 typedef struct
501 quicktime_atom_t atom;
502 } quicktime_mdat_t;
504 typedef struct
506 /* Offset of end of 8 byte chunk header relative to ix->base_offset */
507 int relative_offset;
508 /* size of data without 8 byte header */
509 int size;
510 } quicktime_ixtable_t;
512 typedef struct
514 quicktime_atom_t atom;
515 quicktime_ixtable_t *table;
516 int table_size;
517 int table_allocation;
518 int longs_per_entry;
519 int index_type;
520 /* ixtable relative_offset is relative to this */
521 int64_t base_offset;
522 /* ix atom title */
523 char tag[5];
524 /* corresponding chunk id */
525 char chunk_id[5];
526 } quicktime_ix_t;
529 typedef struct
531 quicktime_atom_t atom;
533 /* Partial index */
534 /* For writing only, there are multiple movi objects with multiple ix tables. */
535 /* This is not used for reading. Instead an ix_t object in indx_t is used. */
536 quicktime_ix_t *ix[MAXTRACKS];
537 } quicktime_movi_t;
539 typedef struct
541 /* Start of start of corresponding ix## header */
542 int64_t index_offset;
543 /* Size not including 8 byte header */
544 int index_size;
545 /* duration in "ticks" */
546 int duration;
548 /* Partial index for reading only. */
549 quicktime_ix_t *ix;
550 } quicktime_indxtable_t;
552 typedef struct
554 quicktime_atom_t atom;
555 int longs_per_entry;
556 int index_subtype;
557 int index_type;
558 /* corresponding chunk id: 00wb, 00dc */
559 char chunk_id[5];
561 /* Number of partial indexes here */
562 int table_size;
563 int table_allocation;
564 quicktime_indxtable_t *table;
565 } quicktime_indx_t;
567 typedef struct
569 quicktime_atom_t atom;
570 /* Super index for reading */
571 quicktime_indx_t indx;
572 /* AVI needs header placeholders before anything else is written */
573 int64_t length_offset;
574 int64_t samples_per_chunk_offset;
575 int64_t sample_size_offset;
576 /* Start of indx header for later writing */
577 int64_t indx_offset;
578 /* Size of JUNK without 8 byte header which is to be replaced by indx */
579 int64_t padding_size;
580 /* Tag for writer with NULL termination: 00wb, 00dc Not available in reader.*/
581 char tag[5];
582 /* Flags for reader. Not available in writer. */
583 int is_audio;
584 int is_video;
585 /* Notify reader the super indexes are valid */
586 int have_indx;
587 } quicktime_strl_t;
589 typedef struct
591 quicktime_atom_t atom;
592 int64_t frames_offset;
593 int64_t bitrate_offset;
594 /* Offsets to be written during file closure */
595 int64_t total_frames_offset;
597 /* AVI equivalent for each trak. Use file->moov.total_tracks */
598 /* Need it for super indexes during reading. */
599 quicktime_strl_t *strl[MAXTRACKS];
600 } quicktime_hdrl_t;
602 typedef struct
604 char tag[5];
605 uint32_t flags;
606 /* Start of 8 byte chunk header relative to start of the 'movi' string */
607 int32_t offset;
608 /* Size of chunk less the 8 byte header */
609 int32_t size;
610 } quicktime_idx1table_t;
612 typedef struct
614 quicktime_atom_t atom;
615 quicktime_idx1table_t *table;
616 int table_size;
617 int table_allocation;
618 } quicktime_idx1_t;
620 typedef struct
622 quicktime_atom_t atom;
623 quicktime_movi_t movi;
624 quicktime_hdrl_t hdrl;
626 /* Full index */
627 quicktime_idx1_t idx1;
628 /* Notify reader the idx1 table is valid */
629 int have_idx1;
630 int have_hdrl;
631 } quicktime_riff_t;
633 /* table of pointers to every track */
634 typedef struct
636 quicktime_trak_t *track; /* real quicktime track corresponding to this table */
637 int channels; /* number of audio channels in the track */
638 long current_position; /* current sample in output file */
639 long current_chunk; /* current chunk in output file */
640 quicktime_vbr_t vbr; /* Stores for vbr codecs */
642 void *codec;
643 } quicktime_audio_map_t;
645 typedef struct
647 quicktime_trak_t *track;
648 long current_position; /* current frame in output file */
649 long current_chunk; /* current chunk in output file */
651 void *codec;
652 } quicktime_video_map_t;
654 /* file descriptor passed to all routines */
655 typedef struct
657 FILE *stream;
658 int64_t total_length;
659 quicktime_mdat_t mdat;
660 quicktime_moov_t moov;
661 int rd;
662 int wr;
664 /* If the moov atom is compressed */
665 int compressed_moov;
666 unsigned char *moov_data;
668 * Temporary storage of compressed sizes. If the file length is shorter than the
669 * uncompressed sizes, it won't work.
671 int64_t moov_end;
672 int64_t moov_size;
673 int64_t old_preload_size;
674 char *old_preload_buffer;
675 int64_t old_preload_start;
676 int64_t old_preload_end;
677 int64_t old_preload_ptr;
680 /* ASF section */
681 int use_asf;
686 /* AVI section */
687 int use_avi;
688 /* AVI tree */
689 quicktime_riff_t *riff[MAX_RIFFS];
690 int total_riffs;
691 /* is odml version of AVI */
692 int is_odml;
698 /* for begining and ending frame writes where the user wants to write the */
699 /* file descriptor directly */
700 int64_t offset;
702 /* I/O */
703 /* Current position of virtual file descriptor */
704 int64_t file_position;
706 /* Work around a bug in glibc where ftello returns only 32 bits by maintaining */
707 /* our own position */
708 int64_t ftell_position;
710 /* Read ahead buffer */
711 int64_t preload_size; /* Enables preload when nonzero. */
712 char *preload_buffer;
713 int64_t preload_start; /* Start of preload_buffer in file */
714 int64_t preload_end; /* End of preload buffer in file */
715 int64_t preload_ptr; /* Offset of preload_start in preload_buffer */
717 /* Write ahead buffer */
718 /* Amount of data in presave buffer */
719 int64_t presave_size;
720 /* Next presave byte's position in file */
721 int64_t presave_position;
722 char *presave_buffer;
723 /* Presave doesn't matter a whole lot, so its size is fixed */
724 #define QUICKTIME_PRESAVE 0x100000
725 int use_presave;
727 /* mapping of audio channels to movie tracks */
728 /* one audio map entry exists for each channel */
729 int total_atracks;
730 quicktime_audio_map_t *atracks;
732 /* mapping of video tracks to movie tracks */
733 int total_vtracks;
734 quicktime_video_map_t *vtracks;
736 /* Number of processors at our disposal */
737 int cpus;
739 /* Parameters for frame currently being decoded */
740 int do_scaling;
741 int in_x, in_y, in_w, in_h, out_w, out_h;
742 int color_model, row_span;
744 /* Adjustable timecode frame number */
745 int64_t current_frame;
747 } quicktime_t;
750 /* Structure created in track_map to describe the codec */
751 typedef struct
753 int (*delete_vcodec)(quicktime_video_map_t *vtrack);
754 int (*delete_acodec)(quicktime_audio_map_t *atrack);
755 /* Decode a single frame */
756 int (*decode_video)(quicktime_t *file,
757 unsigned char **row_pointers,
758 int track);
759 /* Encode a single frame */
760 int (*encode_video)(quicktime_t *file,
761 unsigned char **row_pointers,
762 int track);
763 /* Decode a certain number of samples */
764 int (*decode_audio)(quicktime_t *file,
765 int16_t *output_i,
766 float *output_f,
767 long samples,
768 int track,
769 int channel);
770 /* Encode a chunk of audio */
771 int (*encode_audio)(quicktime_t *file,
772 int16_t **input_i,
773 float **input_f,
774 int track,
775 long samples);
776 int (*reads_colormodel)(quicktime_t *file,
777 int colormodel,
778 int track);
779 int (*writes_colormodel)(quicktime_t *file,
780 int colormodel,
781 int track);
783 int (*set_parameter)(quicktime_t *file,
784 int track,
785 char *key,
786 void *value);
787 void (*flush)(quicktime_t *file,
788 int track);
790 /* AVI codec ID for audio. AVI codec ID's are based on WAV files, by the way. */
791 int wav_id;
793 /* Pointer to static character code for identifying the codec. */
794 char *fourcc;
796 /* English title of codec. Optional. */
797 char *title;
799 /* English description of codec. Optional. */
800 char *desc;
802 /* Proprietary data for the codec to allocate and delete. */
803 void *priv;
804 } quicktime_codec_t;
808 /* Structure tabulated in plugin.c to search the codecs */
809 typedef struct
811 void (*init_vcodec)(quicktime_video_map_t *);
812 void (*init_acodec)(quicktime_audio_map_t *);
813 } quicktime_codectable_t;
818 #endif