1
0
Fork 0
Commit Graph

50204 Commits

Author SHA1 Message Date
Andreas Rheinhardt 2eab5a1f54 avcodec/aac/aacdec: Fix linking errors with only one decoder enabled
This is achieved by using function pointers for AAC SBR functions.
This unfortunately necessitated to use void* in
ff_aac_sbr_apply(_fixed).
Fixes ticket #10999.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-07 12:33:50 +02:00
Mandava, Mounika b1037d4ebe lavc/qsvenc: add support for oneVPL string API
A new option -qsv_params <str> is added, where <str> is a :-separated
list of key=value parameters.

Example:
$ ffmpeg -y -f lavfi -i testsrc -vf "format=nv12" -c:v h264_qsv -qsv_params
"TargetUsage=1:GopPicSize=30:GopRefDist=2:TargetKbps=5000" -f null -

Signed-off-by: Mounika Mandava <mounika.mandava@intel.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2024-05-07 11:06:37 +08:00
Haihao Xiang df76c3756d lavc/qsvenc: always allocate the array to store mfxExtBuffer points
This allows us to append mfxExtBuffer per user's settings

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2024-05-07 11:06:37 +08:00
Andreas Rheinhardt f5d2dc7b4b avcodec/aac/aacdec_(fixed|float): Set AACDecDSP, AACDecProc directly
This is more in line with how we initialize DSP functions
and avoids tables of function pointers as well as relocations
for these.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-07 00:02:57 +02:00
Andreas Rheinhardt 8762aa4d62 avcodec/aac/aacdec: Move init functions to aacdec_fixed/float
This allows to merge it with AACDecDSP.init and remove the latter
(it is called only once anyway); it also allows to make
the fixed/float AACDecDSP and AACDecProc implementations internal
to aacdec_fixed/float.c (which also fixes a violation of our
naming conventions). And it some linker errors when either decoder
is disabled.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-07 00:01:39 +02:00
Andreas Rheinhardt 0fc3d8e4d6 avcodec/aac/aacdec: Avoid compiling latm decoder if disabled
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-07 00:00:04 +02:00
Andreas Rheinhardt d4fb110f5c avcodec/aac/aacdec: Mark flush as cold
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:59:43 +02:00
Andreas Rheinhardt 41922bef7a avcodec/aac/aacdec_(fixed|float): Avoid AAC_RENAME, INTFLOAT
Unnecessary now that this has been detemplatized.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:59:27 +02:00
Andreas Rheinhardt c13b5d96c8 avcodec/aac/aacdec_float: Call ff_aac_float_common_init() only once
That's enough.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:59:10 +02:00
Andreas Rheinhardt 41ea317ced avcodec/aac/aacdec: Avoid branch to set sample_fmt
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:58:58 +02:00
Andreas Rheinhardt ef16882e8f avcodec/aac/aacdec: Move channel number check out of init_dsp()
Also move initializing random_state.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:58:31 +02:00
Andreas Rheinhardt e4e9144a5c avcodec/aac/aacdec: Remove unnecessary ff_thread_once()
ff_aacdec_common_init_once() already uses its own AVOnce.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:58:08 +02:00
Andreas Rheinhardt 44474dd7b9 avcodec/aacsbr: Fix type mismatch
ff_aac_sbr_apply() and ff_aac_sbr_apply_fixed() still used
pointers to INTFLOAT which is float or int depending upon
whether USE_FIXED is set or not; in particular, according
to these declarations both functions have the same type.
But that is wrong and given that aacdec.c sets USE_FIXED,
it sees the wrong type for ff_aac_sbr_apply().
This leads to a -Wlto-type-mismatch warning when using lto [1].
Fix this by avoiding INTFLOAT in aacsbr.h (which also means
that aac_defines.h need not be included there any more).

[1]: https://fate.ffmpeg.org/log.cgi?slot=x86_64-archlinux-gcc-lto&time=20240506022217&log=compile

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:57:41 +02:00
Andreas Rheinhardt e6bf540048 avcodec/aactab: Provide ff_ltp_coef, ff_tns_tmp2_map unconditionally
The fixed point decoder needs it since
905fdb0601.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:56:40 +02:00
Mark Thompson 7b482815a0 vulkan_av1: Fix force_integer_mv value 2024-05-06 20:17:50 +01:00
Mark Thompson b73e6af337 vaapi_av1: Fix force_integer_mv value 2024-05-06 20:17:50 +01:00
Mark Thompson b62d385ecf nvdec_av1: Use av1dec force_integer_mv value 2024-05-06 20:17:50 +01:00
Mark Thompson e5a5125bbe vdpau_av1: Use av1dec force_integer_mv value 2024-05-06 20:17:50 +01:00
Mark Thompson 5162247092 dxva2_av1: Use av1dec force_integer_mv value 2024-05-06 20:17:50 +01:00
Mark Thompson 6f56e0e7e5 av1dec: Add force_integer_mv derived field for decoder use
This is not the same as the syntax element value in the frame header
because the specification parsing tables override the value on intra
frames.
2024-05-06 20:17:50 +01:00
Rémi Denis-Courmont 9e77188cba lavc/ac3dsp: R-V Zbb ac3_exponent_min
SiFive U74:
ac3_exponent_min_reuse0_c:       10.0
ac3_exponent_min_reuse0_rvb_b:    8.0
ac3_exponent_min_reuse1_c:     2924.7
ac3_exponent_min_reuse1_rvb_b: 1803.0
ac3_exponent_min_reuse2_c:     5043.0
ac3_exponent_min_reuse2_rvb_b: 2827.5
ac3_exponent_min_reuse3_c:     7028.7
ac3_exponent_min_reuse3_rvb_b: 3872.0
ac3_exponent_min_reuse4_c:     8824.2
ac3_exponent_min_reuse4_rvb_b: 5122.2
ac3_exponent_min_reuse5_c:    10487.5
ac3_exponent_min_reuse5_rvb_b: 6412.2
2024-05-06 22:10:16 +03:00
Andreas Rheinhardt 2f8bf90054 avcodec/allcodecs: Remove LIBX264_CONST
Possible since 71669f2ad5.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 14:51:56 +02:00
Nuo Mi a9586a00df avcodec/vvcdec: ff_vvc_frame_submit, avoid initializing task twice.
For some error bitstreams, a CTU belongs to two slices/entry points.
If the decoder initializes and submmits the CTU task twice, it may crash the program
or cause it to enter an infinite loop.

Reported-by: Frank Plowman <post@frankplowman.com>
2024-05-06 20:22:42 +08:00
Michael Niedermayer 96449cfeae
avcodec/mpegvideo_enc: Fix 1 line and one column images
Fixes: Ticket10952
Fixes: poc21ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-06 03:00:41 +02:00
Michael Niedermayer a3bb269db9
avcodec/amrwbdec: assert mode to be valid in decode_fixed_vector()
Inspired-by: CID1473499 Uninitialized scalar variable

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-06 03:00:41 +02:00
Michael Niedermayer a2ec2bd493
avcodec/wavarc: fix integer overflow in decode_5elp() block type 2
Fixes: signed integer overflow: 2097152000 + 107142979 cannot be represented in type 'int'
Fixes: 67919/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_WAVARC_fuzzer-5955101769400320

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-06 03:00:41 +02:00
Michael Niedermayer c7075cdb67
avcodec/dovi_rpuenc: Initialize bl_compat_id
Fixes: CID1596607 Uninitialized scalar variable

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-06 03:00:40 +02:00
Rémi Denis-Courmont 38f67a32b3 lavc/ac3dsp: R-V V min_exponents
T-Head C908:
ac3_exponent_min_reuse0_c:         7.5
ac3_exponent_min_reuse0_rvv_i32:   7.5
ac3_exponent_min_reuse1_c:      1820.7
ac3_exponent_min_reuse1_rvv_i32: 102.5
ac3_exponent_min_reuse2_c:      3088.5
ac3_exponent_min_reuse2_rvv_i32: 138.7
ac3_exponent_min_reuse3_c:      5073.7
ac3_exponent_min_reuse3_rvv_i32: 174.7
ac3_exponent_min_reuse4_c:      4624.2
ac3_exponent_min_reuse4_rvv_i32: 204.2
ac3_exponent_min_reuse5_c:      5138.7
ac3_exponent_min_reuse5_rvv_i32: 238.0
2024-05-04 10:17:11 +03:00
sunyuechi 5bc3b7f513 lavc/rv40dsp: R-V V chroma_mc
This is similar to h264, but here we use manual_avg instead of vaaddu
because rv40's OP differs from h264. If we use vaaddu,
rv40 would need to repeatedly switch between vxrm=0 and vxrm=2,
and switching vxrm is very slow.

C908:
avg_chroma_mc4_c: 2330.0
avg_chroma_mc4_rvv_i32: 602.7
avg_chroma_mc8_c: 1211.0
avg_chroma_mc8_rvv_i32: 602.7
put_chroma_mc4_c: 1825.0
put_chroma_mc4_rvv_i32: 414.7
put_chroma_mc8_c: 932.0
put_chroma_mc8_rvv_i32: 414.7

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
2024-05-03 18:00:53 +03:00
sunyuechi 7d0673db7e lavc/blockdsp: R-V V fill_block
C908:
blockdsp.fill_block_tab[0]_c: 549.7
blockdsp.fill_block_tab[0]_rvv_i64: 48.2
blockdsp.fill_block_tab[1]_c: 77.0
blockdsp.fill_block_tab[1]_rvv_i64: 19.7

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
2024-05-03 17:49:23 +03:00
Rémi Denis-Courmont 6cd97cd797 lavc/ac3dsp: R-V V sum_square_butterfly_float
As we do not need to widen accumulators to 64 bits, we effectively get
double capacity for unrolling compared to the integer function. This
explains the slightly better performance gains.

