Commit a3fee044 authored by Sébastien Escudier's avatar Sébastien Escudier Committed by Rémi Denis-Courmont

libvlc_vlm_release : release events stuff Centralize vlm release operations in...

libvlc_vlm_release : release events stuff Centralize vlm release operations in one new function : libvlc_vlm_release_internal
Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent 8bd3fb71
...@@ -139,8 +139,9 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv, ...@@ -139,8 +139,9 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv,
} }
p_new->p_libvlc_int = p_libvlc_int; p_new->p_libvlc_int = p_libvlc_int;
p_new->p_vlm = NULL; p_new->libvlc_vlm.p_vlm = NULL;
p_new->p_event_manager = NULL; p_new->libvlc_vlm.p_event_manager = NULL;
p_new->libvlc_vlm.pf_release = NULL;
p_new->b_playlist_locked = 0; p_new->b_playlist_locked = 0;
p_new->ref_count = 1; p_new->ref_count = 1;
p_new->verbosity = 1; p_new->verbosity = 1;
...@@ -175,10 +176,8 @@ void libvlc_release( libvlc_instance_t *p_instance ) ...@@ -175,10 +176,8 @@ void libvlc_release( libvlc_instance_t *p_instance )
{ {
vlc_mutex_destroy( lock ); vlc_mutex_destroy( lock );
vlc_mutex_destroy( &p_instance->event_callback_lock ); vlc_mutex_destroy( &p_instance->event_callback_lock );
if( p_instance->p_event_manager ) if( p_instance->libvlc_vlm.pf_release )
libvlc_event_manager_release( p_instance->p_event_manager ); p_instance->libvlc_vlm.pf_release( p_instance );
if( p_instance->p_vlm )
vlm_Delete( p_instance->p_vlm );
libvlc_InternalCleanup( p_instance->p_libvlc_int ); libvlc_InternalCleanup( p_instance->p_libvlc_int );
libvlc_InternalDestroy( p_instance->p_libvlc_int ); libvlc_InternalDestroy( p_instance->p_libvlc_int );
free( p_instance ); free( p_instance );
......
...@@ -47,6 +47,8 @@ VLC_EXPORT (void, libvlc_InternalDestroy, ( libvlc_int_t * ) ); ...@@ -47,6 +47,8 @@ VLC_EXPORT (void, libvlc_InternalDestroy, ( libvlc_int_t * ) );
VLC_EXPORT (int, libvlc_InternalAddIntf, ( libvlc_int_t *, const char * ) ); VLC_EXPORT (int, libvlc_InternalAddIntf, ( libvlc_int_t *, const char * ) );
VLC_EXPORT (void, libvlc_InternalWait, ( libvlc_int_t * ) ); VLC_EXPORT (void, libvlc_InternalWait, ( libvlc_int_t * ) );
typedef void (*libvlc_vlm_release_func_t)( libvlc_instance_t * ) ;
/*************************************************************************** /***************************************************************************
* Opaque structures for libvlc API * Opaque structures for libvlc API
***************************************************************************/ ***************************************************************************/
...@@ -57,11 +59,17 @@ typedef enum libvlc_lock_state_t ...@@ -57,11 +59,17 @@ typedef enum libvlc_lock_state_t
libvlc_UnLocked libvlc_UnLocked
} libvlc_lock_state_t; } libvlc_lock_state_t;
typedef struct libvlc_vlm_t
{
vlm_t *p_vlm;
libvlc_event_manager_t *p_event_manager;
libvlc_vlm_release_func_t pf_release;
} libvlc_vlm_t;
struct libvlc_instance_t struct libvlc_instance_t
{ {
libvlc_int_t *p_libvlc_int; libvlc_int_t *p_libvlc_int;
vlm_t *p_vlm; libvlc_vlm_t libvlc_vlm;
libvlc_event_manager_t *p_event_manager;
int b_playlist_locked; int b_playlist_locked;
unsigned ref_count; unsigned ref_count;
int verbosity; int verbosity;
......
...@@ -76,7 +76,7 @@ char* libvlc_vlm_show_media( libvlc_instance_t *p_instance, char *psz_name, ...@@ -76,7 +76,7 @@ char* libvlc_vlm_show_media( libvlc_instance_t *p_instance, char *psz_name,
CHECK_VLM; CHECK_VLM;
asprintf( &psz_message, "show %s", psz_name ); asprintf( &psz_message, "show %s", psz_name );
asprintf( &psz_response, "", psz_name ); asprintf( &psz_response, "", psz_name );
vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer ); vlm_ExecuteCommand( p_instance->libvlc_vlm.p_vlm, psz_message, &answer );
if( answer->psz_value ) if( answer->psz_value )
{ {
libvlc_exception_raise( p_exception, "Unable to call show %s: %s", libvlc_exception_raise( p_exception, "Unable to call show %s: %s",
...@@ -113,6 +113,10 @@ static int VlmEvent( vlc_object_t *p_this, const char * name, ...@@ -113,6 +113,10 @@ static int VlmEvent( vlc_object_t *p_this, const char * name,
libvlc_event_manager_t *p_event_manager = (libvlc_event_manager_t *) param; libvlc_event_manager_t *p_event_manager = (libvlc_event_manager_t *) param;
libvlc_event_t libvlc_event; libvlc_event_t libvlc_event;
VLC_UNUSED( p_this );
VLC_UNUSED( name );
VLC_UNUSED( old_val );
libvlc_event.u.vlm_media_event.psz_media_name = event->psz_name; libvlc_event.u.vlm_media_event.psz_media_name = event->psz_name;
switch( event->i_type ) switch( event->i_type )
...@@ -137,43 +141,69 @@ static int VlmEvent( vlc_object_t *p_this, const char * name, ...@@ -137,43 +141,69 @@ static int VlmEvent( vlc_object_t *p_this, const char * name,
return 0; return 0;
} }
static void libvlc_vlm_release_internal( libvlc_instance_t *p_instance )
{
vlm_t *p_vlm = p_instance->libvlc_vlm.p_vlm;
if( !p_instance->libvlc_vlm.p_vlm )
return;
/* We need to remove medias in order to receive events */
vlm_Control( p_vlm, VLM_CLEAR_MEDIAS );
vlm_Control( p_vlm, VLM_CLEAR_SCHEDULES );
var_DelCallback( (vlc_object_t *)p_vlm, "intf-event", VlmEvent,
p_instance->libvlc_vlm.p_event_manager );
p_instance->libvlc_vlm.pf_release = NULL;
libvlc_event_manager_release( p_instance->libvlc_vlm.p_event_manager );
p_instance->libvlc_vlm.p_event_manager = NULL;
vlm_Delete( p_vlm );
p_instance->libvlc_vlm.p_vlm = NULL;
}
static int libvlc_vlm_init( libvlc_instance_t *p_instance, static int libvlc_vlm_init( libvlc_instance_t *p_instance,
libvlc_exception_t *p_exception ) libvlc_exception_t *p_exception )
{ {
if( !p_instance->p_event_manager ) if( !p_instance->libvlc_vlm.p_event_manager )
{ {
p_instance->p_event_manager = libvlc_event_manager_new( p_instance->p_vlm, p_instance->libvlc_vlm.p_event_manager = libvlc_event_manager_new( p_instance->libvlc_vlm.p_vlm,
p_instance, p_exception ); p_instance, p_exception );
libvlc_event_manager_register_event_type( p_instance->p_event_manager, libvlc_event_manager_register_event_type( p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaAdded, NULL ); libvlc_VlmMediaAdded, NULL );
libvlc_event_manager_register_event_type( p_instance->p_event_manager, libvlc_event_manager_register_event_type( p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaRemoved, NULL ); libvlc_VlmMediaRemoved, NULL );
libvlc_event_manager_register_event_type( p_instance->p_event_manager, libvlc_event_manager_register_event_type( p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaChanged, NULL ); libvlc_VlmMediaChanged, NULL );
libvlc_event_manager_register_event_type( p_instance->p_event_manager, libvlc_event_manager_register_event_type( p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStarted, NULL ); libvlc_VlmMediaInstanceStarted, NULL );
libvlc_event_manager_register_event_type( p_instance->p_event_manager, libvlc_event_manager_register_event_type( p_instance->libvlc_vlm.p_event_manager,
libvlc_VlmMediaInstanceStopped, NULL ); libvlc_VlmMediaInstanceStopped, NULL );
} }
if( !p_instance->p_vlm ) if( !p_instance->libvlc_vlm.p_vlm )
{ {
p_instance->p_vlm = vlm_New( p_instance->p_libvlc_int ); p_instance->libvlc_vlm.p_vlm = vlm_New( p_instance->p_libvlc_int );
if( !p_instance->p_vlm ) if( !p_instance->libvlc_vlm.p_vlm )
{ {
libvlc_exception_raise( p_exception, libvlc_exception_raise( p_exception,
"Unable to create VLM." ); "Unable to create VLM." );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
var_AddCallback( (vlc_object_t *)p_instance->p_vlm, "intf-event", VlmEvent, var_AddCallback( (vlc_object_t *)p_instance->libvlc_vlm.p_vlm, "intf-event", VlmEvent,
p_instance->p_event_manager ); p_instance->libvlc_vlm.p_event_manager );
p_instance->libvlc_vlm.pf_release = libvlc_vlm_release_internal;
} }
return VLC_SUCCESS; return VLC_SUCCESS;
} }
void libvlc_vlm_release( libvlc_instance_t *p_instance,
libvlc_exception_t *p_exception)
{
libvlc_vlm_release_internal( p_instance );
}
#define VLM_RET(p,ret) do { \ #define VLM_RET(p,ret) do { \
if( libvlc_vlm_init( p_instance, p_exception ) ) return ret;\ if( libvlc_vlm_init( p_instance, p_exception ) ) return ret;\
(p) = p_instance->p_vlm; \ (p) = p_instance->libvlc_vlm.p_vlm; \
} while(0) } while(0)
#define VLM(p) VLM_RET(p,) #define VLM(p) VLM_RET(p,)
...@@ -210,18 +240,6 @@ libvlc_vlm_get_media_instance( libvlc_instance_t *p_instance, ...@@ -210,18 +240,6 @@ libvlc_vlm_get_media_instance( libvlc_instance_t *p_instance,
return p_minstance; return p_minstance;
} }
void libvlc_vlm_release( libvlc_instance_t *p_instance,
libvlc_exception_t *p_exception)
{
vlm_t *p_vlm;
VLM(p_vlm);
vlm_Delete( p_vlm );
p_instance->p_vlm = NULL;
}
void libvlc_vlm_add_broadcast( libvlc_instance_t *p_instance, void libvlc_vlm_add_broadcast( libvlc_instance_t *p_instance,
const char *psz_name, const char *psz_name,
const char *psz_input, const char *psz_input,
...@@ -588,5 +606,5 @@ libvlc_event_manager_t * libvlc_vlm_get_event_manager( libvlc_instance_t *p_inst ...@@ -588,5 +606,5 @@ libvlc_event_manager_t * libvlc_vlm_get_event_manager( libvlc_instance_t *p_inst
{ {
vlm_t *p_vlm; vlm_t *p_vlm;
VLM_RET( p_vlm, NULL); VLM_RET( p_vlm, NULL);
return p_instance->p_event_manager; return p_instance->libvlc_vlm.p_event_manager;
} }
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