1 #include "funcprotos.h"
6 void quicktime_delete_indx(quicktime_indx_t
*indx
)
11 for(i
= 0; i
< indx
->table_size
; i
++)
13 quicktime_indxtable_t
*indx_table
= &indx
->table
[i
];
14 if(indx_table
->ix
) quicktime_delete_ix(indx_table
->ix
);
20 void quicktime_init_indx(quicktime_t
*file
,
21 quicktime_indx_t
*indx
,
22 quicktime_strl_t
*strl
)
24 indx
->longs_per_entry
= 4;
25 indx
->index_subtype
= 0;
26 indx
->index_type
= AVI_INDEX_OF_INDEXES
;
27 memcpy(indx
->chunk_id
, strl
->tag
, 4);
30 void quicktime_update_indx(quicktime_t
*file
,
31 quicktime_indx_t
*indx
,
34 quicktime_indxtable_t
*indx_table
;
37 if(indx
->table_size
>= indx
->table_allocation
)
39 quicktime_indxtable_t
*old_table
= indx
->table
;
40 int new_allocation
= indx
->table_allocation
* 2;
41 if(new_allocation
< 1) new_allocation
= 1;
42 indx
->table
= calloc(1, sizeof(quicktime_indxtable_t
) * new_allocation
);
45 memcpy(indx
->table
, old_table
, sizeof(quicktime_indxtable_t
) * indx
->table_size
);
48 indx
->table_allocation
= new_allocation
;
52 indx_table
= &indx
->table
[indx
->table_size
++];
53 indx_table
->index_offset
= ix
->atom
.start
- 8;
54 indx_table
->index_size
= ix
->atom
.size
;
55 indx_table
->duration
= ix
->table_size
;
60 void quicktime_finalize_indx(quicktime_t
*file
)
63 quicktime_riff_t
*riff
= file
->riff
[0];
64 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
65 quicktime_strl_t
*strl
;
66 quicktime_indx_t
*indx
;
67 quicktime_atom_t junk_atom
;
71 for(i
= 0; i
< file
->moov
.total_tracks
; i
++)
77 quicktime_set_position(file
, strl
->indx_offset
);
78 quicktime_atom_write_header(file
, &indx
->atom
, "indx");
80 quicktime_write_int16_le(file
, indx
->longs_per_entry
);
82 quicktime_write_char(file
, indx
->index_subtype
);
84 quicktime_write_char(file
, indx
->index_type
);
86 quicktime_write_int32_le(file
, indx
->table_size
);
88 quicktime_write_char32(file
, indx
->chunk_id
);
90 quicktime_write_int32_le(file
, 0);
91 quicktime_write_int32_le(file
, 0);
92 quicktime_write_int32_le(file
, 0);
95 for(j
= 0; j
< indx
->table_size
; j
++)
97 quicktime_indxtable_t
*indx_table
= &indx
->table
[j
];
98 quicktime_write_int64_le(file
, indx_table
->index_offset
);
99 quicktime_write_int32_le(file
, indx_table
->index_size
);
100 quicktime_write_int32_le(file
, indx_table
->duration
);
103 quicktime_atom_write_footer(file
, &indx
->atom
);
107 /* Rewrite JUNK less indx size and indx header size */
108 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
);
145 //printf("quicktime_read_indx 1\n");
146 /* Read indx entries */
147 indx
->table
= calloc(indx
->table_size
, sizeof(quicktime_indxtable_t
));
148 for(i
= 0; i
< indx
->table_size
; i
++)
150 indx_table
= &indx
->table
[i
];
151 indx_table
->index_offset
= quicktime_read_int64_le(file
);
152 indx_table
->index_size
= quicktime_read_int32_le(file
);
153 indx_table
->duration
= quicktime_read_int32_le(file
);
154 offset
= quicktime_position(file
);
156 indx_table
->ix
= calloc(indx
->table_size
, sizeof(quicktime_ix_t
*));
158 /* Now read the partial index */
159 ix
= indx_table
->ix
= calloc(1, sizeof(quicktime_ix_t
));
160 quicktime_set_position(file
, indx_table
->index_offset
);
161 quicktime_read_ix(file
, ix
);
162 quicktime_set_position(file
, offset
);
164 //printf("quicktime_read_indx 100\n");