]> git.sesse.net Git - vlc/commitdiff
services_discovery: storing the category & onelevel playlist items with the services_...
authorRafaël Carré <funman@videolan.org>
Wed, 10 Oct 2007 23:04:09 +0000 (23:04 +0000)
committerRafaël Carré <funman@videolan.org>
Wed, 10 Oct 2007 23:04:09 +0000 (23:04 +0000)
put the services_discovery_t** in the public playlist_t to save one unchecked malloc() and the corresponding free()

include/vlc_playlist.h
src/playlist/engine.c
src/playlist/playlist_internal.h
src/playlist/services_discovery.c

index 9326d08cf9f73f71510867d0364e429259690a93..869c1007cb6cb335987ace4362e5ec68ebd7e742 100644 (file)
@@ -180,7 +180,10 @@ struct services_discovery_t
 struct playlist_t
 {
     VLC_COMMON_MEMBERS
-    struct playlist_internal_t * p_internal; /**< Internal members */
+
+    /* pp_sd & i_sd are for internal use ONLY. Understood ? it's PRIVATE ! */
+    services_discovery_t **pp_sd; /**< Loaded service discovery modules */
+    int                   i_sd;   /**< Number of service discovery modules */
 
     int                   i_enabled; /**< How many items are enabled ? */
 
index 734ad4ffc904c6c7a947868fe8da434d95b12baf..7cd1bff6f629ce3011b52718844f5ec7c870afb6 100644 (file)
@@ -66,8 +66,7 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
         return NULL;
     }
 
-    p_playlist->p_internal = malloc(sizeof(struct playlist_internal_t));
-    memset( p_playlist->p_internal, 0, sizeof(struct playlist_internal_t) );
+    TAB_INIT( p_playlist->i_sd, p_playlist->pp_sd );
 
     p_parent->p_libvlc->p_playlist = p_playlist;
 
@@ -178,7 +177,6 @@ void playlist_Destroy( playlist_t *p_playlist )
 
     vlc_mutex_destroy( &p_playlist->gc_lock );
     vlc_object_detach( p_playlist );
-    free( p_playlist->p_internal );
     vlc_object_destroy( p_playlist );
 }
 
@@ -439,10 +437,10 @@ void playlist_LastLoop( playlist_t *p_playlist )
         vout_Destroy( (vout_thread_t *)p_obj );
     }
 
-    while( p_playlist->p_internal->i_asds )
+    while( p_playlist->i_sd )
     {
         playlist_ServicesDiscoveryRemove( p_playlist,
-                                          p_playlist->p_internal->pp_asds[0]->p_sd->psz_module );
+                                          p_playlist->pp_sd[0]->psz_module );
     }
 
     playlist_MLDump( p_playlist );
index 015bdd726b1d36fcb4d95f5f6cf10bc0c279b8ef..e82b677ee5eb31d54ff736fafc16c4e7657c5e78 100644 (file)
@@ -58,19 +58,6 @@ struct playlist_fetcher_t
     DECL_ARRAY(playlist_album_t) albums;
 };
 
-typedef struct playlist_archived_services_discovery_t {
-        services_discovery_t * p_sd; /* The service discovery module */
-        playlist_item_t      * p_cat;/* Corresponding item in the category view */
-        playlist_item_t      * p_one;/* Corresponding item in the one level view */
-} playlist_archived_services_discovery_t;
-
-struct playlist_internal_t {
-    struct playlist_archived_services_discovery_t
-                **pp_asds; /**< Loaded service discovery modules */
-    int         i_asds;    /**< Number of service discovery modules */
-};
-
-
 /*****************************************************************************
  * Prototypes
  *****************************************************************************/
index 55316d5efc8d9cfbd239cfdd29ce3ba0902b0205..ce119887c95d678bd65706a807753f2729552d8d 100644 (file)
@@ -303,14 +303,8 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,  const char *psz_modu
 
         services_discovery_Start( p_sd );
 
-        /* Free in playlist_ServicesDiscoveryRemove */
-        p_asd = malloc( sizeof(struct playlist_archived_services_discovery_t) );
-        p_asd->p_sd = p_sd;
-        p_asd->p_one = p_one;
-        p_asd->p_cat = p_cat;
-
         PL_LOCK;
-        TAB_APPEND( p_playlist->p_internal->i_asds, p_playlist->p_internal->pp_asds, p_asd );
+        TAB_APPEND( p_playlist->i_sd, p_playlist->pp_sd, p_sd );
         PL_UNLOCK;
     }
 
