[FFmpeg-devel] [PATCH 74/80] avcodec/mpegvideo: Move decode_mb to H263DecContext

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Thu Feb 3 03:06:25 EET 2022


Only used by h263dec-based decoders; and only set by them
in their main threads.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/h263dec.c       | 7 +++++--
 libavcodec/h263dec.h       | 2 ++
 libavcodec/mpeg4videodec.c | 8 ++++----
 libavcodec/mpegvideo.h     | 1 -
 libavcodec/msmpeg4dec.c    | 6 +++---
 5 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 4327aec54d..91e95b910e 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -86,7 +86,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
     ff_mpv_decode_init(m, avctx);
 
     s->quant_precision = 5;
-    s->decode_mb       = ff_h263_decode_mb;
+    h->decode_mb       = ff_h263_decode_mb;
     s->low_delay       = 1;
 
     /* select sub codec */
@@ -201,6 +201,9 @@ static int get_consumed_bytes(H263DecContext *h, int buf_size)
 static int decode_slice(MPVMainDecContext *m)
 {
     MPVDecContext *const s = &m->s;
+    /* The following is only allowed because no h263dec based decoder
+     * uses slice threading. */
+    H263DecContext *const h = (H263DecContext*)s;
     const int part_mask = s->partitioned_frame
                           ? (ER_AC_END | ER_AC_ERROR) : 0x7F;
     const int mb_size   = 16 >> s->avctx->lowres;
@@ -274,7 +277,7 @@ static int decode_slice(MPVMainDecContext *m)
                     get_bits_count(&s->gb), show_bits(&s->gb, 24));
 
             ff_tlog(NULL, "Decoding MB at %dx%d\n", s->mb_x, s->mb_y);
-            ret = s->decode_mb(s, s->block);
+            ret = h->decode_mb(s, s->block);
 
             if (s->pict_type != AV_PICTURE_TYPE_B)
                 ff_h263_update_motion_val(s);
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index b007372f64..13e097358f 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -42,6 +42,8 @@ extern const enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[];
 
 typedef struct H263DecContext {
     MPVMainDecContext m;
+
+    int (*decode_mb)(MPVDecContext *s, int16_t block[12][64]); // used to avoid a switch
 } H263DecContext;
 
 int ff_h263_decode_motion(MPVDecContext *s, int pred, int f_code);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 854ccd5ade..7e3b672312 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -2946,9 +2946,9 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
 
     s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B;
     if (s->partitioned_frame)
-        s->decode_mb = mpeg4_decode_partitioned_mb;
+        h->decode_mb = mpeg4_decode_partitioned_mb;
     else
-        s->decode_mb = mpeg4_decode_mb;
+        h->decode_mb = mpeg4_decode_mb;
 
     time_incr = 0;
     while (get_bits1(gb) != 0)
@@ -3242,7 +3242,7 @@ static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
 
     s->partitioned_frame = 0;
     s->interlaced_dct = 0;
-    s->decode_mb = mpeg4_decode_studio_mb;
+    h->decode_mb = mpeg4_decode_studio_mb;
 
     decode_smpte_tc(ctx, gb);
 
@@ -3653,7 +3653,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     s->h263_pred = 1;
     s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */
-    s->decode_mb = mpeg4_decode_mb;
+    h->decode_mb = mpeg4_decode_mb;
     ctx->time_increment_bits = 4; /* default value for broken headers */
 
     avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 2d5ee61a27..d0e4e8e9ff 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -424,7 +424,6 @@ typedef struct MPVContext {
 
     int16_t (*block)[64]; ///< points to one of the following blocks
     int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
-    int (*decode_mb)(struct MPVContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
 
 #define SLICE_OK         0
 #define SLICE_ERROR     -1
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index b1f4df7aa9..c0d5d60cc6 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -382,15 +382,15 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
     switch(s->msmpeg4_version){
     case 1:
     case 2:
-        s->decode_mb= msmpeg4v12_decode_mb;
+        h->decode_mb = msmpeg4v12_decode_mb;
         break;
     case 3:
     case 4:
-        s->decode_mb= msmpeg4v34_decode_mb;
+        h->decode_mb = msmpeg4v34_decode_mb;
         break;
     case 5:
         if (CONFIG_WMV2_DECODER)
-            s->decode_mb= ff_wmv2_decode_mb;
+            h->decode_mb = ff_wmv2_decode_mb;
     case 6:
         //FIXME + TODO VC1 decode mb
         break;
-- 
2.32.0



More information about the ffmpeg-devel mailing list