@@ -25,10 +25,12 @@
#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];
+static uint8_t 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 };
@@ -290,3 +292,15 @@ const AVRational ff_h263_pixel_aspect[16] = {
{ 0, 1 },
{ 0, 1 },
};
+
+static av_cold void h263_init_rl(void)
+{
+ ff_rl_init(&ff_h263_rl_inter, h263_static_rl_table_store[0]);
+ ff_rl_init(&ff_rl_intra_aic, h263_static_rl_table_store[1]);
+}
+
+av_cold void ff_h263_init_rl(void)
+{
+ static AVOnce init_static_once = AV_ONCE_INIT;
+ ff_thread_once(&init_static_once, h263_init_rl);
+}
@@ -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(void);
extern const uint16_t ff_h263_format[8][2];
@@ -122,8 +122,7 @@ av_cold void ff_h263_decode_init_vlc(void)
INIT_VLC_STATIC(&mv_vlc, 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_rl_init(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]);
+ ff_h263_init_rl();
INIT_VLC_RL(ff_h263_rl_inter, 554);
INIT_VLC_RL(ff_rl_intra_aic, 554);
INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
@@ -757,8 +757,7 @@ static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
static av_cold void h263_encode_init_static(void)
{
- 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_h263_init_rl();
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);
Up until now, ff_h263_rl_inter and ff_rl_intra_aic were initialized by both ituh263dec and ituh263enc; the result was that although ff_h263_encode_init() guards the initialization of its static data with an AVOnce, initializing the aforementioned RLTables was still not thread-safe because ff_h263_decode_init_vlc() might try to initialize it at the same time. This is fixed by only initializing these RLTables from a single place that is guarded by a dedicated AVOnce. This also makes the Snow encoder actually init-threadsafe; it was already wrongly marked as init-threadsafe since commit d49210788b0836d56dd872d517fe73f83b080101. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavcodec/h263data.c | 16 +++++++++++++++- libavcodec/h263data.h | 2 +- libavcodec/ituh263dec.c | 3 +-- libavcodec/ituh263enc.c | 3 +-- 4 files changed, 18 insertions(+), 6 deletions(-)