Use a vlc_CPU() wrapper instead of (ab)using libvlc_global

This commit is contained in:
Rémi Denis-Courmont 2007-05-19 21:43:16 +00:00
parent ce6766b628
commit 7b0773e690
15 changed files with 80 additions and 59 deletions

View File

@ -1162,6 +1162,7 @@ VLC_EXPORT( int, __vlc_execve, ( vlc_object_t *p_object, int i_argc, char *const
#define CPU_CAPABILITY_SSE2 (1<<7)
#define CPU_CAPABILITY_ALTIVEC (1<<16)
#define CPU_CAPABILITY_FPU (1<<31)
VLC_EXPORT( unsigned, vlc_CPU, ( void ) );
/*****************************************************************************
* I18n stuff

View File

@ -313,7 +313,7 @@ static int OpenFilter( vlc_object_t *p_this )
mad_synth_init( &p_sys->mad_synth );
mad_stream_options( &p_sys->mad_stream, MAD_OPTION_IGNORECRC );
if( p_this->p_libvlc_global->i_cpu & CPU_CAPABILITY_FPU )
if( vlc_CPU() & CPU_CAPABILITY_FPU )
p_filter->fmt_out.i_codec = VLC_FOURCC('f','l','3','2');
else
p_filter->fmt_out.i_codec = VLC_FOURCC('f','i','3','2');

View File

@ -357,7 +357,7 @@ static int Open( vlc_object_t *p_this )
/* Choose the linear PCM format (read the comment above about FPU
and float32) */
if( p_aout->p_libvlc_global->i_cpu & CPU_CAPABILITY_FPU )
if( vlc_CPU() & CPU_CAPABILITY_FPU )
{
i_vlc_pcm_format = VLC_FOURCC('f','l','3','2');
i_snd_pcm_format = SND_PCM_FORMAT_FLOAT;

View File

@ -121,7 +121,7 @@ static int Open( vlc_object_t *p_this )
aout_DateSet( &p_sys->date, 0 );
p_dec->fmt_out.i_cat = AUDIO_ES;
if (p_this->p_libvlc_global->i_cpu & CPU_CAPABILITY_FPU)
if (vlc_CPU() & CPU_CAPABILITY_FPU)
p_dec->fmt_out.i_codec = VLC_FOURCC('f','l','3','2');
else
p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE;
@ -156,7 +156,7 @@ static int Open( vlc_object_t *p_this )
/* Set the faad config */
cfg = faacDecGetCurrentConfiguration( p_sys->hfaad );
if (p_this->p_libvlc_global->i_cpu & CPU_CAPABILITY_FPU)
if (vlc_CPU() & CPU_CAPABILITY_FPU)
cfg->outputFormat = FAAD_FMT_FLOAT;
else
cfg->outputFormat = FAAD_FMT_16BIT;
@ -432,7 +432,7 @@ static void DoReordering( decoder_t *p_dec,
}
/* Do the actual reordering */
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_FPU )
if( vlc_CPU() & CPU_CAPABILITY_FPU )
for( i = 0; i < i_samples; i++ )
for( j = 0; j < i_nb_channels; j++ )
p_out[i * i_nb_channels + pi_chan_table[j]] =

View File

@ -261,20 +261,21 @@ int E_(OpenEncoder)( vlc_object_t *p_this )
p_context->opaque = (void *)p_this;
/* Set CPU capabilities */
unsigned i_cpu = vlc_CPU();
p_context->dsp_mask = 0;
if( !(p_enc->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMX) )
if( !(i_cpu & CPU_CAPABILITY_MMX) )
{
p_context->dsp_mask |= FF_MM_MMX;
}
if( !(p_enc->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT) )
if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
{
p_context->dsp_mask |= FF_MM_MMXEXT;
}
if( !(p_enc->p_libvlc_global->i_cpu & CPU_CAPABILITY_3DNOW) )
if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
{
p_context->dsp_mask |= FF_MM_3DNOW;
}
if( !(p_enc->p_libvlc_global->i_cpu & CPU_CAPABILITY_SSE) )
if( !(i_cpu & CPU_CAPABILITY_SSE) )
{
p_context->dsp_mask |= FF_MM_SSE;
p_context->dsp_mask |= FF_MM_SSE2;

View File

@ -234,7 +234,8 @@ vlc_module_begin();
add_shortcut( "ffmpeg-deinterlace" );
#endif
var_Create( p_module->p_libvlc_global, "avcodec", VLC_VAR_MUTEX );
var_Create( (vlc_object_t *)p_module->p_libvlc_global, "avcodec",
VLC_VAR_MUTEX );
vlc_module_end();
@ -284,24 +285,25 @@ static int OpenDecoder( vlc_object_t *p_this )
p_context->opaque = (void *)p_this;
/* Set CPU capabilities */
unsigned i_cpu = vlc_CPU();
p_context->dsp_mask = 0;
if( !(p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMX) )
if( !(i_cpu & CPU_CAPABILITY_MMX) )
{
p_context->dsp_mask |= FF_MM_MMX;
}
if( !(p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT) )
if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
{
p_context->dsp_mask |= FF_MM_MMXEXT;
}
if( !(p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_3DNOW) )
if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
{
p_context->dsp_mask |= FF_MM_3DNOW;
}
if( !(p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_SSE) )
if( !(i_cpu & CPU_CAPABILITY_SSE) )
{
p_context->dsp_mask |= FF_MM_SSE;
}
if( !(p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_SSE2) )
if( !(i_cpu & CPU_CAPABILITY_SSE2) )
{
p_context->dsp_mask |= FF_MM_SSE2;
}
@ -337,7 +339,7 @@ static void CloseDecoder( vlc_object_t *p_this )
decoder_sys_t *p_sys = p_dec->p_sys;
vlc_value_t lockval;
var_Get( p_dec->p_libvlc_global, "avcodec", &lockval );
var_Get( (vlc_object_t *)p_dec->p_libvlc_global, "avcodec", &lockval );
switch( p_sys->i_cat )
{
@ -426,7 +428,7 @@ void E_(InitLibavcodec)( vlc_object_t *p_object )
static int b_ffmpeginit = 0;
vlc_value_t lockval;
var_Get( p_object->p_libvlc_global, "avcodec", &lockval );
var_Get( (vlc_object_t *)p_object->p_libvlc_global, "avcodec", &lockval );
vlc_mutex_lock( lockval.p_address );
/* *** init ffmpeg library (libavcodec) *** */

View File

@ -122,7 +122,7 @@ int E_(InitPostproc)( decoder_t *p_dec, void *p_data,
int i_width, int i_height, int pix_fmt )
{
video_postproc_sys_t *p_sys = (video_postproc_sys_t *)p_data;
int32_t i_cpu = p_dec->p_libvlc_global->i_cpu;
unsigned i_cpu = vlc_CPU();
int i_flags = 0;
/* Set CPU capabilities */

View File

@ -115,20 +115,21 @@ int E_(OpenScaler)( vlc_object_t *p_this )
swscale_fast_memcpy = p_filter->p_libvlc->pf_memcpy;
/* Set CPU capabilities */
unsigned i_cpu = vlc_CPU();
p_sys->i_cpu_mask = 0;
if( p_filter->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMX )
if( i_cpu & CPU_CAPABILITY_MMX )
{
p_sys->i_cpu_mask |= SWS_CPU_CAPS_MMX;
}
if( p_filter->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT )
if( i_cpu & CPU_CAPABILITY_MMXEXT )
{
p_sys->i_cpu_mask |= SWS_CPU_CAPS_MMX2;
}
if( p_filter->p_libvlc_global->i_cpu & CPU_CAPABILITY_3DNOW )
if( i_cpu & CPU_CAPABILITY_3DNOW )
{
p_sys->i_cpu_mask |= SWS_CPU_CAPS_3DNOW;
}
if( p_filter->p_libvlc_global->i_cpu & CPU_CAPABILITY_ALTIVEC )
if( i_cpu & CPU_CAPABILITY_ALTIVEC )
{
p_sys->i_cpu_mask |= SWS_CPU_CAPS_ALTIVEC;
}

View File

@ -148,23 +148,23 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->b_preroll = VLC_FALSE;
#if defined( __i386__ ) || defined( __x86_64__ )
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMX )
if( vlc_CPU() & CPU_CAPABILITY_MMX )
{
i_accel |= MPEG2_ACCEL_X86_MMX;
}
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_3DNOW )
if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
{
i_accel |= MPEG2_ACCEL_X86_3DNOW;
}
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT )
if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
{
i_accel |= MPEG2_ACCEL_X86_MMXEXT;
}
#elif defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_ALTIVEC )
if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
{
i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
}

View File

@ -1114,19 +1114,21 @@ static int Open ( vlc_object_t *p_this )
p_sys->param.i_fps_num = p_enc->fmt_in.video.i_frame_rate;
p_sys->param.i_fps_den = p_enc->fmt_in.video.i_frame_rate_base;
}
if( !(p_enc->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMX) )
unsigned i_cpu = vlc_CPU();
if( !(i_cpu & CPU_CAPABILITY_MMX) )
{
p_sys->param.cpu &= ~X264_CPU_MMX;
}
if( !(p_enc->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT) )
if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
{
p_sys->param.cpu &= ~X264_CPU_MMXEXT;
}
if( !(p_enc->p_libvlc_global->i_cpu & CPU_CAPABILITY_SSE) )
if( !(i_cpu & CPU_CAPABILITY_SSE) )
{
p_sys->param.cpu &= ~X264_CPU_SSE;
}
if( !(p_enc->p_libvlc_global->i_cpu & CPU_CAPABILITY_SSE2) )
if( !(i_cpu & CPU_CAPABILITY_SSE2) )
{
p_sys->param.cpu &= ~X264_CPU_SSE2;
}

View File

@ -152,23 +152,23 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->b_skip = 0;
#if defined( __i386__ )
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMX )
if( vlc_CPU() & CPU_CAPABILITY_MMX )
{
i_accel |= MPEG2_ACCEL_X86_MMX;
}
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_3DNOW )
if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
{
i_accel |= MPEG2_ACCEL_X86_3DNOW;
}
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT )
if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
{
i_accel |= MPEG2_ACCEL_X86_MMXEXT;
}
#elif defined( __powerpc__ ) || defined( SYS_DARWIN )
if( p_dec->p_libvlc_global->i_cpu & CPU_CAPABILITY_ALTIVEC )
if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
{
i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
}

