1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

added pcm formats

Originally committed as revision 142 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Fabrice Bellard 2001-09-23 17:19:49 +00:00
parent f674bf7105
commit 5ed8fafcb6
5 changed files with 183 additions and 12 deletions

View File

@ -140,7 +140,14 @@ extern AVFormat ac3_format;
extern AVFormat h263_format; extern AVFormat h263_format;
extern AVFormat mpeg1video_format; extern AVFormat mpeg1video_format;
extern AVFormat mjpeg_format; extern AVFormat mjpeg_format;
extern AVFormat pcm_format; extern AVFormat pcm_s16le_format;
extern AVFormat pcm_s16be_format;
extern AVFormat pcm_u16le_format;
extern AVFormat pcm_u16be_format;
extern AVFormat pcm_s8_format;
extern AVFormat pcm_u8_format;
extern AVFormat pcm_mulaw_format;
extern AVFormat pcm_alaw_format;
extern AVFormat rawvideo_format; extern AVFormat rawvideo_format;
/* ffm.c */ /* ffm.c */

View File

@ -71,7 +71,9 @@ CodecTag codec_wav_tags[] = {
{ CODEC_ID_MP2, 0x55 }, { CODEC_ID_MP2, 0x55 },
{ CODEC_ID_MP2, 0x50 }, { CODEC_ID_MP2, 0x50 },
{ CODEC_ID_AC3, 0x2000 }, { CODEC_ID_AC3, 0x2000 },
{ CODEC_ID_PCM, 0x01 }, { CODEC_ID_PCM_S16LE, 0x01 },
{ CODEC_ID_PCM_ALAW, 0x06 },
{ CODEC_ID_PCM_MULAW, 0x07 },
{ 0, 0 }, { 0, 0 },
}; };

View File

