]> git.sesse.net Git - vlc/blobdiff - src/input/item.c
Some more const
[vlc] / src / input / item.c
index 4d7d94ecaf9d712a4488a18597b4285714ebb8ae..06685af7f500e5d2fb64062c3a3d275e0816a22d 100644 (file)
@@ -38,7 +38,7 @@ static void GuessType( input_item_t *p_item );
  *         empty string otherwise. The caller should free the returned
  *         pointer.
  */
-char *vlc_input_item_GetInfo( input_item_t *p_i,
+char *input_ItemGetInfo( input_item_t *p_i,
                               const char *psz_cat,
                               const char *psz_name )
 {
@@ -67,34 +67,52 @@ char *vlc_input_item_GetInfo( input_item_t *p_i,
     return strdup( "" );
 }
 
-static void vlc_input_item_Destroy ( gc_object_t *p_this )
+static void input_ItemDestroy ( gc_object_t *p_this )
 {
     vlc_object_t *p_obj = (vlc_object_t *)p_this->p_destructor_arg;
-    int i;
     input_item_t *p_input = (input_item_t *) p_this;
+    int i;
+
+    playlist_t *p_playlist = pl_Yield( p_obj );
+    input_ItemClean( p_input );
 
-    playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_obj,
-                                          VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    ARRAY_BSEARCH( p_playlist->input_items,->i_id, int, p_input->i_id, i);
+    if( i != -1 )
+        ARRAY_REMOVE( p_playlist->input_items, i);
 
-    vlc_input_item_Clean( p_input );
+    pl_Release( p_obj );
+    free( p_input );
+}
 
-    if( p_playlist )
+void input_ItemAddOption( input_item_t *p_input,
+                          const char *psz_option )
+{
+    if( !psz_option ) return;
+    vlc_mutex_lock( &p_input->lock );
+    INSERT_ELEM( p_input->ppsz_options, p_input->i_options,
+                 p_input->i_options, strdup( psz_option ) );
+    vlc_mutex_unlock( &p_input->lock );
+}
+
+void input_ItemAddOptionNoDup( input_item_t *p_input,
+                               const char *psz_option )
+{
+    int i;
+    if( !psz_option ) return ;
+    vlc_mutex_lock( &p_input->lock );
+    for( i = 0 ; i< p_input->i_options; i++ )
     {
-        for( i = 0 ; i< p_playlist->i_input_items ; i++ )
+        if( !strcmp( p_input->ppsz_options[i], psz_option ) )
         {
-            if( p_playlist->pp_input_items[i]->i_id == p_input->i_id )
-            {
-                REMOVE_ELEM( p_playlist->pp_input_items,
-                             p_playlist->i_input_items, i );
-                break;
-            }
+            vlc_mutex_unlock(& p_input->lock );
+            return;
         }
-        vlc_object_release( p_playlist );
     }
-    free( p_input );
+    TAB_APPEND( p_input->i_options, p_input->ppsz_options, strdup( psz_option));    vlc_mutex_unlock( &p_input->lock );
 }
 
-int vlc_input_item_AddInfo( input_item_t *p_i,
+
+int input_ItemAddInfo( input_item_t *p_i,
                             const char *psz_cat,
                             const char *psz_name,
                             const char *psz_format, ... )
@@ -161,41 +179,18 @@ int vlc_input_item_AddInfo( input_item_t *p_i,
     return VLC_SUCCESS;
 }
 
-void vlc_input_item_AddOption( input_item_t *p_input,
-                              const char *psz_option )
-{
-    if( !psz_option ) return;
-    vlc_mutex_lock( &p_input->lock );
-    INSERT_ELEM( p_input->ppsz_options, p_input->i_options,
-                 p_input->i_options, strdup( psz_option ) );
-    vlc_mutex_unlock( &p_input->lock );
-};
-
-
 input_item_t *input_ItemGetById( playlist_t *p_playlist, int i_id )
 {
-    int i, i_top, i_bottom;
-    i_bottom = 0; i_top = p_playlist->i_input_items -1;
-    i = i_top  /2 ;
-    while( p_playlist->pp_input_items[i]->i_id != i_id &&
-           i_top > i_bottom )
-    {
-        if( p_playlist->pp_input_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_input_items[i]->i_id == i_id )
-    {
-        return p_playlist->pp_input_items[i];
-    }
+    int i;
+    ARRAY_BSEARCH( p_playlist->input_items, ->i_id, int, i_id, i);
+    if( i != -1 )
+        return ARRAY_VAL( p_playlist->input_items, i);
     return NULL;
 }
 
 input_item_t *__input_ItemNewExt( vlc_object_t *p_obj, const char *psz_uri,
                                   const char *psz_name, int i_options,
-                                  const char **ppsz_options, int i_duration )
+                                  const char *const *ppsz_options, int i_duration )
 {
     return input_ItemNewWithType( p_obj, psz_uri, psz_name,
                                   i_options, ppsz_options,
@@ -205,23 +200,20 @@ input_item_t *__input_ItemNewExt( vlc_object_t *p_obj, const char *psz_uri,
 
 input_item_t *input_ItemNewWithType( vlc_object_t *p_obj, const char *psz_uri,
                                 const char *psz_name, int i_options,
-                                const char **ppsz_options, int i_duration,
+                                const char *const *ppsz_options, int i_duration,
                                 int i_type )
 {
-    /* FIXME DON'T SEARCH PLAYLIST */
-    /* FIXME SHOULD LOCK */
-    input_item_t *p_input = (input_item_t *)malloc( sizeof( input_item_t ) );
-    playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_obj,
-                                VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+    playlist_t *p_playlist = pl_Yield( p_obj );
+    DECMALLOC_NULL( p_input, input_item_t );
 
-    vlc_input_item_Init( p_obj, p_input );
-    vlc_gc_init( p_input, vlc_input_item_Destroy, (void *)p_obj );
+    input_ItemInit( p_obj, p_input );
+    vlc_gc_init( p_input, input_ItemDestroy, (void *)p_obj );
 
+    PL_LOCK;
     p_input->i_id = ++p_playlist->i_last_input_id;
-
-    INSERT_ELEM( p_playlist->pp_input_items, p_playlist->i_input_items,
-                 p_playlist->i_input_items, p_input );
-    vlc_object_release( p_playlist );
+    ARRAY_APPEND( p_playlist->input_items, p_input );
+    PL_UNLOCK;
+    pl_Release( p_obj );
 
     p_input->b_fixed_name = VLC_FALSE;
 
@@ -230,17 +222,26 @@ input_item_t *input_ItemNewWithType( vlc_object_t *p_obj, const char *psz_uri,
     else
         p_input->psz_uri = NULL;
 
-    if( psz_name != NULL )
-        p_input->psz_name = strdup( psz_name );
-    else
-        p_input->psz_name = strdup ( p_input->psz_uri );
-
     p_input->i_type = i_type;
     p_input->b_prefers_tree = VLC_FALSE;
 
     if( p_input->i_type == ITEM_TYPE_UNKNOWN )
         GuessType( p_input );
 
+    if( psz_name != NULL )
+        p_input->psz_name = strdup( psz_name );
+    else if( p_input->i_type == ITEM_TYPE_AFILE
+             || p_input->i_type == ITEM_TYPE_VFILE )
+    {
+        const char *psz_filename = strrchr( p_input->psz_uri, DIR_SEP_CHAR );
+        if( psz_filename && *psz_filename == DIR_SEP_CHAR )
+            psz_filename++;
+        p_input->psz_name = strdup( psz_filename && *psz_filename
+                                    ? psz_filename : p_input->psz_uri );
+    }
+    else
+        p_input->psz_name = strdup( p_input->psz_uri );
+
     p_input->i_duration = i_duration;
     p_input->ppsz_options = NULL;
 
@@ -262,7 +263,7 @@ input_item_t *input_ItemNewWithType( vlc_object_t *p_obj, const char *psz_uri,
 static void GuessType( input_item_t *p_item)
 {
     int i;
-    static struct { char *psz_search; int i_type; }  types_array[] =
+    static struct { const char *psz_search; int i_type; }  types_array[] =
     {
         { "http", ITEM_TYPE_NET },
         { "dvd", ITEM_TYPE_DISC },