Commit graph

118355 commits

Author SHA1 Message Date
34c06f5284
avcodec/escape130: move get_buffer down
This way the (slow) allocation of an image is done after various additional checks

Fixes: Timeout
Fixes: 379418967/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_ESCAPE130_fuzzer-6507383574036480

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-12-24 02:46:47 +01:00
89efc6c97c
tools/target_dec_fuzzer: Adjust Threshold for indeo5
Fixes: 379768251/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_INDEO5_fuzzer-5981329084186624
Fixes: Timeout

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-12-24 02:46:47 +01:00
6ba33b50f5
avutil/timecode: Avoid fps overflow in av_timecode_get_smpte_from_framenum()
Fix from c94875471e

Found-by: Youngjae Choi <youngjaechoi@korea.ac.kr>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-12-24 02:45:13 +01:00
James Almer
f1ddba24a0 avutil/frame: add missing size dependent prop to LCEVC payload side data
Signed-off-by: James Almer <jamrial@gmail.com>
2024-12-23 17:39:57 -03:00
Niklas Haas
d23f443dfc avfilter/vf_lut*: strip color volume metadata
These filters, in general, will apply some arbitrary color volume
transformation. Strip corresponding metadata to be conservative/safe.
2024-12-23 14:23:13 +01:00
Niklas Haas
eecdc25d4b avfilter/vf_colorspace: strip color volume metadata 2024-12-23 14:23:13 +01:00
Niklas Haas
0d468730bc avfilter/vf_libplacebo: update metadata stripping logic
Switches to av_frame_side_data_remove_by_props(), covering a number of
cases that we previously ignored. Additionally, stop stripping metadata
when merely changing colorspace or color range, since these do not
affect the actual color volume of the image data, only the encoding.
2024-12-23 14:23:13 +01:00
Niklas Haas
d1eadc43b9 avfilter/vf_zscale: strip metadata on change
Required for both size changes and color volume changes (as a result of
changing primaries/transfer).
2024-12-23 14:23:13 +01:00
Niklas Haas
f22965b882 avfilter/vf_scale*: strip metadata on size change 2024-12-23 14:23:13 +01:00
Niklas Haas
b88944a8aa avutil/frame: add av_frame_side_data_remove_by_props()
As discussed in the previous commit, we often need a convenient way of
stripping all side data related to a certain aspect of the frame. This helper
accomplishes just that.

I considered also adding a way to match only side data matching *all*
properties, but I think this is sufficiently useless in practise to not warrant
inclusion in the API.
2024-12-23 14:22:56 +01:00
Niklas Haas
3428a8d830 avutil/frame: add AV_SIDE_DATA_PROP_{SIZE,COLOR}_DEPENDENT
Many filters modify certain aspects of frame data, e.g. through resizing
(vf_*scale* family), color volume mapping (vf_lut*, vf_tonemap*), or
possibly others.

When this happens, we should strip all frame side data that will no
longer be correct/relevant after the operation. For example, changing
the image size should invalidate AV_FRAME_DATA_PANSCAN because the crop
window (given in pixels) no longer corresponds to the actual image size.
For another example, tone-mapping filters (e.g. from HDR to SDR) should
strip all of the dynamic HDR related metadata.

Since there are a lot of different side data types that are affected by such
operations, it makes sense to establish this information in a common, easily
accessible way. The existing side data properties enum is a perfect fit for
this.
2024-12-23 13:33:33 +01:00
Niklas Haas
01084f3d16 avutil/frame: add AVSideDataDescriptor for AV_FRAME_DATA_VIDEO_HINT
This entry was seemingly missing.
2024-12-23 13:32:48 +01:00
Niklas Haas
5ca5bbd462 swscale/options: add -sws_dither none alias
While this one was technically supported on account of the generic options
code allowing "none" as a valid alias for 0, not having it listed here meant
it never showed up in e.g. the -h output, and is also inconsistent with other
places in the code that generally add an explicit alias with appropriate
documentation. Reduces user confusion at negligible cost.

