*
* \param p_ml a media list instance
* \param p_mi a media instance
- * \param p_e initialized exception object
+ * \return 0 on success, -1 if the media list is read-only
*/
-VLC_PUBLIC_API void
- libvlc_media_list_add_media( libvlc_media_list_t *,
- libvlc_media_t *,
- libvlc_exception_t * );
+VLC_PUBLIC_API int
+libvlc_media_list_add_media( libvlc_media_list_t *, libvlc_media_t * );
/**
* Insert media instance in media list on a position
* \param p_ml a media list instance
* \param p_mi a media instance
* \param i_pos position in array where to insert
- * \param p_e initialized exception object
+ * \return 0 on success, -1 if the media list si read-only
*/
-VLC_PUBLIC_API void
- libvlc_media_list_insert_media( libvlc_media_list_t *,
- libvlc_media_t *,
- int,
- libvlc_exception_t * );
+VLC_PUBLIC_API int
+libvlc_media_list_insert_media( libvlc_media_list_t *,
+ libvlc_media_t *, int );
+
/**
* Remove media instance from media list on a position
* The libvlc_media_list_lock should be held upon entering this function.
*
* \param p_ml a media list instance
* \param i_pos position in array where to insert
- * \param p_e initialized exception object
+ * \return 0 on success, -1 if the list is read-only or the item was not found
*/
-VLC_PUBLIC_API void
- libvlc_media_list_remove_index( libvlc_media_list_t *, int,
- libvlc_exception_t * );
+VLC_PUBLIC_API int
+libvlc_media_list_remove_index( libvlc_media_list_t *, int );
/**
* Get count on media list items
*
* \param p_ml a media list instance
* \param i_pos position in array where to insert
- * \param p_e initialized exception object
- * \return media instance at position i_pos and libvlc_media_retain() has been called to increase the refcount on this object.
+ * \return media instance at position i_pos, or NULL if not found.
+ * In case of success, libvlc_media_retain() is called to increase the refcount
+ * on the media.
*/
VLC_PUBLIC_API libvlc_media_t *
- libvlc_media_list_item_at_index( libvlc_media_list_t *, int,
- libvlc_exception_t * );
+ libvlc_media_list_item_at_index( libvlc_media_list_t *, int );
/**
* Find index position of List media instance in media list.
* Warning: the function will return the first matched position.
}
if( p_md->p_subitems )
{
- libvlc_media_list_add_media( p_md->p_subitems, p_md_child, NULL );
+ libvlc_media_list_add_media( p_md->p_subitems, p_md_child );
}
/* Construct the event */
libvlc_media_list_lock( p_mdis->p_mlist );
for( i = 0; i < count; i++ )
{
- p_md = libvlc_media_list_item_at_index( p_mdis->p_mlist, i, NULL );
+ p_md = libvlc_media_list_item_at_index( p_mdis->p_mlist, i );
if( p_md->p_input_item == p_item )
{
- _libvlc_media_list_remove_index( p_mdis->p_mlist, i, NULL );
+ _libvlc_media_list_remove_index( p_mdis->p_mlist, i );
break;
}
}
/**************************************************************************
* static mlist_is_writable (private)
- *
- * Raise exception and return 0 when the media_list instance is read-only,
- * or else return 1.
**************************************************************************/
static inline
-int mlist_is_writable( libvlc_media_list_t *p_mlist, libvlc_exception_t *p_e )
+bool mlist_is_writable( libvlc_media_list_t *p_mlist )
{
if( !p_mlist||p_mlist->b_read_only )
{
/* We are read-only from user side */
- libvlc_exception_raise( p_e );
libvlc_printerr( "Attempt to write a read-only media list" );
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/*
return;
}
- libvlc_media_list_add_media( p_mlist, p_md, p_e );
- if( libvlc_exception_raised( p_e ) )
+ if( libvlc_media_list_add_media( p_mlist, p_md ) )
+ {
+ libvlc_exception_raise( p_e );
return;
+ }
input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item );
*
* Lock should be held when entering.
**************************************************************************/
-void libvlc_media_list_add_media(
- libvlc_media_list_t * p_mlist,
- libvlc_media_t * p_md,
- libvlc_exception_t * p_e )
+int libvlc_media_list_add_media( libvlc_media_list_t * p_mlist,
+ libvlc_media_t * p_md )
{
- if( mlist_is_writable(p_mlist,p_e) )
- _libvlc_media_list_add_media( p_mlist, p_md );
+ if( !mlist_is_writable(p_mlist) )
+ return -1;
+ _libvlc_media_list_add_media( p_mlist, p_md );
+ return 0;
}
/* LibVLC internal version */
*
* Lock should be hold when entering.
**************************************************************************/
-void libvlc_media_list_insert_media(
- libvlc_media_list_t * p_mlist,
- libvlc_media_t * p_md,
- int index,
- libvlc_exception_t * p_e )
+int libvlc_media_list_insert_media( libvlc_media_list_t * p_mlist,
+ libvlc_media_t * p_md,
+ int index )
{
- if( mlist_is_writable(p_mlist,p_e) )
- _libvlc_media_list_insert_media( p_mlist, p_md, index );
+ if( !mlist_is_writable(p_mlist) )
+ return -1;
+ _libvlc_media_list_insert_media( p_mlist, p_md, index );
+ return 0;
}
/* LibVLC internal version */
*
* Lock should be held when entering.
**************************************************************************/
-void libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
- int index,
- libvlc_exception_t * p_e )
+int libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
+ int index )
{
- if( mlist_is_writable(p_mlist,p_e) )
- _libvlc_media_list_remove_index( p_mlist, index, p_e );
+ if( !mlist_is_writable(p_mlist) )
+ return -1;
+ return _libvlc_media_list_remove_index( p_mlist, index );
}
/* LibVLC internal version */
-void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
- int index,
- libvlc_exception_t * p_e )
+int _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
+ int index )
{
libvlc_media_t * p_md;
if( index < 0 || index >= vlc_array_count( &p_mlist->items ))
{
- libvlc_exception_raise( p_e );
libvlc_printerr( "Index out of bounds" );
- return;
+ return -1;
}
p_md = vlc_array_item_at_index( &p_mlist->items, index );
notify_item_deletion( p_mlist, p_md, index, EventDidHappen );
libvlc_media_release( p_md );
+ return 0;
}
/**************************************************************************
**************************************************************************/
libvlc_media_t *
libvlc_media_list_item_at_index( libvlc_media_list_t * p_mlist,
- int index,
- libvlc_exception_t * p_e )
+ int index )
{
libvlc_media_t * p_md;
if( index < 0 || index >= vlc_array_count( &p_mlist->items ))
{
- libvlc_exception_raise( p_e );
libvlc_printerr( "Index out of bounds" );
return NULL;
}
libvlc_media_list_t * p_mlist,
libvlc_media_t * p_md, int index );
-void _libvlc_media_list_remove_index(
- libvlc_media_list_t * p_mlist, int index,
- libvlc_exception_t * p_e );
+int _libvlc_media_list_remove_index(
+ libvlc_media_list_t * p_mlist, int index );
#endif
count = libvlc_media_list_count( p_current_mlist );
for( i = 0; i < count; i++ )
{
- libvlc_media_t * p_md = libvlc_media_list_item_at_index( p_current_mlist, i, NULL );
+ libvlc_media_t * p_md = libvlc_media_list_item_at_index( p_current_mlist, i );
if( p_md == p_searched_md )
return libvlc_media_list_path_copy_by_appending( path, i ); /* Found! */
int i;
for( i = 0; path[i] != -1; i++ )
{
- p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i], NULL );
+ p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i] );
if( p_current_mlist != p_mlist )
libvlc_media_list_release( p_current_mlist );
return p_current_mlist;
}
- p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i], NULL );
+ p_md = libvlc_media_list_item_at_index( p_current_mlist, path[i] );
p_current_mlist = libvlc_media_subitems( p_md );
libvlc_media_release( p_md );
libvlc_instance_t *vlc;
libvlc_media_t *md1, *md2, *md3, *md4;
libvlc_media_list_t *ml;
+ int ret;
log ("Testing media_list\n");
md3 = libvlc_media_new (vlc, "/dev/null");
assert (md3 != NULL);
- libvlc_media_list_add_media (ml, md1, &ex);
- catch ();
- libvlc_media_list_add_media (ml, md2, &ex);
- catch ();
+ ret = libvlc_media_list_add_media (ml, md1);
+ assert (!ret);
+ ret = libvlc_media_list_add_media (ml, md2);
+ assert (!ret);
assert( libvlc_media_list_count (ml) == 2 );
assert( libvlc_media_list_index_of_item (ml, md1) == 0 );
assert( libvlc_media_list_index_of_item (ml, md2) == 1 );
- libvlc_media_list_remove_index (ml, 0, &ex); /* removing first item */
- catch ();
+ ret = libvlc_media_list_remove_index (ml, 0); /* removing first item */
+ assert (!ret);
/* test if second item was moved on first place */
assert( libvlc_media_list_index_of_item (ml, md2) == 0 );
- libvlc_media_list_add_media (ml, md1, &ex); /* add 2 items */
- catch ();
- libvlc_media_list_add_media (ml, md1, &ex);
- catch ();
+ ret = libvlc_media_list_add_media (ml, md1); /* add 2 items */
+ assert (!ret);
+ ret = libvlc_media_list_add_media (ml, md1);
+ assert (!ret);
/* there should be 3 pieces */
assert( libvlc_media_list_count (ml) == 3 );
- libvlc_media_list_insert_media (ml, md3, 2, &ex);
- catch ();
+ ret = libvlc_media_list_insert_media (ml, md3, 2);
+ assert (!ret);
/* there should be 4 pieces */
assert( libvlc_media_list_count (ml) == 4 );
assert( libvlc_media_list_index_of_item (ml, md3) == 2 );
/* test right returning descriptor*/
- assert ( libvlc_media_list_item_at_index (ml, 0, &ex) == md2 );
- catch ();
+ assert ( libvlc_media_list_item_at_index (ml, 0) == md2 );
- assert ( libvlc_media_list_item_at_index (ml, 2, &ex) == md3 );
- catch ();
+ assert ( libvlc_media_list_item_at_index (ml, 2) == md3 );
/* test if give exceptions, when it should */
/* have 4 items, so index 4 should give exception */
- libvlc_media_list_remove_index (ml, 4, &ex);
- assert (have_exception ());
+ ret = libvlc_media_list_remove_index (ml, 4);
+ assert (ret == -1);
- libvlc_media_list_remove_index (ml, 100, &ex);
- assert (have_exception ());
+ ret = libvlc_media_list_remove_index (ml, 100);
+ assert (ret == -1);
- libvlc_media_list_remove_index (ml, -1, &ex);
- assert (have_exception ());
+ ret = libvlc_media_list_remove_index (ml, -1);
+ assert (ret == -1);
/* getting non valid items */
libvlc_media_t * p_non_exist =
- libvlc_media_list_item_at_index (ml, 4, &ex);
- assert (have_exception ());
+ libvlc_media_list_item_at_index (ml, 4);
+ assert (p_non_exist == NULL);
- p_non_exist = libvlc_media_list_item_at_index (ml, 100, &ex);
- assert (have_exception ());
+ p_non_exist = libvlc_media_list_item_at_index (ml, 100);
+ assert (p_non_exist == NULL);
- p_non_exist = libvlc_media_list_item_at_index (ml, -1, &ex);
- assert (have_exception ());
+ p_non_exist = libvlc_media_list_item_at_index (ml, -1);
+ assert (p_non_exist == NULL);
md4 = libvlc_media_new (vlc, "/dev/null");
assert (md4 != NULL);