1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00
Commit Graph

119012 Commits

Author SHA1 Message Date
d256118b7e videotoolbox: Fix building with older SDKs
The kVTVideoDecoderReferenceMissingErr constant was only added
in the macOS 12 and iOS 15 SDKs. Use a hardcoded value instead
of the named constant, to fix building with older SDKs
after c6214b0d69.

Signed-off-by: Martin Storsjö <martin@martin.st>
2025-03-26 22:33:16 +02:00
e5a33c898a avcodec/mpegvideo: Only keep the actually used unquantize funcs
For all encoders and all decoders except MPEG-4 the unquantize
functions to use don't change at all and therefore needn't be
kept in the context. So discard them after setting them;
for MPEG-4, the functions get assigned on a per-frame basis.

Decoders not using any unquantize functions (H.261, MPEG-1/2)
as well as decoders that only call ff_mpv_reconstruct_mb()
through error resilience (RV30/40, the VC-1 family) don't have
the remaining pointers set at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:17:00 +01:00
917652d7c8 avcodec/ppc/mpegvideo_altivec: Don't process coeffs as scalars
block_last_index and nCoeffs is an optimization designed
to avoid processing unnecessarily many coefficients; yet
it would be legal to always process all coefficients
(all coefficients beyond nCoeffs are zero anyway and
zeros are always unquantized to zeros). Therefore
one does not need a scalar tail.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:16:35 +01:00
46c5466dd8 avcodec/ppc/mpegvideo_altivec: Don't process unnecessarily many coeffs
Use the same number as the C version.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:16:11 +01:00
b96ba44432 avcodec/ppc/mpegvideo_altivec: Set unquantize functions unconditionally
Don't do it depending upon dct_algo, as this is not supposed
to influence the unquantize function selection.
(This check originated in 05c4072b45
where it was used for the dct_quantize function only.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:15:46 +01:00
b2866b7216 avcodec/ppc/mpegvideo_altivec: Use correct inter scantable
This affected the WMV1/2 encoders (but not when running FATE because
the encoding part uses the fastint dct, so this code isn't used
then anyway).

It did not affect anything else, because a) only WMV1/2 use different
scantables, b) ff_msmpeg4_decode_block() (and therefore the WMV1
decoder) already unquantize inter macroblocks as they are parsed
c) the WMV2 decoder does not use the unquantize functions for inter
macroblocks at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:15:22 +01:00
63864545cd avcodec/mpegvideo: Move unquantize functions into a file of their own
This is in preparation for only keeping the actually used
unquantize functions in MpegEncContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:14:49 +01:00
34b624d98c avcodec/error_resilience: Avoid me_cmp.h inclusion
Use spell out what me_cmp_func means.
Avoids inclusions in the H.264 decoder as well as all
mpegvideo decoders.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:14:15 +01:00
b29ae29ee7 avcodec/h261dec: Set FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
This decoder sets the AVCodecContext fields even when a frame
is skipped.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:13:50 +01:00
46a2d03b75 avcodec/mpegvideo_enc: Use better variable name
Also fixes shadowing.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:13:24 +01:00
d5fba4aef9 avcodec/mpegvideo_enc: Defer initialization of mb-pos dependent vars
Only set them after mb_x and mb_y are known which happens
only after the call to ff_h261_reorder_mb_index().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:12:58 +01:00
854a3ed547 avcodec/motion_est: Reset scene_change score, MB variance stats
Reset them in ff_me_init_pic(). It is the appropriate place for it
and allows to remove resetting code from multiple places
(e.g. mpegvideo_enc.c resetted it in two different places
(one for the main slice context, one for all the others)).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:12:30 +01:00
479dac17f8 avcodec/mpegvideo_enc: Move code to initialize variables immediately
Also avoid casts and parentheses.
(This is only possible now because ff_update_duplicate_context()
no longer touches the PutBitContext.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:12:04 +01:00
6e45f7f535 avcodec/mpegvideo: Move MotionEstContext to MPVEncContext
All that is necessary to do so is perform ff_me_init_pic()
on every slice.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:11:32 +01:00
35fecd3e68 avcodec/motion_est: Move ff_h263_round_chroma() to h263.h
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:11:00 +01:00
ec6c8e5273 avcodec/mpegvideoenc: Constify vlc length pointees
These pointers point to static tables which must not be modified
by anyone after they have been initialized. So constify the pointees.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:10:31 +01:00
8b15979a4b avcodec/mpegvideo_enc: Don't reset statistics twice
This happens currently for the non-main slice contexts.
But these variables get reset at the start of encode_thread()
anyway for all slices, so this is unnecessary.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:10:06 +01:00
d66e9cb0d2 avcodec/mpegvideo_enc: Move lambda, lambda2 to MPVEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:09:33 +01:00
6ebc810e6f avcodec/mpeg12enc, speedhqenc: Optimize writing escape codes
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:09:10 +01:00
a064d34a32 avcodec/mpegvideoenc: Add MPVEncContext
Many of the fields of MpegEncContext (which is also used by decoders)
are actually only used by encoders. Therefore this commit adds
a new encoder-only structure and moves all of the encoder-only
fields to it except for those which require more explicit
synchronisation between the main slice context and the other
slice contexts. This synchronisation is currently mainly provided
by ff_update_thread_context() which simply copies most of
the main slice context over the other slice contexts. Fields
which are moved to the new MPVEncContext no longer participate
in this (which is desired, because it is horrible and for the
fields b) below wasteful) which means that some fields can only
be moved when explicit synchronisation code is added in later commits.

