- current_offset = LE_32(&vmd->vmd_header[20]);
- current_frame_record = raw_frame_table;
- total_frames = vmd->frame_count;
- i = 0;
- while (total_frames--) {
-
- /* if the frame size is 0, do not count the frame and bring the
- * total frame count down */
- // note, we limit the size to 1Gb to ensure that we dont end up overflowing the size integer used to allocate the memory
- vmd->frame_table[i].frame_size = LE_32(¤t_frame_record[2]) & 0x3FFFFFFF;
-
- /* this logic is present so that 0-length audio chunks are not
- * accounted */
- if (!vmd->frame_table[i].frame_size) {
- vmd->frame_count--; /* one less frame to count */
- current_frame_record += BYTES_PER_FRAME_RECORD;
- continue;
+ total_frames = 0;
+ for (i = 0; i < vmd->frame_count; i++) {
+
+ current_offset = AV_RL32(&raw_frame_table[6 * i + 2]);
+
+ /* handle each entry in index block */
+ for (j = 0; j < vmd->frames_per_block; j++) {
+ int type;
+ uint32_t size;
+
+ get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD);
+ type = chunk[0];
+ size = AV_RL32(&chunk[2]);
+ if(!size)
+ continue;
+ switch(type) {
+ case 1: /* Audio Chunk */
+ if (!st) break;
+ /* first audio chunk contains several audio buffers */
+ if(current_audio_pts){
+ vmd->frame_table[total_frames].frame_offset = current_offset;
+ vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index;
+ vmd->frame_table[total_frames].frame_size = size;
+ memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
+ vmd->frame_table[total_frames].pts = current_audio_pts;
+ total_frames++;
+ current_audio_pts += pts_inc;
+ }else{
+ uint32_t flags;
+ int k;
+ int noff;
+ int64_t pos;
+
+ pos = url_ftell(pb);
+ url_fseek(pb, current_offset, SEEK_SET);
+ flags = get_le32(pb);
+ noff = 4;
+ url_fseek(pb, pos, SEEK_SET);
+ av_log(s, AV_LOG_DEBUG, "Sound mapping = %08X (%i bufs)\n", flags, sound_buffers);
+ for(k = 0; k < sound_buffers - 1; k++){
+ if(flags & 1) { /* silent block */
+ vmd->frame_table[total_frames].frame_size = 0;
+ }else{
+ vmd->frame_table[total_frames].frame_size = st->codec->block_align + (st->codec->block_align & 1);
+ }
+ noff += vmd->frame_table[total_frames].frame_size;
+ vmd->frame_table[total_frames].frame_offset = current_offset + noff;
+ vmd->frame_table[total_frames].stream_index = vmd->audio_stream_index;
+ memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
+ vmd->frame_table[total_frames].pts = current_audio_pts;
+ total_frames++;
+ current_audio_pts += pts_inc;
+ flags >>= 1;
+ }
+ }
+ break;
+ case 2: /* Video Chunk */
+ vmd->frame_table[total_frames].frame_offset = current_offset;
+ vmd->frame_table[total_frames].stream_index = vmd->video_stream_index;
+ vmd->frame_table[total_frames].frame_size = size;
+ memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
+ vmd->frame_table[total_frames].pts = current_video_pts;
+ total_frames++;
+ break;
+ }
+ current_offset += size;