Commit 145b1961 authored by Sam Hocevar's avatar Sam Hocevar

* ./src/libvlc.c, ./include/main.h: the root of all objects is now

    p_libvlc, and each p_vlc is a child of p_libvlc. Reasons for this are:

     o the module bank and the message bank only need to be initialized once,
       which gives faster loads when multiple instances of libvlc are used,
     o we allow the possibility of different p_vlc sharing objects, for
       instance the audio output,
     o the CPU detection is only done once.

    This patch is not polished yet, but I cannot do any intensive tests for
    the moment because of a bug somewhere that leaves audio output objects
    lying here and there which needs to be investigated first. The current
    major issue is that the module bank is no longer freed.
parent 75873492
......@@ -17,6 +17,7 @@ Description: a free MPEG, DVD and DivX player
DVDs, or MPEG streams from a network source.
Package: libvlc0-dev
Section: devel
Architecture: any
Depends: vlc (= ${Source-Version}), ${shlibs:Depends}
Description: development files for the VideoLAN Client
......
......@@ -3,7 +3,7 @@
* Declaration and extern access to global program object.
*****************************************************************************
* Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
* $Id: main.h,v 1.45 2002/08/20 18:08:51 sam Exp $
* $Id: main.h,v 1.46 2002/10/03 13:21:54 sam Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
*
......@@ -23,14 +23,54 @@
*****************************************************************************/
/*****************************************************************************
* vlc_t, p_vlc (global variable)
* libvlc_t (global variable)
*****************************************************************************
* This structure has an unique instance, declared in main and pointed by the
* only global variable of the program. It should allow access to any variable
* of the program, for user-interface purposes or more easier call of interface
* and common functions (example: the intf_*Msg functions). Please avoid using
* it when you can access the members you need in an other way. In fact, it
* should only be used by interface thread.
* This structure has an unique instance, statically allocated in main and
* never accessed from the outside. It store once-initialized data such as
* the CPU capabilities or the global lock.
*****************************************************************************/
struct libvlc_t
{
VLC_COMMON_MEMBERS
/* Initialization boolean */
vlc_bool_t b_ready;
/* CPU extensions */
u32 i_cpu;
/* Object structure data */
int i_counter; /* object counter */
int i_objects; /* Attached objects count */
vlc_object_t ** pp_objects; /* Array of all objects */
/* The big, evil global lock */
vlc_mutex_t global_lock;
void * p_global_data;
/* Locks */
vlc_mutex_t structure_lock; /* lock for the p_vlc tree */
/* The message bank */
msg_bank_t msg_bank;
/* The module bank */
module_bank_t * p_module_bank;
/* Arch-specific variables */
#if defined( SYS_BEOS )
vlc_object_t * p_appthread;
#elif defined( WIN32 )
SIGNALOBJECTANDWAIT SignalObjectAndWait;
vlc_bool_t b_fast_mutex;
int i_win9x_cv;
#endif
};
/*****************************************************************************
* vlc_t, p_vlc
*****************************************************************************
* This structure is a LibVLC instance.
*****************************************************************************/
struct vlc_t
{
......@@ -38,56 +78,31 @@ struct vlc_t
/* The vlc structure status */
int i_status;
int i_instance; /* p_vlc instance # */
/* Global properties */
int i_argc; /* command line arguments count */
char ** ppsz_argv; /* command line arguments */
char * psz_homedir; /* user's home directory */
u32 i_cpu; /* CPU extensions */
/* Generic settings */
vlc_bool_t b_quiet; /* be quiet ? */
vlc_bool_t b_verbose; /* info messages ? */
vlc_bool_t b_color; /* color messages ? */
mtime_t i_desync; /* relative desync of the audio ouput */
/* CPU extensions (inherited from libvlc_t) */
u32 i_cpu;
/* Fast memcpy plugin used */
module_t * p_memcpy_module;
void* ( *pf_memcpy ) ( void *, const void *, size_t );
void* ( *pf_memset ) ( void *, int, size_t );
/* The module bank */
module_bank_t * p_module_bank;
/* The message bank */
msg_bank_t msg_bank;
/* Shared data - these structures are accessed directly from p_vlc by
* several modules */
input_channel_t * p_channel; /* channel library data */
/* Locks */
vlc_mutex_t config_lock; /* lock for the config file */
vlc_mutex_t structure_lock; /* lock for the p_vlc tree */
/* Object structure data */
int i_counter; /* object counter */
int i_objects; /* Attached objects count */
vlc_object_t ** pp_objects; /* Array of all objects */
/* Pointer to the big, evil global lock */
vlc_mutex_t * p_global_lock;
void ** pp_global_data;
/* System-specific variables */
#if defined( SYS_BEOS )
vlc_object_t * p_appthread;
#elif defined( WIN32 )
SIGNALOBJECTANDWAIT SignalObjectAndWait;
vlc_bool_t b_fast_mutex;
int i_win9x_cv;
#endif
};
......@@ -3,7 +3,7 @@
* Collection of useful common types and macros definitions
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: vlc_common.h,v 1.27 2002/09/18 21:21:23 massiot Exp $
* $Id: vlc_common.h,v 1.28 2002/10/03 13:21:54 sam Exp $
*
* Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr>
......@@ -154,6 +154,9 @@ typedef u32 vlc_fourcc_t;
* Classes declaration
*****************************************************************************/
/* Internal types */
typedef struct libvlc_t libvlc_t;
/* Messages */
typedef struct msg_bank_t msg_bank_t;
typedef struct msg_subscription_t msg_subscription_t;
......@@ -273,7 +276,8 @@ typedef struct iso639_lang_t iso639_lang_t;
volatile vlc_bool_t b_dead; /* set by the object */ \
volatile vlc_bool_t b_attached; /* set by the object */ \
\
vlc_t * p_vlc; /* root of all evil */ \
libvlc_t * p_libvlc; /* root of all evil */ \
vlc_t * p_vlc; /* (root of all evil) - 1 */ \
\
volatile int i_refcount; /* usage count */ \
vlc_object_t * p_parent; /* our parent */ \
......
......@@ -2,7 +2,7 @@
* cpu.h: CPU type detection
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: vlc_cpu.h,v 1.3 2002/07/31 20:56:50 sam Exp $
* $Id: vlc_cpu.h,v 1.4 2002/10/03 13:21:54 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -21,6 +21,5 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#define CPUCapabilities(a) __CPUCapabilities(VLC_OBJECT(a))
u32 __CPUCapabilities( vlc_object_t * );
u32 CPUCapabilities( void );
......@@ -2,7 +2,7 @@
* vlc_objects.h: vlc_object_t definition.
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: vlc_objects.h,v 1.10 2002/08/15 12:11:15 sam Exp $
* $Id: vlc_objects.h,v 1.11 2002/10/03 13:21:54 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -23,15 +23,16 @@
/* Object types */
#define VLC_OBJECT_ROOT (-1)
#define VLC_OBJECT_MODULE (-2)
#define VLC_OBJECT_INTF (-3)
#define VLC_OBJECT_PLAYLIST (-4)
#define VLC_OBJECT_ITEM (-5)
#define VLC_OBJECT_INPUT (-6)
#define VLC_OBJECT_DECODER (-7)
#define VLC_OBJECT_VOUT (-8)
#define VLC_OBJECT_AOUT (-9)
#define VLC_OBJECT_SOUT (-10)
#define VLC_OBJECT_VLC (-2)
#define VLC_OBJECT_MODULE (-3)
#define VLC_OBJECT_INTF (-4)
#define VLC_OBJECT_PLAYLIST (-5)
#define VLC_OBJECT_ITEM (-6)
#define VLC_OBJECT_INPUT (-7)
#define VLC_OBJECT_DECODER (-8)
#define VLC_OBJECT_VOUT (-9)
#define VLC_OBJECT_AOUT (-10)
#define VLC_OBJECT_SOUT (-11)
#define VLC_OBJECT_GENERIC (-666)
/* Object search mode */
......
......@@ -2,7 +2,7 @@
* rc.c : remote control stdin/stdout plugin for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: rc.c,v 1.5 2002/09/30 11:05:37 sam Exp $
* $Id: rc.c,v 1.6 2002/10/03 13:21:55 sam Exp $
*
* Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
*
......@@ -181,7 +181,7 @@ static void Run( intf_thread_t *p_intf )
{
p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT,
FIND_ANYWHERE );
//if( p_input )
if( p_input )
{
p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
FIND_PARENT );
......
......@@ -2,7 +2,7 @@
* gtk_main.c : Gtk+ wrapper for gtk_main
*****************************************************************************
* Copyright (C) 2002 VideoLAN
* $Id: gtk_main.c,v 1.6 2002/09/30 11:05:39 sam Exp $
* $Id: gtk_main.c,v 1.7 2002/10/03 13:21:55 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -80,12 +80,12 @@ vlc_module_end();
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
vlc_mutex_lock( p_this->p_vlc->p_global_lock );
vlc_mutex_lock( &p_this->p_libvlc->global_lock );
if( i_refcount > 0 )
{
i_refcount++;
vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
vlc_mutex_unlock( &p_this->p_libvlc->global_lock );
return VLC_SUCCESS;
}
......@@ -105,12 +105,12 @@ static int Open( vlc_object_t *p_this )
{
vlc_object_destroy( p_gtk_main );
i_refcount--;
vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
vlc_mutex_unlock( &p_this->p_libvlc->global_lock );
return VLC_ETHREAD;
}
i_refcount++;
vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
vlc_mutex_unlock( &p_this->p_libvlc->global_lock );
return VLC_SUCCESS;
}
......@@ -120,13 +120,13 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
vlc_mutex_lock( p_this->p_vlc->p_global_lock );
vlc_mutex_lock( &p_this->p_libvlc->global_lock );
i_refcount--;
if( i_refcount > 0 )
{
vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
vlc_mutex_unlock( &p_this->p_libvlc->global_lock );
return;
}
......@@ -136,7 +136,7 @@ static void Close( vlc_object_t *p_this )
vlc_object_destroy( p_gtk_main );
p_gtk_main = NULL;
vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
vlc_mutex_unlock( &p_this->p_libvlc->global_lock );
}
static gint foo(gpointer foo)
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* cpu.c: CPU detection code
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
* $Id: cpu.c,v 1.6 2002/08/19 11:37:57 sam Exp $
* $Id: cpu.c,v 1.7 2002/10/03 13:21:55 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Christophe Massiot <massiot@via.ecp.fr>
......@@ -44,7 +44,6 @@
* Local prototypes
*****************************************************************************/
static void SigHandler ( int );
static u32 Capabilities ( vlc_object_t * );
/*****************************************************************************
* Global variables - they're needed for signal handling
......@@ -58,25 +57,9 @@ static char *psz_capability;
/*****************************************************************************
* CPUCapabilities: get the CPU capabilities
*****************************************************************************
* This function is a wrapper around Capabilities().
*****************************************************************************/
u32 __CPUCapabilities( vlc_object_t *p_this )
{
u32 i_capabilities;
vlc_mutex_lock( p_this->p_vlc->p_global_lock );
i_capabilities = Capabilities( p_this );
vlc_mutex_unlock( p_this->p_vlc->p_global_lock );
return i_capabilities;
}
/*****************************************************************************
* Capabilities: list the processors MMX support and other capabilities
*****************************************************************************
* This function is called to list extensions the CPU may have.
*****************************************************************************/
static u32 Capabilities( vlc_object_t *p_this )
u32 CPUCapabilities( void )
{
volatile u32 i_capabilities = CPU_CAPABILITY_NONE;
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* modules.c : Builtin and plugin modules management functions
*****************************************************************************
* Copyright (C) 2001 VideoLAN
* $Id: modules.c,v 1.93 2002/09/30 11:05:42 sam Exp $
* $Id: modules.c,v 1.94 2002/10/03 13:21:55 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Ethan C. Baldridge <BaldridgeE@cadmus.com>
......@@ -123,8 +123,8 @@ void __module_InitBank( vlc_object_t *p_this )
#endif
/* Everything worked, attach the object */
p_this->p_vlc->p_module_bank = p_bank;
vlc_object_attach( p_bank, p_this->p_vlc );
p_this->p_libvlc->p_module_bank = p_bank;
vlc_object_attach( p_bank, p_this->p_libvlc );
return;
}
......@@ -151,11 +151,11 @@ void __module_EndBank( vlc_object_t *p_this )
{
module_t * p_next;
vlc_object_detach( p_this->p_vlc->p_module_bank );
vlc_object_detach( p_this->p_libvlc->p_module_bank );
while( p_this->p_vlc->p_module_bank->i_children )
while( p_this->p_libvlc->p_module_bank->i_children )
{
p_next = (module_t *)p_this->p_vlc->p_module_bank->pp_children[0];
p_next = (module_t *)p_this->p_libvlc->p_module_bank->pp_children[0];
if( DeleteModule( p_next ) )
{
......@@ -169,7 +169,7 @@ void __module_EndBank( vlc_object_t *p_this )
}
}
vlc_object_destroy( p_this->p_vlc->p_module_bank );
vlc_object_destroy( p_this->p_libvlc->p_module_bank );
return;
}
......@@ -680,7 +680,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file )
/* We need to fill these since they may be needed by CallEntry() */
p_module->psz_filename = psz_file;
p_module->handle = handle;
p_module->p_symbols = &p_this->p_vlc->p_module_bank->symbols;
p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
/* Initialize the module: fill p_module->psz_object_name, default config */
if( CallEntry( p_module ) != 0 )
......@@ -701,7 +701,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file )
/* msg_Dbg( p_this, "plugin \"%s\", %s",
p_module->psz_object_name, p_module->psz_longname ); */
vlc_object_attach( p_module, p_this->p_vlc->p_module_bank );
vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
return 0;
}
......@@ -806,7 +806,7 @@ static int AllocateBuiltinModule( vlc_object_t * p_this,
/* msg_Dbg( p_this, "builtin \"%s\", %s",
p_module->psz_object_name, p_module->psz_longname ); */
vlc_object_attach( p_module, p_this->p_vlc->p_module_bank );
vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
return 0;
}
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* threads.c : threads implementation for the VideoLAN client
*****************************************************************************
* Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
* $Id: threads.c,v 1.17 2002/09/29 18:16:04 sam Exp $
* $Id: threads.c,v 1.18 2002/10/03 13:21:55 sam Exp $
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
......@@ -31,60 +31,17 @@
#define VLC_THREADS_READY 3
/*****************************************************************************
* Prototype for GPROF wrapper
*****************************************************************************/
#ifdef GPROF
/* Wrapper function for profiling */
static void * vlc_thread_wrapper ( void *p_wrapper );
# ifdef WIN32
# define ITIMER_REAL 1
# define ITIMER_PROF 2
struct itimerval
{
struct timeval it_value;
struct timeval it_interval;
};
int setitimer(int kind, const struct itimerval* itnew, struct itimerval* itold);
# endif /* WIN32 */
typedef struct wrapper_t
{
/* Data lock access */
vlc_mutex_t lock;
vlc_cond_t wait;
/* Data used to spawn the real thread */
vlc_thread_func_t func;
void *p_data;
/* Profiling timer passed to the thread */
struct itimerval itimer;
} wrapper_t;
#endif /* GPROF */
/*****************************************************************************
* Global mutexes for lazy initialization of the threads system
* Global mutex for lazy initialization of the threads system
*****************************************************************************/
static volatile int i_initializations = 0;
#if defined( PTH_INIT_IN_PTH_H )
/* Unimplemented */
#elif defined( ST_INIT_IN_ST_H )
/* Unimplemented */
#elif defined( WIN32 )
/* Unimplemented */
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
static pthread_mutex_t once_mutex = PTHREAD_MUTEX_INITIALIZER;
#elif defined( HAVE_CTHREADS_H )
/* Unimplemented */
#elif defined( HAVE_KERNEL_SCHEDULER_H )
/* Unimplemented */
#endif
/*****************************************************************************
......@@ -97,98 +54,102 @@ static volatile int i_initializations = 0;
int __vlc_threads_init( vlc_object_t *p_this )
{
static volatile int i_status = VLC_THREADS_UNINITIALIZED;
int i_ret = 0;
libvlc_t *p_libvlc = (libvlc_t *)p_this;
int i_ret = VLC_SUCCESS;
/* If we have lazy mutex initialization, use it. Otherwise, we just
* hope nothing wrong happens. */
#if defined( PTH_INIT_IN_PTH_H )
/* Unimplemented */
#elif defined( ST_INIT_IN_ST_H )
/* Unimplemented */
#elif defined( WIN32 )
HINSTANCE hInstLib;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
pthread_mutex_lock( &once_mutex );
#elif defined( HAVE_CTHREADS_H )
/* Unimplemented */
#elif defined( HAVE_KERNEL_SCHEDULER_H )
/* Unimplemented */
#endif
if( i_status == VLC_THREADS_UNINITIALIZED )
{
i_status = VLC_THREADS_PENDING;
/* We should be safe now. Do all the initialization stuff we want. */
vlc_object_create( p_libvlc, VLC_OBJECT_ROOT );
p_libvlc->b_ready = VLC_FALSE;
#if defined( PTH_INIT_IN_PTH_H )
i_ret = pth_init();
#elif defined( ST_INIT_IN_ST_H )
i_ret = st_init();
#elif defined( WIN32 )
/* dynamically get the address of SignalObjectAndWait */
/* Dynamically get the address of SignalObjectAndWait */
if( GetVersion() < 0x80000000 )
{
/* We are running on NT/2K/XP, we can use SignalObjectAndWait */
hInstLib = LoadLibrary( "kernel32" );
if( hInstLib )
{
p_this->p_vlc->SignalObjectAndWait =
p_libvlc->SignalObjectAndWait =
(SIGNALOBJECTANDWAIT)GetProcAddress( hInstLib,
"SignalObjectAndWait" );
}
}
else
{
p_this->p_vlc->SignalObjectAndWait = NULL;
p_libvlc->SignalObjectAndWait = NULL;
}
p_this->p_vlc->b_fast_mutex = 0;
p_this->p_vlc->i_win9x_cv = 0;
p_libvlc->b_fast_mutex = 0;
p_libvlc->i_win9x_cv = 0;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
/* Unimplemented */
#elif defined( HAVE_CTHREADS_H )
/* Unimplemented */
#elif defined( HAVE_KERNEL_SCHEDULER_H )
/* Unimplemented */
#endif
vlc_mutex_init( p_libvlc, &p_libvlc->global_lock );
if( i_ret )
{
i_status = VLC_THREADS_ERROR;
}
else
{
vlc_mutex_init( p_this, p_this->p_vlc->p_global_lock );
i_initializations++;
i_status = VLC_THREADS_READY;
}
}
else
{
i_ret = ( i_status == VLC_THREADS_READY );
/* Just increment the initialization count */
i_initializations++;
}
i_initializations++;
/* If we have lazy mutex initialization support, unlock the mutex;
* otherwize, do a naive wait loop. */
#if defined( PTH_INIT_IN_PTH_H )
/* Unimplemented */
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( ST_INIT_IN_ST_H )
/* Unimplemented */
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( WIN32 )
/* Unimplemented */
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
pthread_mutex_unlock( &once_mutex );
return i_ret;
#elif defined( HAVE_CTHREADS_H )
/* Unimplemented */
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#elif defined( HAVE_KERNEL_SCHEDULER_H )
/* Unimplemented */
while( i_status == VLC_THREADS_PENDING ) msleep( THREAD_SLEEP );
#endif
/* Wait until the other thread has initialized the thread library */
while( i_status == VLC_THREADS_PENDING )
if( i_status != VLC_THREADS_READY )
{
msleep( THREAD_SLEEP );
return VLC_ETHREAD;
}
return i_status == VLC_THREADS_READY;
return i_ret;
}
/*****************************************************************************
......@@ -205,33 +166,66 @@ int __vlc_threads_end( vlc_object_t *p_this )
{
return pth_kill();
}
return 0;
#elif defined( ST_INIT_IN_ST_H )
i_initializations--;
return 0;
#elif defined( WIN32 )
i_initializations--;
return 0;
#elif defined( PTHREAD_COND_T_IN_PTHREAD_H )
pthread_mutex_lock( &once_mutex );
i_initializations--;
pthread_mutex_unlock( &once_mutex );
return 0;
#elif defined( HAVE_CTHREADS_H )
i_initializations--;
return 0;
#elif defined( HAVE_KERNEL_SCHEDULER_H )
i_initializations--;
return 0;
#endif
return VLC_SUCCESS;
}
/*****************************************************************************
* Prototype for GPROF wrapper
*****************************************************************************/
#ifdef GPROF
/* Wrapper function for profiling */
static void * vlc_thread_wrapper ( void *p_wrapper );
# ifdef WIN32
# define ITIMER_REAL 1
# define ITIMER_PROF 2
struct itimerval
{
struct timeval it_value;
struct timeval it_interval;
};
int setitimer(int kind, const struct itimerval* itnew, struct itimerval* itold);
# endif /* WIN32 */
typedef struct wrapper_t
{
/* Data lock access */
vlc_mutex_t lock;
vlc_cond_t wait;
/* Data used to spawn the real thread */
vlc_thread_func_t func;
void *p_data;
/* Profiling timer passed to the thread */
struct itimerval itimer;
} wrapper_t;
#endif /* GPROF */
/*****************************************************************************
* vlc_mutex_init: initialize a mutex
*****************************************************************************/
......
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