More explicitly, this commit moves the following fields:
a) Fields not copied by ff_update_duplicate_context():
dct_error_sum and dct_count; the former does not need synchronisation,
the latter is synchronised in merge_context_after_encode().
b) Fields which do not change after initialisation (these fields
could also be put into MPVMainEncContext at the cost of
an indirection to access them): lambda_table, adaptive_quant,
{luma,chroma}_elim_threshold, new_pic, fdsp, mpvencdsp, pdsp,
{p,b_forw,b_back,b_bidir_forw,b_bidir_back,b_direct,b_field}_mv_table,
[pb]_field_select_table, mb_{type,var,mean}, mc_mb_var, {min,max}_qcoeff,
{inter,intra}_quant_bias, ac_esc_length, the *_vlc_length fields,
the q_{intra,inter,chroma_intra}_matrix{,16}, dct_offset, mb_info,
mjpeg_ctx, rtp_mode, rtp_payload_size, encode_mb, all function
pointers, mpv_flags, quantizer_noise_shaping,
frame_reconstruction_bitfield, error_rate and intra_penalty.
c) Fields which are already (re)set explicitly: The PutBitContexts
pb, tex_pb, pb2; dquant, skipdct, encoding_error, the statistics
fields {mv,i_tex,p_tex,misc,last}_bits and i_count; last_mv_dir,
esc_pos (reset when writing the header).
d) Fields which are only used by encoders not supporting slice
threading for which synchronisation doesn't matter: esc3_level_length
and the remaining mb_info fields.
e) coded_score: This field is only really used when FF_MPV_FLAG_CBP_RD
is set (which implies trellis) and even then it is only used for
non-intra blocks. For these blocks dct_quantize_trellis_c() either
sets coded_score[n] or returns a last_non_zero value of -1
in which case coded_score will be reset in encode_mb_internal().
Therefore no old values are ever used.

