[vlc-commits] sd: merge Create and Start, and Stop and Destroy

Rémi Denis-Courmont git at videolan.org
Mon Nov 14 21:03:03 CET 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Nov 14 22:01:27 2016 +0200| [6d370752244733f394b636e72ef7643cb8416dee] | committer: Rémi Denis-Courmont

sd: merge Create and Start, and Stop and Destroy

Without the legacy event handler, the distinction is superfluous.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6d370752244733f394b636e72ef7643cb8416dee
---

 include/vlc_services_discovery.h  |  2 --
 lib/media_discoverer.c            | 53 ++++++++++++++++--------------------
 src/libvlccore.sym                |  2 --
 src/playlist/services_discovery.c | 56 +++++++++------------------------------
 4 files changed, 36 insertions(+), 77 deletions(-)

diff --git a/include/vlc_services_discovery.h b/include/vlc_services_discovery.h
index 50a3b8a..4c5f4f6 100644
--- a/include/vlc_services_discovery.h
+++ b/include/vlc_services_discovery.h
@@ -143,8 +143,6 @@ VLC_API services_discovery_t *vlc_sd_Create(vlc_object_t *parent,
     const char *chain, const struct services_discovery_owner_t *owner)
 VLC_USED;
 
-VLC_API bool vlc_sd_Start( services_discovery_t * );
-VLC_API void vlc_sd_Stop( services_discovery_t * );
 VLC_API void vlc_sd_Destroy( services_discovery_t * );
 
 /* Read info from discovery object */
diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
index 730b5c3..9d4ded5 100644
--- a/lib/media_discoverer.c
+++ b/lib/media_discoverer.c
@@ -45,8 +45,8 @@ struct libvlc_media_discoverer_t
     libvlc_instance_t *      p_libvlc_instance;
     services_discovery_t *   p_sd;
     libvlc_media_list_t *    p_mlist;
-    bool                     running;
     vlc_dictionary_t         catname_to_submedialist;
+    char                     name[];
 };
 
 /*
@@ -143,8 +143,10 @@ libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char * psz_name )
     if( !strncasecmp( psz_name, "podcast", 7 ) )
         return NULL;
 
-    libvlc_media_discoverer_t *p_mdis = malloc(sizeof(*p_mdis));
-    if( unlikely(!p_mdis) )
+    libvlc_media_discoverer_t *p_mdis;
+
+    p_mdis = malloc(sizeof(*p_mdis) + strlen(psz_name) + 1);
+    if( unlikely(p_mdis == NULL) )
     {
         libvlc_printerr( "Not enough memory" );
         return NULL;
@@ -153,7 +155,7 @@ libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char * psz_name )
     p_mdis->p_libvlc_instance = p_inst;
     p_mdis->p_mlist = libvlc_media_list_new( p_inst );
     p_mdis->p_mlist->b_read_only = true;
-    p_mdis->running = false;
+    p_mdis->p_sd = NULL;
 
     vlc_dictionary_init( &p_mdis->catname_to_submedialist, 0 );
 
@@ -164,24 +166,8 @@ libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char * psz_name )
         return NULL;
     }
 
-    struct services_discovery_owner_t owner = {
-        p_mdis,
-        services_discovery_item_added,
-        services_discovery_item_removed,
-    };
-
-    p_mdis->p_sd = vlc_sd_Create( (vlc_object_t*)p_inst->p_libvlc_int,
-                                  psz_name, &owner );
-    if( unlikely(p_mdis->p_sd == NULL) )
-    {
-        libvlc_printerr( "%s: no such discovery module found", psz_name );
-        libvlc_media_list_release( p_mdis->p_mlist );
-        libvlc_event_manager_release( p_mdis->p_event_manager );
-        free( p_mdis );
-        return NULL;
-    }
-
     libvlc_retain( p_inst );
+    strcpy( p_mdis->name, psz_name );
     return p_mdis;
 }
 
@@ -191,11 +177,21 @@ libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char * psz_name )
 LIBVLC_API int
 libvlc_media_discoverer_start( libvlc_media_discoverer_t * p_mdis )
 {
+    struct services_discovery_owner_t owner = {
+        p_mdis,
+        services_discovery_item_added,
+        services_discovery_item_removed,
+    };
+
     /* Here we go */
-    if (!vlc_sd_Start( p_mdis->p_sd ))
+    p_mdis->p_sd = vlc_sd_Create( (vlc_object_t *)p_mdis->p_libvlc_instance->p_libvlc_int,
+                                  p_mdis->name, &owner );
+    if( p_mdis->p_sd == NULL )
+    {
+        libvlc_printerr( "%s: no such discovery module found", p_mdis->name );
         return -1;
+    }
 
-    p_mdis->running = true;
     libvlc_event_t event;
     event.type = libvlc_MediaDiscovererStarted;
     libvlc_event_send( p_mdis->p_event_manager, &event );
