[FFmpeg-cvslog] avcodec/mpegvideo: Move mpeg_quant to {Mpeg4Dec,MPVEnc}Context

Andreas Rheinhardt git at videolan.org
Mon May 26 06:25:18 EEST 2025


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Wed May 21 00:22:46 2025 +0200| [ed73675832ed580559ea6f27fd0ddb7685cf2b29] | committer: Andreas Rheinhardt

avcodec/mpegvideo: Move mpeg_quant to {Mpeg4Dec,MPVEnc}Context

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ed73675832ed580559ea6f27fd0ddb7685cf2b29
---

 libavcodec/mpeg12enc.c                 |  2 +-
 libavcodec/mpeg4videodec.c             | 15 ++++++++-------
 libavcodec/mpeg4videodec.h             |  1 +
 libavcodec/mpeg4videoenc.c             | 10 +++++-----
 libavcodec/mpegvideo.h                 |  1 -
 libavcodec/mpegvideo_enc.c             | 15 ++++++++-------
 libavcodec/mpegvideoenc.h              |  1 +
 libavcodec/nvdec_mpeg4.c               |  2 +-
 libavcodec/vaapi_mpeg4.c               |  2 +-
 libavcodec/vdpau_mpeg4.c               |  2 +-
 libavcodec/x86/mpegvideoenc_template.c |  2 +-
 11 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index d4791e8b33..96957235e9 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -1125,7 +1125,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
     } else {
         s->min_qcoeff = -2047;
         s->max_qcoeff = 2047;
-        s->c.mpeg_quant = 1;
+        s->mpeg_quant = 1;
     }
     if (s->c.intra_vlc_format) {
         s->intra_ac_vlc_length      =
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 936711d72e..313d73157f 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1399,7 +1399,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
 
         scan_table = s->intra_scantable.permutated;
 
-        if (s->mpeg_quant) {
+        if (ctx->mpeg_quant) {
             qmul = 1;
             qadd = 0;
             if (rvlc)
@@ -2155,7 +2155,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
 
     s->last_dc[cc] += dct_diff;
 
-    if (s->mpeg_quant)
+    if (ctx->mpeg_quant)
         block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision);
     else
         block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision) * (8 >> s->dct_precision);
@@ -2585,7 +2585,7 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
     skip_bits(gb, 15); /* latter_half_vbv_occupancy */
     check_marker(s->avctx, gb, "after latter_half_vbv_occupancy");
     s->low_delay  = get_bits1(gb);
-    s->mpeg_quant = get_bits1(gb); /* mpeg2_stream */
+    ctx->mpeg_quant = get_bits1(gb); /* mpeg2_stream */
 
     next_start_code_studio(gb);
     extension_and_user_data(s, gb, 2);
@@ -2767,7 +2767,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
 
         // FIXME a bunch of grayscale shape things
 
-        if ((s->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */
+        if ((ctx->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */
             int i, v;
 
             mpeg4_load_default_matrices(s);
@@ -3415,10 +3415,10 @@ 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;
+    s->dct_unquantize_intra = ctx->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;
+    s->dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
 
 end:
     /* detect buggy encoders which don't set the low_delay flag
@@ -3857,6 +3857,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
     s->sprite_warping_accuracy   = s1->sprite_warping_accuracy;
     s->num_sprite_warping_points = s1->num_sprite_warping_points;
     s->m.data_partitioning       = s1->m.data_partitioning;
+    s->mpeg_quant                = s1->mpeg_quant;
     s->rvlc                      = s1->rvlc;
     s->resync_marker             = s1->resync_marker;
     s->t_frame                   = s1->t_frame;
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 111d60ba10..593c8ab290 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -52,6 +52,7 @@ typedef struct Mpeg4DecContext {
     /// sprite shift [isChroma]
     int sprite_shift[2];
 
+    int mpeg_quant;
     // reversible vlc
     int rvlc;
     /// could this stream contain resync markers
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index d3828760ec..0fa8159f18 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -952,9 +952,9 @@ static void mpeg4_encode_vol_header(Mpeg4EncContext *const m4,
         put_bits(&s->pb, 2, 0);       /* sprite enable */
 
     put_bits(&s->pb, 1, 0);             /* not 8 bit == false */
-    put_bits(&s->pb, 1, s->c.mpeg_quant); /* quant type = (0 = H.263 style) */
+    put_bits(&s->pb, 1, s->mpeg_quant); /* quant type = (0 = H.263 style) */
 
-    if (s->c.mpeg_quant) {
+    if (s->mpeg_quant) {
         ff_write_quant_matrix(&s->pb, s->c.avctx->intra_matrix);
         ff_write_quant_matrix(&s->pb, s->c.avctx->inter_matrix);
     }
@@ -1304,11 +1304,11 @@ void ff_mpeg4_encode_video_packet_header(MPVEncContext *const s)
     put_bits(&s->pb, 1, 0); /* no HEC */
 }
 
-#define OFFSET(x) offsetof(MPVEncContext, c.x)
+#define OFFSET(x) offsetof(MPVEncContext, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-    { "data_partitioning", "Use data partitioning.",      OFFSET(data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
-    { "alternate_scan",    "Enable alternate scantable.", OFFSET(alternate_scan),    AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+    { "data_partitioning", "Use data partitioning.",      OFFSET(c.data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+    { "alternate_scan",    "Enable alternate scantable.", OFFSET(c.alternate_scan),    AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
     { "mpeg_quant",        "Use MPEG quantizers instead of H.263",
       OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, VE },
     FF_MPV_COMMON_BFRAME_OPTS
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 20a5759958..239d026960 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -254,7 +254,6 @@ typedef struct MpegEncContext {
     int data_partitioning;           ///< data partitioning flag from header
     int partitioned_frame;           ///< is current frame partitioned
     int low_delay;                   ///< no reordering needed / has no B-frames
-    int mpeg_quant;
     int padding_bug_score;             ///< used to detect the VERY common padding bug in MPEG-4
 
     /* divx specific, used to workaround (many) bugs in divx5 */
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 313c2e5744..27a01d1063 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -313,14 +313,15 @@ av_cold void ff_dct_encode_init(MPVEncContext *const s)
         s->dct_quantize  = dct_quantize_trellis_c;
 }
 
-static av_cold void init_unquantize(MpegEncContext *const s, AVCodecContext *avctx)
+static av_cold void init_unquantize(MPVEncContext *const s2, AVCodecContext *avctx)
 {
+    MpegEncContext *const s = &s2->c;
     MPVUnquantDSPContext unquant_dsp_ctx;
 
     ff_mpv_unquantize_init(&unquant_dsp_ctx,
                            avctx->flags & AV_CODEC_FLAG_BITEXACT, s->q_scale_type);
 
-    if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+    if (s2->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
         s->dct_unquantize_intra = unquant_dsp_ctx.dct_unquantize_mpeg2_intra;
         s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
     } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
@@ -403,7 +404,7 @@ static av_cold int init_matrices(MPVMainEncContext *const m, AVCodecContext *avc
     }
 
     if (CONFIG_MPEG4_ENCODER && s->c.codec_id == AV_CODEC_ID_MPEG4 &&
-        s->c.mpeg_quant) {
+        s->mpeg_quant) {
         intra_matrix = ff_mpeg4_default_intra_matrix;
         inter_matrix = ff_mpeg4_default_non_intra_matrix;
     } else if (s->c.out_format == FMT_H263 || s->c.out_format == FMT_H261) {
@@ -839,7 +840,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
         //return -1;
     }
 
-    if (s->c.mpeg_quant || s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO || s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO || s->c.codec_id == AV_CODEC_ID_MJPEG || s->c.codec_id == AV_CODEC_ID_AMV || s->c.codec_id == AV_CODEC_ID_SPEEDHQ) {
+    if (s->mpeg_quant || s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO || s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO || s->c.codec_id == AV_CODEC_ID_MJPEG || s->c.codec_id == AV_CODEC_ID_AMV || s->c.codec_id == AV_CODEC_ID_SPEEDHQ) {
         // (a + x * 3 / 8) / x
         s->intra_quant_bias = 3 << (QUANT_BIAS_SHIFT - 3);
         s->inter_quant_bias = 0;
@@ -1027,7 +1028,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
      * before calling ff_mpv_common_init(). */
     s->parent = m;
     ff_mpv_idct_init(&s->c);
-    init_unquantize(&s->c, avctx);
+    init_unquantize(s, avctx);
     ff_fdctdsp_init(&s->fdsp, avctx);
     ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
     ff_pixblockdsp_init(&s->pdsp, avctx);
@@ -4016,7 +4017,7 @@ static int dct_quantize_trellis_c(MPVEncContext *const s,
         last_non_zero = 0;
         qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale];
         matrix = n < 4 ? s->c.intra_matrix : s->c.chroma_intra_matrix;
-        if (s->c.mpeg_quant || s->c.out_format == FMT_MPEG1 || s->c.out_format == FMT_MJPEG)
+        if (s->mpeg_quant || s->c.out_format == FMT_MPEG1 || s->c.out_format == FMT_MJPEG)
             bias= 1<<(QMAT_SHIFT-1);
 
         if (n > 3 && s->intra_chroma_ac_vlc_length) {
@@ -4331,7 +4332,7 @@ static int dct_quantize_refine(MPVEncContext *const s, //FIXME breaks denoise?
         dc= block[0]*q;
 //        block[0] = (block[0] + (q >> 1)) / q;
         start_i = 1;
-//        if (s->c.mpeg_quant || s->c.out_format == FMT_MPEG1)
+//        if (s->mpeg_quant || s->c.out_format == FMT_MPEG1)
 //            bias= 1<<(QMAT_SHIFT-1);
         if (n > 3 && s->intra_chroma_ac_vlc_length) {
             length     = s->intra_chroma_ac_vlc_length;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index ec0304c4a0..5510b43f86 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -147,6 +147,7 @@ typedef struct MPVEncContext {
     int last_mv_dir;               ///< last mv_dir, used for B-frame encoding
 
     /* MPEG-4 specific */
+    int mpeg_quant;
     PutBitContext tex_pb;          ///< used for data partitioned VOPs
     PutBitContext pb2;             ///< used for data partitioned VOPs
 
diff --git a/libavcodec/nvdec_mpeg4.c b/libavcodec/nvdec_mpeg4.c
index 7d158321ae..8272439031 100644
--- a/libavcodec/nvdec_mpeg4.c
+++ b/libavcodec/nvdec_mpeg4.c
@@ -70,7 +70,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx,
             .vop_time_increment_bitcount  = m->time_increment_bits,
             .top_field_first              = s->top_field_first,
             .resync_marker_disable        = !m->resync_marker,
-            .quant_type                   = s->mpeg_quant,
+            .quant_type                   = m->mpeg_quant,
             .quarter_sample               = s->quarter_sample,
             .short_video_header           = avctx->codec->id == AV_CODEC_ID_H263,
             .divx_flags                   = s->divx_packed ? 5 : 0,
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index 8338c0732d..533e6750a1 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -70,7 +70,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx,
             .obmc_disable                 = 1,
             .sprite_enable                = ctx->vol_sprite_usage,
             .sprite_warping_accuracy      = ctx->sprite_warping_accuracy,
-            .quant_type                   = s->mpeg_quant,
+            .quant_type                   = ctx->mpeg_quant,
             .quarter_sample               = s->quarter_sample,
             .data_partitioned             = s->data_partitioning,
             .reversible_vlc               = ctx->rvlc,
diff --git a/libavcodec/vdpau_mpeg4.c b/libavcodec/vdpau_mpeg4.c
index 91981935f5..7ec7a74ad1 100644
--- a/libavcodec/vdpau_mpeg4.c
+++ b/libavcodec/vdpau_mpeg4.c
@@ -68,7 +68,7 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
     info->vop_fcode_backward                = ctx->b_code;
     info->resync_marker_disable             = !ctx->resync_marker;
     info->interlaced                        = !s->progressive_sequence;
-    info->quant_type                        = s->mpeg_quant;
+    info->quant_type                        = ctx->mpeg_quant;
     info->quarter_sample                    = s->quarter_sample;
     info->short_video_header                = avctx->codec->id == AV_CODEC_ID_H263;
     info->rounding_control                  = s->no_rounding;
diff --git a/libavcodec/x86/mpegvideoenc_template.c b/libavcodec/x86/mpegvideoenc_template.c
index 85e9159f91..dbb2187121 100644
--- a/libavcodec/x86/mpegvideoenc_template.c
+++ b/libavcodec/x86/mpegvideoenc_template.c
@@ -109,7 +109,7 @@ static int RENAME(dct_quantize)(MPVEncContext *const s,
         qmat = s->q_inter_matrix16[qscale][0];
     }
 
-    if ((s->c.out_format == FMT_H263 || s->c.out_format == FMT_H261) && !s->c.mpeg_quant) {
+    if ((s->c.out_format == FMT_H263 || s->c.out_format == FMT_H261) && !s->mpeg_quant) {
         __asm__ volatile(
             "movd %%"FF_REG_a", %%xmm3          \n\t" // last_non_zero_p1
             SPREADW("%%xmm3")



More information about the ffmpeg-cvslog mailing list