1
0
mirror of https://git.ffmpeg.org/ffmpeg.git synced 2026-10-24 02:09:03 +03:00
Commit Graph

743 Commits

Author SHA1 Message Date
Michael Niedermayer
66143d6aaa Bump minor version for release/9.1
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-10-23 06:44:03 +02:00
Kacper Michajłow
a17a624069 swresample: skip the rematrix stage when there are no samples
When resampling first, a call that produced no output passed midbuf to
swri_rematrix() before it was ever allocated, and copied channels did a
memcpy() of zero bytes from NULL. Skip rematrixing zero samples, as the
output conversion already does.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-30 14:40:12 +00:00
Kacper Michajłow
755b6bdfd5 swresample/tests/swresample: align the sample buffers
They are plain byte arrays on the stack but are read and written as
samples of up to double size.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-29 22:39:11 +02:00
Kacper Michajłow
739132b015 swresample/tests/swresample: fail when a context cannot be initialized
swr_init() failures were only printed and the test still exited with 0.
Return failure through the cleanup instead, also for the allocation
failures that returned without it.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-29 22:39:11 +02:00
Kacper Michajłow
5191917736 swresample/tests/swresample: free the contexts
The two contexts and the layouts were never released, which trips leak
checking once the test runs under FATE.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-29 22:39:11 +02:00
Kacper Michajłow
09f879b074 swresample: keep integer samples if channels are only copied
With a matrix, samples of more than 16 bits are mixed in floating
point, which takes the lowest bits of s32. A matrix that only copies
channels computes nothing, so select the internal format like without
a matrix. Layouts that differ in the order of their channels or in
unused ones get such a matrix.

The matrix is built before the format is selected for this. The limit
for its coefficients no longer looks at the selected format. For
mixing that is an integer format only if the output has one or if it
was set, which is what the limit looks at now.

s64 still goes through double, the matrix has no functions for it.

Bump the micro version, as this and the previous commits change which
custom layouts can be used.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-29 22:16:46 +02:00
Kacper Michajłow
c7ad544c1f swresample/rematrix: don't check channels that are only reordered
Layouts with the same channels in another order need a matrix, but
nothing is mixed. The checks for channels that can be mixed rejected
them anyway, for example BL+BR to BR+BL.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-29 22:15:33 +02:00
Kacper Michajłow
bccb1b6fb8 swresample/rematrix: allow layouts of SWR_CH_MAX channels
Classic off by one check :)

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-29 22:15:33 +02:00
Kacper Michajłow
70e948e2e5 swresample/rematrix: recognize the stereo downmix pair in custom layouts
The pair is mixed like stereo if the other side has no such channels.
It was only recognized as the native layout, so a custom layout with
the pair in another order or next to unused channels was rejected for
the lack of a front channel.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-29 22:15:33 +02:00
Kacper Michajłow
4bab8327f9 swresample/rematrix: treat a single channel next to unused ones as mono
A layout of one channel is mixed like mono, whatever the channel is.
Unused channels carry no audio, so the same holds for a custom layout
that has a single channel next to them. It was rejected for being
asymmetric.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-29 22:15:33 +02:00
Kacper Michajłow
24914d60df avutil: remove libm.h
It only wrapped math.h and mathematics.h since the fallbacks went away.
Include math.h and mathematics.h directly where needed. internal.h keeps
both so that the many translation units relying on them transitively
keep building.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-12 23:52:20 +00:00
Kacper Michajłow
72b81d5b64 swresample: support AV_SAMPLE_FMT_DSD input
Convert DSD to PCM with the same 96-tap symmetric lowpass filter the
libavcodec DSD decoders use. The implementation is copied from
libavcodec/dsd.c, minus the LSBF table variants, since AV_SAMPLE_FMT_DSD
is defined as MSBF.

The libavcodec copy will be removed in future commits as decoders are
transitioned to SWR.

The conversion is stateful (per-channel filter history), so the audio
conversion functions gain a per-channel state argument.

DSD silence is the 0x69 bit pattern instead of the 0x80 used for PCM.

