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

avcodec/mpegvideo_dec: Simplify check for unquantizing inter blocks

Just ensure that dct_unquantize_inter is set iff it is used
and check for the function pointer instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-05-20 23:58:34 +02:00
parent f2c04fd587
commit 778c0a48fa
5 changed files with 14 additions and 8 deletions

View File

@ -110,7 +110,8 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
ff_mpv_unquantize_init(&unquant_dsp_ctx,
avctx->flags & AV_CODEC_FLAG_BITEXACT, 0);
// dct_unquantize defaults for H.263;
// they might change on a per-frame basis for MPEG-4.
// they might change on a per-frame basis for MPEG-4;
// dct_unquantize_inter will be unset for MSMPEG4 codecs later.
s->dct_unquantize_intra = unquant_dsp_ctx.dct_unquantize_h263_intra;
s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_h263_inter;

View File

@ -3417,6 +3417,8 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
s->dct_unquantize_intra = s->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
: ctx->dct_unquantize_h263_intra;
// The following tells ff_mpv_reconstruct_mb() to unquantize iff mpeg_quant
s->dct_unquantize_inter = s->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
end:
/* detect buggy encoders which don't set the low_delay flag
@ -3961,8 +3963,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
ctx->dct_unquantize_h263_intra = unquant_dsp_ctx.dct_unquantize_h263_intra;
ctx->dct_unquantize_mpeg2_intra = unquant_dsp_ctx.dct_unquantize_mpeg2_intra;
// dct_unquantize_inter is only used with MPEG-2 quantizers,
// so we can already set dct_unquantize_inter here once and for all.
s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
// so that is all we keep.
ctx->dct_unquantize_mpeg2_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
s->y_dc_scale_table = ff_mpeg4_y_dc_scale_table;
s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table;

View File

@ -91,6 +91,8 @@ typedef struct Mpeg4DecContext {
Mpeg4VideoDSPContext mdsp;
void (*dct_unquantize_mpeg2_inter)(MpegEncContext *s,
int16_t *block, int n, int qscale);
void (*dct_unquantize_mpeg2_intra)(MpegEncContext *s,
int16_t *block, int n, int qscale);
void (*dct_unquantize_h263_intra)(MpegEncContext *s,

View File

@ -960,11 +960,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
/* add dct residue */
if (!(IS_MPEG12_H261(s) || s->msmpeg4_version != MSMP4_UNUSED ||
(s->codec_id == AV_CODEC_ID_MPEG4 && !s->mpeg_quant))) {
if (is_mpeg12 != DEFINITELY_MPEG12_H261 && s->dct_unquantize_inter) {
// H.263, H.263+, H.263I, FLV, RV10, RV20 and MPEG-4 with MPEG-2 quantization
// Also RV30, RV40 when performing error resilience, but
// all blocks are skipped in this case.
add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
@ -978,7 +975,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
} else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
// H.261, MPEG-1, MPEG-2, MPEG-4 with H.263 quantization,
// MSMP4V1-3 and WMV1.
// Also the VC-1 family when performing error resilience
// Also RV30, RV40 and the VC-1 family when performing error resilience,
// but all blocks are skipped in this case.
add_dct(s, block[0], 0, dest_y , dct_linesize);
add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);

View File

@ -366,6 +366,9 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
if (ff_h263_decode_init(avctx) < 0)
return -1;
// We unquantize inter blocks as we parse them.
s->dct_unquantize_inter = NULL;
ff_msmpeg4_common_init(s);
switch (s->msmpeg4_version) {