]> git.sesse.net Git - vlc/commitdiff
A bit of cleanup in libvlc playlist API. Preliminary work for: Refs:#457
authorClément Stenac <zorglub@videolan.org>
Mon, 18 Dec 2006 22:03:30 +0000 (22:03 +0000)
committerClément Stenac <zorglub@videolan.org>
Mon, 18 Dec 2006 22:03:30 +0000 (22:03 +0000)
include/vlc/libvlc.h
include/vlc/vlc.h
src/control/playlist.c
src/playlist/item.c
src/playlist/playlist_internal.h
src/playlist/search.c

index 688d940fa01992c6bb8e3273ee4e028a0221dec8..12406a36c52a6798c49f88726135b25e3a4f590f 100644 (file)
@@ -51,6 +51,7 @@ extern "C" {
 struct libvlc_exception_t
 {
     int b_raised;
+    int i_code;
     char *psz_message;
 };
 typedef struct libvlc_exception_t libvlc_exception_t;
@@ -142,7 +143,8 @@ void libvlc_destroy( libvlc_instance_t *, libvlc_exception_t * );
 /**
  * Set loop variable
  */
-void libvlc_playlist_loop( libvlc_instance_t* , vlc_bool_t, libvlc_exception_t * );
+void libvlc_playlist_loop( libvlc_instance_t* , vlc_bool_t,
+                           libvlc_exception_t * );
 
 /**
  * Start playing. You can give some additionnal playlist item options
@@ -233,7 +235,7 @@ int libvlc_playlist_add_extended( libvlc_instance_t *, const char *,
                                   const char *, int, const char **,
                                   libvlc_exception_t * );
 
-/** 
+/**
  * Delete the playlist item with the given ID.
  * \param p_instance the instance
  * \param i_id the id to remove
index c2e2cdeffb5f3a369357f04b0b5a09b57e83d1b6..df11673c0ad10cb577ddabf1d4b16d1ed8a0393c 100644 (file)
@@ -122,6 +122,8 @@ struct vlc_list_t
 #define VLC_ENOVAR         -30                         /* Variable not found */
 #define VLC_EBADVAR        -31                         /* Bad variable value */
 
+#define VLC_ENOITEM        -40                           /**< Item not found */
+
 #define VLC_EEXIT         -255                             /* Program exited */
 #define VLC_EEXITSUCCESS  -999                /* Program exited successfully */
 #define VLC_EGENERIC      -666                              /* Generic error */
index 0872b5ac86032e6e30de0dd0004eb23a4345b37b..22a75a6fc4aef5bda3ea4107a78afecca7a45e3e 100644 (file)
 
 #include <assert.h>
 
+#include "../playlist/playlist_internal.h"
+
 #define PL p_instance->p_libvlc_int->p_playlist
 
 void libvlc_playlist_loop( libvlc_instance_t *p_instance, vlc_bool_t loop,
                            libvlc_exception_t *p_e)
 {
     assert( PL );
-    var_SetBool(PL,"loop",loop);
+    var_SetBool( PL, "loop", loop );
 }
 
 void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
@@ -46,7 +48,8 @@ void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
     if( PL->items.i_size == 0 ) RAISEVOID( "Empty playlist" );
     if( i_id > 0 )
     {
-        playlist_item_t *p_item = playlist_ItemGetById( PL, i_id, VLC_TRUE );
+        playlist_item_t *p_item = playlist_ItemGetByInputId( PL, i_id,
+                                                           PL->status.p_node );
         if( !p_item ) RAISEVOID( "Unable to find item" );
 
         playlist_Control( PL, PLAYLIST_VIEWPLAY, VLC_FALSE,
@@ -115,31 +118,21 @@ int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
                             i_options, 1 );
 }
 
+
+
 int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
                                  libvlc_exception_t *p_e )
 {
-    playlist_item_t *p_item;
     assert( PL );
-    vlc_mutex_lock( &PL->object_lock );
-    p_item = playlist_ItemGetById( PL, i_id, VLC_TRUE );
-    if( p_item && p_item->p_input ) {
-        int i_ret = playlist_DeleteFromInput( PL, p_item->p_input->i_id, VLC_TRUE );
-        if( i_ret ) {
-            libvlc_exception_raise( p_e, "delete failed" );
-            vlc_mutex_unlock( &PL->object_lock );
-            return VLC_EGENERIC;
-        }
-        else {
-            vlc_mutex_unlock( &PL->object_lock );
-            return VLC_SUCCESS;
-        }
+
+    if( playlist_DeleteFromInput( PL, i_id, VLC_FALSE ) )
+    {
+        libvlc_exception_raise( p_e, "deletion failed" );
+        return VLC_ENOITEM;
     }
-    libvlc_exception_raise( p_e, "item not found" );
-    vlc_mutex_unlock( &PL->object_lock );
-    return VLC_EGENERIC;
+    return VLC_SUCCESS;
 }
 
-
 int libvlc_playlist_isplaying( libvlc_instance_t *p_instance,
                                libvlc_exception_t *p_e )
 {
index e3bfc9578c021a05d6d3a4420e6d38664f101e1e..cc47aa110407756075163ff7c7eb273ab3684629 100644 (file)
@@ -113,13 +113,15 @@ static int DeleteFromInput( playlist_t *p_playlist, int i_input_id,
 int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id,
                               vlc_bool_t b_locked )
 {
+    int i_ret1, i_ret2;
     if( !b_locked ) PL_LOCK;
-    DeleteFromInput( p_playlist, i_input_id,
-                     p_playlist->p_root_category, VLC_TRUE );
-    DeleteFromInput( p_playlist, i_input_id,
+    i_ret1 = DeleteFromInput( p_playlist, i_input_id,
+                             p_playlist->p_root_category, VLC_TRUE );
+    i_ret2 = DeleteFromInput( p_playlist, i_input_id,
                      p_playlist->p_root_onelevel, VLC_TRUE );
     if( !b_locked ) PL_UNLOCK;
-    return VLC_SUCCESS;
+    return ( i_ret1 == VLC_SUCCESS || i_ret2 == VLC_SUCCESS ) ?
+                            VLC_SUCCESS : VLC_ENOITEM;
 }
 
 void playlist_Clear( playlist_t * p_playlist, vlc_bool_t b_locked )
@@ -182,11 +184,15 @@ int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
                      mtime_t i_duration, const char *const *ppsz_options,
                      int i_options, vlc_bool_t b_playlist )
 {
+    int i_ret;
     input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
                                               i_options, ppsz_options,
                                               i_duration );
 
-    return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist );
+    i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist );
+    if( i_ret == VLC_SUCCESS )
+        return p_input->i_id;
+    return -1;
 }
 
 /** Add an input item to the playlist node */
