Commit Graph

21 Commits

Author SHA1 Message Date
Niklas Haas 62dfa54688 avfilter/vf_libplacebo: fix format query
We need to construct the output format list separatedly from the input
format list, because we need to adhere to two extra requirements:

1. Big-endian output formats are always unsupported (runtime error)
2. Combining 'vulkan' with an explicit out_format that is not supported
   by the vulkan frame allocation code is illegal and will crash (abort)

As a free side benefit, this rewrite fixes a possible memory leak in the
`fail` path that was present in the old code.

Signed-off-by: Niklas Haas <git@haasn.dev>
2023-02-07 15:11:49 +01:00
Niklas Haas 9bfdd8524e avfilter/vf_libplacebo: suppress cast warning
This warning was introduced when ee65039 removed the cast.
2023-01-30 20:34:55 +01:00
Timo Rothenpieler ee650398ec avfilter/vf_libplacebo: ensure filter hwdevice is a vulkan one
Before this, the filter blindly casts to AVVulkanDeviceContext and
passes invalid values to libplacebo if it's not.
2022-12-04 15:22:13 +01:00
Niklas Haas 48c385fb4c avfilter/vf_libplacebo: support more output formats
Rather than hard-coding AV_PIX_FMT_VULKAN, expand this to the full list
of formats supported by <libplacebo/utils/libav.h>. We re-use the
existing `format` option to allow selecting specific software formats in
addition to specific vulkan hwframe formats.

Some minor changes are necessary to account for the fact that
`ff_vk_filter_config_output` is now only called optionally, the fact
that the output format must now be parsed before `query_format` gets
called, and the fact that we need to call a different function to
retrieve data from the `pl_frame` in the non-hwaccel case.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-11-28 16:05:36 +01:00
Niklas Haas 46a4cc460e avfilter/vf_libplacebo: fix normalize_sar calculation
This previous expression multiplied a constant (outlink->h) that was
guaranteed to be 0 at this point, thus making it always a no-op.