The MotionEstContext has not been moved yet.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 04:08:33 +01:00
d74d1707a6 avcodec/motion_est: Don't use MpegEncContext.avctx
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:47:55 +01:00
6a42abe561 avcodec/mpegvideo: Move motion_est to MotionEstContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:47:22 +01:00
913322a267 avcodec/mpegvideo: Move me_pre, me_penalty_compensation to MPVMainEncCtx
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:46:49 +01:00
0e333a5451 avcodec/mpeg4videoenc: Move initializations before ff_mpv_encode_init()
This avoids relying on ff_update_duplicate_context() to copy
these fields to the slice contexts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:46:24 +01:00
8397351221 avcodec/mpegvideo_enc: Call ff_mpv_common_init() later
Namely after the main slice context has already been initialized,
so that this initialized state is directly copied to the newly
created slice contexts without relying on it being copied
by ff_update_duplicate_context(). This is in preparation for further
commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:45:57 +01:00
a2ba5b8242 avcodec/mpegvideoenc: Remove declaration of inexistent function
ff_MPV_encode_init_x86() has been renamed to ff_dct_encode_init_x86()
in 6b33e91899 in FFmpeg; libav renamed
it to ff_mpv_encode_init_x86() in commit
6b33e91899. This hasn't been noticed
in c1df467d73 when merging.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:45:27 +01:00
363fe86115 avcodec/{h261,ituh263}enc: Don't set ptr_lastgob unnecessarily
It will be overwritten later in encode_thread() anyway.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:45:02 +01:00
fa630b481c avcodec/mpegvideo: Move last-pic information to MPVMainEncContext
last_pict_type, last_non_b_pict_type and last_lambda_for
are only used by the encoder's main thread.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:44:30 +01:00
f293f95632 avcodec/mpegvideo: Support custom slice context sizes
This is in preparation for adding a special slice context for
the encoders and moving all the encoder-specific fields to it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:43:58 +01:00
1b537de8d4 avcodec/mpegvideo: Move noise_reduction to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:43:25 +01:00
f2ba0676b6 avcodec/mpegvideo_enc: Move allocating remaining buffers to init_buffers
Also allocate mb_type, mc_mb_var, mb_var and mb_mean jointly
while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:41:52 +01:00
a1f18b195e avcodec/mpegvideo_enc: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:41:26 +01:00
9f43de06fa avcodec/mpegvideo_enc: Don't allocate B-frame bufs without B frames
(Checking in the same way for intra_only is not straightforward,
because at least p_mv_table is written to even in intra_only
mode.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:41:00 +01:00
7b5fb2e4ff avcodec/mpegvideo: Move encoder-only base arrays to MPVMainEncContext
Also allocate them jointly (thereby reducing the number of base
arrays considerably) and already set them on all slice contexts;
don't rely on ff_update_duplicate_context().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:40:27 +01:00
a5a2fc04ee avcodec/mpegvideo: Move allocating encoder buffers to mpegvideoenc.c
dct_error_sum and me.map are allocated per slice-context
and therefore their allocation has not been moved to
mpegvideoenc.c in 0154fb43e3.

This commit changes this by allocating them jointly and
moving said allocations to mpegvideo_enc.c like the other
encoder-only buffers.
The buffers are suitably aligned to ensure that no false
sharing occurs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:39:58 +01:00
9964212545 avcodec/mpegvideo: Move MSMPEG4 fields to MSMPEG4 contexts
Several fields are not used by any generic code and can therefore
be moved to more specialized contexts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:39:25 +01:00
967f8a924e avcodec/msmpeg4enc: Avoid using MVTable
Switch to using the length+symbol table combination that is
also used by the decoder and remove MVTable as well as
the old tables altogether.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:39:01 +01:00
3d9a581ec1 avcodec/msmpeg4dec: Avoid lookups when decoding motion vector
Up until now, the decoder uses VLCs to determine whether
this is an escape element or an index in two separate tables
giving the x and y components of the motion vector.
Given that both these components fit into an int16_t and therefore
into a VLCElem's symbol one can simply use a symbol table
to avoid the latter lookups.

This necessitated to combine the two tables for x and y components.
While just at it, also switch to ff_vlc_init_tables_from_lengths().
This will allow to get rid of the code tables (about 4KiB) once
the encoder has been ported, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:38:36 +01:00
82a856e2e9 avcodec/msmpeg4enc: Use LUT to write motion vectors
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:38:11 +01:00
6d47d569d7 avcodec/mpegvideo: Move bit_rate field to MSMP4DecContext
Also make it an int as that is all MSMP4 needs.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:37:39 +01:00
f733cfca28 avcodec/msmpeg4dec: Add MSMPEG4DecContext
This is in preparation for further commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:37:14 +01:00
0a9f58a7a1 avcodec/mpeg12dec: Add bit_rate field to Mpeg1Context
Use it instead of MpegEncContext.bit_rate which will be removed soon.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:36:49 +01:00
9f469e244e avcodec/mpegvideoenc: Add bit_rate to MPVMainEncContext
Use it instead of the MpegEncContext field which will
be removed soon.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:36:20 +01:00
bceeb35857 avcodec/mpegvideo: Move vbv_delay_pos to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:35:47 +01:00
bf4dedd6b5 avcodec/mpegvideo: Move MPVPicture arrays to MPVMainEncContext
Also avoid allocations while at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:35:16 +01:00
72bf3d3c12 avcodec/mpegvideo: Move max_b_frames to MPVMainEncContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:34:44 +01:00
6e02882656 avcodec/mpegvideo: Add pointer to main context to slice contexts
It is a pointer to const to allow the slice threads to inspect
values without modifying them; also make it a simple cast
for codecs that don't support slice threading.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:34:12 +01:00
78391f20c8 avcodec/mjpegenc: Reindent after the previous commit
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:33:48 +01:00
5affd0221e avcodec/mpegvideo_enc: Use func ptr for encoding macroblocks
It gets rid of a switch (with accompanying CONFIG_*_ENCODER checks);
for MJPEG, it even lets one perform the check for whether one is
really encoding or only recording the macroblock once during init.

Furthermore, the switch actually contained lots of dead code --
it is compiled three times (for different pixel formats: 420, 422, 444),
yet most encoders only support 420. The approach used here automatically
fixes this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:33:15 +01:00
2f73a197a1 avcodec/mjpegenc: Move mjpeg_encode_init() down
Will avoid a forward declaration later.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2025-03-26 03:32:51 +01:00