@@ -208,8 +204,6 @@ libvlc_media_discoverer_start( libvlc_media_discoverer_t * p_mdis )
 LIBVLC_API void
 libvlc_media_discoverer_stop( libvlc_media_discoverer_t * p_mdis )
 {
-    p_mdis->running = false;
-
     libvlc_media_list_t * p_mlist = p_mdis->p_mlist;
     libvlc_media_list_lock( p_mlist );
     libvlc_media_list_internal_end_reached( p_mlist );
@@ -219,7 +213,8 @@ libvlc_media_discoverer_stop( libvlc_media_discoverer_t * p_mdis )
     event.type = libvlc_MediaDiscovererEnded;
     libvlc_event_send( p_mdis->p_event_manager, &event );
 
-    vlc_sd_Stop( p_mdis->p_sd );
+    vlc_sd_Destroy( p_mdis->p_sd );
+    p_mdis->p_sd = NULL;
 }
 
 /**************************************************************************
@@ -251,11 +246,9 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
 void
 libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
 {
-    if( p_mdis->running )
+    if( p_mdis->p_sd != NULL )
         libvlc_media_discoverer_stop( p_mdis );
 
-    vlc_sd_Destroy( p_mdis->p_sd );
-
     libvlc_media_list_release( p_mdis->p_mlist );
 
     /* Free catname_to_submedialist and all the mlist */
@@ -310,7 +303,7 @@ libvlc_media_discoverer_event_manager( libvlc_media_discoverer_t * p_mdis )
 int
 libvlc_media_discoverer_is_running( libvlc_media_discoverer_t * p_mdis )
 {
-    return p_mdis->running;
+    return p_mdis->p_sd != NULL;
 }
 
 void
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index e60299f..5d45cdd 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -662,8 +662,6 @@ vlc_sd_Destroy
 vlc_sd_GetNames
 vlc_sd_probe_Add
 vlc_sdp_Start
-vlc_sd_Start
-vlc_sd_Stop
 vlc_testcancel
 vlc_thread_self
 vlc_thread_id
diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c
index b31ae88..d8f75e0 100644
--- a/src/playlist/services_discovery.c
+++ b/src/playlist/services_discovery.c
@@ -116,44 +116,25 @@ services_discovery_t *vlc_sd_Create(vlc_object_t *parent, const char *cfg,
     free(config_ChainCreate(&sd->psz_name, &sd->p_cfg, cfg));
     sd->owner = *owner;
 
-    return sd;
-}
-
-/*******************************************************************//**
- * Start a Service Discovery
- ***********************************************************************/
-bool vlc_sd_Start ( services_discovery_t * p_sd )
-{
-    assert(!p_sd->p_module);
-
-    p_sd->p_module = module_need( p_sd, "services_discovery",
-                                  p_sd->psz_name, true );
-    if( p_sd->p_module == NULL )
+    sd->p_module = module_need(sd, "services_discovery",
+                               sd->psz_name, true);
+    if (sd->p_module == NULL)
     {
-        msg_Err( p_sd, "no suitable services discovery module" );
-        return false;
+        msg_Err(sd, "no suitable services discovery module");
+        vlc_sd_Destroy(sd);
+        sd = NULL;
     }
 
-    return true;
-}
-
-/*******************************************************************//**
- * Stop a Service Discovery
- ***********************************************************************/
-void vlc_sd_Stop ( services_discovery_t * p_sd )
-{
-    module_unneed( p_sd, p_sd->p_module );
-    p_sd->p_module = NULL;
+    return sd;
 }
 
-/*******************************************************************//**
- * Destroy a Service Discovery
- ***********************************************************************/
-void vlc_sd_Destroy( services_discovery_t *p_sd )
+void vlc_sd_Destroy(services_discovery_t *sd)
 {
-    config_ChainDestroy( p_sd->p_cfg );
-    free( p_sd->psz_name );
-    vlc_object_release( p_sd );
+    if (sd->p_module != NULL)
+        module_unneed(sd, sd->p_module);
+    config_ChainDestroy(sd->p_cfg);
+    free(sd->psz_name);
+    vlc_object_release(sd);
 }
 
 /*******************************************************************//**
@@ -295,16 +276,6 @@ int playlist_ServicesDiscoveryAdd(playlist_t *playlist, const char *chain)
         return VLC_ENOMEM;
     }
 
-    if (!vlc_sd_Start(sds->sd))
-    {
-        vlc_sd_Destroy(sds->sd);
-        playlist_Lock(playlist);
-        playlist_NodeDelete(playlist, sds->node, true, false);
-        playlist_Unlock(playlist);
-        free(sds);
-        return VLC_EGENERIC;
-    }
-
     strcpy(sds->name, chain);
 
     playlist_Lock(playlist);
@@ -317,7 +288,6 @@ static void playlist_ServicesDiscoveryInternalRemove(playlist_t *playlist,
                                                      vlc_sd_internal_t *sds)
 {
     assert(sds->sd != NULL);
-    vlc_sd_Stop(sds->sd);
     vlc_sd_Destroy(sds->sd);
 
     /* Remove the sd playlist node if it exists */



More information about the vlc-commits mailing list