[FFmpeg-devel] [PATCH 215/217] avcodec/ituh263enc: Use ff_thread_once() for static initializations
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Wed Dec 2 06:22:42 EET 2020
This already makes initializing all the objects exclusively initialized
by ff_h263_encode_init() thread-safe; this includes the static tables of
ituh263enc.c: uni_h263_int*_rl_len, mv_penalty, fcode_tab as well as
umv_fcode_tab; it does not ff_h263_rl_inter as well as ff_rl_intra_aic,
as these are also initialized by ituh263dec.c and the code there is not
guarded by the AVOnce used here. This will be dealt with in a future
commit.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavcodec/ituh263enc.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index e1debcf63b..88d003ed47 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -30,6 +30,7 @@
#include <limits.h>
#include "libavutil/attributes.h"
+#include "libavutil/thread.h"
#include "avcodec.h"
#include "mpegvideo.h"
#include "mpegvideodata.h"
@@ -671,7 +672,7 @@ void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
}
}
-static av_cold void init_mv_penalty_and_fcode(MpegEncContext *s)
+static av_cold void init_mv_penalty_and_fcode(void)
{
int f_code;
int mv;
@@ -754,21 +755,21 @@ static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
}
}
-av_cold void ff_h263_encode_init(MpegEncContext *s)
+static av_cold void h263_encode_init_static(void)
{
- static int done = 0;
+ 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]);
- if (!done) {
- done = 1;
+ 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);
- 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]);
+ init_mv_penalty_and_fcode();
+}
- 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);
+av_cold void ff_h263_encode_init(MpegEncContext *s)
+{
+ static AVOnce init_static_once = AV_ONCE_INIT;
- init_mv_penalty_and_fcode(s);
- }
s->me.mv_penalty= mv_penalty; // FIXME exact table for MSMPEG4 & H.263+
s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len;
@@ -816,6 +817,8 @@ av_cold void ff_h263_encode_init(MpegEncContext *s)
s->y_dc_scale_table=
s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
}
+
+ ff_thread_once(&init_static_once, h263_encode_init_static);
}
void ff_h263_encode_mba(MpegEncContext *s)
--
2.25.1
More information about the ffmpeg-devel
mailing list