[FFmpeg-cvslog] avcodec/ituh263dec: Make initializing VLCs thread-safe
Andreas Rheinhardt
git at videolan.org
Fri Feb 18 22:22:10 EET 2022
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Feb 11 19:27:55 2022 +0100| [f32685594737339bd8600302cf2fc726c5b8b7b6] | committer: Andreas Rheinhardt
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 at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f32685594737339bd8600302cf2fc726c5b8b7b6
---
libavcodec/flvdec.c | 3 ++-
libavcodec/h263dec.c | 6 ++++--
libavcodec/intelh263dec.c | 3 ++-
libavcodec/ituh263dec.c | 15 ++++++++-------
libavcodec/mpeg4videodec.c | 3 ++-
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[]) {
More information about the ffmpeg-cvslog
mailing list