From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 39/39] avcodec/mpegvideo: Inline values in ff_update_block_index() Date: Wed, 27 Jul 2022 00:08:14 +0200 Message-ID: <DB6PR0101MB2214FB4D03390725FE597C388F949@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw) In-Reply-To: <DB6PR0101MB22140CEE765FDFAB596653698F949@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> 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. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- 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 287fd38bd3..b1b2727535 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 4719a734c9..b04616f84d 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 2ac3f2c7b2..61d1e4c527 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); -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-07-27 9:36 UTC|newest] Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-26 21:47 [FFmpeg-devel] [PATCH 01/39] avcodec/hevcdsp: Constify src pointers Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 02/39] avcodec/hevcdec: Constify src pointers of HEVC DSP functions Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 03/39] avcodec/threadframe: Constify the frame in ff_thread_await_progress Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 04/39] avcodec: Constify ThreadFrames if possible Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 05/39] avcodec/vp9dec: Constify VP9TileData->VP9Context pointer target Andreas Rheinhardt 2022-07-27 10:25 ` Ronald S. Bultje 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 06/39] avcodec/wavpack: Constify slice threads' ptr to main context Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 07/39] avcodec/vp8: " Andreas Rheinhardt 2022-07-27 10:24 ` Ronald S. Bultje 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 08/39] avcodec/proresdec2: " Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 09/39] avcodec/magicyuv: " Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 10/39] avcodec/jpeg2000dec: " Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 11/39] avcodec/dxv: " Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 12/39] avcodec/dvdec: " Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 13/39] avcodec/diracdec: " Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 14/39] avcodec/half2float: Constify arrays in half2float() Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 15/39] avcodec/exr: Constify slice threads' ptr to main context Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 16/39] avcodec/xwdenc: Don't modify input frame Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 17/39] swscale/rgb2rgb: Don't cast const away Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 18/39] avcodec/gif: Remove redundant cast Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 19/39] avcodec/fitsenc: Don't cast const away unnecessarily Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 20/39] avcodec/diracdsp: " Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 21/39] avcodec/dxv: " Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 22/39] avcodec/cinepakenc: Avoid casting const away Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 23/39] avcodec/ilbcdec: Fix const correctness Andreas Rheinhardt 2022-07-26 22:07 ` [FFmpeg-devel] [PATCH 24/39] avcodec/ilbcdec: Move transient GetBitContext from ctx to stack Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 25/39] avcodec/pnmdec, pnm_parser: Improve const-correctness Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 26/39] avcodec/pnmdec: Fix indentation Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 27/39] avcodec/videodsp: Constify buf in VideoDSPContext.prefetch Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 28/39] avcodec/snow: Remove unused halfpel_plane Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 29/39] avcodec/pngenc: Don't cast const away unnecessarily Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 30/39] avcodec/lossless_videoencdsp: Constify src sub_left_predict Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 31/39] avcodec/me_cmp: Constify me_cmp_func buffer parameters Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 32/39] avcodec/h264chroma: Constify src in h264_chroma_mc_func Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 33/39] avcodec/cfhdencdsp: Constify input pointers Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 34/39] avcodec/mpegvideoencdsp: Allow pointers to const where possible Andreas Rheinhardt 2022-07-28 22:05 ` Michael Niedermayer 2022-07-30 9:55 ` Andreas Rheinhardt 2022-07-30 17:12 ` Michael Niedermayer 2022-08-02 9:30 ` Anton Khirnov 2022-08-03 15:28 ` Michael Niedermayer 2022-08-03 15:48 ` Michael Niedermayer 2022-08-06 13:07 ` Anton Khirnov 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 35/39] avcodec/mpegvideodsp: Constify src pointers Andreas Rheinhardt 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 36/39] avcodec/motion_est: Constify pointers to frame data Andreas Rheinhardt 2022-07-28 22:04 ` Michael Niedermayer 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 37/39] avcodec/mpegvideo_motion: Constify ff_mpv_motion Andreas Rheinhardt 2022-07-28 22:03 ` Michael Niedermayer 2022-07-26 22:08 ` [FFmpeg-devel] [PATCH 38/39] avcodec: Constify frame->data pointers for encoders where possible Andreas Rheinhardt 2022-07-26 22:08 ` Andreas Rheinhardt [this message] 2022-07-28 22:02 ` [FFmpeg-devel] [PATCH 39/39] avcodec/mpegvideo: Inline values in ff_update_block_index() Michael Niedermayer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=DB6PR0101MB2214FB4D03390725FE597C388F949@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git