diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-09-27 12:07:35 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2021-10-05 17:48:25 +0200 |
commit | b4f52019675159f303df05490ac5cf9972e279b2 (patch) | |
tree | e8125a953d13a25a9cba981ff76474cd3bfde1e4 /libavfilter/vsrc_testsrc.c | |
parent | aa6360928efee8c3193b1862bb520fc66cb3ef1f (diff) | |
download | ffmpeg-b4f52019675159f303df05490ac5cf9972e279b2.tar.gz |
avfilter: Replace query_formats callback with union of list and callback
If one looks at the many query_formats callbacks in existence,
one will immediately recognize that there is one type of default
callback for video and a slightly different default callback for
audio: It is "return ff_set_common_formats_from_list(ctx, pix_fmts);"
for video with a filter-specific pix_fmts list. For audio, it is
the same with a filter-specific sample_fmts list together with
ff_set_common_all_samplerates() and ff_set_common_all_channel_counts().
This commit allows to remove the boilerplate query_formats callbacks
by replacing said callback with a union consisting the old callback
and pointers for pixel and sample format arrays. For the not uncommon
case in which these lists only contain a single entry (besides the
sentinel) enum AVPixelFormat and enum AVSampleFormat fields are also
added to the union to store them directly in the AVFilter,
thereby avoiding a relocation.
The state of said union will be contained in a new, dedicated AVFilter
field (the nb_inputs and nb_outputs fields have been shrunk to uint8_t
in order to create a hole for this new field; this is no problem, as
the maximum of all the nb_inputs is four; for nb_outputs it is only
two).
The state's default value coincides with the earlier default of
query_formats being unset, namely that the filter accepts all formats
(and also sample rates and channel counts/layouts for audio)
provided that these properties agree coincide for all inputs and
outputs.
By using different union members for audio and video filters
the type-unsafety of using the same functions for audio and video
lists will furthermore be more confined to formats.c than before.
When the new fields are used, they will also avoid allocations:
Currently something nearly equivalent to ff_default_query_formats()
is called after every successful call to a query_formats callback;
yet in the common case that the newly allocated AVFilterFormats
are not used at all (namely if there are no free links) these newly
allocated AVFilterFormats are freed again without ever being used.
Filters no longer using the callback will not exhibit this any more.
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavfilter/vsrc_testsrc.c')
-rw-r--r-- | libavfilter/vsrc_testsrc.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index 414950c442..72d3fd4456 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -273,9 +273,9 @@ const AVFilter ff_vsrc_color = { .init = color_init, .uninit = uninit, .activate = activate, - .query_formats = color_query_formats, .inputs = NULL, FILTER_OUTPUTS(color_outputs), + FILTER_QUERY_FUNC(color_query_formats), .process_command = color_process_command, }; @@ -402,10 +402,10 @@ const AVFilter ff_vsrc_haldclutsrc = { .priv_size = sizeof(TestSourceContext), .init = haldclutsrc_init, .uninit = uninit, - .query_formats = haldclutsrc_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(haldclutsrc_outputs), + FILTER_QUERY_FUNC(haldclutsrc_query_formats), }; #endif /* CONFIG_HALDCLUTSRC_FILTER */ @@ -670,10 +670,10 @@ const AVFilter ff_vsrc_testsrc = { .priv_class = &testsrc_class, .init = test_init, .uninit = uninit, - .query_formats = test_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(avfilter_vsrc_testsrc_outputs), + FILTER_QUERY_FUNC(test_query_formats), }; #endif /* CONFIG_TESTSRC_FILTER */ @@ -942,10 +942,10 @@ const AVFilter ff_vsrc_testsrc2 = { .priv_class = &testsrc2_class, .init = test2_init, .uninit = uninit, - .query_formats = test2_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(avfilter_vsrc_testsrc2_outputs), + FILTER_QUERY_FUNC(test2_query_formats), }; #endif /* CONFIG_TESTSRC2_FILTER */ @@ -1113,10 +1113,10 @@ const AVFilter ff_vsrc_rgbtestsrc = { .priv_class = &rgbtestsrc_class, .init = rgbtest_init, .uninit = uninit, - .query_formats = rgbtest_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(avfilter_vsrc_rgbtestsrc_outputs), + FILTER_QUERY_FUNC(rgbtest_query_formats), }; #endif /* CONFIG_RGBTESTSRC_FILTER */ @@ -1282,10 +1282,10 @@ const AVFilter ff_vsrc_yuvtestsrc = { .priv_class = &nullsrc_yuvtestsrc_class, .init = yuvtest_init, .uninit = uninit, - .query_formats = yuvtest_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(avfilter_vsrc_yuvtestsrc_outputs), + FILTER_QUERY_FUNC(yuvtest_query_formats), }; #endif /* CONFIG_YUVTESTSRC_FILTER */ @@ -1454,10 +1454,10 @@ const AVFilter ff_vsrc_pal75bars = { .priv_size = sizeof(TestSourceContext), .init = pal75bars_init, .uninit = uninit, - .query_formats = smptebars_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(smptebars_outputs), + FILTER_QUERY_FUNC(smptebars_query_formats), }; #endif /* CONFIG_PAL75BARS_FILTER */ @@ -1498,10 +1498,10 @@ const AVFilter ff_vsrc_pal100bars = { .priv_size = sizeof(TestSourceContext), .init = pal100bars_init, .uninit = uninit, - .query_formats = smptebars_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(smptebars_outputs), + FILTER_QUERY_FUNC(smptebars_query_formats), }; #endif /* CONFIG_PAL100BARS_FILTER */ @@ -1565,10 +1565,10 @@ const AVFilter ff_vsrc_smptebars = { .priv_class = &smptebars_class, .init = smptebars_init, .uninit = uninit, - .query_formats = smptebars_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(smptebars_outputs), + FILTER_QUERY_FUNC(smptebars_query_formats), }; #endif /* CONFIG_SMPTEBARS_FILTER */ @@ -1668,10 +1668,10 @@ const AVFilter ff_vsrc_smptehdbars = { .priv_size = sizeof(TestSourceContext), .init = smptehdbars_init, .uninit = uninit, - .query_formats = smptebars_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(smptebars_outputs), + FILTER_QUERY_FUNC(smptebars_query_formats), }; #endif /* CONFIG_SMPTEHDBARS_FILTER */ @@ -1742,10 +1742,10 @@ const AVFilter ff_vsrc_allyuv = { .priv_class = &allyuv_allrgb_class, .init = allyuv_init, .uninit = uninit, - .query_formats = allyuv_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(avfilter_vsrc_allyuv_outputs), + FILTER_QUERY_FUNC(allyuv_query_formats), }; #endif /* CONFIG_ALLYUV_FILTER */ @@ -1812,10 +1812,10 @@ const AVFilter ff_vsrc_allrgb = { .priv_class = &allyuv_allrgb_class, .init = allrgb_init, .uninit = uninit, - .query_formats = allrgb_query_formats, .activate = activate, .inputs = NULL, FILTER_OUTPUTS(avfilter_vsrc_allrgb_outputs), + FILTER_QUERY_FUNC(allrgb_query_formats), }; #endif /* CONFIG_ALLRGB_FILTER */ |