[FFmpeg-devel] [PATCH v2 42/71] avcodec/vc1_mc: Don't check AVFrame INTERLACE flags

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat May 11 23:51:06 EEST 2024


Instead cache these values in VC1Context to avoid the indirection
and AND.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/vc1.h    |  1 +
 libavcodec/vc1_mc.c | 20 +++++++++-----------
 libavcodec/vc1dec.c |  2 ++
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h
index 0e01458c89..185236662f 100644
--- a/libavcodec/vc1.h
+++ b/libavcodec/vc1.h
@@ -293,6 +293,7 @@ typedef struct VC1Context{
     uint8_t next_luty[2][256], next_lutuv[2][256];  ///< lookup tables used for intensity compensation
     uint8_t (*curr_luty)[256]  ,(*curr_lutuv)[256];
     int last_use_ic, *curr_use_ic, next_use_ic, aux_use_ic;
+    int last_interlaced, next_interlaced; ///< whether last_pic, next_pic is interlaced
     int rnd;                        ///< rounding control
     int cbptab;
 
diff --git a/libavcodec/vc1_mc.c b/libavcodec/vc1_mc.c
index 90ff1eee58..fad9a4c370 100644
--- a/libavcodec/vc1_mc.c
+++ b/libavcodec/vc1_mc.c
@@ -233,7 +233,7 @@ void ff_vc1_mc_1mv(VC1Context *v, int dir)
             luty  = v->last_luty;
             lutuv = v->last_lutuv;
             use_ic = v->last_use_ic;
-            interlace = !!(s->last_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
+            interlace = v->last_interlaced;
         }
     } else {
         srcY = s->next_pic.data[0];
@@ -242,7 +242,7 @@ void ff_vc1_mc_1mv(VC1Context *v, int dir)
         luty  = v->next_luty;
         lutuv = v->next_lutuv;
         use_ic = v->next_use_ic;
-        interlace = !!(s->next_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
+        interlace = v->next_interlaced;
     }
 
     if (!srcY || !srcU) {
@@ -482,13 +482,13 @@ void ff_vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg)
             srcY = s->last_pic.data[0];
             luty = v->last_luty;
             use_ic = v->last_use_ic;
-            interlace = !!(s->last_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
+            interlace = v->last_interlaced;
         }
     } else {
         srcY = s->next_pic.data[0];
         luty = v->next_luty;
         use_ic = v->next_use_ic;
-        interlace = !!(s->next_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
+        interlace = v->next_interlaced;
     }
 
     if (!srcY) {
@@ -708,14 +708,14 @@ void ff_vc1_mc_4mv_chroma(VC1Context *v, int dir)
             srcV = s->last_pic.data[2];
             lutuv = v->last_lutuv;
             use_ic = v->last_use_ic;
-            interlace = !!(s->last_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
+            interlace = v->last_interlaced;
         }
     } else {
         srcU = s->next_pic.data[1];
         srcV = s->next_pic.data[2];
         lutuv = v->next_lutuv;
         use_ic = v->next_use_ic;
-        interlace = !!(s->next_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
+        interlace = v->next_interlaced;
     }
 
     if (!srcU) {
@@ -884,13 +884,13 @@ void ff_vc1_mc_4mv_chroma4(VC1Context *v, int dir, int dir2, int avg)
             srcV = s->next_pic.data[2];
             lutuv  = v->next_lutuv;
             use_ic = v->next_use_ic;
-            interlace = !!(s->next_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
+            interlace = v->next_interlaced;
         } else {
             srcU = s->last_pic.data[1];
             srcV = s->last_pic.data[2];
             lutuv  = v->last_lutuv;
             use_ic = v->last_use_ic;
-            interlace = !!(s->last_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
+            interlace = v->last_interlaced;
         }
         if (!srcU)
             return;
@@ -1009,7 +1009,7 @@ void ff_vc1_interp_mc(VC1Context *v)
     int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
     int v_edge_pos = s->v_edge_pos >> v->field_mode;
     int use_ic = v->next_use_ic;
-    int interlace;
+    int interlace = v->next_interlaced;
     int linesize, uvlinesize;
 
     if (!v->field_mode && !v->s.next_pic.data[0])
@@ -1034,8 +1034,6 @@ void ff_vc1_interp_mc(VC1Context *v)
     srcU = s->next_pic.data[1];
     srcV = s->next_pic.data[2];
 
-    interlace = !!(s->next_pic.f->flags & AV_FRAME_FLAG_INTERLACED);
-
     src_x   = s->mb_x * 16 + (mx   >> 2);
     src_y   = s->mb_y * 16 + (my   >> 2);
     uvsrc_x = s->mb_x *  8 + (uvmx >> 2);
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 71fda305da..36a47502f5 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -1064,6 +1064,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
     v->s.cur_pic_ptr->field_picture = v->field_mode;
     v->s.cur_pic_ptr->f->flags |= AV_FRAME_FLAG_INTERLACED * (v->fcm != PROGRESSIVE);
     v->s.cur_pic_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !!v->tff;
+    v->last_interlaced = v->s.last_pic_ptr ? v->s.last_pic_ptr->f->flags & AV_FRAME_FLAG_INTERLACED : 0;
+    v->next_interlaced = v->s.next_pic_ptr ? v->s.next_pic_ptr->f->flags & AV_FRAME_FLAG_INTERLACED : 0;
 
     // process pulldown flags
     s->cur_pic_ptr->f->repeat_pict = 0;
-- 
2.40.1



More information about the ffmpeg-devel mailing list