From 145236741d9a7c18da4ee22c30b777b781bc5ac8 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 26 Jul 2022 20:02:25 +0200 Subject: avcodec/mpegvideo: Inline values in ff_update_block_index() This is possible for most of the callers, because e.g. only the MPEG-4 decoder can have bits_per_raw_sample > 8. Also most mpegvideo-based codecs are 420 only. Reviewed-by: Michael Niedermayer Signed-off-by: Andreas Rheinhardt --- libavcodec/h261dec.c | 4 ++-- libavcodec/h261enc.c | 2 +- libavcodec/h263dec.c | 3 ++- libavcodec/mpeg4videodec.c | 6 ++++-- libavcodec/mpeg_er.c | 3 ++- libavcodec/mpegvideo.h | 12 +++++++----- libavcodec/mpegvideo_enc.c | 2 +- libavcodec/rv10.c | 2 +- libavcodec/rv34.c | 2 +- libavcodec/vc1_block.c | 17 ++++++++++++----- 10 files changed, 33 insertions(+), 20 deletions(-) diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index af9ccbbd70..97c126ab5a 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -214,7 +214,7 @@ static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2) s->mb_y = ((h->gob_number - 1) / 2) * 3 + i / 11; xy = s->mb_x + s->mb_y * s->mb_stride; ff_init_block_index(s); - ff_update_block_index(s); + ff_update_block_index(s, 8, s->avctx->lowres, 1); for (j = 0; j < 6; j++) s->block_last_index[j] = -1; @@ -400,7 +400,7 @@ static int h261_decode_mb(H261DecContext *h) s->mb_y = ((h->gob_number - 1) / 2) * 3 + ((h->current_mba - 1) / 11); xy = s->mb_x + s->mb_y * s->mb_stride; ff_init_block_index(s); - ff_update_block_index(s); + ff_update_block_index(s, 8, s->avctx->lowres, 1); // Read mtype com->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index a7fb666faa..a1fba968a4 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -139,7 +139,7 @@ void ff_h261_reorder_mb_index(MpegEncContext *s) s->mb_y += 3 * index; ff_init_block_index(s); - ff_update_block_index(s); + ff_update_block_index(s, 8, 0, 1); } } diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 39183c8b27..b4f9fa5022 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -258,7 +258,8 @@ static int decode_slice(MpegEncContext *s) for (; s->mb_x < s->mb_width; s->mb_x++) { int ret; - ff_update_block_index(s); + ff_update_block_index(s, s->avctx->bits_per_raw_sample, + s->avctx->lowres, s->chroma_x_shift); if (s->resync_mb_x == s->mb_x && s->resync_mb_y + 1 == s->mb_y) s->first_slice_line = 0; diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 5591816db5..bfebc3806c 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -772,7 +772,8 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx) int dir = 0; mb_num++; - ff_update_block_index(s); + ff_update_block_index(s, s->avctx->bits_per_raw_sample, + s->avctx->lowres, s->chroma_x_shift); if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) s->first_slice_line = 0; @@ -963,7 +964,8 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) const int xy = s->mb_x + s->mb_y * s->mb_stride; mb_num++; - ff_update_block_index(s); + ff_update_block_index(s, s->avctx->bits_per_raw_sample, + s->avctx->lowres, s->chroma_x_shift); if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) s->first_slice_line = 0; diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c index f54cb8548b..02f407d8ea 100644 --- a/libavcodec/mpeg_er.c +++ b/libavcodec/mpeg_er.c @@ -75,7 +75,8 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type, memcpy(s->mv, mv, sizeof(*mv)); ff_init_block_index(s); - ff_update_block_index(s); + ff_update_block_index(s, s->avctx->bits_per_raw_sample, + s->avctx->lowres, s->chroma_x_shift); s->bdsp.clear_blocks(s->block[0]); if (!s->chroma_y_shift) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 82889a0edd..195a2b3238 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -590,9 +590,11 @@ void ff_mpv_motion(MpegEncContext *s, op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16]); -static inline void ff_update_block_index(MpegEncContext *s){ - const int bytes_per_pixel = 1 + (s->avctx->bits_per_raw_sample > 8); - const int block_size= (8*bytes_per_pixel) >> s->avctx->lowres; +static inline void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, + int lowres, int chroma_x_shift) +{ + const int bytes_per_pixel = 1 + (bits_per_raw_sample > 8); + const int block_size = (8 * bytes_per_pixel) >> lowres; s->block_index[0]+=2; s->block_index[1]+=2; @@ -601,8 +603,8 @@ static inline void ff_update_block_index(MpegEncContext *s){ s->block_index[4]++; s->block_index[5]++; s->dest[0]+= 2*block_size; - s->dest[1]+= (2 >> s->chroma_x_shift) * block_size; - s->dest[2]+= (2 >> s->chroma_x_shift) * block_size; + s->dest[1] += (2 >> chroma_x_shift) * block_size; + s->dest[2] += (2 >> chroma_x_shift) * block_size; } #endif /* AVCODEC_MPEGVIDEO_H */ diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index c9d9e2a764..86a9b55078 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -2852,7 +2852,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ s->mb_x = mb_x; s->mb_y = mb_y; // moved into loop, can get changed by H.261 - ff_update_block_index(s); + ff_update_block_index(s, 8, 0, s->chroma_x_shift); if(CONFIG_H261_ENCODER && s->codec_id == AV_CODEC_ID_H261){ ff_h261_reorder_mb_index(s); diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 23947201a4..abf42612cb 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -531,7 +531,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, /* decode each macroblock */ for (s->mb_num_left = mb_count; s->mb_num_left > 0; s->mb_num_left--) { int ret; - ff_update_block_index(s); + ff_update_block_index(s, 8, s->avctx->lowres, 1); ff_tlog(avctx, "**mb x=%d y=%d\n", s->mb_x, s->mb_y); s->mv_dir = MV_DIR_FORWARD; diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 5f3b7d31cd..b789db05fd 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -1445,7 +1445,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int ff_init_block_index(s); while(!check_slice_end(r, s)) { - ff_update_block_index(s); + ff_update_block_index(s, 8, 0, 1); if(r->si.type) res = rv34_decode_inter_macroblock(r, r->intra_types + s->mb_x * 4 + 4); diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c index 119df4081d..3267fc269b 100644 --- a/libavcodec/vc1_block.c +++ b/libavcodec/vc1_block.c @@ -68,6 +68,13 @@ static inline void init_block_index(VC1Context *v) } } +static inline void update_block_index(MpegEncContext *s) +{ + /* VC1 is always 420 except when using AV_CODEC_FLAG_GRAY + * (or a HWAccel). Shall we inline this value? */ + ff_update_block_index(s, 8, 0, s->chroma_x_shift); +} + /** @} */ //Bitplane group static void vc1_put_blocks_clamped(VC1Context *v, int put_signed) @@ -2570,7 +2577,7 @@ static void vc1_decode_i_blocks(VC1Context *v) s->mb_x = 0; init_block_index(v); for (; s->mb_x < v->end_mb_x; s->mb_x++) { - ff_update_block_index(s); + update_block_index(s); s->bdsp.clear_blocks(v->block[v->cur_blk_idx][0]); mb_pos = s->mb_x + s->mb_y * s->mb_width; s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA; @@ -2705,7 +2712,7 @@ static int vc1_decode_i_blocks_adv(VC1Context *v) init_block_index(v); for (;s->mb_x < s->mb_width; s->mb_x++) { mquant = v->pq; - ff_update_block_index(s); + update_block_index(s); s->bdsp.clear_blocks(v->block[v->cur_blk_idx][0]); mb_pos = s->mb_x + s->mb_y * s->mb_stride; s->current_picture.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA; @@ -2830,7 +2837,7 @@ static void vc1_decode_p_blocks(VC1Context *v) s->mb_x = 0; init_block_index(v); for (; s->mb_x < s->mb_width; s->mb_x++) { - ff_update_block_index(s); + update_block_index(s); if (v->fcm == ILACE_FIELD || (v->fcm == PROGRESSIVE && v->mv_type_is_raw) || v->skip_is_raw) if (get_bits_left(&v->s.gb) <= 1) { @@ -2919,7 +2926,7 @@ static void vc1_decode_b_blocks(VC1Context *v) s->mb_x = 0; init_block_index(v); for (; s->mb_x < s->mb_width; s->mb_x++) { - ff_update_block_index(s); + update_block_index(s); if (v->fcm == ILACE_FIELD || v->skip_is_raw || v->dmb_is_raw) if (get_bits_left(&v->s.gb) <= 1) { @@ -2981,7 +2988,7 @@ static void vc1_decode_skip_blocks(VC1Context *v) for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { s->mb_x = 0; init_block_index(v); - ff_update_block_index(s); + update_block_index(s); memcpy(s->dest[0], s->last_picture.f->data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16); memcpy(s->dest[1], s->last_picture.f->data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8); memcpy(s->dest[2], s->last_picture.f->data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8); -- cgit v1.2.3