1 #include "funcprotos.h"
5 static char* make_tag(int number
, char *tag
)
9 tag
[2] = '0' + (number
/ 10);
10 tag
[3] = '0' + (number
% 10);
14 quicktime_ix_t
* quicktime_new_ix(quicktime_t
*file
,
15 quicktime_trak_t
*trak
,
16 quicktime_strl_t
*strl
)
18 quicktime_ix_t
*ix
= calloc(1, sizeof(quicktime_ix_t
));
19 ix
->base_offset
= quicktime_position(file
);
20 make_tag(trak
->tkhd
.track_id
- 1, ix
->tag
);
21 ix
->longs_per_entry
= 2;
22 ix
->index_type
= AVI_INDEX_OF_CHUNKS
;
23 memcpy(ix
->chunk_id
, strl
->tag
, 4);
28 void quicktime_delete_ix(quicktime_ix_t
*ix
)
30 if(ix
->table
) free(ix
->table
);
34 void quicktime_update_ixtable(quicktime_t
*file
,
35 quicktime_trak_t
*trak
,
39 quicktime_riff_t
*riff
= file
->riff
[file
->total_riffs
- 1];
40 quicktime_movi_t
*movi
= &riff
->movi
;
41 quicktime_ix_t
*ix
= movi
->ix
[trak
->tkhd
.track_id
- 1];
42 quicktime_ixtable_t
*ix_table
;
45 if(ix
->table_size
>= ix
->table_allocation
)
47 quicktime_ixtable_t
*old_table
= ix
->table
;
48 int new_allocation
= ix
->table_allocation
* 2;
49 if(new_allocation
< 1) new_allocation
= 1;
50 ix
->table
= calloc(1, sizeof(quicktime_ixtable_t
) * new_allocation
);
53 memcpy(ix
->table
, old_table
, sizeof(quicktime_ixtable_t
) * ix
->table_size
);
56 ix
->table_allocation
= new_allocation
;
60 ix_table
= &ix
->table
[ix
->table_size
++];
61 ix_table
->relative_offset
= offset
- ix
->base_offset
;
62 ix_table
->size
= size
;
66 void quicktime_write_ix(quicktime_t
*file
,
71 quicktime_atom_write_header(file
, &ix
->atom
, ix
->tag
);
74 quicktime_write_int16_le(file
, ix
->longs_per_entry
);
76 quicktime_write_char(file
, 0);
78 quicktime_write_char(file
, ix
->index_type
);
80 quicktime_write_int32_le(file
, ix
->table_size
);
82 quicktime_write_char32(file
, ix
->chunk_id
);
84 quicktime_write_int64_le(file
, ix
->base_offset
);
86 quicktime_write_int32_le(file
, 0);
89 for(i
= 0; i
< ix
->table_size
; i
++)
91 quicktime_ixtable_t
*table
= &ix
->table
[i
];
92 quicktime_write_int32_le(file
, table
->relative_offset
);
93 quicktime_write_int32_le(file
, table
->size
);
96 quicktime_atom_write_footer(file
, &ix
->atom
);
99 /* Update super index */
100 quicktime_riff_t
*riff
= file
->riff
[0];
101 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
102 quicktime_strl_t
*strl
= hdrl
->strl
[track
];
103 quicktime_indx_t
*indx
= &strl
->indx
;
105 quicktime_update_indx(file
, indx
, ix
);
108 void quicktime_read_ix(quicktime_t
*file
,
112 quicktime_atom_t leaf_atom
;
113 quicktime_atom_read_header(file
, &leaf_atom
);
115 ix
->longs_per_entry
= quicktime_read_int16_le(file
);
117 quicktime_read_char(file
);
118 ix
->index_type
= quicktime_read_char(file
);
119 ix
->table_size
= quicktime_read_int32_le(file
);
120 quicktime_read_char32(file
, ix
->chunk_id
);
121 ix
->base_offset
= quicktime_read_int64_le(file
);
123 quicktime_read_int32_le(file
);
125 ix
->table
= calloc(ix
->table_size
, sizeof(quicktime_ixtable_t
));
127 for(i
= 0; i
< ix
->table_size
; i
++)
129 quicktime_ixtable_t
*ixtable
= &ix
->table
[i
];
130 ixtable
->relative_offset
= quicktime_read_int32_le(file
);
131 ixtable
->size
= quicktime_read_int32_le(file
);