aboutsummaryrefslogtreecommitdiffstats
path: root/libav/wav.c
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2002-10-28 00:55:25 +0000
committerFabrice Bellard <fabrice@bellard.org>2002-10-28 00:55:25 +0000
commite095026ab4845e97c61dbf3c3bda149f9195398d (patch)
tree71be331a5579f1704c2c44628683f5f59f0cdb64 /libav/wav.c
parent6d2abd6b3e660108d337e838206623a291d88cad (diff)
downloadffmpeg-e095026ab4845e97c61dbf3c3bda149f9195398d.tar.gz
unified wav header parsing - added extradata support
Originally committed as revision 1092 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libav/wav.c')
-rw-r--r--libav/wav.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/libav/wav.c b/libav/wav.c
index 7fb3bd3328..172a5cbf14 100644
--- a/libav/wav.c
+++ b/libav/wav.c
@@ -1,6 +1,6 @@
/*
* WAV encoder and decoder
- * Copyright (c) 2001 Fabrice Bellard.
+ * Copyright (c) 2001, 2002 Fabrice Bellard.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -29,6 +29,8 @@ CodecTag codec_wav_tags[] = {
{ CODEC_ID_PCM_MULAW, 0x07 },
{ CODEC_ID_ADPCM_MS, 0x02 },
{ CODEC_ID_ADPCM_IMA_WAV, 0x11 },
+ { CODEC_ID_WMAV1, 0x160 },
+ { CODEC_ID_WMAV2, 0x161 },
{ 0, 0 },
};
@@ -101,6 +103,32 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
return hdrsize;
}
+void get_wav_header(ByteIOContext *pb, AVCodecContext *codec,
+ int has_extra_data)
+{
+ int id, bps, size;
+
+ id = get_le16(pb);
+ codec->codec_type = CODEC_TYPE_AUDIO;
+ codec->codec_tag = id;
+ codec->fourcc = id;
+ codec->channels = get_le16(pb);
+ codec->sample_rate = get_le32(pb);
+ codec->bit_rate = get_le32(pb) * 8;
+ codec->block_align = get_le16(pb);
+ bps = get_le16(pb); /* bits per sample */
+ codec->codec_id = wav_codec_get_id(id, bps);
+ if (has_extra_data) {
+ size = get_le16(pb);
+ if (size > 0) {
+ codec->extradata = av_mallocz(size);
+ get_buffer(pb, codec->extradata, size);
+ codec->extradata_size = size;
+ }
+ }
+}
+
+
int wav_codec_get_id(unsigned int tag, int bps)
{
int id;
@@ -213,8 +241,6 @@ static int wav_read_header(AVFormatContext *s,
int size;
unsigned int tag;
ByteIOContext *pb = &s->pb;
- unsigned int id, channels, rate, bit_rate, extra_size, bps;
- unsigned int blkalign;
AVStream *st;
/* check RIFF header */
@@ -231,34 +257,15 @@ static int wav_read_header(AVFormatContext *s,
size = find_tag(pb, MKTAG('f', 'm', 't', ' '));
if (size < 0)
return -1;
- id = get_le16(pb);
- channels = get_le16(pb);
- rate = get_le32(pb);
- bit_rate = get_le32(pb) * 8;
- blkalign = get_le16(pb); /* block align */
- bps = get_le16(pb); /* bits per sample */
- if (size >= 18) {
- /* wav_extra_size */
- extra_size = get_le16(pb);
- /* skip unused data */
- url_fseek(pb, size - 18, SEEK_CUR);
- }
-
- size = find_tag(pb, MKTAG('d', 'a', 't', 'a'));
- if (size < 0)
- return -1;
-
- /* now we are ready: build format streams */
st = av_new_stream(s, 0);
if (!st)
return AVERROR_NOMEM;
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_tag = id;
- st->codec.codec_id = wav_codec_get_id(id, bps);
- st->codec.channels = channels;
- st->codec.sample_rate = rate;
- st->codec.block_align = blkalign;
+ get_wav_header(pb, &st->codec, (size >= 18));
+
+ size = find_tag(pb, MKTAG('d', 'a', 't', 'a'));
+ if (size < 0)
+ return -1;
return 0;
}