diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2012-01-23 22:28:20 +0400 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2012-01-24 23:08:29 +0400 |
commit | 7e813d59335753ab07be82919f36ddcaf075463a (patch) | |
tree | 9710f0ad3d22b3e28f5e136d5cf34431811ceebe /libavformat/westwood_vqa.c | |
parent | 5b4c5628973d212ecaa1aabaeebd0205738ceddd (diff) |
vqa: clean up audio header parsing
Fix setting of bit_rate and bits_per_coded_sample.
Ask for sample for unsupported VQA versions.
Diffstat (limited to 'libavformat/westwood_vqa.c')
-rw-r--r-- | libavformat/westwood_vqa.c | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/libavformat/westwood_vqa.c b/libavformat/westwood_vqa.c index a99a816062..c338d95182 100644 --- a/libavformat/westwood_vqa.c +++ b/libavformat/westwood_vqa.c @@ -86,7 +86,7 @@ static int wsvqa_read_header(AVFormatContext *s, unsigned char scratch[VQA_PREAMBLE_SIZE]; unsigned int chunk_tag; unsigned int chunk_size; - int fps; + int fps, version, flags, sample_rate, channels; /* initialize the video decoder stream */ st = avformat_new_stream(s, NULL); @@ -120,30 +120,43 @@ static int wsvqa_read_header(AVFormatContext *s, avpriv_set_pts_info(st, 64, 1, fps); /* initialize the audio decoder stream for VQA v1 or nonzero samplerate */ - if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) { + version = AV_RL16(&header[ 0]); + flags = AV_RL16(&header[ 2]); + sample_rate = AV_RL16(&header[24]); + channels = header[26]; + if (sample_rate || (version == 1 && flags == 1)) { st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->start_time = 0; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; - if (AV_RL16(&header[0]) == 1) - st->codec->codec_id = CODEC_ID_WESTWOOD_SND1; - else - st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; - st->codec->codec_tag = 0; /* no tag */ - st->codec->sample_rate = AV_RL16(&header[24]); - if (!st->codec->sample_rate) - st->codec->sample_rate = 22050; - st->codec->channels = header[26]; - if (!st->codec->channels) - st->codec->channels = 1; - st->codec->bits_per_coded_sample = 16; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_coded_sample / 4; - st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + if (!sample_rate) + sample_rate = 22050; + st->codec->sample_rate = sample_rate; avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + if (!channels) + channels = 1; + st->codec->channels = channels; + + switch (version) { + case 1: + st->codec->codec_id = CODEC_ID_WESTWOOD_SND1; + break; + case 2: + case 3: + st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; + st->codec->bits_per_coded_sample = 4; + st->codec->bit_rate = channels * sample_rate * 4; + break; + default: + /* NOTE: version 0 is supposedly raw pcm_u8 or pcm_s16le, but we do + not have any samples to validate this */ + av_log_ask_for_sample(s, "VQA version %d audio\n", version); + return AVERROR_PATCHWELCOME; + } + wsvqa->audio_stream_index = st->index; wsvqa->audio_samplerate = st->codec->sample_rate; wsvqa->audio_channels = st->codec->channels; |