diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-02-11 19:27:55 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-02-18 20:17:18 +0100 |
commit | f32685594737339bd8600302cf2fc726c5b8b7b6 (patch) | |
tree | 3822e6c14fe443bc3dfb21979e86020072617632 /libavcodec | |
parent | 6b3957354759386ce9c93f1b3154691d99cb3437 (diff) | |
download | ffmpeg-f32685594737339bd8600302cf2fc726c5b8b7b6.tar.gz |
avcodec/ituh263dec: Make initializing VLCs thread-safe
This automatically makes the FLV, H.263, H.263+, Intel H.263,
MPEG-4, RealVideo 1.0 and RealVideo 2.0 decoders init-threadsafe.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/flvdec.c | 3 | ||||
-rw-r--r-- | libavcodec/h263dec.c | 6 | ||||
-rw-r--r-- | libavcodec/intelh263dec.c | 3 | ||||
-rw-r--r-- | libavcodec/ituh263dec.c | 15 | ||||
-rw-r--r-- | libavcodec/mpeg4videodec.c | 3 | ||||
-rw-r--r-- | libavcodec/rv10.c | 2 |
6 files changed, 20 insertions, 12 deletions
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c index dacc64c81c..b083d05037 100644 --- a/libavcodec/flvdec.c +++ b/libavcodec/flvdec.c @@ -123,7 +123,8 @@ const AVCodec ff_flv_decoder = { .close = ff_h263_decode_end, .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | + FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 09176c2749..e940b7f7c7 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -772,7 +772,8 @@ const AVCodec ff_h263_decoder = { AV_CODEC_CAP_TRUNCATED | #endif AV_CODEC_CAP_DELAY, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | + FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = ff_mpeg_flush, .max_lowres = 3, .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, @@ -793,7 +794,8 @@ const AVCodec ff_h263p_decoder = { AV_CODEC_CAP_TRUNCATED | #endif AV_CODEC_CAP_DELAY, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | + FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = ff_mpeg_flush, .max_lowres = 3, .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c index b61effa4df..b278995561 100644 --- a/libavcodec/intelh263dec.c +++ b/libavcodec/intelh263dec.c @@ -139,7 +139,8 @@ const AVCodec ff_h263i_decoder = { .close = ff_h263_decode_end, .decode = ff_h263_decode_frame, .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | + FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c index 77ca0d7e40..96a343c39f 100644 --- a/libavcodec/ituh263dec.c +++ b/libavcodec/ituh263dec.c @@ -34,6 +34,7 @@ #include "libavutil/internal.h" #include "libavutil/mathematics.h" #include "libavutil/mem_internal.h" +#include "libavutil/thread.h" #include "avcodec.h" #include "mpegvideo.h" #include "h263.h" @@ -103,12 +104,8 @@ static VLC cbpc_b_vlc; /* init vlcs */ -/* XXX: find a better solution to handle static init */ -av_cold void ff_h263_decode_init_vlc(void) +static av_cold void h263_decode_init_vlc(void) { - static volatile int done = 0; - - if (!done) { INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, ff_h263_intra_MCBPC_bits, 1, 1, ff_h263_intra_MCBPC_code, 1, 1, 72); @@ -130,8 +127,12 @@ av_cold void ff_h263_decode_init_vlc(void) INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, &ff_cbpc_b_tab[0][1], 2, 1, &ff_cbpc_b_tab[0][0], 2, 1, 8); - done = 1; - } +} + +av_cold void ff_h263_decode_init_vlc(void) +{ + static AVOnce init_static_once = AV_ONCE_INIT; + ff_thread_once(&init_static_once, h263_decode_init_vlc); } int ff_h263_decode_mba(MpegEncContext *s) diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 83550e48b6..0e0ebb674b 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -3674,7 +3674,8 @@ const AVCodec ff_mpeg4_decoder = { AV_CODEC_CAP_TRUNCATED | #endif AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | + FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_ALLOCATE_PROGRESS, .flush = ff_mpeg_flush, .max_lowres = 3, diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c index 26cb9a2294..c0adcf8853 100644 --- a/libavcodec/rv10.c +++ b/libavcodec/rv10.c @@ -691,6 +691,7 @@ const AVCodec ff_rv10_decoder = { .close = rv10_decode_end, .decode = rv10_decode_frame, .capabilities = AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, @@ -708,6 +709,7 @@ const AVCodec ff_rv20_decoder = { .close = rv10_decode_end, .decode = rv10_decode_frame, .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, .flush = ff_mpeg_flush, .max_lowres = 3, .pix_fmts = (const enum AVPixelFormat[]) { |