From: Vladimir Voroshilov <[email protected]>
Signed-off-by: Vittorio Giovara <[email protected]>
---
Changelog | 1 +
doc/general.texi | 1 +
libavformat/Makefile | 1 +
libavformat/allformats.c | 1 +
libavformat/g729dec.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++
libavformat/version.h | 2 +-
6 files changed, 110 insertions(+), 1 deletion(-)
create mode 100644 libavformat/g729dec.c
diff --git a/Changelog b/Changelog
index 92c694bc..ca9c9b4 100644
--- a/Changelog
+++ b/Changelog
@@ -51,6 +51,7 @@ version <next>:
- support Apple AVFoundation video capture
- G.723.1 muxer and encoder
- compressed SWF
+- G.729 raw demuxer
version 11:
diff --git a/doc/general.texi b/doc/general.texi
index 15e4a66..40d3f4a 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -809,6 +809,7 @@ following image formats are supported:
@item ADPCM Electronic Arts XAS @tab @tab X
@item ADPCM G.722 @tab X @tab X
@item ADPCM G.726 @tab X @tab X
+@item ADPCM G.729 @tab X @tab
@item ADPCM IMA AMV @tab @tab X
@tab Used in AMV files
@item ADPCM IMA Electronic Arts EACS @tab @tab X
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 46cf9e0..891a20f 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -142,6 +142,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_H261_DEMUXER) += h261dec.o rawdec.o
OBJS-$(CONFIG_H261_MUXER) += rawenc.o
OBJS-$(CONFIG_H263_DEMUXER) += h263dec.o rawdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 43d0e6d..0f49756 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 0000000..b87352d
--- /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 f264076..a50e443 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
#include "libavutil/version.h"
#define LIBAVFORMAT_VERSION_MAJOR 57
-#define LIBAVFORMAT_VERSION_MINOR 5
+#define LIBAVFORMAT_VERSION_MINOR 6
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
--
2.7.3
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel