Changeset 42c421605a7d2f7ccfaeb2a8b25d6565fc98279f

Show
Ignore:
Timestamp:
10/23/07 01:47:24 (11 months ago)
Author:
Rafaël Carré <funman@videolan.org>
git-committer:
Rafaël Carré <funman@videolan.org> 1193096844 +0000
git-parent:

[95466d5ef9b48a2ea50d9aa246dee2023f3d12ff]

git-author:
Rafaël Carré <funman@videolan.org> 1193096844 +0000
Message:

dbus: updates to match the current status of MPRIS. Patch by Mirsal Ennaime as usual

Files:

Legend:

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

    r1245f80 r42c4216  
    22 * dbus.c : D-Bus control interface 
    33 ***************************************************************************** 
    4  * Copyright (C) 2006 Rafaël Carré 
     4 * Copyright © 2006-2007 Rafaël Carré 
     5 * Copyright © 2007 Mirsal Ennaime 
    56 * $Id$ 
    67 * 
     
    2930 *      http://dbus.freedesktop.org/doc/dbus/api/html/index.html 
    3031 *  extract: 
    31     "If you use this low-level API directly, you're signing up for some pain." 
    32  * MPRIS Specification (still drafting on June, 25 of 2007): 
    33  *      http://wiki.xmms2.xmms.se/index.php/Media_Player_Interfaces 
     32 *   "If you use this low-level API directly, you're signing up for some pain." 
     33 * 
     34 * MPRIS Specification (still drafting on Oct, 23 of 2007): 
     35 *      http://wiki.xmms2.xmms.se/index.php/MPRIS 
    3436 */ 
    3537 
     
    6365                        vlc_value_t, void * ); 
    6466 
     67static int StatusChangeEmit( vlc_object_t *, const char *, vlc_value_t, 
     68                        vlc_value_t, void * ); 
     69 
    6570static int GetInputMeta ( input_item_t *, DBusMessageIter * ); 
     71static int MarshalStatus ( intf_thread_t *, DBusMessageIter * ); 
    6672 
    6773struct intf_sys_t 
     
    6975    DBusConnection *p_conn; 
    7076    vlc_bool_t      b_meta_read; 
    71     input_thread_t *p_input; 
    7277}; 
    7378 
     
    230235 
    231236DBUS_METHOD( GetStatus ) 
    232 { /* returns an int: 0=playing 1=paused 2=stopped */ 
    233     REPLY_INIT; 
    234     OUT_ARGUMENTS; 
    235  
    236     dbus_int32_t i_status; 
    237     vlc_value_t val; 
    238  
    239     playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this ); 
    240     PL_LOCK; 
    241     input_thread_t *p_input = p_playlist->p_input; 
    242  
    243     i_status = 2; 
    244     if( p_input ) 
    245     { 
    246         var_Get( p_input, "state", &val ); 
    247         if( val.i_int == PAUSE_S ) 
    248             i_status = 1; 
    249         else if( val.i_int == PLAYING_S ) 
    250             i_status = 0; 
    251     } 
    252  
    253     PL_UNLOCK; 
    254     pl_Release( p_playlist ); 
    255  
    256     ADD_INT32( &i_status ); 
     237{ /* returns the current status as a struct of 4 ints */ 
     238/* 
     239    First   0 = Playing, 1 = Paused, 2 = Stopped. 
     240    Second  0 = Playing linearly , 1 = Playing randomly. 
     241    Third   0 = Go to the next element once the current has finished playing , 1 = Repeat the current element 
     242    Fourth  0 = Stop playing once the last element has been played, 1 = Never give up playing * 
     243 */ 
     244    REPLY_INIT; 
     245    OUT_ARGUMENTS; 
     246 
     247    MarshalStatus( p_this, &args ); 
     248 
    257249    REPLY_SEND; 
    258250} 
     
    634626 
    635627    p_sys->b_meta_read = VLC_FALSE; 
    636     p_sys->p_input = NULL; 
    637628 
    638629    dbus_error_init( &error ); 
     
    673664    PL_LOCK; 
    674665    var_AddCallback( p_playlist, "playlist-current", TrackChange, p_intf ); 
     666    var_AddCallback( p_playlist, "random", StatusChangeEmit, p_intf ); 
     667    var_AddCallback( p_playlist, "repeat", StatusChangeEmit, p_intf ); 
     668    var_AddCallback( p_playlist, "loop", StatusChangeEmit, p_intf ); 
    675669    PL_UNLOCK; 
    676670    pl_Release( p_playlist ); 
     
    691685    intf_thread_t   *p_intf     = (intf_thread_t*) p_this; 
    692686    playlist_t      *p_playlist = pl_Yield( p_intf );; 
     687    input_thread_t  *p_input; 
     688 
     689    p_this->b_dead = VLC_TRUE; 
    693690 
    694691    PL_LOCK; 
    695692    var_DelCallback( p_playlist, "playlist-current", TrackChange, p_intf ); 
     693    var_DelCallback( p_playlist, "random", StatusChangeEmit, p_intf ); 
     694    var_DelCallback( p_playlist, "repeat", StatusChangeEmit, p_intf ); 
     695    var_DelCallback( p_playlist, "loop", StatusChangeEmit, p_intf ); 
     696 
     697    p_input = p_playlist->p_input; 
     698    if ( p_input ) 
     699    { 
     700        vlc_object_yield( p_input ); 
     701        var_DelCallback( p_input, "state", StateChange, p_intf ); 
     702        vlc_object_release( p_input ); 
     703    } 
     704 
    696705    PL_UNLOCK; 
    697     if( p_intf->p_sys->p_input ) 
    698         var_DelCallback( p_intf->p_sys->p_input, "state", StateChange, p_intf ); 
    699706    pl_Release( p_playlist ); 
    700707 
     
    733740 
    734741/***************************************************************************** 
     742 * StatusChange: Player status change signal 
     743 *****************************************************************************/ 
     744 
     745DBUS_SIGNAL( StatusChangeSignal ) 
     746{ /* send the updated status info on the bus */ 
     747    SIGNAL_INIT( "StatusChange" ); 
     748    OUT_ARGUMENTS; 
     749 
     750    MarshalStatus( (intf_thread_t*) p_data, &args ); 
     751 
     752    SIGNAL_SEND; 
     753} 
     754 
     755/***************************************************************************** 
    735756 * StateChange: callback on input "state" 
    736757 *****************************************************************************/ 
     
    740761    intf_thread_t       *p_intf     = ( intf_thread_t* ) p_data; 
    741762    intf_sys_t          *p_sys      = p_intf->p_sys; 
     763 
     764    if( p_this->b_dead ) 
     765        return VLC_SUCCESS; 
    742766 
    743767    if( !p_sys->b_meta_read && newval.i_int == PLAYING_S ) 
     
    751775    } 
    752776 
     777    if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S || 
     778        newval.i_int == END_S ) 
     779    { 
     780        StatusChangeSignal( p_sys->p_conn, (void*) p_intf ); 
     781    } 
     782 
     783    return VLC_SUCCESS; 
     784} 
     785 
     786/***************************************************************************** 
     787 * StatusChangeEmit: Emits the StatusChange signal 
     788 *****************************************************************************/ 
     789static int StatusChangeEmit( vlc_object_t *p_this, const char *psz_var, 
     790            vlc_value_t oldval, vlc_value_t newval, void *p_data ) 
     791{ 
     792    if( p_this->b_dead ) 
     793        return VLC_SUCCESS; 
     794 
     795    StatusChangeSignal( ((intf_thread_t*)p_data)->p_sys->p_conn, p_data ); 
    753796    return VLC_SUCCESS; 
    754797} 
     
    768811    VLC_UNUSED( oldval ); VLC_UNUSED( newval ); 
    769812 
     813    if( p_this->b_dead ) 
     814        return VLC_SUCCESS; 
     815 
    770816    p_sys->b_meta_read = VLC_FALSE; 
    771817 
     
    792838    } 
    793839 
    794     p_sys->p_input = NULL; 
    795840    if( input_item_IsPreparsed( p_item ) ) 
    796841    { 
     
    798843        TrackChangeSignal( p_sys->p_conn, p_item ); 
    799844    } 
    800     else 
    801     { 
    802         var_AddCallback( p_input, "state", StateChange, p_intf ); 
    803         p_sys->p_input = p_input; 
    804     } 
     845 
     846    var_AddCallback( p_input, "state", StateChange, p_intf ); 
    805847 
    806848    vlc_object_release( p_input ); 
     
    836878static int GetInputMeta( input_item_t* p_input, 
    837879                        DBusMessageIter *args ) 
    838 { /*FIXME: Works only for already read metadata. */ 
    839  
     880
    840881    DBusMessageIter dict, dict_entry, variant; 
    841882    /* We need the track length to be expressed in seconds 
     
    886927#undef ADD_META 
    887928#undef ADD_VLC_META_STRING 
     929 
     930/***************************************************************************** 
     931 * MarshalStatus: Fill a DBusMessage with the current player status 
     932 *****************************************************************************/ 
     933 
     934static int MarshalStatus( intf_thread_t* p_intf, DBusMessageIter* args ) 
     935{ /* This is NOT the right way to do that, it would be better to sore 
     936     the status information in p_sys and update it on change, thus 
     937     avoiding a long lock */ 
     938 
     939    DBusMessageIter status; 
     940    dbus_int32_t i_state, i_random, i_repeat, i_loop; 
     941    vlc_value_t val; 
     942    playlist_t* p_playlist = NULL; 
     943    input_thread_t* p_input = NULL; 
     944 
     945    p_playlist = pl_Yield( (vlc_object_t*) p_intf ); 
     946    PL_LOCK; 
     947    p_input = p_playlist->p_input; 
     948 
     949    i_state = 2; 
     950    if( p_input ) 
     951    { 
     952        var_Get( p_input, "state", &val ); 
     953        if( val.i_int >= END_S ) 
     954            i_state = 2; 
     955        else if( val.i_int == PAUSE_S ) 
     956            i_state = 1; 
     957        else if( val.i_int <= PLAYING_S ) 
     958            i_state = 0; 
     959    } 
     960 
     961    var_Get( p_playlist, "random", &val ); 
     962    i_random = val.i_int; 
     963 
     964    var_Get( p_playlist, "repeat", &val ); 
     965    i_repeat = val.i_int; 
     966 
     967    var_Get( p_playlist, "loop", &val ); 
     968    i_loop = val.i_int; 
     969 
     970    PL_UNLOCK; 
     971    pl_Release( p_playlist ); 
     972 
     973    dbus_message_iter_open_container( args, DBUS_TYPE_STRUCT, NULL, &status ); 
     974    dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_state ); 
     975    dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_random ); 
     976    dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_repeat ); 
     977    dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_loop ); 
     978    dbus_message_iter_close_container( args, &status ); 
     979 
     980    return VLC_SUCCESS; 
     981 
     982} 
  • modules/control/dbus.h

    r319597f r42c4216  
    111111"  <interface name=\"org.freedesktop.MediaPlayer\">\n" 
    112112"    <method name=\"GetStatus\">\n" 
    113 "      <arg type=\"i\" direction=\"out\" />\n" 
     113"      <arg type=\"(iiii)\" direction=\"out\" />\n" 
    114114"    </method>\n" 
    115115"    <method name=\"Quit\">\n" 
     
    147147"    </signal>\n" 
    148148"    <signal name=\"StatusChange\">\n" 
    149 "      <arg type=\"i\"/>\n" 
     149"      <arg type=\"(iiii)\"/>\n" 
    150150"    </signal>\n" 
    151151"    <signal name=\"CapsChange\">\n"