diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2001-09-23 17:19:49 +0000 |
---|---|---|
committer | Fabrice Bellard <fabrice@bellard.org> | 2001-09-23 17:19:49 +0000 |
commit | 5ed8fafcb6299dcf788438356a0a311344001db3 (patch) | |
tree | 3f53c9af8c23d0ce27325c804ec9801e96995d06 | |
parent | f674bf7105377ba498eb6c4489fa3557b64d663a (diff) | |
download | ffmpeg-5ed8fafcb6299dcf788438356a0a311344001db3.tar.gz |
added pcm formats
Originally committed as revision 142 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libav/avformat.h | 9 | ||||
-rw-r--r-- | libav/avienc.c | 4 | ||||
-rw-r--r-- | libav/raw.c | 161 | ||||
-rw-r--r-- | libav/utils.c | 9 | ||||
-rw-r--r-- | libav/wav.c | 12 |
5 files changed, 183 insertions, 12 deletions
diff --git a/libav/avformat.h b/libav/avformat.h index 298a5b513a..48a8f3f590 100644 --- a/libav/avformat.h +++ b/libav/avformat.h @@ -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 */ diff --git a/libav/avienc.c b/libav/avienc.c index aad37d3f0c..8c5848d2e6 100644 --- a/libav/avienc.c +++ b/libav/avienc.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 }, }; diff --git a/libav/raw.c b/libav/raw.c index f0d0c86c75..02b56b48ee 100644 --- a/libav/raw.c +++ b/libav/raw.c @@ -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, }; diff --git a/libav/utils.c b/libav/utils.c index a2bc404742..c3e8899be8 100644 --- a/libav/utils.c +++ b/libav/utils.c @@ -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); diff --git a/libav/wav.c b/libav/wav.c index 70a0e41b41..59994bbb26 100644 --- a/libav/wav.c +++ b/libav/wav.c @@ -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, |