History

avfilter/avfilter: Add numbers of (in|out)pads directly to AVFilter

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.

Andreas Rheinhardt committed 5 years ago

Commit 8be701d1 parent d53d48c389 files · +906 −1696Browse files

Showing the changes to libavfilter/f_loop.c (1 of 389 files). Show all

Unified · Split

libavfilter/f_loop.c+4−8
@@ -269,7 +269,6 @@ static const AVFilterPad ainputs[] = { · 268 unmodified lines
269269 .type = AVMEDIA_TYPE_AUDIO,
270270 .config_props = aconfig_input,
271271 },
272− { NULL }
273272 };
274273
275274 static const AVFilterPad aoutputs[] = {
@@ -277,7 +276,6 @@ static const AVFilterPad aoutputs[] = { · 1 unmodified line
277276 .name = "default",
278277 .type = AVMEDIA_TYPE_AUDIO,
279278 },
280− { NULL }
281279 };
282280
283281 const AVFilter ff_af_aloop = {
@@ -287,8 +285,8 @@ const AVFilter ff_af_aloop = { · 3 unmodified lines
287285 .priv_class = &aloop_class,
288286 .activate = aactivate,
289287 .uninit = auninit,
290− .inputs = ainputs,
291− .outputs = aoutputs,
288+ FILTER_INPUTS(ainputs),
289+ FILTER_OUTPUTS(aoutputs),
292290 };
293291 #endif /* CONFIG_ALOOP_FILTER */
294292
@@ -442,7 +440,6 @@ static const AVFilterPad inputs[] = { · 147 unmodified lines
442440 .name = "default",
443441 .type = AVMEDIA_TYPE_VIDEO,
444442 },
445− { NULL }
446443 };
447444
448445 static const AVFilterPad outputs[] = {
@@ -450,7 +447,6 @@ static const AVFilterPad outputs[] = { · 1 unmodified line
450447 .name = "default",
451448 .type = AVMEDIA_TYPE_VIDEO,
452449 },
453− { NULL }
454450 };
455451
456452 const AVFilter ff_vf_loop = {
@@ -461,7 +457,7 @@ const AVFilter ff_vf_loop = { · 4 unmodified lines
461457 .init = init,
462458 .uninit = uninit,
463459 .activate = activate,
464− .inputs = inputs,
465− .outputs = outputs,
460+ FILTER_INPUTS(inputs),
461+ FILTER_OUTPUTS(outputs),
466462 };
467463 #endif /* CONFIG_LOOP_FILTER */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t