]> git.sesse.net Git - vlc/blobdiff - lib/media_list.c
direct3d11: give enough room for the \0 in the string
[vlc] / lib / media_list.c
index 0691a2c90a5ce588e1e5b2e704a72b68f0955a99..d4dae1afad310a35797bf28248f896a929aa7436 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * media_list.c: libvlc new API media list functions
  *****************************************************************************
- * Copyright (C) 2007 the VideoLAN team
+ * Copyright (C) 2007 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -44,14 +44,6 @@ typedef enum EventPlaceInTime {
     EventDidHappen
 } EventPlaceInTime;
 
-//#define DEBUG_MEDIA_LIST
-
-#ifdef DEBUG_MEDIA_LIST
-# define trace( fmt, ... ) printf( "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__ )
-#else
-# define trace( ... )
-#endif
-
 /*
  * Private functions
  */
@@ -74,7 +66,6 @@ notify_item_addition( libvlc_media_list_t * p_mlist,
     /* Construct the event */
     if( event_status == EventDidHappen )
     {
-        trace("item was added at index %d\n", index);
         event.type = libvlc_MediaListItemAdded;
         event.u.media_list_item_added.item = p_md;
         event.u.media_list_item_added.index = index;
@@ -106,7 +97,6 @@ notify_item_deletion( libvlc_media_list_t * p_mlist,
     /* Construct the event */
     if( event_status == EventDidHappen )
     {
-        trace("item at index %d was deleted\n", index);
         event.type = libvlc_MediaListItemDeleted;
         event.u.media_list_item_deleted.item = p_md;
         event.u.media_list_item_deleted.index = index;
@@ -122,6 +112,17 @@ notify_item_deletion( libvlc_media_list_t * p_mlist,
     libvlc_event_send( p_mlist->p_event_manager, &event );
 }
 
+/* LibVLC internal */
+void libvlc_media_list_internal_end_reached( libvlc_media_list_t * p_mlist )
+{
+    libvlc_event_t event;
+
+    event.type = libvlc_MediaListEndReached;
+
+    /* Send the event */
+    libvlc_event_send( p_mlist->p_event_manager, &event );
+}
+
 /**************************************************************************
  *       static mlist_is_writable (private)
  **************************************************************************/
@@ -166,8 +167,6 @@ libvlc_media_list_new( libvlc_instance_t * p_inst )
         return NULL;
     }
 
-    /* Code for that one should be handled in flat_media_list.c */
-    p_mlist->p_flat_mlist = NULL;
     p_mlist->b_read_only = false;
 
     libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
@@ -178,6 +177,8 @@ libvlc_media_list_new( libvlc_instance_t * p_inst )
             libvlc_MediaListItemDeleted );
     libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
             libvlc_MediaListWillDeleteItem );
+    libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
+            libvlc_MediaListEndReached );
 
     vlc_mutex_init( &p_mlist->object_lock );
     vlc_mutex_init( &p_mlist->refcount_lock ); // FIXME: spinlock?
@@ -186,6 +187,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst )
     assert( p_mlist->items.i_count == 0 );
     p_mlist->i_refcount = 1;
     p_mlist->p_md = NULL;
+    p_mlist->p_internal_md = NULL;
 
     return p_mlist;
 }
@@ -222,6 +224,7 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
     }
 
     vlc_mutex_destroy( &p_mlist->object_lock );
+    vlc_mutex_destroy( &p_mlist->refcount_lock );
     vlc_array_clear( &p_mlist->items );
 
     free( p_mlist );
@@ -286,6 +289,11 @@ void libvlc_media_list_set_media( libvlc_media_list_t * p_mlist,
 
 {
     vlc_mutex_lock( &p_mlist->object_lock );
+    if( p_mlist->p_internal_md || !mlist_is_writable(p_mlist) )
+    {
+        vlc_mutex_unlock( &p_mlist->object_lock );
+        return;
+    }
     libvlc_media_release( p_mlist->p_md );
     libvlc_media_retain( p_md );
     p_mlist->p_md = p_md;
@@ -307,7 +315,7 @@ libvlc_media_list_media( libvlc_media_list_t * p_mlist )
     libvlc_media_t *p_md;
 
     vlc_mutex_lock( &p_mlist->object_lock );
-    p_md = p_mlist->p_md;
+    p_md = p_mlist->p_internal_md ? p_mlist->p_internal_md : p_mlist->p_md;
     if( p_md )
         libvlc_media_retain( p_md );
     vlc_mutex_unlock( &p_mlist->object_lock );
@@ -335,13 +343,13 @@ int libvlc_media_list_add_media( libvlc_media_list_t * p_mlist,
 {
     if( !mlist_is_writable(p_mlist) )
         return -1;
-    _libvlc_media_list_add_media( p_mlist, p_md );
+    libvlc_media_list_internal_add_media( p_mlist, p_md );
     return 0;
 }
 
 /* LibVLC internal version */
-void _libvlc_media_list_add_media( libvlc_media_list_t * p_mlist,
-                                   libvlc_media_t * p_md )
+void libvlc_media_list_internal_add_media( libvlc_media_list_t * p_mlist,
+                                           libvlc_media_t * p_md )
 {
     libvlc_media_retain( p_md );
 
@@ -363,15 +371,14 @@ int libvlc_media_list_insert_media( libvlc_media_list_t * p_mlist,
 {
     if( !mlist_is_writable(p_mlist) )
         return -1;
-    _libvlc_media_list_insert_media( p_mlist, p_md, index );
+    libvlc_media_list_internal_insert_media( p_mlist, p_md, index );
     return 0;
 }
 
 /* LibVLC internal version */
-void _libvlc_media_list_insert_media(
-                                   libvlc_media_list_t * p_mlist,
-                                   libvlc_media_t * p_md,
-                                   int index )
+void libvlc_media_list_internal_insert_media( libvlc_media_list_t * p_mlist,
+                                              libvlc_media_t * p_md,
+                                              int index )
 {
     libvlc_media_retain( p_md );
 
@@ -390,12 +397,12 @@ int libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
 {
     if( !mlist_is_writable(p_mlist) )
         return -1;
-    return _libvlc_media_list_remove_index( p_mlist, index );
+    return libvlc_media_list_internal_remove_index( p_mlist, index );
 }
 
 /* LibVLC internal version */
-int _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
-                                     int index )
+int libvlc_media_list_internal_remove_index( libvlc_media_list_t * p_mlist,
+                                             int index )
 {
     libvlc_media_t * p_md;