Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / quicktime / funcprotos.h
blobfcbbb8f5547b3e7d29a5360b2b12497f6e7ee5d7
1 #ifndef FUNCPROTOS_H
2 #define FUNCPROTOS_H
4 #include "graphics.h"
5 #include "qtprivate.h"
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);
75 /* Track functions */
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);
93 /* Graphics */
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);
110 /* AVI section */
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,
138 quicktime_ix_t *ix);
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,
161 int do_video,
162 int do_audio);
163 // Set esds header to a copy of the argument
164 void quicktime_set_mpeg4_header(quicktime_stsd_table_t *table,
165 unsigned char *data,
166 int size);
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,
176 unsigned char *data,
177 int size);
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,
206 int new_keyframe);
207 /* Create new IDX1 entry. Used by quicktime_write_chunk_footer */
208 void quicktime_update_idx1table(quicktime_t *file,
209 quicktime_trak_t *trak,
210 int offset,
211 int size);
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,
245 int64_t offset,
246 int size);
247 void quicktime_write_ix(quicktime_t *file,
248 quicktime_ix_t *ix,
249 int track);
250 /* Read entire ix atom from current position in file */
251 /* Called by quicktime_read_indx. */
252 void quicktime_read_ix(quicktime_t *file,
253 quicktime_ix_t *ix);
257 /* compression_id is for AVI reading */
258 int quicktime_trak_init_audio(quicktime_t *file,
259 quicktime_trak_t *trak,
260 int channels,
261 int sample_rate,
262 int bits,
263 char *compressor);
264 int quicktime_trak_init_video(quicktime_t *file,
265 quicktime_trak_t *trak,
266 int frame_w,
267 int frame_h,
268 float frame_rate,
269 char *compressor);
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,
294 int64_t offset);
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,
303 int chunk,
304 quicktime_trak_t *trak);
307 /* total bytes between the two samples */
308 int64_t quicktime_sample_range_size(quicktime_trak_t *trak, int64_t chunk_sample, int64_t sample);
311 int quicktime_chunk_of_sample(int64_t *chunk_sample,
312 int64_t *chunk,
313 quicktime_trak_t *trak,
314 long sample);
318 /* converting between mdat offsets to samples */
319 int64_t quicktime_sample_to_offset(quicktime_t *file, quicktime_trak_t *trak, int64_t 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,
342 int current_chunk,
343 quicktime_atom_t *chunk,
344 int samples);
345 /* Write VBR frame */
346 int quicktime_write_vbr_frame(quicktime_t *file,
347 int track,
348 char *data,
349 int data_size,
350 int samples);
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,
356 * int64_t offset,
357 * int64_t chunk,
358 * int64_t sample,
359 * int64_t samples,
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,
374 double frame_rate);
377 void quicktime_stsd_init_video(quicktime_t *file,
378 quicktime_stsd_t *stsd,
379 int frame_w,
380 int frame_h,
381 float frame_rate,
382 char *compression);
383 void quicktime_stsd_init_audio(quicktime_t *file,
384 quicktime_stsd_t *stsd,
385 int channels,
386 int sample_rate,
387 int bits,
388 char *compressor);
389 void quicktime_stts_init_video(quicktime_t *file,
390 quicktime_stts_t *stts,
391 int time_scale,
392 float frame_rate);
393 void quicktime_stbl_init_video(quicktime_t *file,
394 quicktime_stbl_t *stbl,
395 int frame_w,
396 int frame_h,
397 int time_scale,
398 float frame_rate,
399 char *compressor);
400 void quicktime_stbl_init_audio(quicktime_t *file,
401 quicktime_stbl_t *stbl,
402 int channels,
403 int sample_rate,
404 int bits,
405 char *compressor);
406 void quicktime_minf_init_video(quicktime_t *file,
407 quicktime_minf_t *minf,
408 int frame_w,
409 int frame_h,
410 int time_scale,
411 float frame_rate,
412 char *compressor);
413 void quicktime_mdhd_init_video(quicktime_t *file,
414 quicktime_mdhd_t *mdhd,
415 int frame_w,
416 int frame_h,
417 float frame_rate);
418 void quicktime_mdhd_init_audio(quicktime_mdhd_t *mdhd,
419 int sample_rate);
420 void quicktime_minf_init_audio(quicktime_t *file,
421 quicktime_minf_t *minf,
422 int channels,
423 int sample_rate,
424 int bits,
425 char *compressor);
426 void quicktime_mdia_init_video(quicktime_t *file,
427 quicktime_mdia_t *mdia,
428 int frame_w,
429 int frame_h,
430 float frame_rate,
431 char *compressor);
432 void quicktime_mdia_init_audio(quicktime_t *file,
433 quicktime_mdia_t *mdia,
434 int channels,
435 int sample_rate,
436 int bits,
437 char *compressor);
438 void quicktime_tkhd_init_video(quicktime_t *file,
439 quicktime_tkhd_t *tkhd,
440 int frame_w,
441 int frame_h);
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,
465 int samples);
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
481 // counters
482 void quicktime_store_vbr_float(quicktime_audio_map_t *atrack,
483 float *samples,
484 int sample_count);
486 void quicktime_copy_vbr_float(quicktime_vbr_t *vbr,
487 int64_t start_position,
488 int samples,
489 float *output,
490 int channel);
494 // Frame caching for keyframed video.
495 quicktime_cache_t* quicktime_new_cache();
496 void quicktime_delete_cache(quicktime_cache_t *ptr);
497 void quicktime_reset_cache(quicktime_cache_t *ptr);
498 void quicktime_put_frame(quicktime_cache_t *ptr,
499 int64_t frame_number,
500 unsigned char *y,
501 unsigned char *u,
502 unsigned char *v,
503 int y_size,
504 int u_size,
505 int v_size);
506 // Return 1 if the frame was found.
507 int quicktime_get_frame(quicktime_cache_t *ptr,
508 int64_t frame_number,
509 unsigned char **y,
510 unsigned char **u,
511 unsigned char **v);
512 int quicktime_has_frame(quicktime_cache_t *ptr,
513 int64_t frame_number);
514 int64_t quicktime_cache_usage(quicktime_cache_t *ptr);
520 #endif