ac3_sum_square_bufferfly_float_c:       65.2
ac3_sum_square_bufferfly_float_rvv_f32: 12.2
2024-05-03 17:48:46 +03:00
Rémi Denis-Courmont 6459966beb lavc/ac3dsp: R-V V sum_square_butterfly_int32
ac3_sum_square_bufferfly_int32_c:       61.0
ac3_sum_square_bufferfly_int32_rvv_i64: 14.7
2024-05-03 17:48:46 +03:00
Michael Niedermayer 69b4d9736b
avcodec/av1dec: Change bit_depth to int
Suggested-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-03 02:35:50 +02:00
Michael Niedermayer fd7d24fa3f
avcodec/av1dec: bit_depth cannot be another values than 8,10,12
Fixes: CID1544265 Logically dead code

Sponsored-by: Sovereign Tech Fund
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-03 02:35:50 +02:00
Michael Niedermayer f9218e4d52
avcodec/avs3_parser: assert the return value of init_get_bits()
Fixes: CID1492867 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-03 02:35:50 +02:00
Michael Niedermayer a7c4f119c9
avcodec/avs2_parser: Assert init_get_bits8() success with const size 15
Fixes: CID1506708 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-03 02:35:49 +02:00
Andreas Rheinhardt c3ca90a92e avcodec/x86/vp3dsp_init: Set correct function pointer, fix crash
Regression since fd172185580c1ccdcfb90bbfdb59fa806fad3117;
triggered by vp4/KTkvw8dg1J8.avi in the FATE suite, but not
when running fate as this code is not used when the bitexact
flag is set.

Bisecting done by ami_stuff, patch from user Mika Fischer
in ticket #10027 (which this commit fixes).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-02 23:38:15 +02:00
Andreas Rheinhardt 9fb3d640fb avcodec/av1dec: Always set ret before goto end
Before 0f8763fbea, av1_frame_ref()
and update_reference_list() could fail and therefore needed to
be checked, which incidentally set ret. This is no longer happening,
leading to a potential use of an uninitialized value which is
also the subject of Coverity ticket #1596605.

Fix this by always setting ret before goto end; do not return
some random ancient value.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-02 23:37:16 +02:00
James Almer 86e418ffd7 avcodec/avcodec: free decoded_side_data in ff_codec_close()
It's set by the library when decoding, so it should be freed when closing the
context.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-05-02 10:39:56 -03:00
Niklas Haas 71669f2ad5 avcodec/libx264: bump minimum required version to 155
This version is seven years old, and present in Debian oldoldstable,
Ubuntu 20.04 and Leap 15.0.

Allows cleaning up the file substantially. In particular, this is
motivated by the desire to stop relying on init_static_data.
2024-05-02 12:12:49 +02:00
Michael Niedermayer 615c994739
avcodec/atrac9dec: Check init_get_bits8() for failure
Fixes: CID1439569 Unchecked return value
Fixes: CID1439578 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-01 02:57:11 +02:00
Michael Niedermayer 63415168db
avcodec/ac3_parser: Check init_get_bits8() for failure
Fixes: CID1420393 Unchecked return value

Sponsored-by: Sovereign Tech Fund
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-05-01 02:57:11 +02:00
Niklas Haas 1d89de03d6 avcodec/dovi_rpuenc: avoid division by zero
Fixes: https://trac.ffmpeg.org/ticket/10985
2024-04-30 21:35:42 +02:00
Andreas Rheinhardt 08781ebe1a avcodec/riscv/vp9dsp: Fix inclusion guard
Fixes fate-source.

Reviewed-by: Jan Ekström <jeebjp@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-29 21:23:32 +02:00
sunyuechi c3a96f97f8 lavc/vp9dsp: R-V V ipred dc
C908:
vp9_dc_8x8_8bpp_c: 46.0
vp9_dc_8x8_8bpp_rvv_i64: 41.0
vp9_dc_16x16_8bpp_c: 109.2
vp9_dc_16x16_8bpp_rvv_i32: 72.7
vp9_dc_32x32_8bpp_c: 365.2
vp9_dc_32x32_8bpp_rvv_i32: 165.5
vp9_dc_127_8x8_8bpp_c: 23.0
vp9_dc_127_8x8_8bpp_rvv_i64: 22.0
vp9_dc_127_16x16_8bpp_c: 70.2
vp9_dc_127_16x16_8bpp_rvv_i32: 50.2
vp9_dc_127_32x32_8bpp_c: 295.2
vp9_dc_127_32x32_8bpp_rvv_i32: 136.7
vp9_dc_128_8x8_8bpp_c: 23.0
vp9_dc_128_8x8_8bpp_rvv_i64: 22.0
vp9_dc_128_16x16_8bpp_c: 70.2
vp9_dc_128_16x16_8bpp_rvv_i32: 50.2
vp9_dc_128_32x32_8bpp_c: 295.2
vp9_dc_128_32x32_8bpp_rvv_i32: 136.7
vp9_dc_129_8x8_8bpp_c: 23.0
vp9_dc_129_8x8_8bpp_rvv_i64: 22.0
vp9_dc_129_16x16_8bpp_c: 70.2
vp9_dc_129_16x16_8bpp_rvv_i32: 50.2
vp9_dc_129_32x32_8bpp_c: 295.2
vp9_dc_129_32x32_8bpp_rvv_i32: 136.7
vp9_dc_left_8x8_8bpp_c: 38.0
vp9_dc_left_8x8_8bpp_rvv_i64: 36.0
vp9_dc_left_16x16_8bpp_c: 93.2
vp9_dc_left_16x16_8bpp_rvv_i32: 67.7
vp9_dc_left_32x32_8bpp_c: 333.2
vp9_dc_left_32x32_8bpp_rvv_i32: 158.5
vp9_dc_top_8x8_8bpp_c: 38.7
vp9_dc_top_8x8_8bpp_rvv_i64: 36.0
vp9_dc_top_16x16_8bpp_c: 93.2
vp9_dc_top_16x16_8bpp_rvv_i32: 67.7
vp9_dc_top_32x32_8bpp_c: 333.2
vp9_dc_top_32x32_8bpp_rvv_i32: 156.2

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
2024-04-29 20:46:05 +03:00
Lynne f492095bd3
opustab: macro constant as a double
May increase intermediate precision on some compilers.
2024-04-29 15:30:25 +02:00
Zhao Zhili cf4af4bca0 avcodec/mediacodecenc: Flush bsf after create extradata
Avoid leaving any data inside bsf while also avoid keep bsf in
EOF state.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-29 15:58:48 +08:00
Fei Wang 67fc9b8427 lavc/qsvdec: Use FFmpeg default 1/25 framerate if can't derive it from bitstream
Fix error:
$ ffmpeg -hwaccel qsv -i input.h265 -f null -
...
[null @ 0x55da1a629200] Application provided invalid, non monotonically
increasing dts to muxer in stream 0: 3 >= 3

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
2024-04-29 11:08:41 +08:00
Andreas Rheinhardt 651f3aa7f9 avcodec/h264dec: Remove unused coded_picture_number
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-28 19:13:17 +02:00
Yotam Ofek a9a69a5a31 avcodec/aacenc: don't redundantly re-compute max sfb
Remove an unneeded inner loop in adjust_frame_information that
had no effect, the loop body can be run only once and will compute
the same max sfb.
2024-04-28 13:59:57 +02:00
Michael Niedermayer 091fdce87e
avcodec/pngdec: Check last AVFrame before deref
Fixes: NULL pointer dereference
Fixes: 68184/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-4926478069334016

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-04-27 21:16:40 +02:00
Michael Niedermayer d9699464c3
avcodec/vp3: Call ff_progress_frame_unref() before ff_progress_frame_get_buffer()
Fixes: Assertion !f->f && !f->progress failed at libavcodec/decode.c:1688
Fixes: 68190/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_THEORA_fuzzer-5942090287611904

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-04-27 21:16:40 +02:00
Michael Niedermayer 5eb05f4450
avcodec/hevcdec: Check ref frame
Fixes: NULL pointer dereferences
Fixes: 68197/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-6382538823106560

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-04-27 21:16:39 +02:00
Andreas Rheinhardt 67c7c44c79 avcodec/vp8: Return error on error
Regression since e1ba00ac8f.

Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-27 16:55:00 +02:00
Lynne 3390693bfb
aacdec: avoid generating unused code when either implementation is disabled
Minor optimization to remove extra branches.
We need to include the header for xHE anyway, which is float-only.
2024-04-27 11:12:12 +02:00
Lynne 134dba9544
opusdsp: add ability to modify deemphasis constant
xHE-AAC relies on the same postfilter mechanism
that Opus uses to improve clarity (albeit with a steeper
deemphasis filter).

