From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 2/6] avcodec/mpegvideo: Make inlining is_mpeg12 more flexible
Date: Mon, 17 Oct 2022 03:34:38 +0200
Message-ID: <GV1P250MB0737AEEB637C14640131FC258F299@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <GV1P250MB0737DB7E1DA91101E51ECD208F299@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>
There are two types of checks for whether the current codec
is MPEG-1/2 in mpv_reconstruct_mb_internal(): Those that are
required for correctness and those that are not; an example
of the latter is "is_mpeg12 || (s->codec_id != AV_CODEC_ID_WMV2)".
The reason for the existence of such checks is that
mpv_reconstruct_mb_internal() has the av_always_inline attribute
and is_mpeg12 is usually inlined, so that in case we are dealing
with MPEG-1/2 the above check can be completely optimized away.
But is_mpeg12 is not always inlined: it is not in case
CONFIG_SMALL is true in which case is_mpeg12 is always zero,
so that the checks required for correctness need to check
out_format explicitly. This is currently done via a macro
in mpv_reconstruct_mb_internal(), so that the fact that
it is CONFIG_SMALL that determines this is encoded at two places.
This commit changes this by making is_mpeg12 a three-state:
DEFINITELY_MPEG12, MAY_BE_MPEG12 and NOT_MPEG12. In the second
case, one has to resort to check out_format, in the other cases
is_mpeg12 can be taken at face-value. This will allow to make
inlining is_mpeg12 more flexible in a future commit.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 448b65bb96..c2fedbfdaa 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1294,6 +1294,10 @@ void ff_clean_intra_table_entries(MpegEncContext *s)
s->mbintra_table[xy]= 0;
}
+#define NOT_MPEG12 0
+#define MAY_BE_MPEG12 1
+#define DEFINITELY_MPEG12 2
+
/* generic function called after a macroblock has been parsed by the
decoder or after it has been encoded by the encoder.
@@ -1309,14 +1313,14 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
int lowres_flag, int is_mpeg12)
{
#define IS_ENCODER(s) (CONFIG_MPEGVIDEOENC && !lowres_flag && (s)->encoding)
-#define IS_MPEG12(s) (CONFIG_SMALL ? ((s)->out_format == FMT_MPEG1) : is_mpeg12)
+#define IS_MPEG12(s) (is_mpeg12 == MAY_BE_MPEG12 ? ((s)->out_format == FMT_MPEG1) : is_mpeg12)
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
s->current_picture.qscale_table[mb_xy] = s->qscale;
/* update DC predictors for P macroblocks */
if (!s->mb_intra) {
- if (!is_mpeg12 && (s->h263_pred || s->h263_aic)) {
+ if (is_mpeg12 != DEFINITELY_MPEG12 && (s->h263_pred || s->h263_aic)) {
if(s->mbintra_table[mb_xy])
ff_clean_intra_table_entries(s);
} else {
@@ -1324,8 +1328,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
s->last_dc[1] =
s->last_dc[2] = 128 << s->intra_dc_precision;
}
- }
- else if (!is_mpeg12 && (s->h263_pred || s->h263_aic))
+ } else if (is_mpeg12 != DEFINITELY_MPEG12 && (s->h263_pred || s->h263_aic))
s->mbintra_table[mb_xy]=1;
if (!IS_ENCODER(s) || (s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
@@ -1399,7 +1402,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
}else{
op_qpix = s->me.qpel_put;
- if ((is_mpeg12 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
+ if ((is_mpeg12 == DEFINITELY_MPEG12 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
op_pix = s->hdsp.put_pixels_tab;
}else{
op_pix = s->hdsp.put_no_rnd_pixels_tab;
@@ -1444,7 +1447,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
}
}
- } else if(is_mpeg12 || (s->codec_id != AV_CODEC_ID_WMV2)){
+ } else if (is_mpeg12 == DEFINITELY_MPEG12 || (s->codec_id != AV_CODEC_ID_WMV2)){
add_dct(s, block[0], 0, dest_y , dct_linesize);
add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
@@ -1477,7 +1480,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
} else {
/* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode.
TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */
- if (!is_mpeg12 && CONFIG_MPEG4_DECODER && /* s->codec_id == AV_CODEC_ID_MPEG4 && */
+ if (is_mpeg12 != DEFINITELY_MPEG12 && CONFIG_MPEG4_DECODER &&
+ /* s->codec_id == AV_CODEC_ID_MPEG4 && */
s->avctx->bits_per_raw_sample > 8) {
ff_mpeg4_decode_studio(s, dest_y, dest_cb, dest_cr, block_size,
uvlinesize, dct_linesize, dct_offset);
@@ -1558,12 +1562,16 @@ void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
#if !CONFIG_SMALL
if(s->out_format == FMT_MPEG1) {
- if(s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, 1);
- else mpv_reconstruct_mb_internal(s, block, 0, 1);
- } else
+ if (s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, DEFINITELY_MPEG12);
+ else mpv_reconstruct_mb_internal(s, block, 0, DEFINITELY_MPEG12);
+ } else {
+ if (s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, NOT_MPEG12);
+ else mpv_reconstruct_mb_internal(s, block, 0, NOT_MPEG12);
+ }
+#else
+ if (s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, MAY_BE_MPEG12);
+ else mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12);
#endif
- if(s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, 0);
- else mpv_reconstruct_mb_internal(s, block, 0, 0);
}
void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
--
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-10-17 1:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-17 1:33 [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo: Ignore skip_idct for encoders Andreas Rheinhardt
2022-10-17 1:34 ` Andreas Rheinhardt [this message]
2022-10-17 1:34 ` [FFmpeg-devel] [PATCH 3/6] avcodec/mpegvideo: Inline is_encoder in mpv_reconstruct_mb_internal() Andreas Rheinhardt
2022-10-17 1:34 ` [FFmpeg-devel] [PATCH 4/6] avcodec/mpegvideo: Split ff_mpv_reconstruct_mb() into de/encoder part Andreas Rheinhardt
2022-10-17 1:34 ` [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg12dec: Remove always-true check Andreas Rheinhardt
2022-10-17 1:34 ` [FFmpeg-devel] [PATCH 6/6] avcodec/mpv_reconstruct_mb_template: Optimize dead code away Andreas Rheinhardt
2022-10-19 12:12 ` [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo: Ignore skip_idct for encoders Andreas Rheinhardt
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=GV1P250MB0737AEEB637C14640131FC258F299@GV1P250MB0737.EURP250.PROD.OUTLOOK.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