Commit cac55911 authored by Rémi Denis-Courmont's avatar 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.
parent df4c7f8c
...@@ -302,9 +302,7 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -302,9 +302,7 @@ static int OpenDecoder( vlc_object_t *p_this )
p_context->opaque = (void *)p_this; p_context->opaque = (void *)p_this;
/* set CPU capabilities */ /* set CPU capabilities */
#if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100) #if !LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
#else
p_context->dsp_mask = GetVlcDspMask(); p_context->dsp_mask = GetVlcDspMask();
#endif #endif
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "avcommon_compat.h" #include "avcommon_compat.h"
unsigned GetVlcDspMask(void);
#ifdef HAVE_LIBAVUTIL_AVUTIL_H #ifdef HAVE_LIBAVUTIL_AVUTIL_H
# include <libavutil/avutil.h> # include <libavutil/avutil.h>
...@@ -81,24 +82,23 @@ static inline void vlc_init_avutil(vlc_object_t *obj) ...@@ -81,24 +82,23 @@ static inline void vlc_init_avutil(vlc_object_t *obj)
} }
av_log_set_level(level); 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 #endif
unsigned GetVlcDspMask( void );
#ifdef HAVE_LIBAVFORMAT_AVFORMAT_H #ifdef HAVE_LIBAVFORMAT_AVFORMAT_H
# include <libavformat/avformat.h> # include <libavformat/avformat.h>
static inline void vlc_init_avformat(vlc_object_t *obj) static inline void vlc_init_avformat(vlc_object_t *obj)
{ {
vlc_avcodec_lock(); vlc_avcodec_lock();
avformat_network_init();
vlc_init_avutil(obj); vlc_init_avutil(obj);
#if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100) avformat_network_init();
av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
#endif
av_register_all(); av_register_all();
......
...@@ -317,9 +317,7 @@ int OpenEncoder( vlc_object_t *p_this ) ...@@ -317,9 +317,7 @@ int OpenEncoder( vlc_object_t *p_this )
p_context->opaque = (void *)p_this; p_context->opaque = (void *)p_this;
/* set CPU capabilities */ /* set CPU capabilities */
#if LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100) #if !LIBAVUTIL_VERSION_CHECK(51, 25, 0, 42, 100)
av_set_cpu_flags_mask( INT_MAX & ~GetVlcDspMask() );
#else
p_context->dsp_mask = GetVlcDspMask(); p_context->dsp_mask = GetVlcDspMask();
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment