4 /* ================================= structures */
6 /* Version used internally. You need to query it with the C functions */
7 #define QUICKTIME_MAJOR 2
8 #define QUICKTIME_MINOR 2
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
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.
51 // End of the output buffer in the file in samples
53 // Number of samples in output buffer before end
55 // Position in output buffer of buffer_end
57 // Output buffer, linear for each channel.
58 double **output_buffer
;
59 // Copy of channel count for deletion
61 // Input buffer for temporary compressed data
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
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 */
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];
100 unsigned long creation_time
;
101 unsigned long modification_time
;
110 quicktime_matrix_t matrix
;
129 /* ===================== sample table ======================== // */
133 /* sample description */
137 int motion_jpeg_quantization_table
;
143 int motion_jpeg_huffman_table
;
150 int mpeg4_header_size
;
165 /* common to audio and video */
170 /* video description */
171 long temporal_quality
;
172 long spatial_quality
;
175 float dpi_horizontal
;
178 int frames_per_sample
;
179 char compressor_name
[32];
182 quicktime_ctab_t ctab
;
186 /* 0 - unknown 1 - top first 2 - bottom first */
188 quicktime_mjqt_t mjqt
;
189 quicktime_mjht_t mjht
;
191 /* audio description */
198 /* Version 1 of audio description */
199 int samples_per_packet
;
200 int bytes_per_packet
;
202 int bytes_per_sample
;
204 quicktime_esds_t esds
;
205 quicktime_avcc_t avcc
;
209 } quicktime_stsd_table_t
;
217 quicktime_stsd_table_t
*table
;
225 long sample_duration
;
226 } quicktime_stts_table_t
;
234 quicktime_stts_table_t
*table
;
242 } quicktime_stss_table_t
;
249 long entries_allocated
;
250 quicktime_stss_table_t
*table
;
254 /* sample to chunk */
260 } quicktime_stsc_table_t
;
268 long entries_allocated
;
269 quicktime_stsc_table_t
*table
;
277 } quicktime_stsz_table_t
;
286 long entries_allocated
; /* used by the library for allocating a table */
287 quicktime_stsz_table_t
*table
;
295 } quicktime_stco_table_t
;
303 long entries_allocated
; /* used by the library for allocating a table */
304 quicktime_stco_table_t
*table
;
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
;
329 char *data_reference
;
330 } quicktime_dref_table_t
;
337 quicktime_dref_table_t
*table
;
340 /* data information */
344 quicktime_dref_t dref
;
347 /* video media header */
358 /* sound media header */
368 /* handler reference */
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];
382 /* media information */
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
;
402 unsigned long creation_time
;
403 unsigned long modification_time
;
415 quicktime_mdhd_t mdhd
;
416 quicktime_minf_t minf
;
417 quicktime_hdlr_t hdlr
;
426 } quicktime_elst_table_t
;
434 quicktime_elst_table_t
*table
;
439 quicktime_elst_t elst
;
447 quicktime_tkhd_t tkhd
;
448 quicktime_mdia_t mdia
;
449 quicktime_edts_t edts
;
457 unsigned long creation_time
;
458 unsigned long modification_time
;
461 float preferred_rate
;
462 float preferred_volume
;
464 quicktime_matrix_t matrix
;
466 long preview_duration
;
469 long selection_duration
;
493 quicktime_mvhd_t mvhd
;
494 quicktime_trak_t
*trak
[MAXTRACKS
];
495 quicktime_udta_t udta
;
496 quicktime_ctab_t ctab
;
501 quicktime_atom_t atom
;
506 /* Offset of end of 8 byte chunk header relative to ix->base_offset */
508 /* size of data without 8 byte header */
510 } quicktime_ixtable_t
;
514 quicktime_atom_t atom
;
515 quicktime_ixtable_t
*table
;
517 int table_allocation
;
520 /* ixtable relative_offset is relative to this */
524 /* corresponding chunk id */
531 quicktime_atom_t atom
;
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
];
541 /* Start of start of corresponding ix## header */
542 int64_t index_offset
;
543 /* Size not including 8 byte header */
545 /* duration in "ticks" */
548 /* Partial index for reading only. */
550 } quicktime_indxtable_t
;
554 quicktime_atom_t atom
;
558 /* corresponding chunk id: 00wb, 00dc */
561 /* Number of partial indexes here */
563 int table_allocation
;
564 quicktime_indxtable_t
*table
;
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 */
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.*/
582 /* Flags for reader. Not available in writer. */
585 /* Notify reader the super indexes are valid */
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
];
606 /* Start of 8 byte chunk header relative to start of the 'movi' string */
608 /* Size of chunk less the 8 byte header */
610 } quicktime_idx1table_t
;
614 quicktime_atom_t atom
;
615 quicktime_idx1table_t
*table
;
617 int table_allocation
;
622 quicktime_atom_t atom
;
623 quicktime_movi_t movi
;
624 quicktime_hdrl_t hdrl
;
627 quicktime_idx1_t idx1
;
628 /* Notify reader the idx1 table is valid */
635 unsigned char *y
, *u
, *v
;
639 int64_t frame_number
;
640 } quicktime_cacheframe_t
;
644 quicktime_cacheframe_t
*frames
;
649 /* table of pointers to every track */
652 quicktime_trak_t
*track
; /* real quicktime track corresponding to this table */
653 int channels
; /* number of audio channels in the track */
654 int64_t current_position
; /* current sample in output file */
655 int64_t current_chunk
; /* current chunk in output file */
656 quicktime_vbr_t vbr
; /* Stores for vbr codecs */
659 } quicktime_audio_map_t
;
663 quicktime_trak_t
*track
;
664 int64_t current_position
; /* current frame in output file */
665 int64_t current_chunk
; /* current chunk in output file */
666 // Cache for the current GOP after a seek.
667 quicktime_cache_t
*frame_cache
;
670 } quicktime_video_map_t
;
672 /* file descriptor passed to all routines */
676 int64_t total_length
;
677 quicktime_mdat_t mdat
;
678 quicktime_moov_t moov
;
682 /* If the moov atom is compressed */
684 unsigned char *moov_data
;
686 * Temporary storage of compressed sizes. If the file length is shorter than the
687 * uncompressed sizes, it won't work.
691 int64_t old_preload_size
;
692 char *old_preload_buffer
;
693 int64_t old_preload_start
;
694 int64_t old_preload_end
;
695 int64_t old_preload_ptr
;
707 quicktime_riff_t
*riff
[MAX_RIFFS
];
709 /* is odml version of AVI */
716 /* for begining and ending frame writes where the user wants to write the */
717 /* file descriptor directly */
721 /* Current position of virtual file descriptor */
722 int64_t file_position
;
724 /* Work around a bug in glibc where ftello returns only 32 bits by maintaining */
725 /* our own position */
726 int64_t ftell_position
;
728 /* Read ahead buffer */
729 int64_t preload_size
; /* Enables preload when nonzero. */
730 char *preload_buffer
;
731 int64_t preload_start
; /* Start of preload_buffer in file */
732 int64_t preload_end
; /* End of preload buffer in file */
733 int64_t preload_ptr
; /* Offset of preload_start in preload_buffer */
735 /* Write ahead buffer */
736 /* Amount of data in presave buffer */
737 int64_t presave_size
;
738 /* Next presave byte's position in file */
739 int64_t presave_position
;
740 char *presave_buffer
;
741 /* Presave doesn't matter a whole lot, so its size is fixed */
742 #define QUICKTIME_PRESAVE 0x100000
745 /* mapping of audio channels to movie tracks */
746 /* one audio map entry exists for each channel */
748 quicktime_audio_map_t
*atracks
;
750 /* mapping of video tracks to movie tracks */
752 quicktime_video_map_t
*vtracks
;
754 /* Number of processors at our disposal */
757 /* Parameters for frame currently being decoded */
759 int in_x
, in_y
, in_w
, in_h
, out_w
, out_h
;
760 int color_model
, row_span
;
762 /* Adjustable timecode frame number */
763 int64_t current_frame
;
768 /* Structure created in track_map to describe the codec */
771 int (*delete_vcodec
)(quicktime_video_map_t
*vtrack
);
772 int (*delete_acodec
)(quicktime_audio_map_t
*atrack
);
773 /* Decode a single frame */
774 int (*decode_video
)(quicktime_t
*file
,
775 unsigned char **row_pointers
,
777 /* Encode a single frame */
778 int (*encode_video
)(quicktime_t
*file
,
779 unsigned char **row_pointers
,
781 /* Decode a certain number of samples */
782 int (*decode_audio
)(quicktime_t
*file
,
788 /* Encode a chunk of audio */
789 int (*encode_audio
)(quicktime_t
*file
,
794 int (*reads_colormodel
)(quicktime_t
*file
,
797 int (*writes_colormodel
)(quicktime_t
*file
,
801 int (*set_parameter
)(quicktime_t
*file
,
805 void (*flush
)(quicktime_t
*file
,
808 /* AVI codec ID for audio. AVI codec ID's are based on WAV files, by the way. */
811 /* Pointer to static character code for identifying the codec. */
814 /* English title of codec. Optional. */
817 /* English description of codec. Optional. */
820 /* Frame cache for seeking only. */
823 /* Proprietary data for the codec to allocate and delete. */
829 /* Structure tabulated in plugin.c to search the codecs */
832 void (*init_vcodec
)(quicktime_video_map_t
*);
833 void (*init_acodec
)(quicktime_audio_map_t
*);
834 } quicktime_codectable_t
;