The code to apply it is identical, it's still just a
simple IIR low-pass filter. This commit makes it possible
to use alternative constants.
2024-04-27 11:12:07 +02:00
Diego Felix de Souza 9d675bb60d avcodec/nvenc: add high bit depth encoding for HEVC
Adding 10-bit encoding support for HEVC if the input is 8-bit. In
case of 8-bit input content, NVENC performs an internal CUDA 8 to
10-bit conversion of the input prior to encoding. Currently, only
AV1 supports encoding 8-bit content as 10-bit.

Signed-off-by: Diego Felix de Souza <ddesouza@nvidia.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2024-04-25 00:33:13 +02:00
Haihao Xiang 8c62d77139 lavc/vp9: Fix regression introduced in 0ba05857
It is possible that ff_progress_frame_await() is called but
ff_progress_frame_report() isn't called when a hardware acceleration
method is used, so a thread for vp9 decoding might get stuck.

Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2024-04-24 11:47:34 +08:00
James Almer c4e3d6cdb0 avcodec/codec_par: always clear extradata_size in avcodec_parameters_to_context()
Missed in d383ae43c2.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-24 00:11:37 -03:00
Michael Niedermayer b91e3c4c90
avcodec/cbs_h2645: Check NAL space
Found-by-reviewing: CID1419833 Untrusted loop bound

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-04-24 02:52:17 +02:00
James Almer 63702d5f9c avcodec/aac/aacdec: remove double colon
Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-23 11:02:00 -03:00
Zhao Zhili 66161166dc avcodec/mediacodecenc: add AV_CODEC_CAP_ENCODER_FLUSH support
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-23 15:35:26 +08:00
Zhao Zhili 9e49915195 avcodec/mediacodecenc: Add global header support
The extradata is generated by encoding a dummy frame, then reset
the encoder state by mediacodec flush(). It only works for pixel
format other than AV_PIX_FMT_MEDIACODEC, since I'm not sure how
to create a dummy frame safely with AV_PIX_FMT_MEDIACODEC.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-23 15:35:26 +08:00
Zhao Zhili 3cfea6993a avcodec/mediacodecenc: Remove write only variable
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-23 15:35:26 +08:00
Zhao Zhili a5a3788f56 avcodec/mediacodecenc: Fix return empty packet when bsf is used
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2024-04-23 15:35:26 +08:00
Zhao Zhili 32fa20c0c9 avcodec/mediacodec_wrapper: Fix unused variable warning 2024-04-23 15:35:26 +08:00
Zhao Zhili 98b5e80fd6 avcodec/mediacodec_wrapper: link to NDK mediacodec API directly
Drop support of Android version before 5.0.
2024-04-23 15:35:26 +08:00
Lynne e3650886c7
aacdec: initialize float/fixed SBR tables only when either is needed 2024-04-23 08:31:41 +02:00
Lynne 176c922e4e
aacsbr: constify the only SBR table 2024-04-23 08:31:41 +02:00
Lynne 03cf101645
aacdec: remove AAC-specific MIPS optimizations
The code was written in 2012, but seems to have been broken
for just as long. Compilation is broken on every MIPS/MIPS64
system with an FPU (which the code depends on).
2024-04-23 08:31:40 +02:00
Lynne ae7c6cc17d
aac: move aacdec.c to aac/aacdec.c 2024-04-23 08:31:40 +02:00
Lynne 551ce16b59
aacdec: move aacdec.h into libavcodec/aac 2024-04-23 08:31:40 +02:00
Lynne cd1e404a10
aacdec: merge previously-templated code 2024-04-23 08:31:39 +02:00
Lynne ce740618d1
aacdec: move LATM decode functions into a separate file 2024-04-23 08:31:39 +02:00
Lynne e93793bf3c
aacdec: fully detemplate decoder core 2024-04-23 08:31:38 +02:00
Lynne 2f90d83981
aacdec: move fixed/float DSP initialization to templated init functions 2024-04-23 08:31:38 +02:00
Lynne 905fdb0601
aacdec: reuse TNS and LTP tables between fixed and float decoders
The fixed decoder derives the values from floats anyway.
2024-04-23 08:31:38 +02:00
Lynne 49e7be1e37
aacdec: move prediction to separate files 2024-04-23 08:31:37 +02:00
Lynne b1718ce0f9
aacdec: move CCE decoding to a separate templated file
Unfortunately, although it's a purely decode function, it does
need to be templated.
2024-04-23 08:31:37 +02:00
Lynne 41c04bec0a
aacdec: move fixed-point clipping to a separate function 2024-04-23 08:31:36 +02:00
Lynne 87a93a5670
aacdec: split off channel coupling into a new file 2024-04-23 08:31:36 +02:00
Lynne b7387ea00e
aacdec: deduplicate table initizalization
All tables now initialized by aac/aacdec_fixed|float
2024-04-23 08:31:36 +02:00
Lynne 41ae2b03a5
aacdec: move spectrum decode and dequantization to a new file 2024-04-23 08:31:35 +02:00
Lynne 5c026e6637
aacdec: remove unnecessary decode_spectrum_and_dequant arguments
Small cleanup to reduce number of arguments.
2024-04-23 08:31:35 +02:00
Lynne eef9100a8e
aacdec: template LTP windowing separately
The function is called only internally in DSP, so we do not
need to expose it.

apply_ltp on MIPS uses this function, but due to the function
being just a glue function with no real optimizations,
duplicate it there.
2024-04-23 08:31:35 +02:00
Lynne 091d85217d
aacdec: template windowing and transforms separately 2024-04-23 08:31:34 +02:00
Lynne a309aa4127
aacdec: duplicate table initialization
Preparation to move all table init and support windowing functions.
2024-04-23 08:31:34 +02:00
Lynne e9fc7661da
aacdec: template LTP application separately 2024-04-23 08:31:33 +02:00
Lynne db5128ef70
aacdec: template TNS application separately 2024-04-23 08:31:33 +02:00
Lynne ad16349f9b
aacdec: template intensity stereo application separately 2024-04-23 08:31:33 +02:00
Lynne 9f3fa77e0d
aacdec: template mid/side stereo application separately 2024-04-23 08:31:32 +02:00
Lynne a6295586f5
aacdec: template scalefactor dequantization separately 2024-04-23 08:31:32 +02:00
Lynne 7f3b3e2df1
aacdec: switch-ify scalefactor decoding
Brings it in line with dequantization.
2024-04-23 08:31:31 +02:00
Lynne 77a88bbdda
aacdec: give spectrum dequant+decode SCE rather than an ICS
Eliminates using templated values in function definition.
2024-04-23 08:31:31 +02:00
Lynne 60b60dd635
aacdec: separate out scalefactor dequantization from decoding
Allows to template away dequantization.
2024-04-23 08:31:31 +02:00
Lynne ed009bfd3d
aacdec: add a decoder DSP structure
To be used to abstract away DSP functions.
2024-04-23 08:31:30 +02:00
Andreas Rheinhardt 9de66fd449
avcodec/aacdec_template: Deduplicate common part of aac_decode_init()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-23 08:31:30 +02:00
Andreas Rheinhardt 980a55fb46
avcodec/aacdec_template: Deduplicate AVClass+AVOptions
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-23 08:31:29 +02:00
Andreas Rheinhardt e3693c6f56
avcodec/aacdec_template: Deduplicate aac_decode_close()
This is possible now that both AAC decoders share the same
context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-23 08:31:29 +02:00
Andreas Rheinhardt 7117e0c7be
avcodec/aacdec: Use same AACDecContext for fixed and float
Up until now, there was one AACDecContext for the fixed
and one for the floating point decoder. These differed
mostly in certain arrays which were int for the fixed-point
and float for the floating point decoder; there were also
differences in corresponding function pointers.

Yet in order to deduplicate the enormous amount of currently
duplicated code between the float and the fixed-point decoder,
one needs common contexts. Given that int and float have the
same size on all common systems, this commit replaces these
arrays by unions of int arrays and of float arrays. The names
of these arrays have been chosen to be compatible with
AAC_RENAME().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-23 08:31:29 +02:00
Andreas Rheinhardt fc3c2ea8dc
avcodec/aacdec: PredictorState array out of SingleChannelElement
sizeof(PredictorState) is different for the floating-point and
the fixed-point AAC decoders; this is an obstacle for deduplicating
code between these decoders. So don't include this array in
SingleChannelElement, instead add a union of pointers to the
fixed-point PredictorState and the floating-point PredictorState.
The actual arrays are part of the extended ChannelElement
to be allocated by ff_aac_sbr_ctx_alloc_init(); it also
sets the pointers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-23 08:31:28 +02:00
Andreas Rheinhardt 8b2261e573
avcodec/aacdec: Always include AV(Fixed|Float)DSPContext in AACDecContext
Up until now, AACDecContext included pointers to one of these
contexts depending upon USE_FIXED. Yet deduplicating
the common parts of the float and fixed-point AAC decoders
needs common structures, so we put both of these pointers
in a union.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-23 08:31:28 +02:00
Andreas Rheinhardt 5bd7b8d999
avcodec/aacdec: Split SBR context from ChannelElement
The AAC fixed-point and floating-point decoders have
a lot of duplicated code; the main obstacle to
deduplicating it is that several structures with the
same name are actually different types, because
they contain INTFLOATs (int or float) and AAC_FLOATs
(SoftFloat or float). SoftFloat and float typically
have different sizes, so dealing with it is the more
complicated of the two.

