Commit Graph

88 Commits

Author SHA1 Message Date
Andreas Rheinhardt 790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
James Almer e58afae1e4 avfilter: remove deprecated FF_API_LIBPLACEBO_OPTS
Signed-off-by: James Almer <jamrial@gmail.com>
2024-03-07 08:53:30 -03:00
Anton Khirnov 1e7d2007c3 all: use designated initializers for AVOption.unit
Makes it robust against adding fields before it, which will be useful in
following commits.

Majority of the patch generated by the following Coccinelle script:

@@
typedef AVOption;
identifier arr_name;
initializer list il;
initializer list[8] il1;
expression tail;
@@
AVOption arr_name[] = { il, { il1,
- tail
+ .unit = tail
}, ...  };

with some manual changes, as the script:
* has trouble with options defined inside macros
* sometimes does not handle options under an #else branch
* sometimes swallows whitespace
2024-02-14 14:53:41 +01:00
Niklas Haas e82277b548 avfilter/vf_libplacebo: switch to colorspace negotiation API 2023-12-31 13:35:35 -08:00
Niklas Haas ff506b8d8f avfilter/vf_libplacebo: don't force dovi frames to bt.2020-ncl
This is at odds with the YUV matrix negotiation API, in which such
dynamic changes in YUV encoding are no longer easily possible. There is
also no really strong motivating reason to do this, since the choice of
YUV matrix is essentially arbitrary and not actually related to the
Dolby Vision decoding process.
2023-12-31 13:35:35 -08:00
Niklas Haas bef151d1ce vf_libplacebo: warn on extra_opts + too old libplacebo
Instead of silently ignoring this option as before.
2023-09-03 13:40:27 +02:00
Niklas Haas 3c9dc009b6 lavfi/vf_libplacebo: add extra_opts AVDictionary
Can be used to configure libplacebo's underlying raw options, which
sometimes includes new or advanced / in-depth settings not (yet) exposed
by vf_libplacebo.
2023-08-27 13:37:03 +02:00
Niklas Haas 816983d951 lavfi/vf_libplacebo: switch to new pl_options struct
This new upstream struct simplifies params struct management by allowing
them to all be contained in a single dynamically allocated struct. This
commit switches to the new API in a backwards-compatible way.