Fix the calculation, and also properly reset the SAR to 1:1 as is now
necessary (the failure to do so previously hid this bug's existence).
2022-11-19 14:15:47 +01:00
Niklas Haas 05d390890a avfilter/vf_libplacebo: default to normalize_sar=0
As a result of a typo in the source code, this option was completely
non-functional. In order to fix it, without breaking the current default
behavior, explicitly change this default to 0.

This behavior is also consistent with how other scale filters behave by
default, so it's probably best to enshrine it anyways.
2022-11-19 14:15:19 +01:00
Niklas Haas 12b4ab5d4d avfilter/vf_libplacebo: fix output format selection
After commit c0b93, it's possible that `ff_vk_filter_config_input` never
gets called, leading to `s->vkctx.input_format` being left unset. This
broke the format auto-selection logic in `libplacebo_config_output`,
resulting in a default to yuv420p, instead of defaulting to the input
format as intended.

Fixes: c0b93c4f8b
2022-11-18 16:14:23 +01:00
Niklas Haas d1b14b4f0b avfilter/vf_libplacebo: suppress warning on older libplacebo
Move the declaration before the code.
2022-11-18 16:11:01 +01:00
Niklas Haas c0b93c4f8b avfilter/vf_libplacebo: support all supported pixfmts
This is done only to the inputs, not the outputs, because we always
output vulkan hwframes.

Doing so also requires keeping track of backing textures for non-hwdec
formats, but is otherwise a mostly straightforward change to the format
query function. Special care needs to be taken to avoid crashing on
older libplacebo due to AV_PIX_FMT_RGBF32LE et al.
2022-11-15 16:47:55 +01:00
Niklas Haas be13812a23 avfilter/vf_libplacebo: init vulkan device in query_format
Instead of doing it ad-hoc in `filter_frame`. This is not a huge change
on its own, but paves the way for adding support for more formats in the
future, in particular formats other than AV_PIX_FMT_VULKAN.
2022-11-15 16:47:55 +01:00
Michael Niedermayer 0a3e121798 avfilter/vf_libplacebo: Match AV_OPT_TYPE_FLOAT to dbl
Reviewed-by: "mypopy@gmail.com" <mypopy@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2022-05-06 15:57:45 +02:00
Andreas Rheinhardt 2b2380c098 avfilter: Constify non-const filters
This makes the filters match their declaration in
libavfilter/allfilters.c; the earlier discrepancy was btw UB.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-01 21:29:01 +02:00
Niklas Haas e301a24fa1 avfilter/vf_libplacebo: update for new tone mapping API
Upstream gained a new tone-mapping API, which we never switched to. We
don't need a version bump for this because it was included as part of
the v4.192 release we currently already depend on.

Some of the old options can be moderately approximated with the new API,
but specifically "desaturation_base" and "max_boost" cannot. Remove
these entirely, rather than deprecating them. They have actually been
non-functional for a while as a result of the upstream deprecation.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-03-31 11:55:53 +02:00
Niklas Haas ecf09764dc lavfi/vf_libplacebo: fix side data stripping logic
This was accidentally comparing s->colorspace against out->colorspace,
which is wrong - the intent was to compare in->colorspace against
out->colorspace.

We also forgot to strip mastering metadata. Finally, the order is sort
of wrong - we should strip this side data *before* process_frames,
because otherwise it may end up being seen and used by libplacebo.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-01-10 09:11:02 +01:00
Niklas Haas db28bb8fb4 lavfi/libplacebo: support dovi metadata application
libplacebo supports automatic dolby vision application, but it requires
us to switch to a new API. Also add some logic to strip the dolby vision
metadata from the output frames in any case where we end up changing the
colorimetry.

The libplacebo dependency bump is justified because neither 184 nor 192
are part of any stable libplacebo release, so users have to build from
git anyways for this filter to exist.

Signed-off-by: Niklas Haas <git@haasn.dev>
2022-01-05 03:13:12 +01:00
Niklas Haas e9ba40c5c9 lavfi/vf_libplacebo: update deprecated option name
This was renamed upstream quite a while ago (v3.112.0). Rename the
option name as well for consistency (and expand the description just
slightly).

Signed-off-by: Niklas Haas <git@haasn.dev>
2021-12-15 23:38:29 +01:00
Niklas Haas 5317a6366f vf_libplacebo: switch to newer libplacebo helpers
Support for mapping/unmapping hardware frames has been added into
libplacebo itself, so we can scrap this code in favor of using the new
functions. This has the additional benefit of being forwards-compatible
as support for more complicated frame-related state management is added
to libplacebo (e.g. mapping dolby vision metadata).

It's worth pointing out that, technically, this would also allow
`vf_libplacebo` to accept, practically unmodified, other frame types
(e.g. vaapi or drm), or even software input formats. (Although we still
need a vulkan *device* to be available)

To keep things simple, though, retain the current restriction to vulkan
frames. It's possible we could rethink this in a future commit, but for
now I don't want to introduce any more potentially breaking changes.
2021-12-15 23:38:21 +01:00
Lynne f6dd30df24
lavfi/vulkan: split off lavfi-specific code into vulkan_filter.c
The issue is that libavfilter depends on libavcodec, and when doing a
static build, if libavcodec also includes "libavfilter/vulkan.c", then
during link-time, compiling programs will fail as there would be multiple
definitions of the same symbols in both libavfilter and libavcodec's
object files.
Linkers are, however, more permitting if both files that include
a common file that's used as a template are one-to-one identical.
Hence, to make both files the same in the future, export all avfilter
specific functions to a separate file.
There is some work in progress to make templated files like this be
compiled only once, so this is not a long-term solution.

This also removes a macro that could be used to toggle SPIRV compilation
capability on #include-time, as this could cause the files to be different.
2021-11-19 16:47:26 +01:00
Lynne d1133e8c44
lavu/vulkan: move common Vulkan code from libavfilter to libavutil 2021-11-19 13:44:45 +01:00
Niklas Haas a943f527a1 lavfi/vf_libplacebo: pick log level dynamically
In particular, allows users to go all the way up to PL_LOG_TRACE if
desired. (While also avoiding some potentially unnecessary callbacks for
filtered messages, including e.g. the CPU cost of printing out shader
sources)

Response to runtime log level changes by updating it once per
filter_frame(), which should hopefully be often enough.
2021-11-12 22:00:14 +01:00
Niklas Haas 51e03409d7 lavfi: add a libplacebo filter
This filter conceptually maps the libplacebo `pl_renderer` API into
libavfilter, which is a high-level image rendering API designed to work
with an RGB pipeline internally. As such, there's no way to avoid e.g.
chroma interpolation with this filter, although new versions of
libplacebo support outputting back to subsampled YCbCr after processing
is done.

That being said, `pl_renderer` supports automatic integration of the
majority of libplacebo's shaders, ranging from debanding to tone
mapping, and also supports loading custom mpv-style user shaders, making
this API a natural candidate for getting a lot of functionality out of
relatively little code.

In the future, I may approach this problem either by rewriting this
filter to also support a non-renderer codepath, or by upgrading
libplacebo's renderer to support a full YCbCr pipeline.

This unfortunately requires a very new version of libplacebo (unreleased
at time of writing) for timeline semaphore support. But the amount of
boilerplate needed to hack in backwards compatibility would have been
very unreasonable.
2021-11-12 14:45:36 +01:00