diff mbox series

[FFmpeg-devel,11/14] avcodec/msmpeg4enc: Only calculate coded_cbp when used

Message ID GV1SPRMB0021B508A1FDAA0D7E21D37C8F1B2@GV1SPRMB0021.EURP250.PROD.OUTLOOK.COM
State Superseded
Headers show
Series [FFmpeg-devel,01/14] avcodec/get_buffer: Remove redundant check | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Andreas Rheinhardt April 29, 2024, 12:35 a.m. UTC
With this patch, msmpeg4v1 and msmpeg4v2 no longer use
MpegEncContext.coded_block.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/msmpeg4enc.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 119ea8f15e..282b3e958b 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -389,7 +389,6 @@  void ff_msmpeg4_encode_mb(MpegEncContext * s,
 {
     int cbp, coded_cbp, i;
     int pred_x, pred_y;
-    uint8_t *coded_block;
 
     ff_msmpeg4_handle_slices(s);
 
@@ -450,20 +449,10 @@  void ff_msmpeg4_encode_mb(MpegEncContext * s,
     } else {
         /* compute cbp */
         cbp = 0;
-        coded_cbp = 0;
-        for (i = 0; i < 6; i++) {
-            int val, pred;
-            val = (s->block_last_index[i] >= 1);
+        for (int i = 0; i < 6; i++) {
+            int val = (s->block_last_index[i] >= 1);
             cbp |= val << (5 - i);
-            if (i < 4) {
-                /* predict value for close blocks only for luma */
-                pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
-                *coded_block = val;
-                val = val ^ pred;
-            }
-            coded_cbp |= val << (5 - i);
         }
-
         if(s->msmpeg4_version<=2){
             if (s->pict_type == AV_PICTURE_TYPE_I) {
                 put_bits(&s->pb,
@@ -481,6 +470,18 @@  void ff_msmpeg4_encode_mb(MpegEncContext * s,
                      ff_h263_cbpy_tab[cbp>>2][0]);
         }else{
             if (s->pict_type == AV_PICTURE_TYPE_I) {
+                /* compute coded_cbp; the 0x3 corresponds to chroma cbp;
+                 * luma coded_cbp are set in the loop below */
+                coded_cbp = cbp & 0x3;
+                for (int i = 0; i < 4; i++) {
+                    uint8_t *coded_block;
+                    int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
+                    int val = (s->block_last_index[i] >= 1);
+                    *coded_block = val;
+                    val ^= pred;
+                    coded_cbp |= val << (5 - i);
+                }
+
                 put_bits(&s->pb,
                          ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
             } else {