- 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;
- }
-
- if (current_frame_record[0] == 0x02)
- vmd->frame_table[i].stream_index = vmd->video_stream_index;
- else
- vmd->frame_table[i].stream_index = vmd->audio_stream_index;
- vmd->frame_table[i].frame_offset = current_offset;
- current_offset += vmd->frame_table[i].frame_size;
- memcpy(vmd->frame_table[i].frame_record, current_frame_record,
- BYTES_PER_FRAME_RECORD);
-
- /* figure out the pts for this frame */
- if (current_frame_record[0] == 0x02) {
- vmd->frame_table[i].pts = current_video_pts;
- current_video_pts += video_pts_inc;
- } else if (current_frame_record[0] == 0x01) {
- /* figure out the pts during the dispatch phase */
- vmd->frame_table[i].pts = 0;
+ total_frames = 0;
+ for (i = 0; i < vmd->frame_count; i++) {
+
+ current_offset = LE_32(&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 = LE_32(&chunk[2]);
+ if(!size)
+ continue;
+ switch(type) {
+ case 1: /* Audio Chunk */
+ 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);
+ total_frames++;
+ break;
+ case 2: /* Video Chunk */
+ vmd->frame_table[total_frames].frame_offset = current_offset;
+ vmd->frame_table[total_frames].frame_size = size;
+ vmd->frame_table[total_frames].stream_index = vmd->video_stream_index;
+ memcpy(vmd->frame_table[total_frames].frame_record, chunk, BYTES_PER_FRAME_RECORD);
+ vmd->frame_table[total_frames].pts = current_video_pts;
+ if (lastframe) {
+ vmd->frame_table[lastframe].pts = current_video_pts - video_pts_inc;
+ }
+ lastframe = total_frames;
+ total_frames++;
+ break;
+ }
+ current_offset += size;