1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-11-23 21:54:53 +02:00
Commit Graph

121456 Commits

Author SHA1 Message Date
Jack Lau
469aad3897 avformat/whip: add ICE consent freshness support
Refer to RFC 9725 4.2,
"Once a session is set up, consent freshness as per
[RFC7675] SHALL be used to detect non-graceful
disconnection by full ICE implementations and DTLS
teardown for session termination by either side"

Refer to RFC 7675,
send STUN Binding request every 5s,
expire consent after 30s without response,
terminate session when the consent expired.

TODO:
Random consent check interval (4-6s) will be
added later.

Co-authored-by: Sergio Garcia Murillo <sergio.garcia.murillo@gmail.com>
Signed-off-by: Jack Lau <jacklau1222@qq.com>
2025-10-09 09:29:25 +00:00
Jack Lau
aba84db96f avformat/whip: add WHIP_US_PER_MS macro to replace 1000
Signed-off-by: Jack Lau <jacklau1222@qq.com>
2025-10-09 09:29:25 +00:00
Manuel Lauss
aa91ae25b8 avcodec/sanm: minor comment and size detection changes
Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:02 +02:00
Manuel Lauss
c46c1cb0db avcodec/sanm: remove rotate_code context member
Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:02 +02:00
Manuel Lauss
72df8f271d avcodec/sanm: implement 3 blits for codec37/47/48
The various game engines implement the following blit types, from the decoded
result to the main canvas:
- normal (opaque) blit (c37/c47/c48)
- masked blit (c37/c48)
- interpolated-frame blit (c48)
  Here an artificial frame is generated by looking up the pixels
  from both buffers and picking a color from the interpolation table
  for the artificial frame.
  This is only supported in the decoder of "Making Magic".

Implement and hook up these 3 schemes for each of the 3 compresstion types,
and switch codec20 to a call to the opaque blit function.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:02 +02:00
Manuel Lauss
d7d97ea32c avcodec/sanm: partially fix codec48 for Making Magic
Making Magic makes use of codec48 flag bit 0, which, when set,
means NOT to swap both buffers on even sequence numbers.

This fixes most of the artifacts in the Making Magic videos.
It's not complete though, bits 1 and 4 still need to be handled.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:02 +02:00
Manuel Lauss
9e72b2f2d0 avcodec/sanm: codec37/47/48 updates
- align the incoming widths to 4(c37) / 8(c47/78) pixels. LucasArts
   game videos have these aligned.
- since these codecs use their 2/3 buffers for themselves, adjust the
  stride to the aligned width, keeping it even, which gets rid of
  an unaligned store in c48_4to8() found by the fuzzer with an
  odd stride.
- clear the whole diff buffer, not just the area described by w/h.
- adjust the RLE "decoded_size" to the product of the aligned width
   and reported height.

These changes are the result of various fuzzer-found issues; all my
test videos still work fine.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:02 +02:00
Manuel Lauss
0eb58e40cb avcodec/sanm: codec20 left/top offset support
Add left/top offsets and clipping to codec20 (raw images),
use it for the copying of codec37/47/48 images to main buffer.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
a108be2ba3 avcodec/sanm: for ANIM codecs with own buffers, really check dimensions
Codec37/47/48 have their own buffers; left/top are applied after
the decoding is done when copying to the main buffer.  Don't add left/top
to their width/height when doing checks against the established buffer sizes.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
b6a9c4671a avcodec/sanm: reimplement XPAL algorithm identical to DOS smush engine
This implements XPAL the same way the DOS/Windows players do, with an
additional 768-entry table holding the palette left-shifted by 7 bits,
and adding the deltapal values to this.

This results in a perfectly smooth day-to-night transition in the last
30 seconds of the Outlaws RAE.SAN (ending) video, while before there
were visible brightness "pulses" when a new palette was loaded.
It also fixes color banding in the The Dig Intro (sq1.san), in the
scene showing the shuttle launch pad and the night sky.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
4316914b39 avcodec/sanm: codec37: comp1: guard against invalid mv index
the c37 mvtable has only 255 pairs, change index 255 to zero to
avoid reading outside the table boundaries.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
5f1f5dd2d4 avcodec/sanm: guard against image area growing larger than buffer
When checking for oversized frames, check not only for the width
and height being larger, but also the area not outgrowing the
allocated buffer.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
556cef27d9 avcodec/sanm: enforce SANM min and max sizes at decode_init()
Enforce at least 8x8 and at max 800x600 for SANM/BL16.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
70b04717d0 avcodec/sanm: distrust dimensions for ANIM in decode_init
When decode_init() is called for ANIM content, zero the dimensions
set in avctx width/height. Only SANM files have image dimensions in
their header, while ANIM do not.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
0802044d81 avcodec/sanm: codec48: reimplement block scaling
Reimplement opcodes 0xFF and 0xFD the same way the c48 decoder
in the "Mysteries of the Sith" game engine does it:
The source pixel(s) and various pixels from inside the same and above
block of the second to last image rendered to the destination buffer
are used together with the interpolation table to generate a 4x4 pattern,
which is then expanded by doubling each pixel horizontally and vertically
to produce the final 8x8 block.

