]> git.sesse.net Git - vlc/blobdiff - src/playlist/item.c
Re-enable random.
[vlc] / src / playlist / item.c
index a1f164dd03cb0b5524126fd88b1b2618bacd68bf..f6dbdaa8d66904b46e06a4baf2f480a1fbc96492 100644 (file)
@@ -37,48 +37,27 @@ int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
 /*****************************************************************************
  * Playlist item creation
  *****************************************************************************/
-/**
- * Create a new item, without adding it to the playlist
- *
- * \param p_obj a vlc object (anyone will do)
- * \param psz_uri the mrl of the item
- * \param psz_name a text giving a name or description of the item
- * \return the new item or NULL on failure
- */
-playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
-                                      const char *psz_uri,
-                                      const char *psz_name )
-{
-    return playlist_ItemNewWithType( p_obj, psz_uri,
-                                     psz_name, 0, NULL, -1,
-                                     ITEM_TYPE_UNKNOWN );
-}
-
 playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
                                             const char *psz_uri,
                                             const char *psz_name,
                                             int i_options,
                                             const char **ppsz_options,
-                                            int i_duration,
-                                            int i_type )
+                                            int i_duration, int i_type )
 {
     input_item_t *p_input;
-
     if( psz_uri == NULL ) return NULL;
     p_input = input_ItemNewWithType( p_obj, psz_uri,
-                                        psz_name, i_options, ppsz_options,
-                                        i_duration, i_type );
+                                     psz_name, i_options, ppsz_options,
+                                     i_duration, i_type );
     return playlist_ItemNewFromInput( p_obj, p_input );
 }
 
 playlist_item_t *__playlist_ItemNewFromInput( vlc_object_t *p_obj,
-                                            input_item_t *p_input )
+                                              input_item_t *p_input )
 {
     /** FIXME !!!!! don't find playlist each time */
     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_obj, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    playlist_item_t * p_item;
-    p_item = malloc( sizeof( playlist_item_t ) );
-    if( p_item == NULL ) return NULL;
+    DECMALLOC_NULL( p_item, playlist_item_t );
 
     p_item->p_input = p_input;
     vlc_gc_incref( p_item->p_input );
@@ -139,14 +118,16 @@ int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id,
             p_root->pp_children[i]->p_input->i_id == i_input_id )
         {
             DeleteInner( p_playlist, p_root->pp_children[i], b_do_stop );
+            return VLC_SUCCESS;
         }
         else if( p_root->pp_children[i]->i_children >= 0 )
         {
-            return playlist_DeleteFromInput( p_playlist, i_input_id,
+            int i_ret = playlist_DeleteFromInput( p_playlist, i_input_id,
                                         p_root->pp_children[i], b_do_stop );
+            if( i_ret == VLC_SUCCESS ) return VLC_SUCCESS;
         }
     }
-    return -1;
+    return VLC_EGENERIC;
 }
 
 /** Remove a playlist item from the playlist, given its id */
@@ -185,10 +166,7 @@ void playlist_LockClear( playlist_t *p_playlist )
 /***************************************************************************
  * Playlist item addition
  ***************************************************************************/
-
-/**
- * Add a MRL into the playlist.
- *
+/** Add an item to the playlist or the media library
  * \param p_playlist the playlist to add into
  * \param psz_uri the mrl to add to the playlist
  * \param psz_name a text giving a name or description of this item
@@ -196,17 +174,19 @@ void playlist_LockClear( playlist_t *p_playlist )
  * \param i_pos the position in the playlist where to add. If this is
  *        PLAYLIST_END the item will be added at the end of the playlist
  *        regardless of it's size
+ * \param b_playlist TRUE for playlist, FALSE for media library
  * \return The id of the playlist item
  */
