[libav-devel] [PATCH 2/3] lavf: Raw G.729 demuxer

Luca Barbato lu_zero at gentoo.org
Mon Nov 16 18:03:13 CET 2015


On 12/11/15 14:53, Vittorio Giovara wrote:
> From: Vladimir Voroshilov <voroshil at gmail.com>
> 
> Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>
> ---
>  Changelog                |  1 +
>  libavformat/Makefile     |  1 +
>  libavformat/allformats.c |  1 +
>  libavformat/g729dec.c    | 99 ++++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 102 insertions(+)
>  create mode 100644 libavformat/g729dec.c
> 
> diff --git a/Changelog b/Changelog
> index 6ac6adf..09050c7 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -48,6 +48,7 @@ version <next>:
>  - libkvazaar HEVC encoder
>  - innoHeim/Rsupport Screen Capture Codec decoder
>  - G.723.1 muxer
> +- G.729 demuxer
>  
>  
>  version 11:
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index c5d1bfa..04ef693 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -139,6 +139,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 a514c63..1df2a60 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -112,6 +112,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..92c36a3
> --- /dev/null
> +++ b/libavformat/g729dec.c
> @@ -0,0 +1,99 @@
> +/*
> + * 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->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
> +    st->codec->codec_id    = AV_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 == 6400) {
> +        st->codec->block_align = 8;
> +    } else if (s->bit_rate == 8000) {
> +        st->codec->block_align = 10;

This should be a switch.

> +    } 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;
> +    }

This should be a request for samples.

The rest shouldn't hurt.

lu


More information about the libav-devel mailing list