This fixes visible artifacts in frames 25-50 of the S1L1OCS.SAN
video of Mysteries of the Sith.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
b99b7a6f90 avcodec/sanm: change codec37 opcode FE to 4 2x2 blocks
It was initially implemented as 4 4x1 blocks, reimplement it as 4 2x2 blocks.
Fixes a few The Dig videos, esp. black dots on the asteroid in the
intro scene.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
d618577747 avcodec/sanm: check codec48 subblock mv index
Codec48 opcodes F9 and FC take per-subblock indices into the motion vector
table from the source stream, however the table has only 255 entries.
Luckily, index 255 is index 0 of the following table, which means no
motion vector, the same as index 0 of the current table.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
dd875f56b7 avcodec/sanm: invalidate STOR data when subversion changes
since the STOR data is a different format.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
b7e55ef8a1 avcodec/sanm: per-fobj GetByteContext
Create a separate GetByteContext from the general one, to be able
to limit the size of the FOBJ to the size described in the tag size.
Otherwise each fobj could theoretically use all the remaining data
in the FRME (which also contains audio, subtitles, ...).

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
a0c4dfc63b avcodec/sanm: handle FTCH on video start
some videos have a FTCH at the start of the video, to restore the
last image produced by the previous game file.  This leads to
ugly messages like these:

[sanm @ 0x7f18cc001980] [IMGUTILS @ 0x7f18d7ffe8e0] Picture size 0x0 is invalid
[sanm @ 0x7f18cc001980] video_get_buffer: image parameters invalid
[sanm @ 0x7f18cc001980] get_buffer() failed

Fix this by not setting the got_frame_ptr when there is nothing to
restore/fetch.  Seen with a lot of RA1 and the RA2 Level 11/12 videos.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:01 +02:00
Manuel Lauss
7c205b5397 avcodec/sanm: rename motion_vectors[] table to c47_mv[]
Rename the generic motion_vectors to c47_mv, as this vector table
was initially introduced with codec47 which predates bl16 by 1-2 years,
and bl16 is a development of codec47 (with a bit of c48 thrown in).

No functional change.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
3945d100ef avcodec/sanm: remove unused SANMFrameHeader
Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
2ef26c30eb avcodec/sanm: implement BL16 subcodecs 1 and 7
Both of these encode a quarter-sized keyframe, with missing pixels
interpolated from the immediate neighbours.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
b1a7f8b7cf avcodec/sanm: factor out the ANIM decoding into separate function
Mainly for readability. No functional changes.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
49c552d066 avcodec/sanm: restructure SANM like the other block codecs
Restructe the SANM (or BL16 as LucasArts calls it) decoder to make it
look like the others, as it is basically a development of old_codec47
for rgb565 values.

No functional changes.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
4d5e87eaa4 Revert "avcodec/sanm: Check w,h,left,top"
This reverts commit 134fbfd1dc.

As it breaks valid uses of this in Rebel Assault 1 videos.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
75b6937527 avcodec/sanm: reset rotate_code every iteration
and eliminate the explicit reset in the other decoders that
don't need it.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
de7db62acc avcodec/sanm: rename process_block to codec47_block
the new name better indicates where it belongs to.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
043dafc4c2 avcodec/sanm: codec37/47/48 size checks
Add more size checks to old_codec37/47/48, esp. the headers.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
f98cd66b4b avcodec/sanm: codec47: read the small codebook
codec47 carries a 4-byte small codebook in its header. Read those
4 bytes into context member instead of awkwardly redirecting the
bytestream pointer every time it needs to be accessed.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
72e6206c88 avcodec/sanm: partially fix codec48
The mv check introduced with d5bdb0b705 broke MotS videos:
- their height (300 lines) is 37,5 blocks; unfortunately the videos try to
  access up to 1 block more.
  Extend the mv check to the aligned_height, which fixes most artifacts.
- don't return an error when an mv is invalid; rather skip the (subblock).
  Gets rid of almost all artifacts.

Some artifacts still remain, esp in space scenes where the original
encoder apparently fetched black pixels from outside of the aligned
height.  An increase of the buffer size by 8 lines will fix that later.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
24ce42b406 avcodec/sanm: codec4 improvements
- don't draw outside the buffers
- don't wrap around when coordinates go over the edge

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
dfe4a0626f avcodec/sanm: codec31 improvements
- don't draw outside the buffers
- don't wrap around when coordinates go over the edge
  this is especially noticeable in the e.g. O1OPEN.ANM, C1C3PO.ANM
  RA1 files with planets wrapping around.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:29:00 +02:00
