Make FloatAutos::get_values() always use a PLAY_FORWARD direction.
[cinelerra_cv/pmdumuid.git] / quicktime / stsz.c
blobe1b3062892f37bb9cb86a88bf16352cd9a6af0d0
1 #include "funcprotos.h"
2 #include "quicktime.h"
6 void quicktime_stsz_init(quicktime_stsz_t *stsz)
8 stsz->version = 0;
9 stsz->flags = 0;
10 stsz->sample_size = 0;
11 stsz->total_entries = 0;
12 stsz->entries_allocated = 0;
13 stsz->table = 0;
16 void quicktime_stsz_init_video(quicktime_t *file, quicktime_stsz_t *stsz)
18 stsz->sample_size = 0;
19 if(!stsz->entries_allocated)
21 stsz->entries_allocated = 2048;
22 stsz->total_entries = 0;
23 stsz->table = (quicktime_stsz_table_t*)calloc(sizeof(quicktime_stsz_table_t),
24 stsz->entries_allocated);
25 //printf("quicktime_stsz_init_video 1 %p\n", stsz->table);
29 void quicktime_stsz_init_audio(quicktime_t *file,
30 quicktime_stsz_t *stsz,
31 int channels,
32 int bits,
33 char *compressor)
35 /*stsz->sample_size = channels * bits / 8; */
37 stsz->table = 0;
38 stsz->sample_size = 0;
40 //printf("quicktime_stsz_init_audio 1 %d\n", stsz->sample_size);
41 stsz->total_entries = 0; /* set this when closing */
42 stsz->entries_allocated = 0;
45 void quicktime_stsz_delete(quicktime_stsz_t *stsz)
47 if(!stsz->sample_size && stsz->total_entries) free(stsz->table);
48 stsz->table = 0;
49 stsz->total_entries = 0;
50 stsz->entries_allocated = 0;
53 void quicktime_stsz_dump(quicktime_stsz_t *stsz)
55 int i;
56 printf(" sample size\n");
57 printf(" version %d\n", stsz->version);
58 printf(" flags %d\n", stsz->flags);
59 printf(" sample_size %d\n", stsz->sample_size);
60 printf(" total_entries %d\n", stsz->total_entries);
62 if(!stsz->sample_size)
64 for(i = 0; i < stsz->total_entries; i++)
66 printf(" sample_size %x\n", stsz->table[i].size);
71 void quicktime_read_stsz(quicktime_t *file, quicktime_stsz_t *stsz)
73 int i;
74 stsz->version = quicktime_read_char(file);
75 stsz->flags = quicktime_read_int24(file);
76 stsz->sample_size = quicktime_read_int32(file);
77 stsz->total_entries = quicktime_read_int32(file);
78 stsz->entries_allocated = stsz->total_entries;
79 //printf("quicktime_read_stsz 1 %d\n", stsz->sample_size);
80 if(!stsz->sample_size)
82 stsz->table = (quicktime_stsz_table_t*)malloc(sizeof(quicktime_stsz_table_t) * stsz->entries_allocated);
83 for(i = 0; i < stsz->total_entries; i++)
85 stsz->table[i].size = quicktime_read_int32(file);
90 void quicktime_write_stsz(quicktime_t *file, quicktime_stsz_t *stsz)
92 int i, result;
93 quicktime_atom_t atom;
94 quicktime_atom_write_header(file, &atom, "stsz");
96 /* optimize if possible */
97 /* Xanim requires an unoptimized table for video. */
98 /* if(!stsz->sample_size) */
99 /* { */
100 /* for(i = 0, result = 0; i < stsz->total_entries && !result; i++) */
101 /* { */
102 /* if(stsz->table[i].size != stsz->table[0].size) result = 1; */
103 /* } */
104 /* */
105 /* if(!result) */
106 /* { */
107 /* stsz->sample_size = stsz->table[0].size; */
108 /* stsz->total_entries = 0; */
109 /* free(stsz->table); */
110 /* } */
111 /* } */
113 quicktime_write_char(file, stsz->version);
114 quicktime_write_int24(file, stsz->flags);
116 // Force idiosynchratic handling of fixed bitrate audio.
117 // Since audio has millions of samples it's not practical to declare a size
118 // of each sample. Instead Quicktime stores a 1 for every sample's size and
119 // relies on the samples per chunk table to determine the chunk size.
120 quicktime_write_int32(file, stsz->sample_size);
121 quicktime_write_int32(file, stsz->total_entries);
123 if(!stsz->sample_size)
125 for(i = 0; i < stsz->total_entries; i++)
127 quicktime_write_int32(file, stsz->table[i].size);
131 quicktime_atom_write_footer(file, &atom);
134 // Sample starts on 0
135 void quicktime_update_stsz(quicktime_stsz_t *stsz,
136 long sample,
137 long sample_size)
139 int i;
141 if(!stsz->sample_size)
143 if(sample >= stsz->entries_allocated)
145 stsz->entries_allocated = sample * 2;
146 //printf("quicktime_update_stsz 1 %d %d\n", sample, sample_size);
147 stsz->table = (quicktime_stsz_table_t *)realloc(stsz->table,
148 sizeof(quicktime_stsz_table_t) * stsz->entries_allocated);
149 //printf("quicktime_update_stsz 2 %d %d\n", sample, sample_size);
152 stsz->table[sample].size = sample_size;
153 if(sample >= stsz->total_entries) stsz->total_entries = sample + 1;
156 //printf("quicktime_update_stsz 5 %d %d\n", sample, sample_size);
160 int quicktime_sample_size(quicktime_trak_t *trak, int sample)
162 quicktime_stsz_t *stsz = &trak->mdia.minf.stbl.stsz;
163 if(stsz->sample_size) return stsz->sample_size;
164 if(sample < stsz->total_entries && sample >= 0)
165 return stsz->table[sample].size;
166 return 0;