Commit 4ec509ce authored by Carl Eugen Hoyos's avatar Carl Eugen Hoyos

Support demuxing of audio-only vmd files.

Reviewed-by: Paul B Mahol
parent a07ac1f7
...@@ -64,8 +64,8 @@ typedef struct VmdDemuxContext { ...@@ -64,8 +64,8 @@ typedef struct VmdDemuxContext {
static int vmd_probe(AVProbeData *p) static int vmd_probe(AVProbeData *p)
{ {
int w, h; int w, h, sample_rate;
if (p->buf_size < 16) if (p->buf_size < 806)
return 0; return 0;
/* check if the first 2 bytes of the file contain the appropriate size /* check if the first 2 bytes of the file contain the appropriate size
* of a VMD header chunk */ * of a VMD header chunk */
...@@ -73,7 +73,9 @@ static int vmd_probe(AVProbeData *p) ...@@ -73,7 +73,9 @@ static int vmd_probe(AVProbeData *p)
return 0; return 0;
w = AV_RL16(&p->buf[12]); w = AV_RL16(&p->buf[12]);
h = AV_RL16(&p->buf[14]); h = AV_RL16(&p->buf[14]);
if (!w || w > 2048 || !h || h > 2048) sample_rate = AV_RL16(&p->buf[804]);
if ((!w || w > 2048 || !h || h > 2048) &&
sample_rate != 22050)
return 0; return 0;
/* only return half certainty since this check is a bit sketchy */ /* only return half certainty since this check is a bit sketchy */
...@@ -84,12 +86,12 @@ static int vmd_read_header(AVFormatContext *s) ...@@ -84,12 +86,12 @@ static int vmd_read_header(AVFormatContext *s)
{ {
VmdDemuxContext *vmd = s->priv_data; VmdDemuxContext *vmd = s->priv_data;
AVIOContext *pb = s->pb; AVIOContext *pb = s->pb;
AVStream *st = NULL, *vst; AVStream *st = NULL, *vst = NULL;
unsigned int toc_offset; unsigned int toc_offset;
unsigned char *raw_frame_table; unsigned char *raw_frame_table;
int raw_frame_table_size; int raw_frame_table_size;
int64_t current_offset; int64_t current_offset;
int i, j; int i, j, width, height;
unsigned int total_frames; unsigned int total_frames;
int64_t current_audio_pts = 0; int64_t current_audio_pts = 0;
unsigned char chunk[BYTES_PER_FRAME_RECORD]; unsigned char chunk[BYTES_PER_FRAME_RECORD];
...@@ -101,6 +103,9 @@ static int vmd_read_header(AVFormatContext *s) ...@@ -101,6 +103,9 @@ static int vmd_read_header(AVFormatContext *s)
if (avio_read(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE) if (avio_read(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE)
return AVERROR(EIO); return AVERROR(EIO);
width = AV_RL16(&vmd->vmd_header[12]);
height = AV_RL16(&vmd->vmd_header[14]);
if (width && height) {
if(vmd->vmd_header[24] == 'i' && vmd->vmd_header[25] == 'v' && vmd->vmd_header[26] == '3') if(vmd->vmd_header[24] == 'i' && vmd->vmd_header[25] == 'v' && vmd->vmd_header[26] == '3')
vmd->is_indeo3 = 1; vmd->is_indeo3 = 1;
else else
...@@ -114,8 +119,8 @@ static int vmd_read_header(AVFormatContext *s) ...@@ -114,8 +119,8 @@ static int vmd_read_header(AVFormatContext *s)
vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; vst->codec->codec_type = AVMEDIA_TYPE_VIDEO;
vst->codec->codec_id = vmd->is_indeo3 ? AV_CODEC_ID_INDEO3 : AV_CODEC_ID_VMDVIDEO; vst->codec->codec_id = vmd->is_indeo3 ? AV_CODEC_ID_INDEO3 : AV_CODEC_ID_VMDVIDEO;
vst->codec->codec_tag = 0; /* no fourcc */ vst->codec->codec_tag = 0; /* no fourcc */
vst->codec->width = AV_RL16(&vmd->vmd_header[12]); vst->codec->width = width;
vst->codec->height = AV_RL16(&vmd->vmd_header[14]); vst->codec->height = height;
if(vmd->is_indeo3 && vst->codec->width > 320){ if(vmd->is_indeo3 && vst->codec->width > 320){
vst->codec->width >>= 1; vst->codec->width >>= 1;
vst->codec->height >>= 1; vst->codec->height >>= 1;
...@@ -123,6 +128,7 @@ static int vmd_read_header(AVFormatContext *s) ...@@ -123,6 +128,7 @@ static int vmd_read_header(AVFormatContext *s)
vst->codec->extradata_size = VMD_HEADER_SIZE; vst->codec->extradata_size = VMD_HEADER_SIZE;
vst->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); vst->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE); memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE);
}
/* if sample rate is 0, assume no audio */ /* if sample rate is 0, assume no audio */
vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]); vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]);
...@@ -156,6 +162,7 @@ static int vmd_read_header(AVFormatContext *s) ...@@ -156,6 +162,7 @@ static int vmd_read_header(AVFormatContext *s)
num = st->codec->block_align; num = st->codec->block_align;
den = st->codec->sample_rate * st->codec->channels; den = st->codec->sample_rate * st->codec->channels;
av_reduce(&num, &den, num, den, (1UL<<31)-1); av_reduce(&num, &den, num, den, (1UL<<31)-1);
if (vst)
avpriv_set_pts_info(vst, 33, num, den); avpriv_set_pts_info(vst, 33, num, den);
avpriv_set_pts_info(st, 33, num, den); avpriv_set_pts_info(st, 33, num, den);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment