Commit 121930fe authored by Clément Stenac's avatar Clément Stenac

Use a separate message bank for each libvlc instance

Fix compilation for libvlc users
parent 3d5f0231
......@@ -755,7 +755,7 @@ HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
_p_libvlc = NULL;
vlcDataObject->onClose();
libvlc_destroy(p_libvlc);
libvlc_destroy(p_libvlc, NULL );
}
return S_OK;
};
......
......@@ -83,7 +83,7 @@ JNIEXPORT void JNICALL Java_org_videolan_jvlc_JVLC__1destroy (JNIEnv *env, jobje
instance = getClassInstance( env, _this );
libvlc_destroy( (libvlc_instance_t *) instance);
libvlc_destroy( (libvlc_instance_t *) instance, NULL );
return;
}
......
......@@ -36,16 +36,11 @@ struct libvlc_global_data_t
vlc_bool_t b_ready; ///< Initialization boolean
uint32_t i_cpu; ///< CPU extensions
int i_verbose; ///< info messages
vlc_bool_t b_color; ///< color messages?
/* Object structure data */
/* Object structure data */
int i_counter; ///< object counter
int i_objects; ///< Attached objects count
vlc_object_t ** pp_objects; ///< Array of all objects
msg_bank_t msg_bank; ///< The message bank
module_bank_t * p_module_bank; ///< The module bank
intf_thread_t *p_probe; ///< Devices prober
......@@ -88,6 +83,11 @@ struct libvlc_int_t
playlist_t *p_playlist; ///< playlist object
/* Messages */
msg_bank_t msg_bank; ///< The message bank
int i_verbose; ///< info messages
vlc_bool_t b_color; ///< color messages?
module_t * p_memcpy_module; ///< Fast memcpy plugin used
void* ( *pf_memcpy ) ( void *, const void *, size_t ); ///< fast memcpy
void* ( *pf_memset ) ( void *, int, size_t ); ///< fast memset
......
......@@ -265,7 +265,7 @@ VlcPlugin::~VlcPlugin()
delete psz_baseURL;
delete psz_target;
if( libvlc_instance )
libvlc_destroy(libvlc_instance);
libvlc_destroy(libvlc_instance, NULL );
}
/*****************************************************************************
......
......@@ -145,6 +145,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
int i_ret;
libvlc_int_t * p_libvlc = NULL;
vlc_value_t lockval;
char *psz_env;
/* &libvlc_global never changes,
* so we can safely call this multiple times. */
......@@ -165,30 +166,9 @@ libvlc_int_t * libvlc_InternalCreate( void )
if( !libvlc_global.b_ready )
{
char *psz_env;
/* Guess what CPU we have */
libvlc_global.i_cpu = CPUCapabilities();
/* Find verbosity from VLC_VERBOSE environment variable */
psz_env = getenv( "VLC_VERBOSE" );
libvlc_global.i_verbose = psz_env ? atoi( psz_env ) : -1;
#if defined( HAVE_ISATTY ) && !defined( WIN32 )
libvlc_global.b_color = isatty( 2 ); /* 2 is for stderr */
#else
libvlc_global.b_color = VLC_FALSE;
#endif
/* Initialize message queue */
msg_Create( p_libvlc_global );
/* Announce who we are */
msg_Dbg( p_libvlc_global, COPYRIGHT_MESSAGE );
msg_Dbg( p_libvlc_global, "libvlc was configured with %s",
CONFIGURE_LINE );
/* The module bank will be initialized later */
/* The module bank will be initialized later */
libvlc_global.p_module_bank = NULL;
libvlc_global.b_ready = VLC_TRUE;
......@@ -203,6 +183,22 @@ libvlc_int_t * libvlc_InternalCreate( void )
p_libvlc->p_playlist = NULL;
p_libvlc->psz_object_name = "libvlc";
/* Initialize message queue */
msg_Create( p_libvlc );
/* Announce who we are - Do it only for first instance ? */
msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
/* Find verbosity from VLC_VERBOSE environment variable */
psz_env = getenv( "VLC_VERBOSE" );
p_libvlc->i_verbose = psz_env ? atoi( psz_env ) : -1;
#if defined( HAVE_ISATTY ) && !defined( WIN32 )
p_libvlc->b_color = isatty( 2 ); /* 2 is for stderr */
#else
p_libvlc->b_color = VLC_FALSE;
#endif
/* Initialize mutexes */
vlc_mutex_init( p_libvlc, &p_libvlc->config_lock );
#ifdef __APPLE__
......@@ -350,7 +346,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
/* End hack */
/* Will be re-done properly later on */
p_libvlc->p_libvlc_global->i_verbose = config_GetInt( p_libvlc, "verbose" );
p_libvlc->i_verbose = config_GetInt( p_libvlc, "verbose" );
/* Check for daemon mode */
#ifndef WIN32
......@@ -586,8 +582,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, char *ppsz_argv[] )
var_AddCallback( p_libvlc, "verbose", VerboseCallback, NULL );
var_Change( p_libvlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
libvlc_global.b_color = libvlc_global.b_color &&
config_GetInt( p_libvlc, "color" );
p_libvlc->b_color = p_libvlc->b_color && config_GetInt( p_libvlc, "color" );
/*
* Output messages that may still be in the queue
......@@ -898,16 +893,15 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc, vlc_bool_t b_release )
/* System specific cleaning code */
system_End( p_libvlc );
/* Free message queue. Nobody shall use msg_* afterward. */
msg_Flush( p_libvlc );
msg_Destroy( p_libvlc_global );
/* Destroy global iconv */
/* Destroy global iconv */
LocaleDeinit();
}
vlc_mutex_unlock( lockval.p_address );
var_Destroy( p_libvlc_global, "libvlc" );
msg_Flush( p_libvlc );
msg_Destroy( p_libvlc );
/* Destroy mutexes */
vlc_mutex_destroy( &p_libvlc->config_lock );
......@@ -1560,11 +1554,11 @@ static int ConsoleWidth( void )
static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param)
{
libvlc_int_t *p_vlc = (libvlc_int_t *)p_this;
libvlc_int_t *p_libvlc = (libvlc_int_t *)p_this;
if( new_val.i_int >= -1 )
{
p_vlc->p_libvlc_global->i_verbose = __MIN( new_val.i_int, 2 );
p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
}
return VLC_SUCCESS;
}
......
......@@ -60,6 +60,8 @@
# define vlc_va_copy(dest,src) (dest)=(src)
#endif
#define QUEUE(i) p_this->p_libvlc->msg_bank.pp_queues[i]
/*****************************************************************************
* Local prototypes
*****************************************************************************/
......@@ -75,18 +77,17 @@ static void CreateMsgQueue( vlc_object_t *p_this, int i_queue );
*/
void __msg_Create( vlc_object_t *p_this )
{
vlc_mutex_init( p_this, &(p_this->p_libvlc_global->msg_bank.lock) );
vlc_mutex_init( p_this, &(p_this->p_libvlc->msg_bank.lock) );
CreateMsgQueue( p_this, MSG_QUEUE_NORMAL );
CreateMsgQueue( p_this, MSG_QUEUE_HTTPD_ACCESS );
#ifdef UNDER_CE
p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile =
QUEUE(MSG_QUEUE_NORMAL)->logfile =
CreateFile( L"vlc-log.txt", GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
CREATE_ALWAYS, 0, NULL );
SetFilePointer( p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->
logfile, 0, NULL, FILE_END );
SetFilePointer( QUEUE(MSG_QUEUE_NORMAL)->logfile, 0, NULL, FILE_END );
#endif
}
......@@ -105,8 +106,8 @@ static void CreateMsgQueue( vlc_object_t *p_this, int i_queue )
p_queue->i_sub = 0;
p_queue->pp_sub = NULL;
INSERT_ELEM( p_this->p_libvlc_global->msg_bank.pp_queues,
p_this->p_libvlc_global->msg_bank.i_queues,
INSERT_ELEM( p_this->p_libvlc->msg_bank.pp_queues,
p_this->p_libvlc->msg_bank.i_queues,
i_queue,
p_queue );
}
......@@ -118,11 +119,11 @@ void __msg_Flush( vlc_object_t *p_this )
{
int i;
for( i = 0 ; i < p_this->p_libvlc_global->msg_bank.i_queues; i++ )
for( i = 0 ; i < p_this->p_libvlc->msg_bank.i_queues; i++ )
{
vlc_mutex_lock( &p_this->p_libvlc_global->msg_bank.pp_queues[i]->lock );
FlushMsg( p_this->p_libvlc_global->msg_bank.pp_queues[i] );
vlc_mutex_unlock( &p_this->p_libvlc_global->msg_bank.pp_queues[i]->lock );
vlc_mutex_lock( &QUEUE(i)->lock );
FlushMsg( QUEUE(i) );
vlc_mutex_unlock( &QUEUE(i)->lock );
}
}
......@@ -136,9 +137,9 @@ void __msg_Flush( vlc_object_t *p_this )
void __msg_Destroy( vlc_object_t *p_this )
{
int i;
for( i = p_this->p_libvlc_global->msg_bank.i_queues -1 ; i >= 0; i-- )
for( i = p_this->p_libvlc->msg_bank.i_queues -1 ; i >= 0; i-- )
{
msg_queue_t *p_queue = p_this->p_libvlc_global->msg_bank.pp_queues[i];
msg_queue_t *p_queue = QUEUE(i);
if( p_queue->i_sub )
{
msg_Err( p_this, "stale interface subscribers" );
......@@ -147,15 +148,15 @@ void __msg_Destroy( vlc_object_t *p_this )
#ifdef UNDER_CE
if( i == MSG_QUEUE_NORMAL )
CloseHandle( p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
CloseHandle( QUEUE(MSG_QUEUE_NORMAL)->logfile );
#endif
/* Destroy lock */
vlc_mutex_destroy( &p_queue->lock );
REMOVE_ELEM( p_this->p_libvlc_global->msg_bank.pp_queues,
p_this->p_libvlc_global->msg_bank.i_queues, i );
REMOVE_ELEM( p_this->p_libvlc->msg_bank.pp_queues,
p_this->p_libvlc->msg_bank.i_queues, i );
free( p_queue );
}
vlc_mutex_destroy( &(p_this->p_libvlc_global->msg_bank.lock) );
vlc_mutex_destroy( &(p_this->p_libvlc->msg_bank.lock) );
}
/**
......@@ -163,7 +164,7 @@ void __msg_Destroy( vlc_object_t *p_this )
*/
msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i_queue )
{
msg_bank_t *p_bank = &p_this->p_libvlc_global->msg_bank;
msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
msg_subscription_t *p_sub = malloc( sizeof( msg_subscription_t ) );
msg_queue_t *p_queue = NULL;
int i;
......@@ -172,7 +173,7 @@ msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i_queue )
for( i = 0 ; i <p_bank->i_queues ;i++ )
{
if( p_bank->pp_queues[i]->i_id == i_queue )
if( QUEUE(i)->i_id == i_queue )
{
p_queue = p_bank->pp_queues[i];
}
......@@ -209,7 +210,7 @@ msg_subscription_t *__msg_Subscribe( vlc_object_t *p_this, int i_queue )
*/
void __msg_Unsubscribe( vlc_object_t *p_this, msg_subscription_t *p_sub )
{
msg_bank_t *p_bank = &p_this->p_libvlc_global->msg_bank;
msg_bank_t *p_bank = &p_this->p_libvlc->msg_bank;
int i,j;
vlc_mutex_lock( &p_bank->lock );
......@@ -319,7 +320,7 @@ static void QueueMsg( vlc_object_t *p_this, int i_queue_id, int i_type,
return;
}
p_bank = &p_this->p_libvlc_global->msg_bank;
p_bank = &p_this->p_libvlc->msg_bank;
/*
* Convert message to string
......@@ -547,16 +548,16 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
switch( i_type )
{
case VLC_MSG_ERR:
if( p_this->p_libvlc_global->i_verbose < 0 ) return;
if( p_this->p_libvlc->i_verbose < 0 ) return;
break;
case VLC_MSG_INFO:
if( p_this->p_libvlc_global->i_verbose < 0 ) return;
if( p_this->p_libvlc->i_verbose < 0 ) return;
break;
case VLC_MSG_WARN:
if( p_this->p_libvlc_global->i_verbose < 1 ) return;
if( p_this->p_libvlc->i_verbose < 1 ) return;
break;
case VLC_MSG_DBG:
if( p_this->p_libvlc_global->i_verbose < 2 ) return;
if( p_this->p_libvlc->i_verbose < 2 ) return;
break;
}
......@@ -585,7 +586,7 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
}
#ifdef UNDER_CE
# define CE_WRITE(str) WriteFile( p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile, \
# define CE_WRITE(str) WriteFile( QUEUE(MSG_QUEUE_NORMAL)->logfile, \
str, strlen(str), &i_dummy, NULL );
CE_WRITE( p_item->psz_module );
CE_WRITE( " " );
......@@ -594,11 +595,11 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
CE_WRITE( ": " );
CE_WRITE( p_item->psz_msg );
CE_WRITE( "\r\n" );
FlushFileBuffers( p_this->p_libvlc_global->msg_bank.pp_queues[MSG_QUEUE_NORMAL]->logfile );
FlushFileBuffers( QUEUE(MSG_QUEUE_NORMAL)->logfile );
#else
/* Send the message to stderr */
if( p_this->p_libvlc_global->b_color )
if( p_this->p_libvlc->b_color )
{
if( p_item->psz_header )
{
......
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