The only nontrivial change that was required was to handle
`sigmoid_params` in a way consistent with the rest of the params
structs, instead of setting it directly to the upstream default.
2023-08-27 13:37:03 +02:00
Andreas Rheinhardt 19af142d45 avfilter/internal: Don't include formats.h
internal.h doesn't rely on it; instead include it directly
in every user that needs it (a filter needing it is basically
equivalent to it using FILTER_QUERY_FUNC, i.e. a majority of
filters doesn't need it).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-07 09:21:13 +02:00
Andreas Rheinhardt 6d15643173 avfilter/internal: Don't include video.h
internal.h does not depend on video.h (and should not depend on it)
and therefore should not include video.h at all; instead all users
of video.h should include it directly.

Doing so also avoids unnecessary video.h inclusions in files that
don't need it, like most audio filters.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2023-08-07 09:21:13 +02:00
Niklas Haas e9e37ea2f1 avfilter/vf_libplacebo: fix skip_aa option range
Max incorrectly specified as 0, should be 1.
2023-07-23 17:50:41 +02:00
Niklas Haas 138d3ac15d lavfi/vf_libplacebo: test for renderable pixel formats
Requires a new upstream function to test not for *import* support on a
given output pixel format, but also whether we can render to it.

Fixes: https://github.com/haasn/libplacebo/issues/173
2023-07-15 13:37:54 +02:00
Niklas Haas 13e9899014 lavfi/vf_libplacebo: add contrast recovery options
New upstream option. Enabled by default in the high-quality preset
upstream, so enable it by default here.
2023-07-08 12:54:49 +02:00
Niklas Haas 2e83ba001d lavfi/vf_libplacebo: deprecate hybrid_mix option
Deprecated upstream in libplacebo v6.292.
2023-07-08 12:41:45 +02:00
Niklas Haas 5fdb12d6a0 lavfi/vf_libplacebo: simplify SAR normalization
The old logic was trying to be excessively clever in "deducing" that the
user wanted to stretch/scale the image when ow/oh differed from iw/ih
aspect ratio. But this is almost surely unintended except in
pathological cases, and in those cases users should simply disable
normalize_sar and do all the stretching/scaling logic themselves. This
is especially important in multi-input mode, where the canvas may be
vastly different from the input dimensions of any stream. Also, passing
through input 0 SAR in multi-input mode is arbitrary and nearly useless,
so again force output SAR to 1:1 here.
2023-06-23 15:18:25 +02:00
Niklas Haas e998d0a4f7 lavfi/vf_libplacebo: allow pos_w to depend on pos_h
Ditto for crop_w/crop_h. Requires simply repeating the evaluation of the
first variable to be evaluated.
2023-06-20 17:09:58 +02:00
Niklas Haas f998a618ba lavfi/vf_libplacebo: add nb_inputs option
To control the number of inputs.
2023-06-20 17:09:58 +02:00
Niklas Haas 9049ea6763 lavfi/vf_libplacebo: set time_base/frame_rate dynamically
Use the gcd of all input timebases to ensure PTS accuracy. For the
framerate, just pick the highest of all the inputs, under the assumption
that we will render frames with approximately this frequency. Of course,
this is not 100% accurate, in particular if the input frames are badly
misaligned. But this field is informational to begin with.

Importantly, it covers the "common" case of combining high FPS and low
FPS streams with aligned frames.
2023-06-20 17:09:58 +02:00
Niklas Haas 1b2c6c9a03 lavfi/vf_libplacebo: also skip cache if in FPS == out FPS
Fixes an oversight in the previous code which should have been >=, not >.
2023-06-20 17:09:58 +02:00
Niklas Haas 618b72d4b4 lavfi/vf_libplacebo: skip cache selectively per-input
It may be the case that we want to skip the single frame cache for some
inputs but not others.
2023-06-20 17:09:58 +02:00
Niklas Haas 015c3b659e lavfi/vf_libplacebo: set format list for all inputs 2023-06-20 17:09:58 +02:00
Niklas Haas 5989719e87 lavfi/vf_libplacebo: add in_idx variable
To allow placing an input dynamically, as a function of the input index.
2023-06-20 17:09:58 +02:00
Niklas Haas 7645c8df66 lavfi/vf_libplacebo: make input-dependent vars dynamic
Because these can differ based on the input, for multiple inputs.
2023-06-20 17:09:58 +02:00
Niklas Haas d625010acd lavfi/vf_libplacebo: generalize frame update to multiple inputs
In the event that some frame mixes are OK while others are not, the
priority goes:

1. Errors in updating any frame -> return error
2. Any input incomplete -> request frames and return
3. Any inputs OK -> ignore EOF streams and render remaining inputs
4. No inputs OK -> set output to most recent status

This logic ensures that we can continue rendering the remaining streams,
no matter which streams reach their end of life, until we have no
streams left at which point we forward the last EOF.
2023-06-20 17:09:58 +02:00
Niklas Haas 6c41c3f928 lavfi/vf_libplacebo: only drain actually used PTS
When combining multiple inputs, the output PTS may be less than the PTS
of the input. In this case, the current's code assumption of always
draining one value from the FIFO is incorrect. Replace by a smarter
function which drains only those PTS values that were actually consumed.
2023-06-20 17:09:58 +02:00
Niklas Haas 502b699a50 lavfi/vf_libplacebo: determine PTS of next frame from any input
When combining multiple inputs with different PTS and durations, in
input-timed mode, we emit one output frame for every input frame PTS,
from *any* input. So when combining a low FPS stream with a high FPS
stream, the output framerate would match the higher FPS, independent of
which order they are specified in.
2023-06-20 17:09:58 +02:00
Niklas Haas 0eb37c2419 lavfi/vf_libplacebo: handle multiple inputs
This commit still relies on a single input for PTS determination, to be
changed in the next commit.
2023-06-20 17:09:58 +02:00
Niklas Haas 56e550b264 lavfi/vf_libplacebo: support blending multiple inputs
Subsequent inputs require frame blending to be enabled, in order to not
overwrite the existing frame contents.

For output metadata, we implicitly copy the metadata of the *first*
available stream (falling back to the second stream if the first has
already reached EOF, and so on). This is done to resolve any conflicts
between inputs with differing metadata. So when e.g. input 1 is HDR and
output 2 is SDR, the output will be HDR, and vice versa. This logic
could probablly be improved by dynamically determining some "superior"
set of metadata, but I don't want to handle that complexity in this
series.
2023-06-20 17:09:58 +02:00
Niklas Haas 0c66d912ba lavfi/vf_libplacebo: keep track of latest status globally
This field will effectively hold the most recent status set by any
input. Currently functionally equivalent to input->status, but will
change soon.
2023-06-20 17:09:57 +02:00
Niklas Haas 4e4a66b8c4 lavfi/vf_libplacebo: replace s->input by dynamic array
For now, hard-coded to 1 element.
2023-06-20 17:09:57 +02:00
Niklas Haas a7775bd32c lavfi/vf_libplacebo: use correct link in update_crops()
Instead of hard-coding input 0, pass the per-input structure and use the
link contained inside it.
2023-06-20 17:09:57 +02:00
Niklas Haas 93c7e8c0ae lavfi/vf_libplacebo: factor out ref frame logic
Instead of finding the ref frame in output_frame() and then passing its
signature to update_crops(), pull out the logic and invoke it a second
time inside update_crops().

This may seem wasteful at present, but will actually become required in
the future, since update_crops() runs on *every* input, and needs values
specific to that input (which the signature isn't), while output_frame()
is only interested in a single input. It's much easier to just split the
logic cleanly.
2023-06-20 17:09:57 +02:00
Niklas Haas 666c8aa4d7 lavif/vf_libplacebo: remove pl_frame_mix from output_frame_mix
Instead, rename this function to `output_frame` and make it pull the
`pl_frame_mix` from the input structure. Step towards handling multiple
inputs.
2023-06-20 17:09:57 +02:00
Niklas Haas ad445a7030 lavfi/vf_libplacebo: move temporary vars into per-input struct
Including the queue status, because these will need to be re-queried
inside output_frame_mix when that function is refactored to handle
multiple inputs.
2023-06-20 17:09:57 +02:00
Niklas Haas a4197196a0 lavfi/vf_libplacebo: cosmetic
Assign local variable 'in' for 's->input' and replace 'inlink' by
'in->link' to avoid hard-coding ID 0 in more than one place.
2023-06-20 17:09:57 +02:00
Niklas Haas b5d48111ad lavfi/vf_libplacebo: move input handling to separate function
To be re-used once we support more than one input.
2023-06-20 17:09:57 +02:00
Niklas Haas c3b17ccc62 lavfi/vf_libplacebo: move input-specific state to struct
In anticipation of a refactor which will enable multiple input support.

Note: the renderer is also input-specific because it maintains a frame
cache, HDR peak detection state and mixing cache, all of which are tied
to a specific input stream.
2023-06-20 17:09:57 +02:00
Niklas Haas 7be4434c88 lavfi/vf_libplacebo: drop redundant case
If the input queue is EOF, then the s->status check should already have
covered it, and prevented the code from getting this far.

If we still hit this case for some reason, it's probably a bug. Better
to hit the AVERROR_BUG branch.
2023-06-20 17:09:57 +02:00
Niklas Haas d26ea03f60 lavfi/vf_libplacebo: fix typo in assert
Not caught because av_assert1 was compiled out on my end.
2023-06-13 15:28:32 +02:00
Niklas Haas c4cdd79435 lavfi/vf_libplacebo: add corner_rounding option
For what use it may be.
2023-05-29 19:11:18 +02:00
Niklas Haas 098b338369 lavfi/vf_libplacebo: require v5.278 for importing
Importing Vulkan device on older versions no longer works due to the
lavu vulkan API changes (specifically, the switch to planar textures by
default). Additionally, importing on versions that don't suppirt
lock/unlock_queue is unsafe with the advent of the threaded vulkan
hwaccel. As a plus, saves us some annoying #ifdef boilerplate.

I will raise the minimum vf_libplacebo version globally on the next
stable release of libplacebo, and remove all of these checks.
2023-05-29 18:56:56 +02:00
Niklas Haas b41ea8c6c3
avfilter/vf_libplacebo: bump max vk version
For two reasons:
1. We now create a vulkan 1.3 device
2. libplacebo master currently requires a vulkan 1.3 device
2023-05-29 00:41:55 +02:00
Niklas Haas 661db605db
avfilter/vf_libplacebo: forward queue locking primitives
For thread safety.
2023-05-29 00:41:55 +02:00
Niklas Haas 0bce5590c3 lavfi/vf_libplacebo: fix crop expr PTS calculation
mix->timestamps is expressed relative to the source timebase, which is
possibly a different timescale from `base_pts`. We can't mix-and-match
here. The only reason this worked in my previous testing was because I
was testing on a source file which had an exactly matching timebase.

Fix it by always using the exact PTS as tagged on the AVFrame.
2023-05-24 14:39:40 +02:00
Niklas Haas d815584755 lavif/vf_libplacebo: move code (cosmetic)
To eliminate need for forward declaration
2023-05-23 15:06:18 +02:00
Niklas Haas ee13414444 lavfi/vf_libplacebo: update settings after adding hooks
Failure to do so led to the update s->hooks never getting correctly
propagated to the render params.
2023-05-23 15:05:21 +02:00
Niklas Haas 877ccaf776 lavfi/vf_libplacebo: don't intrude on pl_ namespace
No reason to use this prefix here.
2023-05-22 10:31:51 +02:00
Niklas Haas 21715ecff1 lavfi/vf_libplacebo: update peak detection options
Upstream peak detection lost one option and gained one option. Update
code and documentation as required.
2023-05-22 10:31:51 +02:00
Niklas Haas 643cf2ec46 lavfi/vf_libplacebo: update for new tone mapping API
This algorithm has once again been refactored, this time leading to a
dropping of the old `tone_mapping_mode` field, to be replaced by a
single tunable hybrid mode with configurable strength.

We can approximately map the old modes onto the new API for backwards
compatibility. Replace deprecated enums by their integer equivalents to
safely preserve this API until the next bump.
2023-05-22 10:31:50 +02:00
Niklas Haas d637f20f05 lavfi/vf_libplacebo: switch to new gamut mapping API
Upstream deprecated the old ad-hoc, enum/intent-based gamut mapping API
and added a new API based on colorimetrically accurate gamut mapping
functions.

The relevant change for us is the addition of several new modes, as well
as deprecation of the old options. Update the documentation accordingly.
2023-05-22 10:31:50 +02:00