]> git.sesse.net Git - vlc/blobdiff - src/control/media_list.c
Removes trailing spaces. Removes tabs.
[vlc] / src / control / media_list.c
index 461ffd5e71618eac5add9bf9f8c43e654a2687e9..db69555dc0a5b395e6f4605c0f391c89b4d1894e 100644 (file)
@@ -74,79 +74,6 @@ notify_item_deletion( libvlc_media_list_t * p_mlist,
     libvlc_event_send( p_mlist->p_event_manager, &event );
 }
 
-/**************************************************************************
- *       media_descriptor_changed (private) (libvlc Event Callback )
- *
- * An item has changed.
- **************************************************************************/
-static void
-media_descriptor_changed( const libvlc_event_t * p_event, void * user_data )
-{
-    libvlc_media_list_t * p_mlist = user_data;
-    libvlc_media_descriptor_t * p_md = p_event->p_obj;
-    libvlc_event_t event;
-    
-    /* Construct the new media list event */
-    event.type = libvlc_MediaListItemChanged;
-    event.u.media_list_item_changed.item = p_md;
-
-    /* XXX: this is not good, but there is a solution in the pipeline */
-    event.u.media_list_item_changed.index =
-        libvlc_media_list_index_of_item( p_mlist, p_md, NULL );
-
-    /* Send the event */
-    libvlc_event_send( p_mlist->p_event_manager, &event );
-}
-
-/**************************************************************************
- *       media_descriptor_subitem_added (private) (libvlc Event Callback )
- *
- * An item (which is a playlist) has gained sub child.
- **************************************************************************/
-static void
-media_descriptor_subitem_added( const libvlc_event_t * p_event, void * user_data )
-{
-    /* Todo: Just forward that event to our event_manager */
-}
-
-/**************************************************************************
- *       install_media_descriptor_observer (private)
- *
- * Do the appropriate action when an item is deleted.
- **************************************************************************/
-static void
-install_media_descriptor_observer( libvlc_media_list_t * p_mlist,
-                                   libvlc_media_descriptor_t * p_md )
-{
-    libvlc_event_attach( p_md->p_event_manager,
-                         libvlc_MediaDescriptorMetaChanged,
-                         media_descriptor_changed,
-                         p_mlist, NULL );
-    libvlc_event_attach( p_md->p_event_manager,
-                         libvlc_MediaDescriptorSubItemAdded,
-                         media_descriptor_subitem_added,
-                         p_mlist, NULL );
-}
-
-/**************************************************************************
- *       uninstall_media_descriptor_observer (private)
- *
- * Do the appropriate action when an item is deleted.
- **************************************************************************/
-static void
-uninstall_media_descriptor_observer( libvlc_media_list_t * p_mlist,
-                                     libvlc_media_descriptor_t * p_md )
-{
-    libvlc_event_detach( p_md->p_event_manager,
-                         libvlc_MediaDescriptorMetaChanged,
-                         media_descriptor_changed,
-                         p_mlist, NULL );
-    libvlc_event_detach( p_md->p_event_manager,
-                         libvlc_MediaDescriptorSubItemAdded,
-                         media_descriptor_subitem_added,
-                         p_mlist, NULL );
-}
-
 /*
  * Public libvlc functions
  */
@@ -166,7 +93,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
 
     if( !p_mlist )
         return NULL;
-    
     p_mlist->p_libvlc_instance = p_inst;
     p_mlist->p_event_manager = libvlc_event_manager_new( p_mlist, p_inst, p_e );
 
@@ -175,8 +102,6 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
 
     libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
             libvlc_MediaListItemAdded, p_e );
-    libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
-            libvlc_MediaListItemChanged, p_e );
     libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
             libvlc_MediaListItemDeleted, p_e );
 
@@ -188,10 +113,10 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
     }
 
     vlc_mutex_init( p_inst->p_libvlc_int, &p_mlist->object_lock );
-    
     ARRAY_INIT(p_mlist->items);
     p_mlist->i_refcount = 1;
-    p_mlist->psz_name = NULL;
+    p_mlist->p_md = NULL;
 
     return p_mlist;
 }
@@ -209,21 +134,22 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
     p_mlist->i_refcount--;
     if( p_mlist->i_refcount > 0 )
     {
-        vlc_mutex_unlock( &p_mlist->object_lock );        
+        vlc_mutex_unlock( &p_mlist->object_lock );
         return;
     }
-    vlc_mutex_unlock( &p_mlist->object_lock );        
+    vlc_mutex_unlock( &p_mlist->object_lock );
 
     /* Refcount null, time to free */
 
     /* Handled in flat_media_list.c */
