[FFmpeg-devel] [PATCH] Add af_afifo - audio fifo filter
Stefano Sabatini
stefano.sabatini-lala
Wed Aug 18 11:22:34 CEST 2010
On date Tuesday 2010-08-17 19:44:31 -0700, S.N. Hemanth Meenakshisundaram encoded:
> Added filter.texi doc
>
> ---
> doc/filters.texi | 8 +++
> libavfilter/Makefile | 1 +
> libavfilter/af_afifo.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++
> libavfilter/allfilters.c | 1 +
> 4 files changed, 128 insertions(+), 0 deletions(-)
> create mode 100644 libavfilter/af_afifo.c
>
>
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index ff77fc4..f72f54e 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -8,6 +8,14 @@ build.
>
> Below is a description of the currently available video filters.
>
> + at section afifo
> +
> +First in first out buffer for audio frames.
> +
> + at example
> +./ffmpeg -i in.wav -af "afifo" out.wav
> + at end example
Please be more informative here. Check the docs I wrote for the
pending video fifo filter patch (I'm still fixing some bugs on it).
Also maybe we should start to write some tests for audio.
> +
> @section crop
>
> Crop the input video to @var{x}:@var{y}:@var{width}:@var{height}.
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 3e25e39..0e38e8a 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -14,6 +14,7 @@ OBJS = allfilters.o \
> graphparser.o \
> parseutils.o \
>
> +OBJS-$(CONFIG_AFIFO_FILTER) += af_afifo.o
> OBJS-$(CONFIG_NULLAUD_FILTER) += af_nullaud.o
>
> OBJS-$(CONFIG_ASPECT_FILTER) += vf_aspect.o
> diff --git a/libavfilter/af_afifo.c b/libavfilter/af_afifo.c
> new file mode 100644
> index 0000000..33ce8e0
> --- /dev/null
> +++ b/libavfilter/af_afifo.c
> @@ -0,0 +1,118 @@
> +/*
> + * audio frame FIFO
> + * 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 "avfilter.h"
> +
> +typedef struct BufSamples
> +{
Nit: "{" on the same line, same below.
> + AVFilterBufferRef *samples;
samplesref is less ambiguous.
> + struct BufSamples *next;
> +} BufSamples;
> +
> +typedef struct
> +{
> + BufSamples root; ///< first buffered audio buffer.
> + BufSamples *last; ///< last buffered audio buffer.
> + int frame_requests_pending; ///< flag to indicate pending frame requests.
> +} FifoContext;
> +
> +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
> +{
> + FifoContext *fifo = ctx->priv;
> + fifo->last = &fifo->root;
> +
> + return 0;
> +}
> +
> +static av_cold void uninit(AVFilterContext *ctx)
> +{
> + FifoContext *fifo = ctx->priv;
> + BufSamples *samples, *tmp;
> +
> + for(samples = fifo->root.next; samples; samples = tmp) {
> + tmp = samples->next;
> + avfilter_unref_buffer(samples->samples);
> + av_free(samples);
> + }
> +}
> +
> +static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
> +{
> + FifoContext *fifo = link->dst->priv;
> +
> + // if frame requests are pending, directly pass on buffer, do not queue.
> + if (fifo->frame_requests_pending) {
> + filter_samples(link->dst->outputs[0], samplesref);
> + fifo->frame_requests_pending--;
> + return;
> + }
> + fifo->last->next = av_mallocz(sizeof(BufSamples));
> + fifo->last = fifo->last->next;
> + fifo->last->samples = samplesref;
> +}
> +
> +static int request_frame(AVFilterLink *link)
> +{
> + FifoContext *fifo = link->src->priv;
> + BufSamples *tmp;
> +
> + if(!fifo->root.next)
Nits: if_(, same below.
> + if(avfilter_request_frame(link->src->inputs[0])) {
> + fifo->frame_requests_pending++;
> + return -1;
Propagate the avfilter_request_frame error code.
> + }
> +
> + /**
> + * by passing our own reference, we give ownership of the reference to the
> + * next filter so we don't have to worry about dereferencing it ourselves.
> + */
> + avfilter_filter_samples(link, fifo->root.next->samples);
> +
> + if(fifo->last == fifo->root.next)
> + fifo->last = &fifo->root;
> + tmp = fifo->root.next->next;
> + av_free(fifo->root.next);
> + fifo->root.next = tmp;
> +
> + return 0;
> +}
> +
> +AVFilter avfilter_af_afifo =
> +{
"{" on the same line.
> + .name = "afifo",
Missing description.
> +
> + .init = init,
> + .uninit = uninit,
> +
> + .priv_size = sizeof(FifoContext),
> +
> + .inputs = (AVFilterPad[]) {{ .name = "default",
> + .type = AVMEDIA_TYPE_AUDIO,
> + .get_audio_buffer = avfilter_null_get_audio_buffer,
> + .filter_samples = filter_samples,
> + .rej_perms = AV_PERM_REUSE2, },
> + { .name = NULL}},
> + .outputs = (AVFilterPad[]) {{ .name = "default",
> + .type = AVMEDIA_TYPE_AUDIO,
> + .request_frame = request_frame, },
> + { .name = NULL}},
> +};
> +
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index cab7d4b..9bf8c10 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -34,6 +34,7 @@ void avfilter_register_all(void)
> return;
> initialized = 1;
>
> + REGISTER_FILTER (AFIFO, afifo, af);
> REGISTER_FILTER (NULLAUD, nullaud, af);
>
> REGISTER_FILTER (ASPECT, aspect, vf);
>
Regards.
--
FFmpeg = Fiendish & Furious Martial Portable Educated Gargoyle
More information about the ffmpeg-devel
mailing list