History

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

Andreas Rheinhardt committed 1 year ago

Commit ed736751 parent 778c0a411 files · +28 −25Browse files

Unified · Split

11 files
  1. libavcodec/mpeg12enc.c +1 −1
  2. libavcodec/mpeg4videodec.c +8 −7
  3. libavcodec/mpeg4videodec.h +1 −0
  4. libavcodec/mpeg4videoenc.c +5 −5
  5. libavcodec/mpegvideo.h +0 −1
  6. libavcodec/mpegvideo_enc.c +8 −7
  7. libavcodec/mpegvideoenc.h +1 −0
  8. libavcodec/nvdec_mpeg4.c +1 −1
  9. libavcodec/vaapi_mpeg4.c +1 −1
  10. libavcodec/vdpau_mpeg4.c +1 −1
  11. libavcodec/x86/mpegvideoenc_template.c +1 −1
libavcodec/mpeg12enc.c+1−1
@@ -1125,7 +1125,7 @@ static av_cold int encode_init(AVCodecContext *avctx) · 1124 unmodified lines
11251125 } else {
11261126 s->min_qcoeff = -2047;
11271127 s->max_qcoeff = 2047;
1128− s->c.mpeg_quant = 1;
1128+ s->mpeg_quant = 1;
11291129 }
11301130 if (s->c.intra_vlc_format) {
11311131 s->intra_ac_vlc_length =
libavcodec/mpeg4videodec.c+8−7
@@ -1399,7 +1399,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1398 unmodified lines
13991399
14001400 scan_table = s->intra_scantable.permutated;
14011401
1402− if (s->mpeg_quant) {
1402+ if (ctx->mpeg_quant) {
14031403 qmul = 1;
14041404 qadd = 0;
14051405 if (rvlc)
@@ -2155,7 +2155,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 749 unmodified lines
21552155
21562156 s->last_dc[cc] += dct_diff;
21572157
2158− if (s->mpeg_quant)
2158+ if (ctx->mpeg_quant)
21592159 block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision);
21602160 else
21612161 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) · 423 unmodified lines
25852585 skip_bits(gb, 15); /* latter_half_vbv_occupancy */
25862586 check_marker(s->avctx, gb, "after latter_half_vbv_occupancy");
25872587 s->low_delay = get_bits1(gb);
2588− s->mpeg_quant = get_bits1(gb); /* mpeg2_stream */
2588+ ctx->mpeg_quant = get_bits1(gb); /* mpeg2_stream */
25892589
25902590 next_start_code_studio(gb);
25912591 extension_and_user_data(s, gb, 2);
@@ -2767,7 +2767,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 175 unmodified lines
27672767
27682768 // FIXME a bunch of grayscale shape things
27692769
2770− if ((s->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */
2770+ if ((ctx->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */
27712771 int i, v;
27722772
27732773 mpeg4_load_default_matrices(s);
@@ -3415,10 +3415,10 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 641 unmodified lines
34153415 }
34163416 }
34173417
3418− s->dct_unquantize_intra = s->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
3419− : ctx->dct_unquantize_h263_intra;
3418+ s->dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
3419+ : ctx->dct_unquantize_h263_intra;
34203420 // 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;
3421+ s->dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
34223422
34233423 end:
34243424 /* detect buggy encoders which don't set the low_delay flag
@@ -3857,6 +3857,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 432 unmodified lines
38573857 s->sprite_warping_accuracy = s1->sprite_warping_accuracy;
38583858 s->num_sprite_warping_points = s1->num_sprite_warping_points;
38593859 s->m.data_partitioning = s1->m.data_partitioning;
3860+ s->mpeg_quant = s1->mpeg_quant;
38603861 s->rvlc = s1->rvlc;
38613862 s->resync_marker = s1->resync_marker;
38623863 s->t_frame = s1->t_frame;
libavcodec/mpeg4videodec.h+1−0
@@ -52,6 +52,7 @@ typedef struct Mpeg4DecContext { · 51 unmodified lines
5252 /// sprite shift [isChroma]
5353 int sprite_shift[2];
5454
55+ int mpeg_quant;
5556 // reversible vlc
5657 int rvlc;
5758 /// could this stream contain resync markers
libavcodec/mpeg4videoenc.c+5−5
@@ -952,9 +952,9 @@ static void mpeg4_encode_vol_header(Mpeg4EncContext *const m4, · 951 unmodified lines
952952 put_bits(&s->pb, 2, 0); /* sprite enable */
953953
954954 put_bits(&s->pb, 1, 0); /* not 8 bit == false */
955− put_bits(&s->pb, 1, s->c.mpeg_quant); /* quant type = (0 = H.263 style) */
955+ put_bits(&s->pb, 1, s->mpeg_quant); /* quant type = (0 = H.263 style) */
956956
957− if (s->c.mpeg_quant) {
957+ if (s->mpeg_quant) {
958958 ff_write_quant_matrix(&s->pb, s->c.avctx->intra_matrix);
959959 ff_write_quant_matrix(&s->pb, s->c.avctx->inter_matrix);
960960 }
@@ -1304,11 +1304,11 @@ void ff_mpeg4_encode_video_packet_header(MPVEncContext *const s) · 343 unmodified lines
13041304 put_bits(&s->pb, 1, 0); /* no HEC */
13051305 }
13061306
1307−#define OFFSET(x) offsetof(MPVEncContext, c.x)
1307+#define OFFSET(x) offsetof(MPVEncContext, x)
13081308 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
13091309 static const AVOption options[] = {
1310− { "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
1311− { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
1310+ { "data_partitioning", "Use data partitioning.", OFFSET(c.data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
1311+ { "alternate_scan", "Enable alternate scantable.", OFFSET(c.alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
13121312 { "mpeg_quant", "Use MPEG quantizers instead of H.263",
13131313 OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, VE },
13141314 FF_MPV_COMMON_BFRAME_OPTS
libavcodec/mpegvideo.h+0−1
@@ -254,7 +254,6 @@ typedef struct MpegEncContext { · 253 unmodified lines
254254 int data_partitioning; ///< data partitioning flag from header
255255 int partitioned_frame; ///< is current frame partitioned
256256 int low_delay; ///< no reordering needed / has no B-frames
257− int mpeg_quant;
258257 int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG-4
259258
260259 /* divx specific, used to workaround (many) bugs in divx5 */
libavcodec/mpegvideo_enc.c+8−7
@@ -313,14 +313,15 @@ av_cold void ff_dct_encode_init(MPVEncContext *const s) · 312 unmodified lines
313313 s->dct_quantize = dct_quantize_trellis_c;
314314 }
315315
316−static av_cold void init_unquantize(MpegEncContext *const s, AVCodecContext *avctx)
316+static av_cold void init_unquantize(MPVEncContext *const s2, AVCodecContext *avctx)
317317 {
318+ MpegEncContext *const s = &s2->c;
318319 MPVUnquantDSPContext unquant_dsp_ctx;
319320
320321 ff_mpv_unquantize_init(&unquant_dsp_ctx,
321322 avctx->flags & AV_CODEC_FLAG_BITEXACT, s->q_scale_type);
322323
323− if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
324+ if (s2->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
324325 s->dct_unquantize_intra = unquant_dsp_ctx.dct_unquantize_mpeg2_intra;
325326 s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
326327 } 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 · 76 unmodified lines
403404 }
404405
405406 if (CONFIG_MPEG4_ENCODER && s->c.codec_id == AV_CODEC_ID_MPEG4 &&
406− s->c.mpeg_quant) {
407+ s->mpeg_quant) {
407408 intra_matrix = ff_mpeg4_default_intra_matrix;
408409 inter_matrix = ff_mpeg4_default_non_intra_matrix;
409410 } 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) · 429 unmodified lines
839840 //return -1;
840841 }
841842
842− 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) {
843+ 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) {
843844 // (a + x * 3 / 8) / x
844845 s->intra_quant_bias = 3 << (QUANT_BIAS_SHIFT - 3);
845846 s->inter_quant_bias = 0;
@@ -1027,7 +1028,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 181 unmodified lines
10271028 * before calling ff_mpv_common_init(). */
10281029 s->parent = m;
10291030 ff_mpv_idct_init(&s->c);
1030− init_unquantize(&s->c, avctx);
1031+ init_unquantize(s, avctx);
10311032 ff_fdctdsp_init(&s->fdsp, avctx);
10321033 ff_mpegvideoencdsp_init(&s->mpvencdsp, avctx);
10331034 ff_pixblockdsp_init(&s->pdsp, avctx);
@@ -4016,7 +4017,7 @@ static int dct_quantize_trellis_c(MPVEncContext *const s, · 2982 unmodified lines
40164017 last_non_zero = 0;
40174018 qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale];
40184019 matrix = n < 4 ? s->c.intra_matrix : s->c.chroma_intra_matrix;
4019− if (s->c.mpeg_quant || s->c.out_format == FMT_MPEG1 || s->c.out_format == FMT_MJPEG)
4020+ if (s->mpeg_quant || s->c.out_format == FMT_MPEG1 || s->c.out_format == FMT_MJPEG)
40204021 bias= 1<<(QMAT_SHIFT-1);
40214022
40224023 if (n > 3 && s->intra_chroma_ac_vlc_length) {
@@ -4331,7 +4332,7 @@ static int dct_quantize_refine(MPVEncContext *const s, //FIXME breaks denoise? · 308 unmodified lines
43314332 dc= block[0]*q;
43324333 // block[0] = (block[0] + (q >> 1)) / q;
43334334 start_i = 1;
4334−// if (s->c.mpeg_quant || s->c.out_format == FMT_MPEG1)
4335+// if (s->mpeg_quant || s->c.out_format == FMT_MPEG1)
43354336 // bias= 1<<(QMAT_SHIFT-1);
43364337 if (n > 3 && s->intra_chroma_ac_vlc_length) {
43374338 length = s->intra_chroma_ac_vlc_length;
libavcodec/mpegvideoenc.h+1−0
@@ -147,6 +147,7 @@ typedef struct MPVEncContext { · 146 unmodified lines
147147 int last_mv_dir; ///< last mv_dir, used for B-frame encoding
148148
149149 /* MPEG-4 specific */
150+ int mpeg_quant;
150151 PutBitContext tex_pb; ///< used for data partitioned VOPs
151152 PutBitContext pb2; ///< used for data partitioned VOPs
152153
libavcodec/nvdec_mpeg4.c+1−1
@@ -70,7 +70,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, · 69 unmodified lines
7070 .vop_time_increment_bitcount = m->time_increment_bits,
7171 .top_field_first = s->top_field_first,
7272 .resync_marker_disable = !m->resync_marker,
73− .quant_type = s->mpeg_quant,
73+ .quant_type = m->mpeg_quant,
7474 .quarter_sample = s->quarter_sample,
7575 .short_video_header = avctx->codec->id == AV_CODEC_ID_H263,
7676 .divx_flags = s->divx_packed ? 5 : 0,
libavcodec/vaapi_mpeg4.c+1−1
@@ -70,7 +70,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, · 69 unmodified lines
7070 .obmc_disable = 1,
7171 .sprite_enable = ctx->vol_sprite_usage,
7272 .sprite_warping_accuracy = ctx->sprite_warping_accuracy,
73− .quant_type = s->mpeg_quant,
73+ .quant_type = ctx->mpeg_quant,
7474 .quarter_sample = s->quarter_sample,
7575 .data_partitioned = s->data_partitioning,
7676 .reversible_vlc = ctx->rvlc,
libavcodec/vdpau_mpeg4.c+1−1
@@ -68,7 +68,7 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, · 67 unmodified lines
6868 info->vop_fcode_backward = ctx->b_code;
6969 info->resync_marker_disable = !ctx->resync_marker;
7070 info->interlaced = !s->progressive_sequence;
71− info->quant_type = s->mpeg_quant;
71+ info->quant_type = ctx->mpeg_quant;
7272 info->quarter_sample = s->quarter_sample;
7373 info->short_video_header = avctx->codec->id == AV_CODEC_ID_H263;
7474 info->rounding_control = s->no_rounding;
libavcodec/x86/mpegvideoenc_template.c+1−1
@@ -109,7 +109,7 @@ static int RENAME(dct_quantize)(MPVEncContext *const s, · 108 unmodified lines
109109 qmat = s->q_inter_matrix16[qscale][0];
110110 }
111111
112− if ((s->c.out_format == FMT_H263 || s->c.out_format == FMT_H261) && !s->c.mpeg_quant) {
112+ if ((s->c.out_format == FMT_H263 || s->c.out_format == FMT_H261) && !s->mpeg_quant) {
113113 __asm__ volatile(
114114 "movd %%"FF_REG_a", %%xmm3 \n\t" // last_non_zero_p1
115115 SPREADW("%%xmm3")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t