Fixes: #9192
Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-23 12:47:10 +01:00
Niklas Haas
253b8977c0 swscale: remove primaries/trc change warning
This is now supported when using the new API.
2024-12-23 12:33:43 +01:00
Niklas Haas
6da940e118 swscale/graph: allow dynamically updating HDR metadata
Without triggering a full graph reinit.
2024-12-23 12:33:43 +01:00
Niklas Haas
efff80c8f6 swscale/graph: add color mapping pass
This leverages the previously introduced color management subsystem in order
to adapt between transfer functions and color spaces, as well as for HDR tone
mapping.

Take special care to handle grayscale formats without a colorspace
gracefully.
2024-12-23 12:33:43 +01:00
Niklas Haas
a57fe519b6 swscale/lut3d: add 3DLUT dispatch system
This is a lightweight wrapper around the underlying color management system,
whose job it is merely to manage the 3DLUT state and apply them to the frame
data. This is where we might add platform-specific optimizations in the future.

I also plan on adding support for more pixel formats in the future. In
particular, we could support YUV or XYZ input formats directly using only
negligible additional code in the 3DLUT setup functions. This would eliminate
the major source of slowdown, which is currently the roundtrip to RGBA64.
2024-12-23 12:33:43 +01:00
Niklas Haas
dddf536d3d swscale/cms: add color management subsystem
The underlying color mapping logic was ported as straightforwardly as possible
from libplacebo, although the API and glue code has been very heavily
refactored / rewritten. In particular, the generalization of gamut mapping
methods is replaced by a single ICC intent selection, and constants have been
hard-coded.

To minimize the amount of overall operations, this gamut mapping LUT now embeds
a direct end-to-end transformation to the output color space; something that
libplacebo does in shaders, but which is prohibitively expensive in software.

In order to preserve compatibility with dynamic tone mapping without severely
regressing performance, we add the ability to generate a pair of "split" LUTS,
one for encoding the input and output to the perceptual color space, and a
third to embed the tone mapping operation. Additionally, this intermediate
space could be used for additional subjective effect (e.g. changing
saturation or brightness).

The big downside of the new approach is that generating a static color mapping
LUT is now fairly slow, as the chromaticity lobe peaks have to be recomputed
for every single RGB value, since correlated RGB colors are not necessarily
aligned in ICh space. Generating a split 3DLUT significantly alleviates this
problem because the expensive step is done as part of the IPT input LUT, which
can share the same hue peak calculation at least for all input intensities.
2024-12-23 12:33:43 +01:00
Niklas Haas
2e674780b7 swscale/csputils: add internal colorspace math helpers
Logic is, for the most part, a straight port of similar logic in
liplacebo's colorspace.c, with some general edits and refactors.
2024-12-23 12:33:43 +01:00
Niklas Haas
01ce9d7963 avfilter/vf_scale: strip metadata when changing colorspace
This is no longer relevant after a change in color space.
2024-12-23 12:33:43 +01:00
Niklas Haas
4315cc943a avfilter/vf_scale: make options alignment consistent (cosmetic) 2024-12-23 12:33:43 +01:00
Niklas Haas
b7a2333357 avfilter/vf_scale: add colorspace and transfer property options
In the long run, it would be ideal if we could add these to the avfilter
negotiation as well, but for now, this is a good start.
2024-12-23 12:33:43 +01:00
Niklas Haas
45f0a7ad33 swscale: add ICC intent enum and option
This setting can be used to infuence the type of tone and gamut mapping used
internally when color space conversions are required. As discussed at VDD'24,
the default was set to relative colorimetric clipping, which is approximately
associative, surjective and idempotent. As such, it roundtrips well, although
it is strictly speaking not associative on out-of-gamut colors.
2024-12-23 12:33:43 +01:00
Niklas Haas
7b7c32322d swscale/utils: fix XYZ primaries tagging
Swscale currently handles XYZ by embedding a forced conversion to
BT.709 RGB with a hardcoded matrix. This is not ideal, but to preserve the
status quo and avoid any unexpected changes in behavior, this patch merely
fixes the inferred primaries tag to match the reality.

