1 #include "funcprotos.h"
6 static char* make_tag(int number
, char *tag
)
10 tag
[2] = '0' + (number
/ 10);
11 tag
[3] = '0' + (number
% 10);
15 quicktime_ix_t
* quicktime_new_ix(quicktime_t
*file
,
16 quicktime_trak_t
*trak
,
17 quicktime_strl_t
*strl
)
19 quicktime_ix_t
*ix
= calloc(1, sizeof(quicktime_ix_t
));
20 ix
->base_offset
= quicktime_position(file
);
21 make_tag(trak
->tkhd
.track_id
- 1, ix
->tag
);
22 ix
->longs_per_entry
= 2;
23 ix
->index_type
= AVI_INDEX_OF_CHUNKS
;
24 memcpy(ix
->chunk_id
, strl
->tag
, 4);
29 void quicktime_delete_ix(quicktime_ix_t
*ix
)
31 if(ix
->table
) free(ix
->table
);
35 void quicktime_update_ixtable(quicktime_t
*file
,
36 quicktime_trak_t
*trak
,
40 quicktime_riff_t
*riff
= file
->riff
[file
->total_riffs
- 1];
41 quicktime_movi_t
*movi
= &riff
->movi
;
42 quicktime_ix_t
*ix
= movi
->ix
[trak
->tkhd
.track_id
- 1];
43 quicktime_ixtable_t
*ix_table
;
46 if(ix
->table_size
>= ix
->table_allocation
)
48 quicktime_ixtable_t
*old_table
= ix
->table
;
49 int new_allocation
= ix
->table_allocation
* 2;
50 if(new_allocation
< 1) new_allocation
= 1;
51 ix
->table
= calloc(1, sizeof(quicktime_ixtable_t
) * new_allocation
);
54 memcpy(ix
->table
, old_table
, sizeof(quicktime_ixtable_t
) * ix
->table_size
);
57 ix
->table_allocation
= new_allocation
;
61 ix_table
= &ix
->table
[ix
->table_size
++];
62 ix_table
->relative_offset
= offset
- ix
->base_offset
;
63 ix_table
->size
= size
;
67 void quicktime_write_ix(quicktime_t
*file
,
72 quicktime_atom_write_header(file
, &ix
->atom
, ix
->tag
);
75 quicktime_write_int16_le(file
, ix
->longs_per_entry
);
77 quicktime_write_char(file
, 0);
79 quicktime_write_char(file
, ix
->index_type
);
81 quicktime_write_int32_le(file
, ix
->table_size
);
83 quicktime_write_char32(file
, ix
->chunk_id
);
85 quicktime_write_int64_le(file
, ix
->base_offset
);
87 quicktime_write_int32_le(file
, 0);
90 for(i
= 0; i
< ix
->table_size
; i
++)
92 quicktime_ixtable_t
*table
= &ix
->table
[i
];
93 quicktime_write_int32_le(file
, table
->relative_offset
);
94 quicktime_write_int32_le(file
, table
->size
);
97 quicktime_atom_write_footer(file
, &ix
->atom
);
100 /* Update super index */
101 quicktime_riff_t
*riff
= file
->riff
[0];
102 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
103 quicktime_strl_t
*strl
= hdrl
->strl
[track
];
104 quicktime_indx_t
*indx
= &strl
->indx
;
106 quicktime_update_indx(file
, indx
, ix
);
109 void quicktime_read_ix(quicktime_t
*file
,
113 quicktime_atom_t leaf_atom
;
114 quicktime_atom_read_header(file
, &leaf_atom
);
116 ix
->longs_per_entry
= quicktime_read_int16_le(file
);
118 quicktime_read_char(file
);
119 ix
->index_type
= quicktime_read_char(file
);
120 ix
->table_size
= quicktime_read_int32_le(file
);
121 quicktime_read_char32(file
, ix
->chunk_id
);
122 ix
->base_offset
= quicktime_read_int64_le(file
);
124 quicktime_read_int32_le(file
);
126 ix
->table
= calloc(ix
->table_size
, sizeof(quicktime_ixtable_t
));
128 for(i
= 0; i
< ix
->table_size
; i
++)
130 quicktime_ixtable_t
*ixtable
= &ix
->table
[i
];
131 ixtable
->relative_offset
= quicktime_read_int32_le(file
);
132 ixtable
->size
= quicktime_read_int32_le(file
);