[vlc-commits] sd: move callbacks to constant structure

Rémi Denis-Courmont git at videolan.org
Sun Jun 10 14:12:07 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 10 15:11:07 2018 +0300| [9882ff2ece6d9c71639523f7e862418ac1a3da54] | committer: Rémi Denis-Courmont

sd: move callbacks to constant structure

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

 include/vlc_services_discovery.h  | 17 +++++++++++------
 lib/media_discoverer.c            |  8 ++++++--
 src/playlist/services_discovery.c |  8 ++++++--
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/include/vlc_services_discovery.h b/include/vlc_services_discovery.h
index 682a3654cf..1f5305b788 100644
--- a/include/vlc_services_discovery.h
+++ b/include/vlc_services_discovery.h
@@ -40,14 +40,19 @@ extern "C" {
  * @{
  */
 
-struct services_discovery_owner_t
+struct services_discovery_callbacks
 {
-    void *sys; /**< Private data for the owner callbacks */
     void (*item_added)(struct services_discovery_t *sd, input_item_t *parent,
                        input_item_t *item, const char *category);
     void (*item_removed)(struct services_discovery_t *sd, input_item_t *item);
 };
 
+struct services_discovery_owner_t
+{
+    const struct services_discovery_callbacks *cbs;
+    void *sys; /**< Private data for the owner callbacks */
+};
+
 /**
  * Main service discovery structure to build a SD module
  */
@@ -157,7 +162,7 @@ VLC_API void vlc_sd_Destroy( services_discovery_t * );
 static inline void services_discovery_AddItem(services_discovery_t *sd,
                                               input_item_t *item)
 {
-    sd->owner.item_added(sd, NULL, item, NULL);
+    sd->owner.cbs->item_added(sd, NULL, item, NULL);
 }
 
 /**
@@ -181,7 +186,7 @@ static inline void services_discovery_AddSubItem(services_discovery_t *sd,
                                                  input_item_t *parent,
                                                  input_item_t *item)
 {
-    sd->owner.item_added(sd, parent, item, NULL);
+    sd->owner.cbs->item_added(sd, parent, item, NULL);
 }
 
 /**
@@ -195,7 +200,7 @@ static inline void services_discovery_AddItemCat(services_discovery_t *sd,
                                                  input_item_t *item,
                                                  const char *category)
 {
-    sd->owner.item_added(sd, NULL, item, category);
+    sd->owner.cbs->item_added(sd, NULL, item, category);
 }
 
 /**
@@ -207,7 +212,7 @@ static inline void services_discovery_AddItemCat(services_discovery_t *sd,
 static inline void services_discovery_RemoveItem(services_discovery_t *sd,
                                                  input_item_t *item)
 {
-    sd->owner.item_removed(sd, item);
+    sd->owner.cbs->item_removed(sd, item);
 }
 
 /* SD probing */
diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
index b0004ffb1f..f3a13a7717 100644
--- a/lib/media_discoverer.c
+++ b/lib/media_discoverer.c
@@ -169,6 +169,11 @@ libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char * psz_name )
     return p_mdis;
 }
 
+static const struct services_discovery_callbacks sd_cbs = {
+    .item_added = services_discovery_item_added,
+    .item_removed = services_discovery_item_removed,
+};
+
 /**************************************************************************
  *       start (Public)
  **************************************************************************/
@@ -176,9 +181,8 @@ LIBVLC_API int
 libvlc_media_discoverer_start( libvlc_media_discoverer_t * p_mdis )
 {
     struct services_discovery_owner_t owner = {
+        &sd_cbs,
         p_mdis,
-        services_discovery_item_added,
-        services_discovery_item_removed,
     };
 
     /* Here we go */
diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c
index 39a43badd6..3e68366ed2 100644
--- a/src/playlist/services_discovery.c
+++ b/src/playlist/services_discovery.c
@@ -110,6 +110,11 @@ static void playlist_sd_item_removed(services_discovery_t *sd,
     playlist_Unlock(playlist);
 }
 
+static const struct services_discovery_callbacks playlist_sd_cbs = {
+    .item_added = playlist_sd_item_added,
+    .item_removed = playlist_sd_item_removed,
+};
+
 int playlist_ServicesDiscoveryAdd(playlist_t *playlist, const char *chain)
 {
     vlc_sd_internal_t *sds = malloc(sizeof (*sds) + strlen(chain) + 1);
@@ -119,9 +124,8 @@ int playlist_ServicesDiscoveryAdd(playlist_t *playlist, const char *chain)
     sds->node = NULL;
 
     struct services_discovery_owner_t owner = {
+        &playlist_sd_cbs,
         sds,
-        playlist_sd_item_added,
-        playlist_sd_item_removed,
     };
 
     /* Perform the addition */



More information about the vlc-commits mailing list