AAC_FLOAT is mainly used in the sbr code and structures,
so one can still deduplicate the code by only exposing
the common part of ChannelElement (without SBR context)
to the common decoder part. One prerequisite of this
is to move allocating the whole ChannelElement to
code that will stay unduplicated. It is most natural
to move said allocation to ff_aac_sbr_ctx_init().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-23 08:31:28 +02:00
Andreas Rheinhardt 6975d965fc
avcodec/aacsbr: Make ff_aac_sbr_* funcs accept ChannelElement*
Each ChannelElement contains exactly one SpectralBandReplication
structure; the latter structure contains lots of buffers
whose size depend upon USE_FIXED (i.e. AAC_FLOAT arrays).
This complicates deduplicating the parts of the AAC decoder
that are duplicated between the fixed-point and the floating
point decoder.

In order to fix this, the SpectralBandReplication structure
will be moved from the part of ChannelElement visible to
the common code. Therefore the ff_aac_sbr_* functions
are ported to accept a ChannelElement*; they will then have
to translate that to the corresponding SpectralBandReplication*
themselves (which is possible, because there are floating-point
and fixed-point versions of these functions).

While just at it, also ensure that these functions are properly
namespaced.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-23 08:31:27 +02:00
Lynne 3600f757db
aacsbr_template: include mem.h
Future AAC changes remove the need to include this header.
2024-04-23 08:31:27 +02:00
Lynne f55b587820
aacdec: move aacdec_common to aac/aacdec_tab
Start to clean up the decoder.
Also renames a confusingly named file.
2024-04-23 08:31:18 +02:00
Jun Zhao fc02b910ad lavc/libxevd: Fixed the has_b_frames setting
has_b_frames used in decoder for size of the frame
reordering buffer, and we don't used the max_b_frames
in decoder.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2024-04-23 07:27:38 +08:00
Mark Thompson ba6b08c75b av1dec: Fix RefFrameSignBias calculation 2024-04-22 21:41:50 +01:00
Niklas Haas 2f3c1e1641 avcodec/libsvtav1: implement dolby vision coding 2024-04-22 12:17:56 +02:00
Niklas Haas 39ca87ed1e avcodec/libx265: implement dolby vision coding
libx265 supports these natively, we just need to attach the generated
NALs to the x265picture, as well as setting the appropriate DV profile.
2024-04-22 12:17:56 +02:00
Niklas Haas 8dea94a146 avcodec/libaomenc: implement dolby vision coding 2024-04-22 12:17:56 +02:00
Niklas Haas 3306766608 avcodec/dovi_rpuenc: add ff_dovi_rpu_generate()
This function takes a decoded AVDOVIMetadata struct and turns it back
into a binary RPU. Verified using existing tools, and matches the
bitstream in official reference files.

