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 <michael@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-07-26 20:02:25 +02:00
parent dd20ebb2ca
commit 145236741d
10 changed files with 33 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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