Changeset 16364fa65c37326f7b99bb42b899a63b4a5ddbb5

Show
Ignore:
Timestamp:
25/03/08 02:25:24 (8 months ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1206408324 +0100
git-parent:

[fc92a6567e68eb7a22f4107d65d3bd2cced7266e]

git-author:
Mirsal Ennaime <mirsal.ennaime@gmail.com> 1205971701 +0100
Message:

Dbus control module: * Implement (partially) the CapsChange? signal * Refactor capabilities related code * Fix potential race condition * Don't forget to release the playlist.

Signed-off-by: Mirsal Ennaime <mirsal.ennaime@gmail.com>
Signed-off-by: Rafaël Carré <funman@videolan.org>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/control/dbus.c

    r67bda23 r16364fa  
    7979static int GetInputMeta ( input_item_t *, DBusMessageIter * ); 
    8080static int MarshalStatus ( intf_thread_t *, DBusMessageIter *, vlc_bool_t ); 
     81static int UpdateCaps( intf_thread_t* ); 
    8182 
    8283/* GetCaps() capabilities */ 
     
    307308    REPLY_INIT; 
    308309    OUT_ARGUMENTS; 
    309     playlist_t* p_playlist = pl_Yield( (vlc_object_t*) p_this ); 
    310     PL_LOCK; 
    311      
    312     dbus_int32_t i_caps = CAPS_NONE; 
    313  
    314     /* FIXME: 
    315      * Every capability should be checked in a callback, modifying p_sys->i_caps 
    316      * so we can send a signal whenever it changes. 
    317      * When it is done, GetCaps method will just return p_sys->i_caps 
    318      */ 
    319  
    320     if( p_playlist->items.i_size > 0 ) 
    321         i_caps |= CAPS_CAN_PLAY | CAPS_CAN_GO_PREV | CAPS_CAN_GO_NEXT; 
    322  
    323     if( p_playlist->p_input ) 
    324     { 
    325         access_t *p_access = (access_t*)vlc_object_find( p_playlist->p_input,  
    326             VLC_OBJECT_ACCESS, FIND_CHILD ); 
    327         if( p_access ) 
    328         { 
    329             vlc_bool_t b_can_pause; 
    330             if( !access2_Control( p_access, ACCESS_CAN_PAUSE, &b_can_pause ) && 
    331                     b_can_pause ) 
    332                 i_caps |= CAPS_CAN_PAUSE; 
    333             vlc_object_release( p_access ); 
    334         } 
    335         demux_t *p_demux = (demux_t*)vlc_object_find( p_playlist->p_input, 
    336             VLC_OBJECT_DEMUX, FIND_CHILD ); 
    337         if( p_demux ) 
    338         {   /* XXX: is: demux can seek and access can not a possibility ? */ 
    339             vlc_bool_t b_can_seek; 
    340             if( !stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_can_seek ) && 
    341                     b_can_seek ) 
    342                 i_caps |= CAPS_CAN_SEEK; 
    343             vlc_object_release( p_demux ); 
    344         } 
    345     } 
    346  
    347     if( ((intf_thread_t*)p_this)->p_sys->b_meta_read ) 
    348         i_caps |= CAPS_CAN_PROVIDE_METADATA; 
    349  
    350     PL_UNLOCK; 
    351  
    352     ADD_INT32( &i_caps ); 
     310 
     311    UpdateCaps( (intf_thread_t*)p_this ); 
     312    ADD_INT32( &((intf_thread_t*)p_this)->p_sys->i_caps ); 
    353313 
    354314    REPLY_SEND; 
     
    766726    p_sys->p_conn = p_conn; 
    767727 
     728    UpdateCaps( p_intf ); 
     729 
    768730    return VLC_SUCCESS; 
    769731} 
     
    817779        dbus_connection_read_write_dispatch( p_intf->p_sys->p_conn, 0 ); 
    818780    } 
     781} 
     782 
     783/****************************************************************************** 
     784 * CapsChange: player capabilities change signal 
     785 *****************************************************************************/ 
     786DBUS_SIGNAL( CapsChangeSignal ) 
     787{ 
     788    SIGNAL_INIT( "CapsChange" ); 
     789    OUT_ARGUMENTS; 
     790 
     791    ADD_INT32( &((intf_thread_t*)p_data)->p_sys->i_caps ); 
     792    SIGNAL_SEND; 
    819793} 
    820794 
     
    862836        return VLC_SUCCESS; 
    863837 
     838    /* We're called from the playlist, so that would cause locking issues */ 
     839    /* UpdateCaps( p_intf ); */ 
    864840    TrackListChangeSignal( p_intf->p_sys->p_conn, p_data ); 
    865841    return VLC_SUCCESS; 
     
    925901    } 
    926902 
     903 
    927904    return VLC_SUCCESS; 
    928905} 
     
    941918        return VLC_SUCCESS; 
    942919 
     920    UpdateCaps( p_intf ); 
    943921    StatusChangeSignal( p_intf->p_sys->p_conn, p_data ); 
    944922    return VLC_SUCCESS; 
     
    992970    } 
    993971 
     972    UpdateCaps( p_intf ); 
     973 
     974    var_AddCallback( p_input, "state", StateChange, p_intf ); 
     975 
     976    vlc_object_release( p_input ); 
     977    return VLC_SUCCESS; 
     978} 
     979 
     980/***************************************************************************** 
     981 * UpdateCaps: update p_sys->i_caps 
     982 ****************************************************************************/ 
     983static int UpdateCaps( intf_thread_t* p_intf ) 
     984{ 
    994985    dbus_int32_t i_caps = CAPS_NONE; 
    995  
     986    playlist_t* p_playlist = pl_Yield( (vlc_object_t*)p_intf ); 
     987    PL_LOCK; 
     988     
    996989    if( p_playlist->items.i_size > 0 ) 
    997990        i_caps |= CAPS_CAN_PLAY | CAPS_CAN_GO_PREV | CAPS_CAN_GO_NEXT; 
     
    10211014    } 
    10221015 
    1023     if( ((intf_thread_t*)p_this)->p_sys->b_meta_read ) 
     1016    PL_UNLOCK; 
     1017    pl_Release( p_playlist ); 
     1018 
     1019    if( p_intf->p_sys->b_meta_read ) 
    10241020        i_caps |= CAPS_CAN_PROVIDE_METADATA; 
    10251021 
    1026  
    1027     var_AddCallback( p_input, "state", StateChange, p_intf ); 
    1028  
    1029     vlc_object_release( p_input ); 
     1022    if( i_caps != p_intf->p_sys->i_caps ) 
     1023    { 
     1024        p_intf->p_sys->i_caps = i_caps; 
     1025        CapsChangeSignal( p_intf->p_sys->p_conn, (vlc_object_t*)p_intf ); 
     1026    } 
     1027 
    10301028    return VLC_SUCCESS; 
    10311029}