]> git.sesse.net Git - vlc/blobdiff - src/playlist/services_discovery.c
Don't unlock the playlist to lock it the next instruction.
[vlc] / src / playlist / services_discovery.c
index e7d924994ea4d60c7f65dc168fa209fde32d37a0..4eecba32c0d54ff8936756cc921bb5cf8830ba92 100644 (file)
@@ -214,18 +214,37 @@ static void playlist_sd_item_added( const vlc_event_t * p_event, void * user_dat
     input_item_t * p_input = p_event->u.services_discovery_item_added.p_new_item;
     const char * psz_cat = p_event->u.services_discovery_item_added.psz_category;
     playlist_item_t *p_new_item, * p_parent = user_data;
+    playlist_t * p_playlist = p_parent->p_playlist;
 
-    msg_Dbg( p_parent->p_playlist, "Adding %s in %s",
+    msg_Dbg( p_playlist, "Adding %s in %s",
                 p_input->psz_name ? p_input->psz_name : "(null)",
                 psz_cat ? psz_cat : "(null)" );
 
-    p_new_item = playlist_NodeAddInput( p_parent->p_playlist, p_input, p_parent,
-                                        PLAYLIST_APPEND, PLAYLIST_END, false );
+    PL_LOCK;
+    /* If p_parent is in root category (this is clearly a hack) and we have a cat */
+    if( !EMPTY_STR(psz_cat) &&
+        p_parent->p_parent == p_playlist->p_root_category )
+    {
+        /* */
+        playlist_item_t * p_cat;
+        p_cat = playlist_ChildSearchName( p_parent, psz_cat );
+        if( !p_cat )
+        {
+            p_cat = playlist_NodeCreate( p_playlist, psz_cat,
+                                         p_parent, 0, NULL );
+            p_cat->i_flags &= ~PLAYLIST_SKIP_FLAG;
+        }
+        p_parent = p_cat;
+    }
+
+    p_new_item = playlist_NodeAddInput( p_playlist, p_input, p_parent,
+                                        PLAYLIST_APPEND, PLAYLIST_END, pl_Locked );
     if( p_new_item )
     {
         p_new_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
         p_new_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
     }
+    PL_UNLOCK;
 }
 
  /* A new item has been removed from a certain sd */
@@ -247,11 +266,12 @@ static void playlist_sd_item_removed( const vlc_event_t * p_event, void * user_d
         vlc_object_unlock( p_parent->p_playlist );
         return;
     }
-    vlc_object_unlock( p_parent->p_playlist );
 
     /* Delete the non-node item normally */
     playlist_DeleteInputInParent( p_parent->p_playlist, p_input->i_id,
-                                  p_parent, false );
+                                  p_parent, true );
+
+    vlc_object_unlock( p_parent->p_playlist );
 }
 
 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,  const char *psz_modules )
@@ -290,8 +310,10 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,  const char *psz_modu
 
         char * psz = services_discovery_GetLocalizedName( p_sd );
         assert( psz );
+        PL_LOCK;
         playlist_NodesPairCreate( p_playlist, psz,
                 &p_cat, &p_one, false );
+        PL_UNLOCK;
         free( psz );
 
         vlc_event_attach( services_discovery_EventManager( p_sd ),
@@ -319,10 +341,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,  const char *psz_modu
         /* Free in playlist_ServicesDiscoveryRemove */
         p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );
         if( !p_sds )
-        {
-            msg_Err( p_playlist, "No more memory" );
             return VLC_ENOMEM;
-        }
         p_sds->p_sd = p_sd;
         p_sds->p_one = p_one;
         p_sds->p_cat = p_cat;
@@ -414,3 +433,10 @@ bool playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
     return false;
 }
 
+void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist )
+{
+    while( p_playlist->i_sds > 0 )
+        playlist_ServicesDiscoveryRemove( p_playlist,
+                                     p_playlist->pp_sds[0]->p_sd->psz_module );
+}
+