[FFmpeg-cvslog] avcodec/msmpeg4enc: Don't use code for static init that can fail

Andreas Rheinhardt git at videolan.org
Sat Apr 3 01:19:03 EEST 2021


ffmpeg | branch: release/4.4 | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Thu Dec 10 06:01:45 2020 +0100| [7f139498f58bf2911f69707614bb55f0f04327ac] | committer: Andreas Rheinhardt

avcodec/msmpeg4enc: Don't use code for static init that can fail

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
(cherry picked from commit f0042e573e13858ab16b08ad9899eb8c908cd058)

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

 libavcodec/mpegvideo_enc.c |  3 +--
 libavcodec/msmpeg4.h       |  2 +-
 libavcodec/msmpeg4enc.c    | 23 ++++++++---------------
 3 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index a095062052..29572dd61e 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1008,8 +1008,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
     if (CONFIG_H263_ENCODER && s->out_format == FMT_H263)
         ff_h263_encode_init(s);
     if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version)
-        if ((ret = ff_msmpeg4_encode_init(s)) < 0)
-            return ret;
+        ff_msmpeg4_encode_init(s);
     if ((CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
         && s->out_format == FMT_MPEG1)
         ff_mpeg1_encode_init(s);
diff --git a/libavcodec/msmpeg4.h b/libavcodec/msmpeg4.h
index f9c63b5022..483c965b9d 100644
--- a/libavcodec/msmpeg4.h
+++ b/libavcodec/msmpeg4.h
@@ -50,7 +50,7 @@ void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my);
 int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n,
                                 uint8_t **coded_block_ptr);
 
-int ff_msmpeg4_encode_init(MpegEncContext *s);
+void ff_msmpeg4_encode_init(MpegEncContext *s);
 void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
 void ff_msmpeg4_encode_ext_header(MpegEncContext *s);
 void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64],
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 5f809c2aeb..59a18532c2 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -32,7 +32,6 @@
 
 #include "libavutil/attributes.h"
 #include "libavutil/avutil.h"
-#include "libavutil/mem.h"
 #include "mpegvideo.h"
 #include "h263.h"
 #include "internal.h"
@@ -46,13 +45,11 @@
 static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
 
 /* build the table which associate a (x,y) motion vector to a vlc */
-static av_cold int init_mv_table(MVTable *tab)
+static av_cold void init_mv_table(MVTable *tab, uint16_t table_mv_index[4096])
 {
     int i, x, y;
 
-    tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
-    if (!tab->table_mv_index)
-        return AVERROR(ENOMEM);
+    tab->table_mv_index = table_mv_index;
 
     /* mark all entries as not used */
     for(i=0;i<4096;i++)
@@ -63,8 +60,6 @@ static av_cold int init_mv_table(MVTable *tab)
         y = tab->table_mvy[i];
         tab->table_mv_index[(x << 6) | y] = i;
     }
-
-    return 0;
 }
 
 void ff_msmpeg4_code012(PutBitContext *pb, int n)
@@ -118,10 +113,10 @@ static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run,
     return size;
 }
 
-av_cold int ff_msmpeg4_encode_init(MpegEncContext *s)
+av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
 {
     static int init_done=0;
-    int i, ret;
+    int i;
 
     ff_msmpeg4_common_init(s);
     if(s->msmpeg4_version>=4){
@@ -130,12 +125,12 @@ av_cold int ff_msmpeg4_encode_init(MpegEncContext *s)
     }
 
     if (!init_done) {
+        static uint16_t mv_index_tables[2][4096];
         /* init various encoding tables */
         init_done = 1;
-        if ((ret = init_mv_table(&ff_mv_tables[0])) < 0)
-            return ret;
-        if ((ret = init_mv_table(&ff_mv_tables[1])) < 0)
-            return ret;
+        init_mv_table(&ff_mv_tables[0], mv_index_tables[0]);
+        init_mv_table(&ff_mv_tables[1], mv_index_tables[1]);
+
         for(i=0;i<NB_RL_TABLES;i++)
             ff_rl_init(&ff_rl_table[i], ff_static_rl_table_store[i]);
 
@@ -152,8 +147,6 @@ av_cold int ff_msmpeg4_encode_init(MpegEncContext *s)
             }
         }
     }
-
-    return 0;
 }
 
 static void find_best_tables(MpegEncContext * s)



More information about the ffmpeg-cvslog mailing list