Commit 5ede6b91 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

lib: vlm: do not allocate inside the instance

parent 9f7f6743
...@@ -63,9 +63,7 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv ) ...@@ -63,9 +63,7 @@ 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->libvlc_vlm.p_vlm = NULL; p_new->vlm = NULL;
p_new->libvlc_vlm.p_event_manager = NULL;
p_new->libvlc_vlm.pf_release = NULL;
p_new->ref_count = 1; p_new->ref_count = 1;
p_new->p_callback_list = NULL; p_new->p_callback_list = NULL;
vlc_mutex_init(&p_new->instance_lock); vlc_mutex_init(&p_new->instance_lock);
...@@ -100,8 +98,8 @@ void libvlc_release( libvlc_instance_t *p_instance ) ...@@ -100,8 +98,8 @@ void libvlc_release( libvlc_instance_t *p_instance )
if( refs == 0 ) if( refs == 0 )
{ {
vlc_mutex_destroy( lock ); vlc_mutex_destroy( lock );
if( p_instance->libvlc_vlm.pf_release ) if( p_instance->vlm != NULL )
p_instance->libvlc_vlm.pf_release( p_instance ); libvlc_vlm_release( p_instance );
libvlc_Quit( p_instance->p_libvlc_int ); libvlc_Quit( p_instance->p_libvlc_int );
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 );
......
...@@ -53,8 +53,6 @@ VLC_API void libvlc_InternalPlay( libvlc_int_t * ); ...@@ -53,8 +53,6 @@ VLC_API void libvlc_InternalPlay( libvlc_int_t * );
VLC_API void libvlc_InternalWait( libvlc_int_t * ); VLC_API void libvlc_InternalWait( libvlc_int_t * );
VLC_API void libvlc_SetExitHandler( libvlc_int_t *, void (*) (void *), void * ); VLC_API void libvlc_SetExitHandler( libvlc_int_t *, void (*) (void *), void * );
typedef void (*libvlc_vlm_release_func_t)( libvlc_instance_t * ) ;
/*************************************************************************** /***************************************************************************
* Opaque structures for libvlc API * Opaque structures for libvlc API
***************************************************************************/ ***************************************************************************/
...@@ -63,13 +61,12 @@ typedef struct libvlc_vlm_t ...@@ -63,13 +61,12 @@ typedef struct libvlc_vlm_t
{ {
vlm_t *p_vlm; vlm_t *p_vlm;
libvlc_event_manager_t *p_event_manager; libvlc_event_manager_t *p_event_manager;
libvlc_vlm_release_func_t pf_release;
} libvlc_vlm_t; } libvlc_vlm_t;
struct libvlc_instance_t struct libvlc_instance_t
{ {
libvlc_int_t *p_libvlc_int; libvlc_int_t *p_libvlc_int;
libvlc_vlm_t libvlc_vlm; libvlc_vlm_t *vlm;
unsigned ref_count; unsigned ref_count;
vlc_mutex_t instance_lock; vlc_mutex_t instance_lock;
struct libvlc_callback_entry_list_t *p_callback_list; struct libvlc_callback_entry_list_t *p_callback_list;
......
...@@ -103,45 +103,53 @@ static int VlmEvent( vlc_object_t *p_this, const char * name, ...@@ -103,45 +103,53 @@ static int VlmEvent( vlc_object_t *p_this, const char * name,
void libvlc_vlm_release( libvlc_instance_t *p_instance ) void libvlc_vlm_release( libvlc_instance_t *p_instance )
{ {
vlm_t *p_vlm = p_instance->libvlc_vlm.p_vlm; vlm_t *p_vlm = p_instance->vlm->p_vlm;
if( !p_instance->libvlc_vlm.p_vlm ) if( !p_vlm )
return; return;
/* We need to remove medias in order to receive events */ /* We need to remove medias in order to receive events */
vlm_Control( p_vlm, VLM_CLEAR_MEDIAS ); vlm_Control( p_vlm, VLM_CLEAR_MEDIAS );
vlm_Control( p_vlm, VLM_CLEAR_SCHEDULES ); vlm_Control( p_vlm, VLM_CLEAR_SCHEDULES );
var_DelCallback( (vlc_object_t *)p_vlm, "intf-event", VlmEvent, var_DelCallback( (vlc_object_t *)p_vlm, "intf-event", VlmEvent,
p_instance->libvlc_vlm.p_event_manager ); p_instance->vlm->p_event_manager );
p_instance->libvlc_vlm.pf_release = NULL; libvlc_event_manager_release( p_instance->vlm->p_event_manager );
libvlc_event_manager_release( p_instance->libvlc_vlm.p_event_manager ); p_instance->vlm->p_event_manager = NULL;
p_instance->libvlc_vlm.p_event_manager = NULL;
vlm_Delete( p_vlm ); vlm_Delete( p_vlm );
p_instance->libvlc_vlm.p_vlm = NULL; free( p_instance->vlm );
p_instance->vlm = NULL;
libvlc_release( p_instance ); libvlc_release( p_instance );
} }
static int libvlc_vlm_init( libvlc_instance_t *p_instance ) static int libvlc_vlm_init( libvlc_instance_t *p_instance )
{ {
if( !p_instance->libvlc_vlm.p_event_manager ) if( !p_instance->vlm )
{ {
p_instance->libvlc_vlm.p_event_manager = p_instance->vlm = malloc( sizeof(*p_instance->vlm) );
libvlc_event_manager_new( p_instance->libvlc_vlm.p_vlm ); if( p_instance->vlm == NULL )
if( unlikely(p_instance->libvlc_vlm.p_event_manager == NULL) )
return VLC_ENOMEM; return VLC_ENOMEM;
p_instance->vlm->p_vlm = NULL;
p_instance->vlm->p_event_manager = NULL;
} }
if( !p_instance->libvlc_vlm.p_vlm ) if( !p_instance->vlm->p_event_manager )
{ {
p_instance->libvlc_vlm.p_vlm = vlm_New( p_instance->p_libvlc_int ); p_instance->vlm->p_event_manager =
if( !p_instance->libvlc_vlm.p_vlm ) libvlc_event_manager_new( p_instance->vlm->p_vlm );
if( unlikely(p_instance->vlm->p_event_manager == NULL) )
return VLC_ENOMEM;
}
if( !p_instance->vlm->p_vlm )
{
p_instance->vlm->p_vlm = vlm_New( p_instance->p_libvlc_int );
if( !p_instance->vlm->p_vlm )
{ {
libvlc_printerr( "VLM not supported or out of memory" ); libvlc_printerr( "VLM not supported or out of memory" );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
var_AddCallback( (vlc_object_t *)p_instance->libvlc_vlm.p_vlm, var_AddCallback( (vlc_object_t *)p_instance->vlm->p_vlm,
"intf-event", VlmEvent, "intf-event", VlmEvent,
p_instance->libvlc_vlm.p_event_manager ); p_instance->vlm->p_event_manager );
p_instance->libvlc_vlm.pf_release = libvlc_vlm_release;
libvlc_retain( p_instance ); libvlc_retain( p_instance );
} }
...@@ -151,7 +159,7 @@ static int libvlc_vlm_init( libvlc_instance_t *p_instance ) ...@@ -151,7 +159,7 @@ static int libvlc_vlm_init( libvlc_instance_t *p_instance )
#define VLM_RET(p,ret) do { \ #define VLM_RET(p,ret) do { \
if( libvlc_vlm_init( p_instance ) ) \ if( libvlc_vlm_init( p_instance ) ) \
return (ret); \ return (ret); \
(p) = p_instance->libvlc_vlm.p_vlm; \ (p) = p_instance->vlm->p_vlm; \
} while(0) } while(0)
static vlm_media_instance_t * static vlm_media_instance_t *
...@@ -734,5 +742,5 @@ libvlc_vlm_get_event_manager( libvlc_instance_t *p_instance ) ...@@ -734,5 +742,5 @@ libvlc_vlm_get_event_manager( libvlc_instance_t *p_instance )
{ {
if( libvlc_vlm_init( p_instance ) ) if( libvlc_vlm_init( p_instance ) )
return NULL; return NULL;
return p_instance->libvlc_vlm.p_event_manager; return p_instance->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