diff options
author | Vladimir Voroshilov <voroshil@gmail.com> | 2016-03-19 17:48:39 -0400 |
---|---|---|
committer | Vittorio Giovara <vittorio.giovara@gmail.com> | 2016-05-17 12:24:32 -0400 |
commit | d621b2f795684f7119057f986066060adbe84220 (patch) | |
tree | 72e6c5c5bbbf77671ef6f344f0631ea806cb4b94 /libavformat | |
parent | 34effe816f9f3df2e6b8bc738e2b5a86a24fd0d7 (diff) | |
download | ffmpeg-d621b2f795684f7119057f986066060adbe84220.tar.gz |
lavf: Raw G.729 demuxer
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/Makefile | 1 | ||||
-rw-r--r-- | libavformat/allformats.c | 1 | ||||
-rw-r--r-- | libavformat/g729dec.c | 105 | ||||
-rw-r--r-- | libavformat/version.h | 4 |
4 files changed, 109 insertions, 2 deletions
diff --git a/libavformat/Makefile b/libavformat/Makefile index 7f4a0be6ca..48b66cf464 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -140,6 +140,7 @@ OBJS-$(CONFIG_G722_DEMUXER) += g722.o rawdec.o OBJS-$(CONFIG_G722_MUXER) += rawenc.o OBJS-$(CONFIG_G723_1_DEMUXER) += g723_1.o OBJS-$(CONFIG_G723_1_MUXER) += rawenc.o +OBJS-$(CONFIG_G729_DEMUXER) += g729dec.o OBJS-$(CONFIG_GIF_MUXER) += gif.o OBJS-$(CONFIG_GSM_DEMUXER) += gsmdec.o OBJS-$(CONFIG_GXF_DEMUXER) += gxf.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 687ae1bf2a..f51c4e75ed 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -105,6 +105,7 @@ void av_register_all(void) REGISTER_MUXER (FRAMEMD5, framemd5); REGISTER_MUXDEMUX(G722, g722); REGISTER_MUXDEMUX(G723_1, g723_1); + REGISTER_DEMUXER (G729, g729); REGISTER_MUXER (GIF, gif); REGISTER_DEMUXER (GSM, gsm); REGISTER_MUXDEMUX(GXF, gxf); diff --git a/libavformat/g729dec.c b/libavformat/g729dec.c new file mode 100644 index 0000000000..c2beb60eda --- /dev/null +++ b/libavformat/g729dec.c @@ -0,0 +1,105 @@ +/* + * G.729 raw format demuxer + * Copyright (c) 2011 Vladimir Voroshilov + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/log.h" +#include "libavutil/opt.h" + +#include "avformat.h" +#include "internal.h" + +typedef struct G729DemuxerContext { + AVClass *class; + + int bit_rate; +} G729DemuxerContext; + +static int g729_read_header(AVFormatContext *s) +{ + AVStream* st; + G729DemuxerContext *s1 = s->priv_data; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_G729; + st->codecpar->sample_rate = 8000; + st->codecpar->channels = 1; + + if (s1 && s1->bit_rate) + s->bit_rate = s1->bit_rate; + + switch(s->bit_rate) { + case 6400: + st->codecpar->block_align = 8; + break; + case 8000: + st->codecpar->block_align = 10; + break; + default: + av_log(s, AV_LOG_ERROR, "Invalid bit_rate value %d. " + "Only 6400 and 8000 b/s are supported.", s->bit_rate); + return AVERROR(EINVAL); + } + + avpriv_set_pts_info(st, st->codecpar->block_align << 3, 1, + st->codecpar->sample_rate); + + return 0; +} + +static int g729_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVStream *st = s->streams[0]; + int ret = av_get_packet(s->pb, pkt, st->codecpar->block_align); + if (ret < 0) + return ret; + + pkt->stream_index = 0; + pkt->dts = pkt->pts = pkt->pos / st->codecpar->block_align; + + return 0; +} + +#define OFFSET(x) offsetof(G729DemuxerContext, x) +static const AVOption g729_options[] = { + { "bit_rate", "", OFFSET(bit_rate), AV_OPT_TYPE_INT, { .i64 = 8000 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; + +static const AVClass g729_demuxer_class = { + .class_name = "g729 demuxer", + .item_name = av_default_item_name, + .option = g729_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_g729_demuxer = { + .name = "g729", + .long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"), + .priv_data_size = sizeof(G729DemuxerContext), + .read_header = g729_read_header, + .read_packet = g729_read_packet, + .flags = AVFMT_GENERIC_INDEX, + .extensions = "g729", + .priv_class = &g729_demuxer_class, +}; diff --git a/libavformat/version.h b/libavformat/version.h index aae1e23163..a50e443c76 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,8 +30,8 @@ #include "libavutil/version.h" #define LIBAVFORMAT_VERSION_MAJOR 57 -#define LIBAVFORMAT_VERSION_MINOR 5 -#define LIBAVFORMAT_VERSION_MICRO 2 +#define LIBAVFORMAT_VERSION_MINOR 6 +#define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ |