summaryrefslogtreecommitdiff
path: root/libavformat/sierravmd.c
diff options
context:
space:
mode:
authorCarl Eugen Hoyos <cehoyos@ag.or.at>2013-05-05 19:52:30 +0200
committerCarl Eugen Hoyos <cehoyos@ag.or.at>2013-05-05 19:52:30 +0200
commit4ec509ce3d1f9377c8519cdcc385753bb53b14aa (patch)
treefd336909060a6c8d5b04eb4a8b87cbd88e2d7835 /libavformat/sierravmd.c
parenta07ac1f7888fd08e42da2bed0421e74f1cfac177 (diff)
Support demuxing of audio-only vmd files.
Reviewed-by: Paul B Mahol
Diffstat (limited to 'libavformat/sierravmd.c')
-rw-r--r--libavformat/sierravmd.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/libavformat/sierravmd.c b/libavformat/sierravmd.c
index d2f2b69cd7..5a88128ee6 100644
--- a/libavformat/sierravmd.c
+++ b/libavformat/sierravmd.c
@@ -64,8 +64,8 @@ typedef struct VmdDemuxContext {
static int vmd_probe(AVProbeData *p)
{
- int w, h;
- if (p->buf_size < 16)
+ int w, h, sample_rate;
+ if (p->buf_size < 806)
return 0;
/* check if the first 2 bytes of the file contain the appropriate size
* of a VMD header chunk */
@@ -73,7 +73,9 @@ static int vmd_probe(AVProbeData *p)
return 0;
w = AV_RL16(&p->buf[12]);
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;
/* only return half certainty since this check is a bit sketchy */
@@ -84,12 +86,12 @@ static int vmd_read_header(AVFormatContext *s)
{
VmdDemuxContext *vmd = s->priv_data;
AVIOContext *pb = s->pb;
- AVStream *st = NULL, *vst;
+ AVStream *st = NULL, *vst = NULL;
unsigned int toc_offset;
unsigned char *raw_frame_table;
int raw_frame_table_size;
int64_t current_offset;
- int i, j;
+ int i, j, width, height;
unsigned int total_frames;
int64_t current_audio_pts = 0;
unsigned char chunk[BYTES_PER_FRAME_RECORD];
@@ -101,6 +103,9 @@ static int vmd_read_header(AVFormatContext *s)
if (avio_read(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE)
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')
vmd->is_indeo3 = 1;
else
@@ -114,8 +119,8 @@ static int vmd_read_header(AVFormatContext *s)
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_tag = 0; /* no fourcc */
- vst->codec->width = AV_RL16(&vmd->vmd_header[12]);
- vst->codec->height = AV_RL16(&vmd->vmd_header[14]);
+ vst->codec->width = width;
+ vst->codec->height = height;
if(vmd->is_indeo3 && vst->codec->width > 320){
vst->codec->width >>= 1;
vst->codec->height >>= 1;
@@ -123,6 +128,7 @@ static int vmd_read_header(AVFormatContext *s)
vst->codec->extradata_size = VMD_HEADER_SIZE;
vst->codec->extradata = av_mallocz(VMD_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(vst->codec->extradata, vmd->vmd_header, VMD_HEADER_SIZE);
+ }
/* if sample rate is 0, assume no audio */
vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]);
@@ -156,6 +162,7 @@ static int vmd_read_header(AVFormatContext *s)
num = st->codec->block_align;
den = st->codec->sample_rate * st->codec->channels;
av_reduce(&num, &den, num, den, (1UL<<31)-1);
+ if (vst)
avpriv_set_pts_info(vst, 33, num, den);
avpriv_set_pts_info(st, 33, num, den);
}