[vlc-commits] avutil: vector and serialize CPU flags initialization

Rémi Denis-Courmont git at videolan.org
Sat Feb 22 18:24:43 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Feb 22 19:03:22 2014 +0200| [cac559118ec6bbbef12ac84d9310e7391978c2ca] | committer: Rémi Denis-Courmont

avutil: vector and serialize CPU flags initialization

av_set_cpu_flags_mask() is not thread-safe. So are the first call to
av_get_cpu_flags() after loading libavutil, and the first call to
av_get_cpu_flags() after a call to av_set_cpu_flags_mask(). So call
those under the avcodec lock during initialization.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cac559118ec6bbbef12ac84d9310e7391978c2ca
---

 modules/codec/avcodec/avcodec.c  |    4 +---
 modules/codec/avcodec/avcommon.h |   14 +++++++-------
 modules/codec/avcodec/encoder.c  |    4 +---
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/modules/codec/avcodec/avcodec.c b/modules/codec/avcodec/avcodec.c
index 9ce9221..956c72b 100644
--- a/modules/codec/avcodec/avcodec.c
+++ b/modules/codec/avcodec/avcodec.c
@@ -302,9 +302,7 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_context->opaque = (void *)p_this;
 
     /* set CPU capabilities */
-#if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
-    av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
-#else
+#if !LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
     p_context->dsp_mask = GetVlcDspMask();
 #endif
 
diff --git a/modules/codec/avcodec/avcommon.h b/modules/codec/avcodec/avcommon.h
index 3d64f53..c147cba 100644
--- a/modules/codec/avcodec/avcommon.h
+++ b/modules/codec/avcodec/avcommon.h
@@ -36,6 +36,7 @@
 
 #include "avcommon_compat.h"
 
+unsigned GetVlcDspMask(void);
 
 #ifdef HAVE_LIBAVUTIL_AVUTIL_H
 # include <libavutil/avutil.h>
@@ -81,24 +82,23 @@ static inline void vlc_init_avutil(vlc_object_t *obj)
     }
 
     av_log_set_level(level);
+
+#if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
+    av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
+#endif
+    av_get_cpu_flags();
 }
 #endif
 
-unsigned GetVlcDspMask( void );
-
 #ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
 # include <libavformat/avformat.h>
 static inline void vlc_init_avformat(vlc_object_t *obj)
 {
     vlc_avcodec_lock();
 
-    avformat_network_init();
-
     vlc_init_avutil(obj);
 
-#if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
-    av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
-#endif
+    avformat_network_init();
 
     av_register_all();
 
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 31bcd28..aa2435a3 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -317,9 +317,7 @@ int OpenEncoder( vlc_object_t *p_this )
     p_context->opaque = (void *)p_this;
 
     /* set CPU capabilities */
-#if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
-    av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
-#else
+#if !LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
     p_context->dsp_mask = GetVlcDspMask();
 #endif
 



More information about the vlc-commits mailing list