Manuel Lauss
da4b88494c avcodec/sanm: codec1 improvements
- don't draw outside the buffers
- don't wrap around when coordinates go over the edge
  this is especially noticeable in the e.g. O1OPEN.ANM, C1C3PO.ANM
  RA1 files with planets wrapping around.

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:28:59 +02:00
Manuel Lauss
d18c25f1a9 avcodec/sanm: codec21 improvements
- don't draw outside the buffers
- don't wrap around when coordinates go over the edge

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:28:59 +02:00
Manuel Lauss
67b28acba3 avcodec/sanm: codec23 improvements
- don't draw outside the buffers
- don't wrap around when coordinates go over the edge

Signed-off-by: Manuel Lauss <manuel.lauss@gmail.com>
2025-10-09 10:28:59 +02:00
Kacper Michajłow
3a8ea78b88 avutil/attributes: add AV_HAS_ATTRIBUTE
Maybe useful and to fix MSVC preprocessor warnings.

Fixes: afad332d77
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-10-09 06:25:06 +02:00
Zhao Zhili
9034ca30ef avformat/flacdec: fix self assign warning 2025-10-09 03:41:29 +00:00
Kacper Michajłow
afad332d77 avutil/attributes: use __has_attribute to test for format attribute
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-10-09 03:35:16 +00:00
Kacper Michajłow
086597adae avutil/attributes: don't force format checking to __gnu_printf__ on mingw build
Use __MINGW_{PRINTF,SCANF}_FORMAT which matches the format check for
implementation that is actually used.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-10-09 03:35:16 +00:00
James Almer
4377affc28 avcodec/hevc/refs: don't unconditionally discard non-IRAP frames if no IRAP frame was seen before
Should fix issue #20661

Signed-off-by: James Almer <jamrial@gmail.com>
2025-10-09 02:52:46 +00:00
Andreas Rheinhardt
378d5bb08a avcodec/x86/fpel: Add blocksize x blocksize avg/put functions
This commit deduplicates the wrappers around the fpel functions
for copying whole blocks (i.e. height equaling width). It does
this in a manner which avoids having push/pop function arguments
when the calling convention forces one to pass them on the stack
(as in 32bit systems).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-10-08 20:40:53 +02:00
Andreas Rheinhardt
ad498f9759 avcodec/x86/cavsdsp: Remove MMXEXT Qpeldsp
Superseded by SSE2. Saves about 11630B here.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-10-08 20:40:08 +02:00
Andreas Rheinhardt
650098955e avcodec/x86/cavs_qpel: Add SSE2 vertical motion compensation
This is not based on the MMXEXT one, because the latter is quite
suboptimal: Motion vector types mc01 and mc03 (vertical motion vectors
with remainder of one quarter or three quarter) use different neighboring
lines for interpolation: mc01 uses two lines above and two lines below,
mc03 one line above and three lines below. The MMXEXT code uses
a common macro for all of them and therefore reads six lines
before it processes them (even reading lines which are not used
at all), leading to severe register pressure.

Another difference to the old code is that the positive and negative
parts of the sum to calculate are accumulated separately and
the subtraction is performed with unsigned saturation, so
that one can avoid biasing the sum.

The fact that the mc01 and mc03 filter coefficients are mirrors
of each other has been exploited to reduce mc01 to mc03.

But of course the most important different difference between
this code and the MMXEXT one is that XMM registers allow to
process eight words at a time, ideal for 8x8 subblocks,
whereas the MMXEXT code processes them in 4x8 or 4x16 blocks.

