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