In the future, I would like to handle XYZ properly, via direct conversion
to the target colorspace (or possibly simply by using a more fitting
RGB intermediate like SMPTE428), but for now just keep the status quo.
2024-12-23 12:33:43 +01:00
Niklas Haas
1f0c500784 swscale/utils: add helper function to infer colorspace metadata
Logic is loosely on equivalent decisions in libplacebo. The basic idea is to try
and be a bit conservative by treating AVCOL_*_UNSPECIFIED as a no-op, unless the
other primaries set are non-standard / wide-gamut or HDR. This helps avoid
unintended or unexpected colorspace conversions, while forcing it in cases where
we are almost certain it is needed. The major departure from libplacebo semantics
is that we no default to a 1000:1 contrast ration for SDR displays, instead modelling
them as idealized devices with an infinite contrast ratio.

In either case, setting SWS_STRICT overrides this behavior in favor of always
requiring explicit colorspace metadata.
2024-12-23 12:33:43 +01:00
Niklas Haas
9084d581e8 swscale/utils: read dynamic HDR10+ metadata from AVFrame
Logic ported from libplacebo's AVFrame helpers. The basic idea is to use the
provided MaxRGB/MaxSCL values to infer what the actual luminance would have
been, which HDR10+ metadata does not provide directly. It's worth pointing out
that this gives us an *upper* bound on the true maximum luminance, so any
error in the estimation cannot result in clipping.
2024-12-23 12:33:43 +01:00
Niklas Haas
7432fa19cd swscale/utils: read HDR mastering metadata from AVFrame 2024-12-23 12:33:43 +01:00
Niklas Haas
5b21b7f52c swscale/utils: set static/implied HDR metadata
Provide default values for the fields added in the previous commit.
2024-12-23 12:33:43 +01:00
Niklas Haas
a8d01dff9a swscale/utils: add HDR metadata to SwsFormat
Only add the condensed values that we actually care about. Group them into
a new struct to make it easier to discard or replace this metadata.

Define a special comparison function that does not choke on undefined/unknown
metadata.
2024-12-23 12:33:43 +01:00
Niklas Haas
b9dfe8138e swscale/utils: check for supported color transfers
We will use the av_csp_itu_eotf() functions to decode these internally, so
check this function to see if it succeeds.
2024-12-23 12:33:43 +01:00
Niklas Haas
6c9218d748 swscale/unscaled: allow semiplanar copies
As fixed in the previous commit, this enables semipacked range and
bit depth conversions. Previously these would go through the general
purpose path.

Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-23 11:32:02 +01:00
Niklas Haas
77db7f9b87 swscale/unscaled: correctly copy semiplanar formats
This fixes multiple bugs with semiplanar formats like NV12. Not only do these
false positive the grayscale format checks (because dst[2] in NULL), but they
also copied an incorrect number of pixels.

Fixes conversions such as nv12 -> nv12, gray8 -> nv12, nv20le -> nv20be, etc.

Fixes: #11239
Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-23 11:31:58 +01:00
Niklas Haas
c6bf7f6645 swscale/unscaled: correctly round yuv2yuv when not dithering
We should at least bias towards the nearest integer, instead of always
rounding down, when not dithering. This is a bit more correct.

The FATE changes are only in the cases where sws_dither was explicitly set
to "none", which is exactly as expected.

Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-23 11:29:22 +01:00
Niklas Haas
a9ae2cc14d checkasm/sw_rgb: add alpToYV12 check
Mirroring lumToYV12 and chrToYV12.

Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-23 11:20:59 +01:00
Niklas Haas
c601bb8df5 checkasm/sw_rgb: add tests for yuv2packed{1,2,X}
Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-23 11:20:58 +01:00
Niklas Haas
57bbdb4fb1 checkasm/sw_scale: add test for yuv2nv12cX
Mirroring yuv2yuvX.

Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-23 11:20:58 +01:00
Niklas Haas
fe9bf7cd52 checkasm/sw_scale: add assertion for hscale assumption
This code only checks hcScale. In practice this is not an issue because
the function pointers should always be identical to hyScale for the same
filter size.

