7 /* atom handling routines */
8 int quicktime_atom_write_header(quicktime_t
*file
, quicktime_atom_t
*atom
, char *text
);
9 int quicktime_atom_write_header64(quicktime_t
*file
, quicktime_atom_t
*atom
, char *text
);
10 int64_t quicktime_byte_position(quicktime_t
*file
);
11 // Used internally to replace ftello values
12 int64_t quicktime_ftell(quicktime_t
*file
);
13 int quicktime_atom_is(quicktime_atom_t
*atom
, unsigned char *type
);
15 quicktime_trak_t
* quicktime_add_track(quicktime_t
*file
);
19 int quicktime_file_open(quicktime_t
*file
, char *path
, int rd
, int wr
);
20 int quicktime_file_close(quicktime_t
*file
);
21 int64_t quicktime_get_file_length(char *path
);
23 /* Initialize audio_map_t and video_map_t objects after loading headers */
24 /* Called by quicktime_read_info */
25 void quicktime_init_maps(quicktime_t
*file
);
27 int quicktime_read_char(quicktime_t
*file
);
28 float quicktime_read_fixed32(quicktime_t
*file
);
29 float quicktime_read_fixed16(quicktime_t
*file
);
30 int64_t quicktime_read_int64(quicktime_t
*file
);
31 int64_t quicktime_read_int64_le(quicktime_t
*file
);
32 unsigned long quicktime_read_uint32(quicktime_t
*file
);
33 long quicktime_read_int32(quicktime_t
*file
);
34 long quicktime_read_int32_le(quicktime_t
*file
);
35 long quicktime_read_int24(quicktime_t
*file
);
36 int64_t quicktime_position(quicktime_t
*file
);
37 int quicktime_set_position(quicktime_t
*file
, int64_t position
);
38 int quicktime_write_fixed32(quicktime_t
*file
, float number
);
39 int quicktime_write_char(quicktime_t
*file
, char x
);
40 int quicktime_write_int16(quicktime_t
*file
, int number
);
41 int quicktime_write_int16_le(quicktime_t
*file
, int number
);
42 int quicktime_write_int24(quicktime_t
*file
, long number
);
43 int quicktime_write_int32(quicktime_t
*file
, long value
);
44 int quicktime_write_int32_le(quicktime_t
*file
, long value
);
45 int quicktime_write_int64(quicktime_t
*file
, int64_t value
);
46 int quicktime_write_int64_le(quicktime_t
*file
, int64_t value
);
47 int quicktime_write_char32(quicktime_t
*file
, char *string
);
48 int quicktime_write_fixed16(quicktime_t
*file
, float number
);
50 /* Returns number of bytes written */
51 int quicktime_write_data(quicktime_t
*file
, char *data
, int size
);
52 /* Enable or disable presave */
53 void quicktime_set_presave(quicktime_t
*file
, int value
);
54 /* Returns 1 if equal or 0 if different */
55 int quicktime_match_32(char *input
, char *output
);
56 int quicktime_match_24(char *input
, char *output
);
57 void quicktime_write_pascal(quicktime_t
*file
, char *data
);
58 int quicktime_read_data(quicktime_t
*file
, char *data
, int64_t size
);
59 /* Quantize the number to the nearest multiple of 16 */
60 /* Used by ffmpeg codecs */
61 int quicktime_quantize16(int number
);
62 int quicktime_quantize32(int number
);
66 /* Convert Microsoft audio id to codec */
67 void quicktime_id_to_codec(char *result
, int id
);
69 int quicktime_find_vcodec(quicktime_video_map_t
*vtrack
);
70 int quicktime_find_acodec(quicktime_audio_map_t
*atrack
);
78 /* Most codecs don't specify the actual number of bits on disk in the stbl. */
79 /* Convert the samples to the number of bytes for reading depending on the codec. */
80 int64_t quicktime_samples_to_bytes(quicktime_trak_t
*track
, long samples
);
82 char* quicktime_compressor(quicktime_trak_t
*trak
);
84 /* Get median duration of video frames for calculating frame rate. */
85 int quicktime_sample_duration(quicktime_trak_t
*trak
);
87 /* Get alternative mpeg4 parameters from esds table */
88 void quicktime_esds_samplerate(quicktime_stsd_table_t
*table
,
89 quicktime_esds_t
*esds
);
94 quicktime_scaletable_t
* quicktime_new_scaletable(int input_w
, int input_h
, int output_w
, int output_h
);
98 /* chunks always start on 1 */
99 /* samples start on 0 */
101 /* update the position pointers in all the tracks after a set_position */
102 int quicktime_update_positions(quicktime_t
*file
);
111 void quicktime_read_strh(quicktime_t
*file
, quicktime_atom_t
*parent_atom
);
112 void quicktime_write_strh(quicktime_t
*file
, int track
);
117 /* Create new strl object for reading or writing */
118 quicktime_strl_t
* quicktime_new_strl();
119 /* Initialize new strl object for writing */
120 void quicktime_init_strl(quicktime_t
*file
,
121 quicktime_audio_map_t
*atrack
,
122 quicktime_video_map_t
*vtrack
,
123 quicktime_trak_t
*trak
,
124 quicktime_strl_t
*strl
);
125 void quicktime_delete_strl(quicktime_strl_t
*strl
);
126 /* Read strl object */
127 void quicktime_read_strl(quicktime_t
*file
,
128 quicktime_strl_t
*strl
,
129 quicktime_atom_t
*parent_atom
);
132 void quicktime_delete_indx(quicktime_indx_t
*indx
);
133 void quicktime_init_indx(quicktime_t
*file
,
134 quicktime_indx_t
*indx
,
135 quicktime_strl_t
*strl
);
136 void quicktime_update_indx(quicktime_t
*file
,
137 quicktime_indx_t
*indx
,
139 void quicktime_finalize_indx(quicktime_t
*file
);
140 /* Called by quicktime_read_strl */
141 void quicktime_read_indx(quicktime_t
*file
,
142 quicktime_strl_t
*strl
,
143 quicktime_atom_t
*parent_atom
);
147 void quicktime_delete_hdrl(quicktime_t
*file
, quicktime_hdrl_t
*hdrl
);
148 void quicktime_read_hdrl(quicktime_t
*file
,
149 quicktime_hdrl_t
*hdrl
,
150 quicktime_atom_t
*parent_atom
);
151 void quicktime_init_hdrl(quicktime_t
*file
, quicktime_hdrl_t
*hdrl
);
152 void quicktime_finalize_hdrl(quicktime_t
*file
, quicktime_hdrl_t
*hdrl
);
155 void quicktime_delete_esds(quicktime_esds_t
*esds
);
156 void quicktime_read_esds(quicktime_t
*file
,
157 quicktime_atom_t
*parent_atom
,
158 quicktime_esds_t
*esds
);
159 void quicktime_write_esds(quicktime_t
*file
,
160 quicktime_esds_t
*esds
,
163 // Set esds header to a copy of the argument
164 void quicktime_set_mpeg4_header(quicktime_stsd_table_t
*table
,
167 void quicktime_esds_dump(quicktime_esds_t
*esds
);
170 void quicktime_delete_avcc(quicktime_avcc_t
*avcc
);
171 int quicktime_read_avcc(quicktime_t
*file
,
172 quicktime_atom_t
*parent_atom
,
173 quicktime_avcc_t
*avcc
);
174 void quicktime_avcc_dump(quicktime_avcc_t
*avcc
);
175 void quicktime_set_avcc_header(quicktime_avcc_t
*avcc
,
182 /* Read movi and create objects */
183 void quicktime_delete_movi(quicktime_t
*file
, quicktime_movi_t
*movi
);
184 void quicktime_read_movi(quicktime_t
*file
,
185 quicktime_atom_t
*parent_atom
,
186 quicktime_movi_t
*movi
);
187 /* Write preliminary movi data and create objects */
188 void quicktime_init_movi(quicktime_t
*file
, quicktime_riff_t
*riff
);
189 void quicktime_finalize_movi(quicktime_t
*file
, quicktime_movi_t
*movi
);
196 void quicktime_delete_idx1(quicktime_idx1_t
*idx1
);
197 void quicktime_read_idx1(quicktime_t
*file
,
198 quicktime_riff_t
*riff
,
199 quicktime_atom_t
*parent_atom
);
200 void quicktime_write_idx1(quicktime_t
*file
,
201 quicktime_idx1_t
*idx1
);
202 /* Set the keyframe flag in the right IDX1 entry. new_keyframes starts on 0 */
203 /* Used by quicktime_insert_keyframe */
204 void quicktime_set_idx1_keyframe(quicktime_t
*file
,
205 quicktime_trak_t
*trak
,
207 /* Create new IDX1 entry. Used by quicktime_write_chunk_footer */
208 void quicktime_update_idx1table(quicktime_t
*file
,
209 quicktime_trak_t
*trak
,
216 void quicktime_read_odml(quicktime_t
*file
, quicktime_atom_t
*parent_atom
);
217 void quicktime_finalize_odml(quicktime_t
*file
, quicktime_hdrl_t
*hdrl
);
218 void quicktime_init_odml(quicktime_t
*file
, quicktime_hdrl_t
*hdrl
);
227 /* Create new riff and put on riff table */
228 quicktime_riff_t
* quicktime_new_riff(quicktime_t
*file
);
229 void quicktime_delete_riff(quicktime_t
*file
, quicktime_riff_t
*riff
);
230 void quicktime_read_riff(quicktime_t
*file
, quicktime_atom_t
*parent_atom
);
232 /* Write riff header and initialize structures */
233 /* Only the first riff has a hdrl object */
234 void quicktime_init_riff(quicktime_t
*file
);
235 void quicktime_finalize_riff(quicktime_t
*file
, quicktime_riff_t
*riff
);
238 /* Create ix object for writing only */
239 quicktime_ix_t
* quicktime_new_ix(quicktime_t
*file
,
240 quicktime_trak_t
*trak
,
241 quicktime_strl_t
*strl
);
242 void quicktime_delete_ix(quicktime_ix_t
*ix
);
243 void quicktime_update_ixtable(quicktime_t
*file
,
244 quicktime_trak_t
*trak
,
247 void quicktime_write_ix(quicktime_t
*file
,
250 /* Read entire ix atom from current position in file */
251 /* Called by quicktime_read_indx. */
252 void quicktime_read_ix(quicktime_t
*file
,
257 /* compression_id is for AVI reading */
258 int quicktime_trak_init_audio(quicktime_t
*file
,
259 quicktime_trak_t
*trak
,
264 int quicktime_trak_init_video(quicktime_t
*file
,
265 quicktime_trak_t
*trak
,
270 int quicktime_trak_delete(quicktime_trak_t
*trak
);
271 int quicktime_trak_dump(quicktime_trak_t
*trak
);
272 int quicktime_delete_trak(quicktime_moov_t
*moov
);
273 int quicktime_read_trak(quicktime_t
*file
, quicktime_trak_t
*trak
, quicktime_atom_t
*trak_atom
);
274 int quicktime_write_trak(quicktime_t
*file
, quicktime_trak_t
*trak
, long moov_time_scale
);
275 int64_t quicktime_track_end(quicktime_trak_t
*trak
);
278 /* the total number of samples in the track depending on the access mode */
279 long quicktime_track_samples(quicktime_t
*file
, quicktime_trak_t
*trak
);
282 /* queries for every atom */
283 /* the starting sample in the given chunk */
284 long quicktime_sample_of_chunk(quicktime_trak_t
*trak
, long chunk
);
287 /* the byte offset from mdat start of the chunk. Chunk is numbered from 1 */
288 int64_t quicktime_chunk_to_offset(quicktime_t
*file
, quicktime_trak_t
*trak
, long chunk
);
291 /* the chunk of any offset from mdat start */
292 long quicktime_offset_to_chunk(int64_t *chunk_offset
,
293 quicktime_trak_t
*trak
,
296 /* Bytes in the chunk. Chunk is numbered from 1 */
297 /* Only available in AVI. */
298 /* Reads the chunk header to get the size. */
299 /* Stores the chunk offset in chunk_offset. */
300 /* Returns the bytes in the chunk less the 8 byte header size */
301 int quicktime_chunk_bytes(quicktime_t
*file
,
302 int64_t *chunk_offset
,
304 quicktime_trak_t
*trak
);
307 /* total bytes between the two samples */
308 int64_t quicktime_sample_range_size(quicktime_trak_t
*trak
, long chunk_sample
, long sample
);
311 int quicktime_chunk_of_sample(int64_t *chunk_sample
,
313 quicktime_trak_t
*trak
,
318 /* converting between mdat offsets to samples */
319 int64_t quicktime_sample_to_offset(quicktime_t
*file
, quicktime_trak_t
*trak
, long sample
);
320 long quicktime_offset_to_sample(quicktime_trak_t
*trak
, int64_t offset
);
321 quicktime_trak_t
* quicktime_add_trak(quicktime_t
*file
);
324 int quicktime_time_to_sample(quicktime_stts_t
*stts
,
325 int64_t *start_time
);
326 /* Used by VBR to append a sample of known duration to the table. */
327 /* Overrides any previous fixed bitrate entry. */
328 /* Sets the is_vbr flag to prevent post processing of the table. */
329 void quicktime_stts_append_audio(quicktime_t
*file
,
330 quicktime_stts_t
*stts
,
331 int sample_duration
);
332 /* Get total stts samples for VBR encoding. */
333 int64_t quicktime_stts_total_samples(quicktime_t
*file
,
334 quicktime_stts_t
*stts
);
337 void quicktime_write_chunk_header(quicktime_t
*file
,
338 quicktime_trak_t
*trak
,
339 quicktime_atom_t
*chunk
);
340 void quicktime_write_chunk_footer(quicktime_t
*file
,
341 quicktime_trak_t
*trak
,
343 quicktime_atom_t
*chunk
,
345 /* Write VBR frame */
346 int quicktime_write_vbr_frame(quicktime_t
*file
,
351 /* update all the tables after writing a buffer */
352 /* set sample_size to 0 if no sample size should be set */
354 * int quicktime_update_tables(quicktime_t *file,
355 * quicktime_trak_t *trak,
360 * int64_t sample_size);
362 void quicktime_update_stco(quicktime_stco_t
*stco
, long chunk
, int64_t offset
);
363 void quicktime_update_stsz(quicktime_stsz_t
*stsz
, long sample
, long sample_size
);
364 int quicktime_update_stsc(quicktime_stsc_t
*stsc
, long chunk
, long samples
);
365 int quicktime_trak_duration(quicktime_trak_t
*trak
, long *duration
, long *timescale
);
366 int quicktime_trak_fix_counts(quicktime_t
*file
, quicktime_trak_t
*trak
);
367 int quicktime_sample_size(quicktime_trak_t
*trak
, int sample
);
369 /* number of samples in the chunk */
370 long quicktime_chunk_samples(quicktime_trak_t
*trak
, long chunk
);
371 int quicktime_trak_shift_offsets(quicktime_trak_t
*trak
, int64_t offset
);
372 void quicktime_mhvd_init_video(quicktime_t
*file
,
373 quicktime_mvhd_t
*mvhd
,
377 void quicktime_stsd_init_video(quicktime_t
*file
,
378 quicktime_stsd_t
*stsd
,
383 void quicktime_stsd_init_audio(quicktime_t
*file
,
384 quicktime_stsd_t
*stsd
,
389 void quicktime_stts_init_video(quicktime_t
*file
,
390 quicktime_stts_t
*stts
,
393 void quicktime_stbl_init_video(quicktime_t
*file
,
394 quicktime_stbl_t
*stbl
,
400 void quicktime_stbl_init_audio(quicktime_t
*file
,
401 quicktime_stbl_t
*stbl
,
406 void quicktime_minf_init_video(quicktime_t
*file
,
407 quicktime_minf_t
*minf
,
413 void quicktime_mdhd_init_video(quicktime_t
*file
,
414 quicktime_mdhd_t
*mdhd
,
418 void quicktime_mdhd_init_audio(quicktime_mdhd_t
*mdhd
,
420 void quicktime_minf_init_audio(quicktime_t
*file
,
421 quicktime_minf_t
*minf
,
426 void quicktime_mdia_init_video(quicktime_t
*file
,
427 quicktime_mdia_t
*mdia
,
432 void quicktime_mdia_init_audio(quicktime_t
*file
,
433 quicktime_mdia_t
*mdia
,
438 void quicktime_tkhd_init_video(quicktime_t
*file
,
439 quicktime_tkhd_t
*tkhd
,
442 int quicktime_get_timescale(double frame_rate
);
444 unsigned long quicktime_current_time(void);
455 // Utility functions for decoding vbr audio codecs
457 // Delete buffers from the vbr structure when finished
458 void quicktime_clear_vbr(quicktime_vbr_t
*ptr
);
459 void quicktime_vbr_set_channels(quicktime_vbr_t
*ptr
, int channels
);
460 void quicktime_init_vbr(quicktime_vbr_t
*ptr
, int channels
);
462 // Shift the output buffer and fix pointers for the given range.
463 // Return 1 if not possible to handle the sample count.
464 int quicktime_align_vbr(quicktime_audio_map_t
*atrack
,
467 // The current endpoint of the buffer
468 int64_t quicktime_vbr_end(quicktime_vbr_t
*ptr
);
469 unsigned char* quicktime_vbr_input(quicktime_vbr_t
*ptr
);
470 int quicktime_vbr_input_size(quicktime_vbr_t
*ptr
);
472 // Append the next sample/frame of compressed data to the input buffer
473 // and advance the counters.
474 int quicktime_read_vbr(quicktime_t
*file
,
475 quicktime_audio_map_t
*atrack
);
477 // Shift the input buffer
478 void quicktime_shift_vbr(quicktime_audio_map_t
*atrack
, int bytes
);
480 // Put the next sample/frame of uncompressed data in the buffer and advance the
482 void quicktime_store_vbr_float(quicktime_audio_map_t
*atrack
,
486 void quicktime_copy_vbr_float(quicktime_vbr_t
*vbr
,
487 int64_t start_position
,