*/
/**
- * @file sierravmd.c
+ * @file libavformat/sierravmd.c
* Sierra VMD file demuxer
* by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
* for more information on the Sierra VMD file format, visit:
static int vmd_probe(AVProbeData *p)
{
+ int w, h;
+ if (p->buf_size < 16)
+ return 0;
/* check if the first 2 bytes of the file contain the appropriate size
* of a VMD header chunk */
if (AV_RL16(&p->buf[0]) != VMD_HEADER_SIZE - 2)
return 0;
+ w = AV_RL16(&p->buf[12]);
+ h = AV_RL16(&p->buf[14]);
+ if (!w || w > 2048 || !h || h > 2048)
+ return 0;
/* only return half certainty since this check is a bit sketchy */
return AVPROBE_SCORE_MAX / 2;
int64_t current_offset;
int i, j;
unsigned int total_frames;
- int64_t pts_inc = 1;
- int64_t current_video_pts = 0, current_audio_pts = 0;
+ int64_t current_audio_pts = 0;
unsigned char chunk[BYTES_PER_FRAME_RECORD];
int num, den;
int sound_buffers;
av_reduce(&den, &num, den, num, (1UL<<31)-1);
av_set_pts_info(vst, 33, num, den);
av_set_pts_info(st, 33, num, den);
- pts_inc = num;
}
toc_offset = AV_RL32(&vmd->vmd_header[812]);
vmd->frame_table = NULL;
sound_buffers = AV_RL16(&vmd->vmd_header[808]);
raw_frame_table_size = vmd->frame_count * 6;
- if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame)){
+ if(vmd->frame_count * vmd->frames_per_block >= UINT_MAX / sizeof(vmd_frame) - sound_buffers){
av_log(s, AV_LOG_ERROR, "vmd->frame_count * vmd->frames_per_block too large\n");
return -1;
}
get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD);
type = chunk[0];
size = AV_RL32(&chunk[2]);
- if(!size)
+ if(!size && type != 1)
continue;
switch(type) {
case 1: /* Audio Chunk */
if (!st) break;
/* first audio chunk contains several audio buffers */
- 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;
+ 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++;
+ if(!current_audio_pts)
+ current_audio_pts += sound_buffers;
+ else
+ current_audio_pts++;
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;
+ vmd->frame_table[total_frames].pts = i;
total_frames++;
break;
}
current_offset += size;
}
- current_video_pts += pts_inc;
}
av_free(raw_frame_table);
}
pkt->stream_index = frame->stream_index;
pkt->pts = frame->pts;
- av_log(NULL, AV_LOG_DEBUG, " dispatching %s frame with %d bytes and pts %"PRId64"\n",
+ av_log(s, AV_LOG_DEBUG, " dispatching %s frame with %d bytes and pts %"PRId64"\n",
(frame->frame_record[0] == 0x02) ? "video" : "audio",
frame->frame_size + BYTES_PER_FRAME_RECORD,
pkt->pts);