4 /* ================================= structures */
6 /* Version used internally. You need to query it with the C functions */
7 #define QUICKTIME_MAJOR 2
8 #define QUICKTIME_MINOR 3
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 #define QT_TRACE printf("%s: %d\n", __FILE__, __LINE__);
39 #define FTELL ftello64
40 #define FSEEK fseeko64
43 // ffmpeg requires global variable initialization
44 // These are defined in mpeg4.c
45 extern int ffmpeg_initialized;
46 extern pthread_mutex_t ffmpeg_lock;
50 // Utility functions for vbr audio. This is accessed through quicktime_audio_map_t.
53 // End of the input/output buffer in the file in samples
54 int64_t input_end, output_end;
55 // Number of samples in input/output buffer before end
56 int input_size, output_size;
57 // Position in input/output buffer of buffer_end
59 // Output buffer, linear for each channel.
60 double **output_buffer;
61 // Copy of channel count for deletion
63 // Input buffer for temporary compressed data
65 unsigned char *input_buffer;
66 // Next sample/frame to read
80 /* for AVI it's the end of the 8 byte header in the file */
81 /* for Quicktime it's the start of the 8 byte header in the file */
83 int64_t end; /* byte endpoint in file */
84 int64_t size; /* byte size for writing */
85 int use_64; /* Use 64 bit header */
86 unsigned char type[5];
99 unsigned long creation_time;
100 unsigned long modification_time;
109 quicktime_matrix_t matrix;
128 /* ===================== sample table ======================== // */
132 /* sample description */
136 int motion_jpeg_quantization_table;
142 int motion_jpeg_huffman_table;
149 int mpeg4_header_size;
170 /* common to audio and video */
175 /* video description */
176 long temporal_quality;
177 long spatial_quality;
180 float dpi_horizontal;
183 int frames_per_sample;
184 char compressor_name[32];
187 quicktime_ctab_t ctab;
191 /* 0 - unknown 1 - top first 2 - bottom first */
193 quicktime_mjqt_t mjqt;
194 quicktime_mjht_t mjht;
196 /* audio description */
203 /* Version 1 of audio description */
204 int samples_per_packet;
205 int bytes_per_packet;
207 int bytes_per_sample;
209 quicktime_esds_t esds;
210 quicktime_avcc_t avcc;
215 quicktime_frma_t frma;
216 } quicktime_stsd_table_t;
224 quicktime_stsd_table_t *table;
232 long sample_duration;
233 } quicktime_stts_table_t;
241 quicktime_stts_table_t *table;
249 } quicktime_stss_table_t;
256 long entries_allocated;
257 quicktime_stss_table_t *table;
261 /* sample to chunk */
267 } quicktime_stsc_table_t;
275 long entries_allocated;
276 quicktime_stsc_table_t *table;
284 } quicktime_stsz_table_t;
293 long entries_allocated; /* used by the library for allocating a table */
294 quicktime_stsz_table_t *table;
302 } quicktime_stco_table_t;
310 long entries_allocated; /* used by the library for allocating a table */
311 quicktime_stco_table_t *table;
320 quicktime_stsd_t stsd;
321 quicktime_stts_t stts;
322 quicktime_stss_t stss;
323 quicktime_stsc_t stsc;
324 quicktime_stsz_t stsz;
325 quicktime_stco_t stco;
336 char *data_reference;
337 } quicktime_dref_table_t;
344 quicktime_dref_table_t *table;
347 /* data information */
351 quicktime_dref_t dref;
354 /* video media header */
365 /* sound media header */
375 /* handler reference */
381 char component_type[4];
382 char component_subtype[4];
383 long component_manufacturer;
384 long component_flags;
385 long component_flag_mask;
386 char component_name[256];
389 /* media information */
395 quicktime_vmhd_t vmhd;
396 quicktime_smhd_t smhd;
397 quicktime_stbl_t stbl;
398 quicktime_hdlr_t hdlr;
399 quicktime_dinf_t dinf;
409 unsigned long creation_time;
410 unsigned long modification_time;
422 quicktime_mdhd_t mdhd;
423 quicktime_minf_t minf;
424 quicktime_hdlr_t hdlr;
433 } quicktime_elst_table_t;
441 quicktime_elst_table_t *table;
446 quicktime_elst_t elst;
454 quicktime_tkhd_t tkhd;
455 quicktime_mdia_t mdia;
456 quicktime_edts_t edts;
464 unsigned long creation_time;
465 unsigned long modification_time;
468 float preferred_rate;
469 float preferred_volume;
471 quicktime_matrix_t matrix;
473 long preview_duration;
476 long selection_duration;
500 quicktime_mvhd_t mvhd;
501 quicktime_trak_t *trak[MAXTRACKS];
502 quicktime_udta_t udta;
503 quicktime_ctab_t ctab;
508 quicktime_atom_t atom;
513 /* Offset of end of 8 byte chunk header relative to ix->base_offset */
515 /* size of data without 8 byte header */
517 } quicktime_ixtable_t;
521 quicktime_atom_t atom;
522 quicktime_ixtable_t *table;
524 int table_allocation;
527 /* ixtable relative_offset is relative to this */
531 /* corresponding chunk id */
538 quicktime_atom_t atom;
541 /* For writing only, there are multiple movi objects with multiple ix tables. */
542 /* This is not used for reading. Instead an ix_t object in indx_t is used. */
543 quicktime_ix_t *ix[MAXTRACKS];
548 /* Start of start of corresponding ix## header */
549 int64_t index_offset;
550 /* Size not including 8 byte header */
552 /* duration in "ticks" */
555 /* Partial index for reading only. */
557 } quicktime_indxtable_t;
561 quicktime_atom_t atom;
565 /* corresponding chunk id: 00wb, 00dc */
568 /* Number of partial indexes here */
570 int table_allocation;
571 quicktime_indxtable_t *table;
574 /* AVI equivalent for each trak. Use file->moov.total_tracks */
575 /* Need it for super indexes during reading. */
578 quicktime_atom_t atom;
579 /* Super index for reading */
580 quicktime_indx_t indx;
581 /* AVI needs header placeholders before anything else is written */
582 int64_t length_offset;
583 /* Sample count read directly from auds */
585 /* Bytes per second read directly from auds */
586 int bytes_per_second;
587 /* Bytes totalled up from idx1 */
589 int64_t samples_per_chunk_offset;
590 int64_t sample_size_offset;
591 /* Start of indx header for later writing */
593 /* Size of JUNK without 8 byte header which is to be replaced by indx */
594 int64_t padding_size;
595 /* Tag for writer with NULL termination: 00wb, 00dc Not available in reader.*/
597 /* Flags for reader. Not available in writer. */
600 /* Notify reader the super indexes are valid */
606 quicktime_atom_t atom;
607 int64_t frames_offset;
608 int64_t bitrate_offset;
609 /* Offsets to be written during file closure */
610 int64_t total_frames_offset;
612 /* AVI equivalent for each trak. Use file->moov.total_tracks */
613 /* Need it for super indexes during reading. */
614 quicktime_strl_t *strl[MAXTRACKS];
621 /* Start of 8 byte chunk header relative to start of the 'movi' string */
623 /* Size of chunk less the 8 byte header */
625 } quicktime_idx1table_t;
629 quicktime_atom_t atom;
630 quicktime_idx1table_t *table;
632 int table_allocation;
637 quicktime_atom_t atom;
638 quicktime_movi_t movi;
639 quicktime_hdrl_t hdrl;
642 quicktime_idx1_t idx1;
643 /* Notify reader the idx1 table is valid */
650 unsigned char *y, *u, *v;
654 int64_t frame_number;
655 } quicktime_cacheframe_t;
659 quicktime_cacheframe_t *frames;
665 /* table of pointers to every track */
668 quicktime_trak_t *track; /* real quicktime track corresponding to this table */
669 int channels; /* number of audio channels in the track */
670 int64_t current_position; /* current sample in output file */
671 int64_t current_chunk; /* current chunk in output file */
672 quicktime_vbr_t vbr; /* Stores for vbr codecs */
675 } quicktime_audio_map_t;
679 quicktime_trak_t *track;
680 int64_t current_position; /* current frame in output file */
681 int64_t current_chunk; /* current chunk in output file */
682 // Cache for the current GOP after a seek.
683 quicktime_cache_t *frame_cache;
686 } quicktime_video_map_t;
688 /* file descriptor passed to all routines */
692 int64_t total_length;
693 quicktime_mdat_t mdat;
694 quicktime_moov_t moov;
698 /* If the moov atom is compressed */
700 unsigned char *moov_data;
702 * Temporary storage of compressed sizes. If the file length is shorter than the
703 * uncompressed sizes, it won't work.
707 int64_t old_preload_size;
708 char *old_preload_buffer;
709 int64_t old_preload_start;
710 int64_t old_preload_end;
711 int64_t old_preload_ptr;
717 /* ASF/WMV section */
727 quicktime_riff_t *riff[MAX_RIFFS];
729 /* is odml version of AVI */
739 /* for begining and ending frame writes where the user wants to write the */
740 /* file descriptor directly */
744 /* Current position of virtual file descriptor */
745 int64_t file_position;
747 /* Work around a bug in glibc where ftello returns only 32 bits by maintaining */
748 /* our own position */
749 int64_t ftell_position;
751 /* Read ahead buffer */
752 int64_t preload_size; /* Enables preload when nonzero. */
753 char *preload_buffer;
754 int64_t preload_start; /* Start of preload_buffer in file */
755 int64_t preload_end; /* End of preload buffer in file */
756 int64_t preload_ptr; /* Offset of preload_start in preload_buffer */
758 /* Temporary storage until tracks are created */
761 /* Write ahead buffer */
762 /* Amount of data in presave buffer */
763 int64_t presave_size;
764 /* Next presave byte's position in file */
765 int64_t presave_position;
766 char *presave_buffer;
767 /* Presave doesn't matter a whole lot, so its size is fixed */
768 #define QUICKTIME_PRESAVE 0x100000
771 /* mapping of audio channels to movie tracks */
772 /* one audio map entry exists for each channel */
774 quicktime_audio_map_t *atracks;
776 /* mapping of video tracks to movie tracks */
778 quicktime_video_map_t *vtracks;
780 /* Number of processors at our disposal */
783 /* Parameters for frame currently being decoded */
785 int in_x, in_y, in_w, in_h, out_w, out_h;
786 int color_model, row_span;
788 /* Adjustable timecode frame number */
789 int64_t current_frame;
794 /* Structure created in track_map to describe the codec */
797 void (*delete_vcodec)(quicktime_video_map_t *vtrack);
798 void (*delete_acodec)(quicktime_audio_map_t *atrack);
799 /* Decode a single frame */
800 int (*decode_video)(quicktime_t *file,
801 unsigned char **row_pointers,
803 /* Encode a single frame */
804 int (*encode_video)(quicktime_t *file,
805 unsigned char **row_pointers,
807 /* Decode a certain number of samples */
808 int (*decode_audio)(quicktime_t *file,
814 /* Encode a chunk of audio */
815 int (*encode_audio)(quicktime_t *file,
820 int (*reads_colormodel)(quicktime_t *file,
823 int (*writes_colormodel)(quicktime_t *file,
827 int (*set_parameter)(quicktime_t *file,
831 void (*flush)(quicktime_t *file,
834 /* AVI codec ID for audio. AVI codec ID's are based on WAV files, by the way. */
837 /* Pointer to static character code for identifying the codec. */
840 /* English title of codec. Optional. */
843 /* English description of codec. Optional. */
846 /* Frame cache for seeking only. */
849 /* Proprietary data for the codec to allocate and delete. */
855 /* Structure tabulated in plugin.c to search the codecs */
859 void (*init_vcodec)(quicktime_video_map_t *);
860 void (*init_acodec)(quicktime_audio_map_t *);
861 } quicktime_codectable_t;