Changeset 48586f51f89bd34422d50520fffea10f0f1ba402

Show
Ignore:
Timestamp:
24/08/07 16:02:11 (1 year ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1187964131 +0000
git-parent:

[9bd5dd03ed6b9fc925810faeb61a9558bbc85d99]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1187964131 +0000
Message:

media_list.c: Handle item addition and removal in the flat list. Also Get the media_list to init and release the flat media list.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/control/flat_media_list.c

    r9dba5e1 r48586f5  
    3131 * Private functions 
    3232 */ 
     33static void add_media_list( libvlc_media_list_t * p_mlist, libvlc_media_list_t * p_submlist ); 
     34static void remove_media_list( libvlc_media_list_t * p_fmlist, libvlc_media_list_t * p_mlist ); 
    3335static void add_item( libvlc_media_list_t * p_mlist, libvlc_media_descriptor_t * p_md ); 
    3436static void remove_item( libvlc_media_list_t * p_mlist, libvlc_media_descriptor_t * p_md ); 
     
    3638static void sublist_item_added( const libvlc_event_t * p_event, void * p_user_data ); 
    3739static void sublist_item_removed( const libvlc_event_t * p_event, void * p_user_data ); 
    38 static void add_media_list( libvlc_media_list_t * p_mlist, libvlc_media_list_t * p_submlist ); 
    39 static void remove_media_list( libvlc_media_list_t * p_fmlist, libvlc_media_list_t * p_mlist ); 
     40static void install_flat_mlist_observer( libvlc_media_list_t * p_mlist ); 
     41static void uninstall_flat_mlist_observer( libvlc_media_list_t * p_mlist ); 
     42 
     43/************************************************************************** 
     44 *       uninstall_media_list_observer (Private) 
     45 **************************************************************************/ 
     46static void 
     47uninstall_media_list_observer( libvlc_media_list_t * p_mlist, 
     48                             libvlc_media_list_t * p_submlist ) 
     49
     50    libvlc_event_detach( p_submlist->p_event_manager, 
     51                         libvlc_MediaListItemAdded, 
     52                         sublist_item_added, p_mlist, NULL ); 
     53    libvlc_event_detach( p_submlist->p_event_manager, 
     54                         libvlc_MediaListItemDeleted, 
     55                         sublist_item_removed, p_mlist, NULL ); 
     56 
     57
     58 
     59/************************************************************************** 
     60 *       install_media_list_observer (Private) 
     61 **************************************************************************/ 
     62static void 
     63install_media_list_observer( libvlc_media_list_t * p_mlist, 
     64                             libvlc_media_list_t * p_submlist ) 
     65
     66    libvlc_event_attach( p_submlist->p_event_manager, 
     67                         libvlc_MediaListItemAdded, 
     68                         sublist_item_added, p_mlist, NULL ); 
     69    libvlc_event_attach( p_submlist->p_event_manager, 
     70                         libvlc_MediaListItemDeleted, 
     71                         sublist_item_removed, p_mlist, NULL ); 
     72
     73 
     74/************************************************************************** 
     75 *       add_media_list (Private) 
     76 **************************************************************************/ 
     77static void 
     78add_media_list( libvlc_media_list_t * p_mlist, 
     79                libvlc_media_list_t * p_submlist ) 
     80
     81    int count = libvlc_media_list_count( p_submlist, NULL ); 
     82    int i; 
     83 
     84    for( i = 0; i < count; i++ ) 
     85    { 
     86        libvlc_media_descriptor_t * p_md; 
     87        p_md = libvlc_media_list_item_at_index( p_submlist, i, NULL ); 
     88        add_item( p_mlist->p_flat_mlist, p_md ); 
     89    } 
     90    install_media_list_observer( p_mlist, p_submlist ); 
     91
     92 
     93/************************************************************************** 
     94 *       remove_media_list (Private) 
     95 **************************************************************************/ 
     96static void 
     97remove_media_list( libvlc_media_list_t * p_mlist, 
     98                   libvlc_media_list_t * p_submlist ) 
     99
     100    int count = libvlc_media_list_count( p_submlist, NULL );     
     101    int i; 
     102    uninstall_media_list_observer( p_mlist, p_submlist ); 
     103 
     104    for( i = 0; i < count; i++ ) 
     105    { 
     106        libvlc_media_descriptor_t * p_md; 
     107        p_md = libvlc_media_list_item_at_index( p_submlist, i, NULL ); 
     108        remove_item( p_mlist, p_md ); 
     109    } 
     110
     111 
    40112 
    41113/************************************************************************** 
     
    57129                                 libvlc_MediaDescriptorSubItemAdded, 
    58130                                 subitems_created, p_mlist, NULL ); 
     131            uninstall_flat_mlist_observer( p_mlist ); 
    59132            libvlc_media_list_add_media_descriptor( p_mlist->p_flat_mlist, 
    60133                                                    p_md, NULL ); 
     134            install_flat_mlist_observer( p_mlist );            
    61135        } 
    62136    } 
     
    75149                         subitems_created, p_mlist, NULL ); 
    76150    int i = libvlc_media_list_index_of_item( p_mlist->p_flat_mlist, p_md, NULL ); 
     151    uninstall_flat_mlist_observer( p_mlist ); 
    77152    libvlc_media_list_remove_index( p_mlist->p_flat_mlist, i, NULL ); 
     153    install_flat_mlist_observer( p_mlist ); 
    78154} 
    79155 
     
    118194 
    119195/************************************************************************** 
    120  *       add_media_list (Private) 
    121  **************************************************************************/ 
    122 void 
    123 add_media_list( libvlc_media_list_t * p_mlist, 
    124                 libvlc_media_list_t * p_submlist ) 
    125 
    126     int count = libvlc_media_list_count( p_submlist, NULL ); 
    127     int i; 
    128  
    129     libvlc_event_attach( p_submlist->p_event_manager, 
    130                          libvlc_MediaListItemAdded, 
    131                          sublist_item_added, p_mlist, NULL ); 
    132     libvlc_event_attach( p_submlist->p_event_manager, 
    133                          libvlc_MediaListItemDeleted, 
    134                          sublist_item_removed, p_mlist, NULL ); 
    135     for( i = 0; i < count; i++ ) 
    136     { 
    137         libvlc_media_descriptor_t * p_md; 
    138         p_md = libvlc_media_list_item_at_index( p_submlist, i, NULL ); 
    139         add_item( p_mlist->p_flat_mlist, p_md );     
    140     } 
    141 
    142  
    143 /************************************************************************** 
    144  *       remove_media_list (Private) 
    145  **************************************************************************/ 
    146 void 
    147 remove_media_list( libvlc_media_list_t * p_mlist, 
    148                    libvlc_media_list_t * p_submlist ) 
    149 
     196 *       remove_item_in_submlist_rec (private) 
     197 **************************************************************************/ 
     198static void 
     199remove_item_in_submlist_rec( libvlc_media_list_t * p_mlist, 
     200                             libvlc_media_list_t * p_submlist, 
     201                             libvlc_media_descriptor_t * p_md ) 
     202
     203    libvlc_media_descriptor_t * p_md_insub;     
    150204    int count = libvlc_media_list_count( p_submlist, NULL );     
    151205    int i; 
    152206    for( i = 0; i < count; i++ ) 
    153207    { 
    154         libvlc_media_descriptor_t * p_md; 
    155         p_md = libvlc_media_list_item_at_index( p_submlist, i, NULL ); 
    156         remove_item( p_mlist, p_md ); 
    157     } 
    158      
    159     libvlc_event_detach( p_mlist->p_event_manager, 
     208        p_md_insub = libvlc_media_list_item_at_index( p_submlist, 
     209                                                      i, NULL ); 
     210        if( p_md_insub->p_subitems ) 
     211            remove_item_in_submlist_rec( p_mlist, p_submlist, p_md ); 
     212        if( p_md == p_md_insub ) 
     213        { 
     214            uninstall_media_list_observer( p_mlist, p_submlist ); 
     215            libvlc_media_list_remove_index( p_submlist, i, NULL ); 
     216            install_media_list_observer( p_mlist, p_submlist ); 
     217        } 
     218    } 
     219
     220 
     221/************************************************************************** 
     222 *       flat_mlist_item_removed (private) (Event Callback) 
     223 **************************************************************************/ 
     224static void 
     225flat_mlist_item_removed( const libvlc_event_t * p_event, void * p_user_data ) 
     226
     227    /* Remove all occurences of that one in sublist */ 
     228    libvlc_media_list_t * p_mlist = p_user_data; 
     229    libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_deleted.item; 
     230    remove_item( p_mlist, p_md ); /* Just to detach the event */ 
     231    remove_item_in_submlist_rec( p_mlist, p_mlist, p_md ); 
     232
     233 
     234/************************************************************************** 
     235 *       flat_mlist_item_added (private) (Event Callback) 
     236 **************************************************************************/ 
     237static void 
     238flat_mlist_item_added( const libvlc_event_t * p_event, void * p_user_data ) 
     239
     240    libvlc_media_list_t * p_mlist = p_user_data; 
     241    libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_added.item; 
     242 
     243    /* Add in our root */ 
     244    uninstall_media_list_observer( p_mlist, p_mlist );     
     245    libvlc_media_list_add_media_descriptor( p_mlist, p_md, NULL ); 
     246    install_media_list_observer( p_mlist, p_mlist ); 
     247
     248 
     249/************************************************************************** 
     250 *       install_flat_mlist_observer (Private) 
     251 **************************************************************************/ 
     252static void 
     253install_flat_mlist_observer( libvlc_media_list_t * p_mlist ) 
     254
     255    libvlc_event_attach( p_mlist->p_flat_mlist->p_event_manager, 
    160256                         libvlc_MediaListItemAdded, 
    161                          sublist_item_added, p_mlist, NULL ); 
    162     libvlc_event_detach( p_mlist->p_event_manager, 
     257                         flat_mlist_item_added, p_mlist, NULL ); 
     258    libvlc_event_attach( p_mlist->p_flat_mlist->p_event_manager, 
    163259                         libvlc_MediaListItemDeleted, 
    164                          sublist_item_removed, p_mlist, NULL ); 
    165 
    166  
     260                         flat_mlist_item_removed, p_mlist, NULL ); 
     261 
     262
     263 
     264/************************************************************************** 
     265 *       uninstall_flat_mlist_observer (Private) 
     266 **************************************************************************/ 
     267static void 
     268uninstall_flat_mlist_observer( libvlc_media_list_t * p_mlist ) 
     269
     270    libvlc_event_detach( p_mlist->p_flat_mlist->p_event_manager, 
     271                         libvlc_MediaListItemAdded, 
     272                         flat_mlist_item_added, p_mlist, NULL ); 
     273    libvlc_event_attach( p_mlist->p_flat_mlist->p_event_manager, 
     274                         libvlc_MediaListItemDeleted, 
     275                         flat_mlist_item_removed, p_mlist, NULL ); 
     276 
     277
     278 
     279/* 
     280 * libvlc Internal functions 
     281 */ 
     282/************************************************************************** 
     283 *       flat_media_list_release (Internal) 
     284 **************************************************************************/ 
     285void 
     286libvlc_media_list_flat_media_list_release( libvlc_media_list_t * p_mlist ) 
     287
     288    if( !p_mlist->p_flat_mlist ) 
     289        return; 
     290    uninstall_flat_mlist_observer( p_mlist ); 
     291    libvlc_media_list_release( p_mlist->p_flat_mlist ); 
     292
    167293 
    168294/* 
     
    183309                                            p_e ); 
    184310        add_media_list( p_mlist->p_flat_mlist, p_mlist ); 
     311        install_flat_mlist_observer( p_mlist ); 
    185312    } 
    186313    libvlc_media_list_retain( p_mlist->p_flat_mlist ); 
  • src/control/libvlc_internal.h

    r9dba5e1 r48586f5  
    247247                        ( libvlc_media_descriptor_t * ) ); 
    248248 
     249/* Media List */ 
     250VLC_EXPORT ( void, libvlc_media_list_flat_media_list_release, 
     251                        ( libvlc_media_list_t * ) ); 
     252 
    249253/* Events */ 
    250254VLC_EXPORT (void, libvlc_event_init, ( libvlc_instance_t *p_instance, libvlc_exception_t *p_e ) ); 
  • src/control/media_list.c

    r8375127 r48586f5  
    218218 
    219219    /* Handled in flat_media_list.c */ 
    220     if( p_mlist->p_flat_mlist ) 
    221         libvlc_media_list_release( p_mlist->p_flat_mlist ); 
     220    libvlc_media_list_flat_media_list_release( p_mlist ); 
    222221 
    223222    libvlc_event_manager_release( p_mlist->p_event_manager );