[FFmpeg-devel] [PATCH] asrc_abuffer - audio source filter

Michael Niedermayer michaelni
Fri Aug 20 01:39:22 CEST 2010


On Thu, Aug 19, 2010 at 06:07:38AM -0700, S.N. Hemanth Meenakshisundaram wrote:
> Updated doc, minor cosmetic changes in filter, added string sample
> format init argument parsing.
> 
> ---
>  doc/filters.texi           |   42 +++++++++++++
>  libavfilter/Makefile       |    2 +
>  libavfilter/allfilters.c   |    2 +
>  libavfilter/asrc_abuffer.c |  146 ++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/asrc_abuffer.h |   24 +++++++
>  5 files changed, 216 insertions(+), 0 deletions(-)
>  create mode 100644 libavfilter/asrc_abuffer.c
>  create mode 100644 libavfilter/asrc_abuffer.h
> 
> 
> 

>  doc/filters.texi           |   42 ++++++++++++
>  libavfilter/Makefile       |    2 
>  libavfilter/allfilters.c   |    2 
>  libavfilter/asrc_abuffer.c |  146 +++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/asrc_abuffer.h |   24 +++++++
>  5 files changed, 216 insertions(+)
> 1dec1949cb6dbca1016f3b8172878745b88b67e2  0001-asrc_abuffer-audio-source-filter.patch
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 7f0cb71..7eb8ae7 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -224,6 +224,48 @@ Flip the input video vertically.
>  
>  @c man end VIDEO FILTERS
>  
> + at chapter Audio Sources
> + at c man begin AUDIO SOURCES
> +
> +Below is a description of the currently available audio sources.
> +
> + at section abuffer
> +
> +Buffer audio frames, and make them available to the filter chain.
> +
> +This source is mainly intended for a programmatic use, in particular
> +through the interface defined in @file{libavfilter/asrc_abuffer.h}.
> +
> +It accepts a single mandatory parameter:
> + at var{sample_fmt_string}
> +
> +Follows the list of the accepted parameters.
> +
> + at table @option
> +
> + at item sample_fmt_string
> +
> +A string representing the sample format of the buffered audio frames.
> +It may be a number corresponding to a sample format, or a sample format
> +name.
> +
> + at end table
> +
> +For example:
> + at example
> +abuffer=s16
> + at end example
> +
> +will instruct the source to accept audio frames with format "s16".
> +Since the sample format with name "s16" corresponds to the number
> +1 (check the enum SampleFormatInfo definition in
> + at file{libavcodec/audioconvert.h}), this example corresponds to:
> + at example
> +abuffer=1
> + at end example
> +
> + at c man end AUDIO SOURCES
> +
>  @chapter Video Sources
>  @c man begin VIDEO SOURCES
>  
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index feef16c..722a5ac 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -27,6 +27,8 @@ OBJS-$(CONFIG_SLICIFY_FILTER)                += vf_slicify.o
>  OBJS-$(CONFIG_UNSHARP_FILTER)                += vf_unsharp.o
>  OBJS-$(CONFIG_VFLIP_FILTER)                  += vf_vflip.o
>  
> +OBJS-$(CONFIG_ABUFFER_FILTER)                += asrc_abuffer.o
> +
>  OBJS-$(CONFIG_BUFFER_FILTER)                 += vsrc_buffer.o
>  OBJS-$(CONFIG_COLOR_FILTER)                  += vf_pad.o
>  OBJS-$(CONFIG_NULLSRC_FILTER)                += vsrc_nullsrc.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index e8bc771..fe8a011 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -47,6 +47,8 @@ void avfilter_register_all(void)
>      REGISTER_FILTER (UNSHARP,     unsharp,     vf);
>      REGISTER_FILTER (VFLIP,       vflip,       vf);
>  
> +    REGISTER_FILTER (ABUFFER,     abuffer,     asrc);
> +
>      REGISTER_FILTER (BUFFER,      buffer,      vsrc);
>      REGISTER_FILTER (COLOR,       color,       vsrc);
>      REGISTER_FILTER (NULLSRC,     nullsrc,     vsrc);
> diff --git a/libavfilter/asrc_abuffer.c b/libavfilter/asrc_abuffer.c
> new file mode 100644
> index 0000000..00f60cc
> --- /dev/null
> +++ b/libavfilter/asrc_abuffer.c
> @@ -0,0 +1,146 @@
> +/*
> + * Memory buffer source filter for audio
> + * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram
> + *
> + * 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 "libavcodec/audioconvert.h"
> +#include "libavutil/fifo.h"
> +#include "avfilter.h"
> +#include "asrc_abuffer.h"
> +
> +#define FIFO_SIZE 8
> +
> +typedef struct {
> +    unsigned int init_sample_fmt;  ///< initial sample format indicated by client
> +    AVFifoBuffer *fifo;            ///< fifo buffer of audio frame pointers
> +} ABufferSourceContext;
> +
> +
> +int av_asrc_buffer_add_frame(AVFilterContext *ctx, uint8_t *frame, int sample_fmt,
> +                             int size, int64_t ch_layout, int planar, int64_t pts)
> +{
> +    AVFilterLink *link = ctx->outputs[0];
> +    ABufferSourceContext *abuffer = ctx->priv;
> +    AVFilterBufferRef *samplesref;
> +
> +    if (av_fifo_space(abuffer->fifo) < sizeof(samplesref)) {
> +        av_log(ctx, AV_LOG_ERROR,
> +               "Buffering limit reached. Please consume some available frames before adding new ones.\n");
> +        return AVERROR(ENOMEM);
> +    }
> +
> +    samplesref = avfilter_get_audio_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
> +                                           AV_PERM_REUSE2, sample_fmt, size, ch_layout, planar);
> +
> +    memcpy(samplesref->data[0], frame, samplesref->audio->size);

an api with forced memcpy :(
either the user should be able to provide a buffer that is used without
copy or the user should get a pointer where he can then store the data
possibly without copy

]...[
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100820/91e7217a/attachment.pgp>



More information about the ffmpeg-devel mailing list