Add an assertion just to make sure this assumption never regresses.

Signed-off-by: Niklas Haas <git@haasn.dev>
Sponsored-by: Sovereign Tech Fund
2024-12-23 11:20:58 +01:00
Scott Theisen
9da1d2e66a libavcodec/v4l2_buffers.c: set AVFrame interlaced flags
Originally from:
669955c6cb

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-12-23 16:16:16 +08:00
1b8cd00da6
configure: add option to statically link to libvulkan
This may be useful in weird setups and on platforms where
static linking to libvulkan is supported.

libplacebo also has this fallback.
2024-12-23 04:25:09 +09:00
8fbecfd1a0
vulkan_decode: add queue_flags field to specify queue used 2024-12-23 04:25:09 +09:00
2e06b84e27
vulkan: do not reinvent a queue context struct
We recently introduced a public field which was a superset
of the queue context we used to have.

Switch to using it entirely.

This also allows us to get rid of the NIH function which was
valid only for video queues.
2024-12-23 04:25:09 +09:00
157cd820ad
vulkan: remove pointless mutex locks
This code was simply incorrect through and through. It did not
protect what actually has to be protected in a multi-threaded setup.
Perhaps it was used to silence threading errors?

Either way, remove it, and document the correct way to use execution
pools in a threaded environment.
2024-12-23 04:25:09 +09:00
7239be07be
vulkan_decode: use a single execution pool
Originally, the decoder had a single execution pool, with one
execution context per thread. Execution pools were always intended
to be thread-safe, as long as there were enough execution contexts
in the pool to satisfy all threads.

Due to synchronization issues, the threading part was removed at some
point, and, for decoding, each thread had its own execution pool.
Having a single execution pool per context is hacky, not to mention
wasteful.
Most importantly, we *cannot* associate single shaders across multiple
execution pools for a single application. This means that we cannot
use shaders to either apply film grain, or use this framework for
software-defined decoders.

The recent commits added threading capabilities back to the execution
pool, and the number of contexts in each pool was increased. This was
done with the assumption that the execution pool was singular, which
it was not. This led to increased parallelism and number of frames
in flight, which is taxing on memory.

This commit finally restores proper threading behaviour.
The validation layer has isses that are reported and addressed in the
earlier commit.
2024-12-23 04:25:08 +09:00
4ca2b86ed5
hwcontext_vulkan: disable validation layer threading warnings
The layer is buggy currently:
https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/9045
2024-12-23 04:25:08 +09:00
18af3a1db2
hwcontext_vulkan: do not enable portability subset by default
It doesn't make sense to, and could result in the implementation
picking emulation layers.
2024-12-23 04:25:01 +09:00
Benjamin Cheng
bf9f921ef7 avcodec/hw_base_encode: restrict size of next_prev
Some drivers are more strict about the size of the reference lists given
(i.e. VAOn12 [1]). The next_prev list is used to handle multiple "L0"
references in AV1 encode. Restrict the size of next_prev based on the
value of ref_l0 when the GOP structure is initialized.

[1] https://github.com/intel/cartwheel-ffmpeg/issues/278

v2: fix indentation issues
2024-12-23 04:24:54 +09:00
Nuo Mi
0a6388d1da avcodec/hevcdec: remove hevc prefix for x86 asm files 2024-12-22 21:00:06 +08:00
Nuo Mi
8d27256a74 avcodec/vvcdec: remove vvc prefix for x86 and riscv 2024-12-22 21:00:06 +08:00
Peter Ross
350ebef112
avformat/iff: remove surplus if statement
Fixes CID 1636854
2024-12-22 06:24:49 -05:00
Peter Ross
b2cba76d4f avformat/riff: map 0069 twocc to ADPCM IMA XBOX decoder 2024-12-22 16:08:33 +11:00