Only a direct DSD to float conversion function is provided. For format
pairs without a direct conversion function (e.g. DSD to s16 with equal
rates), swr_init() now falls back from the full_convert shortcut to
the generic two-stage path instead of failing, and reports unsupported
conversions with a proper error message instead of ENOMEM.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-09-06 00:48:24 +02:00
Hao Chen
88ae625e69 libswresample/aarch64: Fix sign extension in audio conversion
The channel count passed as a 32-bit register (w3) is later used
as a 64-bit register (x3) for pointer offsets without proper sign
extension, resulting in misbehavior. This commit adds an explicit
sxtw instruction to ensure the channel count is properly sign-extended.

Additionally, standardizes the use of the 32-bit w2 and w12 registers
in the core length logic across functions to prevent sign extension
issues with lengths without relying on explicit 64-bit casting, matching
expected input bounds tracking.

Signed-off-by: Hao Chen <haochenc@google.com>
2026-08-21 12:27:48 +00:00
Romain Beauxis
e4be207d82 Add missing .gitignore. 2026-08-17 22:21:44 +00:00
Andreas Rheinhardt
df86c5ef3a swresample/tests/swresample: Avoid av_assert2, remove ASSERT_LEVEL override
Said #define ASSERT_LEVEL 2 was ineffective because it followed
the inclusion of avassert.h. It only leads to warnings when
ASSERT_LEVEL is defined to something other than 2 (it is not
defined by default).

Also avoid using av_assert2() in a test tool: These are supposed to
be picky, so using always-enabled av_assert0 is appropriate.
This was probably the intention of the ASSERT_LEVEL override
all along.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-08-15 18:51:18 +02:00
Andreas Rheinhardt
3956f2ffe3 av*/x86/resample,h264_intrapred: Avoid using PSHUFLW
It is useless in the absence of mmx.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-08-14 21:21:52 +02:00
James Almer
c39bc13fdb swresample/tests/rematrix: print rows in layout order
Otherwise, custom layouts will be printed as if they were in native order.

Signed-off-by: James Almer <jamrial@gmail.com>
2026-08-14 16:11:08 -03:00
Ayoub Nabil Boubagrat
d02bad0c90 swresample/rematrix: accept unused channels
custom layouts containing AV_CHAN_UNUSED were rejected by
swr_build_matrix2().

accept unused channels in input and output layouts. preserve their
physical positions, clear input columns, and leave output rows silent.

add fate coverage for both cases. this fixes #24094.

Signed-off-by: Ayoub Nabil Boubagrat <237098474+ayoubnabil@users.noreply.github.com>
2026-08-14 19:08:29 +00:00
Ayoub Nabil Boubagrat
85d2cfd52e libswresample/tests/rematrix: uninit channel layouts
release parsed channel layouts before exiting.

Signed-off-by: Ayoub Nabil Boubagrat <237098474+ayoubnabil@users.noreply.github.com>
2026-08-14 19:08:29 +00:00
Andreas Rheinhardt
7a205ebf3a swresample/rematrix: Avoid repeated calls to av_channel_layout* funcs
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-08-12 00:09:05 +02:00
Andreas Rheinhardt
715d7d85d6 swresample/rematrix: Use AVChannel in av_channel_layout_index_from_chan
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-08-12 00:09:05 +02:00
James Almer
afd6b8451f libswresample/tests/rematrix: rewrite into a matrix printing tool
Signed-off-by: James Almer <jamrial@gmail.com>
2026-08-09 13:55:37 -03:00
James Almer
77998c0dec swresample/rematrix: handle missing channels from 22.2 layout
Signed-off-by: James Almer <jamrial@gmail.com>
2026-08-09 13:55:37 -03:00
Ayoub Nabil Boubagrat
5c395992f9 swresample/rematrix: handle top-back channels
top-back channels are currently left unaccounted and can be dropped during downmixing.

when the output retains top-front channels, follow IAMF 1.1.0 and fold top-back into top-front at 0.707. prefer this path over ear-level rear channels to preserve the height layer in x.1.4 to x.1.2 downmixes.

