From b456ece55731c545d0bf62641fee2da437861987 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 1 Nov 2015 13:15:36 +0100 Subject: XMA1 and XMA2 stereo decoders Signed-off-by: Paul B Mahol --- libavformat/riffdec.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'libavformat/riffdec.c') diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c index 26779e1..e75aee5 100644 --- a/libavformat/riffdec.c +++ b/libavformat/riffdec.c @@ -99,10 +99,12 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, codec->codec_type = AVMEDIA_TYPE_AUDIO; if (!big_endian) { id = avio_rl16(pb); - codec->channels = avio_rl16(pb); - codec->sample_rate = avio_rl32(pb); - bitrate = avio_rl32(pb) * 8LL; - codec->block_align = avio_rl16(pb); + if (id != 0x0165) { + codec->channels = avio_rl16(pb); + codec->sample_rate = avio_rl32(pb); + bitrate = avio_rl32(pb) * 8LL; + codec->block_align = avio_rl16(pb); + } } else { id = avio_rb16(pb); codec->channels = avio_rb16(pb); @@ -126,7 +128,7 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample); } - if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */ + if (size >= 18 && id != 0x0165) { /* We're obviously dealing with WAVEFORMATEX */ int cbSize = avio_rl16(pb); /* cbSize */ if (big_endian) { avpriv_report_missing_feature(codec, "WAVEFORMATEX support for RIFX files\n"); @@ -149,6 +151,21 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, /* It is possible for the chunk to contain garbage at the end */ if (size > 0) avio_skip(pb, size); + } else if (id == 0x0165 && size >= 32) { + int nb_streams, i; + + size -= 4; + av_freep(&codec->extradata); + if (ff_get_extradata(codec, pb, size) < 0) + return AVERROR(ENOMEM); + nb_streams = AV_RL16(codec->extradata + 4); + codec->sample_rate = AV_RL32(codec->extradata + 12); + codec->channels = 0; + bitrate = 0; + if (size < 8 + nb_streams * 20) + return AVERROR_INVALIDDATA; + for (i = 0; i < nb_streams; i++) + codec->channels += codec->extradata[8 + i * 20 + 17]; } if (bitrate > INT_MAX) { -- cgit v1.1