]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/msmpeg4: Factor out common RLTable initialization code
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 10 Dec 2020 05:39:41 +0000 (06:39 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>
Mon, 26 Apr 2021 22:43:51 +0000 (00:43 +0200)
Up until now, both the msmpeg4 decoders and encoders initialized several
RLTables common to them (the decoders also initialized the VLCs of these
RLTables). This is an obstacle to making these codecs init-threadsafe.
So move this initialization to ff_msmpeg4_common_init() that already
contains this initialization code. This allows to reuse the AVOnce used
for initializing ff_v2_dc_lum/chroma_table which automatically makes
initializing these RLTables thread-safe.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/msmpeg4.c
libavcodec/msmpeg4data.c
libavcodec/msmpeg4data.h
libavcodec/msmpeg4dec.c
libavcodec/msmpeg4enc.c

index 6673b4523194fe722e9967a1d8db758ece102077..16b6f1895090893d7da447a8156c9324a1c6359c 100644 (file)
@@ -103,6 +103,16 @@ static av_cold void init_h263_dc_for_msmpeg4(void)
     }
 }
 
+static av_cold void msmpeg4_common_init_static(void)
+{
+    static uint8_t rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3];
+
+    for (int i = 0; i < NB_RL_TABLES; i++)
+        ff_rl_init(&ff_rl_table[i], rl_table_store[i]);
+
+    init_h263_dc_for_msmpeg4();
+}
+
 av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
 {
     static AVOnce init_static_once = AV_ONCE_INIT;
@@ -145,7 +155,7 @@ av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
     }
     //Note the default tables are set in common_init in mpegvideo.c
 
-    ff_thread_once(&init_static_once, init_h263_dc_for_msmpeg4);
+    ff_thread_once(&init_static_once, msmpeg4_common_init_static);
 }
 
 /* predict coded block */
index fb0c6185bfda77e0413a2acd0a8a945a9d34e3ea..890aeb5670d7976ae73f0773321bdd498792cf5c 100644 (file)
@@ -33,7 +33,6 @@
 
 uint32_t ff_v2_dc_lum_table[512][2];
 uint32_t ff_v2_dc_chroma_table[512][2];
-uint8_t  ff_static_rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3];
 
 VLC ff_msmp4_mb_i_vlc;
 VLC ff_msmp4_dc_luma_vlc[2];
index 68a1d14f55e870b2149023399d4316bceeaa8428..87b4057d971ec5faed7962c29d594ad0813f9ae4 100644 (file)
@@ -59,7 +59,6 @@ extern const uint8_t ff_wmv1_scantable[WMV1_SCANTABLE_COUNT][64];
 #define NB_RL_TABLES  6
 
 extern RLTable ff_rl_table[NB_RL_TABLES];
-extern uint8_t ff_static_rl_table_store[NB_RL_TABLES][2][2 * MAX_RUN + MAX_LEVEL + 3];
 
 extern uint32_t ff_v2_dc_lum_table[512][2];
 extern uint32_t ff_v2_dc_chroma_table[512][2];
index 8fcd5b94cdd24f705f1fd4752bd1ef88579a8e0e..ef8d510a02a5adcf74a35d3c3627498a1edd81d2 100644 (file)
@@ -295,7 +295,7 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
 {
     MpegEncContext *s = avctx->priv_data;
     static volatile int done = 0;
-    int i, ret;
+    int ret;
     MVTable *mv;
 
     if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
@@ -307,9 +307,6 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
     ff_msmpeg4_common_init(s);
 
     if (!done) {
-        for(i=0;i<NB_RL_TABLES;i++) {
-            ff_rl_init(&ff_rl_table[i], ff_static_rl_table_store[i]);
-        }
         INIT_FIRST_VLC_RL(ff_rl_table[0], 642);
         INIT_FIRST_VLC_RL(ff_rl_table[1], 1104);
         INIT_FIRST_VLC_RL(ff_rl_table[2], 554);
index 714701504253d75558a8ab0727b71bbc013547f1..e22e8107adcc133038e901af525c13562bf54701 100644 (file)
@@ -131,9 +131,6 @@ av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
         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]);
-
         for(i=0; i<NB_RL_TABLES; i++){
             int level;
             for (level = 1; level <= MAX_LEVEL; level++) {