Commit Graph

40 Commits

Author SHA1 Message Date
Andreas Rheinhardt
b4f5201967 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>
2021-10-05 17:48:25 +02:00
Andreas Rheinhardt
8be701d9f7 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.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-20 12:53:58 +02:00
Andreas Rheinhardt
1b20853fb3 avfilter/internal: Factor out executing a filter's execute_func
The current way of doing it involves writing the ctx parameter twice.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-15 21:33:25 +02:00
Andreas Rheinhardt
a04ad248a0 avfilter: Constify all AVFilters
This is possible now that the next-API is gone.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 11:48:05 -03:00
Anton Khirnov
e15371061d lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bump
They are not properly namespaced and not intended for public use.
2021-01-01 14:14:57 +01:00
Andrew Klaassen
a6e72fb46d vf_colorspace: Added linear trc.
This patch adds the coefficients for the linear gamma function (1,0,1,0)
to the colorspace filter.

Signed-off-by: Andrew Klaassen <clawsoon@yahoo.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2020-09-27 09:14:46 -04:00
Nicolas George
2f76476549 lavfi: regroup formats lists in a single structure.
It will allow to refernce it as a whole without clunky macros.

Most of the changes have been automatically made with sed:

sed -i '
  s/-> *in_formats/->incfg.formats/g;
  s/-> *out_formats/->outcfg.formats/g;
  s/-> *in_channel_layouts/->incfg.channel_layouts/g;
  s/-> *out_channel_layouts/->outcfg.channel_layouts/g;
  s/-> *in_samplerates/->incfg.samplerates/g;
  s/-> *out_samplerates/->outcfg.samplerates/g;
  ' src/libavfilter/*(.)
2020-09-08 14:02:40 +02:00
Paul B Mahol
fddef964e8 avfilter/vf_colorspace: fix memmory leaks
Fixes #8303
2019-10-18 10:48:22 +02:00
Jun Zhao
88a9998fe8 lavfi/colorspace: typedef ThreadData as all other filters
typedef ThreadData as all other filters.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-10-10 09:00:15 +08:00
Paul B Mahol
22f3b6286e avfilter: add av_cold where it is missing 2019-10-03 12:09:07 +02:00
Raphaël Zumer
08dfd57fd8 avfilter: Support EBU Tech. 3213-E primaries values
Signed-off-by: Raphaël Zumer <rzumer@tebako.net>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-09-01 20:00:53 -03:00
Yonglin Luo
664a27ea40 libavfilter/vf_colorspace.c: fix demarcation point of gamma linearize function
The linearize function (usually refered to EOTF) is the inverse of
delinearize function (usually referred to OETF). Demarcation point of
EOTF should be beta*delta, but the actual value used now in the source
code is beta.

For ITU Rec.709, they are 0.081 (0.018*4.5) and 0.018 respectively
(beta = 0.018 and delta = 4.5), and they correspond to pixel value 5
and 21 for an 8-bit image. Linearized result of pixel within that range
(5-21) will be different, but this commit will make linearize function
of the filter more accurate in the mathematical sense.

Signed-off-by: Yonglin Luo <vincenluo@tencent.com>
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2019-07-03 13:57:11 -04:00
Ruiling Song
d0f3798b4e lavfi/colorspace: move some functions to common file
These functions can be reused by other colorspace filters,
so move them to common file. No functional changes.

Signed-off-by: Ruiling Song <ruiling.song@intel.com>
2019-03-22 09:33:28 +08:00
Paul B Mahol
b0cfb2cfb9 avfilter/vf_colorspace: fix typo in comment 2018-09-17 12:51:59 +02:00
Mark Thompson
46fb150a81 lavfi/colorspace: Add namespace prefix to global functions 2018-06-28 16:14:35 +01:00
Ruiling Song
649d7ca477 lavfi: make vf_colorspace use functions from colorspace.c
These functions are shared among colorspace related filters.