when no matching height output remains, map top-back to back or side channels, then fall back to front or mono outputs. handle top-back center separately and add direct tests for every matrix path.

Signed-off-by: Ayoub Nabil Boubagrat <237098474+ayoubnabil@users.noreply.github.com>
2026-08-07 02:33:33 +00:00
Ayoub Nabil Boubagrat
c717827955 swresample/rematrix: use unity gain for top-front downmix
ITU-R BS.2127-1 maps U+030 and U-030 to the matching ear-level front channels at unity gain.

the current matrix uses 0.707 when the input also contains front channels. use 1.0 instead.

Signed-off-by: Ayoub Nabil Boubagrat <237098474+ayoubnabil@users.noreply.github.com>
2026-08-07 02:33:33 +00:00
James Almer
9646228fd6 swresample/rematrix: print custom downmix matrix coefficients
Similar to how it's done to the matrix built in auto_matrix().

Signed-off-by: James Almer <jamrial@gmail.com>
2026-07-11 19:32:17 -03:00
Michael Niedermayer
d66e84695b Bump minor after release/9.0 branch on master
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-26 02:47:51 +02:00
Michael Niedermayer
47e9d68e20 Bump minor for release/9.0
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-26 02:43:34 +02:00
Andreas Rheinhardt
762b94e672 libs: Bump major version of all libraries
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-23 19:15:57 +02:00
Michael Niedermayer
4171581953 swresample/x86/resample: write only int16 in the int16 resampler
The resample asm code as it is currently handles 1 sample at a time

The asm code should be redesigned and handle more than 1 sample at a
time. That is the whole purpose of SIMD. There is also multiple samples
available that need identical handling like from several channels or
similar handling from other points in time.

Such redesign would make the resampler faster and would change the
requirements of padding and maybe memory layout. So it seems simpler
to just avoid overwriting in the asm as it is today than to have
the allocation handle specific overallocation for asm code that
ideally should be redesigned

Fixes writing 16bits over the end of the array

This is an alternative fix for https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23053

Found-by: Ivan Grigorev <ivangrigoriev@meta.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-06-14 15:34:43 +00:00
Ivan Grigorev
bdbb580d9c swresample/tests: add resample realloc regression test
Add a regression test exercising the swr_convert(N) -> swr_convert(2N)
edge case: the second call reuses the internal preout buffer at full
capacity, with no trailing slack from swri_realloc_audio()'s amortized
doubling. internal_sample_fmt is forced to S16P to reach the int16 SIMD
resample path, where ff_resample_common_int16_sse2 overruns its
destination by 2 bytes on the last iteration.

Without a resampler fix this test fails under valgrind/ASAN with a
heap-buffer-overflow (Invalid write of size 4, 2 bytes past the end).

Signed-off-by: Ivan Grigorev <ivangrigoriev@meta.com>
2026-06-14 15:34:43 +00:00
Martin Storsjö
c5a3cb00b7 libswresample/arm: Change to the common indentation size
These files consistently aligned instructions to 4/24 columns,
while we commonly indent arm/aarch64 assembly to 8/24 columns.
2026-04-29 13:49:27 +03:00
Andreas Rheinhardt
999ccf6495 swresample/x86/{audio_convert,rematrix}: Remove remnants of MMX
Forgotten in 2b94f23b06,
4e51e48ebd and
374b3ab03c.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-13 01:16:46 +02:00
Michael Niedermayer
c1263a3dd9 Bump versions for master after release/8.1
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-08 02:31:23 +01:00
Michael Niedermayer
67c886222f Bump versions for release/8.1
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-08 02:29:20 +01:00
Michael Niedermayer
17cad7ac75 swresample/resample_template: add casts to avoid undefined overflows
resample_linear can produce overflows with craftet input,
The added casts should have no effect on the binary output or the operations they
just change things to a defined regime