View File

@ -352,20 +352,21 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
id->ff_enc_c = avcodec_alloc_context();
/* Set CPU capabilities */
unsigned i_cpu = vlc_CPU();
id->ff_enc_c->dsp_mask = 0;
if( !(p_stream->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMX) )
if( !(i_cpu & CPU_CAPABILITY_MMX) )
{
id->ff_enc_c->dsp_mask |= FF_MM_MMX;
}
if( !(p_stream->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT) )
if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
{
id->ff_enc_c->dsp_mask |= FF_MM_MMXEXT;
}
if( !(p_stream->p_libvlc_global->i_cpu & CPU_CAPABILITY_3DNOW) )
if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
{
id->ff_enc_c->dsp_mask |= FF_MM_3DNOW;
}
if( !(p_stream->p_libvlc_global->i_cpu & CPU_CAPABILITY_SSE) )
if( !(i_cpu & CPU_CAPABILITY_SSE) )
{
id->ff_enc_c->dsp_mask |= FF_MM_SSE;
id->ff_enc_c->dsp_mask |= FF_MM_SSE2;
@ -725,20 +726,21 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
id->ff_enc_c = avcodec_alloc_context();
/* Set CPU capabilities */
unsigned i_cpu = vlc_CPU();
id->ff_enc_c->dsp_mask = 0;
if( !(p_stream->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMX) )
if( !(i_cpu & CPU_CAPABILITY_MMX) )
{
id->ff_enc_c->dsp_mask |= FF_MM_MMX;
}
if( !(p_stream->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT) )
if( !(i_cpu & CPU_CAPABILITY_MMXEXT) )
{
id->ff_enc_c->dsp_mask |= FF_MM_MMXEXT;
}
if( !(p_stream->p_libvlc_global->i_cpu & CPU_CAPABILITY_3DNOW) )
if( !(i_cpu & CPU_CAPABILITY_3DNOW) )
{
id->ff_enc_c->dsp_mask |= FF_MM_3DNOW;
}
if( !(p_stream->p_libvlc_global->i_cpu & CPU_CAPABILITY_SSE) )
if( !(i_cpu & CPU_CAPABILITY_SSE) )
{
id->ff_enc_c->dsp_mask |= FF_MM_SSE;
id->ff_enc_c->dsp_mask |= FF_MM_SSE2;

View File

@ -207,7 +207,7 @@ static int Create( vlc_object_t *p_this )
vlc_mutex_init( p_vout, &p_vout->p_sys->filter_lock );
#if defined(CAN_COMPILE_C_ALTIVEC)
if( p_vout->p_libvlc_global->i_cpu & CPU_CAPABILITY_ALTIVEC )
if( vlc_CPU() & CPU_CAPABILITY_ALTIVEC )
{
p_vout->p_sys->pf_merge = MergeAltivec;
p_vout->p_sys->pf_end_merge = NULL;
@ -215,7 +215,7 @@ static int Create( vlc_object_t *p_this )
else
#endif
#if defined(CAN_COMPILE_SSE)
if( p_vout->p_libvlc_global->i_cpu & CPU_CAPABILITY_SSE2 )
if( vlc_CPU() & CPU_CAPABILITY_SSE2 )
{
p_vout->p_sys->pf_merge = MergeSSE2;
p_vout->p_sys->pf_end_merge = EndMMX;
@ -223,7 +223,7 @@ static int Create( vlc_object_t *p_this )
else
#endif
#if defined(CAN_COMPILE_MMXEXT)
if( p_vout->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT )
if( vlc_CPU() & CPU_CAPABILITY_MMXEXT )
{
p_vout->p_sys->pf_merge = MergeMMXEXT;
p_vout->p_sys->pf_end_merge = EndMMX;
@ -231,7 +231,7 @@ static int Create( vlc_object_t *p_this )
else
#endif
#if defined(CAN_COMPILE_3DNOW)
if( p_vout->p_libvlc_global->i_cpu & CPU_CAPABILITY_3DNOW )
if( vlc_CPU() & CPU_CAPABILITY_3DNOW )
{
p_vout->p_sys->pf_merge = Merge3DNow;
p_vout->p_sys->pf_end_merge = End3DNow;
@ -1965,7 +1965,7 @@ static void RenderX( vout_thread_t *p_vout,
uint8_t *src = &p_pic->p[i_plane].p_pixels[8*y*i_src];
#ifdef CAN_COMPILE_MMXEXT
if( p_vout->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT )
if( vlc_CPU & CPU_CAPABILITY_MMXEXT )
XDeintBand8x8MMXEXT( dst, i_dst, src, i_src, i_mbx, i_modx );
else
#endif
@ -1992,7 +1992,7 @@ static void RenderX( vout_thread_t *p_vout,
}
#ifdef CAN_COMPILE_MMXEXT
if( p_vout->p_libvlc_global->i_cpu & CPU_CAPABILITY_MMXEXT )
if( vlc_CPU & CPU_CAPABILITY_MMXEXT )
emms();
#endif
}

View File

@ -173,7 +173,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
if( !libvlc_global.b_ready )
{
/* Guess what CPU we have */
libvlc_global.i_cpu = CPUCapabilities();
cpu_flags = CPUCapabilities();
/* The module bank will be initialized later */
libvlc_global.p_module_bank = NULL;
@ -728,27 +728,27 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
msg_Flush( p_libvlc );
if( !config_GetInt( p_libvlc, "fpu" ) )
libvlc_global.i_cpu &= ~CPU_CAPABILITY_FPU;
cpu_flags &= ~CPU_CAPABILITY_FPU;
#if defined( __i386__ ) || defined( __x86_64__ )
if( !config_GetInt( p_libvlc, "mmx" ) )
libvlc_global.i_cpu &= ~CPU_CAPABILITY_MMX;
cpu_flags &= ~CPU_CAPABILITY_MMX;
if( !config_GetInt( p_libvlc, "3dn" ) )
libvlc_global.i_cpu &= ~CPU_CAPABILITY_3DNOW;
cpu_flags &= ~CPU_CAPABILITY_3DNOW;
if( !config_GetInt( p_libvlc, "mmxext" ) )
libvlc_global.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
cpu_flags &= ~CPU_CAPABILITY_MMXEXT;
if( !config_GetInt( p_libvlc, "sse" ) )
libvlc_global.i_cpu &= ~CPU_CAPABILITY_SSE;
cpu_flags &= ~CPU_CAPABILITY_SSE;
if( !config_GetInt( p_libvlc, "sse2" ) )
libvlc_global.i_cpu &= ~CPU_CAPABILITY_SSE2;
cpu_flags &= ~CPU_CAPABILITY_SSE2;
#endif
#if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
if( !config_GetInt( p_libvlc, "altivec" ) )
libvlc_global.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
cpu_flags &= ~CPU_CAPABILITY_ALTIVEC;
#endif
#define PRINT_CAPABILITY( capability, string ) \
if( libvlc_global.i_cpu & capability ) \
if( vlc_CPU() & capability ) \
{ \
strncat( p_capabilities, string " ", \
sizeof(p_capabilities) - strlen(p_capabilities) ); \

View File

@ -51,7 +51,7 @@ static void SigHandler ( int );
static jmp_buf env;
static int i_illegal;
#if defined( __i386__ ) || defined( __x86_64__ )
static char *psz_capability;
static const char *psz_capability;
#endif
#endif
@ -60,7 +60,7 @@ static char *psz_capability;
*****************************************************************************
* This function is called to list extensions the CPU may have.
*****************************************************************************/
uint32_t CPUCapabilities( void )
static uint32_t CPUCapabilities( void )
{
volatile uint32_t i_capabilities = CPU_CAPABILITY_NONE;
@ -338,3 +338,15 @@ static void SigHandler( int i_signal )
}
#endif
extern uint32_t cpu_flags = 0;
/*****************************************************************************
* vlc_CPU: get pre-computed CPU capability flags
****************************************************************************/
unsigned vlc_CPU (void)
{
return cpu_flags;
}