1 /*****************************************************************************
2 * dbus.c : D-Bus control interface
3 *****************************************************************************
4 * Copyright © 2006-2007 Rafaël Carré
5 * Copyright © 2007 Mirsal Ennaime
8 * Authors: Rafaël Carré <funman at videolanorg>
9 * Mirsal Ennaime <mirsal dot ennaime at gmail dot com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
27 * D-Bus Specification:
28 * http://dbus.freedesktop.org/doc/dbus-specification.html
29 * D-Bus low-level C API (libdbus)
30 * http://dbus.freedesktop.org/doc/dbus/api/html/index.html
32 * "If you use this low-level API directly, you're signing up for some pain."
34 * MPRIS Specification (still drafting on Oct, 23 of 2007):
35 * http://wiki.xmms2.xmms.se/index.php/MPRIS
38 /*****************************************************************************
40 *****************************************************************************/
42 #include <dbus/dbus.h>
48 #include <vlc_interface.h>
50 #include <vlc_input.h>
51 #include <vlc_playlist.h>
53 /*****************************************************************************
55 *****************************************************************************/
57 static int Open ( vlc_object_t * );
58 static void Close ( vlc_object_t * );
59 static void Run ( intf_thread_t * );
61 static int StateChange( vlc_object_t *, const char *, vlc_value_t,
62 vlc_value_t, void * );
64 static int TrackChange( vlc_object_t *, const char *, vlc_value_t,
65 vlc_value_t, void * );
67 static int StatusChangeEmit( vlc_object_t *, const char *, vlc_value_t,
68 vlc_value_t, void * );
70 static int GetInputMeta ( input_item_t *, DBusMessageIter * );
71 static int MarshalStatus ( intf_thread_t *, DBusMessageIter *, vlc_bool_t );
75 DBusConnection *p_conn;
76 vlc_bool_t b_meta_read;
79 /*****************************************************************************
81 *****************************************************************************/
84 set_shortname( _("dbus"));
85 set_category( CAT_INTERFACE );
86 set_subcategory( SUBCAT_INTERFACE_CONTROL );
87 set_description( _("D-Bus control interface") );
88 set_capability( "interface", 0 );
89 set_callbacks( Open, Close );
92 /*****************************************************************************
94 *****************************************************************************/
101 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
102 playlist_Stop( p_playlist );
103 pl_Release( ((vlc_object_t*) p_this) );
104 vlc_object_kill(((vlc_object_t*)p_this)->p_libvlc);
108 DBUS_METHOD( PositionGet )
109 { /* returns position in milliseconds */
112 vlc_value_t position;
115 playlist_t *p_playlist = pl_Yield( ((vlc_object_t*) p_this) );
117 input_thread_t *p_input = p_playlist->p_input;
123 var_Get( p_input, "time", &position );
124 i_pos = position.i_time / 1000;
127 pl_Release( ((vlc_object_t*) p_this) );
132 DBUS_METHOD( PositionSet )
133 { /* set position in milliseconds */
136 vlc_value_t position;
137 playlist_t* p_playlist = NULL;
141 dbus_error_init( &error );
143 dbus_message_get_args( p_from, &error,
144 DBUS_TYPE_INT32, &i_pos,
147 if( dbus_error_is_set( &error ) )
149 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
151 dbus_error_free( &error );
152 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
154 p_playlist = pl_Yield( ((vlc_object_t*) p_this) );
156 input_thread_t *p_input = p_playlist->p_input;
160 position.i_time = i_pos * 1000;
161 var_Set( p_input, "time", position );
164 pl_Release( ((vlc_object_t*) p_this) );
168 DBUS_METHOD( VolumeGet )
169 { /* returns volume in percentage */
172 dbus_int32_t i_dbus_vol;
173 audio_volume_t i_vol;
174 /* 2nd argument of aout_VolumeGet is int32 */
175 aout_VolumeGet( (vlc_object_t*) p_this, &i_vol );
176 i_dbus_vol = ( 100 * i_vol ) / AOUT_VOLUME_MAX;
177 ADD_INT32( &i_dbus_vol );
181 DBUS_METHOD( VolumeSet )
182 { /* set volume in percentage */
186 dbus_error_init( &error );
188 dbus_int32_t i_dbus_vol;
189 audio_volume_t i_vol;
191 dbus_message_get_args( p_from, &error,
192 DBUS_TYPE_INT32, &i_dbus_vol,
195 if( dbus_error_is_set( &error ) )
197 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
199 dbus_error_free( &error );
200 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
203 i_vol = ( AOUT_VOLUME_MAX / 100 ) *i_dbus_vol;
204 aout_VolumeSet( (vlc_object_t*) p_this, i_vol );
210 { /* next playlist item */
212 playlist_t *p_playlist = pl_Yield( ((vlc_object_t*) p_this) );
213 playlist_Next( p_playlist );
214 pl_Release( ((vlc_object_t*) p_this) );
219 { /* previous playlist item */
221 playlist_t *p_playlist = pl_Yield( ((vlc_object_t*) p_this) );
222 playlist_Prev( p_playlist );
223 pl_Release( ((vlc_object_t*) p_this) );
230 playlist_t *p_playlist = pl_Yield( ((vlc_object_t*) p_this) );
231 playlist_Stop( p_playlist );
232 pl_Release( ((vlc_object_t*) p_this) );
236 DBUS_METHOD( GetStatus )
237 { /* returns the current status as a struct of 4 ints */
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 *
247 MarshalStatus( p_this, &args, VLC_TRUE );
255 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
256 playlist_Pause( p_playlist );
257 pl_Release( p_playlist );
264 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
265 playlist_Play( p_playlist );
266 pl_Release( p_playlist );
270 DBUS_METHOD( GetCurrentMetadata )
274 playlist_t* p_playlist = pl_Yield( (vlc_object_t*) p_this );
276 if( p_playlist->status.p_item )
277 GetInputMeta( p_playlist->status.p_item->p_input, &args );
279 pl_Release( p_playlist );
283 /* Media Player information */
285 DBUS_METHOD( Identity )
290 if( asprintf( &psz_identity, "%s %s", PACKAGE, VERSION ) != -1 )
292 ADD_STRING( &psz_identity );
293 free( psz_identity );
296 return DBUS_HANDLER_RESULT_NEED_MEMORY;
303 DBUS_METHOD( AddTrack )
304 { /* add the string to the playlist, and play it if the boolean is true */
308 dbus_error_init( &error );
309 playlist_t* p_playlist = NULL;
314 dbus_message_get_args( p_from, &error,
315 DBUS_TYPE_STRING, &psz_mrl,
316 DBUS_TYPE_BOOLEAN, &b_play,
319 if( dbus_error_is_set( &error ) )
321 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
323 dbus_error_free( &error );
324 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
327 p_playlist = pl_Yield( (vlc_object_t*) p_this );
328 playlist_Add( p_playlist, psz_mrl, NULL, PLAYLIST_APPEND |
329 ( ( b_play == TRUE ) ? PLAYLIST_GO : 0 ) ,
330 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
331 pl_Release( p_playlist );
336 DBUS_METHOD( GetCurrentTrack )
341 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
342 dbus_int32_t i_position = p_playlist->i_current_index;
343 pl_Release( p_playlist );
345 ADD_INT32( &i_position );
349 DBUS_METHOD( GetMetadata )
354 dbus_error_init( &error );
356 dbus_int32_t i_position;
358 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
361 dbus_message_get_args( p_from, &error,
362 DBUS_TYPE_INT32, &i_position,
365 if( dbus_error_is_set( &error ) )
368 pl_Release( p_playlist );
369 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
371 dbus_error_free( &error );
372 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
375 if( i_position <= p_playlist->items.i_size / 2 )
377 GetInputMeta( p_playlist->items.p_elems[i_position*2-1]->p_input, &args );
381 pl_Release( p_playlist );
385 DBUS_METHOD( GetLength )
390 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
391 dbus_int32_t i_elements = p_playlist->items.i_size / 2;
392 pl_Release( p_playlist );
394 ADD_INT32( &i_elements );
398 DBUS_METHOD( DelTrack )
403 dbus_error_init( &error );
405 dbus_int32_t i_position;
406 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
408 dbus_message_get_args( p_from, &error,
409 DBUS_TYPE_INT32, &i_position,
412 if( dbus_error_is_set( &error ) )
414 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
416 dbus_error_free( &error );
417 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
420 if( i_position <= p_playlist->items.i_size / 2 )
422 playlist_DeleteFromInput( p_playlist,
423 p_playlist->items.p_elems[i_position*2-1]->i_id,
427 pl_Release( p_playlist );
440 playlist_t* p_playlist = NULL;
442 dbus_error_init( &error );
443 dbus_message_get_args( p_from, &error,
444 DBUS_TYPE_BOOLEAN, &b_loop,
447 if( dbus_error_is_set( &error ) )
449 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
451 dbus_error_free( &error );
452 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
455 val.b_bool = ( b_loop == TRUE ) ? VLC_TRUE : VLC_FALSE ;
456 p_playlist = pl_Yield( (vlc_object_t*) p_this );
457 var_Set ( p_playlist, "loop", val );
458 pl_Release( ((vlc_object_t*) p_this) );
463 DBUS_METHOD( Repeat )
469 dbus_bool_t b_repeat;
471 playlist_t* p_playlist = NULL;
473 dbus_error_init( &error );
474 dbus_message_get_args( p_from, &error,
475 DBUS_TYPE_BOOLEAN, &b_repeat,
478 if( dbus_error_is_set( &error ) )
480 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
482 dbus_error_free( &error );
483 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
486 val.b_bool = ( b_repeat == TRUE ) ? VLC_TRUE : VLC_FALSE ;
488 p_playlist = pl_Yield( (vlc_object_t*) p_this );
489 var_Set ( p_playlist, "repeat", val );
490 pl_Release( ((vlc_object_t*) p_this) );
495 DBUS_METHOD( Random )
501 dbus_bool_t b_random;
503 playlist_t* p_playlist = NULL;
505 dbus_error_init( &error );
506 dbus_message_get_args( p_from, &error,
507 DBUS_TYPE_BOOLEAN, &b_random,
510 if( dbus_error_is_set( &error ) )
512 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
514 dbus_error_free( &error );
515 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
518 val.b_bool = ( b_random == TRUE ) ? VLC_TRUE : VLC_FALSE ;
520 p_playlist = pl_Yield( (vlc_object_t*) p_this );
521 var_Set ( p_playlist, "random", val );
522 pl_Release( ((vlc_object_t*) p_this) );
526 /*****************************************************************************
527 * Introspection method
528 *****************************************************************************/
530 DBUS_METHOD( handle_introspect_root )
531 { /* handles introspection of root object */
534 ADD_STRING( &psz_introspection_xml_data_root );
538 DBUS_METHOD( handle_introspect_player )
542 ADD_STRING( &psz_introspection_xml_data_player );
546 DBUS_METHOD( handle_introspect_tracklist )
550 ADD_STRING( &psz_introspection_xml_data_tracklist );
554 /*****************************************************************************
555 * handle_*: answer to incoming messages
556 *****************************************************************************/
558 #define METHOD_FUNC( method, function ) \
559 else if( dbus_message_is_method_call( p_from, MPRIS_DBUS_INTERFACE, method ) )\
560 return function( p_conn, p_from, p_this )
562 DBUS_METHOD( handle_root )
565 if( dbus_message_is_method_call( p_from,
566 DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
567 return handle_introspect_root( p_conn, p_from, p_this );
569 /* here D-Bus method's names are associated to an handler */
571 METHOD_FUNC( "Identity", Identity );
573 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
577 DBUS_METHOD( handle_player )
579 if( dbus_message_is_method_call( p_from,
580 DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
581 return handle_introspect_player( p_conn, p_from, p_this );
583 /* here D-Bus method's names are associated to an handler */
585 METHOD_FUNC( "Prev", Prev );
586 METHOD_FUNC( "Next", Next );
587 METHOD_FUNC( "Quit", Quit );
588 METHOD_FUNC( "Stop", Stop );
589 METHOD_FUNC( "Play", Play );
590 METHOD_FUNC( "Pause", Pause );
591 METHOD_FUNC( "Repeat", Repeat );
592 METHOD_FUNC( "VolumeSet", VolumeSet );
593 METHOD_FUNC( "VolumeGet", VolumeGet );
594 METHOD_FUNC( "PositionSet", PositionSet );
595 METHOD_FUNC( "PositionGet", PositionGet );
596 METHOD_FUNC( "GetStatus", GetStatus );
597 METHOD_FUNC( "GetMetadata", GetCurrentMetadata );
599 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
602 DBUS_METHOD( handle_tracklist )
604 if( dbus_message_is_method_call( p_from,
605 DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
606 return handle_introspect_tracklist( p_conn, p_from, p_this );
608 /* here D-Bus method's names are associated to an handler */
610 METHOD_FUNC( "GetMetadata", GetMetadata );
611 METHOD_FUNC( "GetCurrentTrack", GetCurrentTrack );
612 METHOD_FUNC( "GetLength", GetLength );
613 METHOD_FUNC( "AddTrack", AddTrack );
614 METHOD_FUNC( "DelTrack", DelTrack );
615 METHOD_FUNC( "Loop", Loop );
616 METHOD_FUNC( "Random", Random );
618 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
621 /*****************************************************************************
622 * Open: initialize interface
623 *****************************************************************************/
625 static int Open( vlc_object_t *p_this )
626 { /* initialisation of the connection */
627 intf_thread_t *p_intf = (intf_thread_t*)p_this;
628 intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) );
629 playlist_t *p_playlist;
630 DBusConnection *p_conn;
636 p_sys->b_meta_read = VLC_FALSE;
638 dbus_error_init( &error );
640 /* connect to the session bus */
641 p_conn = dbus_bus_get( DBUS_BUS_SESSION, &error );
644 msg_Err( p_this, "Failed to connect to the D-Bus session daemon: %s",
646 dbus_error_free( &error );
651 /* register a well-known name on the bus */
652 dbus_bus_request_name( p_conn, VLC_MPRIS_DBUS_SERVICE, 0, &error );
653 if( dbus_error_is_set( &error ) )
655 msg_Err( p_this, "Error requesting service " VLC_MPRIS_DBUS_SERVICE
656 ": %s", error.message );
657 dbus_error_free( &error );
662 /* we register the objects */
663 dbus_connection_register_object_path( p_conn, MPRIS_DBUS_ROOT_PATH,
664 &vlc_dbus_root_vtable, p_this );
665 dbus_connection_register_object_path( p_conn, MPRIS_DBUS_PLAYER_PATH,
666 &vlc_dbus_player_vtable, p_this );
667 dbus_connection_register_object_path( p_conn, MPRIS_DBUS_TRACKLIST_PATH,
668 &vlc_dbus_tracklist_vtable, p_this );
670 dbus_connection_flush( p_conn );
672 p_playlist = pl_Yield( p_intf );
674 var_AddCallback( p_playlist, "playlist-current", TrackChange, p_intf );
675 var_AddCallback( p_playlist, "random", StatusChangeEmit, p_intf );
676 var_AddCallback( p_playlist, "repeat", StatusChangeEmit, p_intf );
677 var_AddCallback( p_playlist, "loop", StatusChangeEmit, p_intf );
679 pl_Release( p_playlist );
681 p_intf->pf_run = Run;
682 p_intf->p_sys = p_sys;
683 p_sys->p_conn = p_conn;
688 /*****************************************************************************
689 * Close: destroy interface
690 *****************************************************************************/
692 static void Close ( vlc_object_t *p_this )
694 intf_thread_t *p_intf = (intf_thread_t*) p_this;
695 playlist_t *p_playlist = pl_Yield( p_intf );;
696 input_thread_t *p_input;
698 p_this->b_dead = VLC_TRUE;
701 var_DelCallback( p_playlist, "playlist-current", TrackChange, p_intf );
702 var_DelCallback( p_playlist, "random", StatusChangeEmit, p_intf );
703 var_DelCallback( p_playlist, "repeat", StatusChangeEmit, p_intf );
704 var_DelCallback( p_playlist, "loop", StatusChangeEmit, p_intf );
706 p_input = p_playlist->p_input;
709 vlc_object_yield( p_input );
710 var_DelCallback( p_input, "state", StateChange, p_intf );
711 vlc_object_release( p_input );
715 pl_Release( p_playlist );
717 dbus_connection_unref( p_intf->p_sys->p_conn );
719 free( p_intf->p_sys );
722 /*****************************************************************************
724 *****************************************************************************/
726 static void Run ( intf_thread_t *p_intf )
728 while( !intf_ShouldDie( p_intf ) )
730 msleep( INTF_IDLE_SLEEP );
731 dbus_connection_read_write_dispatch( p_intf->p_sys->p_conn, 0 );
735 /*****************************************************************************
736 * TrackChange: Playlist item change callback
737 *****************************************************************************/
739 DBUS_SIGNAL( TrackChangeSignal )
740 { /* emit the metadata of the new item */
741 SIGNAL_INIT( "TrackChange" );
744 input_item_t *p_item = (input_item_t*) p_data;
745 GetInputMeta ( p_item, &args );
750 /*****************************************************************************
751 * StatusChange: Player status change signal
752 *****************************************************************************/
754 DBUS_SIGNAL( StatusChangeSignal )
755 { /* send the updated status info on the bus */
756 SIGNAL_INIT( "StatusChange" );
759 /* we're called from a callback of input_thread_t, so it can not be
760 * destroyed before we return */
761 MarshalStatus( (intf_thread_t*) p_data, &args, VLC_FALSE );
766 /*****************************************************************************
767 * StateChange: callback on input "state"
768 *****************************************************************************/
769 static int StateChange( vlc_object_t *p_this, const char* psz_var,
770 vlc_value_t oldval, vlc_value_t newval, void *p_data )
772 intf_thread_t *p_intf = ( intf_thread_t* ) p_data;
773 intf_sys_t *p_sys = p_intf->p_sys;
778 if( !p_sys->b_meta_read && newval.i_int == PLAYING_S )
780 input_item_t *p_item = input_GetItem( (input_thread_t*)p_this );
783 p_sys->b_meta_read = VLC_TRUE;
784 TrackChangeSignal( p_sys->p_conn, p_item );
788 if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S ||
789 newval.i_int == END_S )
791 StatusChangeSignal( p_sys->p_conn, (void*) p_intf );
797 /*****************************************************************************
798 * StatusChangeEmit: Emits the StatusChange signal
799 *****************************************************************************/
800 static int StatusChangeEmit( vlc_object_t *p_this, const char *psz_var,
801 vlc_value_t oldval, vlc_value_t newval, void *p_data )
803 intf_thread_t *p_intf = p_data;
808 StatusChangeSignal( p_intf->p_sys->p_conn, p_data );
812 /*****************************************************************************
813 * TrackChange: callback on playlist "playlist-current"
814 *****************************************************************************/
815 static int TrackChange( vlc_object_t *p_this, const char *psz_var,
816 vlc_value_t oldval, vlc_value_t newval, void *p_data )
818 intf_thread_t *p_intf = ( intf_thread_t* ) p_data;
819 intf_sys_t *p_sys = p_intf->p_sys;
820 playlist_t *p_playlist;
821 input_thread_t *p_input = NULL;
822 input_item_t *p_item = NULL;
823 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var );
824 VLC_UNUSED( oldval ); VLC_UNUSED( newval );
829 p_sys->b_meta_read = VLC_FALSE;
831 p_playlist = pl_Yield( p_intf );
833 p_input = p_playlist->p_input;
838 pl_Release( p_playlist );
842 vlc_object_yield( p_input );
844 pl_Release( p_playlist );
846 p_item = input_GetItem( p_input );
849 vlc_object_release( p_input );
853 if( input_item_IsPreparsed( p_item ) )
855 p_sys->b_meta_read = VLC_TRUE;
856 TrackChangeSignal( p_sys->p_conn, p_item );
859 var_AddCallback( p_input, "state", StateChange, p_intf );
861 vlc_object_release( p_input );
865 /*****************************************************************************
866 * GetInputMeta: Fill a DBusMessage with the given input item metadata
867 *****************************************************************************/
869 #define ADD_META( entry, type, data ) \
871 dbus_message_iter_open_container( &dict, DBUS_TYPE_DICT_ENTRY, \
872 NULL, &dict_entry ); \
873 dbus_message_iter_append_basic( &dict_entry, DBUS_TYPE_STRING, \
874 &ppsz_meta_items[entry] ); \
875 dbus_message_iter_open_container( &dict_entry, DBUS_TYPE_VARIANT, \
876 type##_AS_STRING, &variant ); \
877 dbus_message_iter_append_basic( &variant, \
880 dbus_message_iter_close_container( &dict_entry, &variant ); \
881 dbus_message_iter_close_container( &dict, &dict_entry ); }
883 #define ADD_VLC_META_STRING( entry, item ) \
885 char * psz = input_item_Get##item( p_input );\
886 ADD_META( entry, DBUS_TYPE_STRING, \
891 static int GetInputMeta( input_item_t* p_input,
892 DBusMessageIter *args )
894 DBusMessageIter dict, dict_entry, variant;
895 /* We need the track length to be expressed in milli-seconds
896 * instead of µ-seconds */
897 dbus_int64_t i_length = ( input_item_GetDuration( p_input ) / 1000 );
899 const char* ppsz_meta_items[] =
901 "title", "artist", "genre", "copyright", "album", "tracknum",
902 "description", "rating", "date", "setting", "url", "language",
903 "nowplaying", "publisher", "encodedby", "arturl", "trackid",
904 "status", "URI", "length", "video-codec", "audio-codec",
905 "video-bitrate", "audio-bitrate", "audio-samplerate"
908 dbus_message_iter_open_container( args, DBUS_TYPE_ARRAY, "{sv}", &dict );
910 ADD_VLC_META_STRING( 0, Title );
911 ADD_VLC_META_STRING( 1, Artist );
912 ADD_VLC_META_STRING( 2, Genre );
913 ADD_VLC_META_STRING( 3, Copyright );
914 ADD_VLC_META_STRING( 4, Album );
915 ADD_VLC_META_STRING( 5, TrackNum );
916 ADD_VLC_META_STRING( 6, Description );
917 ADD_VLC_META_STRING( 7, Rating );
918 ADD_VLC_META_STRING( 8, Date );
919 ADD_VLC_META_STRING( 9, Setting );
920 ADD_VLC_META_STRING( 10, URL );
921 ADD_VLC_META_STRING( 11, Language );
922 ADD_VLC_META_STRING( 12, NowPlaying );
923 ADD_VLC_META_STRING( 13, Publisher );
924 ADD_VLC_META_STRING( 14, EncodedBy );
925 ADD_VLC_META_STRING( 15, ArtURL );
926 ADD_VLC_META_STRING( 16, TrackID );
928 vlc_mutex_lock( &p_input->lock );
929 if( p_input->p_meta )
930 ADD_META( 17, DBUS_TYPE_INT32, p_input->p_meta->i_status );
931 vlc_mutex_unlock( &p_input->lock );
933 ADD_VLC_META_STRING( 18, URI );
934 ADD_META( 19, DBUS_TYPE_INT64, i_length );
936 dbus_message_iter_close_container( args, &dict );
941 #undef ADD_VLC_META_STRING
943 /*****************************************************************************
944 * MarshalStatus: Fill a DBusMessage with the current player status
945 *****************************************************************************/
947 static int MarshalStatus( intf_thread_t* p_intf, DBusMessageIter* args,
949 { /* This is NOT the right way to do that, it would be better to sore
950 the status information in p_sys and update it on change, thus
951 avoiding a long lock */
953 DBusMessageIter status;
954 dbus_int32_t i_state, i_random, i_repeat, i_loop;
956 playlist_t* p_playlist = NULL;
957 input_thread_t* p_input = NULL;
959 p_playlist = pl_Yield( (vlc_object_t*) p_intf );
965 p_input = p_playlist->p_input;
968 var_Get( p_input, "state", &val );
969 if( val.i_int >= END_S )
971 else if( val.i_int == PAUSE_S )
973 else if( val.i_int <= PLAYING_S )
977 var_Get( p_playlist, "random", &val );
978 i_random = val.i_int;
980 var_Get( p_playlist, "repeat", &val );
981 i_repeat = val.i_int;
983 var_Get( p_playlist, "loop", &val );
988 pl_Release( p_playlist );
990 dbus_message_iter_open_container( args, DBUS_TYPE_STRUCT, NULL, &status );
991 dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_state );
992 dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_random );
993 dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_repeat );
994 dbus_message_iter_append_basic( &status, DBUS_TYPE_INT32, &i_loop );
995 dbus_message_iter_close_container( args, &status );