-    if( p_mlist->p_flat_mlist )
-        libvlc_media_list_release( p_mlist->p_flat_mlist );
+    libvlc_media_list_flat_media_list_release( p_mlist );
 
     libvlc_event_manager_release( p_mlist->p_event_manager );
 
+    if( p_mlist->p_md )
+        libvlc_media_descriptor_release( p_mlist->p_md );
+
     FOREACH_ARRAY( p_md, p_mlist->items )
-        uninstall_media_descriptor_observer( p_mlist, p_md );
         libvlc_media_descriptor_release( p_md );
     FOREACH_END()
  
@@ -283,34 +209,45 @@ libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist,
 }
 
 /**************************************************************************
- *       set_name (Public)
+ *       set_media_descriptor (Public)
  **************************************************************************/
-void libvlc_media_list_set_name( libvlc_media_list_t * p_mlist,
-                                 const char * psz_name,
-                                 libvlc_exception_t * p_e)
+void libvlc_media_list_set_media_descriptor( libvlc_media_list_t * p_mlist,
+                                             libvlc_media_descriptor_t * p_md,
+                                             libvlc_exception_t * p_e)
 
 {
     (void)p_e;
     vlc_mutex_lock( &p_mlist->object_lock );
-    free( p_mlist->psz_name );
-    p_mlist->psz_name = psz_name ? strdup( psz_name ) : NULL;
+    if( p_mlist->p_md )
+        libvlc_media_descriptor_release( p_mlist->p_md );
+    libvlc_media_descriptor_retain( p_md );
+    p_mlist->p_md = p_md;
     vlc_mutex_unlock( &p_mlist->object_lock );
 }
 
 /**************************************************************************
- *       name (Public)
+ *       media_descriptor (Public)
+ *
+ * If this media_list comes is a media_descriptor's subitems,
+ * This holds the corresponding media_descriptor.
+ * This md is also seen as the information holder for the media_list.
+ * Indeed a media_list can have meta information through this
+ * media_descriptor.
  **************************************************************************/
-char * libvlc_media_list_name( libvlc_media_list_t * p_mlist,
-                               libvlc_exception_t * p_e)
+libvlc_media_descriptor_t *
+libvlc_media_list_media_descriptor( libvlc_media_list_t * p_mlist,
+                                    libvlc_exception_t * p_e)
 {
-    char *ret;
+    libvlc_media_descriptor_t *p_md;
     (void)p_e;
 
     vlc_mutex_lock( &p_mlist->object_lock );
-    ret = p_mlist->psz_name ? strdup( p_mlist->psz_name ) : NULL;
+    p_md = p_mlist->p_md;
+    if( p_md )
+        libvlc_media_descriptor_retain( p_md );
     vlc_mutex_unlock( &p_mlist->object_lock );
 
-    return ret;
+    return p_md;
 }
 
 /**************************************************************************
@@ -330,16 +267,15 @@ int libvlc_media_list_count( libvlc_media_list_t * p_mlist,
  *
  * Lock should be hold when entering.
  **************************************************************************/
-void libvlc_media_list_add_media_descriptor( 
+void libvlc_media_list_add_media_descriptor(
                                    libvlc_media_list_t * p_mlist,
                                    libvlc_media_descriptor_t * p_md,
                                    libvlc_exception_t * p_e )
 {
     (void)p_e;
     libvlc_media_descriptor_retain( p_md );
-    ARRAY_APPEND( p_mlist->items, p_md );
+    ARRAY_INSERT( p_mlist->items, p_md, p_mlist->items.i_size );
     notify_item_addition( p_mlist, p_md, p_mlist->items.i_size-1 );
-    install_media_descriptor_observer( p_mlist, p_md );
 }
 
 /**************************************************************************
@@ -347,7 +283,7 @@ void libvlc_media_list_add_media_descriptor(
  *
  * Lock should be hold when entering.
  **************************************************************************/
-void libvlc_media_list_insert_media_descriptor( 
+void libvlc_media_list_insert_media_descriptor(
                                    libvlc_media_list_t * p_mlist,
                                    libvlc_media_descriptor_t * p_md,
                                    int index,
@@ -358,7 +294,6 @@ void libvlc_media_list_insert_media_descriptor(
 
     ARRAY_INSERT( p_mlist->items, p_md, index);
     notify_item_addition( p_mlist, p_md, index );
-    install_media_descriptor_observer( p_mlist, p_md );
 }
 
 /**************************************************************************
@@ -374,8 +309,6 @@ void libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
 
     p_md = ARRAY_VAL( p_mlist->items, index );
 
-    uninstall_media_descriptor_observer( p_mlist, p_md );
-
     ARRAY_REMOVE( p_mlist->items, index )
     notify_item_deletion( p_mlist, p_md, index );