Commit b5846574 authored by bellard's avatar bellard

unified wav header parsing - added extradata support


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@1092 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 33d9c19b
...@@ -745,7 +745,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -745,7 +745,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
AVStream *st; AVStream *st;
ASFStream *asf_st; ASFStream *asf_st;
int size, i, bps; int size, i;
INT64 gsize; INT64 gsize;
av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */ 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) ...@@ -784,7 +784,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
asf->packet_size = asf->hdr.max_pktsize; asf->packet_size = asf->hdr.max_pktsize;
asf->nb_packets = asf->hdr.packets_count; asf->nb_packets = asf->hdr.packets_count;
} else if (!memcmp(&g, &stream_header, sizeof(GUID))) { } else if (!memcmp(&g, &stream_header, sizeof(GUID))) {
int type, id, total_size; int type, total_size;
unsigned int tag1; unsigned int tag1;
INT64 pos1, pos2; INT64 pos1, pos2;
...@@ -819,20 +819,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -819,20 +819,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec.codec_type = type; st->codec.codec_type = type;
st->codec.frame_rate = 1000000; // us st->codec.frame_rate = 1000000; // us
if (type == CODEC_TYPE_AUDIO) { if (type == CODEC_TYPE_AUDIO) {
id = get_le16(pb); get_wav_header(pb, &st->codec, 1);
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;
}
/* We have to init the frame size at some point .... */ /* We have to init the frame size at some point .... */
pos2 = url_ftell(pb); pos2 = url_ftell(pb);
if (gsize > (pos2 + 8 - pos1 + 24)) { if (gsize > (pos2 + 8 - pos1 + 24)) {
......
...@@ -17,6 +17,8 @@ typedef struct CodecTag { ...@@ -17,6 +17,8 @@ typedef struct CodecTag {
void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, CodecTag *tags); void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, CodecTag *tags);
int put_wav_header(ByteIOContext *pb, AVCodecContext *enc); int put_wav_header(ByteIOContext *pb, AVCodecContext *enc);
int wav_codec_get_id(unsigned int tag, int bps); 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_bmp_tags[];
extern CodecTag codec_wav_tags[]; extern CodecTag codec_wav_tags[];
......
...@@ -51,7 +51,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -51,7 +51,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
UINT32 tag, tag1; UINT32 tag, tag1;
int codec_type, stream_index, size, frame_period, bit_rate; int codec_type, stream_index, size, frame_period, bit_rate;
int i, bps; int i;
AVStream *st; AVStream *st;
/* check RIFF header */ /* check RIFF header */
...@@ -160,19 +160,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -160,19 +160,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
url_fskip(pb, size - 5 * 4); url_fskip(pb, size - 5 * 4);
break; break;
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
tag1 = get_le16(pb); get_wav_header(pb, &st->codec, (size >= 18));
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);
break; break;
default: default:
url_fskip(pb, size); url_fskip(pb, size);
......
/* /*
* WAV encoder and decoder * 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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -29,6 +29,8 @@ CodecTag codec_wav_tags[] = { ...@@ -29,6 +29,8 @@ CodecTag codec_wav_tags[] = {
{ CODEC_ID_PCM_MULAW, 0x07 }, { CODEC_ID_PCM_MULAW, 0x07 },
{ CODEC_ID_ADPCM_MS, 0x02 }, { CODEC_ID_ADPCM_MS, 0x02 },
{ CODEC_ID_ADPCM_IMA_WAV, 0x11 }, { CODEC_ID_ADPCM_IMA_WAV, 0x11 },
{ CODEC_ID_WMAV1, 0x160 },
{ CODEC_ID_WMAV2, 0x161 },
{ 0, 0 }, { 0, 0 },
}; };
...@@ -101,6 +103,32 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc) ...@@ -101,6 +103,32 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
return hdrsize; 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 wav_codec_get_id(unsigned int tag, int bps)
{ {
int id; int id;
...@@ -213,8 +241,6 @@ static int wav_read_header(AVFormatContext *s, ...@@ -213,8 +241,6 @@ static int wav_read_header(AVFormatContext *s,
int size; int size;
unsigned int tag; unsigned int tag;
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
unsigned int id, channels, rate, bit_rate, extra_size, bps;
unsigned int blkalign;
AVStream *st; AVStream *st;
/* check RIFF header */ /* check RIFF header */
...@@ -231,34 +257,15 @@ static int wav_read_header(AVFormatContext *s, ...@@ -231,34 +257,15 @@ static int wav_read_header(AVFormatContext *s,
size = find_tag(pb, MKTAG('f', 'm', 't', ' ')); size = find_tag(pb, MKTAG('f', 'm', 't', ' '));
if (size < 0) if (size < 0)
return -1; 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); st = av_new_stream(s, 0);
if (!st) if (!st)
return AVERROR_NOMEM; return AVERROR_NOMEM;
st->codec.codec_type = CODEC_TYPE_AUDIO; get_wav_header(pb, &st->codec, (size >= 18));
st->codec.codec_tag = id;
st->codec.codec_id = wav_codec_get_id(id, bps); size = find_tag(pb, MKTAG('d', 'a', 't', 'a'));
st->codec.channels = channels; if (size < 0)
st->codec.sample_rate = rate; return -1;
st->codec.block_align = blkalign;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment