Commit cac55911 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

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 )
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
......
......@@ -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();
......
......@@ -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
......
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