]> git.sesse.net Git - vlc/blobdiff - src/playlist/search.c
Same as previous commit, for invalid MMS URLs
[vlc] / src / playlist / search.c
index 10a8b706a30b5e1eabef8217d75c05c0e71274fb..c709074cbc9c3f7fc3906060187559a2a4b8acb3 100644 (file)
@@ -21,9 +21,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-
 #include "vlc_playlist.h"
+#include "playlist_internal.h"
 
 /***************************************************************************
  * Item search functions
  * \param i_id the id to find
  * \return the item or NULL on failure
  */
-playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
+playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id,
+                                        vlc_bool_t b_locked )
 {
-    int i, i_top, i_bottom;
-    i_bottom = 0; i_top = p_playlist->i_all_size - 1;
-    i = i_top / 2;
-    while( p_playlist->pp_all_items[i]->i_id != i_id &&
-           i_top > i_bottom )
-    {
-        if( p_playlist->pp_all_items[i]->i_id < i_id )
-            i_bottom = i + 1;
-        else
-            i_top = i - 1;
-        i = i_bottom + ( i_top - i_bottom ) / 2;
-    }
-    if( p_playlist->pp_all_items[i]->i_id == i_id )
-    {
-        return p_playlist->pp_all_items[i];
+    int i;
+    if( !b_locked ) PL_LOCK;
+    ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
+    if( i != -1 ) {
+        if( !b_locked ) PL_UNLOCK;
+        return ARRAY_VAL( p_playlist->all_items, i );
     }
+    if( !b_locked ) PL_UNLOCK;
     return NULL;
 }
 
@@ -65,22 +57,27 @@ playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
  * \return the item, or NULL on failure
  */
 playlist_item_t * playlist_ItemGetByInput( playlist_t * p_playlist ,
-                                           input_item_t *p_item )
+                                           input_item_t *p_item,
+                                           vlc_bool_t b_locked )
 {
     int i;
-    if( p_playlist->status.p_item && p_playlist->status.p_item->p_input == p_item )
+    if( !b_locked ) PL_LOCK;
+    if( p_playlist->status.p_item &&
+        p_playlist->status.p_item->p_input == p_item )
     {
+        if( !b_locked ) PL_UNLOCK;
         return p_playlist->status.p_item;
     }
-
-    for( i =  0 ; i < p_playlist->i_all_size; i++ )
+    /** \todo Check if this is always incremental and whether we can bsearch */
+    for( i =  0 ; i < p_playlist->all_items.i_size; i++ )
     {
-msg_Err( p_playlist, "%p, %p", p_item, p_playlist->pp_all_items[i]->p_input );
-        if( p_playlist->pp_all_items[i]->p_input == p_item )
+        if( ARRAY_VAL(p_playlist->all_items, i)->p_input->i_id == p_item->i_id )
         {
-            return p_playlist->pp_all_items[i];
+            if( !b_locked ) PL_UNLOCK;
+            return ARRAY_VAL(p_playlist->all_items, i);
         }
     }
+    if( !b_locked ) PL_UNLOCK;
     return NULL;
 }
 
@@ -92,6 +89,7 @@ int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root,
                                const char *psz_string )
 {
    int i;
+   p_playlist->b_reset_currently_playing = VLC_TRUE;
    for( i = 0 ; i< p_root->i_children ; i ++ )
    {
         playlist_item_t *p_item = p_root->pp_children[i];
@@ -102,12 +100,12 @@ int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root,
 #define META_MATCHES( field ) ( p_item->p_input->p_meta && \
                                 p_item->p_input->p_meta->psz_##field && \
                                 strcasestr( p_item->p_input->p_meta->psz_##field, psz_string ) )
-        /* Todo: Filter on all fields */
         if( strcasestr( p_item->p_input->psz_name, psz_string ) ||
             META_MATCHES( artist ) || META_MATCHES( album ) )
             p_item->i_flags &= ~PLAYLIST_DBL_FLAG;
         else
             p_item->i_flags |= PLAYLIST_DBL_FLAG;
    }
+   vlc_cond_signal( &p_playlist->object_wait );
    return VLC_SUCCESS;
 }