Just ensure that dct_unquantize_inter is set iff it is used and check for the function pointer instead.
Showing the changes to libavcodec (5 of 5 files). Show all
Unified · Split
| @@ -110,7 +110,8 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) · 109 unmodified lines | ||
| 110 | 110 | ff_mpv_unquantize_init(&unquant_dsp_ctx, |
| 111 | 111 | avctx->flags & AV_CODEC_FLAG_BITEXACT, 0); |
| 112 | 112 | // 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. | |
| 114 | 115 | s->dct_unquantize_intra = unquant_dsp_ctx.dct_unquantize_h263_intra; |
| 115 | 116 | s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_h263_inter; |
| 116 | 117 | |
| @@ -3417,6 +3417,8 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 3416 unmodified lines | ||
| 3417 | 3417 | |
| 3418 | 3418 | s->dct_unquantize_intra = s->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra |
| 3419 | 3419 | : 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; | |
| 3420 | 3422 | |
| 3421 | 3423 | end: |
| 3422 | 3424 | /* 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 | ||
| 3961 | 3963 | ctx->dct_unquantize_h263_intra = unquant_dsp_ctx.dct_unquantize_h263_intra; |
| 3962 | 3964 | ctx->dct_unquantize_mpeg2_intra = unquant_dsp_ctx.dct_unquantize_mpeg2_intra; |
| 3963 | 3965 | // 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; | |
| 3966 | 3968 | |
| 3967 | 3969 | s->y_dc_scale_table = ff_mpeg4_y_dc_scale_table; |
| 3968 | 3970 | s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table; |
| @@ -91,6 +91,8 @@ typedef struct Mpeg4DecContext { · 90 unmodified lines | ||
| 91 | 91 | |
| 92 | 92 | Mpeg4VideoDSPContext mdsp; |
| 93 | 93 | |
| 94 | + void (*dct_unquantize_mpeg2_inter)(MpegEncContext *s, | |
| 95 | + int16_t *block, int n, int qscale); | |
| 94 | 96 | void (*dct_unquantize_mpeg2_intra)(MpegEncContext *s, |
| 95 | 97 | int16_t *block, int n, int qscale); |
| 96 | 98 | void (*dct_unquantize_h263_intra)(MpegEncContext *s, |
| @@ -960,11 +960,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], · 959 unmodified lines | ||
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | /* 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) { | |
| 965 | 964 | // 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. | |
| 968 | 965 | add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); |
| 969 | 966 | add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); |
| 970 | 967 | 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 | ||
| 978 | 975 | } else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) { |
| 979 | 976 | // H.261, MPEG-1, MPEG-2, MPEG-4 with H.263 quantization, |
| 980 | 977 | // 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. | |
| 982 | 980 | add_dct(s, block[0], 0, dest_y , dct_linesize); |
| 983 | 981 | add_dct(s, block[1], 1, dest_y + block_size, dct_linesize); |
| 984 | 982 | add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize); |
| @@ -366,6 +366,9 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) · 365 unmodified lines | ||
| 366 | 366 | if (ff_h263_decode_init(avctx) < 0) |
| 367 | 367 | return -1; |
| 368 | 368 | |
| 369 | + // We unquantize inter blocks as we parse them. | |
| 370 | + s->dct_unquantize_inter = NULL; | |
| 371 | + | |
| 369 | 372 | ff_msmpeg4_common_init(s); |
| 370 | 373 | |
| 371 | 374 | switch (s->msmpeg4_version) { |