r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / quicktime / qtprivate.h
bloba0f0e395ca0157173640d2f340cc2cb0ed24ff48
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 4
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;
73 typedef struct
75 /* for AVI it's the end of the 8 byte header in the file */
76 /* for Quicktime it's the start of the 8 byte header in the file */
77 int64_t start;
78 int64_t end; /* byte endpoint in file */
79 int64_t size; /* byte size for writing */
80 int use_64; /* Use 64 bit header */
81 unsigned char type[4];
82 } quicktime_atom_t;
84 typedef struct
86 float values[9];
87 } quicktime_matrix_t;
90 typedef struct
92 int version;
93 long flags;
94 unsigned long creation_time;
95 unsigned long modification_time;
96 int track_id;
97 long reserved1;
98 long duration;
99 char reserved2[8];
100 int layer;
101 int alternate_group;
102 float volume;
103 long reserved3;
104 quicktime_matrix_t matrix;
105 float track_width;
106 float track_height;
107 } quicktime_tkhd_t;
110 typedef struct
112 long seed;
113 long flags;
114 long size;
115 short int *alpha;
116 short int *red;
117 short int *green;
118 short int *blue;
119 } quicktime_ctab_t;
123 /* ===================== sample table ======================== // */
127 /* sample description */
129 typedef struct
131 int motion_jpeg_quantization_table;
132 } quicktime_mjqt_t;
135 typedef struct
137 int motion_jpeg_huffman_table;
138 } quicktime_mjht_t;
141 typedef struct
143 char format[4];
144 char reserved[6];
145 int data_reference;
147 /* common to audio and video */
148 int version;
149 int revision;
150 char vendor[4];
152 /* video description */
153 long temporal_quality;
154 long spatial_quality;
155 int width;
156 int height;
157 float dpi_horizontal;
158 float dpi_vertical;
159 int64_t data_size;
160 int frames_per_sample;
161 char compressor_name[32];
162 int depth;
163 int ctab_id;
164 quicktime_ctab_t ctab;
165 float gamma;
166 /* 0, 1, or 2 */
167 int fields;
168 /* 0 - unknown 1 - top first 2 - bottom first */
169 int field_dominance;
170 quicktime_mjqt_t mjqt;
171 quicktime_mjht_t mjht;
173 /* audio description */
174 int channels;
175 int sample_size;
176 int compression_id;
177 int packet_size;
178 float sample_rate;
179 char *mpeg4_header;
180 int mpeg4_header_size;
182 /* Version 1 of audio description */
183 int samples_per_packet;
184 int bytes_per_packet;
185 int bytes_per_frame;
186 int bytes_per_sample;
187 } quicktime_stsd_table_t;
190 typedef struct
192 int version;
193 long flags;
194 long total_entries;
195 quicktime_stsd_table_t *table;
196 } quicktime_stsd_t;
199 /* time to sample */
200 typedef struct
202 long sample_count;
203 long sample_duration;
204 } quicktime_stts_table_t;
206 typedef struct
208 int version;
209 long flags;
210 long total_entries;
211 quicktime_stts_table_t *table;
212 } quicktime_stts_t;
215 /* sync sample */
216 typedef struct
218 long sample;
219 } quicktime_stss_table_t;
221 typedef struct
223 int version;
224 long flags;
225 long total_entries;
226 long entries_allocated;
227 quicktime_stss_table_t *table;
228 } quicktime_stss_t;
231 /* sample to chunk */
232 typedef struct
234 long chunk;
235 long samples;
236 long id;
237 } quicktime_stsc_table_t;
239 typedef struct
241 int version;
242 long flags;
243 long total_entries;
245 long entries_allocated;
246 quicktime_stsc_table_t *table;
247 } quicktime_stsc_t;
250 /* sample size */
251 typedef struct
253 int64_t size;
254 } quicktime_stsz_table_t;
256 typedef struct
258 int version;
259 long flags;
260 int64_t sample_size;
261 long total_entries;
263 long entries_allocated; /* used by the library for allocating a table */
264 quicktime_stsz_table_t *table;
265 } quicktime_stsz_t;
268 /* chunk offset */
269 typedef struct
271 int64_t offset;
272 } quicktime_stco_table_t;
274 typedef struct
276 int version;
277 long flags;
278 long total_entries;
280 long entries_allocated; /* used by the library for allocating a table */
281 quicktime_stco_table_t *table;
282 } quicktime_stco_t;
285 /* sample table */
286 typedef struct
288 int version;
289 long flags;
290 quicktime_stsd_t stsd;
291 quicktime_stts_t stts;
292 quicktime_stss_t stss;
293 quicktime_stsc_t stsc;
294 quicktime_stsz_t stsz;
295 quicktime_stco_t stco;
296 } quicktime_stbl_t;
298 /* data reference */
300 typedef struct
302 int64_t size;
303 char type[4];
304 int version;
305 long flags;
306 char *data_reference;
307 } quicktime_dref_table_t;
309 typedef struct
311 int version;
312 long flags;
313 long total_entries;
314 quicktime_dref_table_t *table;
315 } quicktime_dref_t;
317 /* data information */
319 typedef struct
321 quicktime_dref_t dref;
322 } quicktime_dinf_t;
324 /* video media header */
326 typedef struct
328 int version;
329 long flags;
330 int graphics_mode;
331 int opcolor[3];
332 } quicktime_vmhd_t;
335 /* sound media header */
337 typedef struct
339 int version;
340 long flags;
341 int balance;
342 int reserved;
343 } quicktime_smhd_t;
345 /* handler reference */
347 typedef struct
349 int version;
350 long flags;
351 char component_type[4];
352 char component_subtype[4];
353 long component_manufacturer;
354 long component_flags;
355 long component_flag_mask;
356 char component_name[256];
357 } quicktime_hdlr_t;
359 /* media information */
361 typedef struct
363 int is_video;
364 int is_audio;
365 quicktime_vmhd_t vmhd;
366 quicktime_smhd_t smhd;
367 quicktime_stbl_t stbl;
368 quicktime_hdlr_t hdlr;
369 quicktime_dinf_t dinf;
370 } quicktime_minf_t;
373 /* media header */
375 typedef struct
377 int version;
378 long flags;
379 unsigned long creation_time;
380 unsigned long modification_time;
381 long time_scale;
382 long duration;
383 int language;
384 int quality;
385 } quicktime_mdhd_t;
388 /* media */
390 typedef struct
392 quicktime_mdhd_t mdhd;
393 quicktime_minf_t minf;
394 quicktime_hdlr_t hdlr;
395 } quicktime_mdia_t;
397 /* edit list */
398 typedef struct
400 long duration;
401 long time;
402 float rate;
403 } quicktime_elst_table_t;
405 typedef struct
407 int version;
408 long flags;
409 long total_entries;
411 quicktime_elst_table_t *table;
412 } quicktime_elst_t;
414 typedef struct
416 quicktime_elst_t elst;
417 } quicktime_edts_t;
422 typedef struct
424 quicktime_tkhd_t tkhd;
425 quicktime_mdia_t mdia;
426 quicktime_edts_t edts;
427 } quicktime_trak_t;
430 typedef struct
432 int version;
433 long flags;
434 unsigned long creation_time;
435 unsigned long modification_time;
436 long time_scale;
437 long duration;
438 float preferred_rate;
439 float preferred_volume;
440 char reserved[10];
441 quicktime_matrix_t matrix;
442 long preview_time;
443 long preview_duration;
444 long poster_time;
445 long selection_time;
446 long selection_duration;
447 long current_time;
448 long next_track_id;
449 } quicktime_mvhd_t;
451 typedef struct
453 char *copyright;
454 int copyright_len;
455 char *name;
456 int name_len;
457 char *info;
458 int info_len;
459 } quicktime_udta_t;
462 typedef struct
464 int total_tracks;
466 quicktime_mvhd_t mvhd;
467 quicktime_trak_t *trak[MAXTRACKS];
468 quicktime_udta_t udta;
469 quicktime_ctab_t ctab;
470 } quicktime_moov_t;
472 typedef struct
474 quicktime_atom_t atom;
475 } quicktime_mdat_t;
477 typedef struct
479 /* Offset of end of 8 byte chunk header relative to ix->base_offset */
480 int relative_offset;
481 /* size of data without 8 byte header */
482 int size;
483 } quicktime_ixtable_t;
485 typedef struct
487 quicktime_atom_t atom;
488 quicktime_ixtable_t *table;
489 int table_size;
490 int table_allocation;
491 int longs_per_entry;
492 int index_type;
493 /* ixtable relative_offset is relative to this */
494 int64_t base_offset;
495 /* ix atom title */
496 char tag[5];
497 /* corresponding chunk id */
498 char chunk_id[5];
499 } quicktime_ix_t;
502 typedef struct
504 quicktime_atom_t atom;
506 /* Partial index */
507 /* For writing only, there are multiple movi objects with multiple ix tables. */
508 /* This is not used for reading. Instead an ix_t object in indx_t is used. */
509 quicktime_ix_t *ix[MAXTRACKS];
510 } quicktime_movi_t;
512 typedef struct
514 /* Start of start of corresponding ix## header */
515 int64_t index_offset;
516 /* Size not including 8 byte header */
517 int index_size;
518 /* duration in "ticks" */
519 int duration;
521 /* Partial index for reading only. */
522 quicktime_ix_t *ix;
523 } quicktime_indxtable_t;
525 typedef struct
527 quicktime_atom_t atom;
528 int longs_per_entry;
529 int index_subtype;
530 int index_type;
531 /* corresponding chunk id: 00wb, 00dc */
532 char chunk_id[5];
534 /* Number of partial indexes here */
535 int table_size;
536 int table_allocation;
537 quicktime_indxtable_t *table;
538 } quicktime_indx_t;
540 typedef struct
542 quicktime_atom_t atom;
543 /* Super index for reading */
544 quicktime_indx_t indx;
545 /* AVI needs header placeholders before anything else is written */
546 int64_t length_offset;
547 int64_t samples_per_chunk_offset;
548 int64_t sample_size_offset;
549 /* Start of indx header for later writing */
550 int64_t indx_offset;
551 /* Size of JUNK without 8 byte header which is to be replaced by indx */
552 int64_t padding_size;
553 /* Tag for writer with NULL termination: 00wb, 00dc Not available in reader.*/
554 char tag[5];
555 /* Flags for reader. Not available in writer. */
556 int is_audio;
557 int is_video;
558 /* Notify reader the super indexes are valid */
559 int have_indx;
560 } quicktime_strl_t;
562 typedef struct
564 quicktime_atom_t atom;
565 int64_t frames_offset;
566 int64_t bitrate_offset;
567 /* Offsets to be written during file closure */
568 int64_t total_frames_offset;
570 /* AVI equivalent for each trak. Use file->moov.total_tracks */
571 /* Need it for super indexes during reading. */
572 quicktime_strl_t *strl[MAXTRACKS];
573 } quicktime_hdrl_t;
575 typedef struct
577 char tag[5];
578 uint32_t flags;
579 /* Start of 8 byte chunk header relative to start of the 'movi' string */
580 int32_t offset;
581 /* Size of chunk less the 8 byte header */
582 int32_t size;
583 } quicktime_idx1table_t;
585 typedef struct
587 quicktime_atom_t atom;
588 quicktime_idx1table_t *table;
589 int table_size;
590 int table_allocation;
591 } quicktime_idx1_t;
593 typedef struct
595 quicktime_atom_t atom;
596 quicktime_movi_t movi;
597 quicktime_hdrl_t hdrl;
599 /* Full index */
600 quicktime_idx1_t idx1;
601 /* Notify reader the idx1 table is valid */
602 int have_idx1;
603 int have_hdrl;
604 } quicktime_riff_t;
606 /* table of pointers to every track */
607 typedef struct
609 quicktime_trak_t *track; /* real quicktime track corresponding to this table */
610 int channels; /* number of audio channels in the track */
611 long current_position; /* current sample in output file */
612 long current_chunk; /* current chunk in output file */
613 quicktime_vbr_t vbr; /* Stores for vbr codecs */
615 void *codec;
616 } quicktime_audio_map_t;
618 typedef struct
620 quicktime_trak_t *track;
621 long current_position; /* current frame in output file */
622 long current_chunk; /* current chunk in output file */
624 void *codec;
625 } quicktime_video_map_t;
627 /* file descriptor passed to all routines */
628 typedef struct
630 FILE *stream;
631 int64_t total_length;
632 quicktime_mdat_t mdat;
633 quicktime_moov_t moov;
634 int rd;
635 int wr;
637 /* If the moov atom is compressed */
638 int compressed_moov;
639 unsigned char *moov_data;
641 * Temporary storage of compressed sizes. If the file length is shorter than the
642 * uncompressed sizes, it won't work.
644 int64_t moov_end;
645 int64_t moov_size;
646 int64_t old_preload_size;
647 char *old_preload_buffer;
648 int64_t old_preload_start;
649 int64_t old_preload_end;
650 int64_t old_preload_ptr;
653 /* ASF section */
654 int use_asf;
659 /* AVI section */
660 int use_avi;
661 /* AVI tree */
662 quicktime_riff_t *riff[MAX_RIFFS];
663 int total_riffs;
669 /* for begining and ending frame writes where the user wants to write the */
670 /* file descriptor directly */
671 int64_t offset;
673 /* I/O */
674 /* Current position of virtual file descriptor */
675 int64_t file_position;
677 /* Work around a bug in glibc where ftello returns only 32 bits by maintaining */
678 /* our own position */
679 int64_t ftell_position;
681 /* Read ahead buffer */
682 int64_t preload_size; /* Enables preload when nonzero. */
683 char *preload_buffer;
684 int64_t preload_start; /* Start of preload_buffer in file */
685 int64_t preload_end; /* End of preload buffer in file */
686 int64_t preload_ptr; /* Offset of preload_start in preload_buffer */
688 /* Write ahead buffer */
689 /* Amount of data in presave buffer */
690 int64_t presave_size;
691 /* Next presave byte's position in file */
692 int64_t presave_position;
693 char *presave_buffer;
694 /* Presave doesn't matter a whole lot, so its size is fixed */
695 #define QUICKTIME_PRESAVE 0x100000
696 int use_presave;
698 /* mapping of audio channels to movie tracks */
699 /* one audio map entry exists for each channel */
700 int total_atracks;
701 quicktime_audio_map_t *atracks;
703 /* mapping of video tracks to movie tracks */
704 int total_vtracks;
705 quicktime_video_map_t *vtracks;
707 /* Number of processors at our disposal */
708 int cpus;
710 /* Parameters for frame currently being decoded */
711 int do_scaling;
712 int in_x, in_y, in_w, in_h, out_w, out_h;
713 int color_model, row_span;
715 /* Adjustable timecode frame number */
716 int64_t current_frame;
718 /* is odml file? */
719 int is_odml;
721 } quicktime_t;
724 /* Structure created in track_map to describe the codec */
725 typedef struct
727 int (*delete_vcodec)(quicktime_video_map_t *vtrack);
728 int (*delete_acodec)(quicktime_audio_map_t *atrack);
729 /* Decode a single frame */
730 int (*decode_video)(quicktime_t *file,
731 unsigned char **row_pointers,
732 int track);
733 /* Encode a single frame */
734 int (*encode_video)(quicktime_t *file,
735 unsigned char **row_pointers,
736 int track);
737 /* Decode a certain number of samples */
738 int (*decode_audio)(quicktime_t *file,
739 int16_t *output_i,
740 float *output_f,
741 long samples,
742 int track,
743 int channel);
744 /* Encode a chunk of audio */
745 int (*encode_audio)(quicktime_t *file,
746 int16_t **input_i,
747 float **input_f,
748 int track,
749 long samples);
750 int (*reads_colormodel)(quicktime_t *file,
751 int colormodel,
752 int track);
753 int (*writes_colormodel)(quicktime_t *file,
754 int colormodel,
755 int track);
757 int (*set_parameter)(quicktime_t *file,
758 int track,
759 char *key,
760 void *value);
761 void (*flush)(quicktime_t *file,
762 int track);
764 /* AVI codec ID for audio. AVI codec ID's are based on WAV files, by the way. */
765 int wav_id;
767 /* Pointer to static character code for identifying the codec. */
768 char *fourcc;
770 /* English title of codec. Optional. */
771 char *title;
773 /* English description of codec. Optional. */
774 char *desc;
776 /* Proprietary data for the codec to allocate and delete. */
777 void *priv;
778 } quicktime_codec_t;
782 /* Structure tabulated in plugin.c to search the codecs */
783 typedef struct
785 void (*init_vcodec)(quicktime_video_map_t *);
786 void (*init_acodec)(quicktime_audio_map_t *);
787 } quicktime_codectable_t;
792 #endif