1 #include "funcprotos.h"
5 void quicktime_delete_indx(quicktime_indx_t
*indx
)
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
);
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
,
33 quicktime_indxtable_t
*indx_table
;
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
);
44 memcpy(indx
->table
, old_table
, sizeof(quicktime_indxtable_t
) * indx
->table_size
);
47 indx
->table_allocation
= new_allocation
;
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
)
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
;
70 for(i
= 0; i
< file
->moov
.total_tracks
; i
++)
76 quicktime_set_position(file
, strl
->indx_offset
);
77 quicktime_atom_write_header(file
, &indx
->atom
, "indx");
79 quicktime_write_int16_le(file
, indx
->longs_per_entry
);
81 quicktime_write_char(file
, indx
->index_subtype
);
83 quicktime_write_char(file
, indx
->index_type
);
85 quicktime_write_int32_le(file
, indx
->table_size
);
87 quicktime_write_char32(file
, indx
->chunk_id
);
89 quicktime_write_int32_le(file
, 0);
90 quicktime_write_int32_le(file
, 0);
91 quicktime_write_int32_le(file
, 0);
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
;
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");