Commit 4e9d2f92 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

services_discovery: Partially fix service discovery. We yet need to find a way...

services_discovery: Partially fix service discovery. We yet need to find a way to properly get the localized name... grr.

Previously we properly initialized the localized name of the object in Open(). Now Open() also runs Run() so we are kind of stuck. Please fix.
parent 319d3dcf
...@@ -52,7 +52,6 @@ struct services_discovery_t ...@@ -52,7 +52,6 @@ struct services_discovery_t
services_discovery_sys_t *p_sys; services_discovery_sys_t *p_sys;
}; };
/*********************************************************************** /***********************************************************************
* Service Discovery * Service Discovery
***********************************************************************/ ***********************************************************************/
...@@ -65,7 +64,20 @@ VLC_EXPORT( char **, __services_discovery_GetServicesNames, ( vlc_object_t * p_s ...@@ -65,7 +64,20 @@ VLC_EXPORT( char **, __services_discovery_GetServicesNames, ( vlc_object_t * p_s
/* Creation of a service_discovery object */ /* Creation of a service_discovery object */
VLC_EXPORT( services_discovery_t *, services_discovery_Create, ( vlc_object_t * p_super, const char * psz_service_name ) ); VLC_EXPORT( services_discovery_t *, services_discovery_Create, ( vlc_object_t * p_super, const char * psz_service_name ) );
VLC_EXPORT( void, services_discovery_Destroy, ( services_discovery_t * p_this ) ); VLC_EXPORT( bool, services_discovery_Start, ( services_discovery_t * p_this ) );
VLC_EXPORT( void, services_discovery_Stop, ( services_discovery_t * p_this ) );
static inline void services_discovery_CreateAndStart( vlc_object_t * p_super, const char * psz_service_name )
{
services_discovery_t * sd = services_discovery_Create( p_super, psz_service_name );
services_discovery_Start( sd );
}
static inline void services_discovery_StopAndRelease( services_discovery_t * p_this )
{
services_discovery_Stop( p_this );
vlc_object_release( p_this );
}
/* Read info from discovery object */ /* Read info from discovery object */
VLC_EXPORT( char *, services_discovery_GetLocalizedName, ( services_discovery_t * p_this ) ); VLC_EXPORT( char *, services_discovery_GetLocalizedName, ( services_discovery_t * p_this ) );
......
...@@ -179,6 +179,7 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst, ...@@ -179,6 +179,7 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
if( !p_mdis->p_sd ) if( !p_mdis->p_sd )
{ {
free( p_mdis ); free( p_mdis );
libvlc_media_list_release( p_mdis->p_mlist );
libvlc_exception_raise( p_e, "Can't find the services_discovery module named '%s'", psz_name ); libvlc_exception_raise( p_e, "Can't find the services_discovery module named '%s'", psz_name );
return NULL; return NULL;
} }
...@@ -201,6 +202,14 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst, ...@@ -201,6 +202,14 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
p_mdis ); p_mdis );
/* Here we go */ /* Here we go */
bool ret = services_discovery_Start( p_mdis->p_sd );
if(!ret)
{
free( p_mdis );
libvlc_media_list_release( p_mdis->p_mlist );
libvlc_exception_raise( p_e, "Can't start the services_discovery module named '%s'", psz_name );
return NULL;
}
return p_mdis; return p_mdis;
} }
...@@ -214,7 +223,7 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis ) ...@@ -214,7 +223,7 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
int i; int i;
libvlc_media_list_release( p_mdis->p_mlist ); libvlc_media_list_release( p_mdis->p_mlist );
services_discovery_Destroy( p_mdis->p_sd ); services_discovery_StopAndRelease( p_mdis->p_sd );
/* Free catname_to_submedialist and all the mlist */ /* Free catname_to_submedialist and all the mlist */
char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist ); char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist );
......
...@@ -310,7 +310,8 @@ sdp_AddMedia ...@@ -310,7 +310,8 @@ sdp_AddMedia
secstotimestr secstotimestr
services_discovery_AddItem services_discovery_AddItem
services_discovery_Create services_discovery_Create
services_discovery_Destroy services_discovery_Start
services_discovery_Stop
services_discovery_EventManager services_discovery_EventManager
services_discovery_GetLocalizedName services_discovery_GetLocalizedName
__services_discovery_GetServicesNames __services_discovery_GetServicesNames
......
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
#include "playlist_internal.h" #include "playlist_internal.h"
#include "../libvlc.h" #include "../libvlc.h"
static void services_discovery_Destructor ( services_discovery_t * p_sd );
/* /*
* Services discovery * Services discovery
* Basically you just listen to Service discovery event through the * Basically you just listen to Service discovery event through the
...@@ -55,12 +58,14 @@ services_discovery_t * ...@@ -55,12 +58,14 @@ services_discovery_t *
services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name ) services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name )
{ {
services_discovery_t *p_sd; services_discovery_t *p_sd;
assert( psz_module_name );
p_sd = vlc_custom_create( p_super, sizeof( *p_sd ), VLC_OBJECT_GENERIC, p_sd = vlc_custom_create( p_super, sizeof( *p_sd ), VLC_OBJECT_GENERIC,
"services discovery" ); "services discovery" );
if( !p_sd ) if( !p_sd )
return NULL; return NULL;
p_sd->psz_localized_name = NULL; p_sd->psz_localized_name = strdup( "Unnamed service discovery" ); // FIXME: Set that back to NULL
p_sd->psz_module = strdup( psz_module_name );
vlc_event_manager_init( &p_sd->event_manager, p_sd, (vlc_object_t *)p_sd ); vlc_event_manager_init( &p_sd->event_manager, p_sd, (vlc_object_t *)p_sd );
vlc_event_manager_register_event_type( &p_sd->event_manager, vlc_event_manager_register_event_type( &p_sd->event_manager,
...@@ -72,22 +77,10 @@ services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name ...@@ -72,22 +77,10 @@ services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name
vlc_event_manager_register_event_type( &p_sd->event_manager, vlc_event_manager_register_event_type( &p_sd->event_manager,
vlc_ServicesDiscoveryEnded ); vlc_ServicesDiscoveryEnded );
p_sd->p_module = module_Need( p_sd, "services_discovery", psz_module_name, true ); p_sd->b_die = false; /* FIXME */
if( p_sd->p_module == NULL )
{
msg_Err( p_super, "no suitable services discovery module" );
vlc_object_release( p_sd );
return NULL;
}
p_sd->psz_module = strdup( psz_module_name );
vlc_object_attach( p_sd, p_super ); vlc_object_attach( p_sd, p_super );
vlc_event_t event = {
.type = vlc_ServicesDiscoveryStarted
};
vlc_event_send( &p_sd->event_manager, &event );
return p_sd; return p_sd;
} }
...@@ -104,9 +97,31 @@ static void ObjectKillChildrens( vlc_object_t *p_obj ) ...@@ -104,9 +97,31 @@ static void ObjectKillChildrens( vlc_object_t *p_obj )
} }
/*********************************************************************** /***********************************************************************
* Destroy * Stop
***********************************************************************/
bool services_discovery_Start ( services_discovery_t * p_sd )
{
assert(!p_sd->p_module);
p_sd->p_module = module_Need( p_sd, "services_discovery", p_sd->psz_module, true );
if( p_sd->p_module == NULL )
{
msg_Err( p_sd, "no suitable services discovery module" );
return false;
}
vlc_event_t event = {
.type = vlc_ServicesDiscoveryStarted
};
vlc_event_send( &p_sd->event_manager, &event );
return true;
}
/***********************************************************************
* Stop
***********************************************************************/ ***********************************************************************/
void services_discovery_Destroy ( services_discovery_t * p_sd ) void services_discovery_Stop ( services_discovery_t * p_sd )
{ {
vlc_event_t event = { vlc_event_t event = {
.type = vlc_ServicesDiscoveryEnded .type = vlc_ServicesDiscoveryEnded
...@@ -115,7 +130,17 @@ void services_discovery_Destroy ( services_discovery_t * p_sd ) ...@@ -115,7 +130,17 @@ void services_discovery_Destroy ( services_discovery_t * p_sd )
ObjectKillChildrens( VLC_OBJECT(p_sd) ); ObjectKillChildrens( VLC_OBJECT(p_sd) );
vlc_event_send( &p_sd->event_manager, &event ); vlc_event_send( &p_sd->event_manager, &event );
module_Unneed( p_sd, p_sd->p_module ); module_Unneed( p_sd, p_sd->p_module );
p_sd->p_module = NULL;
}
/***********************************************************************
* Destructor
***********************************************************************/
static void services_discovery_Destructor ( services_discovery_t * p_sd )
{
assert(!p_sd->p_module); /* Forgot to call Stop */
vlc_event_manager_fini( &p_sd->event_manager ); vlc_event_manager_fini( &p_sd->event_manager );
...@@ -285,6 +310,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu ...@@ -285,6 +310,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
if( !p_sd ) if( !p_sd )
continue; continue;
/* FIXME: Thanks to previous changeset this is broken */
char * psz = services_discovery_GetLocalizedName( p_sd ); char * psz = services_discovery_GetLocalizedName( p_sd );
assert( psz ); assert( psz );
PL_LOCK; PL_LOCK;
...@@ -313,6 +339,13 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu ...@@ -313,6 +339,13 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
playlist_sd_item_removed, playlist_sd_item_removed,
p_cat ); p_cat );
bool ret = services_discovery_Start( p_sd );
if(!ret)
{
vlc_object_release( p_sd );
return VLC_EGENERIC;
}
/* Free in playlist_ServicesDiscoveryRemove */ /* Free in playlist_ServicesDiscoveryRemove */
p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) ); p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );
if( !p_sds ) if( !p_sds )
...@@ -327,6 +360,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu ...@@ -327,6 +360,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
PL_LOCK; PL_LOCK;
TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sds ); TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sds );
PL_UNLOCK; PL_UNLOCK;
} }
return retval; return retval;
...@@ -386,7 +420,7 @@ int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist, ...@@ -386,7 +420,7 @@ int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
} }
PL_UNLOCK; PL_UNLOCK;
services_discovery_Destroy( p_sds->p_sd ); services_discovery_StopAndRelease( p_sds->p_sd );
free( p_sds ); free( p_sds );
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -416,4 +450,3 @@ void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist ) ...@@ -416,4 +450,3 @@ void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist )
playlist_ServicesDiscoveryRemove( p_playlist, playlist_ServicesDiscoveryRemove( p_playlist,
p_playlist->pp_sds[0]->p_sd->psz_module ); p_playlist->pp_sds[0]->p_sd->psz_module );
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment