Commit Graph

172 Commits

Author SHA1 Message Date
Paul B Mahol
e1b820fa33 avfilter/vf_overlay: unbreak alpha composition with negative y and threads > 1 2021-10-14 20:05:39 +02:00
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
18ec426a86 avfilter/formats: Factor common function combinations out
Several combinations of functions happen quite often in query_format
functions; e.g. ff_set_common_formats(ctx, ff_make_format_list(sample_fmts))
is very common. This commit therefore adds functions that are equivalent
to commonly used function combinations in order to reduce code
duplication.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-08-13 17:36:22 +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
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
Andreas Rheinhardt
a86ee5fd79 avfilter/vf_overlay: Fix double-free of AVFilterFormats on error
The query_formats function of the overlay filter tries to allocate
two lists (only one in a special case) of formats which on success
are attached to more permanent objects (AVFilterLinks) for storage
afterwards. If attaching a list to an AVFilterLink succeeds, it is
in turn owned by the AVFilterLink (or more exactly, the AVFilterLink
becomes one of the common owners of the list). Yet if attaching a list
to one of its links succeeds and an error happens lateron, both lists
were manually freed, whic is wrong if the list is already owned by one
or more links; these links' pointers to their lists will become dangling
and there will be a double-free/use-after-free when these links are
cleaned up automatically.

This commit fixes this by removing the custom freeing code; this will
temporarily add a leaking codepath (if attaching a list not already
owned by a link to a link fails, the list will leak), but this will
be fixed soon by making sure that an AVFilterFormats without owner will
be automatically freed when attaching it to an AVFilterLink fails.
Notice that at most one list leaks because a new list is only allocated
after the old list has been successfully attached to a link.

Reviewed-by: Nicolas George <george@nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-23 23:29:58 +02:00
Andreas Rheinhardt
c5e204c84f avfilter/vf_overlay: Remove superfluous ;
In a function body, a redundant ; is just a null statement that does
nothing. Yet outside a function body, a superfluous ';' like one that
exists if one adds a ';' immediately after a function body's closing
brace is actually invalid C that compilers happen to accept. Yet when
compiled in -pedantic mode, both GCC as well as Clang emit warnings for
this like "ISO C does not allow extra ‘;’ outside of a function
[-Wpedantic]".

The scenario described above existed in vf_overlay.c as a result of
macro expansion. This commit fixes it.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-21 13:52:44 +02:00
Limin Wang
dacae40a4b avfilter/vf_overlay: add yuv420p10 and yuv422p10 10bit format support
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-19 07:14:46 +08:00
Limin Wang
4d787c16e8 avfilter/vf_overlay: support for 8bit and 10bit overlay with macro-based function
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-06-19 07:14:46 +08:00
Paul B Mahol
d64cbd4fda remove CHAR_MIN/CHAR_MAX usage
It is not needed at all.
2020-03-17 22:46:36 +01:00
Paul B Mahol
8440835dbe avfilter/vf_overlay: fix filtering with negative y 2018-12-03 10:32:59 +01:00
Paul B Mahol
57815cfad5 avfilter/vf_overlay: fix crash with negative y 2018-11-20 23:18:47 +01:00
Paul B Mahol
0f0d468fbc avfilter/vf_overlay: exclude nv12/nv21 formats from x86 asm check
They are yet to be supported,

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-05-03 09:22:28 +02:00
Paul B Mahol
6d7c63588c avfilter/vf_overlay: add x86 SIMD
Specifically for yuv444, yuv422, yuv420 format when main stream has no alpha, and alpha
is straight.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-05-02 23:58:21 +02:00
Paul B Mahol
70d25b89db avfilter/vf_overlay: use slice_end in alpha_composite()
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-29 10:02:57 +02:00
Paul B Mahol
d54014d157 avfilter/vf_overlay: add slice threading
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-28 18:54:12 +02:00
Steven Liu
27fe8930e0 avfilter: add comments for duplicate line
comment about the looks like a duplicate line.
but that is used to reason x is expressed from y

