diff mbox series

[FFmpeg-devel,v2,025/162] avcodec/wnv1: Make decoder init-threadsafe

Message ID 20201120072116.818090-26-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series VLC, esp. init_vlc patches | expand

Checks

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

Commit Message

Andreas Rheinhardt Nov. 20, 2020, 7:18 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/wnv1.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/wnv1.c b/libavcodec/wnv1.c
index 7dd0e72596..a17a2bc3b6 100644
--- a/libavcodec/wnv1.c
+++ b/libavcodec/wnv1.c
@@ -24,6 +24,8 @@ 
  * Winnov WNV1 codec.
  */
 
+#include "libavutil/thread.h"
+
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
 #include "get_bits.h"
@@ -112,14 +114,22 @@  static int decode_frame(AVCodecContext *avctx,
     return buf_size;
 }
 
-static av_cold int decode_init(AVCodecContext *avctx)
+static av_cold void wnv1_init_static(void)
 {
-    avctx->pix_fmt = AV_PIX_FMT_YUV422P;
-
     INIT_VLC_STATIC_FROM_LENGTHS(&code_vlc, CODE_VLC_BITS, 16,
                                  &code_tab[0][1], 2,
                                  &code_tab[0][0], 2, 1,
                                  -7, INIT_VLC_OUTPUT_LE, 1 << CODE_VLC_BITS);
+}
+
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+    static AVOnce init_static_once = AV_ONCE_INIT;
+
+    avctx->pix_fmt = AV_PIX_FMT_YUV422P;
+
+    ff_thread_once(&init_static_once, wnv1_init_static);
+
     return 0;
 }
 
@@ -131,4 +141,5 @@  AVCodec ff_wnv1_decoder = {
     .init           = decode_init,
     .decode         = decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE,
 };