[FFmpeg-cvslog] avcodec/mpegvideo: Partially check for being encoder at compile-time

Andreas Rheinhardt git at videolan.org
Tue Jan 4 18:21:09 EET 2022


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Dec 23 05:43:33 2021 +0100| [7c0c73bca0bc73fbb7f02128bd6b2af95f3ceb38] | committer: Andreas Rheinhardt

avcodec/mpegvideo: Partially check for being encoder at compile-time

Whether lowres is in use or not is inlined in
mpv_reconstruct_mb_internal(), so one can use the fact
that lowres is always zero during encoding to evaluate
the checks for whether one is encoding or not at compile-time
when one is in lowres mode.
Also reorder the main check to check for whether it is an encoder
first to shortcircuit it in the common case of a decoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7c0c73bca0bc73fbb7f02128bd6b2af95f3ceb38
---

 libavcodec/mpegvideo.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index b38282dcb2..0d09a3f058 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1961,6 +1961,7 @@ static av_always_inline
 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)
     const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
 
     s->current_picture.qscale_table[mb_xy] = s->qscale;
@@ -1979,8 +1980,8 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
     else if (!is_mpeg12 && (s->h263_pred || s->h263_aic))
         s->mbintra_table[mb_xy]=1;
 
-    if ((s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
-        !(s->encoding && (s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
+    if (!IS_ENCODER(s) || (s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
+        !((s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
           s->avctx->mb_decision != FF_MB_DECISION_RD)) { // FIXME precalc
         uint8_t *dest_y, *dest_cb, *dest_cr;
         int dct_linesize, dct_offset;
@@ -1988,12 +1989,12 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
         qpel_mc_func (*op_qpix)[16];
         const int linesize   = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong for field pics
         const int uvlinesize = s->current_picture.f->linesize[1];
-        const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band || lowres_flag;
+        const int readable = s->pict_type != AV_PICTURE_TYPE_B || IS_ENCODER(s) || s->avctx->draw_horiz_band || lowres_flag;
         const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8;
 
         /* avoid copy if macroblock skipped in last frame too */
         /* skip only during decoding as we might trash the buffers during encoding a bit */
-        if(!s->encoding){
+        if (!IS_ENCODER(s)) {
             uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
 
             if (s->mb_skipped) {
@@ -2023,7 +2024,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
         if (!s->mb_intra) {
             /* motion handling */
             /* decoding or more than one mb_type (MC was already done otherwise) */
-            if(!s->encoding){
+            if (!IS_ENCODER(s)) {
 
                 if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
                     if (s->mv_dir & MV_DIR_FORWARD) {
@@ -2075,7 +2076,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
             }
 
             /* add dct residue */
-            if(s->encoding || !(   s->msmpeg4_version || s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDEO
+            if (IS_ENCODER(s) || !(s->msmpeg4_version || s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO
                                 || (s->codec_id==AV_CODEC_ID_MPEG4 && !s->mpeg_quant))){
                 add_dequant_dct(s, block[0], 0, dest_y                          , dct_linesize, s->qscale);
                 add_dequant_dct(s, block[1], 1, dest_y              + block_size, dct_linesize, s->qscale);
@@ -2182,7 +2183,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
                 }
             }
             /* dct only in intra block */
-            else if(s->encoding || !(s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDEO)){
+            else if (IS_ENCODER(s) || !(s->codec_id == AV_CODEC_ID_MPEG1VIDEO || s->codec_id == AV_CODEC_ID_MPEG2VIDEO)) {
                 put_dct(s, block[0], 0, dest_y                          , dct_linesize, s->qscale);
                 put_dct(s, block[1], 1, dest_y              + block_size, dct_linesize, s->qscale);
                 put_dct(s, block[2], 2, dest_y + dct_offset             , dct_linesize, s->qscale);



More information about the ffmpeg-cvslog mailing list