1 #include "funcprotos.h"
16 static int is_keyframe(quicktime_trak_t
*trak
, int frame
)
19 quicktime_stss_t
*stss
= &trak
->mdia
.minf
.stbl
.stss
;
21 for(i
= 0; i
< stss
->total_entries
; i
++)
23 if(stss
->table
[i
].sample
== frame
) return 1;
29 void quicktime_delete_idx1(quicktime_idx1_t
*idx1
)
31 if(idx1
->table
) free(idx1
->table
);
34 void quicktime_read_idx1(quicktime_t
*file
,
35 quicktime_riff_t
*riff
,
36 quicktime_atom_t
*parent_atom
)
39 quicktime_riff_t
*first_riff
= file
->riff
[0];
40 quicktime_hdrl_t
*hdrl
= &first_riff
->hdrl
;
41 quicktime_idx1_t
*idx1
= &riff
->idx1
;
43 //printf("quicktime_read_idx1 1 %llx\n", quicktime_position(file));
46 idx1
->table_size
= (parent_atom
->end
- quicktime_position(file
)) / 16;
47 idx1
->table_allocation
= idx1
->table_size
;
48 idx1
->table
= calloc(sizeof(quicktime_idx1table_t
), idx1
->table_size
);
49 //printf("quicktime_read_idx1 10\n");
51 // Store it in idx1 table now.
52 // Wait for full ix table discovery before converting to stco.
53 for(i
= 0; i
< idx1
->table_size
; i
++)
55 quicktime_idx1table_t
*idx1table
= idx1
->table
+ i
;
57 quicktime_read_data(file
, idx1table
->tag
, 4);
58 idx1table
->flags
= quicktime_read_int32_le(file
);
59 idx1table
->offset
= quicktime_read_int32_le(file
);
60 idx1table
->size
= quicktime_read_int32_le(file
);
63 //printf("quicktime_read_idx1 100\n");
69 while(quicktime_position(file
) <= parent_atom
->end
- 0x10)
71 int current_vtrack
= 0;
72 int current_atrack
= 0;
73 quicktime_read_data(file
, data
, 4);
75 for(i
= 0; i
< file
->moov
.total_tracks
; i
++)
77 if(quicktime_match_24(data
, tags
[i
]))
80 int flags
= quicktime_read_int32_le(file
);
81 int64_t offset
= quicktime_read_int32_le(file
);
83 // Offset from start of movi
84 quicktime_update_stco(&file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stco
,
85 file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stco
.total_entries
+ 1,
88 if(file
->moov
.trak
[i
]->mdia
.minf
.is_audio
)
93 chunk_size
= quicktime_read_int32_le(file
);
96 // Update samples per chunk table if PCM
97 if(file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stsd
.table
[0].packet_size
> 0)
99 quicktime_update_stsc(&file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stsc
,
100 file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stsc
.total_entries
+ 1,
102 file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stsd
.table
[0].packet_size
);
110 sample_size
= quicktime_read_int32_le(file
);
112 //printf("quicktime_read_idx1 5 %d %d\n", file->moov.trak[i]->mdia.minf.stbl.stsz.total_entries, current_vtrack);
114 // Update keyframe table
115 if((flags
& AVI_KEYFRAME
) == AVI_KEYFRAME
)
116 quicktime_insert_keyframe(file
,
117 file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stsz
.total_entries
,
119 //printf("quicktime_read_idx1 6\n");
121 // Update samplesize table
122 quicktime_update_stsz(&file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stsz
,
123 file
->moov
.trak
[i
]->mdia
.minf
.stbl
.stsz
.total_entries
,
125 //printf("quicktime_read_idx1 7\n");
129 if(file
->moov
.trak
[i
]->mdia
.minf
.is_audio
)
136 quicktime_atom_skip(file
, parent_atom
);
143 void quicktime_write_idx1(quicktime_t
*file
,
144 quicktime_idx1_t
*idx1
)
147 quicktime_idx1table_t
*table
= idx1
->table
;
148 int table_size
= idx1
->table_size
;
153 quicktime_atom_write_header(file
, &idx1
->atom
, "idx1");
155 for(i
= 0; i
< table_size
; i
++)
157 quicktime_idx1table_t
*entry
= &table
[i
];
158 quicktime_write_char32(file
, entry
->tag
);
159 quicktime_write_int32_le(file
, entry
->flags
);
160 quicktime_write_int32_le(file
, entry
->offset
);
161 quicktime_write_int32_le(file
, entry
->size
);
165 quicktime_atom_write_footer(file
, &idx1
->atom
);
168 void quicktime_set_idx1_keyframe(quicktime_t
*file
,
169 quicktime_trak_t
*trak
,
172 quicktime_riff_t
*riff
= file
->riff
[0];
173 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
174 quicktime_strl_t
*strl
= hdrl
->strl
[trak
->tkhd
.track_id
- 1];
175 char *tag
= strl
->tag
;
176 quicktime_idx1_t
*idx1
= &riff
->idx1
;
180 // Search through entire index for right numbered tag.
181 // Since all the tracks are combined in the same index, this is unavoidable.
182 for(i
= 0; i
< idx1
->table_size
; i
++)
184 quicktime_idx1table_t
*idx1_table
= &idx1
->table
[i
];
185 if(!memcmp(idx1_table
->tag
, tag
, 4))
188 if(counter
== new_keyframe
)
190 idx1_table
->flags
|= AVI_KEYFRAME
;
197 void quicktime_update_idx1table(quicktime_t
*file
,
198 quicktime_trak_t
*trak
,
202 quicktime_riff_t
*riff
= file
->riff
[0];
203 quicktime_hdrl_t
*hdrl
= &riff
->hdrl
;
204 quicktime_strl_t
*strl
= hdrl
->strl
[trak
->tkhd
.track_id
- 1];
205 char *tag
= strl
->tag
;
206 quicktime_idx1_t
*idx1
= &riff
->idx1
;
207 quicktime_movi_t
*movi
= &riff
->movi
;
208 quicktime_idx1table_t
*idx1_table
;
209 quicktime_stss_t
*stss
= &trak
->mdia
.minf
.stbl
.stss
;
212 int keyframe_frame
= idx1
->table_size
+ 1;
214 // Set flag for keyframe
215 for(i
= stss
->total_entries
- 1; i
>= 0; i
--)
217 if(stss
->table
[i
].sample
== keyframe_frame
)
219 flags
|= AVI_KEYFRAME
;
223 if(stss
->table
[i
].sample
< keyframe_frame
)
231 if(idx1
->table_size
>= idx1
->table_allocation
)
233 quicktime_idx1table_t
*old_table
= idx1
->table
;
234 int new_allocation
= idx1
->table_allocation
* 2;
235 if(new_allocation
< 1) new_allocation
= 1;
236 idx1
->table
= calloc(1, sizeof(quicktime_idx1table_t
) * new_allocation
);
239 memcpy(idx1
->table
, old_table
, sizeof(quicktime_idx1table_t
) * idx1
->table_size
);
242 idx1
->table_allocation
= new_allocation
;
247 idx1_table
= &idx1
->table
[idx1
->table_size
];
248 memcpy(idx1_table
->tag
, tag
, 4);
249 idx1_table
->flags
= flags
;
250 idx1_table
->offset
= offset
- 8 - movi
->atom
.start
;
251 idx1_table
->size
= size
;