X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fplaylist%2Fservices_discovery.c;h=6f3cda60de2041337b0031dbc5a83bb1bbcc67ae;hb=d666030b2349e8a710fcba4d2cabb912cc700580;hp=142fdc6fc7c2cd5012555a27be0262d70dda2490;hpb=027b8eabd3d40ec522e0e19cb9db0e73b51ddd25;p=vlc diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c index 142fdc6fc7..6f3cda60de 100644 --- a/src/playlist/services_discovery.c +++ b/src/playlist/services_discovery.c @@ -20,10 +20,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include + +#include #include "vlc_playlist.h" #include "vlc_events.h" #include "playlist_internal.h" +#include "../libvlc.h" static void RunSD( services_discovery_t *p_sd ); @@ -37,9 +43,11 @@ static void RunSD( services_discovery_t *p_sd ); /*********************************************************************** * GetServicesNames ***********************************************************************/ -char ** services_discovery_GetServicesNames( vlc_object_t * p_super ) +char ** __services_discovery_GetServicesNames( vlc_object_t * p_super, + char ***pppsz_longnames ) { - return module_GetModulesNamesForCapability( p_super, "services_discovery" ); + return module_GetModulesNamesForCapability( p_super, "services_discovery", + pppsz_longnames ); } /*********************************************************************** @@ -48,7 +56,9 @@ char ** services_discovery_GetServicesNames( vlc_object_t * p_super ) services_discovery_t * services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name ) { - services_discovery_t *p_sd = vlc_object_create( p_super, VLC_OBJECT_SD ); + services_discovery_t *p_sd; + p_sd = vlc_custom_create( p_super, sizeof( *p_sd ), VLC_OBJECT_GENERIC, + "services discovery" ); if( !p_sd ) return NULL; @@ -60,17 +70,21 @@ services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name vlc_ServicesDiscoveryItemAdded ); vlc_event_manager_register_event_type( &p_sd->event_manager, vlc_ServicesDiscoveryItemRemoved ); + vlc_event_manager_register_event_type( &p_sd->event_manager, + vlc_ServicesDiscoveryStarted ); + vlc_event_manager_register_event_type( &p_sd->event_manager, + vlc_ServicesDiscoveryEnded ); - p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module_name, 0 ); + p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module_name, true ); if( p_sd->p_module == NULL ) { msg_Err( p_super, "no suitable services discovery module" ); - vlc_object_destroy( p_sd ); + vlc_object_release( p_sd ); return NULL; } p_sd->psz_module = strdup( psz_module_name ); - p_sd->b_die = VLC_FALSE; /* FIXME */ + p_sd->b_die = false; /* FIXME */ vlc_object_attach( p_sd, p_super ); return p_sd; @@ -87,7 +101,7 @@ void services_discovery_Destroy ( services_discovery_t * p_sd ) free( p_sd->psz_localized_name ); vlc_object_detach( p_sd ); - vlc_object_destroy( p_sd ); + vlc_object_release( p_sd ); } /*********************************************************************** @@ -97,10 +111,10 @@ int services_discovery_Start ( services_discovery_t * p_sd ) { if ((p_sd->pf_run != NULL) && vlc_thread_create( p_sd, "services_discovery", RunSD, - VLC_THREAD_PRIORITY_LOW, VLC_FALSE)) + VLC_THREAD_PRIORITY_LOW, false)) { msg_Err( p_sd, "cannot create services discovery thread" ); - vlc_object_destroy( p_sd ); + vlc_object_release( p_sd ); return VLC_EGENERIC; } return VLC_SUCCESS; @@ -132,7 +146,7 @@ services_discovery_GetLocalizedName ( services_discovery_t * p_sd ) void services_discovery_SetLocalizedName ( services_discovery_t * p_sd, const char *psz ) { - if(p_sd->psz_localized_name) free( p_sd->psz_localized_name ); + free( p_sd->psz_localized_name ); p_sd->psz_localized_name = strdup(psz); } @@ -178,7 +192,15 @@ services_discovery_RemoveItem ( services_discovery_t * p_sd, input_item_t * p_it ***********************************************************************/ static void RunSD( services_discovery_t *p_sd ) { + vlc_event_t event; + + event.type = vlc_ServicesDiscoveryStarted; + vlc_event_send( &p_sd->event_manager, &event ); + p_sd->pf_run( p_sd ); + + event.type = vlc_ServicesDiscoveryEnded; + vlc_event_send( &p_sd->event_manager, &event ); return; } @@ -207,16 +229,19 @@ static void playlist_sd_item_added( const vlc_event_t * p_event, void * user_dat if( !p_cat ) { p_cat = playlist_NodeCreate( p_parent->p_playlist, psz_cat, - p_parent, 0 ); + p_parent, 0, NULL ); p_cat->i_flags &= ~PLAYLIST_SKIP_FLAG; } p_parent = p_cat; } p_new_item = playlist_NodeAddInput( p_parent->p_playlist, p_input, p_parent, - PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE ); - p_new_item->i_flags &= ~PLAYLIST_SKIP_FLAG; - p_new_item->i_flags &= ~PLAYLIST_SAVE_FLAG; + PLAYLIST_APPEND, PLAYLIST_END, false ); + if( p_new_item ) + { + p_new_item->i_flags &= ~PLAYLIST_SKIP_FLAG; + p_new_item->i_flags &= ~PLAYLIST_SAVE_FLAG; + } } /* A new item has been removed from a certain sd */ @@ -224,9 +249,25 @@ static void playlist_sd_item_removed( const vlc_event_t * p_event, void * user_d { input_item_t * p_input = p_event->u.services_discovery_item_removed.p_item; playlist_item_t * p_parent = user_data; + playlist_item_t * p_pl_item; + /* First make sure that if item is a node it will be deleted. + * XXX: Why don't we have a function to ensure that in the playlist code ? */ + vlc_object_lock( p_parent->p_playlist ); + p_pl_item = playlist_ItemFindFromInputAndRoot( p_parent->p_playlist, + p_input->i_id, p_parent, false ); + + if( p_pl_item && p_pl_item->i_children > -1 ) + { + playlist_NodeDelete( p_parent->p_playlist, p_pl_item, true, false ); + vlc_object_unlock( p_parent->p_playlist ); + return; + } + vlc_object_unlock( p_parent->p_playlist ); + + /* Delete the non-node item normally */ playlist_DeleteInputInParent( p_parent->p_playlist, p_input->i_id, - p_parent, VLC_FALSE ); + p_parent, false ); } int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modules ) @@ -236,7 +277,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu for (;;) { - struct playlist_archived_services_discovery_t * p_asd; + struct playlist_services_discovery_support_t * p_sds; playlist_item_t * p_cat; playlist_item_t * p_one; @@ -264,20 +305,10 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu continue; char * psz = services_discovery_GetLocalizedName( p_sd ); - if( psz ) - { - playlist_NodesPairCreate( p_playlist, psz, - &p_cat, &p_one, VLC_FALSE ); - free( psz ); - } - else - { - /* No name, just add at the top of the playlist */ - PL_LOCK; - p_cat = p_playlist->p_root_category; - p_one = p_playlist->p_root_onelevel; - PL_UNLOCK; - } + assert( psz ); + playlist_NodesPairCreate( p_playlist, psz, + &p_cat, &p_one, false ); + free( psz ); vlc_event_attach( services_discovery_EventManager( p_sd ), vlc_ServicesDiscoveryItemAdded, @@ -302,13 +333,18 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu services_discovery_Start( p_sd ); /* Free in playlist_ServicesDiscoveryRemove */ - p_asd = malloc( sizeof(struct playlist_archived_services_discovery_t) ); - p_asd->p_sd = p_sd; - p_asd->p_one = p_one; - p_asd->p_cat = p_cat; + p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) ); + if( !p_sds ) + { + msg_Err( p_playlist, "No more memory" ); + return VLC_ENOMEM; + } + p_sds->p_sd = p_sd; + p_sds->p_one = p_one; + p_sds->p_cat = p_cat; PL_LOCK; - TAB_APPEND( p_playlist->p_internal->i_asds, p_playlist->p_internal->pp_asds, p_asd ); + TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sds ); PL_UNLOCK; } @@ -318,82 +354,79 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist, const char *psz_module ) { + struct playlist_services_discovery_support_t * p_sds = NULL; int i; - struct playlist_archived_services_discovery_t *p_asd = NULL; PL_LOCK; - for( i = 0 ; i< p_playlist->p_internal->i_asds ; i ++ ) + for( i = 0 ; i< p_playlist->i_sds ; i ++ ) { - if( !strcmp( psz_module, p_playlist->p_internal->pp_asds[i]->p_sd->psz_module ) ) + if( !strcmp( psz_module, p_playlist->pp_sds[i]->p_sd->psz_module ) ) { - p_asd = p_playlist->p_internal->pp_asds[i]; - REMOVE_ELEM( p_playlist->p_internal->pp_asds, p_playlist->p_internal->i_asds, i ); + p_sds = p_playlist->pp_sds[i]; + REMOVE_ELEM( p_playlist->pp_sds, p_playlist->i_sds, i ); break; } } PL_UNLOCK; - if( p_asd && p_asd->p_sd ) + if( !p_sds || !p_sds->p_sd ) { - services_discovery_Stop( p_asd->p_sd ); + msg_Warn( p_playlist, "module %s is not loaded", psz_module ); + return VLC_EGENERIC; + } - vlc_event_detach( services_discovery_EventManager( p_asd->p_sd ), - vlc_ServicesDiscoveryItemAdded, - playlist_sd_item_added, - p_asd->p_one ); + services_discovery_Stop( p_sds->p_sd ); - vlc_event_detach( services_discovery_EventManager( p_asd->p_sd ), - vlc_ServicesDiscoveryItemAdded, - playlist_sd_item_added, - p_asd->p_cat ); + vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ), + vlc_ServicesDiscoveryItemAdded, + playlist_sd_item_added, + p_sds->p_one ); - vlc_event_detach( services_discovery_EventManager( p_asd->p_sd ), - vlc_ServicesDiscoveryItemRemoved, - playlist_sd_item_removed, - p_asd->p_one ); + vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ), + vlc_ServicesDiscoveryItemAdded, + playlist_sd_item_added, + p_sds->p_cat ); - vlc_event_detach( services_discovery_EventManager( p_asd->p_sd ), - vlc_ServicesDiscoveryItemRemoved, - playlist_sd_item_removed, - p_asd->p_cat ); + vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ), + vlc_ServicesDiscoveryItemRemoved, + playlist_sd_item_removed, + p_sds->p_one ); - /* Remove the sd playlist node if it exists */ - PL_LOCK; - if( p_asd->p_cat != p_playlist->p_root_category && - p_asd->p_one != p_playlist->p_root_onelevel ) - { - playlist_NodeDelete( p_playlist, p_asd->p_cat, VLC_TRUE, VLC_FALSE ); - playlist_NodeDelete( p_playlist, p_asd->p_one, VLC_TRUE, VLC_FALSE ); - } - PL_UNLOCK; + vlc_event_detach( services_discovery_EventManager( p_sds->p_sd ), + vlc_ServicesDiscoveryItemRemoved, + playlist_sd_item_removed, + p_sds->p_cat ); - services_discovery_Destroy( p_asd->p_sd ); - - free( p_asd ); - } - else + /* Remove the sd playlist node if it exists */ + PL_LOCK; + if( p_sds->p_cat != p_playlist->p_root_category && + p_sds->p_one != p_playlist->p_root_onelevel ) { - msg_Warn( p_playlist, "module %s is not loaded", psz_module ); - return VLC_EGENERIC; + playlist_NodeDelete( p_playlist, p_sds->p_cat, true, false ); + playlist_NodeDelete( p_playlist, p_sds->p_one, true, false ); } + PL_UNLOCK; + + services_discovery_Destroy( p_sds->p_sd ); + return VLC_SUCCESS; } -vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist, +bool playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist, const char *psz_module ) { int i; PL_LOCK; - for( i = 0 ; i< p_playlist->p_internal->i_asds ; i ++ ) + for( i = 0 ; i< p_playlist->i_sds ; i ++ ) { - if( !strcmp( psz_module, p_playlist->p_internal->pp_asds[i]->p_sd->psz_module ) ) + if( !strcmp( psz_module, p_playlist->pp_sds[i]->p_sd->psz_module ) ) { PL_UNLOCK; - return VLC_TRUE; + return true; } } PL_UNLOCK; - return VLC_FALSE; + return false; }