mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
unified wav header parsing - added extradata support
Originally committed as revision 1092 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
6d2abd6b3e
commit
e095026ab4
19
libav/asf.c
19
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)) {
|
||||
|
@ -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[];
|
||||
|
@ -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);
|
||||
|
61
libav/wav.c
61
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user