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 @@ ...@@ -26,49 +26,6 @@
#error You are not libvlc or one of its plugins. You cannot include this file #error You are not libvlc or one of its plugins. You cannot include this file
#endif #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 * libvlc_internal_instance_t
***************************************************************************** *****************************************************************************
......
...@@ -566,7 +566,7 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */ ...@@ -566,7 +566,7 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */
variable_t * p_vars; \ variable_t * p_vars; \
\ \
/* Stuff related to the libvlc structure */ \ /* 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 */ \ libvlc_int_t *p_libvlc; /**< (root of all evil) - 1 */ \
\ \
volatile int i_refcount; /**< usage count */ \ volatile int i_refcount; /**< usage count */ \
......
...@@ -234,8 +234,7 @@ vlc_module_begin(); ...@@ -234,8 +234,7 @@ vlc_module_begin();
add_shortcut( "ffmpeg-deinterlace" ); add_shortcut( "ffmpeg-deinterlace" );
#endif #endif
var_Create( (vlc_object_t *)p_module->p_libvlc_global, "avcodec", var_Create( p_module->p_libvlc_global, "avcodec", VLC_VAR_MUTEX );
VLC_VAR_MUTEX );
vlc_module_end(); vlc_module_end();
...@@ -339,7 +338,7 @@ static void CloseDecoder( vlc_object_t *p_this ) ...@@ -339,7 +338,7 @@ static void CloseDecoder( vlc_object_t *p_this )
decoder_sys_t *p_sys = p_dec->p_sys; decoder_sys_t *p_sys = p_dec->p_sys;
vlc_value_t lockval; 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 ) switch( p_sys->i_cat )
{ {
...@@ -428,7 +427,7 @@ void E_(InitLibavcodec)( vlc_object_t *p_object ) ...@@ -428,7 +427,7 @@ void E_(InitLibavcodec)( vlc_object_t *p_object )
static int b_ffmpeginit = 0; static int b_ffmpeginit = 0;
vlc_value_t lockval; 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 ); vlc_mutex_lock( lockval.p_address );
/* *** init ffmpeg library (libavcodec) *** */ /* *** init ffmpeg library (libavcodec) *** */
......
...@@ -125,8 +125,8 @@ static int Open( vlc_object_t *p_this ) ...@@ -125,8 +125,8 @@ static int Open( vlc_object_t *p_this )
int i_port = 0; int i_port = 0;
char *psz_src; char *psz_src;
var_Create(p_intf->p_libvlc_global, "http-host", VLC_VAR_STRING ); var_Create(p_intf->p_libvlc, "http-host", VLC_VAR_STRING );
psz_address=var_GetString(p_intf->p_libvlc_global, "http-host"); psz_address = var_GetString(p_intf->p_libvlc, "http-host");
if( !psz_address || !*psz_address ) if( !psz_address || !*psz_address )
{ {
psz_address = config_GetPsz( p_intf, "http-host" ); psz_address = config_GetPsz( p_intf, "http-host" );
...@@ -281,7 +281,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -281,7 +281,7 @@ static int Open( vlc_object_t *p_this )
/* Ugly hack to run several HTTP servers on different ports */ /* Ugly hack to run several HTTP servers on different ports */
snprintf( psz_tmp, sizeof (psz_tmp), "%s:%d", psz_address, i_port + 1 ); 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; p_sys->i_files = 0;
......
...@@ -127,11 +127,10 @@ typedef struct bridge_t ...@@ -127,11 +127,10 @@ typedef struct bridge_t
#define GetBridge(a) __GetBridge( VLC_OBJECT(a) ) #define GetBridge(a) __GetBridge( VLC_OBJECT(a) )
static bridge_t *__GetBridge( vlc_object_t *p_object ) 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; bridge_t *p_bridge;
vlc_value_t val; 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; p_bridge = NULL;
} }
...@@ -219,7 +218,7 @@ static sout_stream_id_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -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 ); p_bridge = GetBridge( p_stream );
if ( p_bridge == NULL ) 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; vlc_value_t val;
p_bridge = malloc( sizeof( bridge_t ) ); p_bridge = malloc( sizeof( bridge_t ) );
...@@ -519,7 +518,7 @@ static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id, ...@@ -519,7 +518,7 @@ static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id,
if( b_no_es ) 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++ ) for ( i = 0; i < p_bridge->i_es_num; i++ )
free( p_bridge->pp_es[i] ); free( p_bridge->pp_es[i] );
free( p_bridge->pp_es ); free( p_bridge->pp_es );
......
...@@ -177,7 +177,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -177,7 +177,7 @@ static int Open( vlc_object_t *p_this )
{ {
sout_stream_t *p_stream = (sout_stream_t *)p_this; sout_stream_t *p_stream = (sout_stream_t *)p_this;
sout_stream_sys_t *p_sys; 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; vlc_value_t val;
config_ChainParse( p_stream, CFG_PREFIX, ppsz_sout_options, 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 ) ...@@ -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 ); p_bridge = GetBridge( p_stream );
if ( p_bridge == NULL ) 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; vlc_value_t val;
p_bridge = malloc( sizeof( bridge_t ) ); p_bridge = malloc( sizeof( bridge_t ) );
...@@ -498,7 +498,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) ...@@ -498,7 +498,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
if ( b_last_es ) 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++ ) for ( i = 0; i < p_bridge->i_es_num; i++ )
free( p_bridge->pp_es[i] ); free( p_bridge->pp_es[i] );
free( p_bridge->pp_es ); free( p_bridge->pp_es );
......
...@@ -286,7 +286,7 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -286,7 +286,7 @@ static int CreateFilter( vlc_object_t *p_this )
{ {
filter_t *p_filter = (filter_t *)p_this; filter_t *p_filter = (filter_t *)p_this;
filter_sys_t *p_sys; 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_order;
char *psz_offsets; char *psz_offsets;
int i_index; int i_index;
......
...@@ -40,7 +40,7 @@ typedef struct bridge_t ...@@ -40,7 +40,7 @@ typedef struct bridge_t
#define GetBridge(a) __GetBridge( VLC_OBJECT(a) ) #define GetBridge(a) __GetBridge( VLC_OBJECT(a) )
static bridge_t *__GetBridge( vlc_object_t *p_object ) 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; bridge_t *p_bridge;
vlc_value_t val; vlc_value_t val;
......
...@@ -369,7 +369,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] ) ...@@ -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" ); msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
b_exit = VLC_TRUE; 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 */ /* lets check if we need to write the pidfile */
psz_pidfile = config_GetPsz( p_libvlc, "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[] ) ...@@ -416,7 +416,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
close( STDOUT_FILENO ); close( STDOUT_FILENO );
close( STDERR_FILENO ); close( STDERR_FILENO );
p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE; libvlc_global.b_daemon = VLC_TRUE;
} }
#endif #endif
} }
...@@ -1039,7 +1039,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release ) ...@@ -1039,7 +1039,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
#ifndef WIN32 #ifndef WIN32
char* psz_pidfile = NULL; 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" ) ) if( config_GetInt( p_libvlc, "daemon" ) )
{ {
psz_pidfile = config_GetPsz( p_libvlc, "pidfile" ); psz_pidfile = config_GetPsz( p_libvlc, "pidfile" );
...@@ -1117,7 +1117,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, ...@@ -1117,7 +1117,7 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc,
return VLC_EGENERIC; return VLC_EGENERIC;
#ifndef WIN32 #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. /* Daemon mode hack.
* We prefer the dummy interface if none is specified. */ * We prefer the dummy interface if none is specified. */
......
...@@ -34,7 +34,6 @@ extern vlc_object_t * ...@@ -34,7 +34,6 @@ extern vlc_object_t *
vlc_custom_create (vlc_object_t *p_this, size_t i_size, int i_type, vlc_custom_create (vlc_object_t *p_this, size_t i_size, int i_type,
const char *psz_type); const char *psz_type);
#if 0
/***************************************************************************** /*****************************************************************************
* libvlc_global_data_t (global variable) * libvlc_global_data_t (global variable)
***************************************************************************** *****************************************************************************
...@@ -71,8 +70,11 @@ struct libvlc_global_data_t ...@@ -71,8 +70,11 @@ struct libvlc_global_data_t
char * psz_vlcpath; char * psz_vlcpath;
#endif #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; extern uint32_t cpu_flags;
......
...@@ -139,32 +139,33 @@ vlc_object_t *vlc_custom_create( vlc_object_t *p_this, size_t i_size, ...@@ -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 == VLC_OBJECT_GLOBAL )
{ {
/* If i_type is global, then p_new is actually p_libvlc_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 = NULL;
p_new->p_libvlc_global->i_counter = 0; p_libvlc_global->i_counter = 0;
p_new->i_object_id = 0; p_new->i_object_id = 0;
p_new->p_libvlc_global->i_objects = 1; p_libvlc_global->i_objects = 1;
p_new->p_libvlc_global->pp_objects = malloc( sizeof(vlc_object_t *) ); p_libvlc_global->pp_objects = malloc( sizeof(vlc_object_t *) );
p_new->p_libvlc_global->pp_objects[0] = p_new; p_libvlc_global->pp_objects[0] = p_new;
p_new->b_attached = VLC_TRUE; p_new->b_attached = VLC_TRUE;
} }
else 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_new->p_libvlc = ( i_type == VLC_OBJECT_LIBVLC ) ? (libvlc_int_t*)p_new
: p_this->p_libvlc; : p_this->p_libvlc;
vlc_mutex_lock( &structure_lock ); vlc_mutex_lock( &structure_lock );
p_new->p_libvlc_global->i_counter++; p_libvlc_global->i_counter++;
p_new->i_object_id = p_new->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 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
* useless to try and recover anything if pp_objects gets smashed. */ * useless to try and recover anything if pp_objects gets smashed. */
TAB_APPEND( p_new->p_libvlc_global->i_objects, TAB_APPEND( p_libvlc_global->i_objects, p_libvlc_global->pp_objects,
p_new->p_libvlc_global->pp_objects,
p_new ); p_new );
vlc_mutex_unlock( &structure_lock ); vlc_mutex_unlock( &structure_lock );
...@@ -395,25 +396,27 @@ void __vlc_object_destroy( vlc_object_t *p_this ) ...@@ -395,25 +396,27 @@ void __vlc_object_destroy( vlc_object_t *p_this )
if( p_this->i_object_type == VLC_OBJECT_GLOBAL ) 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. */ /* We are the global object ... no need to lock. */
free( p_this->p_libvlc_global->pp_objects ); free( p_global->pp_objects );
p_this->p_libvlc_global->pp_objects = NULL; p_global->pp_objects = NULL;
p_this->p_libvlc_global->i_objects--; p_global->i_objects--;
vlc_mutex_destroy( &structure_lock ); vlc_mutex_destroy( &structure_lock );
} }
else else
{ {
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
int i_index; int i_index;
vlc_mutex_lock( &structure_lock ); vlc_mutex_lock( &structure_lock );
/* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
* useless to try and recover anything if pp_objects gets smashed. */ * useless to try and recover anything if pp_objects gets smashed. */
i_index = FindIndex( p_this, p_this->p_libvlc_global->pp_objects, i_index = FindIndex( p_this, p_libvlc_global->pp_objects,
p_this->p_libvlc_global->i_objects ); p_libvlc_global->i_objects );
REMOVE_ELEM( p_this->p_libvlc_global->pp_objects, REMOVE_ELEM( p_libvlc_global->pp_objects,
p_this->p_libvlc_global->i_objects, i_index ); p_libvlc_global->i_objects, i_index );
vlc_mutex_unlock( &structure_lock ); vlc_mutex_unlock( &structure_lock );
} }
...@@ -465,13 +468,14 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id ) ...@@ -465,13 +468,14 @@ void * __vlc_object_get( vlc_object_t *p_this, int i_id )
{ {
int i_max, i_middle; int i_max, i_middle;
vlc_object_t **pp_objects; vlc_object_t **pp_objects;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
vlc_mutex_lock( &structure_lock ); vlc_mutex_lock( &structure_lock );
pp_objects = p_this->p_libvlc_global->pp_objects; pp_objects = p_libvlc_global->pp_objects;
/* Perform our dichotomy */ /* 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; 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 ) ...@@ -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_list_t *p_list;
vlc_object_t **pp_current, **pp_end; vlc_object_t **pp_current, **pp_end;
int i_count = 0, i_index = 0; int i_count = 0, i_index = 0;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
vlc_mutex_lock( &structure_lock ); 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 ) ...@@ -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 ) switch( i_mode & 0x000f )
{ {
case FIND_ANYWHERE: case FIND_ANYWHERE:
pp_current = p_this->p_libvlc_global->pp_objects; pp_current = p_libvlc_global->pp_objects;
pp_end = pp_current + p_this->p_libvlc_global->i_objects; pp_end = pp_current + p_libvlc_global->i_objects;
for( ; pp_current < pp_end ; pp_current++ ) 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 ) ...@@ -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 ); 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++ ) 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 ) ...@@ -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, static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) 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; (void)oldval; (void)p_data;
if( *psz_cmd == 'l' ) if( *psz_cmd == 'l' )
{ {
...@@ -790,8 +797,8 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd, ...@@ -790,8 +797,8 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
vlc_object_t **pp_current, **pp_end; vlc_object_t **pp_current, **pp_end;
pp_current = p_this->p_libvlc_global->pp_objects; pp_current = p_libvlc_global->pp_objects;
pp_end = pp_current + p_this->p_libvlc_global->i_objects; pp_end = pp_current + p_libvlc_global->i_objects;
for( ; pp_current < pp_end ; pp_current++ ) for( ; pp_current < pp_end ; pp_current++ )
{ {
......
...@@ -155,7 +155,6 @@ static char * GetWindowsError ( void ); ...@@ -155,7 +155,6 @@ static char * GetWindowsError ( void );
static void module_LoadMain( vlc_object_t *p_this ); static void module_LoadMain( vlc_object_t *p_this );
/* Sub-version number /* Sub-version number
* (only used to avoid breakage in dev version when cache structure changes) */ * (only used to avoid breakage in dev version when cache structure changes) */
#define CACHE_SUBVERSION_NUM 3 #define CACHE_SUBVERSION_NUM 3
...@@ -170,19 +169,20 @@ void __module_InitBank( vlc_object_t *p_this ) ...@@ -170,19 +169,20 @@ void __module_InitBank( vlc_object_t *p_this )
{ {
module_bank_t *p_bank = NULL; module_bank_t *p_bank = NULL;
vlc_value_t lockval; vlc_value_t lockval;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
var_Create( p_this->p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "libvlc", &lockval ); var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address ); vlc_mutex_lock( lockval.p_address );
if( p_this->p_libvlc_global->p_module_bank ) if( p_libvlc_global->p_module_bank )
{ {
p_this->p_libvlc_global->p_module_bank->i_usage++; p_libvlc_global->p_module_bank->i_usage++;
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
return; return;
} }
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
p_bank = vlc_object_create( p_this, sizeof(module_bank_t) ); p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
if( !p_bank ) if( !p_bank )
...@@ -202,23 +202,12 @@ void __module_InitBank( vlc_object_t *p_this ) ...@@ -202,23 +202,12 @@ void __module_InitBank( vlc_object_t *p_this )
#endif #endif
/* Everything worked, attach the object */ /* Everything worked, attach the object */
p_this->p_libvlc_global->p_module_bank = p_bank; p_libvlc_global->p_module_bank = p_bank;
vlc_object_attach( p_bank, p_this->p_libvlc_global ); vlc_object_attach( p_bank, p_libvlc_global );
module_LoadMain( p_this ); module_LoadMain( p_this );
} }
/*****************************************************************************
* module_ResetBank: reset the module bank.
*****************************************************************************
* This function resets the module bank by unloading all unused plugin
* modules.
*****************************************************************************/
void __module_ResetBank( vlc_object_t *p_this )
{
msg_Err( p_this, "FIXME: module_ResetBank unimplemented" );
return;
}
/***************************************************************************** /*****************************************************************************
* module_EndBank: empty the module bank. * module_EndBank: empty the module bank.
...@@ -230,35 +219,37 @@ void __module_EndBank( vlc_object_t *p_this ) ...@@ -230,35 +219,37 @@ void __module_EndBank( vlc_object_t *p_this )
{ {
module_t * p_next = NULL; module_t * p_next = NULL;
vlc_value_t lockval; vlc_value_t lockval;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
var_Create( p_this->p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "libvlc", &lockval ); var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address ); vlc_mutex_lock( lockval.p_address );
if( !p_this->p_libvlc_global->p_module_bank ) if( !p_libvlc_global->p_module_bank )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
return; return;
} }
if( --p_this->p_libvlc_global->p_module_bank->i_usage ) if( --p_libvlc_global->p_module_bank->i_usage )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
return; return;
} }
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
config_AutoSaveConfigFile( p_this ); config_AutoSaveConfigFile( p_this );
#ifdef HAVE_DYNAMIC_PLUGINS #ifdef HAVE_DYNAMIC_PLUGINS
#define p_bank p_this->p_libvlc_global->p_module_bank # define p_bank p_libvlc_global->p_module_bank
if( p_bank->b_cache ) CacheSave( p_this ); if( p_bank->b_cache ) CacheSave( p_this );
while( p_bank->i_loaded_cache-- ) while( p_bank->i_loaded_cache-- )
{ {
if( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] ) if( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] )
{ {
DeleteModule( p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->p_module, p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->b_used ); DeleteModule( p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->p_module,
p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->b_used );
free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->psz_file ); free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache]->psz_file );
free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] ); free( p_bank->pp_loaded_cache[p_bank->i_loaded_cache] );
p_bank->pp_loaded_cache[p_bank->i_loaded_cache] = NULL; p_bank->pp_loaded_cache[p_bank->i_loaded_cache] = NULL;
...@@ -280,14 +271,14 @@ void __module_EndBank( vlc_object_t *p_this ) ...@@ -280,14 +271,14 @@ void __module_EndBank( vlc_object_t *p_this )
free( p_bank->pp_cache ); free( p_bank->pp_cache );
p_bank->pp_cache = NULL; p_bank->pp_cache = NULL;
} }
#undef p_bank # undef p_bank
#endif #endif
vlc_object_detach( p_this->p_libvlc_global->p_module_bank ); vlc_object_detach( p_libvlc_global->p_module_bank );
while( p_this->p_libvlc_global->p_module_bank->i_children ) while( p_libvlc_global->p_module_bank->i_children )
{ {
p_next = (module_t *)p_this->p_libvlc_global->p_module_bank->pp_children[0]; p_next = (module_t *)p_libvlc_global->p_module_bank->pp_children[0];
if( DeleteModule( p_next, VLC_TRUE ) ) if( DeleteModule( p_next, VLC_TRUE ) )
{ {
...@@ -301,10 +292,8 @@ void __module_EndBank( vlc_object_t *p_this ) ...@@ -301,10 +292,8 @@ void __module_EndBank( vlc_object_t *p_this )
} }
} }
vlc_object_destroy( p_this->p_libvlc_global->p_module_bank ); vlc_object_destroy( p_libvlc_global->p_module_bank );
p_this->p_libvlc_global->p_module_bank = NULL; p_libvlc_global->p_module_bank = NULL;
return;
} }
/***************************************************************************** /*****************************************************************************
...@@ -318,19 +307,20 @@ void __module_EndBank( vlc_object_t *p_this ) ...@@ -318,19 +307,20 @@ void __module_EndBank( vlc_object_t *p_this )
static void module_LoadMain( vlc_object_t *p_this ) static void module_LoadMain( vlc_object_t *p_this )
{ {
vlc_value_t lockval; vlc_value_t lockval;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
var_Create( p_this->p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "libvlc", &lockval ); var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address ); vlc_mutex_lock( lockval.p_address );
if( p_this->p_libvlc_global->p_module_bank->b_main ) if( p_libvlc_global->p_module_bank->b_main )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
return; return;
} }
p_this->p_libvlc_global->p_module_bank->b_main = VLC_TRUE; p_libvlc_global->p_module_bank->b_main = VLC_TRUE;
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
AllocateBuiltinModule( p_this, vlc_entry__main ); AllocateBuiltinModule( p_this, vlc_entry__main );
} }
...@@ -343,19 +333,20 @@ static void module_LoadMain( vlc_object_t *p_this ) ...@@ -343,19 +333,20 @@ static void module_LoadMain( vlc_object_t *p_this )
void __module_LoadBuiltins( vlc_object_t * p_this ) void __module_LoadBuiltins( vlc_object_t * p_this )
{ {
vlc_value_t lockval; vlc_value_t lockval;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
var_Create( p_this->p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "libvlc", &lockval ); var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address ); vlc_mutex_lock( lockval.p_address );
if( p_this->p_libvlc_global->p_module_bank->b_builtins ) if( p_libvlc_global->p_module_bank->b_builtins )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
return; return;
} }
p_this->p_libvlc_global->p_module_bank->b_builtins = VLC_TRUE; p_libvlc_global->p_module_bank->b_builtins = VLC_TRUE;
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
msg_Dbg( p_this, "checking builtin modules" ); msg_Dbg( p_this, "checking builtin modules" );
ALLOCATE_ALL_BUILTINS(); ALLOCATE_ALL_BUILTINS();
...@@ -370,27 +361,28 @@ void __module_LoadPlugins( vlc_object_t * p_this ) ...@@ -370,27 +361,28 @@ void __module_LoadPlugins( vlc_object_t * p_this )
{ {
#ifdef HAVE_DYNAMIC_PLUGINS #ifdef HAVE_DYNAMIC_PLUGINS
vlc_value_t lockval; vlc_value_t lockval;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
var_Create( p_this->p_libvlc_global, "libvlc", VLC_VAR_MUTEX ); var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
var_Get( p_this->p_libvlc_global, "libvlc", &lockval ); var_Get( p_libvlc_global, "libvlc", &lockval );
vlc_mutex_lock( lockval.p_address ); vlc_mutex_lock( lockval.p_address );
if( p_this->p_libvlc_global->p_module_bank->b_plugins ) if( p_libvlc_global->p_module_bank->b_plugins )
{ {
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
return; return;
} }
p_this->p_libvlc_global->p_module_bank->b_plugins = VLC_TRUE; p_libvlc_global->p_module_bank->b_plugins = VLC_TRUE;
vlc_mutex_unlock( lockval.p_address ); vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_this->p_libvlc_global, "libvlc" ); var_Destroy( p_libvlc_global, "libvlc" );
msg_Dbg( p_this, "checking plugin modules" ); msg_Dbg( p_this, "checking plugin modules" );
if( config_GetInt( p_this, "plugins-cache" ) ) if( config_GetInt( p_this, "plugins-cache" ) )
p_this->p_libvlc_global->p_module_bank->b_cache = VLC_TRUE; p_libvlc_global->p_module_bank->b_cache = VLC_TRUE;
if( p_this->p_libvlc_global->p_module_bank->b_cache || if( p_libvlc_global->p_module_bank->b_cache ||
p_this->p_libvlc_global->p_module_bank->b_cache_delete ) CacheLoad( p_this ); p_libvlc_global->p_module_bank->b_cache_delete ) CacheLoad( p_this );
AllocateAllPlugins( p_this ); AllocateAllPlugins( p_this );
#endif #endif
...@@ -1073,6 +1065,8 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file, ...@@ -1073,6 +1065,8 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
if( p_module ) if( p_module )
{ {
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
/* Everything worked fine ! /* Everything worked fine !
* The module is ready to be added to the list. */ * The module is ready to be added to the list. */
p_module->b_builtin = VLC_FALSE; p_module->b_builtin = VLC_FALSE;
...@@ -1080,13 +1074,13 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file, ...@@ -1080,13 +1074,13 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
/* msg_Dbg( p_this, "plugin \"%s\", %s", /* msg_Dbg( p_this, "plugin \"%s\", %s",
p_module->psz_object_name, p_module->psz_longname ); */ p_module->psz_object_name, p_module->psz_longname ); */
vlc_object_attach( p_module, p_this->p_libvlc_global->p_module_bank ); vlc_object_attach( p_module, p_libvlc_global->p_module_bank );
if( !p_this->p_libvlc_global->p_module_bank->b_cache ) if( !p_libvlc_global->p_module_bank->b_cache )
return 0; return 0;
#define p_bank p_libvlc_global->p_module_bank
/* Add entry to cache */ /* Add entry to cache */
#define p_bank p_this->p_libvlc_global->p_module_bank
p_bank->pp_cache = p_bank->pp_cache =
realloc( p_bank->pp_cache, (p_bank->i_cache + 1) * sizeof(void *) ); realloc( p_bank->pp_cache, (p_bank->i_cache + 1) * sizeof(void *) );
p_bank->pp_cache[p_bank->i_cache] = malloc( sizeof(module_cache_t) ); p_bank->pp_cache[p_bank->i_cache] = malloc( sizeof(module_cache_t) );
...@@ -1256,7 +1250,7 @@ static int AllocateBuiltinModule( vlc_object_t * p_this, ...@@ -1256,7 +1250,7 @@ static int AllocateBuiltinModule( vlc_object_t * p_this,
/* msg_Dbg( p_this, "builtin \"%s\", %s", /* msg_Dbg( p_this, "builtin \"%s\", %s",
p_module->psz_object_name, p_module->psz_longname ); */ p_module->psz_object_name, p_module->psz_longname ); */
vlc_object_attach( p_module, p_this->p_libvlc_global->p_module_bank ); vlc_object_attach( p_module, vlc_global( p_this )->p_module_bank );
return 0; return 0;
} }
...@@ -1632,6 +1626,7 @@ static void CacheLoad( vlc_object_t *p_this ) ...@@ -1632,6 +1626,7 @@ static void CacheLoad( vlc_object_t *p_this )
int i_cache; int i_cache;
module_cache_t **pp_cache = 0; module_cache_t **pp_cache = 0;
int32_t i_file_size, i_marker; int32_t i_file_size, i_marker;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
psz_homedir = p_this->p_libvlc->psz_homedir; psz_homedir = p_this->p_libvlc->psz_homedir;
if( !psz_homedir ) if( !psz_homedir )
...@@ -1648,7 +1643,7 @@ static void CacheLoad( vlc_object_t *p_this ) ...@@ -1648,7 +1643,7 @@ static void CacheLoad( vlc_object_t *p_this )
return; return;
} }
if( p_this->p_libvlc_global->p_module_bank->b_cache_delete ) if( p_libvlc_global->p_module_bank->b_cache_delete )
{ {
#if !defined( UNDER_CE ) #if !defined( UNDER_CE )
unlink( psz_filename ); unlink( psz_filename );
...@@ -1737,7 +1732,7 @@ static void CacheLoad( vlc_object_t *p_this ) ...@@ -1737,7 +1732,7 @@ static void CacheLoad( vlc_object_t *p_this )
return; return;
} }
p_this->p_libvlc_global->p_module_bank->i_loaded_cache = 0; p_libvlc_global->p_module_bank->i_loaded_cache = 0;
if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) ) if (fread( &i_cache, 1, sizeof(i_cache), file ) != sizeof(i_cache) )
{ {
msg_Warn( p_this, "This doesn't look like a valid plugins cache " msg_Warn( p_this, "This doesn't look like a valid plugins cache "
...@@ -1747,7 +1742,7 @@ static void CacheLoad( vlc_object_t *p_this ) ...@@ -1747,7 +1742,7 @@ static void CacheLoad( vlc_object_t *p_this )
} }
if( i_cache ) if( i_cache )
pp_cache = p_this->p_libvlc_global->p_module_bank->pp_loaded_cache = pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache =
malloc( i_cache * sizeof(void *) ); malloc( i_cache * sizeof(void *) );
#define LOAD_IMMEDIATE(a) \ #define LOAD_IMMEDIATE(a) \
...@@ -1778,7 +1773,7 @@ static void CacheLoad( vlc_object_t *p_this ) ...@@ -1778,7 +1773,7 @@ static void CacheLoad( vlc_object_t *p_this )
int i_submodules; int i_submodules;
pp_cache[i] = malloc( sizeof(module_cache_t) ); pp_cache[i] = malloc( sizeof(module_cache_t) );
p_this->p_libvlc_global->p_module_bank->i_loaded_cache++; p_libvlc_global->p_module_bank->i_loaded_cache++;
/* Load common info */ /* Load common info */
LOAD_STRING( pp_cache[i]->psz_file ); LOAD_STRING( pp_cache[i]->psz_file );
...@@ -1844,7 +1839,7 @@ static void CacheLoad( vlc_object_t *p_this ) ...@@ -1844,7 +1839,7 @@ static void CacheLoad( vlc_object_t *p_this )
msg_Warn( p_this, "plugins cache not loaded (corrupted)" ); msg_Warn( p_this, "plugins cache not loaded (corrupted)" );
/* TODO: cleanup */ /* TODO: cleanup */
p_this->p_libvlc_global->p_module_bank->i_loaded_cache = 0; p_libvlc_global->p_module_bank->i_loaded_cache = 0;
fclose( file ); fclose( file );
return; return;
...@@ -1985,6 +1980,7 @@ static void CacheSave( vlc_object_t *p_this ) ...@@ -1985,6 +1980,7 @@ static void CacheSave( vlc_object_t *p_this )
int i, j, i_cache; int i, j, i_cache;
module_cache_t **pp_cache; module_cache_t **pp_cache;
int32_t i_file_size = 0; int32_t i_file_size = 0;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
psz_homedir = p_this->p_libvlc->psz_homedir; psz_homedir = p_this->p_libvlc->psz_homedir;
if( !psz_homedir ) if( !psz_homedir )
...@@ -2052,8 +2048,8 @@ static void CacheSave( vlc_object_t *p_this ) ...@@ -2052,8 +2048,8 @@ static void CacheSave( vlc_object_t *p_this )
i_file_size = ftell( file ); i_file_size = ftell( file );
fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file ); fwrite( &i_file_size, sizeof(char), sizeof(i_file_size), file );
i_cache = p_this->p_libvlc_global->p_module_bank->i_cache; i_cache = p_libvlc_global->p_module_bank->i_cache;
pp_cache = p_this->p_libvlc_global->p_module_bank->pp_cache; pp_cache = p_libvlc_global->p_module_bank->pp_cache;
fwrite( &i_cache, sizeof(char), sizeof(i_cache), file ); fwrite( &i_cache, sizeof(char), sizeof(i_cache), file );
...@@ -2237,9 +2233,10 @@ static module_cache_t *CacheFind( vlc_object_t *p_this, char *psz_file, ...@@ -2237,9 +2233,10 @@ static module_cache_t *CacheFind( vlc_object_t *p_this, char *psz_file,
{ {
module_cache_t **pp_cache; module_cache_t **pp_cache;
int i_cache, i; int i_cache, i;
libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
pp_cache = p_this->p_libvlc_global->p_module_bank->pp_loaded_cache; pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache;
i_cache = p_this->p_libvlc_global->p_module_bank->i_loaded_cache; i_cache = p_libvlc_global->p_module_bank->i_loaded_cache;
for( i = 0; i < i_cache; i++ ) for( i = 0; i < i_cache; i++ )
{ {
......
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