[FFmpeg-devel] [PATCH 3/5] lavfi: add asrc_abuffer - audio source buffer filter

Stefano Sabatini stefano.sabatini-lala at poste.it
Mon Aug 8 17:18:52 CEST 2011


On date Monday 2011-08-08 11:11:47 +0300, Mina Nagy Zaki encoded:
> Originally based on code by Stefano Sabatini and S. N. Hemanth
> ---
>  doc/filters.texi           |   44 ++++++
>  libavfilter/Makefile       |    2 +
>  libavfilter/allfilters.c   |    1 +
>  libavfilter/asrc_abuffer.c |  368 ++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/asrc_abuffer.h |   81 ++++++++++
>  5 files changed, 496 insertions(+), 0 deletions(-)
>  create mode 100644 libavfilter/asrc_abuffer.c
>  create mode 100644 libavfilter/asrc_abuffer.h
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 8dc1c15..53017b2 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
[...]
> +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
> +{
> +    ABufferSourceContext *abuffer = ctx->priv;
> +    char *arg, chlayout_str[16];
> +
> +    arg = strsep(&args, ":");
> +    if (!arg) goto arg_fail;
> +    abuffer->sample_rate = ff_parse_sample_rate(arg, ctx);
> +    if (abuffer->sample_rate == -1) return AVERROR(EINVAL);
> +
> +    arg = strsep(&args, ":");
> +    if (!arg) goto arg_fail;
> +    abuffer->sample_fmt = ff_parse_sample_format(arg, ctx);
> +    if (abuffer->sample_fmt == -1) return AVERROR(EINVAL);
> +
> +    arg = strsep(&args, ":");
> +    if (!arg) goto arg_fail;
> +    abuffer->channel_layout = ff_parse_channel_layout(arg, ctx);
> +    if (abuffer->channel_layout == -1) return AVERROR(EINVAL);
> +
> +    arg = strsep(&args, ":");
> +    if (!arg) goto arg_fail;
> +    abuffer->planar = ff_parse_packing_format(arg, ctx);
> +    if (abuffer->planar == -1) return AVERROR(EINVAL);

as already told in another mail, returning -1 is ugly, just return
AVERROR(EINVAL) and check on <0.
Alternatively:
int ff_parse_sample_rate(int &sample_rate, arg, log_ctx);

i.e.: you return an error code and put the resulting thing in the
passed pointer (easier in case you don't have to return an int,
e.g. if you return an unsigned, more generic).

[...]

Sounds fine otherwise, I assume it has been tested with
mid-stream-format-changing streams.
-- 
FFmpeg = Fiendish & Fabulous Merciful Powered Elected Genius


More information about the ffmpeg-devel mailing list