Commit Graph

52480 Commits

Author SHA1 Message Date
Cosmin Stejerean 5c3ee7ee63 avcodec/dovi_rpudec: fix reading el_bit_depth_minus8
now that we are reading ext_mapping_idc as the upper 8 bits of
el_bit_depth_minus8 we need to use get_ue_golomb_long rather than
get_ue_golomb_31 for reading it
2026-04-20 20:51:25 +08:00
Lynne dec93eac16 aacdec_usac, aacsbr: implement SBR support for USAC
Currently, no eSBR features are supported.
Thankfully, no encoders exist for it yet.
2026-04-20 20:51:24 +08:00
Cosmin Stejerean b33ece57b0 avcodec/dovi_rpu: correctly read el_bit_depth_minus8 and ext_mapping_idc
These two fields are coded together into a single 16 bit integer with upper 8
bits for ext_mapping_idc and lower 8 bits for el_bit_depth_minus8.

Furthermore ext_mapping_idc has two components, upper 3 bits and lower 5 bits.

Co-authored-by: Niklas Haas <git@haasn.dev>
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-04-20 20:51:24 +08:00
Lynne 12b2ba6f52 aacdec_usac: remove custom rate_idx and use standard variable for it
m4ac.sampling_index is what aacdec.c uses.
2026-04-20 20:51:24 +08:00
Lynne 27dee77d73 aacdec_usac: rename noise_scale to noise_bands
This was a typo.
2026-04-20 20:51:24 +08:00
Lynne 0de12ce743 aacdec_ac: fix an overread
Fixes reading state->last[i + 1] in ff_aac_ac_get_context for the
last array member.
2026-04-20 20:51:24 +08:00
Lynne 38dcd774b8 aac: expose ff_aac_sample_rate_idx() in aac.h
The rate index is a value important to both encoders and decoders.
USAC needs it as well, so put it into the shared main header.
2026-04-20 20:51:24 +08:00
Lynne 7f0e8c9890 aacdec_usac: apply specification fix M55715 2026-04-20 20:51:24 +08:00
Andreas Rheinhardt 8bbfb658e0 avcodec/h261enc: Fix ac_vlc_length tables
These tables are supposed to contain the number of bits needed
to encode a given (run, level) pair. Yet the number of bits
for pairs needing the escape code was wrong (it only contained
the escape code and not the bits needed for run and level).

Furthermore, H.261 (a format with explicit end-of-block codes)
does not work well together with the RLTable API from rl.c:
The EOB code is the first one in ff_h261_rl_tcoeff's VLC table
and has a run value of zero. Therefore the result of get_rl_index()
is off by one for run == 0 and level values with explicit
(run, level) pair.

Fixing this necessitated changing the ref files of the
vsynth*-h261-trellis tests. Both filesizes as well as PSNR
decreased. If one used a qscale value of 11 for this test,
one would have received files with about the same size as
before this patch (with qscale 12), but with better PSNR.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:23 +08:00
Andreas Rheinhardt d04b5a05a8 avcodec/h261enc: Avoid RLTable when writing macroblock
The RLTable API in rl.c is not well designed for codecs with
an explicit end-of-block code. ff_h261_rl_tcoeff's vlc has
the EOB code as first element (presumably so that the decoder
can check for it via "if (level == 0)") and this implies
that the indices returned by get_rl_index() are off by one
for run == 0 which is therefore explicitly checked.

This commit changes this by adding a simple LUT for the
values not requiring escaping. It is easy to directly
include the sign bit into this, so this has also been done.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:23 +08:00
Andreas Rheinhardt ff3a036343 avcodec/h261data: Make some tables non-static
This will allow to avoid the indirection via ff_h261_rl_tcoeff
in future commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:23 +08:00
Andreas Rheinhardt a427b7f7a9 avcodec/mpegvideo_enc: Constify pointers to static storage
These must not be modified (even when they are initialized at runtime
and therefore modifiable).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:23 +08:00
Andreas Rheinhardt db766a4232 avcodec/motion_est: Optimize dead code away
H.261 does not have B-frames.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:23 +08:00
Andreas Rheinhardt 8b96760dfe avcodec/h261enc: Inline constants
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:23 +08:00
Andreas Rheinhardt b8333aeb4f avcodec/mpegvideo_dec: Move setting dct_unquant funcs to h263dec.c
It is a better place for it; no non-h263-based decoder needs
these functions any more (both H.261 and the error resilience
code recently stopped doing so).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt e49a7227a7 avcodec/rv10: Avoid indirection
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt f28a1f7f2b avcodec/mpegvideo: Move quant_precision to Mpeg4DecContext
It is an MPEG-4-only value; it is always five for the MPEG-4
encoder, so just hardcode this value and move the MpegEncContext
field to Mpeg4DecContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt 7979222d98 avcodec/rv10: Use ff_h263_decode_init()
The RV10 and RV20 decoders use ff_h263_decode_mb() and also the
H.263 DSP and VLCs. Despite not calling ff_h263_decode_frame(),
it is nevertheless beneficial to call ff_h263_decode_init()
to reduce code duplication.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt ee77189a4b avcodec/mpeg_er: Simplify disabling IDCT
The error resilience code does not make up block coefficients
and therefore zeroes them in order to disable the IDCT.
But this can be done in a simpler manner, namely by setting
block_last_index to a negative value. Doing so also has
the advantage that the dct_unquantize functions are never even
called for those codecs that do not use ff_mpv_reconstruct_mb()
for ordinary decoding (namely RV-30/40 and the VC-1 family).

