[FFmpeg-devel] [PATCH v2 1/4] avcodec/allcodecs: make avcodec_register_all thread safe
Muhammad Faiz
mfcc64 at gmail.com
Tue Mar 7 11:01:58 EET 2017
use ff_thread_once
Suggested-by: wm4 <nfxjfg at googlemail.com>
Signed-off-by: Muhammad Faiz <mfcc64 at gmail.com>
---
libavcodec/allcodecs.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index eee322b..6ec7e79 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -25,6 +25,7 @@
*/
#include "config.h"
+#include "libavutil/thread.h"
#include "avcodec.h"
#include "version.h"
@@ -58,14 +59,8 @@
av_register_codec_parser(&ff_##x##_parser); \
}
-void avcodec_register_all(void)
+static void register_all(void)
{
- static int initialized;
-
- if (initialized)
- return;
- initialized = 1;
-
/* hardware accelerators */
REGISTER_HWACCEL(H263_VAAPI, h263_vaapi);
REGISTER_HWACCEL(H263_VIDEOTOOLBOX, h263_videotoolbox);
@@ -717,3 +712,10 @@ void avcodec_register_all(void)
REGISTER_PARSER(VP9, vp9);
REGISTER_PARSER(XMA, xma);
}
+
+void avcodec_register_all(void)
+{
+ static AVOnce control = AV_ONCE_INIT;
+
+ ff_thread_once(&control, register_all);
+}
--
2.9.3
More information about the ffmpeg-devel
mailing list