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 * );
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 );
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 )
289 char *psz_identity = malloc( strlen( PACKAGE ) + strlen( VERSION ) + 2 );
290 sprintf( psz_identity, "%s %s", PACKAGE, VERSION );
291 ADD_STRING( &psz_identity );
292 free( psz_identity );
298 DBUS_METHOD( AddTrack )
299 { /* add the string to the playlist, and play it if the boolean is true */
303 dbus_error_init( &error );
304 playlist_t* p_playlist = NULL;
309 dbus_message_get_args( p_from, &error,
310 DBUS_TYPE_STRING, &psz_mrl,
311 DBUS_TYPE_BOOLEAN, &b_play,
314 if( dbus_error_is_set( &error ) )
316 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
318 dbus_error_free( &error );
319 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
322 p_playlist = pl_Yield( (vlc_object_t*) p_this );
323 playlist_Add( p_playlist, psz_mrl, NULL, PLAYLIST_APPEND |
324 ( ( b_play == TRUE ) ? PLAYLIST_GO : 0 ) ,
325 PLAYLIST_END, VLC_TRUE, VLC_FALSE );
326 pl_Release( p_playlist );
331 DBUS_METHOD( GetCurrentTrack )
336 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
337 dbus_int32_t i_position = p_playlist->i_current_index;
338 pl_Release( p_playlist );
340 ADD_INT32( &i_position );
344 DBUS_METHOD( GetMetadata )
349 dbus_error_init( &error );
351 dbus_int32_t i_position;
353 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
355 dbus_message_get_args( p_from, &error,
356 DBUS_TYPE_INT32, &i_position,
359 if( dbus_error_is_set( &error ) )
361 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
363 dbus_error_free( &error );
364 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
367 if( i_position <= p_playlist->items.i_size / 2 )
369 GetInputMeta( p_playlist->items.p_elems[i_position*2-1]->p_input, &args );
372 pl_Release( p_playlist );
376 DBUS_METHOD( GetLength )
381 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
382 dbus_int32_t i_elements = p_playlist->items.i_size / 2;
383 pl_Release( p_playlist );
385 ADD_INT32( &i_elements );
389 DBUS_METHOD( DelTrack )
394 dbus_error_init( &error );
396 dbus_int32_t i_position;
397 playlist_t *p_playlist = pl_Yield( (vlc_object_t*) p_this );
399 dbus_message_get_args( p_from, &error,
400 DBUS_TYPE_INT32, &i_position,
403 if( dbus_error_is_set( &error ) )
405 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
407 dbus_error_free( &error );
408 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
411 if( i_position >= p_playlist->items.i_size / 2 )
413 playlist_DeleteFromInput( p_playlist,
414 p_playlist->items.p_elems[i_position*2-1]->i_id,
418 pl_Release( p_playlist );
431 playlist_t* p_playlist = NULL;
433 dbus_error_init( &error );
434 dbus_message_get_args( p_from, &error,
435 DBUS_TYPE_BOOLEAN, &b_loop,
438 if( dbus_error_is_set( &error ) )
440 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
442 dbus_error_free( &error );
443 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
446 val.b_bool = ( b_loop == TRUE ) ? VLC_TRUE : VLC_FALSE ;
447 p_playlist = pl_Yield( (vlc_object_t*) p_this );
448 var_Set ( p_playlist, "loop", val );
449 pl_Release( ((vlc_object_t*) p_this) );
454 DBUS_METHOD( Repeat )
460 dbus_bool_t b_repeat;
462 playlist_t* p_playlist = NULL;
464 dbus_error_init( &error );
465 dbus_message_get_args( p_from, &error,
466 DBUS_TYPE_BOOLEAN, &b_repeat,
469 if( dbus_error_is_set( &error ) )
471 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
473 dbus_error_free( &error );
474 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
477 val.b_bool = ( b_repeat == TRUE ) ? VLC_TRUE : VLC_FALSE ;
479 p_playlist = pl_Yield( (vlc_object_t*) p_this );
480 var_Set ( p_playlist, "repeat", val );
481 pl_Release( ((vlc_object_t*) p_this) );
486 DBUS_METHOD( Random )
492 dbus_bool_t b_random;
494 playlist_t* p_playlist = NULL;
496 dbus_error_init( &error );
497 dbus_message_get_args( p_from, &error,
498 DBUS_TYPE_BOOLEAN, &b_random,
501 if( dbus_error_is_set( &error ) )
503 msg_Err( (vlc_object_t*) p_this, "D-Bus message reading : %s\n",
505 dbus_error_free( &error );
506 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
509 val.b_bool = ( b_random == TRUE ) ? VLC_TRUE : VLC_FALSE ;
511 p_playlist = pl_Yield( (vlc_object_t*) p_this );
512 var_Set ( p_playlist, "random", val );
513 pl_Release( ((vlc_object_t*) p_this) );
517 /*****************************************************************************
518 * Introspection method
519 *****************************************************************************/
521 DBUS_METHOD( handle_introspect_root )
522 { /* handles introspection of root object */
525 ADD_STRING( &psz_introspection_xml_data_root );
529 DBUS_METHOD( handle_introspect_player )
533 ADD_STRING( &psz_introspection_xml_data_player );
537 DBUS_METHOD( handle_introspect_tracklist )
541 ADD_STRING( &psz_introspection_xml_data_tracklist );
545 /*****************************************************************************
546 * handle_*: answer to incoming messages
547 *****************************************************************************/
549 #define METHOD_FUNC( method, function ) \
550 else if( dbus_message_is_method_call( p_from, MPRIS_DBUS_INTERFACE, method ) )\
551 return function( p_conn, p_from, p_this )
553 DBUS_METHOD( handle_root )
556 if( dbus_message_is_method_call( p_from,
557 DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
558 return handle_introspect_root( p_conn, p_from, p_this );
560 /* here D-Bus method's names are associated to an handler */
562 METHOD_FUNC( "Identity", Identity );
564 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
568 DBUS_METHOD( handle_player )
570 if( dbus_message_is_method_call( p_from,
571 DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
572 return handle_introspect_player( p_conn, p_from, p_this );
574 /* here D-Bus method's names are associated to an handler */
576 METHOD_FUNC( "Prev", Prev );
577 METHOD_FUNC( "Next", Next );
578 METHOD_FUNC( "Quit", Quit );
579 METHOD_FUNC( "Stop", Stop );
580 METHOD_FUNC( "Play", Play );
581 METHOD_FUNC( "Pause", Pause );
582 METHOD_FUNC( "Repeat", Repeat );
583 METHOD_FUNC( "VolumeSet", VolumeSet );
584 METHOD_FUNC( "VolumeGet", VolumeGet );
585 METHOD_FUNC( "PositionSet", PositionSet );
586 METHOD_FUNC( "PositionGet", PositionGet );
587 METHOD_FUNC( "GetStatus", GetStatus );
588 METHOD_FUNC( "GetMetadata", GetCurrentMetadata );
590 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
593 DBUS_METHOD( handle_tracklist )
595 if( dbus_message_is_method_call( p_from,
596 DBUS_INTERFACE_INTROSPECTABLE, "Introspect" ) )
597 return handle_introspect_tracklist( p_conn, p_from, p_this );
599 /* here D-Bus method's names are associated to an handler */
601 METHOD_FUNC( "GetMetadata", GetMetadata );
602 METHOD_FUNC( "GetCurrentTrack", GetCurrentTrack );
603 METHOD_FUNC( "GetLength", GetLength );
604 METHOD_FUNC( "AddTrack", AddTrack );
605 METHOD_FUNC( "DelTrack", DelTrack );
606 METHOD_FUNC( "Loop", Loop );
607 METHOD_FUNC( "Random", Random );
609 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
612 /*****************************************************************************
613 * Open: initialize interface
614 *****************************************************************************/
616 static int Open( vlc_object_t *p_this )
617 { /* initialisation of the connection */
618 intf_thread_t *p_intf = (intf_thread_t*)p_this;
619 intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) );
620 playlist_t *p_playlist;
621 DBusConnection *p_conn;
627 p_sys->b_meta_read = VLC_FALSE;
629 dbus_error_init( &error );
631 /* connect to the session bus */
632 p_conn = dbus_bus_get( DBUS_BUS_SESSION, &error );
635 msg_Err( p_this, "Failed to connect to the D-Bus session daemon: %s",
637 dbus_error_free( &error );
642 /* register a well-known name on the bus */
643 dbus_bus_request_name( p_conn, VLC_MPRIS_DBUS_SERVICE, 0, &error );
644 if( dbus_error_is_set( &error ) )
646 msg_Err( p_this, "Error requesting service " VLC_MPRIS_DBUS_SERVICE
647 ": %s", error.message );
648 dbus_error_free( &error );
653 /* we register the objects */
654 dbus_connection_register_object_path( p_conn, MPRIS_DBUS_ROOT_PATH,
655 &vlc_dbus_root_vtable, p_this );
656 dbus_connection_register_object_path( p_conn, MPRIS_DBUS_PLAYER_PATH,
657 &vlc_dbus_player_vtable, p_this );
658 dbus_connection_register_object_path( p_conn, MPRIS_DBUS_TRACKLIST_PATH,
659 &vlc_dbus_tracklist_vtable, p_this );
661 dbus_connection_flush( p_conn );
663 p_playlist = pl_Yield( p_intf );
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 );
670 pl_Release( p_playlist );
672 p_intf->pf_run = Run;
673 p_intf->p_sys = p_sys;
674 p_sys->p_conn = p_conn;
679 /*****************************************************************************
680 * Close: destroy interface
681 *****************************************************************************/
683 static void Close ( vlc_object_t *p_this )
685 intf_thread_t *p_intf = (intf_thread_t*) p_this;
686 playlist_t *p_playlist = pl_Yield( p_intf );;
687 input_thread_t *p_input;
689 p_this->b_dead = VLC_TRUE;
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 );
697 p_input = p_playlist->p_input;
700 vlc_object_yield( p_input );
701 var_DelCallback( p_input, "state", StateChange, p_intf );
702 vlc_object_release( p_input );
706 pl_Release( p_playlist );
708 dbus_connection_unref( p_intf->p_sys->p_conn );
710 free( p_intf->p_sys );
713 /*****************************************************************************
715 *****************************************************************************/
717 static void Run ( intf_thread_t *p_intf )
719 while( !intf_ShouldDie( p_intf ) )
721 msleep( INTF_IDLE_SLEEP );
722 dbus_connection_read_write_dispatch( p_intf->p_sys->p_conn, 0 );
726 /*****************************************************************************
727 * TrackChange: Playlist item change callback
728 *****************************************************************************/
730 DBUS_SIGNAL( TrackChangeSignal )
731 { /* emit the metadata of the new item */
732 SIGNAL_INIT( "TrackChange" );
735 input_item_t *p_item = (input_item_t*) p_data;
736 GetInputMeta ( p_item, &args );
741 /*****************************************************************************
742 * StatusChange: Player status change signal
743 *****************************************************************************/
745 DBUS_SIGNAL( StatusChangeSignal )
746 { /* send the updated status info on the bus */
747 SIGNAL_INIT( "StatusChange" );
750 MarshalStatus( (intf_thread_t*) p_data, &args );
755 /*****************************************************************************
756 * StateChange: callback on input "state"
757 *****************************************************************************/
758 static int StateChange( vlc_object_t *p_this, const char* psz_var,
759 vlc_value_t oldval, vlc_value_t newval, void *p_data )
761 intf_thread_t *p_intf = ( intf_thread_t* ) p_data;
762 intf_sys_t *p_sys = p_intf->p_sys;
767 if( !p_sys->b_meta_read && newval.i_int == PLAYING_S )
769 input_item_t *p_item = input_GetItem( (input_thread_t*)p_this );
772 p_sys->b_meta_read = VLC_TRUE;
773 TrackChangeSignal( p_sys->p_conn, p_item );
777 if( newval.i_int == PLAYING_S || newval.i_int == PAUSE_S ||
778 newval.i_int == END_S )
780 StatusChangeSignal( p_sys->p_conn, (void*) p_intf );
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 )
795 StatusChangeSignal( ((intf_thread_t*)p_data)->p_sys->p_conn, p_data );
799 /*****************************************************************************
800 * TrackChange: callback on playlist "playlist-current"
801 *****************************************************************************/
802 static int TrackChange( vlc_object_t *p_this, const char *psz_var,
803 vlc_value_t oldval, vlc_value_t newval, void *p_data )
805 intf_thread_t *p_intf = ( intf_thread_t* ) p_data;
806 intf_sys_t *p_sys = p_intf->p_sys;
807 playlist_t *p_playlist;
808 input_thread_t *p_input = NULL;
809 input_item_t *p_item = NULL;
810 VLC_UNUSED( p_this ); VLC_UNUSED( psz_var );
811 VLC_UNUSED( oldval ); VLC_UNUSED( newval );
816 p_sys->b_meta_read = VLC_FALSE;
818 p_playlist = pl_Yield( p_intf );
820 p_input = p_playlist->p_input;
825 pl_Release( p_playlist );
829 vlc_object_yield( p_input );
831 pl_Release( p_playlist );
833 p_item = input_GetItem( p_input );
836 vlc_object_release( p_input );
840 if( input_item_IsPreparsed( p_item ) )
842 p_sys->b_meta_read = VLC_TRUE;
843 TrackChangeSignal( p_sys->p_conn, p_item );
846 var_AddCallback( p_input, "state", StateChange, p_intf );
848 vlc_object_release( p_input );
852 /*****************************************************************************
853 * GetInputMeta: Fill a DBusMessage with the given input item metadata
854 *****************************************************************************/
856 #define ADD_META( entry, type, data ) \
858 dbus_message_iter_open_container( &dict, DBUS_TYPE_DICT_ENTRY, \
859 NULL, &dict_entry ); \
860 dbus_message_iter_append_basic( &dict_entry, DBUS_TYPE_STRING, \
861 &ppsz_meta_items[entry] ); \
862 dbus_message_iter_open_container( &dict_entry, DBUS_TYPE_VARIANT, \
863 type##_AS_STRING, &variant ); \
864 dbus_message_iter_append_basic( &variant, \
867 dbus_message_iter_close_container( &dict_entry, &variant ); \
868 dbus_message_iter_close_container( &dict, &dict_entry ); }
870 #define ADD_VLC_META_STRING( entry, item ) \
872 char * psz = input_item_Get##item( p_input );\
873 ADD_META( entry, DBUS_TYPE_STRING, \
878 static int GetInputMeta( input_item_t* p_input,
879 DBusMessageIter *args )
881 DBusMessageIter dict, dict_entry, variant;
882 /* We need the track length to be expressed in seconds
883 * instead of milliseconds */
884 dbus_int64_t i_length = ( input_item_GetDuration( p_input ) / 1000 );
886 const char* ppsz_meta_items[] =
888 "title", "artist", "genre", "copyright", "album", "tracknum",
889 "description", "rating", "date", "setting", "url", "language",
890 "nowplaying", "publisher", "encodedby", "arturl", "trackid",
891 "status", "URI", "length", "video-codec", "audio-codec",
892 "video-bitrate", "audio-bitrate", "audio-samplerate"
895 dbus_message_iter_open_container( args, DBUS_TYPE_ARRAY, "{sv}", &dict );
897 ADD_VLC_META_STRING( 0, Title );
898 ADD_VLC_META_STRING( 1, Artist );
899 ADD_VLC_META_STRING( 2, Genre );
900 ADD_VLC_META_STRING( 3, Copyright );
901 ADD_VLC_META_STRING( 4, Album );
902 ADD_VLC_META_STRING( 5, TrackNum );
903 ADD_VLC_META_STRING( 6, Description );
904 ADD_VLC_META_STRING( 7, Rating );
905 ADD_VLC_META_STRING( 8, Date );
906 ADD_VLC_META_STRING( 9, Setting );
907 ADD_VLC_META_STRING( 10, URL );
908 ADD_VLC_META_STRING( 11, Language );
909 ADD_VLC_META_STRING( 12, NowPlaying );
910 ADD_VLC_META_STRING( 13, Publisher );
911 ADD_VLC_META_STRING( 14, EncodedBy );
912 ADD_VLC_META_STRING( 15, ArtURL );
913 ADD_VLC_META_STRING( 16, TrackID );
915 vlc_mutex_lock( &p_input->lock );
916 if( p_input->p_meta )
917 ADD_META( 17, DBUS_TYPE_INT32, p_input->p_meta->i_status );
918 vlc_mutex_unlock( &p_input->lock );
920 ADD_VLC_META_STRING( 18, URI );
921 ADD_META( 19, DBUS_TYPE_INT64, i_length );
923 dbus_message_iter_close_container( args, &dict );
928 #undef ADD_VLC_META_STRING
930 /*****************************************************************************
931 * MarshalStatus: Fill a DBusMessage with the current player status
932 *****************************************************************************/
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 */
939 DBusMessageIter status;
940 dbus_int32_t i_state, i_random, i_repeat, i_loop;
942 playlist_t* p_playlist = NULL;
943 input_thread_t* p_input = NULL;
945 p_playlist = pl_Yield( (vlc_object_t*) p_intf );
947 p_input = p_playlist->p_input;
952 var_Get( p_input, "state", &val );
953 if( val.i_int >= END_S )
955 else if( val.i_int == PAUSE_S )
957 else if( val.i_int <= PLAYING_S )
961 var_Get( p_playlist, "random", &val );
962 i_random = val.i_int;
964 var_Get( p_playlist, "repeat", &val );
965 i_repeat = val.i_int;
967 var_Get( p_playlist, "loop", &val );
971 pl_Release( p_playlist );
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 );