2 * G.729 raw format demuxer
3 * Copyright (c) 2011 Vladimir Voroshilov
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "libavutil/log.h"
25 #include "libavutil/opt.h"
27 typedef struct G729DemuxerContext {
32 static int g729_read_header(AVFormatContext *s)
35 G729DemuxerContext *s1 = s->priv_data;
37 st = avformat_new_stream(s, NULL);
39 return AVERROR(ENOMEM);
41 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
42 st->codec->codec_id = AV_CODEC_ID_G729;
43 st->codec->sample_rate = 8000;
44 st->codec->channels = 1;
46 if (s1 && s1->bit_rate) {
47 s->bit_rate = s1->bit_rate;
50 if (s->bit_rate == 0) {
51 av_log(s, AV_LOG_DEBUG, "No bitrate specified. Assuming 8000 b/s\n");
55 if (s->bit_rate == 6400) {
56 st->codec->block_align = 8;
57 } else if (s->bit_rate == 8000) {
58 st->codec->block_align = 10;
60 av_log(s, AV_LOG_ERROR, "Only 8000 b/s and 6400 b/s bitrates are supported. Provided: %"PRId64" b/s\n", (int64_t)s->bit_rate);
61 return AVERROR_INVALIDDATA;
64 avpriv_set_pts_info(st, st->codec->block_align << 3, 1, st->codec->sample_rate);
67 static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
71 ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align);
73 pkt->stream_index = 0;
77 pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codec->block_align;
82 static const AVOption g729_options[] = {
83 { "bit_rate", "", offsetof(G729DemuxerContext, bit_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
87 static const AVClass g729_demuxer_class = {
88 .class_name = "g729 demuxer",
89 .item_name = av_default_item_name,
90 .option = g729_options,
91 .version = LIBAVUTIL_VERSION_INT,
94 AVInputFormat ff_g729_demuxer = {
96 .long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"),
97 .priv_data_size = sizeof(G729DemuxerContext),
98 .read_header = g729_read_header,
99 .read_packet = g729_read_packet,
100 .flags = AVFMT_GENERIC_INDEX,
101 .extensions = "g729",
102 .priv_class = &g729_demuxer_class,