Commit Graph

19 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 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
nyanmisaka 0c5098d1a2 avfilter/hwupload_cuda: add YUVA420P format support
Signed-off-by: nyanmisaka <nst799610810@gmail.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2021-03-25 04:30:50 +01: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
Philip Langdale 88d2ccbe93 lavfi/vf_hwupload: Add support for HW -> HW transfers
As we find ourselves wanting a way to transfer frames between
HW devices (or more realistically, between APIs on the same device),
it's desirable to have a way to describe the relationship. While
we could imagine introducing a `hwtransfer` filter, there is
almost no difference from `hwupload`. The main new feature we need
is a way to specify the target device. Having a single device
for the filter chain is obviously insufficient if we're dealing
with two devices.

So let's add a way to specify the upload target device, and if none
is specified, continue with the existing behaviour.

We must also correctly preserve the sw_format on such a transfer.
2020-02-04 23:19:48 +00:00
Timo Rothenpieler 1c15d26615 avfilter/vf_hwupload_cuda: update supported pix_fmts 2018-05-10 00:34:22 +02:00
Yogender Gupta 2e8679373a hwupload_cuda : Add 10/16 bit format support
Signed-off-by: Philip Langdale <philipl@overt.org>
2017-08-03 15:25:35 -07:00
Matthieu Bouron b5e1ec5660 Merge commit 'e3fb74f7f9a8f1895381355f40c92cac3c1023d9'
* commit 'e3fb74f7f9a8f1895381355f40c92cac3c1023d9':
  lavfi: Always propagate hw_frames_ctx through links

Merged-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2017-03-30 00:02:08 +02:00
Matthieu Bouron 78e871ebbc Merge commit '7e2561fa8313982aa21f7657953eedeeb33b210d'
* commit '7e2561fa8313982aa21f7657953eedeeb33b210d':
  lavfi: Use ff_get_video_buffer in all filters using hwframes
  vf_hwupload_cuda: Fix build error

Merged-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2017-03-29 23:33:20 +02:00
Srinath K R 4df5a6a26a avfilter/vf_hwupload_cuda: Add min/max limits for the 'device' option
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2016-12-08 11:11:26 +01:00
Timo Rothenpieler 7dafb3a25a avfilter/vf_hwupload_cuda: fix potential leak 2016-11-30 12:36:23 +01:00
Timo Rothenpieler 0faf3c3a25 avfilter/vf_hwupload_cuda: check ff_formats_ref for errors 2016-11-22 10:34:27 +01:00
Timo Rothenpieler b0ca90d7cb avfilter/vf_hwupload_cuda: use new hwdevice allocation API 2016-11-22 10:34:27 +01:00
Mark Thompson e3fb74f7f9 lavfi: Always propagate hw_frames_ctx through links
Also adds a new flag to mark filters which are aware of hwframes and
will perform this task themselves, and marks all appropriate filters
with this flag.

This is required to allow software-mapped hardware frames to work,
because we need to have the frames context available for any later
mapping operation in the filter graph.

The output from the filter graph should only propagate further to an
encoder if the hardware format actually matches the visible format
(mapped frames are valid here and have an hw_frames_ctx, but this
should not be given to the encoder as its hardware context).
2016-11-02 20:29:05 +00:00
Mark Thompson 7e2561fa83 lavfi: Use ff_get_video_buffer in all filters using hwframes 2016-11-02 20:07:15 +00:00
Matt Oliver 7ecef5ed51 avfilter/hwupload_cuda: Add missing semicolon.
Signed-off-by: Matt Oliver <protogonoi@gmail.com>
2016-02-25 15:52:01 +11:00
Derek Buitenhuis ef9915a0e2 Merge commit '21f7cd4acd8dc4b4796b55966dd015cb037164d8'
* commit '21f7cd4acd8dc4b4796b55966dd015cb037164d8':
  lavfi: add a filter for uploading normal frames to CUDA

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-02-24 17:02:48 +00:00
Anton Khirnov 21f7cd4acd lavfi: add a filter for uploading normal frames to CUDA 2016-02-14 22:25:38 +01:00