Signed-off-by: Ruiling Song <ruiling.song@intel.com>
2018-06-21 01:19:25 +01:00
Vittorio Giovara
c12e8f5f0b vf_colorspace: Add a pixdesc API alias name for bt2020nc color space 2017-06-09 10:44:11 -04:00
Vittorio Giovara
f7f60749e0 vf_colorspace: Add support for jedec p22 primaries
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2017-06-07 23:39:31 -04:00
Vittorio Giovara
35c76f2e13 vf_colorspace: Add support for smpte248 color primaries 2017-06-07 22:56:11 -04:00
Vittorio Giovara
d9909b11d9 vf_colorspace: Add support for gbr color space
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2017-06-06 11:22:52 -04:00
Vittorio Giovara
afb84857bf vf_colorspace: Forbid odd dimensions
This prevents writing past bounds.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2016-11-28 11:24:09 -05:00
Vittorio Giovara
6f2ad32a16 vf_colorspace: Add support for film primaries
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2016-11-01 17:47:25 -04:00
Vittorio Giovara
4697f60444 vf_colorspace: Add support for smpte 431/432 (dci/display p3) primaries
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2016-11-01 17:47:25 -04:00
Vittorio Giovara
2996604acd vf_colorspace: Add support for ycgco color space
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2016-11-01 17:47:25 -04:00
Vittorio Giovara
5a123f1424 vf_colorspace: Add support for iec61966-2.4 (xvYCC) transfer
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Reviewed-by: "Ronald S. Bultje" <rsbultje@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-10-31 21:02:12 +01:00
Vittorio Giovara
ba53d3ae8b vf_colorspace: Add support for iec61966-2.1 (sRGB) transfer
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2016-10-24 16:07:44 -04:00
Ronald S. Bultje
f141ac4d0b vf_colorspace: don't spam console with warnings if range is unspecified. 2016-10-24 16:03:16 -04:00
James Almer
e4bfc9ecf7 avfilter/vf_colorspace: fix range for output colorspace option
Rreviewed-by: BBB
Signed-off-by: James Almer <jamrial@gmail.com>
2016-09-28 17:33:38 -03:00
Vittorio Giovara
cb78d14cf9 vf_colorspace: Interpret unspecified color range as limited range
This is the assumption that is made in pixel format conversion do
throughout the code (in particular swscale), and BT-specifications
mandate.

Add a warning to inform the user that an automatic selection is being
made.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2016-09-19 08:26:49 -04:00
Vittorio Giovara
76c28360b5 vf_colorspace: Add modern names for color range option
Allows to use values returned from API and from ffprobe directly.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2016-09-14 17:24:22 -04:00
Vittorio Giovara
d41bfa9c0b vf_colorspace: Add BT-names for gamma22/28 transfer option
Allows to use values returned from API and from ffprobe directly.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2016-09-13 10:22:23 -04:00
Vittorio Giovara
5df993f3b1 vf_colorspace: Allow overriding input color properties
The filter needs input frames with color properties filled out by
the decoder. Since this is not always possible, add input options to
the filter so that user may override color space, color primaries,
transfer characteristics, and color range, as well as a generic option
to set all properties at once.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2016-09-04 13:11:32 +02:00
Paul B Mahol
a0a57072c9 avfilter: make use of ff_filter_get_nb_threads 2016-08-29 16:27:09 +02:00
Vittorio Giovara
69abf4f93c vf_colorspace: Add support for full range yuv
Whenever a full range video is input, since the YUVJ* formats are not
listed as supported for this filter, a range reduction takes place
through the auto-inserted format filter, forcing the conversion to
operate on a limited range,

However the filter handles full range videos perfectly fine, so adding
support to YUVJ* formats will allow skipping a conversion step, while
providing completely identical results.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Reviewed-by: "Ronald S. Bultje" <rsbultje@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-08-27 13:08:43 +02:00
Vittorio Giovara
6648da3591 vf_colorspace: Check av_frame_copy_props() return value
This function can potentially allocate memory.

Reviewed-by: "Ronald S. Bultje" <rsbultje@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-08-27 13:08:43 +02:00
Ronald S. Bultje
531ff7161d vf_colorspace: don't enable passthrough if bitdepth doesn't match.
Also check return value of av_frame_copy() in passthrough mode, so that
if a copy fails (as it did here, because bitdepth didn't match), the filter
doesn't return success, which would mean sending an uninitialized framebuffer
further down the filtergraph.
2016-05-10 09:26:17 -04:00
Ronald S. Bultje
356c116536 vf_colorspace: fix range order. 2016-05-10 09:26:17 -04:00
Ronald S. Bultje
9bbed8645a vf_colorspace: make whitepoint adaptation mode configurable.
Also add von kries whitepoint adaptation, and add 'identity' to turn
whitepoint adaptation off.
2016-05-10 09:26:16 -04:00
Ronald S. Bultje
431117dcb5 vf_colorspace: add floyd-steinberg dithering option to full conversion. 2016-05-10 08:37:55 -04:00
Ronald S. Bultje
2e2e08a35b lavfi: new colorspace conversion filter.
The intent here is similar to colormatrix, but it's LGPLv2.1-or-later
(instead of GPLv2.0) and supports gamma/chromaticity correction.
2016-04-12 16:42:45 -04:00