You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/mpegvideo: Move mpeg_quant to {Mpeg4Dec,MPVEnc}Context
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -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 =
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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")
|
||||
|
Reference in New Issue
Block a user