@@ -321,63 +315,60 @@ int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
                                        const char *psz_module )
 {
     int i;
-    struct playlist_archived_services_discovery_t *p_asd = NULL;
+    struct services_discovery_t *p_sd = NULL;
 
     PL_LOCK;
-    for( i = 0 ; i< p_playlist->p_internal->i_asds ; i ++ )
+    for( i = 0 ; i< p_playlist->i_sd ; i ++ )
     {
-        if( !strcmp( psz_module, p_playlist->p_internal->pp_asds[i]->p_sd->psz_module ) )
+        if( !strcmp( psz_module, p_playlist->pp_sd[i]->psz_module ) )
         {
-            p_asd = p_playlist->p_internal->pp_asds[i];
-            REMOVE_ELEM( p_playlist->p_internal->pp_asds, p_playlist->p_internal->i_asds, i );
+            p_sd = p_playlist->pp_sd[i];
+            REMOVE_ELEM( p_playlist->pp_sd, p_playlist->i_sd, i );
             break;
         }
     }
     PL_UNLOCK;
 
-    if( p_asd && p_asd->p_sd )
+    if( p_sd == NULL )
     {
-        services_discovery_Stop( p_asd->p_sd );
-
-        vlc_event_detach( services_discovery_EventManager( p_asd->p_sd ),
-                          vlc_ServicesDiscoveryItemAdded,
-                          playlist_sd_item_added,
-                          p_asd->p_one );
+        msg_Warn( p_playlist, "module %s is not loaded", psz_module );
+        return VLC_EGENERIC;
+    }
 
-        vlc_event_detach( services_discovery_EventManager( p_asd->p_sd ),
-                          vlc_ServicesDiscoveryItemAdded,
-                          playlist_sd_item_added,
-                          p_asd->p_cat );
+    services_discovery_Stop( p_sd );
 
-        vlc_event_detach( services_discovery_EventManager( p_asd->p_sd ),
-                          vlc_ServicesDiscoveryItemRemoved,
-                          playlist_sd_item_removed,
-                          p_asd->p_one );
+    vlc_event_detach( services_discovery_EventManager( p_sd ),
+                        vlc_ServicesDiscoveryItemAdded,
+                        playlist_sd_item_added,
+                        p_sd->p_one );
 
-        vlc_event_detach( services_discovery_EventManager( p_asd->p_sd ),
-                          vlc_ServicesDiscoveryItemRemoved,
-                          playlist_sd_item_removed,
-                          p_asd->p_cat );
+    vlc_event_detach( services_discovery_EventManager( p_sd ),
+                        vlc_ServicesDiscoveryItemAdded,
+                        playlist_sd_item_added,
+                        p_sd->p_cat );
 
-        /* Remove the sd playlist node if it exists */
-        PL_LOCK;
-        if( p_asd->p_cat != p_playlist->p_root_category &&
-            p_asd->p_one != p_playlist->p_root_onelevel )
-        {
-            playlist_NodeDelete( p_playlist, p_asd->p_cat, VLC_TRUE, VLC_FALSE );
-            playlist_NodeDelete( p_playlist, p_asd->p_one, VLC_TRUE, VLC_FALSE );
-        }
-        PL_UNLOCK;
+    vlc_event_detach( services_discovery_EventManager( p_sd ),
+                        vlc_ServicesDiscoveryItemRemoved,
+                        playlist_sd_item_removed,
+                        p_sd->p_one );
 
-        services_discovery_Destroy( p_asd->p_sd );
+    vlc_event_detach( services_discovery_EventManager( p_sd ),
+                        vlc_ServicesDiscoveryItemRemoved,
+                        playlist_sd_item_removed,
+                        p_sd->p_cat );
 
-        free( p_asd );
-    }
-    else
+    /* Remove the sd playlist node if it exists */
+    PL_LOCK;
+    if( p_sd->p_cat != p_playlist->p_root_category &&
+        p_sd->p_one != p_playlist->p_root_onelevel )
     {
-        msg_Warn( p_playlist, "module %s is not loaded", psz_module );
-        return VLC_EGENERIC;
+        playlist_NodeDelete( p_playlist, p_sd->p_cat, VLC_TRUE, VLC_FALSE );
+        playlist_NodeDelete( p_playlist, p_sd->p_one, VLC_TRUE, VLC_FALSE );
     }
+    PL_UNLOCK;
+
+    services_discovery_Destroy( p_sd );
+
     return VLC_SUCCESS;
 }
 
@@ -387,9 +378,9 @@ vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
     int i;
     PL_LOCK;
 
-    for( i = 0 ; i< p_playlist->p_internal->i_asds ; i ++ )
+    for( i = 0 ; i< p_playlist->i_sd ; i ++ )
     {
-        if( !strcmp( psz_module, p_playlist->p_internal->pp_asds[i]->p_sd->psz_module ) )
+        if( !strcmp( psz_module, p_playlist->pp_sd[i]->psz_module ) )
         {
             PL_UNLOCK;
             return VLC_TRUE;