avcodec/msmpeg4: Factor out common RLTable initialization code

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 <[email protected]>
Signed-off-by: Andreas Rheinhardt <[email protected]>
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 6673b45..16b6f18 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -103,6 +103,16 @@
     }
 }
 
+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 @@
     }
     //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 */