It is an MPEG-4-only value; it is always five for the MPEG-4
encoder, so just hardcode this value and move the MpegEncContext
field to Mpeg4DecContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>
---
 libavcodec/h263dec.c           |  1 -
 libavcodec/mpeg4video_parser.c |  2 +-
 libavcodec/mpeg4videodec.c     | 20 ++++++++++----------
 libavcodec/mpeg4videodec.h     |  2 ++
 libavcodec/mpeg4videoenc.c     |  2 +-
 libavcodec/mpegvideo.h         |  1 -
 libavcodec/mpegvideo_enc.c     |  2 --
 libavcodec/vaapi_mpeg4.c       |  2 +-
 8 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 19a57582ad..a81786479d 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -99,7 +99,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
     if (ret < 0)
         return ret;
 
-    s->quant_precision = 5;
     s->decode_mb       = ff_h263_decode_mb;
     s->low_delay       = 1;
 
diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
index 402594e01d..b00b523bde 100644
--- a/libavcodec/mpeg4video_parser.c
+++ b/libavcodec/mpeg4video_parser.c
@@ -122,7 +122,7 @@ static av_cold int 
mpeg4video_parse_init(AVCodecParserContext *s)
     struct Mp4vParseContext *pc = s->priv_data;
 
     pc->first_picture           = 1;
-    pc->dec_ctx.m.quant_precision     = 5;
+    pc->dec_ctx.quant_precision       = 5;
     pc->dec_ctx.m.slice_context_count = 1;
     pc->dec_ctx.showed_packed_warning = 1;
     return 0;
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 77bd3e9947..debcafc4c0 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -728,7 +728,7 @@ int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext 
*ctx)
     s->mb_y = mb_num / s->mb_width;
 
     if (ctx->shape != BIN_ONLY_SHAPE) {
-        int qscale = get_bits(&s->gb, s->quant_precision);
+        int qscale = get_bits(&s->gb, ctx->quant_precision);
         if (qscale)
             s->chroma_qscale = s->qscale = qscale;
     }
@@ -2706,17 +2706,16 @@ static int decode_vol_header(Mpeg4DecContext *ctx, 
GetBitContext *gb)
         // FIXME sadct disable bit if verid!=1 && shape not rect
 
         if (get_bits1(gb) == 1) {                   /* not_8_bit */
-            s->quant_precision = get_bits(gb, 4);   /* quant_precision */
+            ctx->quant_precision = get_bits(gb, 4); /* quant_precision */
             if (get_bits(gb, 4) != 8)               /* bits_per_pixel */
                 av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n");
-            if (s->quant_precision != 5)
+            if (ctx->quant_precision != 5)
                 av_log(s->avctx, AV_LOG_ERROR,
-                       "quant precision %d\n", s->quant_precision);
-            if (s->quant_precision<3 || s->quant_precision>9) {
-                s->quant_precision = 5;
-            }
+                       "quant precision %d\n", ctx->quant_precision);
+            if (ctx->quant_precision < 3 || ctx->quant_precision > 9)
+                ctx->quant_precision = 5;
         } else {
-            s->quant_precision = 5;
+            ctx->quant_precision = 5;
         }
 
         // FIXME a bunch of grayscale shape things
@@ -2904,7 +2903,7 @@ no_cplx_est:
         av_log(s->avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, 
ps:%d, low_delay:%d  %s%s%s%s\n",
                s->avctx->framerate.den, s->avctx->framerate.num,
                ctx->time_increment_bits,
-               s->quant_precision,
+               ctx->quant_precision,
                s->progressive_sequence,
                s->low_delay,
                ctx->scalability ? "scalability " :"" , s->quarter_sample ? 
"qpel " : "",
@@ -3286,7 +3285,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, 
GetBitContext *gb,
     }
 
     if (ctx->shape != BIN_ONLY_SHAPE) {
-        s->chroma_qscale = s->qscale = get_bits(gb, s->quant_precision);
+        s->chroma_qscale = s->qscale = get_bits(gb, ctx->quant_precision);
         if (s->qscale == 0) {
             av_log(s->avctx, AV_LOG_ERROR,
                    "Error, header damaged or not MPEG-4 header (qscale=0)\n");
@@ -3798,6 +3797,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     s->low_delay = 0; /* default, might be overridden in the vol header during 
header parsing */
     s->decode_mb = mpeg4_decode_mb;
     ctx->time_increment_bits = 4; /* default value for broken headers */
+    ctx->quant_precision     = 5;
 
     avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
 
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 4a26d18987..734237b16f 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -60,6 +60,8 @@ typedef struct Mpeg4DecContext {
     int enhancement_type;
     int scalability;
 
+    int quant_precision;
+
     /// QP above which the ac VLC should be used for intra dc
     int intra_dc_threshold;
 
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 84b603f312..0b18776497 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -1358,7 +1358,7 @@ void ff_mpeg4_encode_video_packet_header(MpegEncContext 
*s)
     put_bits(&s->pb, 1, 1);
 
     put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y * s->mb_width);
-    put_bits(&s->pb, s->quant_precision, s->qscale);
+    put_bits(&s->pb, 5 /* quant_precision */, s->qscale);
     put_bits(&s->pb, 1, 0); /* no HEC */
 }
 
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 844da6881f..8083299b66 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -384,7 +384,6 @@ typedef struct MpegEncContext {
     uint16_t pp_field_time;
     uint16_t pb_field_time;         ///< like above, just for interlaced
     int mcsel;
-    int quant_precision;
     int quarter_sample;              ///< 1->qpel, 0->half pel ME/MC
     int data_partitioning;           ///< data partitioning flag from header
     int partitioned_frame;           ///< is current frame partitioned
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d05a93d249..abeb235277 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -951,8 +951,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
             s->h263_slice_structured = 1;
     }
 
-    s->quant_precision = 5;
-
     if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) {
         ff_h263_encode_init(s);
 #if CONFIG_MSMPEG4ENC
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index d182f879cb..2c9dfbe42f 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -74,7 +74,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, 
av_unused const uint8_
             .resync_marker_disable        = !ctx->resync_marker,
         },
         .no_of_sprite_warping_points      = ctx->num_sprite_warping_points,
-        .quant_precision                  = s->quant_precision,
+        .quant_precision                  = ctx->quant_precision,
         .vop_fields.bits = {
             .vop_coding_type              = s->pict_type - AV_PICTURE_TYPE_I,
             .backward_reference_vop_coding_type =
-- 
2.40.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to