00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avformat.h"
00028 #include "internal.h"
00029
00030 static const uint8_t frame_size[4] = {24, 20, 4, 1};
00031
00032 static int g723_1_init(AVFormatContext *s, AVFormatParameters *ap)
00033 {
00034 AVStream *st;
00035
00036 st = avformat_new_stream(s, NULL);
00037 if (!st)
00038 return AVERROR(ENOMEM);
00039
00040 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00041 st->codec->codec_id = CODEC_ID_G723_1;
00042 st->codec->channels = 1;
00043 st->codec->sample_rate = 8000;
00044
00045 avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
00046
00047 return 0;
00048 }
00049
00050 static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
00051 {
00052 int size, byte, ret;
00053
00054 pkt->pos = avio_tell(s->pb);
00055 byte = avio_r8(s->pb);
00056 size = frame_size[byte & 3];
00057
00058 ret = av_new_packet(pkt, size);
00059 if (ret < 0)
00060 return ret;
00061
00062 pkt->data[0] = byte;
00063 pkt->duration = 240;
00064 pkt->stream_index = 0;
00065
00066 ret = avio_read(s->pb, pkt->data + 1, size - 1);
00067 if (ret < size - 1) {
00068 av_free_packet(pkt);
00069 return ret < 0 ? ret : AVERROR_EOF;
00070 }
00071
00072 return pkt->size;
00073 }
00074
00075 AVInputFormat ff_g723_1_demuxer = {
00076 .name = "g723_1",
00077 .long_name = NULL_IF_CONFIG_SMALL("G.723.1 format"),
00078 .read_header = g723_1_init,
00079 .read_packet = g723_1_read_packet,
00080 .extensions = "tco,rco",
00081 .flags = AVFMT_GENERIC_INDEX
00082 };