]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/hal.c
Last patch to close #1479 (add a column with the track id)
[vlc] / modules / services_discovery / hal.c
index 5ae53c20fcfdde3979ba3b3d4d11a6719a8a9688..45b7937071f4383727e452c4886f7c255ec0eccc 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 #include <vlc_playlist.h>
 
@@ -187,7 +191,7 @@ static void Close( vlc_object_t *p_this )
 
 static void AddItem( services_discovery_t *p_sd, input_item_t * p_input
 #ifdef HAVE_HAL_1
-                ,char* psz_device
+                , const char* psz_device
 #endif
                     )
 {
@@ -201,13 +205,14 @@ static void AddItem( services_discovery_t *p_sd, input_item_t * p_input
     {
         return;
     }
+    vlc_gc_incref( p_input );
     p_udi_entry->p_item = p_input;
     p_udi_entry->psz_udi = strdup( psz_device );
     TAB_APPEND( p_sys->i_devices_number, p_sys->pp_devices, p_udi_entry );
 #endif
 }
 
-static void AddDvd( services_discovery_t *p_sd, char *psz_device )
+static void AddDvd( services_discovery_t *p_sd, const char *psz_device )
 {
     char *psz_name;
     char *psz_uri;
@@ -238,54 +243,31 @@ static void AddDvd( services_discovery_t *p_sd, char *psz_device )
 #else
     AddItem( p_sd, p_input );
 #endif
+    vlc_gc_decref( p_input );
 }
 
 #ifdef HAVE_HAL_1
-static void DelItem( services_discovery_t *p_sd, char* psz_udi )
+static void DelItem( services_discovery_t *p_sd, const char* psz_udi )
 {
     services_discovery_sys_t    *p_sys  = p_sd->p_sys;
-    playlist_item_t             *p_pl_item;
-
-    playlist_t *p_playlist = pl_Yield( p_sd );
-    if( !p_playlist )
-    {
-        msg_Err( p_sd, "playlist not found" );
-        return;
-    }
 
     int i;
     for( i = 0; i < p_sys->i_devices_number; i++ )
     { /*  looks for a matching udi */
         if( strcmp( psz_udi, p_sys->pp_devices[i]->psz_udi ) == 0 )
-        { /* delete the corresponding item */
-            p_pl_item = playlist_ItemGetByInputId( p_playlist,
-                p_sys->pp_devices[i]->p_item->i_id, p_sd->p_cat );
-            if( p_pl_item )
-            {
-                while( p_pl_item->i_children > 0 )
-                { /* delete all childs */
-                    playlist_DeleteFromInput( p_playlist,
-                        p_pl_item->pp_children[0]->p_input->i_id, VLC_FALSE );
-                }
-                /* HACK: if i_children == 0 the item won't be deleted
-                 * That means that it _had_ children but they were deleted */
-                if( p_pl_item->i_children == 0 )
-                    p_pl_item->i_children = -1;
-            }
+        { /* delete the corresponding item */    
             services_discovery_RemoveItem( p_sd, p_sys->pp_devices[i]->p_item );
-
+            vlc_gc_decref( p_sys->pp_devices[i]->p_item );
             if( p_sys->pp_devices[i]->psz_udi )
                 free( p_sys->pp_devices[i]->psz_udi );
             TAB_REMOVE( p_sys->i_devices_number, p_sys->pp_devices,
                     p_sys->pp_devices[i] );
         }
     }
-
-    pl_Release( p_playlist );
 }
 #endif
 
-static void AddCdda( services_discovery_t *p_sd, char *psz_device )
+static void AddCdda( services_discovery_t *p_sd, const char *psz_device )
 {
     char *psz_uri;
     char *psz_blockdevice;
@@ -299,7 +281,7 @@ static void AddCdda( services_discovery_t *p_sd, char *psz_device )
 #endif
     if( asprintf( &psz_uri, "cdda://%s", psz_blockdevice ) == -1 )
         return;
-    /* Create the playlist item here */
+    /* Create the item here */
     p_input = input_ItemNew( p_sd, psz_uri, "Audio CD" );
     free( psz_uri );
     if( !p_input )
@@ -309,9 +291,10 @@ static void AddCdda( services_discovery_t *p_sd, char *psz_device )
 #else
     AddItem( p_sd, p_input );
 #endif
+    vlc_gc_decref( p_input );
 }
 
-static void ParseDevice( services_discovery_t *p_sd, char *psz_device )
+static void ParseDevice( services_discovery_t *p_sd, const char *psz_device )
 {
     char *psz_disc_type;
     services_discovery_sys_t    *p_sys  = p_sd->p_sys;
@@ -398,11 +381,13 @@ static void Run( services_discovery_t *p_sd )
 #ifdef HAVE_HAL_1
 void DeviceAdded( LibHalContext *p_ctx, const char *psz_udi )
 {
-        ParseDevice( p_sd_global, (char*) psz_udi );
+    VLC_UNUSED(p_ctx);
+    ParseDevice( p_sd_global, psz_udi );
 }
 void DeviceRemoved( LibHalContext *p_ctx, const char *psz_udi )
 {
-        DelItem( p_sd_global, (char*) psz_udi );
+    VLC_UNUSED(p_ctx);
+    DelItem( p_sd_global, psz_udi );
 }
 #endif