Changeset 1d2aca81f9ce226e86d286d19031b08a16db3c92

Show
Ignore:
Timestamp:
29/08/07 01:25:54 (1 year ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1188343554 +0000
git-parent:

[1f8d74b9502a2f9243ef91e02dd78b7be1ecb667]

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

control/media_list_player.c: Add support for playing a hierarchical media_list.

Files:

Legend:

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

    rf15a567 r1d2aca8  
    2323#include "libvlc_internal.h" 
    2424#include <vlc/libvlc.h> 
     25#include "media_list_path.h" 
    2526 
    2627/* 
     
    3334 * Simple next item fetcher. 
    3435 **************************************************************************/ 
    35 static int get_next_index( libvlc_media_list_player_t * p_mlp ) 
     36static libvlc_media_list_path_t 
     37get_next_path( libvlc_media_list_player_t * p_mlp ) 
    3638{ 
    3739    /* We are entered with libvlc_media_list_lock( p_mlp->p_list ) */ 
    38      
    39     int next = p_mlp->i_current_playing_index + 1; 
    40  
    41     if( next >= libvlc_media_list_count( p_mlp->p_mlist, NULL ) ) 
    42         return -1; /* no more to play */ 
    43  
    44     return next; 
     40    libvlc_media_list_path_t ret; 
     41    libvlc_media_list_t * p_parent_of_playing_item; 
     42    libvlc_media_list_t * p_sublist_of_playing_item; 
     43    p_sublist_of_playing_item = libvlc_media_list_sublist_at_path( 
     44                            p_mlp->p_mlist, 
     45                            p_mlp->current_playing_item_path ); 
     46     
     47    /* If item just gained a sublist just play it */ 
     48    if( p_sublist_of_playing_item ) 
     49    { 
     50        libvlc_media_list_release( p_sublist_of_playing_item ); 
     51        return libvlc_media_list_path_copy_by_appending( p_mlp->current_playing_item_path, 0 ); 
     52    } 
     53 
     54    /* Try to catch next element */ 
     55    p_parent_of_playing_item = libvlc_media_list_parentlist_at_path( 
     56                            p_mlp->p_mlist, 
     57                            p_mlp->current_playing_item_path ); 
     58 
     59    int deepness = libvlc_media_list_path_deepness( p_mlp->current_playing_item_path ); 
     60    if( deepness < 1 || !p_parent_of_playing_item ) 
     61        return NULL; 
     62 
     63    ret = libvlc_media_list_path_copy( p_mlp->current_playing_item_path ); 
     64 
     65    while( ret[deepness-1] >= libvlc_media_list_count( p_parent_of_playing_item, NULL ) ) 
     66    { 
     67        deepness--; 
     68        if( deepness <= 0 ) 
     69        { 
     70            free( ret ); 
     71            libvlc_media_list_release( p_parent_of_playing_item ); 
     72            return NULL; 
     73        } 
     74        ret[deepness] = -1; 
     75        ret[deepness-1]++; 
     76        p_parent_of_playing_item  = libvlc_media_list_parentlist_at_path( 
     77                                        p_mlp->p_mlist, 
     78                                        ret ); 
     79    } 
     80    libvlc_media_list_release( p_parent_of_playing_item ); 
     81    return ret; 
    4582} 
    4683 
     
    5592    libvlc_media_instance_t * p_mi = p_event->p_obj; 
    5693    libvlc_media_descriptor_t *p_md, * p_current_md; 
     94 
    5795    p_md = libvlc_media_instance_get_media_descriptor( p_mi, NULL ); 
    5896    /* XXX: need if p_mlp->p_current_playing_index is beyond */ 
    59     p_current_md = libvlc_media_list_item_at_index
     97    p_current_md = libvlc_media_list_item_at_path
    6098                        p_mlp->p_mlist, 
    61                         p_mlp->i_current_playing_index, 
    62                         NULL ); 
     99                        p_mlp->current_playing_item_path ); 
    63100    if( p_md != p_current_md ) 
    64101    { 
     
    84121    libvlc_media_list_t * p_emitting_mlist = p_event->p_obj; 
    85122    /* XXX: need if p_mlp->p_current_playing_index is beyond */ 
    86     p_current_md = libvlc_media_list_item_at_index
     123    p_current_md = libvlc_media_list_item_at_path
    87124                        p_mlp->p_mlist, 
    88                         p_mlp->i_current_playing_index, 
    89                         NULL ); 
     125                        p_mlp->current_playing_item_path ); 
    90126 
    91127    if( p_event->u.media_list_item_deleted.item == p_current_md && 
     
    147183                                    libvlc_exception_t * p_e ) 
    148184{ 
    149     libvlc_exception_raise( p_e, "Unimplemented" ); 
    150     return 0
    151 } 
    152  
    153 /************************************************************************** 
    154  *       Next (private) 
     185    //libvlc_exception_raise( p_e, "Unimplemented" ); 
     186    return 1
     187} 
     188 
     189/************************************************************************** 
     190 *       set_current_playing_item (private) 
    155191 * 
    156192 * Playlist lock should be held 
    157193 **************************************************************************/ 
    158194static void 
    159 media_list_player_set_next( libvlc_media_list_player_t * p_mlp, int index, 
    160                             libvlc_exception_t * p_e ) 
     195set_current_playing_item( libvlc_media_list_player_t * p_mlp, 
     196                          libvlc_media_list_path_t path, 
     197                          libvlc_exception_t * p_e ) 
    161198{ 
    162199    libvlc_media_descriptor_t * p_md; 
    163200     
    164     p_md = libvlc_media_list_item_at_index( p_mlp->p_mlist, index, p_e ); 
     201    p_md = libvlc_media_list_item_at_path( p_mlp->p_mlist, path ); 
    165202    if( !p_md ) 
    166203    { 
    167         libvlc_media_list_unlock( p_mlp->p_mlist );      
    168204        if( !libvlc_exception_raised( p_e ) ) 
    169205            libvlc_exception_raise( p_e, "Can't obtain a media" ); 
    170206        return; 
    171207    } 
    172  
     208     
    173209    vlc_mutex_lock( &p_mlp->object_lock ); 
    174210     
    175     p_mlp->i_current_playing_index = index; 
     211    free( p_mlp->current_playing_item_path ); 
     212    p_mlp->current_playing_item_path = path; 
    176213 
    177214    /* We are not interested in getting media_descriptor stop event now */ 
    178215    uninstall_media_instance_observer( p_mlp ); 
    179     libvlc_media_instance_set_media_descriptor( p_mlp->p_mi, p_md, NULL ); 
     216    if( p_md->p_subitems && libvlc_media_list_count( p_md->p_subitems, NULL ) > 0 ) 
     217    { 
     218        libvlc_media_descriptor_t * p_submd; 
     219        p_submd = libvlc_media_list_item_at_index( p_md->p_subitems, 0, NULL ); 
     220        libvlc_media_instance_set_media_descriptor( p_mlp->p_mi, p_submd, NULL ); 
     221        libvlc_media_descriptor_release( p_submd ); 
     222    } 
     223    else 
     224        libvlc_media_instance_set_media_descriptor( p_mlp->p_mi, p_md, NULL ); 
    180225//  wait_playing_state(); /* If we want to be synchronous */ 
    181226    install_media_instance_observer( p_mlp ); 
     
    202247    libvlc_media_list_player_t * p_mlp; 
    203248    p_mlp = malloc(sizeof(libvlc_media_list_player_t)); 
    204     p_mlp->i_current_playing_index = -1
     249    p_mlp->current_playing_item_path = NULL
    205250    p_mlp->p_mi = NULL; 
    206251    p_mlp->p_mlist = NULL; 
     
    222267void libvlc_media_list_player_release( libvlc_media_list_player_t * p_mlp ) 
    223268{ 
    224     libvlc_event_manager_release( p_mlp->p_event_manager ); 
    225269    free(p_mlp); 
    226270} 
     
    260304     
    261305    if( libvlc_media_list_player_is_playing( p_mlp, p_e ) ) 
    262         libvlc_media_list_player_stop( p_mlp, p_e ); 
     306    { 
     307        libvlc_media_instance_stop( p_mlp->p_mi, p_e ); 
     308        /* Don't bother if there was an error. */ 
     309        libvlc_exception_clear( p_e ); 
     310    } 
    263311 
    264312    if( p_mlp->p_mlist ) 
     
    281329                                  libvlc_exception_t * p_e ) 
    282330{ 
    283     if( p_mlp->i_current_playing_index < 0
     331    if( !p_mlp->current_playing_item_path
    284332    { 
    285333        libvlc_media_list_player_next( p_mlp, p_e ); 
     
    292340/************************************************************************** 
    293341 *        Play item at index (Public) 
    294  * 
    295  * Playlist lock should be help 
    296342 **************************************************************************/ 
    297343void libvlc_media_list_player_play_item_at_index( 
     
    300346                        libvlc_exception_t * p_e ) 
    301347{ 
    302     media_list_player_set_next( p_mlp, i_index, p_e ); 
     348    set_current_playing_item( p_mlp, libvlc_media_list_path_with_root_index(i_index), p_e ); 
    303349 
    304350    if( libvlc_exception_raised( p_e ) ) 
     
    313359} 
    314360 
     361/************************************************************************** 
     362 *        Play item (Public) 
     363 **************************************************************************/ 
     364void libvlc_media_list_player_play_item( 
     365                        libvlc_media_list_player_t * p_mlp, 
     366                        libvlc_media_descriptor_t * p_md, 
     367                        libvlc_exception_t * p_e ) 
     368{ 
     369    libvlc_media_list_path_t path = libvlc_media_list_path_of_item( p_mlp->p_mlist, p_md ); 
     370    if( !path ) 
     371    { 
     372        libvlc_exception_raise( p_e, "No such item in media list" ); 
     373        return; 
     374    } 
     375    set_current_playing_item( p_mlp, path, p_e ); 
     376 
     377    if( libvlc_exception_raised( p_e ) ) 
     378        return; 
     379 
     380    libvlc_media_instance_play( p_mlp->p_mi, p_e ); 
     381} 
    315382 
    316383/************************************************************************** 
     
    323390 
    324391    vlc_mutex_lock( &p_mlp->object_lock ); 
    325     p_mlp->i_current_playing_index = -1
     392    p_mlp->current_playing_item_path = NULL
    326393    vlc_mutex_unlock( &p_mlp->object_lock ); 
    327394} 
     
    333400                                    libvlc_exception_t * p_e ) 
    334401{    
    335     int index
     402    libvlc_media_list_path_t path
    336403     
    337404    libvlc_media_list_lock( p_mlp->p_mlist ); 
    338405 
    339     index = get_next_index( p_mlp ); 
    340  
    341     if( index < 0
     406    path = get_next_path( p_mlp ); 
     407 
     408    if( !path
    342409    { 
    343410        libvlc_media_list_unlock( p_mlp->p_mlist ); 
     
    347414    } 
    348415 
    349     media_list_player_set_next( p_mlp, index, p_e ); 
     416    set_current_playing_item( p_mlp, path, p_e ); 
    350417     
    351418    libvlc_media_instance_play( p_mlp->p_mi, p_e ); 
     
    358425    libvlc_event_send( p_mlp->p_event_manager, &event); 
    359426} 
    360