Changeset 42c421605a7d2f7ccfaeb2a8b25d6565fc98279f
- Timestamp:
- 10/23/07 01:47:24 (11 months ago)
- git-parent:
- Files:
-
- modules/control/dbus.c (modified) (16 diffs)
- modules/control/dbus.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/control/dbus.c
r1245f80 r42c4216 2 2 * dbus.c : D-Bus control interface 3 3 ***************************************************************************** 4 * Copyright (C) 2006 Rafaël Carré 4 * Copyright © 2006-2007 Rafaël Carré 5 * Copyright © 2007 Mirsal Ennaime 5 6 * $Id$ 6 7 * … … 29 30 * http://dbus.freedesktop.org/doc/dbus/api/html/index.html 30 31 * 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 34 36 */ 35 37 … … 63 65 vlc_value_t, void * ); 64 66 67 static int StatusChangeEmit( vlc_object_t *, const char *, vlc_value_t, 68 vlc_value_t, void * ); 69 65 70 static int GetInputMeta ( input_item_t *, DBusMessageIter * ); 71 static int MarshalStatus ( intf_thread_t *, DBusMessageIter * ); 66 72 67 73 struct intf_sys_t … … 69 75 DBusConnection *p_conn; 70 76 vlc_bool_t b_meta_read; 71 input_thread_t *p_input;72 77 }; 73 78 … … 230 235 231 236 DBUS_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 257 249 REPLY_SEND; 258 250 } … … 634 626 635 627 p_sys->b_meta_read = VLC_FALSE; 636 p_sys->p_input = NULL;637 628 638 629 dbus_error_init( &error ); … … 673 664 PL_LOCK; 674 665 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 ); 675 669 PL_UNLOCK; 676 670 pl_Release( p_playlist ); … … 691 685 intf_thread_t *p_intf = (intf_thread_t*) p_this; 692 686 playlist_t *p_playlist = pl_Yield( p_intf );; 687 input_thread_t *p_input; 688 689 p_this->b_dead = VLC_TRUE; 693 690 694 691 PL_LOCK; 695 692 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 696 705 PL_UNLOCK; 697 if( p_intf->p_sys->p_input )698 var_DelCallback( p_intf->p_sys->p_input, "state", StateChange, p_intf );699 706 pl_Release( p_playlist ); 700 707 … … 733 740 734 741 /***************************************************************************** 742 * StatusChange: Player status change signal 743 *****************************************************************************/ 744 745 DBUS_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 /***************************************************************************** 735 756 * StateChange: callback on input "state" 736 757 *****************************************************************************/ … … 740 761 intf_thread_t *p_intf = ( intf_thread_t* ) p_data; 741 762 intf_sys_t *p_sys = p_intf->p_sys; 763 764 if( p_this->b_dead ) 765 return VLC_SUCCESS; 742 766 743 767 if( !p_sys->b_meta_read && newval.i_int == PLAYING_S ) … … 751 775 } 752 776 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 *****************************************************************************/ 789 static 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 ); 753 796 return VLC_SUCCESS; 754 797 } … … 768 811 VLC_UNUSED( oldval ); VLC_UNUSED( newval ); 769 812 813 if( p_this->b_dead ) 814 return VLC_SUCCESS; 815 770 816 p_sys->b_meta_read = VLC_FALSE; 771 817 … … 792 838 } 793 839 794 p_sys->p_input = NULL;795 840 if( input_item_IsPreparsed( p_item ) ) 796 841 { … … 798 843 TrackChangeSignal( p_sys->p_conn, p_item ); 799 844 } 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 ); 805 847 806 848 vlc_object_release( p_input ); … … 836 878 static int GetInputMeta( input_item_t* p_input, 837 879 DBusMessageIter *args ) 838 { /*FIXME: Works only for already read metadata. */ 839 880 { 840 881 DBusMessageIter dict, dict_entry, variant; 841 882 /* We need the track length to be expressed in seconds … … 886 927 #undef ADD_META 887 928 #undef ADD_VLC_META_STRING 929 930 /***************************************************************************** 931 * MarshalStatus: Fill a DBusMessage with the current player status 932 *****************************************************************************/ 933 934 static 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 111 111 " <interface name=\"org.freedesktop.MediaPlayer\">\n" 112 112 " <method name=\"GetStatus\">\n" 113 " <arg type=\" i\" direction=\"out\" />\n"113 " <arg type=\"(iiii)\" direction=\"out\" />\n" 114 114 " </method>\n" 115 115 " <method name=\"Quit\">\n" … … 147 147 " </signal>\n" 148 148 " <signal name=\"StatusChange\">\n" 149 " <arg type=\" i\"/>\n"149 " <arg type=\"(iiii)\"/>\n" 150 150 " </signal>\n" 151 151 " <signal name=\"CapsChange\">\n"
