int libvlc_playlist_items_count( libvlc_instance_t *p_instance, libvlc_exception_t *p_e ) { VLC_UNUSED(p_e); assert( PL ); return playlist_CurrentSize( PL ); }
static void MarshalCanPlay( intf_thread_t *p_intf, DBusMessageIter *container ) { playlist_t *p_playlist = p_intf->p_sys->p_playlist; PL_LOCK; dbus_bool_t b_can_play = playlist_CurrentSize( p_playlist ) > 0; PL_UNLOCK; dbus_message_iter_append_basic( container, DBUS_TYPE_BOOLEAN, &b_can_play ); }
static int MarshalCanPlay( intf_thread_t *p_intf, DBusMessageIter *container ) { playlist_t *p_playlist = p_intf->p_sys->p_playlist; PL_LOCK; dbus_bool_t b_can_play = playlist_CurrentSize( p_playlist ) > 0; PL_UNLOCK; if( !dbus_message_iter_append_basic( container, DBUS_TYPE_BOOLEAN, &b_can_play ) ) return VLC_ENOMEM; return VLC_SUCCESS; }
/** * Retrieves the position of an input item in the playlist, given its id * * This function must be called with the playlist locked * * @param playlist_t* p_playlist The playlist * @param input_item_t* i_input_id An input item ID * * @return int The position of the input item or a VLC error constant */ static int getInputPosition( playlist_t* p_playlist, int i_input_id ) { input_item_t* p_input = NULL; assert( p_playlist ); assert( i_input_id >= 0 ); playlist_AssertLocked( p_playlist ); for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ ) { p_input = p_playlist->current.p_elems[i]->p_input; if( !p_input ) return VLC_EGENERIC; if( p_input->i_id == i_input_id ) return i; } return VLC_ENOITEM; }
static int MarshalTracks( intf_thread_t *p_intf, DBusMessageIter *container ) { DBusMessageIter tracks; char *psz_track_id = NULL; playlist_t *p_playlist = p_intf->p_sys->p_playlist; input_item_t *p_input = NULL; dbus_message_iter_open_container( container, DBUS_TYPE_ARRAY, "o", &tracks ); PL_LOCK; for( int i = 0; i < playlist_CurrentSize( p_playlist ); i++ ) { p_input = p_playlist->current.p_elems[i]->p_input; if( ( -1 == asprintf( &psz_track_id, MPRIS_TRACKID_FORMAT, p_input->i_id ) ) || !dbus_message_iter_append_basic( &tracks, DBUS_TYPE_OBJECT_PATH, &psz_track_id ) ) { PL_UNLOCK; dbus_message_iter_abandon_container( container, &tracks ); return VLC_ENOMEM; } free( psz_track_id ); } PL_UNLOCK; if( !dbus_message_iter_close_container( container, &tracks ) ) return VLC_ENOMEM; return VLC_SUCCESS; }
/** * ProcessEvents() reacts to a list of events originating from other VLC threads * * This function must be called with p_sys->lock unlocked * * @param intf_thread_t *p_intf This interface thread state * @param callback_info_t *p_events the list of events to process */ static void ProcessEvents( intf_thread_t *p_intf, callback_info_t **p_events, int i_events ) { playlist_t *p_playlist = p_intf->p_sys->p_playlist; bool b_can_play = p_intf->p_sys->b_can_play; vlc_dictionary_t player_properties, tracklist_properties; vlc_dictionary_init( &player_properties, 0 ); vlc_dictionary_init( &tracklist_properties, 0 ); for( int i = 0; i < i_events; i++ ) { switch( p_events[i]->signal ) { case SIGNAL_ITEM_CURRENT: TrackChange( p_intf ); vlc_dictionary_insert( &player_properties, "Metadata", NULL ); break; case SIGNAL_INTF_CHANGE: case SIGNAL_PLAYLIST_ITEM_APPEND: case SIGNAL_PLAYLIST_ITEM_DELETED: PL_LOCK; b_can_play = playlist_CurrentSize( p_playlist ) > 0; PL_UNLOCK; if( b_can_play != p_intf->p_sys->b_can_play ) { p_intf->p_sys->b_can_play = b_can_play; vlc_dictionary_insert( &player_properties, "CanPlay", NULL ); } if( !vlc_dictionary_has_key( &tracklist_properties, "Tracks" ) ) vlc_dictionary_insert( &tracklist_properties, "Tracks", NULL ); break; case SIGNAL_VOLUME_MUTED: case SIGNAL_VOLUME_CHANGE: vlc_dictionary_insert( &player_properties, "Volume", NULL ); break; case SIGNAL_RANDOM: vlc_dictionary_insert( &player_properties, "Shuffle", NULL ); break; case SIGNAL_REPEAT: case SIGNAL_LOOP: vlc_dictionary_insert( &player_properties, "LoopStatus", NULL ); break; case SIGNAL_STATE: vlc_dictionary_insert( &player_properties, "PlaybackStatus", NULL ); break; case SIGNAL_RATE: vlc_dictionary_insert( &player_properties, "Rate", NULL ); break; case SIGNAL_INPUT_METADATA: { input_thread_t *p_input = playlist_CurrentInput( p_playlist ); input_item_t *p_item; if( p_input ) { p_item = input_GetItem( p_input ); vlc_object_release( p_input ); if( p_item ) vlc_dictionary_insert( &player_properties, "Metadata", NULL ); } break; } case SIGNAL_CAN_SEEK: vlc_dictionary_insert( &player_properties, "CanSeek", NULL ); break; case SIGNAL_CAN_PAUSE: vlc_dictionary_insert( &player_properties, "CanPause", NULL ); break; case SIGNAL_SEEK: { input_thread_t *p_input; input_item_t *p_item; p_input = playlist_CurrentInput( p_intf->p_sys->p_playlist ); if( p_input ) { p_item = input_GetItem( p_input ); vlc_object_release( p_input ); if( p_item && ( p_item->i_id == p_events[i]->i_item ) ) SeekedEmit( p_intf ); } break; } default: assert(0); } free( p_events[i] ); } if( vlc_dictionary_keys_count( &player_properties ) ) PlayerPropertiesChangedEmit( p_intf, &player_properties ); if( vlc_dictionary_keys_count( &tracklist_properties ) ) TrackListPropertiesChangedEmit( p_intf, &tracklist_properties ); vlc_dictionary_clear( &player_properties, NULL, NULL ); vlc_dictionary_clear( &tracklist_properties, NULL, NULL ); }