Просмотр исходного кода

Minimal patch for G.729 demuxer

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Vladimir Voroshilov 13 лет назад
Родитель
Сommit
0fd59f1d45
3 измененных файлов с 104 добавлено и 0 удалено
  1. 1 0
      libavformat/Makefile
  2. 1 0
      libavformat/allformats.c
  3. 102 0
      libavformat/g729dec.c

+ 1 - 0
libavformat/Makefile

@@ -100,6 +100,7 @@ OBJS-$(CONFIG_G722_DEMUXER)              += 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

+ 1 - 0
libavformat/allformats.c

@@ -101,6 +101,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);

+ 102 - 0
libavformat/g729dec.c

@@ -0,0 +1,102 @@
+/*
+ * G.729 raw format demuxer
+ * Copyright (c) 2011 Vladimir Voroshilov
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avformat.h"
+#include "libavutil/log.h"
+#include "libavutil/opt.h"
+
+typedef struct G729DemuxerContext {
+    AVClass *class;
+    int bit_rate;
+} G729DemuxerContext;
+
+static int g729_read_header(AVFormatContext *s, AVFormatParameters *ap)
+{
+    AVStream* st;
+    G729DemuxerContext *s1 = s->priv_data;
+
+    st = avformat_new_stream(s, NULL);
+    if (!st)
+        return AVERROR(ENOMEM);
+
+    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
+    st->codec->codec_id = CODEC_ID_G729;
+    st->codec->sample_rate = 8000;
+    st->codec->channels = 1;
+
+    if (s1 && s1->bit_rate) {
+        s->bit_rate = s1->bit_rate;
+    }
+
+    if (s->bit_rate == 0) {
+        av_log(s, AV_LOG_DEBUG, "No bitrate specified. Assuming 8000 b/s\n");
+        s->bit_rate = 8000;
+    }
+
+    if (s->bit_rate == 6400) {
+        st->codec->block_align = 8;
+    } else if (s->bit_rate == 8000) {
+        st->codec->block_align = 10;
+    } else {
+        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);
+        return AVERROR_INVALIDDATA;
+    }
+
+    av_set_pts_info(st, st->codec->block_align << 3, 1, st->codec->sample_rate);
+    return 0;
+}
+static int g729_read_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    int ret;
+
+    ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align);
+
+    pkt->stream_index = 0;
+    if (ret < 0)
+        return ret;
+
+    pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codec->block_align;
+
+    return ret;
+}
+
+static const AVOption g729_options[] = {
+    { "bit_rate", "", offsetof(G729DemuxerContext, bit_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 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,
+};