Benchmarks:
avg_cavs_qpel_pixels_tab[0][4]_c:                      917.0 ( 1.00x)
avg_cavs_qpel_pixels_tab[0][4]_mmxext:                 222.0 ( 4.13x)
avg_cavs_qpel_pixels_tab[0][4]_sse2:                    89.0 (10.31x)
avg_cavs_qpel_pixels_tab[0][12]_c:                     885.7 ( 1.00x)
avg_cavs_qpel_pixels_tab[0][12]_mmxext:                223.2 ( 3.97x)
avg_cavs_qpel_pixels_tab[0][12]_sse2:                   88.5 (10.01x)
avg_cavs_qpel_pixels_tab[1][4]_c:                      222.4 ( 1.00x)
avg_cavs_qpel_pixels_tab[1][4]_mmxext:                  57.2 ( 3.89x)
avg_cavs_qpel_pixels_tab[1][4]_sse2:                    23.3 ( 9.55x)
avg_cavs_qpel_pixels_tab[1][12]_c:                     216.0 ( 1.00x)
avg_cavs_qpel_pixels_tab[1][12]_mmxext:                 57.4 ( 3.76x)
avg_cavs_qpel_pixels_tab[1][12]_sse2:                   22.6 ( 9.56x)
put_cavs_qpel_pixels_tab[0][4]_c:                      750.9 ( 1.00x)
put_cavs_qpel_pixels_tab[0][4]_mmxext:                 210.4 ( 3.57x)
put_cavs_qpel_pixels_tab[0][4]_sse2:                    84.2 ( 8.92x)
put_cavs_qpel_pixels_tab[0][12]_c:                     731.6 ( 1.00x)
put_cavs_qpel_pixels_tab[0][12]_mmxext:                210.7 ( 3.47x)
put_cavs_qpel_pixels_tab[0][12]_sse2:                   84.1 ( 8.70x)
put_cavs_qpel_pixels_tab[1][4]_c:                      191.7 ( 1.00x)
put_cavs_qpel_pixels_tab[1][4]_mmxext:                  53.8 ( 3.56x)
put_cavs_qpel_pixels_tab[1][4]_sse2:                    24.5 ( 7.83x)
put_cavs_qpel_pixels_tab[1][12]_c:                     179.1 ( 1.00x)
put_cavs_qpel_pixels_tab[1][12]_mmxext:                 53.9 ( 3.32x)
put_cavs_qpel_pixels_tab[1][12]_sse2:                   24.0 ( 7.47x)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-10-08 20:40:08 +02:00
Andreas Rheinhardt
74a88c0c11 avcodec/x86/cavsdsp: Add SSE2 mc20 horizontal motion compensation
Basically a direct port of the MMXEXT one. The main difference
is of course that one can process eight pixels (unpacked to words)
at a time, leading to speedups.

avg_cavs_qpel_pixels_tab[0][2]_c:                      700.1 ( 1.00x)
avg_cavs_qpel_pixels_tab[0][2]_mmxext:                 158.1 ( 4.43x)
avg_cavs_qpel_pixels_tab[0][2]_sse2:                    86.0 ( 8.14x)
avg_cavs_qpel_pixels_tab[1][2]_c:                      171.9 ( 1.00x)
avg_cavs_qpel_pixels_tab[1][2]_mmxext:                  39.4 ( 4.36x)
avg_cavs_qpel_pixels_tab[1][2]_sse2:                    21.7 ( 7.92x)
put_cavs_qpel_pixels_tab[0][2]_c:                      525.7 ( 1.00x)
put_cavs_qpel_pixels_tab[0][2]_mmxext:                 148.5 ( 3.54x)
put_cavs_qpel_pixels_tab[0][2]_sse2:                    75.2 ( 6.99x)
put_cavs_qpel_pixels_tab[1][2]_c:                      129.5 ( 1.00x)
put_cavs_qpel_pixels_tab[1][2]_mmxext:                  36.7 ( 3.53x)
put_cavs_qpel_pixels_tab[1][2]_sse2:                    19.0 ( 6.81x)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-10-08 20:40:08 +02:00
Andreas Rheinhardt
54598238e4 tests/checkasm: Add CAVS qpel test
This test already uncovered a bug in the vertical qpel motion
compensation code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-10-08 20:40:08 +02:00
Andreas Rheinhardt
cc2e2f12ca avcodec/x86/cavsdsp: Fix vertical qpel motion compensation
The prediction involves terms of the form
(-1 * s0 - 2 * s1 + 96 * s2 + 42 * s3 - 7 * s4 + 64) >> 7,
where the s values are in the range of 0..255.
The sum can have values in the range -2550..35190, which
does not fit into a signed 16bit integer. The code uses
an arithmetic right shift, which does not yield the correct
result for values >= 2^15; such values should be clipped
to 255, yet are clipped to 0 instead.

Fix this by shifting the values by 4096, so that the range
is positive, use a logical right shift and subtract 32.

bunny.mp4 from the FATE suite can be used to reproduce the problem.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-10-08 20:40:08 +02:00
Andreas Rheinhardt
ec2fe94b3f avcodec/cavs: Remove unused parameter
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-10-08 20:40:08 +02:00
Michael Niedermayer
7896cc67c1 avcodec/exr: Check that DWA has 3 channels
The implementation hardcodes access to 3 channels, so we need to check that
Fixes: out of array access
Fixes: BIGSLEEP-445394503-crash.exr

Found-by: Google Big Sleep
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-10-08 00:27:49 +00:00
Michael Niedermayer
c911e00011 avcodec/exr: Round dc_w/h up
Without rounding them up there are too few dc coeffs for the blocks.
We do not know if this way of handling odd dimensions is correct, as we have
no such DWA sample.
thus we ask the user for a sample if she encounters such a file

Fixes: out of array access
Fixes: BIGSLEEP-445392027-crash.exr

Found-by: Google Big Sleep
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-10-08 00:27:49 +00:00