[FFmpeg-devel] [PATCH 2/4] avfilter/avfilter: Add numbers of (in|out)pads directly to AVFilter

Nicolas George george at nsup.org
Sat Aug 14 12:12:24 EEST 2021


Andreas Rheinhardt (12021-08-12):
> Up until now, an AVFilter's lists of input and output AVFilterPads
> were terminated by a sentinel and the only way for the user to get
> the length of these lists was by using avfilter_pad_count(). This
> has two drawbacks: first, sizeof(AVFilterPad) is not negligible
> (i.e. 64B on 64bit systems); second, getting the size involves
> a function call instead of just reading the data.
> 
> This commit therefore changes this. The sentinels are removed and new
> fields nb_inputs and nb_outputs are added to AVFilter that contain the
> number of elements of the respective AVFilterPad array.
> Given that AVFilter.(in|out)puts are the only arrays of zero-terminated
> AVFilterPads an API user has access to (AVFilterContext.(in|out)put_pads
> are not zero-terminated and they already have a size field) the argument
> to avfilter_pad_count() is always one of these lists, so it just has to
> find the filter the list belongs to and read said number. This is slower
> than before, but users are expected to switch to AVFilter.nb_(in|out)puts;
> and furthermore, avfilter_pad_count() is probably never called in hot
> loops anyway.
> 
> This saves about 49KiB from the binary; notice that these sentinels are
> not in .bss despite being zeroed; in fact, they are in .data.rel.ro
> due to the non-sentinels.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

I think it is a good change.

We could shave ~3.5k extra by making the fields uint16_t; lavfi is
absolutely not ready to handle filters with thousands of inputs, there
are loops everywhere.

OTOH, I do not like the fact that it requires more boilerplate code.

> @@ -330,6 +329,7 @@ const AVFilter ff_asrc_aevalsrc = {
>      .priv_size     = sizeof(EvalContext),
>      .inputs        = NULL,
>      .outputs       = aevalsrc_outputs,
> +    .nb_outputs    = FF_ARRAY_ELEMS(aevalsrc_outputs),
>      .priv_class    = &aevalsrc_class,
>  };

A macro would solve that:

#define FILTER_INPUTS(array) \
    .inputs = (array),
    .nb_inputs = FF_ARRAY_ELEMS(array)

Also, I am rather not for using these fields directly. Keeping them
private and leaving avfilter_pad_count() gives us more freedom,
including the freedom to change the type from uint16_t to unsigned later
without break.

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20210814/1c60afe5/attachment.sig>


More information about the ffmpeg-devel mailing list