r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / quicktime / avi_indx.c
blobfbff9ef5a4f054c966dbcba8c6e583ee974f0d0d
1 #include "funcprotos.h"
2 #include "quicktime.h"
5 void quicktime_delete_indx(quicktime_indx_t *indx)
7 int i;
8 if(indx->table)
10 for(i = 0; i < indx->table_size; i++)
12 quicktime_indxtable_t *indx_table = &indx->table[i];
13 if(indx_table->ix) quicktime_delete_ix(indx_table->ix);
15 free(indx->table);
19 void quicktime_init_indx(quicktime_t *file,
20 quicktime_indx_t *indx,
21 quicktime_strl_t *strl)
23 indx->longs_per_entry = 4;
24 indx->index_subtype = 0;
25 indx->index_type = AVI_INDEX_OF_INDEXES;
26 memcpy(indx->chunk_id, strl->tag, 4);
29 void quicktime_update_indx(quicktime_t *file,
30 quicktime_indx_t *indx,
31 quicktime_ix_t *ix)
33 quicktime_indxtable_t *indx_table;
35 /* Allocate */
36 if(indx->table_size >= indx->table_allocation)
38 quicktime_indxtable_t *old_table = indx->table;
39 int new_allocation = indx->table_allocation * 2;
40 if(new_allocation < 1) new_allocation = 1;
41 indx->table = calloc(1, sizeof(quicktime_indxtable_t) * new_allocation);
42 if(old_table)
44 memcpy(indx->table, old_table, sizeof(quicktime_indxtable_t) * indx->table_size);
45 free(old_table);
47 indx->table_allocation = new_allocation;
50 /* Append */
51 indx_table = &indx->table[indx->table_size++];
52 indx_table->index_offset = ix->atom.start - 8;
53 indx_table->index_size = ix->atom.size;
54 indx_table->duration = ix->table_size;
59 void quicktime_finalize_indx(quicktime_t *file)
61 int i, j;
62 quicktime_riff_t *riff = file->riff[0];
63 quicktime_hdrl_t *hdrl = &riff->hdrl;
64 quicktime_strl_t *strl;
65 quicktime_indx_t *indx;
66 quicktime_atom_t junk_atom;
67 int junk_size;
70 for(i = 0; i < file->moov.total_tracks; i++)
72 strl = hdrl->strl[i];
73 indx = &strl->indx;
75 /* Write indx */
76 quicktime_set_position(file, strl->indx_offset);
77 quicktime_atom_write_header(file, &indx->atom, "indx");
78 /* longs per entry */
79 quicktime_write_int16_le(file, indx->longs_per_entry);
80 /* index sub type */
81 quicktime_write_char(file, indx->index_subtype);
82 /* index type */
83 quicktime_write_char(file, indx->index_type);
84 /* entries in use */
85 quicktime_write_int32_le(file, indx->table_size);
86 /* chunk ID */
87 quicktime_write_char32(file, indx->chunk_id);
88 /* reserved */
89 quicktime_write_int32_le(file, 0);
90 quicktime_write_int32_le(file, 0);
91 quicktime_write_int32_le(file, 0);
93 /* table */
94 for(j = 0; j < indx->table_size; j++)
96 quicktime_indxtable_t *indx_table = &indx->table[j];
97 quicktime_write_int64_le(file, indx_table->index_offset);
98 quicktime_write_int32_le(file, indx_table->index_size);
99 quicktime_write_int32_le(file, indx_table->duration);
102 quicktime_atom_write_footer(file, &indx->atom);
106 /* Rewrite JUNK less indx size and indx header size */
107 junk_size = strl->padding_size - indx->atom.size - 8;
109 * quicktime_atom_write_header(file, &junk_atom, "JUNK");
110 * for(j = 0; j < junk_size; j += 4)
111 * quicktime_write_int32_le(file, 0);
112 * quicktime_atom_write_footer(file, &junk_atom);
125 void quicktime_read_indx(quicktime_t *file,
126 quicktime_strl_t *strl,
127 quicktime_atom_t *parent_atom)
129 quicktime_indx_t *indx = &strl->indx;
130 quicktime_indxtable_t *indx_table;
131 quicktime_ix_t *ix;
132 int i;
133 int64_t offset;
135 indx->longs_per_entry = quicktime_read_int16_le(file);
136 indx->index_subtype = quicktime_read_char(file);
137 indx->index_type = quicktime_read_char(file);
138 indx->table_size = quicktime_read_int32_le(file);
139 quicktime_read_char32(file, indx->chunk_id);
140 quicktime_read_int32_le(file);
141 quicktime_read_int32_le(file);
142 quicktime_read_int32_le(file);
144 //printf("quicktime_read_indx 1\n");
145 /* Read indx entries */
146 indx->table = calloc(indx->table_size, sizeof(quicktime_indxtable_t));
147 for(i = 0; i < indx->table_size; i++)
149 indx_table = &indx->table[i];
150 indx_table->index_offset = quicktime_read_int64_le(file);
151 indx_table->index_size = quicktime_read_int32_le(file);
152 indx_table->duration = quicktime_read_int32_le(file);
153 offset = quicktime_position(file);
155 indx_table->ix = calloc(indx->table_size, sizeof(quicktime_ix_t*));
157 /* Now read the partial index */
158 ix = indx_table->ix = calloc(1, sizeof(quicktime_ix_t));
159 quicktime_set_position(file, indx_table->index_offset);
160 quicktime_read_ix(file, ix);
161 quicktime_set_position(file, offset);
163 //printf("quicktime_read_indx 100\n");