@@ -199,25 +205,25 @@ int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
         PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
                                              p_input->psz_uri );
 
-    vlc_mutex_lock( &p_playlist->object_lock );
+    PL_LOCK;
 
     /* Add to ONELEVEL */
     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
-    if( p_item_one == NULL ) return VLC_EGENERIC;
+    if( p_item_one == NULL ) return VLC_ENOMEM;
     AddItem( p_playlist, p_item_one,
              b_playlist ? p_playlist->p_local_onelevel :
                           p_playlist->p_ml_onelevel , i_mode, i_pos );
 
     /* Add to CATEGORY */
     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
-    if( p_item_cat == NULL ) return VLC_EGENERIC;
+    if( p_item_cat == NULL ) return VLC_ENOMEM;
     AddItem( p_playlist, p_item_cat,
              b_playlist ? p_playlist->p_local_category :
                           p_playlist->p_ml_category , i_mode, i_pos );
 
     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
 
-    vlc_mutex_unlock( &p_playlist->object_lock );
+    PL_UNLOCK;
     return VLC_SUCCESS;
 }
 
@@ -236,13 +242,13 @@ int playlist_BothAddInput( playlist_t *p_playlist,
 
     /* Add to category */
     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
-    if( p_item_cat == NULL ) return VLC_EGENERIC;
+    if( p_item_cat == NULL ) return VLC_ENOMEM;
     AddItem( p_playlist, p_item_cat, p_direct_parent, i_mode, i_pos );
 
     /* Add to onelevel */
     /** \todo make a faster case for ml import */
     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
-    if( p_item_one == NULL ) return VLC_EGENERIC;
+    if( p_item_one == NULL ) return VLC_ENOMEM;
 
     p_up = p_direct_parent;
     while( p_up->p_parent != p_playlist->p_root_category )
index e82b677ee5eb31d54ff736fafc16c4e7657c5e78..cbc4bab80ef44363eba468116a9e8166d4767aa9 100644 (file)
@@ -110,6 +110,8 @@ playlist_item_t *playlist_GetLastLeaf( playlist_t *p_playlist,
 int playlist_DeleteFromItemId( playlist_t*, int );
 int playlist_ItemDelete ( playlist_item_t * );
 
+playlist_item_t *playlist_ItemGetByInputId( playlist_t*, int, playlist_item_t*);
+
 /**
  * @}
  */
index 659b9a4f375bd41cab3b94492964ff35eefc9a24..c831566e3327ba24080e5c511e23fcc843da1d4f 100644 (file)
@@ -81,6 +81,29 @@ playlist_item_t * playlist_ItemGetByInput( playlist_t * p_playlist ,
     return NULL;
 }
 
+/** Find the playlist item matching the input id under the given node */
+playlist_item_t * playlist_ItemGetByInputId( playlist_t *p_playlist,
+                                             int i_input_id,
+                                             playlist_item_t *p_root )
+{
+    int i;
+    assert( p_root != NULL );
+    for( i = 0 ; i< p_root->i_children ; i++ )
+    {
+        if( p_root->pp_children[i]->i_children == -1 &&
+            p_root->pp_children[i]->p_input->i_id == i_input_id )
+        {
+            return p_root->pp_children[i];
+        }
+        else if( p_root->pp_children[i]->i_children >= 0 )
+        {
+            return playlist_ItemGetByInputId( p_playlist, i_input_id,
+                                              p_root->pp_children[i] );
+        }
+    }
+    return NULL;
+}
+
 /***************************************************************************
  * Live search handling
  ***************************************************************************/