Commit 5ed8fafc authored by Fabrice Bellard's avatar Fabrice Bellard
Browse files

added pcm formats


Originally committed as revision 142 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent f674bf71
......@@ -140,7 +140,14 @@ extern AVFormat ac3_format;
extern AVFormat h263_format;
extern AVFormat mpeg1video_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;
/* ffm.c */
......
......@@ -71,7 +71,9 @@ CodecTag codec_wav_tags[] = {
{ CODEC_ID_MP2, 0x55 },
{ CODEC_ID_MP2, 0x50 },
{ 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 },
};
......
......@@ -68,7 +68,6 @@ static int raw_read_header(AVFormatContext *s,
case CODEC_TYPE_AUDIO:
st->codec.sample_rate = ap->sample_rate;
st->codec.channels = ap->channels;
/* XXX: endianness */
break;
case CODEC_TYPE_VIDEO:
st->codec.frame_rate = ap->frame_rate;
......@@ -84,6 +83,26 @@ static int raw_read_header(AVFormatContext *s,
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
int raw_read_packet(AVFormatContext *s,
......@@ -229,18 +248,148 @@ AVFormat mjpeg_format = {
raw_read_close,
};
AVFormat pcm_format = {
"pcm",
"pcm raw format",
/* pcm formats */
AVFormat pcm_s16le_format = {
"s16le",
"pcm signed 16 bit little endian format",
NULL,
#ifdef WORDS_BIGENDIAN
"",
#else
"sw",
CODEC_ID_PCM,
#endif
CODEC_ID_PCM_S16LE,
0,
raw_write_header,
raw_write_packet,
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_close,
};
......
......@@ -142,7 +142,14 @@ void register_all(void)
register_avformat(&single_jpeg_format);
register_avformat(&swf_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);
#ifndef CONFIG_WIN32
register_avformat(&ffm_format);
......
......@@ -110,7 +110,7 @@ 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;
unsigned int id, channels, rate, bit_rate, extra_size, bps;
AVStream *st;
/* check RIFF header */
......@@ -132,7 +132,7 @@ static int wav_read_header(AVFormatContext *s,
rate = get_le32(pb);
bit_rate = get_le32(pb) * 8;
get_le16(pb); /* block align */
get_le16(pb); /* bits per sample */
bps = get_le16(pb); /* bits per sample */
if (size >= 18) {
/* wav_extra_size */
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.channels = channels;
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;
}
......@@ -181,6 +184,9 @@ static int wav_read_packet(AVFormatContext *s,
ret = get_buffer(&s->pb, pkt->data, pkt->size);
if (ret < 0)
av_free_packet(pkt);
/* note: we need to modify the packet size here to handle the last
packet */
pkt->size = ret;
return ret;
}
......@@ -194,7 +200,7 @@ AVFormat wav_format = {
"wav format",
"audio/x-wav",
"wav",
CODEC_ID_PCM,
CODEC_ID_PCM_S16LE,
CODEC_ID_NONE,
wav_write_header,
wav_write_packet,
......
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