I decided to just roll the EMDF and NAL encapsulation into this function
because the end user will need to do it otherwise anyways.
2024-04-22 12:17:56 +02:00
Niklas Haas f140935005 avcodec/dovi_rpuenc: add ff_dovi_configure()
We need to set up the configuration struct appropriately based on the
codec type, colorspace metadata, and presence/absence of an EL (though,
we currently don't support an EL).

When present, we use the signalled RPU data header to help infer (and
validate) the right values.

Behavior can be controlled by a new DOVIContext.enable flag.
2024-04-22 12:17:51 +02:00
Niklas Haas f131086a70 avcodec/dovi_rpu: split into dovi_rpu.c and dovi_rpudec.c
To allow compiling the decoding objects without the encoding objects and
vice versa. Common helpers that users of both APIs need are put into the
shared dovi_rpu.c.
2024-04-22 12:17:05 +02:00
Niklas Haas 783734d979 configure: rename dovi_rpu subsystem to dovi_rpudec
To distinguish it from the to-be-added dovi_rpuenc.
2024-04-22 12:17:05 +02:00
Niklas Haas 2a99d3527b avcodec/dovi_rpu: expose guess_profile(), clarify semantics
To allow internally re-using it for both the encoder and decoder.

This is based on HEVC only, H.264/AV1 use their own (hopefully correctly
signalled) profiles (and in particular, the AV1 decoders implicitly
default the correct profile in the absence of a configuration record).
2024-04-22 12:17:05 +02:00
Niklas Haas dbfd979c1b avcodec/dovi_rpu: clarify error on missing RPU VDR
The code was written under the misguided assumption that these fields
would only be present when the value changes, however this does not
match the actual patent specification, which says that streams are
required to either always signal this metadata, or never signal it.

That said, the specification does not really clarify what the defaults
of these fields should be in the event that this metadata is missing, so
without any sample file or other reference I don't wish to hazard
a guess at how to interpret these fields.

Fix the current behavior by making sure we always throw this error, even
for files that have the vdr sequence info in one frame but are missing
it in the next frame.
2024-04-22 12:17:05 +02:00
Niklas Haas fc616de1a5 avcodec/dovi_rpu: properly replace context header
This was never set in ff_dovi_ctx_replace(), leading to possibly
out-of-date when copying from one thread to another.
2024-04-22 12:17:05 +02:00
Niklas Haas d0392619a7 avcodec/dovi_rpu: store entire config record
And make it public.

For encoding, users may also be interested in the configured level and
compatibility ID. So generalize the dv_profile field and just expose the
whole configuration record.

This makes the already rather reductive ff_dovi_update_cfg() function
almost wholly redundant, since users can just directly assign
DOVIContext.cfg.
2024-04-22 12:17:05 +02:00
Andreas Rheinhardt 20206e14d7 avcodec/av1dec: Make av1_frame_replace() out of av1_frame_ref()
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-21 16:31:42 +02:00
Andreas Rheinhardt 0f8763fbea avcodec/av1dec: Use ProgressFrames
AV1 can put a frame into multiple reference slots;
up until now, this involved creating a new reference
to the underlying AVFrame; therefore av1_frame_ref()
could fail.
This commit changes this by using the ProgressFrame API
to share the underlying AVFrames.

(Hint: vaapi_av1_surface_id() checked whether the AV1Frames
contained in the AV1DecContext were NULL or not (of course
they were not); this has been changed to actually check for
whether said AV1Frame is blank or not.)

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-21 16:31:42 +02:00
Andreas Rheinhardt 0ec886ddc7 avcodec/hevcdec: Use union for AVFrame* and ProgressFrame
It avoids having to sync ProgressFrame.f and the pointer
typically used to access the AVFrame.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-21 16:31:42 +02:00
Andreas Rheinhardt 1d17d84b7d avcodec/progressframe: Explain how unnamed union can simplify accesses
This relies on the common initial seqence guarantee
(and on C11 support for unnamed members).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-21 16:31:42 +02:00
Jun Zhao 822e2843ca lavc/vvc/refs: Use dpb_max_num_reorder_pics to control output
Use dpb_max_num_reorder_pics to control output instead of
dpb_max_dec_pic_buffering, when dpb_max_dec_pic_buffering
is much larger than dpb_max_num_reorder_pics, it may cause
dpb overflow error.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
Signed-off-by: elinyhuang <elinyhuang@tencent.com>
2024-04-21 21:06:50 +08:00
Jun Zhao 50b8666dc6 lavc/vvc_parser: Fixed the has_b_frames setting
has_b_frames used in decoder for size of the frame reordering
buffer, setting this field from dpb_max_num_reorder_pics.

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2024-04-21 21:06:50 +08:00
Jun Zhao d9f72eb107 lavc/vvc_parser: Remove max_b_frames setting
We don't used the max_b_frames field in decoder normally

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2024-04-21 21:06:50 +08:00
Andreas Rheinhardt 277f051ff6 avcodec/pthread_frame: Fix leak of coded side data
Happens in the mov-elst-ends-betn-b-and-i and mov-ibi-elst-starts-b
FATE tests with frame-threading.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-21 13:34:33 +02:00
Matthieu Bouron 8cdf1bae94 avcodec/jni: fix mixed declaration and code 2024-04-21 09:43:17 +02:00
Wu Jianhua a44c346312 avcodec/x86/vvc/vvcdsp_init: fix linking error when configuring with --disable-ssse3 --disable-optimizations options
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2024-04-20 12:11:43 +08:00
Wu Jianhua 2f3aaef1b5 avcodec/x86/vvc/vvcdsp_init: add avg prototypes
When we used the --disable-ssse3 --disable-optimizations options,
the compiler would not skip the MC_LINKS like the compilation that
enabled the optimization, so it would fail to find the function
prototypes. Hence, this commit uses the same way to add prototypes
for the functions as HEVC DSP.

And, when prototypes are added for the functions, we cannot add the static qualifier.
Therefore, the ff_vvc prefix is needed to avoid the naming conflict.

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2024-04-20 12:11:43 +08:00
Wu Jianhua 4358f49568 avcodec/x86/vvc/vvcdsp_init: add put prototypes
When we used the --disable-ssse3 --disable-optimizations options,
the compiler would not skip the MC_LINKS like the compilation that
enabled the optimization, so it would fail to find the function
prototypes. Hence, this commit uses the same way to add prototypes
for the functions as HEVC DSP.

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
2024-04-20 12:11:43 +08:00
Andreas Rheinhardt bba996d6cd avcodec/hevcdec: Fix precedence, bogus film grain warning
Reviewed-by: Niklas Haas <ffmpeg@haasn.xyz>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 17:44:21 +02:00
Andreas Rheinhardt f18de5bc4a avcodec/v4l2_(m2m|buffers): Use RefStruct API for context references
Avoids allocations and therefore error checks; also avoids
indirections and allows to remove the boilerplate code
for creating an object with a dedicated free function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt fbd1b90b29 avcodec/rkmppdec: Allocate AVDRMFrameDescriptor and frame ctx jointly
Avoids an allocation and therefore one error path.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 1427e67500 avcodec/rkmppdec: Use RefStruct API for references to decoder itself
Avoids boilerplate code when creating the context
and avoids allocations and therefore whole error paths
when creating references to it. Also avoids an indirection
and improves type-safety.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 9a0614c7bd avcodec/rkmppdec: Check av_buffer_ref()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 4513300989 avcodec/rkmppdec: Fix double-free on error
After having created the AVBuffer that is put into frame->buf[0],
ownership of several objects (namely an AVDRMFrameDescriptor,
an MppFrame and some AVBufferRefs framecontextref and decoder_ref)
has passed to the AVBuffer and therefore to the frame.
Yet it has nevertheless been freed manually on error
afterwards, which would lead to a double-free as soon
as the AVFrame is unreferenced.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt d692c42938 avcodec/qsv: Use RefStruct API for memory id (mids) array
Avoids allocations and therefore error checks and cleanup code;
also avoids indirections.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt ac8288e288 avcodec/ffv1dec: Switch to ProgressFrames
Avoids implicit av_frame_ref() and therefore allocations
and error checks. It also avoids explicitly allocating
the AVFrames (done implicitly when getting the buffer).

It also fixes a data race: The AVFrame's sample_aspect_ratio
is currently updated after ff_thread_finish_setup()
and this write is unsynchronized with the read in av_frame_ref().
Removing the implicit av_frame_ref() fixed this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 2f29147b7f avcodec/pngdec: Switch to ProgressFrames
Avoids implicit av_frame_ref() and therefore allocations
and error checks. It also avoids explicitly allocating
the AVFrames (done implicitly when getting the buffer).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt a807e469d5 avcodec/hevcdec: Switch to ProgressFrames
Avoids implicit av_frame_ref() and therefore allocations
and error checks. It also avoids explicitly allocating
the AVFrames (done implicitly when getting the buffer).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 2b46ae6407 avcodec/codec_internal: Remove FF_CODEC_CAP_ALLOCATE_PROGRESS
Before commit f025b8e110,
every frame-threaded decoder used ThreadFrames, even when
they did not have any inter-frame dependencies at all.
In order to distinguish those decoders that need the AVBuffer
for progress communication from those that do not (to avoid
the allocation for the latter), the former decoders were marked
with the FF_CODEC_CAP_ALLOCATE_PROGRESS internal codec cap.

Yet distinguishing these two can be done in a more natural way:
Don't use ThreadFrames when not needed and split ff_thread_get_buffer()
into a core function that calls the user's get_buffer2 callback
and a wrapper around it that also allocates the progress AVBuffer.
This has been done in 02220b88fc
and since that commit the ALLOCATE_PROGRESS cap was nearly redundant.

The only exception was WebP and VP8. WebP can contain VP8
and uses the VP8 decoder directly (i.e. they share the same
AVCodecContext). Both decoders are frame-threaded and VP8
has inter-frame dependencies (in general, not in valid WebP)
and therefore the ALLOCATE_PROGRESS cap. In order to avoid
allocating progress in case of a frame-threaded WebP decoder
the cap and the check for the cap has been kept in place.

Yet now the VP8 decoder has been switched to use ProgressFrames
and therefore there is just no reason any more for this check
and the cap. This commit therefore removes both.

Also change the value of FF_CODEC_CAP_USES_PROGRESSFRAMES
to leave no gaps.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt d7374ac713 avcodec/vp8: Mark flushing functions as av_cold
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt d48d7bc434 avcodec/vp8: Convert to ProgressFrame API
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt d74102e325 avcodec/wavpack: Move transient variable from context to stack
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 483c85e85e avcodec/wavpack: Optimize always-false comparison away
Also use the correct type limit SIZE_MAX; INT_MAX comes
from a time when this used av_buffer_allocz() which used
an int at the time.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 70e79d289b avcodec/wavpack: Only reset DSD context upon parameter change
The current code resets it all the time unless we are decoding
a DSD frame with identical parameters to the last frame.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 8dd0bd4f9b avcodec/wavpack: Move initializing DSD data to a better place
Namely to code that is only executed if we are indeed
initializing a DSD context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 2aac42605c avcodec/wavpack: Use ThreadProgress API
It is more natural given that WavPack doesn't need the data of
the previous frame at all; it just needs the DSD context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 9dc8f8839e avcodec/pthread_frame: Add API to share RefStruct refs just once
This is useful when the lifetime of the object to be shared
is the whole decoding process as it allows to avoid having
to sync them every time in update_thread_context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 267a763a55 avcodec/vp9: Replace atomic_store() by atomic_init()
This part of the code is not slice-threaded and they are
semantically an initialization, so use atomic_init()
instead of the potentially expensive atomic_store()
(which uses sequentially consistent memory ordering).

Also remove the initial initialization directly after
allocating this array.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 259234b46f avcodec/vp9: Simplify replacing VP9Frame
ff_thread_progress_replace() can handle a blank ProgressFrame
as src (in which case it simply unreferences dst), but not
a NULL one. So add a blank frame to be used as source for
this case, so that we can use the replace functions
to simplify vp9_frame_replace().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 98e1e848ef avcodec/vp9: Reduce wait times
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 0ba058579f avcodec/vp9: Fix race when attaching side-data for show-existing frame
When outputting a show-existing frame, the VP9 decoder simply
created a reference to said frame and returned it immediately to
the caller, without waiting for it to have finished decoding.
In case of frame-threading it is possible for the frame to
only be decoded while it was waiting to be output.
This is normally benign.

But there is one case where it is not: If the user wants
video encoding parameters to be exported, said side data
will only be attached to the src AVFrame at the end of
decoding the frame that is actually being shown. Without
synchronisation adding said side data in the decoder thread
and the reads in av_frame_ref() in the output thread
constitute a data race. This happens e.g. when using the
venc_data_dump tool with vp90-2-10-show-existing-frame.webm
from the FATE-suite.

Fix this by actually waiting for the frame to be output.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 7bd3b73716 avcodec/vp9: Switch to ProgressFrames
This already fixes a race in the vp9-encparams test. In this test,
side data is added to the current frame after having been decoded
(and therefore after ff_thread_finish_setup() has been called).
Yet the update_thread_context callback called ff_thread_ref_frame()
and therefore av_frame_ref() with this frame as source frame and
the ensuing read was unsynchronised with adding the side data,
i.e. there was a data race.

By switching to the ProgressFrame API the implicit av_frame_ref()
is removed and the race fixed except if this frame is later reused by
a show-existing-frame which uses an explicit av_frame_ref().
The vp9-encparams test does not cover this, so this commit
already fixes all the races in this test.

This decoder kept multiple references to the same ThreadFrames
in the same context and therefore had lots of implicit av_frame_ref()
even when decoding single-threaded. This incurred lots of small
allocations: When decoding an ordinary 10s video in single-threaded
mode the number of allocations reported by Valgrind went down
from 57,814 to 20,908; for 10 threads it went down from 84,223 to
21,901.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 444bd353e9 avcodec/vp3: Switch to ProgressFrames
Avoids implicit av_frame_ref() and therefore allocations
and error checks. It also avoids explicitly allocating
the AVFrames (done implicitly when getting the buffer)
and it also allows to reuse the flushing code for freeing
the ProgressFrames.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt c381c23154 avcodec/mimic: Switch to ProgressFrames
Avoids implicit av_frame_ref() and therefore allocations
and error checks.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 2135a40b1c avcodec/decode: Add new ProgressFrame API
Frame-threaded decoders with inter-frame dependencies
use the ThreadFrame API for syncing. It works as follows:

During init each thread allocates an AVFrame for every
ThreadFrame.

Thread A reads the header of its packet and allocates
a buffer for an AVFrame with ff_thread_get_ext_buffer()
(which also allocates a small structure that is shared
with other references to this frame) and sets its fields,
including side data. Then said thread calls ff_thread_finish_setup().
From that moment onward it is not allowed to change any
of the AVFrame fields at all any more, but it may change
fields which are an indirection away, like the content of
AVFrame.data or already existing side data.

After thread A has called ff_thread_finish_setup(),
another thread (the user one) calls the codec's update_thread_context
callback which in turn calls ff_thread_ref_frame() which
calls av_frame_ref() which reads every field of A's
AVFrame; hence the above restriction on modifications
of the AVFrame (as any modification of the AVFrame by A after
ff_thread_finish_setup() would be a data race). Of course,
this av_frame_ref() also incurs allocations and therefore
needs to be checked. ff_thread_ref_frame() also references
the small structure used for communicating progress.

This av_frame_ref() makes it awkward to propagate values that
only become known during decoding to later threads (in case of
frame reordering or other mechanisms of delayed output (like
show-existing-frames) it's not the decoding thread, but a later
thread that returns the AVFrame). E.g. for VP9 when exporting video
encoding parameters as side data the number of blocks only
becomes known during decoding, so one can't allocate the side data
before ff_thread_finish_setup(). It is currently being done afterwards
and this leads to a data race in the vp9-encparams test when using
frame-threading. Returning decode_error_flags is also complicated
by this.

To perform this exchange a buffer shared between the references
is needed (notice that simply giving the later threads a pointer
to the original AVFrame does not work, because said AVFrame will
be reused lateron when thread A decodes the next packet given to it).
One could extend the buffer already used for progress for this
or use a new one (requiring yet another allocation), yet both
of these approaches have the drawback of being unnatural, ugly
and requiring quite a lot of ad-hoc code. E.g. in case of the VP9
side data mentioned above one could not simply use the helper
that allocates and adds the side data to an AVFrame in one go.

The ProgressFrame API meanwhile offers a different solution to all
of this. It is based around the idea that the most natural
shared object for sharing information about an AVFrame between
decoding threads is the AVFrame itself. To actually implement this
the AVFrame needs to be reference counted. This is achieved by
putting a (ownership) pointer into a shared (and opaque) structure
that is managed by the RefStruct API and which also contains
the stuff necessary for progress reporting.
The users get a pointer to this AVFrame with the understanding
that the owner may set all the fields until it has indicated
that it has finished decoding this AVFrame; then the users are
allowed to read everything. Every decoder may of course employ
a different contract than the one outlined above.

Given that there is no underlying av_frame_ref(), creating
references to a ProgressFrame can't fail. Only
ff_thread_progress_get_buffer() can fail, but given that
it will replace calls to ff_thread_get_ext_buffer() it is
at places where errors are already expected and properly
taken care of.

The ProgressFrames are empty (i.e. the AVFrame pointer is NULL
and the AVFrames are not allocated during init at all)
while not being in use; ff_thread_progress_get_buffer() both
sets up the actual ProgressFrame and already calls
ff_thread_get_buffer(). So instead of checking for
ThreadFrame.f->data[0] or ThreadFrame.f->buf[0] being NULL
for "this reference frame is non-existing" one should check for
ProgressFrame.f.

This also implies that one can only set AVFrame properties
after having allocated the buffer. This restriction is not deep:
if it becomes onerous for any codec, ff_thread_progress_get_buffer()
can be broken up. The user would then have to get a buffer
himself.

In order to avoid unnecessary allocations, the shared structure
is pooled, so that both the structure as well as the AVFrame
itself are reused. This means that there won't be lots of
unnecessary allocations in case of non-frame-threaded decoding.
It might even turn out to have fewer than the current code
(the current code allocates AVFrames for every DPB slot, but
these are often excessively large and not completely used;
the new code allocates them on demand). Pooling relies on the
reset function of the RefStruct pool API, it would be impossible
to implement with the AVBufferPool API.

Finally, ProgressFrames have no notion of owner; they are built
on top of the ThreadProgress API which also lacks such a concept.
Instead every ThreadProgress and every ProgressFrame contains
its own mutex and condition variable, making it completely independent
of pthread_frame.c. Just like the ThreadFrame API it is simply
presumed that only the actual owner/producer of a frame reports
progress on said frame.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:18:04 +02:00
Andreas Rheinhardt 89828417b0 avcodec/threadprogress: Add new API for frame-threaded progress
The API is similar to the ThreadFrame API, with the exception
that it no longer has an included AVFrame and that it has its
own mutexes and condition variables which makes it more independent
of pthread_frame.c. One can wait on anything via a ThreadProgress.
One just has to ensure that the lifetime of the object containing
the ThreadProgress is long enough. This will typically be solved
by putting a ThreadProgress in a refcounted structure that is
shared between threads.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Reviewed-by: epirat07@gmail.com
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-19 13:07:48 +02:00
Frank Plowman bb9e4ff355 lavc/vvc: Skip enhancement layer NAL units
The native VVC decoder does not yet support quality/spatial/multiview
scalability.  Bitstreams requiring this feature could cause crashes.
Patch fixes this by skipping NAL units which are not in the base layer,
warning the user while doing so.

Signed-off-by: Frank Plowman <post@frankplowman.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-18 17:38:15 -03:00
Andreas Rheinhardt 7f35c999f6 avcodec/ac3enc: Avoid copying samples
Only the last 256 samples of each frame are used;
the encoder currently uses a buffer for 1536 + 256 samples
whose first 256 samples contain are the last 256 samples
from the last frame and the next 1536 are the samples
of the current frame.
Yet since 238b2d4155 all the
DSP functions only need 256 contiguous samples and this can
be achieved by only retaining the last 256 samples of each
frame. Doing so saves 6KiB per channel.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-18 14:52:26 +02:00
Andreas Rheinhardt da460fb95c avcodec/ac3enc: Combine cpl_coord buffers
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-18 14:52:26 +02:00
Andreas Rheinhardt 5b9fab0f07 avcodec/ac3enc: Combine loops
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-18 14:52:26 +02:00
Andreas Rheinhardt 79d1814b71 avcodec/ac3enc: Avoid indirections, allocations of small arrays
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-18 14:52:26 +02:00
Andreas Rheinhardt 94132dc4aa avcodec/ac3enc: Avoid allocation for mdct_window
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-18 14:52:26 +02:00
Andreas Rheinhardt 3b93b1af13 avcodec/ac3enc: Avoid allocation for windowed_samples
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-18 14:52:26 +02:00
Tong Wu b2e2fb0344 avcodec/vaapi_encode_h265: use is_reference to fill reference_pic_flag
This codec supports FLAG_B_PICTURE_REFERENCES. We need to fill
reference_pic_flag with pic->is_reference.

Signed-off-by: Tong Wu <tong1.wu@intel.com>
2024-04-18 14:43:07 +08:00
Tong Wu 02fb1782ef avcodec/vaapi_encode_h264: use is_reference to fill reference_pic_flag
This codec supports FLAG_B_PICTURE_REFERENCES. We need to correctly fill
the reference_pic_flag with is_reference variable instead of 0 for B
frames.

Signed-off-by: Tong Wu <tong1.wu@intel.com>
2024-04-18 14:43:07 +08:00
Haihao Xiang 41e3d36a39 lavc/vaapi_decode: Use dynamic frame pool if possible
libva2 doesn't require a fixed surface-array any more, so we may use
dynamic frame pool for decoding when libva2 is available, which allows a
downstream element stores more frames from VAAPI decoders and fixes the
error below:

$ ffmpeg -hwaccel vaapi -hwaccel_output_format vaapi \
-i input.mp4 -c:v hevc_vaapi -f null -
...
[h264 @ 0x557a075a1400] get_buffer() failed
[h264 @ 0x557a075a1400] thread_get_buffer() failed
[h264 @ 0x557a075a1400] decode_slice_header error
[h264 @ 0x557a075a1400] no frame!

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2024-04-18 14:43:07 +08:00
Geoff Hill 1abba59738 avcodec/ac3: Remove unused fixed-point ARMv7 DSP
This diff removes 4 unused ARMv7 NEON fixed-point DSP functions.

The function were originally moved here by 4958f35a2 (Dec 2013).

After 9e05421db (Jan 2021), as part of the refactor of the AC3
DSP to consistently use 32-bit sample format in the encoder, these
functions were removed from the DSP function table, but the ARMv7
implementations were kept.

Signed-off-by: Geoff Hill <geoff@geoffhill.org>
2024-04-18 08:38:14 +02:00
arch1t3cht e9e1932c1c avcodec/h264dec: Reindent after the previous commit
Signed-off-by: arch1t3cht <arch1t3cht@gmail.com>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2024-04-16 16:36:22 +01:00
arch1t3cht 728ffe6ca6 avcodec/h264dec: Handle non-recovered frames when draining
When starting on a SEI recovery point close enough to the end of
the stream that draining starts before the recovery point's frame
is output, there can be non-recovered frames in the delayed picture
buffer that would currently cause the decoder to fail to output a
frame. This commit skips such frames and outputs the first recovered
frame, if there exists one.

Signed-off-by: arch1t3cht <arch1t3cht@gmail.com>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2024-04-16 16:36:22 +01:00
arch1t3cht 5a856ac6e6 avcodec/h264dec: Properly mark frames as recovered when draining
When decoding starts at a SEI recovery point very shortly before the
end of the video stream, there can be frames which are decoded before
the recovery point's frame is output and which will only be output once
the draining has started. Previously, these frames would never be set
as recovered. This commit copies the logic from h264_select_output_frame
to send_next_delayed_frame to properly mark such frames as recovered.

Fixes ticket #10936.

Signed-off-by: arch1t3cht <arch1t3cht@gmail.com>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2024-04-16 16:36:22 +01:00
Frank Plowman 993c231de0 lavc/vvc: Increase size of ctb_size_y
sps_log2_ctu_size_minus5 is between 0 and 2, with 3 reserved for future
use.  The VVC decoder allows sps_log2_ctu_size_minus5 to be 3, and so
ctb_size_y should be at least 16 bits to prevent overflows.  An
alternative patch would leave sps_log2_ctu_size_minus5 as 8 bits and
disallow sps_log2_ctu_size_minus5 = 3.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2024-04-15 21:06:13 +08:00
Lynne db09f1a5d8
vulkan_av1: add workaround for NVIDIA drivers tested on broken CTS
The first release of the CTS for AV1 decoding had incorrect
offsets for the OrderHints values.
The CTS will be fixed, and eventually, the drivers will be
updated to the proper spec-conforming behaviour, but we still
need to add a workaround as this will take months.

Only NVIDIA use these values at all, so limit the workaround
to only NVIDIA. Also, other vendors don't tend to provide accurate
CTS information.
2024-04-15 02:40:02 +02:00
Mark Thompson 3cca8dfbd8 lavc/vulkan_av1: Use av1dec reference order hint information 2024-04-14 21:05:08 +01:00
Mark Thompson 22ced1edc6 lavc/av1: Record reference ordering information for each frame
This is needed by Vulkan.  Constructing this can't be delegated to CBS
because packets might contain multiple frames (when non-shown frames are
present) but we need separate snapshots immediately before each frame
for the decoder.
2024-04-14 21:05:05 +01:00
Diego Felix de Souza 1f265aa91d avcodec/nvenc: Multi NVENC Split Frame Encoding in HEVC and AV1
When Split frame encoding is enabled, each input frame is partitioned into
horizontal strips which are encoded independently and simultaneously by
separate NVENCs, usually resulting in increased encoding speed compared to
single NVENC encoding.

Signed-off-by: Diego Felix de Souza <ddesouza@nvidia.com>
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
2024-04-13 18:00:43 +02:00
Kacper Michajłow 1c45104f74 avcodec/h2645_sei: validate Mastering Display Colour Volume SEI values
As we can read in ST 2086:

Values outside the specified ranges of luminance and chromaticity values
are not reserved by SMPTE, and can be used for purposes outside the
scope of this standard.

This is further acknowledged by ITU-T H.264 and ITU-T H.265. Which says
that values out of range are unknown or unspecified or specified by
other means not specified in this Specification.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Niklas Haas <git@haasn.dev>
2024-04-13 17:50:49 +02:00
James Almer 6d0c89980c avcodec/hevcdec: export global side data in AVCodecContext
Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-11 11:48:39 -03:00
James Almer 6def8e3923 avcodec/decode: add AVFrameSideData helper wrappers that don't depend on frames
They will be useful to fill arrays stored in other structs.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-11 11:46:23 -03:00
Andreas Rheinhardt 1533351990 avcodec/flacenc: Avoid shift where possible
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 0458fdbeed avcodec/ac3enc: Avoid calculating the CRC multiple times
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 28ffc39808 avcodec/ac3enc: Move EAC-3 specific initialization to eac3enc.c
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 2281ab5c24 avcodec/ac3enc: Avoid function pointers to initialize MDCT
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 6c55cb95ed avcodec/ac3enc_float: Remove uninformative error message
AVERROR(ENOMEM) is enough.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 3cd136bc12 avcodec/ac3enc: Deduplicate copying input samples
These memcpy operands only depend upon sizeof(SampleType)
(and this size is actually the same for both the fixed-point
and the floating-point encoders for most (all supported?)
systems).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 7311a9086e avcodec/ac3enc: Deduplicate allocating buffers
These allocations only depend upon sizeof(SampleType)
(and this size is actually the same for both the fixed-point
and the floating-point encoders for most (all supported?)
systems).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 2fcc50d1f5 avcodec/ac3enc: Share more code between fixed/float encoders
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 1042ee36cd avcodec/ac3enc: Move ff_ac3_validate_metadate() upwards
Will avoid a forward declaration in the next commit.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt 6244ecf8ec avcodec/ac3enc: Use common encode_frame function
This is in preparation for sharing even more stuff
common to the fixed and floating-point encoders.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:53:26 +02:00
Andreas Rheinhardt fee093a570 avcodec/ac3enc: Remove disabled code for RealAudio variant of AC-3
Implicitly disabled by 4679a474f0.
Given that no one has ever complained about this, this commit
removes the now dead code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:52:46 +02:00
Andreas Rheinhardt 27a830c1d8 avcodec/ac3enc: Remove always-false sample rate check
encode_preinit_audio() already checks that the sample rate
is among AVCodec.supported_samplerates.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:44:27 +02:00
Andreas Rheinhardt e878ec7eb2 avcodec/ac3enc: Avoid copying strings
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:44:27 +02:00
Andreas Rheinhardt 8261d5d38c avcodec/ac3enc: Use bit-operations for bit-mask
Simply masking the LFE bit is more natural than subtracting
if set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:44:27 +02:00
Andreas Rheinhardt b3d12fe200 avcodec/ac3enc: Remove redundant channel layout checks
These are all checked generically via AVCodec.ch_layouts
in encode_preinit_audio().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:44:27 +02:00
Andreas Rheinhardt 13daafd5c0 avcodec/ac3enc: Don't overwrite AVCodecContext.ch_layout
This is unnecessary (the channel layout guessing code became
moot when the channel layouts were enforced generically)
and also dangerous, as a custom channel layout mapping
would leak in case one was used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:44:27 +02:00
Andreas Rheinhardt c3fb0c5bab avcodec/ac3enc: Don't presume ch_layout to be AV_CHANNEL_ORDER_NATIVE
It is perfectly legal for users to use a custom layout
that is equivalent to a supported native one.
In this case the union in AVChannelLayout is not an uint64_t mask,
but a pointer to a custom map.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-11 12:44:27 +02:00
Anton Khirnov 0e4dfa4709 Revert "bsf: use standard include paths"
This reverts commit 41b73ae883.

This patch was pushed extremely quickly, without giving developers the
time to object.
2024-04-10 15:17:54 +02:00
Lynne 89a9042291
lavc/avfft: fix RDFT wrapper stride
Per the lavu/tx docs:

> * For forward transforms (R2C), stride must be the spacing between two
> * samples in bytes. For inverse transforms, the stride must be set
> * to the spacing between two complex values in bytes.

The code did the reverse.
The stride parameter is currently not respected for RDFT transforms,
but has to be correct, for a potential future change.
2024-04-10 13:22:18 +02:00
Andrew Kelley 41b73ae883 bsf: use standard include paths
Removes the special -I flag specified in the avcodec/bsf/ subdirectory.

This makes code copy-pastable to other parts of the ffmpeg codebase, as
well as simplifying the build script.

It also reduces ambiguity, since there are many instances of same-named
header files existing in both libavformat/ and libavcodec/
subdirectories.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-09 22:21:59 -03:00
James Almer 9dbc9a0f97 avcodec/libsvt1: check return value of send/receive functions
Reviewed-by: Sean McGovern <gseanmcg@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-09 21:37:49 -03:00
Martin Storsjö 359b6a7f8a aarch64/ac3dsp: simplify the end of ff_ac3_sum_square_butterfly_float_neon
Before:                           Cortex A53     A72     A78      M1
ac3_sum_square_bufferfly_float_neon:  1005.7   516.5   224.5   194.0
After:
ac3_sum_square_bufferfly_float_neon:   981.7   504.5   223.2   189.5

Signed-off-by: J. Dekker <jdek@itanimul.li>
2024-04-09 16:50:49 +02:00
Frank Plowman 1c0149359a lavc/vvc: Fix out-of-bounds array access
The 2 which has been changed to an 8 in the array length expression is
the maximum value of sps_bitdepth_minus8.  This was missed when updating
to VVCv2, which increased this maximum from 2 to 8.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2024-04-09 22:35:48 +08:00
Frank Plowman 2b7e79e890 lavc/vvc: Avoid overflow in coeff scale intermediate
Make intermediate result 64-bits to avoid an overflow before the right
shift.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2024-04-09 22:30:35 +08:00
Frank Plowman fcf74c5ebc lavc/vvc: Fix buffer overread in CABAC
The size variable here is taken as gospel for the bounds of the input
buffer in later logic.  Clamp it to ensure that the returned region
does not extend past that allocated in the underlying GetBitContext,
even in the case entry point offsets are signalled in the bitstream.
Also assert this for good measure.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2024-04-09 22:30:18 +08:00
Frank Plowman f499503073 lavc/vvc_parser: Fix integer overflow calculating framerate
num_units_in_tick and time_scale are both 32-bit unsigned integers.
Storing them as ints was causing overflows.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2024-04-09 22:15:29 +08:00
Frank Plowman b4baa4c0b3 lavc/vvc: Fix left shifts of negative values
All these variables lie in the range [-12..12]

Signed-off-by: Frank Plowman <post@frankplowman.com>
2024-04-09 22:13:49 +08:00
Niklas Haas 459648761f avcodec/hevcdec: fix segfault on invalid film grain metadata
Invalid input files may contain film grain metadata which survives
ff_h274_film_grain_params_supported() but does not pass
av_film_grain_params_select(), leading to a SIGSEGV on hevc_frame_end().

Fix this by duplicating the av_film_grain_params_select() check at frame
init time.

An alternative solution here would be to defer the incompatibility check
to hevc_frame_end(), but this has the downside of allocating a film
grain buffer even when we already know we can't apply film grain.

Fixes: https://trac.ffmpeg.org/ticket/10951
2024-04-09 15:01:58 +02:00
James Almer b0ef9e35e8 x86/ac3dsp: clear the upper 32 bits for input arguments where needed
Fixes checkasm on win64.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-08 13:45:58 -03:00
Andreas Rheinhardt 17414abb69 avcodec/mpegvideo_dec, h264_slice: Return proper error codes
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt 7f0efe2324 avcodec/mpeg12dec: Remove redundant mpeg_enc_ctx_allocated
Use context_initialized from the underlying MpegEncContext
instead. Also don't check before ff_mpv_common_end()
in mpeg_decode_end().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt 94295bb574 avcodec/mpegvideo: Remove pointless check
Possible since 315c956cbd.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt 6f2f496822 avcodec/mpegvideo_dec: Move getting Picture slot into alloc_picture()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt b7cf2d0efc avcodec/mpegvideo_dec: Factor allocating dummy frame out
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt b00c697654 avcodec/mpegvideo_dec: Remove redundant code to reset keyframe flag
These AVFrames are blank and therefore the flag is already unset.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt da4cca5fc0 avcodec/mpegvideo_dec: Remove obsolete current_picture_ptr reuse code
Obsolete since at least 74d623914f.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt 00e48e6da8 avcodec/mpeg12dec: Remove unnecessary FFCodec.close
The ipu decoder never calls ff_mpv_common_init() or allocates
anything else that would need to be freed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt f48313526b avcodec/mpegvideo_dec: Don't emit non-keyframe warning for H.261
H.261 does not have keyframes (or indeed frame types) at all,
so this warning is not warranted.

Also remove an always-true check while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt 518f79f2a8 avcodec/mpeg12dec: Don't pretend MPEG-1/2 to support alpha
(FF_PTR_ADD has to be kept although MPEG-1/2 only supports
YUV pixel formats because our decoder also supports decoding
to AV_PIX_FMT_GRAY8 depending upon CONFIG_GRAY.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:02 +02:00
Andreas Rheinhardt 1a5452655a avcodec/mpeg12dec: Remove redundant check
This code only gets executed for the first field.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:01 +02:00
Andreas Rheinhardt a9709b3c83 avcodec/mpegvideo_dec, mpeg12dec: Move MPEG1/2 code to mpeg12dec.c
Up until now, ff_mpv_frame_start() offsets the data of the current
picture and doubles the linesizes of all pictures if the current
picture is field-based so that data and linesize allow to address
the current field only.

This is done based upon the current picture_structure value.
Only two mpegvideo-based decoders ever set this field: mpeg1/2
and VC-1; but the latter only does it after ff_mpv_frame_start()
(when using hardware-acceleration and in order to signal it to
the DXVA2 hwaccel) in which case no offset is applied in
ff_mpv_frame_start(). So only one decoder actually wants this
offset*; therefore move the code performing it to mpeg12dec.c.

*: VC-1 doubles linesize when using field_mode (not only the picture's
linesize, but also uvlinesize and linesize), yet it does not offset
anything. This is further proof that this should not be performed
generically.

Also move MPEG-1/2 specific setting of the top-field-first flag.
(The change here implies that the AVFrame in current_picture
may have different top-field-first flags than the AVFrame
from current_picture_ptr, but this doesn't matter as only
the latter's are used.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:01 +02:00
Andreas Rheinhardt ca7b2c393a avcodec/mpeg12: Remove always-false check
Forgotten in 7800cc6e82.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:01 +02:00
Andreas Rheinhardt 66923165d5 avcodec/mpegutils: Move definitions to better places
FRAME_SKIPPED -> h263dec.h
CANDIDATE_MB_TYPE_* -> mpegvideoenc.h
INPLACE_OFFSET -> mpegvideoenc.h
enum OutputFormat -> mpegvideo.h

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:01 +02:00
Andreas Rheinhardt 908a73df31 avcodec/mpegvideo_enc: Don't update current_picture unnecessarily
current_picture is not changed after frame_start() at all
and it therefore does not need to be updated (i.e. copied to the
slice thread contexts) a second time.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-08 15:00:01 +02:00
James Almer 1f049d5627 avcodec/vvc/dec: fix typo
Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-08 09:10:04 -03:00
James Almer 9eca5b8369 avcodec/vvc/ps: reset sps_id_used on flush
Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-08 08:56:53 -03:00
Geoff Hill ee1bc723de avcodec/ac3: Implement sum_square_butterfly_float for aarch64 NEON
Signed-off-by: Geoff Hill <geoff@geoffhill.org>
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-04-08 13:36:40 +03:00
Geoff Hill 42e88f18f3 avcodec/ac3: Implement sum_square_butterfly_int32 for aarch64 NEON
Signed-off-by: Geoff Hill <geoff@geoffhill.org>
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-04-08 13:36:40 +03:00
Geoff Hill 69cb34f885 avcodec/ac3: Implement ac3_extract_exponents for aarch64 NEON
Signed-off-by: Geoff Hill <geoff@geoffhill.org>
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-04-08 13:36:40 +03:00
Geoff Hill 6f6bd10531 avcodec/ac3: Implement ac3_exponent_min for aarch64 NEON
Signed-off-by: Geoff Hill <geoff@geoffhill.org>
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-04-08 13:36:40 +03:00
Geoff Hill b69486ea18 avcodec/ac3: Implement float_to_fixed24 for aarch64 NEON
Signed-off-by: Geoff Hill <geoff@geoffhill.org>
Signed-off-by: Martin Storsjö <martin@martin.st>
2024-04-08 13:36:28 +03:00
Andreas Rheinhardt 2d33d6bfcc avcodec/dv: Don't pretend initializing work chunks can fail
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt f3c8d0399a avcodec/huffyuvdec: Use assert to check for things that can't fail
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt a6d6c8442c avcodec/huffyuvdec: Use bytestream API for byte-aligned reads
This also allows to remove the padding from these buffers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt a6979e3bd2 avcodec/huffyuvenc: Deduplicate options
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt 5110d16f5a avcodec/huffyuvenc: Avoid code duplication
This also fixes misindentated code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt d517c9e51b avcodec/huffyuvenc: Avoid duplicate variables
Also simplify assigningfake strides.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt 0e5af493fc avcodec/huffyuv: Return proper error code
Also forward said error code in the encoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt cf96c0295e avcodec/huffyuv(dec|enc): Use union for temp/temp16
These pointers already point to the same buffers, so using
a union is possible and avoids the overhead of syncing the
pointers (and saves some memory).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt eef5d60ac6 avcodec/huffyuv: Inline common alloc/free functions in their callers
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Andreas Rheinhardt cebf1d59a5 avcodec/huffyuvdec: Don't zero unnecessarily
A decoder's private data has already been zeroed (apart from options)
before init is called.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-07 21:59:32 +02:00
Frank Plowman 2d79ae3f8a lavc/vvc: Error if SPS ID is duplicated within CVS
Key line from the spec is:

"All SPS NAL units with a particular value of sps_seq_parameter_set_id
in a CVS shall have the same content."

Prior to this patch, the VVC decoder's behaviour on encountering a
duplicated SPS ID (within the entire bitstream, not restricted to
a CVS) was simply to replace the entry in the SPS lookup table with the
new data.  Illegal bitstreams with multiple SPSs in the same CVS sharing
an ID but differing elsewhere could cause all manner of issues.

The patch tracks which SPS IDs have been used in the given CVS using the
new sps_id_used field of VVCParamSets.  If it encounters an SPS with an
ID already in use and whose content differs from the previous SPS, it
throws an AVERROR_INVALIDDATA.

Signed-off-by: Frank Plowman <post@frankplowman.com>
2024-04-07 10:13:45 +08:00
Andreas Rheinhardt 0dbf45120a avcodec/libdav1d: Don't cast const away unnecessarily
Possible since c89f6ae689.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-04-06 18:44:06 +02:00
Antoine SOULIER 4865ea48cc avcodec/liblc3dec: retrieve duration of the last packet from the demuxer
Use the packet duration field to invalid last samples of the last frame.
2024-04-06 09:55:57 +02:00
Antoine SOULIER 6de00dc5f1 avcodec/liblc3dec: fix extradata size 2024-04-06 09:40:37 +02:00
Antoine SOULIER ad3fcfd0f2 avcodec/liblc3dec: fix typo in macro name, fix compilation 2024-04-06 09:40:32 +02:00
Oneric 57c545090d avocdec/ass: simplify linebreaks
ff_ass_subtitle_header_* still used explicit CRLF linebreaks
eventhough they will get normalised to LF later since commit
7bf1b9b357. Just directly use LF.
2024-04-06 09:26:30 +02:00
Oneric 0fc975c0d3 avcodec/ass,webvttdec: implement more portable curly brace escapes
Unlike what the old comment suggested, standard ASS has no character
escape mechanism, but a closing curly bracket doesn't even need one.

For manual authored sub files using a full-width variant of an
appropriate font and with scaling and spacing modifiers is a common
workaround.
This is not an option here, but we can still make things much less bad.
Now the desired opening bracket still shows up in libass, and
standard renders will merely display a backslash in its place
instead of stripping the following text like before.
2024-04-06 09:25:03 +02:00
Oneric baa64fa4e6 avcodec/ass,webvttdec: fix handling of backslashes
Backslashes cannot be escaped by a backslash in any ASS renderer,
but unless followed by specific characters it is just printed out.
Insert a word-joiner character after a backslash to break up
active sequences without changing the visual output.
2024-04-06 09:24:47 +02:00