#include <vlc/vlc.h>
#include <vlc/input.h>
#include <assert.h>
-#include "vlc_playlist.h"
+#include <vlc_playlist.h>
+#include "playlist_internal.h"
void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
playlist_item_t *p_node, int i_pos );
/*****************************************************************************
* 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 );
+ playlist_t *p_playlist = p_obj->p_libvlc->p_playlist;
+ vlc_object_yield( p_playlist );
p_item->p_input = p_input;
vlc_gc_incref( p_item->p_input );
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 */
/***************************************************************************
* 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
* \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
* \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 );
+ if( !p_playlist->b_doing_ml )
+ 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 );
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
*/
/* Fast track the media library, no time to loose */
- if( p_item == p_playlist->p_ml_category )
+ 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 );
p_playlist->p_root_onelevel );
ChangeToNode( p_playlist, p_item_in_category );
if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
- {
ChangeToNode( p_playlist, p_item_in_one );
- }
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 );
}
- var_SetInteger( p_playlist, "item-change", p_item->p_input->i_id );
+ p_playlist->b_reset_random = VLC_TRUE;
+ var_SetInteger( p_playlist, "item-change", p_item_in_category->
+ p_input->i_id );
return p_item_in_category;
}
else
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 );
}
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
***************************************************************************/
{
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 ++;
{
playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
}
-
- playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id );
+ if( !p_playlist->b_doing_ml )
+ playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id );
}
/* Actually convert an item to a node */
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 */
/* 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" );
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 );
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;
}