Suggested-by: Paul B Mahol
Suggested-by: Michael Niedermayer
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2018-02-01 10:55:19 +08:00
Mateusz
6260ab60a8 avfilter/vf_overlay: fix packed_rgb case
Signed-off-by: Mateusz Brzostek <mateuszb@poczta.onet.pl>
2017-12-18 14:48:37 +01:00
Paul B Mahol
d29f784a54 avfilter/vf_overlay: add premultiplied alpha mode
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-12-16 18:40:04 +01:00
Nicolas George
5f5dcf44e3 lavfi: rename framesync2 to framesync. 2017-09-12 11:03:51 +02:00
Michael Niedermayer
d8bc198d09 avfilter/vf_overlay: Restore shorthand option order
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2017-09-05 23:55:19 +02:00
Nicolas George
878fd0545a lavfi/vf_overlay: use framesync2 options. 2017-08-29 10:19:04 +02:00
Nicolas George
19804024d5 lavfi/vf_overlay: move to framesync2. 2017-08-29 10:19:04 +02:00
Marton Balint
498c90c708 avfilter/vf_overlay: fix alpha blending for planar formats with a transparent background
When the background had an alpha channel, the old code in blend_plane
calculated premultiplied alpha from the destination plane colors instead of the
destination alpha.

Also the calculation of the output alpha should only happen after the color
planes are already finished.

Fixes output of:
ffplay -f lavfi "testsrc2=alpha=32[a];color=black[b];[b][a]overlay[out0]"

Signed-off-by: Marton Balint <cus@passwd.hu>
2017-08-10 22:25:51 +02:00
Paul B Mahol
f269a1e0b8 avfilter/vf_overlay: separate functions with main alpha
~5-15% faster overall with main input without alpha.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-06-25 12:32:53 +02:00
Paul B Mahol
c1b43e8452 avfilter/vf_overlay: remove rgb option
Its been deprecated for over 3 years.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-06-24 19:20:46 +02:00
Paul B Mahol
565dc0e283 avfilter/vf_overlay: add auto format mode
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-06-24 10:18:30 +02:00
Muhammad Faiz
6af050d7d0 avfilter: do not use AVFrame accessor
Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
2017-04-23 14:40:30 +07:00
Paul B Mahol
3405d6c7bc avfilter/overlay: add gbrp output format
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-01-31 10:54:03 +01:00
Nicolas George
183ce55b0d lavfi: split frame_count between input and output.
AVFilterLink.frame_count is supposed to count the number of frames
that were passed on the link, but with min_samples, that number is
not always the same for the source and destination filters.
With the addition of a FIFO on the link, the difference will become
more significant.

Split the variable in two: frame_count_in counts the number of
frames that entered the link, frame_count_out counts the number
of frames that were sent to the destination filter.
2016-11-13 10:41:16 +01:00
Rodger Combs
f53c26c694
lavfi/vf_overlay: support NV12 and NV21
Tested-by: Michael on x86-32/64 linux, mingw, mips/arm qemu linux
2016-10-26 20:13:30 -05:00
Paul B Mahol
97f50d1c62 avfilter/vf_overlay: add YUVA422P to alpha_pix_fmts
Now yuv422 output format gives similar expected output as other output formats.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2016-09-17 15:38:30 +02:00
Paul B Mahol
0e7d2c60e9 avfilter/vf_overlay: support J formats too
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2016-09-17 15:38:30 +02:00
Paul B Mahol
97297fb144 avfilter/vf_overlay: inline yuv output formats
Overall speedup ~10-20%

Tested-by: Michael on mingw32 mingw64 linux32 mips and arm
2016-09-11 00:38:13 +02:00
Paul B Mahol
140a0485d3 avfilter/vf_overlay: split blend_image into functions for each overlay format
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2016-09-11 00:27:01 +02:00
Clément Bœsch
8ef57a0d61 Merge commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb'
* commit '41ed7ab45fc693f7d7fc35664c0233f4c32d69bb':
  cosmetics: Fix spelling mistakes

Merged-by: Clément Bœsch <u@pkh.me>
2016-06-21 21:55:34 +02:00
Vittorio Giovara
41ed7ab45f cosmetics: Fix spelling mistakes
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2016-05-04 18:16:21 +02:00
Derek Buitenhuis
21f9468402 avutil: Rename FF_CEIL_COMPAT to AV_CEIL_COMPAT
Libav, for some reason, merged this as a public API function. This will
aid in future merges.

A define is left for backwards compat, just in case some person
used it, since it is in a public header.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-01-27 16:36:46 +00:00
Bela Bodecs
cc83177db4 vf_overlay: handles expression evaluation of frame size change in frame-by-frame evalutaion mode
vf_overlay video filter accepts expressions in its parameters. In
'frame-by-frame' evaluation mode it recalculates them regularly, but
incoming video frame size changes did not reflect in their values. So if
you used width or height of any source videos in expressions as
parameters, they stayed on their initial values. This patch corrects
this bug.

Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu>
Reviewed-by: Paul B Mahol <onemda@gmail.com
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-19 23:30:36 +01:00
Ganesh Ajjanagadde
08a96708a5 lavfi/vf_overlay: fix unitialized pointers
Missed in commit 301c2784b3.

Found-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-10 07:53:47 -05:00
Ganesh Ajjanagadde
301c2784b3 lavfi/vf_overlay: fix memory leaks
Recent commits 6aaac24d72 and
3835554bf8 made progress towards cleaning
up usage of the formats API, and in particular fixed possible NULL pointer
dereferences.

This commit addresses the issue of possible resource leaks when some intermediate
call fails.

Tested with valgrind --leak-check=full --show-leak-kinds=all, and manual simulation
of malloc/realloc failures.

Fixes: CID 1338327.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-09 07:57:57 -05:00
Ganesh Ajjanagadde
6aaac24d72 avfilter/all: propagate errors of functions from avfilter/formats
Many of the functions from avfilter/formats can return errors, usually AVERROR(ENOMEM).
This propagates the return values.

All of these were found by using av_warn_unused_result, demonstrating its utility.

Tested with FATE. I am least sure of the changes to avfilter/filtergraph,
since I don't know what/how reduce_format is intended to behave and how it should
react to errors.

Fixes: CID 1325680, 1325679, 1325678.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Previous version Reviewed-by: Nicolas George <george@nsup.org>
Previous version Reviewed-by: Clément Bœsch <u@pkh.me>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-10-14 10:04:01 -04:00
Clément Bœsch
9c52eafd5b avfilter/overlay: use AV_OPT_TYPE_BOOL for rgb, shortest and repeatlast options 2015-09-09 00:33:02 +02:00
Michael Niedermayer
1a79850a8f avfilter/vf_overlay: Change enums to int, which are accessed via AVOption as int
This fixes depending on implementation defined behavior

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2015-03-20 19:11:58 +01:00
Reimar Döffinger
d9e2aceb7f Add missing "const" all over the place.
Only "./configure --enable-gpl" on x86 was tested.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2014-08-29 18:57:25 +02:00
Stefano Sabatini
462c9ee3ac lavfi/overlay: show incoming frames on debug messages
This is especially useful to debug queue overflow issues.

Ideally we should be able to set the debug message at the
dualinput/framesync level, but they do not have the information related
to the filter context and the inlink, so cannot access much useful
information.

Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2014-07-02 18:42:15 +02:00
Clément Bœsch
d5f817793e avfilter/overlay: reindent 2014-06-29 13:26:12 +02:00
Michael Niedermayer
74a8dbe1c4 Merge commit '58400ac133bcfb6bf8196b4e5208bc178307739b'
* commit '58400ac133bcfb6bf8196b4e5208bc178307739b':
  lavfi: name anonymous structs

Conflicts:
	libavfilter/buffersink.c
	libavfilter/f_select.c
	libavfilter/src_movie.c
	libavfilter/vf_drawbox.c
	libavfilter/vf_drawtext.c
	libavfilter/vf_overlay.c
	libavfilter/vf_showinfo.c
	libavfilter/vf_unsharp.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2014-04-19 18:20:17 +02:00