[vlc-commits] lib: media_list_player: allocate event manager in-place

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon May 15 20:16:45 2017 +0300| [7395282cd8cbf59852188e8c43aba9ca348b2bd6] | committer: Rémi Denis-Courmont

lib: media_list_player: allocate event manager in-place

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

 lib/media_list_player.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/lib/media_list_player.c b/lib/media_list_player.c
index 68e2cfaf6f..930b69061a 100644
--- a/lib/media_list_player.c
+++ b/lib/media_list_player.c
@@ -57,7 +57,7 @@
 
 struct libvlc_media_list_player_t
 {
-    libvlc_event_manager_t *    p_event_manager;
+    libvlc_event_manager_t      event_manager;
     int                         i_refcount;
     int                         seek_offset;
     /* Protect access to this structure. */
@@ -486,30 +486,24 @@ libvlc_media_list_player_new(libvlc_instance_t * p_instance)
     vlc_mutex_init(&p_mlp->object_lock);
     vlc_mutex_init(&p_mlp->mp_callback_lock);
     vlc_cond_init(&p_mlp->seek_pending);
-
-    p_mlp->p_event_manager = libvlc_event_manager_new(p_mlp);
-    if (unlikely(p_mlp->p_event_manager == NULL))
-        goto error;
+    libvlc_event_manager_init(&p_mlp->event_manager, p_mlp);
 
     /* Create the underlying media_player */
     p_mlp->p_mi = libvlc_media_player_new(p_instance);
     if( p_mlp->p_mi == NULL )
-    {
-        libvlc_event_manager_release(p_mlp->p_event_manager);
         goto error;
-    }
     install_media_player_observer(p_mlp);
 
     if (vlc_clone(&p_mlp->thread, playlist_thread, p_mlp,
                   VLC_THREAD_PRIORITY_LOW))
     {
         libvlc_media_player_release(p_mlp->p_mi);
-        libvlc_event_manager_release(p_mlp->p_event_manager);
         goto error;
     }
 
     return p_mlp;
 error:
+    libvlc_event_manager_destroy(&p_mlp->event_manager);
     vlc_cond_destroy(&p_mlp->seek_pending);
     vlc_mutex_destroy(&p_mlp->mp_callback_lock);
     vlc_mutex_destroy(&p_mlp->object_lock);
@@ -552,7 +546,7 @@ void libvlc_media_list_player_release(libvlc_media_list_player_t * p_mlp)
 
     unlock(p_mlp);
 
-    libvlc_event_manager_release(p_mlp->p_event_manager);
+    libvlc_event_manager_destroy(&p_mlp->event_manager);
     vlc_cond_destroy(&p_mlp->seek_pending);
     vlc_mutex_destroy(&p_mlp->mp_callback_lock);
     vlc_mutex_destroy(&p_mlp->object_lock);
@@ -580,7 +574,7 @@ void libvlc_media_list_player_retain(libvlc_media_list_player_t * p_mlp)
 libvlc_event_manager_t *
 libvlc_media_list_player_event_manager(libvlc_media_list_player_t * p_mlp)
 {
-    return p_mlp->p_event_manager;
+    return &p_mlp->event_manager;
 }
 
 /**************************************************************************
@@ -698,7 +692,7 @@ int libvlc_media_list_player_play_item_at_index(libvlc_media_list_player_t * p_m
     libvlc_event_t event;
     event.type = libvlc_MediaListPlayerNextItemSet;
     event.u.media_list_player_next_item_set.item = p_md;
-    libvlc_event_send(p_mlp->p_event_manager, &event);
+    libvlc_event_send(&p_mlp->event_manager, &event);
     libvlc_media_release(p_md);
     return 0;
 }
@@ -743,7 +737,7 @@ static void stop(libvlc_media_list_player_t * p_mlp)
     /* Send the event */
     libvlc_event_t event;
     event.type = libvlc_MediaListPlayerStopped;
-    libvlc_event_send(p_mlp->p_event_manager, &event);
+    libvlc_event_send(&p_mlp->event_manager, &event);
 }
 
 /**************************************************************************
@@ -813,7 +807,7 @@ static int set_relative_playlist_position_and_play(
         /* Send list played event */
         libvlc_event_t event;
         event.type = libvlc_MediaListPlayerPlayed;
-        libvlc_event_send(p_mlp->p_event_manager, &event);
+        libvlc_event_send(&p_mlp->event_manager, &event);
         return -1;
     }
 
@@ -826,7 +820,7 @@ static int set_relative_playlist_position_and_play(
     event.type = libvlc_MediaListPlayerNextItemSet;
     libvlc_media_t * p_md = libvlc_media_list_item_at_path(p_mlp->p_mlist, path);
     event.u.media_list_player_next_item_set.item = p_md;
-    libvlc_event_send(p_mlp->p_event_manager, &event);
+    libvlc_event_send(&p_mlp->event_manager, &event);
     libvlc_media_release(p_md);
     return 0;
 }



More information about the vlc-commits mailing list