[vlc-devel] commit: services_discovery: Partially fix service discovery. We yet need to find a way to properly get the localized name... grr. ( Pierre d'Herbemont )
git version control
git at videolan.org
Sat Sep 20 23:09:23 CEST 2008
vlc | branch: master | Pierre d'Herbemont <pdherbemont at videolan.org> | Sat Sep 20 23:02:13 2008 +0200| [4e9d2f92cdaa51783fa29fb7518d81b7d1b21980] | committer: Pierre d'Herbemont
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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4e9d2f92cdaa51783fa29fb7518d81b7d1b21980
---
include/vlc_services_discovery.h | 16 +++++++-
src/control/media_discoverer.c | 11 +++++-
src/libvlccore.sym | 3 +-
src/playlist/services_discovery.c | 79 ++++++++++++++++++++++++++-----------
4 files changed, 82 insertions(+), 27 deletions(-)
diff --git a/include/vlc_services_discovery.h b/include/vlc_services_discovery.h
index f420647..e6778af 100644
--- a/include/vlc_services_discovery.h
+++ b/include/vlc_services_discovery.h
@@ -52,7 +52,6 @@ struct services_discovery_t
services_discovery_sys_t *p_sys;
};
-
/***********************************************************************
* Service Discovery
***********************************************************************/
@@ -65,7 +64,20 @@ VLC_EXPORT( char **, __services_discovery_GetServicesNames, ( vlc_object_t * p_s
/* 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( 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 */
VLC_EXPORT( char *, services_discovery_GetLocalizedName, ( services_discovery_t * p_this ) );
diff --git a/src/control/media_discoverer.c b/src/control/media_discoverer.c
index 1cad2c7..c1b811b 100644
--- a/src/control/media_discoverer.c
+++ b/src/control/media_discoverer.c
@@ -179,6 +179,7 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
if( !p_mdis->p_sd )
{
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 );
return NULL;
}
@@ -201,6 +202,14 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
p_mdis );
/* 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;
}
@@ -214,7 +223,7 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
int i;
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 */
char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist );
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index dc6cc29..804b6ff 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -310,7 +310,8 @@ sdp_AddMedia
secstotimestr
services_discovery_AddItem
services_discovery_Create
-services_discovery_Destroy
+services_discovery_Start
+services_discovery_Stop
services_discovery_EventManager
services_discovery_GetLocalizedName
__services_discovery_GetServicesNames
diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c
index ee91583..53d5187 100644
--- a/src/playlist/services_discovery.c
+++ b/src/playlist/services_discovery.c
@@ -31,6 +31,9 @@
#include "playlist_internal.h"
#include "../libvlc.h"
+
+static void services_discovery_Destructor ( services_discovery_t * p_sd );
+
/*
* Services discovery
* Basically you just listen to Service discovery event through the
@@ -55,12 +58,14 @@ services_discovery_t *
services_discovery_Create ( vlc_object_t * p_super, const char * psz_module_name )
{
services_discovery_t *p_sd;
+ assert( psz_module_name );
p_sd = vlc_custom_create( p_super, sizeof( *p_sd ), VLC_OBJECT_GENERIC,
"services discovery" );
if( !p_sd )
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_register_event_type( &p_sd->event_manager,
@@ -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_ServicesDiscoveryEnded );
- 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_release( p_sd );
- return NULL;
- }
- p_sd->psz_module = strdup( psz_module_name );
+ p_sd->b_die = false; /* FIXME */
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;
}
@@ -104,24 +97,56 @@ 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 = {
.type = vlc_ServicesDiscoveryEnded
};
-
+
ObjectKillChildrens( VLC_OBJECT(p_sd) );
-
+
vlc_event_send( &p_sd->event_manager, &event );
+
module_Unneed( p_sd, p_sd->p_module );
+ p_sd->p_module = NULL;
+}
- vlc_event_manager_fini( &p_sd->event_manager );
+/***********************************************************************
+ * 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 );
+
free( p_sd->psz_module );
free( p_sd->psz_localized_name );
-
+
vlc_object_release( p_sd );
}
@@ -285,6 +310,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
if( !p_sd )
continue;
+ /* FIXME: Thanks to previous changeset this is broken */
char * psz = services_discovery_GetLocalizedName( p_sd );
assert( psz );
PL_LOCK;
@@ -297,7 +323,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
vlc_ServicesDiscoveryItemAdded,
playlist_sd_item_added,
p_one );
-
+
vlc_event_attach( services_discovery_EventManager( p_sd ),
vlc_ServicesDiscoveryItemAdded,
playlist_sd_item_added,
@@ -313,6 +339,13 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
playlist_sd_item_removed,
p_cat );
+ bool ret = services_discovery_Start( p_sd );
+ if(!ret)
+ {
+ vlc_object_release( p_sd );
+ return VLC_EGENERIC;
+ }
+
/* Free in playlist_ServicesDiscoveryRemove */
p_sds = malloc( sizeof(struct playlist_services_discovery_support_t) );
if( !p_sds )
@@ -327,6 +360,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modu
PL_LOCK;
TAB_APPEND( p_playlist->i_sds, p_playlist->pp_sds, p_sds );
PL_UNLOCK;
+
}
return retval;
@@ -386,7 +420,7 @@ int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
}
PL_UNLOCK;
- services_discovery_Destroy( p_sds->p_sd );
+ services_discovery_StopAndRelease( p_sds->p_sd );
free( p_sds );
return VLC_SUCCESS;
@@ -416,4 +450,3 @@ void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist )
playlist_ServicesDiscoveryRemove( p_playlist,
p_playlist->pp_sds[0]->p_sd->psz_module );
}
-
More information about the vlc-devel
mailing list