This approach would not work for intra macroblocks (there is always
at least one coefficient for them and therefore there is no check
for block_last_index for them), but this does not happen at all.
Add an assert for this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt 5aea8d3dce avcodec/rv10: Remove write-only assignments
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt af32dcd319 avcodec/h261dec: Don't set framerate multiple times
Just do it once during init.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt c6a9bacd17 avcodec/h261dec: Simplify decoding motion vectors
Don't use a LUT to negate followed by a conditional ordinary
negation immediately thereafter. Instead fold the two.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt b8d5c425f4 avcodec/h261dec: Unquantize coefficients while parsing them
This is beneficial for performance: When concatenating
the file from the vsynth1-h261 fate-test 100 times,
performance (measured by timing the codec's decode callback)
improved by 9.6%.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt 340eccac6c avcodec/h261enc, msmpeg4: Avoid setting dc_scale_tables unnecessarily
It is unnecessary because ff_mpeg1_dc_scale_table is the default
for both dc_scale_tables.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt 1fc6e6b6d4 avcodec/mpeg_er: Don't set block_index unnecessarily
ff_init_block_index() sets MpegEncContext.dest and
MpegEncContext.block_index. The latter is unused by
ff_mpv_reconstruct_mb() (which is what this code is
preparatory for) and dest is overwritten a few lines below.
So don't initialize block_index at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:22 +08:00
Andreas Rheinhardt 0693a0c11a avcodec/mpeg4videodec: Don't initialize unused inter_scantable
inter_scantable is only used by the dct_unquantize_h263_inter
functions, yet this is not used by the MPEG-4 decoder at all
(in case H.263 quantization is used, the unquantization already
happens in mpeg4_decode_block()).

Also move the common initialization of ff_permute_scantable()
out of the if.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt 302f8f97e5 avcodec/mpv_reconstruct_mb_template: Optimize WMV2 code away if possible
The WMV2 decoder does not support lowres, so one can optimize
the WMV2 specific code away in the lowres version of this function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt 661e6d66bf avcodec/mpegvideo: Join loops when initializing ScanTable
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt 49e63b82af avcodec/mpegvideo_dec: Remove unnecessary FFMIN
No mpegvideo-based decoder supports lowres > 3,
so the FFMIN here are unnecessary.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt d6c5448ea5 avcodec/mpv_reconstruct_mb_template: Optimize always-true branch away
There are only two mpegvideo decoders that use another
(software) pixel format than YUV420: MPEG-1/2 and
the MPEG-4 studio profile. Neither of these use this part
of the code, so one can optimize the 422 code away when
this code is compiled for the decoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt 9b26d20399 avcodec/h261dec: Simplify decoding GOB header
h261_resync() can be completely removed, because
h261_decode_gob_header() checks for a GOB header itself if
gob_start_code_skipped is zero.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt a72d2d74e4 avcodec/h261dec: Fix UB NULL + 0, remove broken resync code
last_resync_gb is never initialized, causing NULL + 0
in align_get_bits(). In addition to that, the loop is never
entered.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt 6754a40953 avcodec/h261dec: Don't reset gob_start_code_skipped in h261_decode_init()
It always gets reset at the start of h261_decode_frame().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt e1c07ddc47 avcodec/msmpeg4enc: Combine writing bits
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt e4c11cf5cc avcodec/mpeg12enc: Pass AVCodecContext* directly
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt 9b5f588edb avcodec/mpeg12enc: Use AVCodecContext, not priv ctx as logctx
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:21 +08:00
Andreas Rheinhardt ba3ec87247 avcodec/mpeg4videodec: Remove always-false check
All valid values of dc_lum and dc_chrom are in the range 0..9,
because they are initialized via tables with 10 elements.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt aada24884a avcodec/vc1_block: Simplify resetting coded_block
Everything that init_block_index() sets will be overwritten
a few lines below again, so don't call it and simply calculate
the only thing that is used (namely block_index[0]) manually.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt 37c8fa914f avcodec/vc1_block: Remove unnecessary assignments
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt c40167856c avcodec/mpeg4videodec: Don't initialize unused stuff
Only the intra scantable is used for studio profile.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt a9ab85cb77 avcodec/mpeg4videodec: Inline constants
Partitioned macroblocks are always 8bit and not studio profile.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt 5a8454ca59 avcodec/h263enc: Remove no-output code
The no-output mode (guarded by AV_CODEC_FLAG2_NO_OUTPUT)
does not provide a noteworthy speedup; in fact, it even
turned out to be slower than the code with the no-output
code removed (ordinary encode: 153259721 decicycles,
noout encode: 153259721; encode with this patch applied:
152451581 decicycles; timings are for encode_frame callbacks
when encoding a 1080p sample to MPEG-4).

(Furthermore, this code was broken for most of its existence
(since 9207dc3b0db368bb9cf5eb295cbc1129c2975e31) and no one
noticed, so the no-output mode is probably not used at all.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt c2ea02bb27 avcodec/ituh263enc: Inline constants
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt 2322040e65 avcodec/svq1enc: Stop copying PutBitContext unnecessarily
Possible since 404fe63e23.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt a02aa4a9b3 avcodec/mpegutils: Don't output wrong mb skip values
The earlier code had two problems:
1. For reference frames that are not directly output (happens unless
low_delay is set), the mb skip values referred to the next reference
frame to be decoded.
2. For non-reference frames, every macroblock was always considered
skipped.
This makes the output (worse than) useless; that no one ever
complained about this shows that this feature is not really used.
It is therefore removed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt e75888c3d3 avcodec/mpegvideo_dec: Don't keep droppable in sync in update_thread_ctx
It is not a stream property, but a property of an individual picture
(in fact, it is only set by the FLV decoder that does not even support
frame threading).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt 501e72f7bb avcodec/mpegvideo_dec: Don't alloc framesize-bufs in update_thread_ctx
It is always allocated in ff_mpv_frame_start(), so the only
reason to put it into ff_mpeg_update_thread_context()
would be for the case that a frame-threaded decoder
that supports coded fields implements frame-threading.

The only mpegvideo-decoders supporting coded fields
are MPEG-1/2 and VC-1. The latter's bitstream requires
both coded fields to be part of the same access unit/packet,
so that every frame thread will always call ff_mpv_frame_start()
itself. The former only "need" the framesize buffers when
using lowres. If MPEG-1/2 gains frame-threading, one could either
perform framesize allocation in its update_thread_context
or when starting a field.

(Given that the next packet may trigger a reinitialization
due to a frame size change, it was possible for the buffers
that were allocated here to be thrown away unused.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:20 +08:00
Andreas Rheinhardt 243f57d506 avcodec/mpeg12dec: Disable allocating scratchpad buffers when possible
They are no longer used by the MPEG-1/2 decoders except when
using lowres.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:19 +08:00
Andreas Rheinhardt bd1d4c25db avcodec/mpv_reconstruct_mb_template: Don't unnecessarily copy data
There is no reason to use a temporary buffer as destination
for the new macroblock before copying it into its proper place.
(Originally, this has been added in commit
b68ab2609c due to concerns about
copying from GPU memory.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:19 +08:00
Andreas Rheinhardt 84fc7ccc79 avcodec/mpegutils: Fix ff_draw_horiz_band()
Broken in 5ecf5b93dda9d0c69875b80d28929f0d97dd7d06.

More precisely, 3994623df2 changed
the precursor of ff_mpv_reconstruct_mb() to always decode
to the first row of macroblocks for B pictures when
a draw_horiz_band callback is set and to (they are exported to
the caller via said callback and each row overwrites the previously
decoded row; this was probably intended as a cache-optimization).
This first macroblock row was used as source for the draw_horiz_band
callback.

This of course means that the ordinary output B-frame was not
decoded correctly at all. Therefore the first aforementioned commit
removed this special handling of draw_horiz_band; yet it did not
remove the special handling for B-frames in ff_draw_horiz_band(),
which broke draw_horiz_band for B-frames. This commit fixes this.

(Actually, draw_horiz_band was already broken before
5ecf5b93dda9d0c69875b80d28929f0d97dd7d06 when using slice-threading:
All slice-threads would write to the first row of macroblocks
for B-frames, leading to data races. It seems no one has ever complained
about this, just as no one has ever complained about the breakage
caused by 5ecf5b93dda9d0c69875b80d28929f0d97dd7d06. Probably no one
uses draw_horiz_band.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-04-20 20:51:19 +08:00