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>
+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;
av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
{
static AVOnce init_static_once = AV_ONCE_INIT;
}
//Note the default tables are set in common_init in mpegvideo.c
}
//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 */
}
/* predict coded block */
uint32_t ff_v2_dc_lum_table[512][2];
uint32_t ff_v2_dc_chroma_table[512][2];
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];
VLC ff_msmp4_mb_i_vlc;
VLC ff_msmp4_dc_luma_vlc[2];
#define NB_RL_TABLES 6
extern RLTable ff_rl_table[NB_RL_TABLES];
#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];
extern uint32_t ff_v2_dc_lum_table[512][2];
extern uint32_t ff_v2_dc_chroma_table[512][2];
{
MpegEncContext *s = avctx->priv_data;
static volatile int done = 0;
{
MpegEncContext *s = avctx->priv_data;
static volatile int done = 0;
MVTable *mv;
if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
MVTable *mv;
if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
ff_msmpeg4_common_init(s);
if (!done) {
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);
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);
init_mv_table(&ff_mv_tables[0], mv_index_tables[0]);
init_mv_table(&ff_mv_tables[1], mv_index_tables[1]);
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++) {
for(i=0; i<NB_RL_TABLES; i++){
int level;
for (level = 1; level <= MAX_LEVEL; level++) {