-int playlist_PlaylistAdd( playlist_t *p_playlist, const char *psz_uri,
-                          const char *psz_name, int i_mode, int i_pos )
+int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
+                  const char *psz_name, int i_mode, int i_pos,
+                  vlc_bool_t b_playlist  )
 {
-    return playlist_PlaylistAddExt( p_playlist, psz_uri, psz_name,
-                                    i_mode, i_pos, -1, NULL, 0 );
+    return playlist_AddExt( p_playlist, psz_uri, psz_name,
+                            i_mode, i_pos, -1, NULL, 0, b_playlist );
 }
 
 /**
- * Add a MRL into the playlist, duration and options given
+ * Add a MRL into the playlist or the media library, duration and options given
  *
  * \param p_playlist the playlist to add into
  * \param psz_uri the mrl to add to the playlist
@@ -218,40 +198,44 @@ int playlist_PlaylistAdd( playlist_t *p_playlist, const char *psz_uri,
  * \param i_duration length of the item in milliseconds.
  * \param ppsz_options an array of options
  * \param i_options the number of options
+ * \param b_playlist TRUE for playlist, FALSE for media library
  * \return The id of the playlist item
 */
-int playlist_PlaylistAddExt( playlist_t *p_playlist, const char * psz_uri,
-                             const char *psz_name, int i_mode, int i_pos,
-                             mtime_t i_duration, const char **ppsz_options,
-                             int i_options )
+int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
+                     const char *psz_name, int i_mode, int i_pos,
+                     mtime_t i_duration, const char **ppsz_options,
+                     int i_options, vlc_bool_t b_playlist )
 {
     input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
                                               i_options, ppsz_options,
                                               i_duration );
 
-    return playlist_PlaylistAddInput( p_playlist, p_input, i_mode, i_pos );
+    return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist );
 }
 
 /** Add an input item to the playlist node */
-int playlist_PlaylistAddInput( playlist_t* p_playlist, input_item_t *p_input,
-                               int i_mode, int i_pos )
+int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
+                      int i_mode, int i_pos, vlc_bool_t b_playlist )
 {
     playlist_item_t *p_item_cat, *p_item_one;
 
-    msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )",
-             p_input->psz_name, p_input->psz_uri );
+    PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name, p_input->psz_uri );
 
     vlc_mutex_lock( &p_playlist->object_lock );
 
     /* Add to ONELEVEL */
     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
     if( p_item_one == NULL ) return VLC_EGENERIC;
-    AddItem( p_playlist, p_item_one ,p_playlist->p_local_onelevel, i_pos );
+    AddItem( p_playlist, p_item_one, 
+             b_playlist ? p_playlist->p_local_onelevel : 
+                          p_playlist->p_ml_onelevel , i_pos );
 
     /* Add to CATEGORY */
     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
     if( p_item_cat == NULL ) return VLC_EGENERIC;
-    AddItem( p_playlist, p_item_cat, p_playlist->p_local_category, i_pos );
+    AddItem( p_playlist, p_item_cat,
+             b_playlist ? p_playlist->p_local_category : 
+                          p_playlist->p_ml_category , i_pos );
 
     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
 
@@ -277,6 +261,7 @@ int playlist_BothAddInput( playlist_t *p_playlist,
     AddItem( p_playlist, p_item_cat, p_direct_parent, 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;
 
@@ -375,6 +360,8 @@ void playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
 playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
                                       playlist_item_t *p_item )
 {
+
+    playlist_item_t *p_item_in_category;
     /* What we do
      * Find the input in CATEGORY.
      *  - If we find it
@@ -389,8 +376,12 @@ playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
      * useful for later BothAddInput )
      */
 
+    /* Fast track the media library, no time to loose */
+    if( p_item == p_playlist->p_ml_category )
+        return p_item;
+
     /** \todo First look if we don't already have it */
-    playlist_item_t *p_item_in_category = playlist_ItemFindFromInputAndRoot(
+    p_item_in_category = playlist_ItemFindFromInputAndRoot(
                                             p_playlist, p_item->p_input->i_id,
                                             p_playlist->p_root_category );
 
@@ -406,9 +397,10 @@ playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
         }
         else
         {
-            playlist_DeleteFromInput( p_playlist, p_item->p_input->i_id,
+            playlist_DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
                                       p_playlist->p_root_onelevel, VLC_FALSE );
         }
+        p_playlist->b_reset_random = VLC_TRUE;
         var_SetInteger( p_playlist, "item-change", p_item->p_input->i_id );
         return p_item_in_category;
     }
@@ -501,6 +493,7 @@ void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
     p_add->i_item = i_item_id;
     p_add->i_node = i_node_id;
     val.p_address = p_add;
+    p_playlist->b_reset_random = VLC_TRUE;
     var_Set( p_playlist, "item-append", val );
     free( p_add );
 }
