+static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
+ AVIContext *avi = s->priv_data;
+ ByteIOContext *pb = &s->pb;
+ int longs_pre_entry= get_le16(pb);
+ int index_sub_type = get_byte(pb);
+ int index_type = get_byte(pb);
+ int entries_in_use = get_le32(pb);
+ int chunk_id = get_le32(pb);
+ int64_t base = get_le64(pb);
+ int stream_id= 10*((chunk_id&0xFF) - '0') + (((chunk_id>>8)&0xFF) - '0');
+ AVStream *st;
+ AVIStream *ast;
+ int i;
+ int64_t last_pos= -1;
+
+// av_log(s, AV_LOG_ERROR, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%Ld\n",
+// longs_pre_entry,index_type, entries_in_use, chunk_id, base);
+
+ if(stream_id > s->nb_streams || stream_id < 0)
+ return -1;
+ st= s->streams[stream_id];
+ ast = st->priv_data;
+
+ if(index_sub_type)
+ return -1;
+
+ get_le32(pb);
+
+ if(index_type && longs_pre_entry != 2)
+ return -1;
+ if(index_type>1)
+ return -1;
+
+ for(i=0; i<entries_in_use; i++){
+ if(index_type){
+ int64_t pos= get_le32(pb) + base - 8;
+ int len = get_le32(pb);
+ int key= len >= 0;
+ len &= 0x7FFFFFFF;
+
+//av_log(s, AV_LOG_ERROR, "pos:%Ld, len:%X\n", pos, len);
+ if(last_pos == pos || pos == base - 8)
+ avi->non_interleaved= 1;
+ else
+ av_add_index_entry(st, pos, ast->cum_len, len, 0, key ? AVINDEX_KEYFRAME : 0);
+
+ if(ast->sample_size)
+ ast->cum_len += len / ast->sample_size;
+ else
+ ast->cum_len ++;
+ last_pos= pos;
+ }else{
+ int64_t offset, pos;
+ int duration;
+ offset = get_le64(pb);
+ get_le32(pb); /* size */
+ duration = get_le32(pb);
+ pos = url_ftell(pb);
+
+ url_fseek(pb, offset+8, SEEK_SET);
+ read_braindead_odml_indx(s, frame_num);
+ frame_num += duration;
+
+ url_fseek(pb, pos, SEEK_SET);
+ }
+ }
+ return 0;
+}
+
+static void clean_index(AVFormatContext *s){
+ int i, j;
+
+ for(i=0; i<s->nb_streams; i++){
+ AVStream *st = s->streams[i];
+ AVIStream *ast = st->priv_data;
+ int n= st->nb_index_entries;
+ int max= ast->sample_size;
+ int64_t pos, size, ts;
+
+ if(n != 1 || ast->sample_size==0)
+ continue;
+
+ while(max < 1024) max+=max;
+
+ pos= st->index_entries[0].pos;
+ size= st->index_entries[0].size;
+ ts= st->index_entries[0].timestamp;
+
+ for(j=0; j<size; j+=max){
+ av_add_index_entry(st, pos+j, ts + j/ast->sample_size, FFMIN(max, size-j), 0, AVINDEX_KEYFRAME);
+ }
+ }
+}
+