[FFmpeg-devel] [PATCH 2/4] lavfi: add audioframe helper functions.

Michael Niedermayer michaelni at gmx.at
Fri Jun 29 16:31:27 CEST 2012


On Fri, Jun 29, 2012 at 02:41:07PM +0200, Nicolas George wrote:
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavfilter/audioframe.h |  145 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 145 insertions(+)
>  create mode 100644 libavfilter/audioframe.h
> 
> diff --git a/libavfilter/audioframe.h b/libavfilter/audioframe.h
> new file mode 100644
> index 0000000..f66cc6b
> --- /dev/null
> +++ b/libavfilter/audioframe.h
> @@ -0,0 +1,145 @@
> +/*
> + * Helpers to get fixed-size audio frames
> + * Copyright (c) 2012 Nicolas George
> + *
> + * 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
> + */
> +
> +#ifndef AVFILTER_AUDIOFRAME_H
> +#define AVFILTER_AUDIOFRAME_H
> +
> +#include "avfilter.h"
> +#include "audio.h"
> +
> +/**
> + * This file implements helpers for filters that require a fixed amount of
> + * samples as their input.
> + *
> + * Here is the basic template to use it:
> + *
> + * Declare somewhere, probably in the private context of the filter:
> + * AVFilterBufferRef *partial_buf = NULL;
> + *
> + * In filter_samples(inlink, insamples), do:
> + *
> + * int insamples_pos = 0;
> + * while (!ff_audioframe_feed(frame_size, inlink, NULL, AV_PERM_READ,
> + *                            insamples, &priv->partial_buf, &insamples_pos)) {
> + *     do_something_with(priv->partial_buf);
> + *     priv->partial_buf = NULL; (or avfilter_unref_bufferp)
> + * }
> + * avfilter_unref_buffer(insamples);
> + *
> + * As a reaction to a call to request_frame() on the input:
> + *
> + * if (ret == AVERROR_EOF && priv->partial_buf) {
> + *     ff_audioframe_pad(frame_size, inlink, priv->partial_buf);
> + *     do_something_with(priv->partial_buf);
> + *     priv->partial_buf = NULL; (or avfilter_unref_bufferp)
> + *     return 0;
> + * }
> + *
> + * In uninit():
> + *
> + * avfilter_unref_bufferp(&priv->partial_buf);
> + */

I think a min and max buffer size set in the AVFilterLink would be
simpler and would allow the source filter to generate the wanted amount
directly when it is capable to do so. Avoiding a memcpy

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

It is what and why we do it that matters, not just one of them.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120629/715d77a1/attachment.asc>


More information about the ffmpeg-devel mailing list