Commit 2e0409a1 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Hide libvlc_global_data_t from plugins

parent c262bd27
......@@ -26,49 +26,6 @@
#error You are not libvlc or one of its plugins. You cannot include this file
#endif
/*****************************************************************************
* libvlc_global_data_t (global variable)
*****************************************************************************
* This structure has an unique instance, statically allocated in main and
* never accessed from the outside. It stores once-initialized data such as
* the CPU capabilities or the global lock.
*****************************************************************************/
struct libvlc_global_data_t
{
VLC_COMMON_MEMBERS
vlc_bool_t b_ready; ///< Initialization boolean
uint32_t i_cpu; ///< CPU extensions
/* Object structure data */
int i_counter; ///< object counter
int i_objects; ///< Attached objects count
vlc_object_t ** pp_objects; ///< Array of all objects
module_bank_t * p_module_bank; ///< The module bank
intf_thread_t *p_probe; ///< Devices prober
/* Arch-specific variables */
#if !defined( WIN32 )
vlc_bool_t b_daemon;
#endif
#if defined( SYS_BEOS )
vlc_object_t * p_appthread;
char * psz_vlcpath;
#elif defined( __APPLE__ )
char * psz_vlcpath;
vlc_iconv_t iconv_macosx; /* for HFS+ file names */
vlc_mutex_t iconv_lock;
#elif defined( WIN32 ) && !defined( UNDER_CE )
SIGNALOBJECTANDWAIT SignalObjectAndWait;
vlc_bool_t b_fast_mutex;
int i_win9x_cv;
char * psz_vlcpath;
#elif defined( UNDER_CE )
char * psz_vlcpath;
#endif
};
/*****************************************************************************
* libvlc_internal_instance_t
*****************************************************************************
......
......@@ -566,7 +566,7 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */
variable_t * p_vars; \
\
/* Stuff related to the libvlc structure */ \
libvlc_global_data_t *p_libvlc_global; /**< root of all evil */ \
vlc_object_t *p_libvlc_global; /**< root of all evil */ \
libvlc_int_t *p_libvlc; /**< (root of all evil) - 1 */ \
\
volatile int i_refcount; /**< usage count */ \
......
......@@ -234,8 +234,7 @@ vlc_module_begin();
add_shortcut( "ffmpeg-deinterlace" );
#endif
var_Create( (vlc_object_t *)p_module->p_libvlc_global, "avcodec",
VLC_VAR_MUTEX );
var_Create( p_module->p_libvlc_global, "avcodec", VLC_VAR_MUTEX );
vlc_module_end();
......@@ -339,7 +338,7 @@ static void CloseDecoder( vlc_object_t *p_this )
decoder_sys_t *p_sys = p_dec->p_sys;
vlc_value_t lockval;
var_Get( (vlc_object_t *)p_dec->p_libvlc_global, "avcodec", &lockval );
var_Get( p_dec->p_libvlc_global, "avcodec", &lockval );
switch( p_sys->i_cat )
{
......@@ -428,7 +427,7 @@ void E_(InitLibavcodec)( vlc_object_t *p_object )
static int b_ffmpeginit = 0;
vlc_value_t lockval;
var_Get( (vlc_object_t *)p_object->p_libvlc_global, "avcodec", &lockval );
var_Get( p_object->p_libvlc_global, "avcodec", &lockval );
vlc_mutex_lock( lockval.p_address );
/* *** init ffmpeg library (libavcodec) *** */
......
......@@ -125,8 +125,8 @@ static int Open( vlc_object_t *p_this )
int i_port = 0;
char *psz_src;
var_Create(p_intf->p_libvlc_global, "http-host", VLC_VAR_STRING );
psz_address=var_GetString(p_intf->p_libvlc_global, "http-host");
var_Create(p_intf->p_libvlc, "http-host", VLC_VAR_STRING );
psz_address = var_GetString(p_intf->p_libvlc, "http-host");
if( !psz_address || !*psz_address )
{
psz_address = config_GetPsz( p_intf, "http-host" );
......@@ -281,7 +281,7 @@ static int Open( vlc_object_t *p_this )
/* Ugly hack to run several HTTP servers on different ports */
snprintf( psz_tmp, sizeof (psz_tmp), "%s:%d", psz_address, i_port + 1 );
var_SetString( p_intf->p_libvlc_global, "http-host", psz_tmp );
var_SetString( p_intf->p_libvlc, "http-host", psz_tmp );
}
p_sys->i_files = 0;
......
......@@ -127,11 +127,10 @@ typedef struct bridge_t
#define GetBridge(a) __GetBridge( VLC_OBJECT(a) )
static bridge_t *__GetBridge( vlc_object_t *p_object )
{
libvlc_global_data_t *p_libvlc_global = p_object->p_libvlc_global;
bridge_t *p_bridge;
vlc_value_t val;
if( var_Get( p_libvlc_global, "bridge-struct", &val ) != VLC_SUCCESS )
if( var_Get( p_object->p_libvlc_global, "bridge-struct", &val ) )
{
p_bridge = NULL;
}
......@@ -219,7 +218,7 @@ static sout_stream_id_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt )
p_bridge = GetBridge( p_stream );
if ( p_bridge == NULL )
{
libvlc_global_data_t *p_libvlc_global = p_stream->p_libvlc_global;
vlc_object_t *p_libvlc_global = p_stream->p_libvlc_global;
vlc_value_t val;
p_bridge = malloc( sizeof( bridge_t ) );
......@@ -519,7 +518,7 @@ static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id,
if( b_no_es )
{
libvlc_global_data_t *p_libvlc_global = p_stream->p_libvlc_global;
vlc_object_t *p_libvlc_global = p_stream->p_libvlc_global;
for ( i = 0; i < p_bridge->i_es_num; i++ )
free( p_bridge->pp_es[i] );
free( p_bridge->pp_es );
......
......@@ -177,7 +177,7 @@ static int Open( vlc_object_t *p_this )
{
sout_stream_t *p_stream = (sout_stream_t *)p_this;
sout_stream_sys_t *p_sys;
libvlc_global_data_t *p_libvlc_global = p_this->p_libvlc_global;
vlc_object_t *p_libvlc_global = p_this->p_libvlc_global;
vlc_value_t val;
config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options,
......@@ -317,7 +317,7 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
p_bridge = GetBridge( p_stream );
if ( p_bridge == NULL )
{
libvlc_global_data_t *p_libvlc_global = p_stream->p_libvlc_global;
vlc_object_t *p_libvlc_global = p_stream->p_libvlc_global;
vlc_value_t val;
p_bridge = malloc( sizeof( bridge_t ) );
......@@ -498,7 +498,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
if ( b_last_es )
{
libvlc_global_data_t *p_libvlc_global = p_stream->p_libvlc_global;
vlc_object_t *p_libvlc_global = p_stream->p_libvlc_global;
for ( i = 0; i < p_bridge->i_es_num; i++ )
free( p_bridge->pp_es[i] );
free( p_bridge->pp_es );
......
......@@ -286,7 +286,7 @@ static int CreateFilter( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys;
libvlc_global_data_t *p_libvlc_global = p_filter->p_libvlc_global;
vlc_object_t *p_libvlc_global = p_filter->p_libvlc_global;
char *psz_order;
char *psz_offsets;
int i_index;
......
......@@ -40,7 +40,7 @@ typedef struct bridge_t
#define GetBridge(a) __GetBridge( VLC_OBJECT(a) )
static bridge_t *__GetBridge( vlc_object_t *p_object )
{
libvlc_global_data_t *p_libvlc_global = p_object->p_libvlc_global;
vlc_object_t *p_libvlc_global = p_object->p_libvlc_global;
bridge_t *p_bridge;
vlc_value_t val;
......
......@@ -369,7 +369,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
b_exit = VLC_TRUE;
}
p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE;
libvlc_global.b_daemon = VLC_TRUE;
/* lets check if we need to write the pidfile */
psz_pidfile = config_GetPsz( p_libvlc, "pidfile" );
......@@ -416,7 +416,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
close( STDOUT_FILENO );
close( STDERR_FILENO );
p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE;
libvlc_global.b_daemon = VLC_TRUE;
}
#endif
}
......@@ -1039,7 +1039,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
#ifndef WIN32
char* psz_pidfile = NULL;
if( p_libvlc->p_libvlc_global->p_module_bank )
if( libvlc_global.p_module_bank )
if( config_GetInt( p_libvlc, "daemon" ) )
{
psz_pidfile = config_GetPsz( p_libvlc, "pidfile" );
......@@ -1117,7 +1117,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc,
return VLC_EGENERIC;
#ifndef WIN32
if( p_libvlc->p_libvlc_global->b_daemon && b_block && !psz_module )
if( libvlc_global.b_daemon && b_block && !psz_module )
{
/* Daemon mode hack.
* We prefer the dummy interface if none is specified. */
......
......@@ -34,7 +34,6 @@ extern vlc_object_t *
vlc_custom_create (vlc_object_t *p_this, size_t i_size, int i_type,
const char *psz_type);
#if 0
/*****************************************************************************
* libvlc_global_data_t (global variable)
*****************************************************************************
......@@ -71,8 +70,11 @@ struct libvlc_global_data_t
char * psz_vlcpath;
#endif
};
#endif
static inline libvlc_global_data_t *vlc_global( vlc_object_t *p_this )
{
return (libvlc_global_data_t *)p_this->p_libvlc_global;
}
extern uint32_t cpu_flags;
......
......@@ -139,32 +139,33 @@ vlc_object_t *vlc_custom_create( vlc_object_t *p_this, size_t i_size,
if( i_type == VLC_OBJECT_GLOBAL )
{
/* If i_type is global, then p_new is actually p_libvlc_global */
p_new->p_libvlc_global = (libvlc_global_data_t*)p_new;
libvlc_global_data_t *p_libvlc_global = (libvlc_global_data_t *)p_new;
p_new->p_libvlc_global = p_new;
p_new->p_libvlc = NULL;
p_new->p_libvlc_global->i_counter = 0;
p_libvlc_global->i_counter = 0;
p_new->i_object_id = 0;
p_new->p_libvlc_global->i_objects = 1;
p_new->p_libvlc_global->pp_objects = malloc( sizeof(vlc_object_t *) );
p_new->p_libvlc_global->pp_objects[0] = p_new;
p_libvlc_global->i_objects = 1;
p_libvlc_global->pp_objects = malloc( sizeof(vlc_object_t *) );
p_libvlc_global->pp_objects[0] = p_new;
p_new->b_attached = VLC_TRUE;
}
else
{
p_new->p_libvlc_global = p_this->p_libvlc_global;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
p_new->p_libvlc_global = VLC_OBJECT (p_libvlc_global);
p_new->p_libvlc = ( i_type == VLC_OBJECT_LIBVLC ) ? (libvlc_int_t*)p_new
: p_this->p_libvlc;
vlc_mutex_lock( &structure_lock );
p_new->p_libvlc_global->i_counter++;
p_new->i_object_id = p_new->p_libvlc_global->i_counter;
p_libvlc_global->i_counter++;
p_new->i_object_id = p_libvlc_global->i_counter;
/* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
* useless to try and recover anything if pp_objects gets smashed. */
TAB_APPEND( p_new->p_libvlc_global->i_objects,
p_new->p_libvlc_global->pp_objects,
TAB_APPEND( p_libvlc_global->i_objects, p_libvlc_global->pp_objects,
p_new );
vlc_mutex_unlock( &structure_lock );
......@@ -395,25 +396,27 @@ void __vlc_object_destroy( vlc_object_t *p_this )
if( p_this->i_object_type == VLC_OBJECT_GLOBAL )
{
libvlc_global_data_t *p_global = (libvlc_global_data_t *)p_this;
/* We are the global object ... no need to lock. */
free( p_this->p_libvlc_global->pp_objects );
p_this->p_libvlc_global->pp_objects = NULL;
p_this->p_libvlc_global->i_objects--;
free( p_global->pp_objects );
p_global->pp_objects = NULL;
p_global->i_objects--;
vlc_mutex_destroy( &structure_lock );
}
else
{
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
int i_index;
vlc_mutex_lock( &structure_lock );
/* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
* useless to try and recover anything if pp_objects gets smashed. */
i_index = FindIndex( p_this, p_this->p_libvlc_global->pp_objects,
p_this->p_libvlc_global->i_objects );
REMOVE_ELEM( p_this->p_libvlc_global->pp_objects,
p_this->p_libvlc_global->i_objects, i_index );
i_index = FindIndex( p_this, p_libvlc_global->pp_objects,
p_libvlc_global->i_objects );
REMOVE_ELEM( p_libvlc_global->pp_objects,
p_libvlc_global->i_objects, i_index );
vlc_mutex_unlock( &structure_lock );
}
......@@ -465,13 +468,14 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id )
{
int i_max, i_middle;
vlc_object_t **pp_objects;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
vlc_mutex_lock( &structure_lock );
pp_objects = p_this->p_libvlc_global->pp_objects;
pp_objects = p_libvlc_global->pp_objects;
/* Perform our dichotomy */
for( i_max = p_this->p_libvlc_global->i_objects - 1 ; ; )
for( i_max = p_libvlc_global->i_objects - 1 ; ; )
{
i_middle = i_max / 2;
......@@ -713,6 +717,7 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
vlc_list_t *p_list;
vlc_object_t **pp_current, **pp_end;
int i_count = 0, i_index = 0;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
vlc_mutex_lock( &structure_lock );
......@@ -720,8 +725,8 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
switch( i_mode & 0x000f )
{
case FIND_ANYWHERE:
pp_current = p_this->p_libvlc_global->pp_objects;
pp_end = pp_current + p_this->p_libvlc_global->i_objects;
pp_current = p_libvlc_global->pp_objects;
pp_end = pp_current + p_libvlc_global->i_objects;
for( ; pp_current < pp_end ; pp_current++ )
{
......@@ -733,7 +738,7 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
}
p_list = NewList( i_count );
pp_current = p_this->p_libvlc_global->pp_objects;
pp_current = p_libvlc_global->pp_objects;
for( ; pp_current < pp_end ; pp_current++ )
{
......@@ -783,6 +788,8 @@ vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
(void)oldval; (void)p_data;
if( *psz_cmd == 'l' )
{
......@@ -790,8 +797,8 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
vlc_object_t **pp_current, **pp_end;
pp_current = p_this->p_libvlc_global->pp_objects;
pp_end = pp_current + p_this->p_libvlc_global->i_objects;
pp_current = p_libvlc_global->pp_objects;
pp_end = pp_current + p_libvlc_global->i_objects;
for( ; pp_current < pp_end ; pp_current++ )
{
......
This diff is collapsed.
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