1 #include "funcprotos.h"
17 static int is_keyframe(quicktime_trak_t
*trak
, int frame
)
20 quicktime_stss_t
*stss
= &trak
->mdia
.minf
.stbl
.stss
;
22 for(i
= 0; i
< stss
->total_entries
; i
++)
24 if(stss
->table
[i
].sample
== frame
) return 1;
30 void quicktime_delete_idx1(quicktime_idx1_t
*idx1
)
32 if(idx1
->table
) free(idx1
->table
);
35 void quicktime_read_idx1(quicktime_t
*file
,
36 quicktime_riff_t
*riff
,
37 quicktime_atom_t
*parent_atom
)
40 quicktime_riff_t
*first_riff
= file
->riff
[0];
41 quicktime_hdrl_t
*hdrl
= &first_riff
->hdrl
;
42 quicktime_idx1_t
*idx1
= &riff
->idx1
;
44 //printf("quicktime_read_idx1 1 %llx\n", quicktime_position(file));
47 idx1
->table_size
= (parent_atom
->end
- quicktime_position(file
)) / 16;
48 idx1
->table_allocation
= idx1
->table_size
;
49 idx1
->table
= calloc(sizeof(quicktime_idx1table_t
), idx1
->table_size
);
50 //printf("quicktime_read_idx1 10\n");
52 // Store it in idx1 table now.
53 // Wait for full ix table discovery before converting to stco.
54 for(i
= 0; i
< idx1
->table_size
; i
++)
56 quicktime_idx1table_t
*idx1table
= idx1
->table
+ i
;
58 quicktime_read_data(file
, idx1table
->tag
, 4);
59 idx1table
->flags
= quicktime_read_int32_le(file
);
60 idx1table
->offset
= quicktime_read_int32_le(file
);
61 idx1table
->size
= quicktime_read_int32_le(file
);
64 //printf("quicktime_read_idx1 100\n");
74 void quicktime_write_idx1(quicktime_t
*file
,
75 quicktime_idx1_t
*idx1
)
78 quicktime_idx1table_t
*table
= idx1
->table
;
79 int table_size
= idx1
->table_size
;
84 quicktime_atom_write_header(file
, &idx1
->atom
, "idx1");
86 for(i
= 0; i
< table_size
; i
++)
88 quicktime_idx1table_t
*entry
= &table
[i
];
89 quicktime_write_char32(file
, entry
->tag
);
90 quicktime_write_int32_le(file
, entry
->flags
);
91 quicktime_write_int32_le(file
, entry
->offset
);
92 quicktime_write_int32_le(file
, entry
->size
);
96 quicktime_atom_write_footer(file
, &idx1
->atom
);
99 void quicktime_set_idx1_keyframe(quicktime_t
*file
,
100 quicktime_trak_t
*trak
,
103 quicktime_riff_t
*riff
= file
->riff
[0];
104 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
105 quicktime_strl_t
*strl
= hdrl
->strl
[trak
->tkhd
.track_id
- 1];
106 char *tag
= strl
->tag
;
107 quicktime_idx1_t
*idx1
= &riff
->idx1
;
111 // Search through entire index for right numbered tag.
112 // Since all the tracks are combined in the same index, this is unavoidable.
113 for(i
= 0; i
< idx1
->table_size
; i
++)
115 quicktime_idx1table_t
*idx1_table
= &idx1
->table
[i
];
116 if(!memcmp(idx1_table
->tag
, tag
, 4))
119 if(counter
== new_keyframe
)
121 idx1_table
->flags
|= AVI_KEYFRAME
;
128 void quicktime_update_idx1table(quicktime_t
*file
,
129 quicktime_trak_t
*trak
,
133 quicktime_riff_t
*riff
= file
->riff
[0];
134 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
135 quicktime_strl_t
*strl
= hdrl
->strl
[trak
->tkhd
.track_id
- 1];
136 char *tag
= strl
->tag
;
137 quicktime_idx1_t
*idx1
= &riff
->idx1
;
138 quicktime_movi_t
*movi
= &riff
->movi
;
139 quicktime_idx1table_t
*idx1_table
;
140 quicktime_stss_t
*stss
= &trak
->mdia
.minf
.stbl
.stss
;
143 int keyframe_frame
= idx1
->table_size
+ 1;
145 // Set flag for keyframe
146 for(i
= stss
->total_entries
- 1; i
>= 0; i
--)
148 if(stss
->table
[i
].sample
== keyframe_frame
)
150 flags
|= AVI_KEYFRAME
;
154 if(stss
->table
[i
].sample
< keyframe_frame
)
162 if(idx1
->table_size
>= idx1
->table_allocation
)
164 quicktime_idx1table_t
*old_table
= idx1
->table
;
165 int new_allocation
= idx1
->table_allocation
* 2;
166 if(new_allocation
< 1) new_allocation
= 1;
167 idx1
->table
= calloc(1, sizeof(quicktime_idx1table_t
) * new_allocation
);
170 memcpy(idx1
->table
, old_table
, sizeof(quicktime_idx1table_t
) * idx1
->table_size
);
173 idx1
->table_allocation
= new_allocation
;
178 idx1_table
= &idx1
->table
[idx1
->table_size
];
179 memcpy(idx1_table
->tag
, tag
, 4);
180 idx1_table
->flags
= flags
;
181 idx1_table
->offset
= offset
- 8 - movi
->atom
.start
;
182 idx1_table
->size
= size
;