Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/9] avcodec/msmpeg4enc: Inline constant
@ 2025-03-13  5:59 Andreas Rheinhardt
  2025-03-15  1:08 ` Andreas Rheinhardt
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Rheinhardt @ 2025-03-13  5:59 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 29 bytes --]

Patches attached.

- Andreas

[-- Attachment #2: 0001-avcodec-msmpeg4enc-Inline-constant.patch --]
[-- Type: text/x-patch, Size: 985 bytes --]

From b3a259cf6bf825a34d9405a555553e923883def1 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 15:42:18 +0100
Subject: [PATCH 1/9] avcodec/msmpeg4enc: Inline constant

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/msmpeg4enc.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 2a9e16975f..8310e0a578 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -354,9 +354,8 @@ static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
     int range, bit_size, sign, code, bits;
 
     if (val == 0) {
-        /* zero vector */
-        code = 0;
-        put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
+        /* zero vector; corresponds to ff_mvtab[0] */
+        put_bits(&s->pb, 1, 0x1);
     } else {
         bit_size = s->f_code - 1;
         range = 1 << bit_size;
-- 
2.45.2


[-- Attachment #3: 0002-avcodec-mpegvideo_dec-Mark-init-flush-close-function.patch --]
[-- Type: text/x-patch, Size: 1626 bytes --]

From 78b6d8190d4dfbfefc80cc663a883e4e7ee7e805 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 01:51:49 +0100
Subject: [PATCH 2/9] avcodec/mpegvideo_dec: Mark init, flush, close functions
 as av_cold

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpegvideo_dec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 532d8cf5c1..2856dbfbd6 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -43,7 +43,7 @@
 #include "threadprogress.h"
 #include "wmv2dec.h"
 
-int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
+av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
 {
     enum ThreadingStatus thread_status;
 
@@ -141,7 +141,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
     return 0;
 }
 
-int ff_mpv_decode_close(AVCodecContext *avctx)
+av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
 {
     MpegEncContext *s = avctx->priv_data;
 
@@ -150,7 +150,7 @@ int ff_mpv_decode_close(AVCodecContext *avctx)
     return 0;
 }
 
-int ff_mpv_common_frame_size_change(MpegEncContext *s)
+av_cold int ff_mpv_common_frame_size_change(MpegEncContext *s)
 {
     int err = 0;
 
@@ -427,7 +427,7 @@ void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
                        s->first_field, s->low_delay);
 }
 
-void ff_mpeg_flush(AVCodecContext *avctx)
+av_cold void ff_mpeg_flush(AVCodecContext *avctx)
 {
     MpegEncContext *const s = avctx->priv_data;
 
-- 
2.45.2


[-- Attachment #4: 0003-avcodec-vc1_block-Stop-setting-write-only-block_last.patch --]
[-- Type: text/x-patch, Size: 5707 bytes --]

From 5956d3424e2eb7c2419dcbf026cb28eee0d880fd Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 02:06:40 +0100
Subject: [PATCH 3/9] avcodec/vc1_block: Stop setting write-only
 block_last_index

It is only used by the mpegvideo unquantize functions which
this decoder does not use at all.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/vc1_block.c | 32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 8babbde38c..26adfbca1d 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -585,7 +585,6 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
     GetBitContext *gb = &v->s.gb;
     MpegEncContext *s = &v->s;
     int dc_pred_dir = 0; /* Direction of the DC prediction used */
-    int i;
     int16_t *dc_val;
     int16_t *ac_val, *ac_val2;
     int dcdiff, scale;
@@ -622,7 +621,6 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
     scale = v->pq * 2 + v->halfpq;
 
     //AC Decoding
-    i = !!coded;
 
     if (coded) {
         int last = 0, skip, value;
@@ -637,14 +635,14 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
         } else
             zz_table = v->zz_8x8[1];
 
-        while (!last) {
+        for (int i = 1; !last; ++i) {
             int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
             if (ret < 0)
                 return ret;
             i += skip;
             if (i > 63)
                 break;
-            block[zz_table[i++]] = value;
+            block[zz_table[i]] = value;
         }
 
         /* apply AC prediction if needed */
@@ -696,8 +694,6 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
             }
         }
     }
-    if (s->ac_pred) i = 63;
-    s->block_last_index[n] = i;
 
     return 0;
 }
@@ -716,7 +712,6 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
     GetBitContext *gb = &v->s.gb;
     MpegEncContext *s = &v->s;
     int dc_pred_dir = 0; /* Direction of the DC prediction used */
-    int i;
     int16_t *dc_val = NULL;
     int16_t *ac_val, *ac_val2;
     int dcdiff;
@@ -778,7 +773,6 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
     }
 
     //AC Decoding
-    i = 1;
 
     if (coded) {
         int last = 0, skip, value;
@@ -801,14 +795,14 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
                 zz_table = v->zzi_8x8;
         }
 
-        while (!last) {
+        for (int i = 1; !last; ++i) {
             int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
             if (ret < 0)
                 return ret;
             i += skip;
             if (i > 63)
                 break;
-            block[zz_table[i++]] = value;
+            block[zz_table[i]] = value;
         }
 
         /* apply AC prediction if needed */
@@ -880,8 +874,6 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
             }
         }
     }
-    if (use_pred) i = 63;
-    s->block_last_index[n] = i;
 
     return 0;
 }
@@ -900,7 +892,6 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
     GetBitContext *gb = &v->s.gb;
     MpegEncContext *s = &v->s;
     int dc_pred_dir = 0; /* Direction of the DC prediction used */
-    int i;
     int16_t *dc_val = NULL;
     int16_t *ac_val, *ac_val2;
     int dcdiff;
@@ -942,7 +933,6 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
     block[0] = dcdiff * s->y_dc_scale;
 
     //AC Decoding
-    i = 1;
 
     /* check if AC is needed at all and adjust direction if needed */
     if (!a_avail) dc_pred_dir = 1;
@@ -973,7 +963,7 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
         int last = 0, skip, value;
         int k;
 
-        while (!last) {
+        for (int i = 1; !last; ++i) {
             int ret = vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
             if (ret < 0)
                 return ret;
@@ -981,15 +971,15 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
             if (i > 63)
                 break;
             if (v->fcm == PROGRESSIVE)
-                block[v->zz_8x8[0][i++]] = value;
+                block[v->zz_8x8[0][i]] = value;
             else {
                 if (use_pred && (v->fcm == ILACE_FRAME)) {
                     if (!dc_pred_dir) // top
-                        block[v->zz_8x8[2][i++]] = value;
+                        block[v->zz_8x8[2][i]] = value;
                     else // left
-                        block[v->zz_8x8[3][i++]] = value;
+                        block[v->zz_8x8[3][i]] = value;
                 } else {
-                    block[v->zzi_8x8[i++]] = value;
+                    block[v->zzi_8x8[i]] = value;
                 }
             }
         }
@@ -1033,8 +1023,6 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
                 if (!v->pquantizer)
                     block[k] += (block[k] < 0) ? -quant : quant;
             }
-
-        if (use_pred) i = 63;
     } else { // no AC coeffs
         int k;
 
@@ -1082,10 +1070,8 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
                         block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -quant : quant;
                 }
             }
-            i = 63;
         }
     }
-    s->block_last_index[n] = i;
 
     return 0;
 }
-- 
2.45.2


[-- Attachment #5: 0004-avcodec-intrax8-Stop-setting-write-only-block_last_i.patch --]
[-- Type: text/x-patch, Size: 5454 bytes --]

From ceb1d54f3dfcd283d6e523bc8e6ced4a551779cc Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 02:16:10 +0100
Subject: [PATCH 4/9] avcodec/intrax8: Stop setting write-only block_last_index

These values are only used by the mpegvideo unquantize functions,
yet these are not active when intrax is in use. Furthermore,
given that ff_intrax8_decode_picture() decodes multiple
macroblocks in a given call, it makes no sense to return
any value (that was in practice the maximum of the indices
of all the macroblocks decoded).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/intrax8.c | 12 ------------
 libavcodec/intrax8.h |  3 ---
 libavcodec/vc1dec.c  |  3 +--
 libavcodec/wmv2dec.c |  3 +--
 4 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
index f1dce86a50..684f15d904 100644
--- a/libavcodec/intrax8.c
+++ b/libavcodec/intrax8.c
@@ -480,24 +480,18 @@ static void x8_ac_compensation(IntraX8Context *const w, const int direction,
 
         t        = T(1084); // g
         B(1, 1) += t;
-
-        w->block_last_index[0] = FFMAX(w->block_last_index[0], 7 * 8);
         break;
     case 1:
         B(0, 1) -= T(6269);
         B(0, 3) -= T(708);
         B(0, 5) -= T(172);
         B(0, 7) -= T(73);
-
-        w->block_last_index[0] = FFMAX(w->block_last_index[0], 7 * 8);
         break;
     case 2:
         B(1, 0) -= T(6269);
         B(3, 0) -= T(708);
         B(5, 0) -= T(172);
         B(7, 0) -= T(73);
-
-        w->block_last_index[0] = FFMAX(w->block_last_index[0], 7);
         break;
     }
 #undef B
@@ -599,10 +593,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
 
             w->block[0][scantable[pos]] = level;
         } while (!final);
-
-        w->block_last_index[0] = pos;
     } else { // DC only
-        w->block_last_index[0] = 0;
         if (w->flat_dc && ((unsigned) (dc_level + 1)) < 3) { // [-1; 1]
             int32_t divide_quant = !chroma ? w->divide_quant_dc_luma
                                            : w->divide_quant_dc_chroma;
@@ -633,7 +624,6 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
          * -> 01'10' 10'10' 00'00' 00'01' 01'11' 11'00 => 0x6A017C */
         direction = (0x6A017C >> (w->orient * 2)) & 3;
         if (direction != 3) {
-            // modify block_last[]
             x8_ac_compensation(w, direction, w->block[0][0]);
         }
     }
@@ -689,7 +679,6 @@ static void x8_init_block_index(IntraX8Context *w, AVFrame *frame)
 av_cold int ff_intrax8_common_init(AVCodecContext *avctx,
                                    IntraX8Context *w,
                                    int16_t (*block)[64],
-                                   int block_last_index[12],
                                    int mb_width, int mb_height)
 {
     static AVOnce init_static_once = AV_ONCE_INIT;
@@ -698,7 +687,6 @@ av_cold int ff_intrax8_common_init(AVCodecContext *avctx,
     w->mb_width  = mb_width;
     w->mb_height = mb_height;
     w->block = block;
-    w->block_last_index = block_last_index;
 
     // two rows, 2 blocks per cannon mb
     w->prediction_table = av_mallocz(w->mb_width * 2 * 2);
diff --git a/libavcodec/intrax8.h b/libavcodec/intrax8.h
index b9f8c4250b..38ad09c837 100644
--- a/libavcodec/intrax8.h
+++ b/libavcodec/intrax8.h
@@ -38,7 +38,6 @@ typedef struct IntraX8Context {
     WMV2DSPContext wdsp;
     uint8_t idct_permutation[64];
     AVCodecContext *avctx;
-    int *block_last_index;  ///< last nonzero coefficient in block
     int16_t (*block)[64];
 
     // set by the caller codec
@@ -77,7 +76,6 @@ typedef struct IntraX8Context {
  * @param avctx pointer to AVCodecContext
  * @param w pointer to IntraX8Context
  * @param block pointer to block array
- * @param block_last_index pointer to index array
  * @param mb_width macroblock width
  * @param mb_height macroblock height
  * @return 0 on success, a negative AVERROR value on error
@@ -85,7 +83,6 @@ typedef struct IntraX8Context {
 int ff_intrax8_common_init(AVCodecContext *avctx,
                            IntraX8Context *w,
                            int16_t (*block)[64],
-                           int block_last_index[12],
                            int mb_width, int mb_height);
 
 /**
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index d92a7da8ab..b9ca38d20d 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -422,8 +422,7 @@ static av_cold int vc1_decode_init_alloc_tables(VC1Context *v)
                 return AVERROR(ENOMEM);
     }
 
-    ret = ff_intrax8_common_init(s->avctx, &v->x8,
-                                 s->block, s->block_last_index,
+    ret = ff_intrax8_common_init(s->avctx, &v->x8, s->block,
                                  s->mb_width, s->mb_height);
     if (ret < 0)
         return ret;
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 677467ccc2..7f43a5c0ba 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -575,8 +575,7 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx)
 
     decode_ext_header(w);
 
-    return ff_intrax8_common_init(avctx, &w->x8,
-                                  w->s.block, w->s.block_last_index,
+    return ff_intrax8_common_init(avctx, &w->x8, w->s.block,
                                   w->s.mb_width, w->s.mb_height);
 }
 
-- 
2.45.2


[-- Attachment #6: 0005-avcodec-mdec-Remove-write-only-block_last_index.patch --]
[-- Type: text/x-patch, Size: 969 bytes --]

From 9c71ed0300745b2b3ff1325a3c44b4df8f90bff0 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 03:34:02 +0100
Subject: [PATCH 5/9] avcodec/mdec: Remove write-only block_last_index

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mdec.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 5ab40719ac..66331d9059 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -56,7 +56,6 @@ typedef struct MDECContext {
     DECLARE_ALIGNED(16, uint16_t, quant_matrix)[64];
     uint8_t *bitstream_buffer;
     unsigned int bitstream_buffer_size;
-    int block_last_index[6];
 } MDECContext;
 
 //very similar to MPEG-1
@@ -126,7 +125,6 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
         }
         CLOSE_READER(re, &a->gb);
     }
-    a->block_last_index[n] = i;
     return 0;
 }
 
-- 
2.45.2


[-- Attachment #7: 0006-avcodec-mdec-Optimize-processing-escape-codes.patch --]
[-- Type: text/x-patch, Size: 1448 bytes --]

From fd1eb4a160d2583d4bbff68daf3738f49b27f089 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 03:57:30 +0100
Subject: [PATCH 6/9] avcodec/mdec: Optimize processing escape codes

Said escape code is only six bits long, so that one has at least 25 - 6
bits in the bitstream reader's cache after reading it; therefore the
whole following 16 bits (containing the actual code) are already in the
bitstream reader's cache, making it unnecessary to reload the cache.

This is the mdec analogue of fe9bc1cc45e2bebba1efa7b9a20b0d66679bf2d5.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 66331d9059..9789a94396 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -100,8 +100,8 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
                 LAST_SKIP_BITS(re, &a->gb, 1);
             } else {
                 /* escape */
-                run = SHOW_UBITS(re, &a->gb, 6)+1; LAST_SKIP_BITS(re, &a->gb, 6);
-                UPDATE_CACHE(re, &a->gb);
+                run = SHOW_UBITS(re, &a->gb, 6) + 1;
+                SKIP_BITS(re, &a->gb, 6);
                 level = SHOW_SBITS(re, &a->gb, 10); SKIP_BITS(re, &a->gb, 10);
                 i += run;
                 if (i > 63) {
-- 
2.45.2


[-- Attachment #8: 0007-avcodec-mdec-Don-t-update-cache-unnecessarily.patch --]
[-- Type: text/x-patch, Size: 1075 bytes --]

From b0ff4956d756d821a02c1b0820038c644fd4777d Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 03:59:36 +0100
Subject: [PATCH 7/9] avcodec/mdec: Don't update cache unnecessarily

It won't be used anyway.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mdec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/mdec.c b/libavcodec/mdec.c
index 9789a94396..c8865d7c63 100644
--- a/libavcodec/mdec.c
+++ b/libavcodec/mdec.c
@@ -102,7 +102,8 @@ static inline int mdec_decode_block_intra(MDECContext *a, int16_t *block, int n)
                 /* escape */
                 run = SHOW_UBITS(re, &a->gb, 6) + 1;
                 SKIP_BITS(re, &a->gb, 6);
-                level = SHOW_SBITS(re, &a->gb, 10); SKIP_BITS(re, &a->gb, 10);
+                level = SHOW_SBITS(re, &a->gb, 10);
+                LAST_SKIP_BITS(re, &a->gb, 10);
                 i += run;
                 if (i > 63) {
                     av_log(a->avctx, AV_LOG_ERROR,
-- 
2.45.2


[-- Attachment #9: 0008-avcodec-eamad-Optimize-processing-escape-codes.patch --]
[-- Type: text/x-patch, Size: 1344 bytes --]

From d7cf99109a79a1632a90c801968ca196174894c5 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 04:20:52 +0100
Subject: [PATCH 8/9] avcodec/eamad: Optimize processing escape codes

Said escape code is only six bits long, so that one has at least 25 - 6
bits in the bitstream reader's cache after reading it; therefore the
whole following 16 bits (containing the actual code) are already in the
bitstream reader's cache, making it unnecessary to reload the cache.

This is the eamad analogue of fe9bc1cc45e2bebba1efa7b9a20b0d66679bf2d5.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/eamad.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 1c3f97653c..41a133c424 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -160,10 +160,8 @@ static inline int decode_block_intra(MadContext *s, int16_t * block)
                 LAST_SKIP_BITS(re, &s->gb, 1);
             } else {
                 /* escape */
-                UPDATE_CACHE(re, &s->gb);
                 level = SHOW_SBITS(re, &s->gb, 10); SKIP_BITS(re, &s->gb, 10);
 
-                UPDATE_CACHE(re, &s->gb);
                 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
 
                 i += run;
-- 
2.45.2


[-- Attachment #10: 0009-avcodec-eamad-Don-t-store-transient-macroblock-indic.patch --]
[-- Type: text/x-patch, Size: 3845 bytes --]

From bf4c6a05f69628bf22f5755c34c3fde9de5f482e Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Fri, 7 Mar 2025 14:15:02 +0100
Subject: [PATCH 9/9] avcodec/eamad: Don't store transient macroblock indices
 in context

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/eamad.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 41a133c424..44dac46083 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -58,8 +58,6 @@ typedef struct MadContext {
     unsigned int bitstream_buf_size;
     DECLARE_ALIGNED(32, int16_t, block)[64];
     uint16_t quant_matrix[64];
-    int mb_x;
-    int mb_y;
 } MadContext;
 
 static av_cold int decode_init(AVCodecContext *avctx)
@@ -148,11 +146,8 @@ static inline int decode_block_intra(MadContext *s, int16_t * block)
                 break;
             } else if (level != 0) {
                 i += run;
-                if (i > 63) {
-                    av_log(s->avctx, AV_LOG_ERROR,
-                           "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
+                if (i > 63)
                     return -1;
-                }
                 j = scantable[i];
                 level = (level*quant_matrix[j]) >> 4;
                 level = (level-1)|1;
@@ -165,11 +160,8 @@ static inline int decode_block_intra(MadContext *s, int16_t * block)
                 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
 
                 i += run;
-                if (i > 63) {
-                    av_log(s->avctx, AV_LOG_ERROR,
-                           "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
+                if (i > 63)
                     return -1;
-                }
                 j = scantable[i];
                 if (level < 0) {
                     level = -level;
@@ -200,7 +192,7 @@ static int decode_motion(GetBitContext *gb)
     return value;
 }
 
-static int decode_mb(MadContext *s, AVFrame *frame, int inter)
+static int decode_mb(MadContext *s, AVFrame *frame, int inter, int mb_x, int mb_y)
 {
     int mv_map = 0;
     int av_uninit(mv_x), av_uninit(mv_y);
@@ -219,12 +211,15 @@ static int decode_mb(MadContext *s, AVFrame *frame, int inter)
         if (mv_map & (1<<j)) {  // mv_x and mv_y are guarded by mv_map
             int add = 2*decode_motion(&s->gb);
             if (s->last_frame->data[0])
-                comp_block(s, frame, s->mb_x, s->mb_y, j, mv_x, mv_y, add);
+                comp_block(s, frame, mb_x, mb_y, j, mv_x, mv_y, add);
         } else {
             s->bdsp.clear_block(s->block);
-            if(decode_block_intra(s, s->block) < 0)
+            if (decode_block_intra(s, s->block) < 0) {
+                av_log(s->avctx, AV_LOG_ERROR,
+                        "ac-tex damaged at %d %d\n", mb_x, mb_y);
                 return -1;
-            idct_put(s, frame, s->block, s->mb_x, s->mb_y, j);
+            }
+            idct_put(s, frame, s->block, mb_x, mb_y, j);
         }
     }
     return 0;
@@ -308,9 +303,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     memset((uint8_t*)s->bitstream_buf + bytestream2_get_bytes_left(&gb), 0, AV_INPUT_BUFFER_PADDING_SIZE);
     init_get_bits(&s->gb, s->bitstream_buf, 8*(bytestream2_get_bytes_left(&gb)));
 
-    for (s->mb_y=0; s->mb_y < (avctx->height+15)/16; s->mb_y++)
-        for (s->mb_x=0; s->mb_x < (avctx->width +15)/16; s->mb_x++)
-            if(decode_mb(s, frame, inter) < 0)
+    for (int mb_y = 0; mb_y < (avctx->height + 15) / 16; mb_y++)
+        for (int mb_x = 0; mb_x < (avctx->width + 15) / 16; mb_x++)
+            if (decode_mb(s, frame, inter, mb_x, mb_y) < 0)
                 return AVERROR_INVALIDDATA;
 
     *got_frame = 1;
-- 
2.45.2


[-- Attachment #11: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-03-15  1:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-13  5:59 [FFmpeg-devel] [PATCH 1/9] avcodec/msmpeg4enc: Inline constant Andreas Rheinhardt
2025-03-15  1:08 ` Andreas Rheinhardt

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