@@ -521,38 +514,6 @@ int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
     return VLC_EGENERIC;
 }
 
-/** Set the duration of a playlist item
- * \param i_duration the new duration in microseconds
- */
-int playlist_ItemSetDuration( playlist_item_t *p_item, mtime_t i_duration )
-{
-    char psz_buffer[MSTRTIME_MAX_SIZE];
-    if( p_item )
-    {
-        p_item->p_input->i_duration = i_duration;
-        if( i_duration != -1 )
-        {
-            secstotimestr( psz_buffer, (int)(i_duration/1000000) );
-        }
-        else
-        {
-            memcpy( psz_buffer, "--:--:--", sizeof("--:--:--") );
-        }
-        vlc_input_item_AddInfo( p_item->p_input, _("General") , _("Duration"),
-                                "%s", psz_buffer );
-
-        return VLC_SUCCESS;
-    }
-    return VLC_EGENERIC;
-}
-
-/** Add an option to a playlist item */
-void playlist_ItemAddOption( playlist_item_t *p_item,
-                             const char *psz_option)
-{
-    vlc_input_item_AddOption( p_item->p_input, psz_option );
-}
-
 /***************************************************************************
  * The following functions are local
  ***************************************************************************/
@@ -599,13 +560,6 @@ void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
 {
     INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size,
                  p_playlist->i_size, p_item );
-#if 0
-    fprintf( stderr, "Adding input %s (id %i) - playlist item id %i "
-                     "to node %s (id %i)\n",
-                     p_item->p_input->psz_name, p_item->p_input->i_id,
-                     p_item->i_id, p_node->p_input->psz_name,
-                     p_node->i_id );
-#endif
     INSERT_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
                  p_playlist->i_all_size, p_item );
     p_playlist->i_enabled ++;
@@ -647,13 +601,11 @@ int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
     int i_id = p_item->i_id;
     vlc_bool_t b_flag = VLC_FALSE;
 
-    //fprintf( stderr, "Deleting item %i - %s\n", i_id,
-    //                                            p_item->p_input->psz_name );
-
     if( p_item->i_children > -1 )
     {
         return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
     }
+    p_playlist->b_reset_random = VLC_TRUE;
     var_SetInteger( p_playlist, "item-deleted", i_id );
 
     /* Remove the item from the bank */
@@ -683,7 +635,7 @@ int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
         /* Hack we don't call playlist_Control for lock reasons */
         if( b_stop )
         {
-            p_playlist->status.i_status = PLAYLIST_STOPPED;
+            p_playlist->request.i_status = PLAYLIST_STOPPED;
             p_playlist->request.b_request = VLC_TRUE;
             p_playlist->request.p_item = NULL;
             msg_Info( p_playlist, "stopping playback" );
@@ -691,8 +643,7 @@ int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
         b_flag = VLC_TRUE;
     }
 
-    msg_Dbg( p_playlist, "deleting playlist item `%s'",
-                          p_item->p_input->psz_name );
+    PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
 
     /* Remove the item from its parent */
     playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
@@ -700,7 +651,10 @@ int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
     if( b_flag == VLC_FALSE )
         playlist_ItemDelete( p_item );
     else
+    {
+        PL_DEBUG( "marking %s for further deletion", PLI_NAME( p_item ) );
         p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
+    }
 
     return VLC_SUCCESS;
 }