avcodec/mpegvideo: Move quant_precision to Mpeg4DecContext

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.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2024-06-14 18:03:06 +02:00
parent c735552b0b
commit 594723ec38
8 changed files with 15 additions and 17 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 */
}

View File

@ -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

View File

@ -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

View File

@ -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 =