@ -68,7 +68,6 @@ static int raw_read_header(AVFormatContext *s,
case CODEC_TYPE_AUDIO: case CODEC_TYPE_AUDIO:
st->codec.sample_rate = ap->sample_rate; st->codec.sample_rate = ap->sample_rate;
st->codec.channels = ap->channels; st->codec.channels = ap->channels;
/* XXX: endianness */
break; break;
case CODEC_TYPE_VIDEO: case CODEC_TYPE_VIDEO:
st->codec.frame_rate = ap->frame_rate; st->codec.frame_rate = ap->frame_rate;
@ -84,6 +83,26 @@ static int raw_read_header(AVFormatContext *s,
return 0; return 0;
} }
/* raw input */
static int pcm_read_header(AVFormatContext *s,
AVFormatParameters *ap)
{
AVStream *st;
st = malloc(sizeof(AVStream));
if (!st)
return -1;
s->nb_streams = 1;
s->streams[0] = st;
st->id = 0;
st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = s->format->audio_codec;
return 0;
}
#define RAW_PACKET_SIZE 1024 #define RAW_PACKET_SIZE 1024
int raw_read_packet(AVFormatContext *s, int raw_read_packet(AVFormatContext *s,
@ -229,18 +248,148 @@ AVFormat mjpeg_format = {
raw_read_close, raw_read_close,
}; };
AVFormat pcm_format = { /* pcm formats */
"pcm",
"pcm raw format", AVFormat pcm_s16le_format = {
"s16le",
"pcm signed 16 bit little endian format",
NULL, NULL,
#ifdef WORDS_BIGENDIAN
"",
#else
"sw", "sw",
CODEC_ID_PCM, #endif
CODEC_ID_PCM_S16LE,
0, 0,
raw_write_header, raw_write_header,
raw_write_packet, raw_write_packet,
raw_write_trailer, raw_write_trailer,
raw_read_header, pcm_read_header,
raw_read_packet,
raw_read_close,
};
AVFormat pcm_s16be_format = {
"s16be",
"pcm signed 16 bit big endian format",
NULL,
#ifdef WORDS_BIGENDIAN
"sw",
#else
"",
#endif
CODEC_ID_PCM_S16BE,
0,
raw_write_header,
raw_write_packet,
raw_write_trailer,
pcm_read_header,
raw_read_packet,
raw_read_close,
};
AVFormat pcm_u16le_format = {
"u16le",
"pcm unsigned 16 bit little endian format",
NULL,
#ifdef WORDS_BIGENDIAN
"",
#else
"uw",
#endif
CODEC_ID_PCM_U16LE,
0,
raw_write_header,
raw_write_packet,
raw_write_trailer,
pcm_read_header,
raw_read_packet,
raw_read_close,
};
AVFormat pcm_u16be_format = {
"u16be",
"pcm unsigned 16 bit big endian format",
NULL,
#ifdef WORDS_BIGENDIAN
"uw",
#else
"",
#endif
CODEC_ID_PCM_U16BE,
0,
raw_write_header,
raw_write_packet,
raw_write_trailer,
pcm_read_header,
raw_read_packet,
raw_read_close,
};
AVFormat pcm_s8_format = {
"s8",
"pcm signed 8 bit format",
NULL,
"sb",
CODEC_ID_PCM_S8,
0,
raw_write_header,
raw_write_packet,
raw_write_trailer,
pcm_read_header,
raw_read_packet,
raw_read_close,
};
AVFormat pcm_u8_format = {
"u8",
"pcm unsigned 8 bit format",
NULL,
"ub",
CODEC_ID_PCM_U8,
0,
raw_write_header,
raw_write_packet,
raw_write_trailer,
pcm_read_header,
raw_read_packet,
raw_read_close,
};
AVFormat pcm_mulaw_format = {
"mulaw",
"pcm mu law format",
NULL,
"ul",
CODEC_ID_PCM_MULAW,
0,
raw_write_header,
raw_write_packet,
raw_write_trailer,
pcm_read_header,
raw_read_packet,
raw_read_close,
};
AVFormat pcm_alaw_format = {
"alaw",
"pcm A law format",
NULL,
"al",
CODEC_ID_PCM_ALAW,
0,
raw_write_header,
raw_write_packet,
raw_write_trailer,
pcm_read_header,
raw_read_packet, raw_read_packet,
raw_read_close, raw_read_close,
}; };

View File

@ -142,7 +142,14 @@ void register_all(void)
register_avformat(&single_jpeg_format); register_avformat(&single_jpeg_format);
register_avformat(&swf_format); register_avformat(&swf_format);
register_avformat(&wav_format); register_avformat(&wav_format);
register_avformat(&pcm_format); register_avformat(&pcm_s16le_format);
register_avformat(&pcm_s16be_format);
register_avformat(&pcm_u16le_format);
register_avformat(&pcm_u16be_format);
register_avformat(&pcm_s8_format);
register_avformat(&pcm_u8_format);
register_avformat(&pcm_mulaw_format);
register_avformat(&pcm_alaw_format);
register_avformat(&rawvideo_format); register_avformat(&rawvideo_format);
#ifndef CONFIG_WIN32 #ifndef CONFIG_WIN32
register_avformat(&ffm_format); register_avformat(&ffm_format);

View File

@ -110,7 +110,7 @@ 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; unsigned int id, channels, rate, bit_rate, extra_size, bps;
AVStream *st; AVStream *st;
/* check RIFF header */ /* check RIFF header */
@ -132,7 +132,7 @@ static int wav_read_header(AVFormatContext *s,
rate = get_le32(pb); rate = get_le32(pb);
bit_rate = get_le32(pb) * 8; bit_rate = get_le32(pb) * 8;
get_le16(pb); /* block align */ get_le16(pb); /* block align */
get_le16(pb); /* bits per sample */ bps = get_le16(pb); /* bits per sample */
if (size >= 18) { if (size >= 18) {
/* wav_extra_size */ /* wav_extra_size */
extra_size = get_le16(pb); extra_size = get_le16(pb);
@ -158,6 +158,9 @@ static int wav_read_header(AVFormatContext *s,
st->codec.codec_id = codec_get_id(codec_wav_tags, id); st->codec.codec_id = codec_get_id(codec_wav_tags, id);
st->codec.channels = channels; st->codec.channels = channels;
st->codec.sample_rate = rate; st->codec.sample_rate = rate;
if (st->codec.codec_id == CODEC_ID_PCM_S16LE && bps == 8) {
st->codec.codec_id = CODEC_ID_PCM_U8;
}
return 0; return 0;
} }
@ -181,6 +184,9 @@ static int wav_read_packet(AVFormatContext *s,
ret = get_buffer(&s->pb, pkt->data, pkt->size); ret = get_buffer(&s->pb, pkt->data, pkt->size);
if (ret < 0) if (ret < 0)
av_free_packet(pkt); av_free_packet(pkt);
/* note: we need to modify the packet size here to handle the last
packet */
pkt->size = ret;
return ret; return ret;
} }
@ -194,7 +200,7 @@ AVFormat wav_format = {
"wav format", "wav format",
"audio/x-wav", "audio/x-wav",
"wav", "wav",
CODEC_ID_PCM, CODEC_ID_PCM_S16LE,
CODEC_ID_NONE, CODEC_ID_NONE,
wav_write_header, wav_write_header,
wav_write_packet, wav_write_packet,