History

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.

Andreas Rheinhardt committed 1 year ago

Commit 778c0a41 parent f2c04fd5 files · +14 −8Browse files

Showing the changes to libavcodec (5 of 5 files). Show all

Unified · Split

5 files
  1. libavcodec/h263dec.c +2 −1
  2. libavcodec/mpeg4videodec.c +4 −2
  3. libavcodec/mpeg4videodec.h +2 −0
  4. libavcodec/mpegvideo_dec.c +3 −5
  5. libavcodec/msmpeg4dec.c +3 −0
libavcodec/h263dec.c+2−1
@@ -110,7 +110,8 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) · 109 unmodified lines
110110 ff_mpv_unquantize_init(&unquant_dsp_ctx,
111111 avctx->flags & AV_CODEC_FLAG_BITEXACT, 0);
112112 // dct_unquantize defaults for H.263;
113− // they might change on a per-frame basis for MPEG-4.
113+ // they might change on a per-frame basis for MPEG-4;
114+ // dct_unquantize_inter will be unset for MSMPEG4 codecs later.
114115 s->dct_unquantize_intra = unquant_dsp_ctx.dct_unquantize_h263_intra;
115116 s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_h263_inter;
116117
libavcodec/mpeg4videodec.c+4−2
@@ -3417,6 +3417,8 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 3416 unmodified lines
34173417
34183418 s->dct_unquantize_intra = s->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
34193419 : ctx->dct_unquantize_h263_intra;
3420+ // The following tells ff_mpv_reconstruct_mb() to unquantize iff mpeg_quant
3421+ s->dct_unquantize_inter = s->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
34203422
34213423 end:
34223424 /* detect buggy encoders which don't set the low_delay flag
@@ -3961,8 +3963,8 @@ static av_cold int decode_init(AVCodecContext *avctx) · 538 unmodified lines
39613963 ctx->dct_unquantize_h263_intra = unquant_dsp_ctx.dct_unquantize_h263_intra;
39623964 ctx->dct_unquantize_mpeg2_intra = unquant_dsp_ctx.dct_unquantize_mpeg2_intra;
39633965 // dct_unquantize_inter is only used with MPEG-2 quantizers,
3964− // so we can already set dct_unquantize_inter here once and for all.
3965− s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
3966+ // so that is all we keep.
3967+ ctx->dct_unquantize_mpeg2_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
39663968
39673969 s->y_dc_scale_table = ff_mpeg4_y_dc_scale_table;
39683970 s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table;
libavcodec/mpeg4videodec.h+2−0
@@ -91,6 +91,8 @@ typedef struct Mpeg4DecContext { · 90 unmodified lines
9191
9292 Mpeg4VideoDSPContext mdsp;
9393
94+ void (*dct_unquantize_mpeg2_inter)(MpegEncContext *s,
95+ int16_t *block, int n, int qscale);
9496 void (*dct_unquantize_mpeg2_intra)(MpegEncContext *s,
9597 int16_t *block, int n, int qscale);
9698 void (*dct_unquantize_h263_intra)(MpegEncContext *s,
libavcodec/mpegvideo_dec.c+3−5
@@ -960,11 +960,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], · 959 unmodified lines
960960 }
961961
962962 /* add dct residue */
963− if (!(IS_MPEG12_H261(s) || s->msmpeg4_version != MSMP4_UNUSED ||
964− (s->codec_id == AV_CODEC_ID_MPEG4 && !s->mpeg_quant))) {
963+ if (is_mpeg12 != DEFINITELY_MPEG12_H261 && s->dct_unquantize_inter) {
965964 // H.263, H.263+, H.263I, FLV, RV10, RV20 and MPEG-4 with MPEG-2 quantization
966− // Also RV30, RV40 when performing error resilience, but
967− // all blocks are skipped in this case.
968965 add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
969966 add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
970967 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], · 7 unmodified lines
978975 } else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
979976 // H.261, MPEG-1, MPEG-2, MPEG-4 with H.263 quantization,
980977 // MSMP4V1-3 and WMV1.
981− // Also the VC-1 family when performing error resilience
978+ // Also RV30, RV40 and the VC-1 family when performing error resilience,
979+ // but all blocks are skipped in this case.
982980 add_dct(s, block[0], 0, dest_y , dct_linesize);
983981 add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
984982 add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
libavcodec/msmpeg4dec.c+3−0
@@ -366,6 +366,9 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) · 365 unmodified lines
366366 if (ff_h263_decode_init(avctx) < 0)
367367 return -1;
368368
369+ // We unquantize inter blocks as we parse them.
370+ s->dct_unquantize_inter = NULL;
371+
369372 ff_msmpeg4_common_init(s);
370373
371374 switch (s->msmpeg4_version) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t