Fixes: signed integer overflow: 2069416960 + 78151680 cannot be represented in type 'int'
Fixes: 472047214/clusterfuzz-testcase-minimized-ffmpeg_SWR_fuzzer-6374046976770048

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-03-02 18:11:58 +01:00
Michael Niedermayer
0e3ac1f4f9 swresample: Check ch layouts in swr_alloc_set_opts2()
This way we can error out earlier

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-02-15 20:16:12 +01:00
Michael Niedermayer
906e3edc70 swresample: Check user chlayout in swr_set_matrix()
All callers in FFmpeg check this already, but it is a public
function that can plausibly be given more channels.
In which case out of array writes would occur

This is likely a regression from when channel layouts where extended
to support more than 64 channels

Found-by: 이동준 <ldj6192@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-02-15 20:16:11 +01:00
Andreas Rheinhardt
509be049b6 swresample/{audioconvert,rematrix}: Don't check for HAVE_MMX
There are no MMX functions left in all of libswresample, so checking
for it makes no sense. Notice that configure currently disables x86asm
if mmx is disabled, so the check is also redundant.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-02-13 09:21:33 +01:00
Andreas Rheinhardt
374b3ab03c swresample/x86/audio_convert: Remove remnants of MMX
Forgotten in 2b94f23b06.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-02-13 09:21:33 +01:00
Kacper Michajłow
018041f150 swresample/soxr_resample: pass initialized data to soxr_process() in flush()
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-12-08 21:31:13 +00:00
Andreas Rheinhardt
d5a47bf2b3 swresample/x86/Makefile: Only compile ASM init files when X86ASM is enabled
To do so, simply add these init files to X86ASM-OBJS instead of OBJS
in the Makefile. The former is already used for the actual assembly
files, but using them for the C init files just works, because the build
system uses file extensions to derive whether it is a C or a NASM file.

This avoids compiling unused function stubs and also reduces our
reliance on DCE: We don't add %if checks to the asm files except
for AVX, AVX2, FMA3, FMA4, XOP and AVX512, so all the MMX-SSE4
functions will be available. It also allows to remove HAVE_X86ASM checks
in these init files.

(x86/ops.c has already been put in X86ASM-OBJS.)

Reviewed-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-11-30 22:20:13 +01:00
Andreas Rheinhardt
2a90e7d725 av{codec,util}/tests: Remove pointless undefs
Before commit e96d90eed6 lavu/internal.h
contained redefined various discouraged/forbidden functions to induce
compilation failures upon use, like e.g.
 #define malloc please_use_av_malloc
In order to use these functions, some files had to undefine these
macros. This commit removes the remaining pointless undefs.

Reviewed-by: Rémi Denis-Courmont <remi@remlab.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-11-24 16:48:31 +01:00
Andreas Rheinhardt
08b74d5d5c swresample/swresample: Avoid av_unused
Possible now that -Wdeclaration-after-statement is no longer used.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-11-09 13:42:27 +01:00
Kacper Michajłow
d6cb0d2c2b ALL: move av_unused to conform with standard requirement
This is required placement by standard [[maybe_unused]] attribute, works
the same for __attribute__((unused)).

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-09-26 16:15:46 +00:00
renjianguang
9e4ff4732c swresample/swresample: Delete unused code
The uch option has been removed

Signed-off-by: renjianguang <renjianguang@xiaomi.com>
2025-09-16 11:27:39 +00:00
Andreas Rheinhardt
162e5a1121 swresample/rematrix_template: Constify get_mix_any_func
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-15 17:52:22 +02:00
Andreas Rheinhardt
fe06d5533f swresample/x86/rematrix_init: Avoid allocation for native_simd_one
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-15 17:52:22 +02:00
Andreas Rheinhardt
853229d140 swresample/rematrix: Avoid allocation for native_one
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-15 17:52:22 +02:00
Andreas Rheinhardt
c48add609a swresample/swresample_internal: Use union for float, int matrix
Saves 16KiB from SwrContext.
(FATE would also pass if one made the double matrix part of
the union, too, but I don't know whether this is truely correct,
because swri_rematrix() accesses the double matrix (to check whether
it is equal to 1.0) even when one of the other matrices is in use.)

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-09-15 17:52:22 +02:00