[vlc-commits] lib: vlm: do not allocate inside the instance

Rémi Denis-Courmont git at videolan.org
Mon May 15 21:32:42 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon May 15 21:20:07 2017 +0300| [5ede6b918f3081071459811fc191be369729097f] | committer: Rémi Denis-Courmont

lib: vlm: do not allocate inside the instance

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5ede6b918f3081071459811fc191be369729097f
---

 lib/core.c            |  8 +++-----
 lib/libvlc_internal.h |  5 +----
 lib/vlm.c             | 46 +++++++++++++++++++++++++++-------------------
 3 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/lib/core.c b/lib/core.c
index c0f990480b..8ca4b5cf4d 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -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->libvlc_vlm.p_vlm = NULL;
-    p_new->libvlc_vlm.p_event_manager = NULL;
-    p_new->libvlc_vlm.pf_release = NULL;
+    p_new->vlm = NULL;
     p_new->ref_count = 1;
     p_new->p_callback_list = NULL;
     vlc_mutex_init(&p_new->instance_lock);
@@ -100,8 +98,8 @@ void libvlc_release( libvlc_instance_t *p_instance )
     if( refs == 0 )
     {
         vlc_mutex_destroy( lock );
-        if( p_instance->libvlc_vlm.pf_release )
-            p_instance->libvlc_vlm.pf_release( p_instance );
+        if( p_instance->vlm != NULL )
+            libvlc_vlm_release( p_instance );
         libvlc_Quit( p_instance->p_libvlc_int );
         libvlc_InternalCleanup( p_instance->p_libvlc_int );
         libvlc_InternalDestroy( p_instance->p_libvlc_int );
diff --git a/lib/libvlc_internal.h b/lib/libvlc_internal.h
index c07a0ca3ab..51fc6d0938 100644
--- a/lib/libvlc_internal.h
+++ b/lib/libvlc_internal.h
@@ -53,8 +53,6 @@ VLC_API void libvlc_InternalPlay( libvlc_int_t * );
 VLC_API void libvlc_InternalWait( libvlc_int_t * );
 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
  ***************************************************************************/
@@ -63,13 +61,12 @@ 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
 {
     libvlc_int_t *p_libvlc_int;
-    libvlc_vlm_t  libvlc_vlm;
+    libvlc_vlm_t *vlm;
     unsigned      ref_count;
     vlc_mutex_t   instance_lock;
     struct libvlc_callback_entry_list_t *p_callback_list;
diff --git a/lib/vlm.c b/lib/vlm.c
index 431acdd939..26f6bdc8e9 100644
--- a/lib/vlm.c
+++ b/lib/vlm.c
@@ -103,45 +103,53 @@ static int VlmEvent( vlc_object_t *p_this, const char * name,
 
 void libvlc_vlm_release( libvlc_instance_t *p_instance )
 {
-    vlm_t *p_vlm = p_instance->libvlc_vlm.p_vlm;
-    if( !p_instance->libvlc_vlm.p_vlm )
+    vlm_t *p_vlm = p_instance->vlm->p_vlm;
+    if( !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;
+                     p_instance->vlm->p_event_manager );
+    libvlc_event_manager_release( p_instance->vlm->p_event_manager );
+    p_instance->vlm->p_event_manager = NULL;
     vlm_Delete( p_vlm );
-    p_instance->libvlc_vlm.p_vlm = NULL;
+    free( p_instance->vlm );
+    p_instance->vlm = NULL;
     libvlc_release( 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 =
-            libvlc_event_manager_new( p_instance->libvlc_vlm.p_vlm );
-        if( unlikely(p_instance->libvlc_vlm.p_event_manager == NULL) )
+        p_instance->vlm = malloc( sizeof(*p_instance->vlm) );
+        if( p_instance->vlm == NULL )
             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 );
-        if( !p_instance->libvlc_vlm.p_vlm )
+        p_instance->vlm->p_event_manager =
+            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" );
             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,
-                         p_instance->libvlc_vlm.p_event_manager );
-        p_instance->libvlc_vlm.pf_release = libvlc_vlm_release;
+                         p_instance->vlm->p_event_manager );
         libvlc_retain( p_instance );
     }
 
@@ -151,7 +159,7 @@ static int libvlc_vlm_init( libvlc_instance_t *p_instance )
 #define VLM_RET(p,ret) do { \
     if( libvlc_vlm_init( p_instance ) ) \
         return (ret); \
-    (p) = p_instance->libvlc_vlm.p_vlm; \
+    (p) = p_instance->vlm->p_vlm; \
   } while(0)
 
 static vlm_media_instance_t *
@@ -734,5 +742,5 @@ libvlc_vlm_get_event_manager( libvlc_instance_t *p_instance )
 {
     if( libvlc_vlm_init( p_instance ) )
         return NULL;
-    return p_instance->libvlc_vlm.p_event_manager;
+    return p_instance->vlm->p_event_manager;
 }



More information about the vlc-commits mailing list