diff mbox series

[FFmpeg-devel,2/4] avcodec/mpeg12enc: Use ff_thread_once() for static initializations

Message ID 20201124144122.1994769-2-andreas.rheinhardt@gmail.com
State Accepted
Commit bf5bfcdbd373ad44fed87ddbd7ee8f6c9ee1217a
Headers show
Series [FFmpeg-devel,1/4] avcodec/mpeg12enc: Always initialize MPEG-2 intra VLC table lengths
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 24, 2020, 2:41 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/mpeg12enc.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

Michael Niedermayer Nov. 24, 2020, 9:04 p.m. UTC | #1
On Tue, Nov 24, 2020 at 03:41:20PM +0100, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/mpeg12enc.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)

LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index eee4af0adc..b069f2db64 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -31,6 +31,7 @@ 
 #include "libavutil/avassert.h"
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
+#include "libavutil/thread.h"
 #include "libavutil/timecode.h"
 #include "libavutil/stereo3d.h"
 
@@ -1034,18 +1035,12 @@  void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[8][64],
         mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8);
 }
 
-av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
+static av_cold void mpeg12_encode_init_static(void)
 {
-    static int done = 0;
-
-    ff_mpeg12_common_init(s);
-
-    if (!done) {
         int f_code;
         int mv;
         int i;
 
-        done = 1;
         ff_rl_init(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
         ff_rl_init(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
 
@@ -1110,7 +1105,14 @@  av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
         for (f_code = MAX_FCODE; f_code > 0; f_code--)
             for (mv = -(8 << f_code); mv < (8 << f_code); mv++)
                 fcode_tab[mv + MAX_MV] = f_code;
-    }
+}
+
+av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+
+    ff_mpeg12_common_init(s);
+
     s->me.mv_penalty = mv_penalty;
     s->fcode_tab     = fcode_tab;
     if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
@@ -1129,6 +1131,8 @@  av_cold void ff_mpeg1_encode_init(MpegEncContext *s)
     }
     s->inter_ac_vlc_length      =
     s->inter_ac_vlc_last_length = uni_mpeg1_ac_vlc_len;
+
+    ff_thread_once(&init_static_once, mpeg12_encode_init_static);
 }
 
 #define OFFSET(x) offsetof(MpegEncContext, x)