00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avformat.h"
00023 #include "internal.h"
00024 #include "libavutil/log.h"
00025 #include "libavutil/opt.h"
00026
00027 typedef struct G729DemuxerContext {
00028 AVClass *class;
00029 int bit_rate;
00030 } G729DemuxerContext;
00031
00032 static int g729_read_header(AVFormatContext *s)
00033 {
00034 AVStream* st;
00035 G729DemuxerContext *s1 = s->priv_data;
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 = CODEC_ID_G729;
00043 st->codec->sample_rate = 8000;
00044 st->codec->channels = 1;
00045
00046 if (s1 && s1->bit_rate) {
00047 s->bit_rate = s1->bit_rate;
00048 }
00049
00050 if (s->bit_rate == 0) {
00051 av_log(s, AV_LOG_DEBUG, "No bitrate specified. Assuming 8000 b/s\n");
00052 s->bit_rate = 8000;
00053 }
00054
00055 if (s->bit_rate == 6400) {
00056 st->codec->block_align = 8;
00057 } else if (s->bit_rate == 8000) {
00058 st->codec->block_align = 10;
00059 } else {
00060 av_log(s, AV_LOG_ERROR, "Only 8000 b/s and 6400 b/s bitrates are supported. Provided: %d b/s\n", s->bit_rate);
00061 return AVERROR_INVALIDDATA;
00062 }
00063
00064 avpriv_set_pts_info(st, st->codec->block_align << 3, 1, st->codec->sample_rate);
00065 return 0;
00066 }
00067 static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
00068 {
00069 int ret;
00070
00071 ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align);
00072
00073 pkt->stream_index = 0;
00074 if (ret < 0)
00075 return ret;
00076
00077 pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codec->block_align;
00078
00079 return ret;
00080 }
00081
00082 static const AVOption g729_options[] = {
00083 { "bit_rate", "", offsetof(G729DemuxerContext, bit_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
00084 { NULL },
00085 };
00086
00087 static const AVClass g729_demuxer_class = {
00088 .class_name = "g729 demuxer",
00089 .item_name = av_default_item_name,
00090 .option = g729_options,
00091 .version = LIBAVUTIL_VERSION_INT,
00092 };
00093
00094 AVInputFormat ff_g729_demuxer = {
00095 .name = "g729",
00096 .long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
00097 .priv_data_size = sizeof(G729DemuxerContext),
00098 .read_header = g729_read_header,
00099 .read_packet = g729_read_packet,
00100 .flags = AVFMT_GENERIC_INDEX,
00101 .extensions = "g729",
00102 .priv_class = &g729_demuxer_class,
00103 };