aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--libav/asf.c19
-rw-r--r--libav/avi.h2
-rw-r--r--libav/avidec.c16
-rw-r--r--libav/wav.c61
4 files changed, 41 insertions, 57 deletions
diff --git a/libav/asf.c b/libav/asf.c
index 1044a12f64..d0529c2eb8 100644
--- a/libav/asf.c
+++ b/libav/asf.c
@@ -745,7 +745,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
ByteIOContext *pb = &s->pb;
AVStream *st;
ASFStream *asf_st;
- int size, i, bps;
+ int size, i;
INT64 gsize;
av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
@@ -784,7 +784,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
asf->packet_size = asf->hdr.max_pktsize;
asf->nb_packets = asf->hdr.packets_count;
} else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
- int type, id, total_size;
+ int type, total_size;
unsigned int tag1;
INT64 pos1, pos2;
@@ -819,20 +819,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec.codec_type = type;
st->codec.frame_rate = 1000000; // us
if (type == CODEC_TYPE_AUDIO) {
- id = get_le16(pb);
- st->codec.codec_tag = id;
- st->codec.channels = get_le16(pb);
- st->codec.sample_rate = get_le32(pb);
- st->codec.bit_rate = get_le32(pb) * 8;
- st->codec.block_align = get_le16(pb); /* block align */
- bps = get_le16(pb); /* bits per sample */
- st->codec.codec_id = wav_codec_get_id(id, bps);
- size = get_le16(pb);
- if (size > 0) {
- st->extra_data = av_mallocz(size);
- get_buffer(pb, st->extra_data, size);
- st->extra_data_size = size;
- }
+ get_wav_header(pb, &st->codec, 1);
/* We have to init the frame size at some point .... */
pos2 = url_ftell(pb);
if (gsize > (pos2 + 8 - pos1 + 24)) {
diff --git a/libav/avi.h b/libav/avi.h
index 043b622635..cdd20769df 100644
--- a/libav/avi.h
+++ b/libav/avi.h
@@ -17,6 +17,8 @@ typedef struct CodecTag {
void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, CodecTag *tags);
int put_wav_header(ByteIOContext *pb, AVCodecContext *enc);
int wav_codec_get_id(unsigned int tag, int bps);
+void get_wav_header(ByteIOContext *pb, AVCodecContext *codec,
+ int has_extra_data);
extern CodecTag codec_bmp_tags[];
extern CodecTag codec_wav_tags[];
diff --git a/libav/avidec.c b/libav/avidec.c
index 86d4af5ffb..80ea928ffa 100644
--- a/libav/avidec.c
+++ b/libav/avidec.c
@@ -51,7 +51,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
ByteIOContext *pb = &s->pb;
UINT32 tag, tag1;
int codec_type, stream_index, size, frame_period, bit_rate;
- int i, bps;
+ int i;
AVStream *st;
/* check RIFF header */
@@ -160,19 +160,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
url_fskip(pb, size - 5 * 4);
break;
case CODEC_TYPE_AUDIO:
- tag1 = get_le16(pb);
- st->codec.codec_type = CODEC_TYPE_AUDIO;
- st->codec.codec_tag = tag1;
-#ifdef DEBUG
- printf("audio: 0x%x\n", tag1);
-#endif
- st->codec.channels = get_le16(pb);
- st->codec.sample_rate = get_le32(pb);
- st->codec.bit_rate = get_le32(pb) * 8;
- get_le16(pb); /* block align */
- bps = get_le16(pb);
- st->codec.codec_id = wav_codec_get_id(tag1, bps);
- url_fskip(pb, size - 4 * 4);
+ get_wav_header(pb, &st->codec, (size >= 18));
break;
default:
url_fskip(pb, size);
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;
}