]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/h263data, ituh263*: Make initializing RL inter table thread-safe
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 2 Dec 2020 02:26:41 +0000 (03:26 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 25 Jan 2021 13:52:58 +0000 (14:52 +0100)
Up until now, ff_h263_rl_inter was initialized by both ituh263dec and
ituh263enc; this is an obstacle in making the codecs that use this code
init-threadsafe.

This obstacle is eliminated by only initializing this RLTable from
a single place that is guarded by a dedicated AVOnce.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/h263data.c
libavcodec/h263data.h
libavcodec/ituh263dec.c
libavcodec/ituh263enc.c

index f649d58f4e682d8c5cc24bce1e08b06d46a76291..604a0425e1a1957915f583e8c11e853eff7de312 100644 (file)
 
 #include <stdint.h>
 
+#include "libavutil/thread.h"
+
 #include "h263data.h"
 #include "mpegvideo.h"
 
-uint8_t ff_h263_static_rl_table_store[2][2][2 * MAX_RUN + MAX_LEVEL + 3];
-
 /* intra MCBPC, mb_type = (intra), then (intraq) */
 const uint8_t ff_h263_intra_MCBPC_code[9] = { 1, 1, 2, 3, 1, 1, 2, 3, 1 };
 const uint8_t ff_h263_intra_MCBPC_bits[9] = { 1, 3, 3, 3, 4, 6, 6, 6, 9 };
@@ -290,3 +290,15 @@ const AVRational ff_h263_pixel_aspect[16] = {
     {  0,  1 },
     {  0,  1 },
 };
+
+static av_cold void h263_init_rl_inter(void)
+{
+    static uint8_t h263_rl_inter_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
+    ff_rl_init(&ff_h263_rl_inter, h263_rl_inter_table);
+}
+
+av_cold void ff_h263_init_rl_inter(void)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+    ff_thread_once(&init_static_once, h263_init_rl_inter);
+}
index 3da0e3771f0fe8232578b0a5a756b85416a4ac40..144704d12b19eb879379db18ab66d37c5e01c5f1 100644 (file)
@@ -61,7 +61,7 @@ extern const int8_t ff_inter_run[102];
 
 extern RLTable ff_h263_rl_inter;
 extern RLTable ff_rl_intra_aic;
-extern uint8_t ff_h263_static_rl_table_store[2][2][2 * MAX_RUN + MAX_LEVEL + 3];
+void ff_h263_init_rl_inter(void);
 
 extern const uint16_t ff_h263_format[8][2];
 
index ce044af9b348e8843eb38013f6ef40b111cafc33..565a6a1ac82bc366d01d3883e0f71be1e65143ab 100644 (file)
@@ -122,7 +122,7 @@ av_cold void ff_h263_decode_init_vlc(void)
         INIT_VLC_STATIC(&ff_h263_mv_vlc, H263_MV_VLC_BITS, 33,
                  &ff_mvtab[0][1], 2, 1,
                  &ff_mvtab[0][0], 2, 1, 538);
-        ff_rl_init(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]);
+        ff_h263_init_rl_inter();
         INIT_VLC_RL(ff_h263_rl_inter, 554);
         INIT_FIRST_VLC_RL(ff_rl_intra_aic, 554);
         INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
index e1debcf63bc11ac136781e12e311a86b1dd0fbbe..43260e6984185e1dcca838e9a9a150ef37482f2f 100644 (file)
@@ -759,10 +759,11 @@ av_cold void ff_h263_encode_init(MpegEncContext *s)
     static int done = 0;
 
     if (!done) {
+        static uint8_t rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
         done = 1;
 
-        ff_rl_init(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]);
-        ff_rl_init(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]);
+        ff_rl_init(&ff_rl_intra_aic, rl_intra_table);
+        ff_h263_init_rl_inter();
 
         init_uni_h263_rl_tab(&ff_rl_intra_aic,  uni_h263_intra_aic_rl_len);
         init_uni_h263_rl_tab(&ff_h263_rl_inter, uni_h263_inter_rl_len);