diff mbox series

[FFmpeg-devel,30/39] avcodec/msmpeg4: Make ff_msmpeg4_common_init() thread-safe

Message ID 20201210111657.2276739-31-andreas.rheinhardt@gmail.com
State Accepted
Commit 26798932ae13f3505dc50be30f17796c4c8c9e67
Headers show
Series Make mpegvideo encoders init-threadsafe
Related show

Checks

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

Commit Message

Andreas Rheinhardt Dec. 10, 2020, 11:16 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/msmpeg4.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Anton Khirnov April 17, 2021, 2:17 p.m. UTC | #1
Quoting Andreas Rheinhardt (2020-12-10 12:16:48)
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/msmpeg4.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 

LGTM
diff mbox series

Patch

diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 920f50f32c..ea1083c1a0 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -27,6 +27,8 @@ 
  * MSMPEG4 backend for encoder and decoder
  */
 
+#include "libavutil/thread.h"
+
 #include "avcodec.h"
 #include "idctdsp.h"
 #include "mpegvideo.h"
@@ -53,9 +55,6 @@  static av_cold void init_h263_dc_for_msmpeg4(void)
 {
         int level, uni_code, uni_len;
 
-        if(ff_v2_dc_chroma_table[255 + 256][1])
-            return;
-
         for(level=-256; level<256; level++){
             int size, v, l;
             /* find number of bits */
@@ -108,6 +107,8 @@  static av_cold void init_h263_dc_for_msmpeg4(void)
 
 av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
 {
+    static AVOnce init_static_once = AV_ONCE_INIT;
+
     switch(s->msmpeg4_version){
     case 1:
     case 2:
@@ -146,7 +147,7 @@  av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
     }
     //Note the default tables are set in common_init in mpegvideo.c
 
-    init_h263_dc_for_msmpeg4();
+    ff_thread_once(&init_static_once, init_h263_dc_for_msmpeg4);
 }
 
 /* predict coded block */