Up until now, an AVFilter's lists of input and output AVFilterPads were terminated by a sentinel and the only way 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 private 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 a replacement function that just reads the internal numbers that users are expected to switch to will be added soon; 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: they are in .data.rel.ro due to the non-sentinels.
Showing the changes to libavfilter/f_loop.c (1 of 389 files). Show all
Unified · Split
| @@ -269,7 +269,6 @@ static const AVFilterPad ainputs[] = { · 268 unmodified lines | ||
| 269 | 269 | .type = AVMEDIA_TYPE_AUDIO, |
| 270 | 270 | .config_props = aconfig_input, |
| 271 | 271 | }, |
| 272 | − { NULL } | |
| 273 | 272 | }; |
| 274 | 273 | |
| 275 | 274 | static const AVFilterPad aoutputs[] = { |
| @@ -277,7 +276,6 @@ static const AVFilterPad aoutputs[] = { · 1 unmodified line | ||
| 277 | 276 | .name = "default", |
| 278 | 277 | .type = AVMEDIA_TYPE_AUDIO, |
| 279 | 278 | }, |
| 280 | − { NULL } | |
| 281 | 279 | }; |
| 282 | 280 | |
| 283 | 281 | const AVFilter ff_af_aloop = { |
| @@ -287,8 +285,8 @@ const AVFilter ff_af_aloop = { · 3 unmodified lines | ||
| 287 | 285 | .priv_class = &aloop_class, |
| 288 | 286 | .activate = aactivate, |
| 289 | 287 | .uninit = auninit, |
| 290 | − .inputs = ainputs, | |
| 291 | − .outputs = aoutputs, | |
| 288 | + FILTER_INPUTS(ainputs), | |
| 289 | + FILTER_OUTPUTS(aoutputs), | |
| 292 | 290 | }; |
| 293 | 291 | #endif /* CONFIG_ALOOP_FILTER */ |
| 294 | 292 | |
| @@ -442,7 +440,6 @@ static const AVFilterPad inputs[] = { · 147 unmodified lines | ||
| 442 | 440 | .name = "default", |
| 443 | 441 | .type = AVMEDIA_TYPE_VIDEO, |
| 444 | 442 | }, |
| 445 | − { NULL } | |
| 446 | 443 | }; |
| 447 | 444 | |
| 448 | 445 | static const AVFilterPad outputs[] = { |
| @@ -450,7 +447,6 @@ static const AVFilterPad outputs[] = { · 1 unmodified line | ||
| 450 | 447 | .name = "default", |
| 451 | 448 | .type = AVMEDIA_TYPE_VIDEO, |
| 452 | 449 | }, |
| 453 | − { NULL } | |
| 454 | 450 | }; |
| 455 | 451 | |
| 456 | 452 | const AVFilter ff_vf_loop = { |
| @@ -461,7 +457,7 @@ const AVFilter ff_vf_loop = { · 4 unmodified lines | ||
| 461 | 457 | .init = init, |
| 462 | 458 | .uninit = uninit, |
| 463 | 459 | .activate = activate, |
| 464 | − .inputs = inputs, | |
| 465 | − .outputs = outputs, | |
| 460 | + FILTER_INPUTS(inputs), | |
| 461 | + FILTER_OUTPUTS(outputs), | |
| 466 | 462 | }; |
| 467 | 463 | #endif /* CONFIG_LOOP_FILTER */ |