[vlc-commits] [Git][videolan/vlc][master] 5 commits: sd: pulse: use AddSubItem() instead of AddItemCat()

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Feb 10 08:25:05 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
f5195886 by Thomas Guillem at 2024-02-10T07:54:29+00:00
sd: pulse: use AddSubItem() instead of AddItemCat()

AddItemCat() is deprecated and sd categories are not plugged to our
media_source.

This adds one top node for all pulse devices, sorted by card.

- - - - -
b0dafb97 by Thomas Guillem at 2024-02-10T07:54:29+00:00
sd: sap: refactor AddItemCat()

Call this deprecated function in only one place.

- - - - -
95eed505 by Thomas Guillem at 2024-02-10T07:54:29+00:00
sd: sap: move sys declaration up

- - - - -
fd84c2b4 by Thomas Guillem at 2024-02-10T07:54:29+00:00
sd: sap: use AddSubItem() instead of AddItemCat()

AddItemCat() is deprecated and sd categories are not plugged to our
media_source.

This adds one top node for all sap items, sorted by category.

- - - - -
fd1444e8 by Thomas Guillem at 2024-02-10T07:54:29+00:00
sd: remove deprecated category support

- - - - -


5 changed files:

- include/vlc_services_discovery.h
- lib/media_discoverer.c
- modules/services_discovery/pulse.c
- modules/services_discovery/sap.c
- src/media_source/media_source.c


Changes:

=====================================
include/vlc_services_discovery.h
=====================================
@@ -42,7 +42,7 @@ extern "C" {
 struct services_discovery_callbacks
 {
     void (*item_added)(struct services_discovery_t *sd, input_item_t *parent,
-                       input_item_t *item, const char *category);
+                       input_item_t *item);
     void (*item_removed)(struct services_discovery_t *sd, input_item_t *item);
 };
 
@@ -163,7 +163,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.cbs->item_added(sd, NULL, item, NULL);
+    sd->owner.cbs->item_added(sd, NULL, item);
 }
 
 /**
@@ -188,23 +188,7 @@ static inline void services_discovery_AddSubItem(services_discovery_t *sd,
                                                  input_item_t *parent,
                                                  input_item_t *item)
 {
-    sd->owner.cbs->item_added(sd, parent, item, NULL);
-}
-
-/**
- * Added service backward compatibility callback.
- *
- * @param sd the service discovery instance exposing the item
- * @param item the item to expose from the service
- * @param category Optional name of a group that the item belongs in
- *                 (for backward compatibility with legacy modules)
- */
-VLC_DEPRECATED
-static inline void services_discovery_AddItemCat(services_discovery_t *sd,
-                                                 input_item_t *item,
-                                                 const char *category)
-{
-    sd->owner.cbs->item_added(sd, NULL, item, category);
+    sd->owner.cbs->item_added(sd, parent, item);
 }
 
 /**


=====================================
lib/media_discoverer.c
=====================================
@@ -44,7 +44,6 @@ struct libvlc_media_discoverer_t
     libvlc_instance_t *      p_libvlc_instance;
     services_discovery_t *   p_sd;
     libvlc_media_list_t *    p_mlist;
-    vlc_dictionary_t         catname_to_submedialist;
     char                     name[];
 };
 
@@ -58,8 +57,7 @@ struct libvlc_media_discoverer_t
 
 static void services_discovery_item_added( services_discovery_t *sd,
                                            input_item_t *parent,
-                                           input_item_t *p_item,
-                                           const char *psz_cat )
+                                           input_item_t *p_item )
 {
     libvlc_media_t * p_md;
     libvlc_media_discoverer_t *p_mdis = sd->owner.sys;
@@ -67,36 +65,7 @@ static void services_discovery_item_added( services_discovery_t *sd,
 
     p_md = libvlc_media_new_from_input_item( p_item );
 
-    if( parent != NULL )
-    {
-        /* Flatten items list for now. TODO: tree support. */
-    }
-    else
-    /* If we have a category, that mean we have to group the items having
-     * that category in a media_list. */
-    if( psz_cat )
-    {
-        p_mlist = vlc_dictionary_value_for_key( &p_mdis->catname_to_submedialist, psz_cat );
-
-        if( p_mlist == kVLCDictionaryNotFound )
-        {
-            libvlc_media_t * p_catmd;
-            p_catmd = libvlc_media_new_as_node( psz_cat );
-            p_mlist = libvlc_media_subitems( p_catmd );
-
-            /* Insert the newly created mlist in our dictionary */
-            vlc_dictionary_insert( &p_mdis->catname_to_submedialist, psz_cat, p_mlist );
-
-            /* Insert the md into the root list */
-            libvlc_media_list_lock( p_mdis->p_mlist );
-            libvlc_media_list_internal_add_media( p_mdis->p_mlist, p_catmd );
-            libvlc_media_list_unlock( p_mdis->p_mlist );
-
-            /* We don't release the mlist cause the dictionary
-             * doesn't retain the object. But we release the md. */
-            libvlc_media_release( p_catmd );
-        }
-    }
+    (void) parent; /* Flatten items list for now. TODO: tree support. */
 
     libvlc_media_list_lock( p_mlist );
     libvlc_media_list_internal_add_media( p_mlist, p_md );
@@ -160,8 +129,6 @@ libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char * psz_name )
     p_mdis->p_mlist->b_read_only = true;
     p_mdis->p_sd = NULL;
 
-    vlc_dictionary_init( &p_mdis->catname_to_submedialist, 0 );
-
     libvlc_retain( p_inst );
     strcpy( p_mdis->name, psz_name );
     return p_mdis;
@@ -213,12 +180,6 @@ libvlc_media_discoverer_stop( libvlc_media_discoverer_t * p_mdis )
 /**************************************************************************
  * release (Public)
  **************************************************************************/
-static void
-MediaListDictValueRelease( void* mlist, void* obj )
-{
-    libvlc_media_list_release( mlist );
-    (void)obj;
-}
 
 void
 libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
@@ -228,9 +189,6 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
 
     libvlc_media_list_release( p_mdis->p_mlist );
 
-    vlc_dictionary_clear( &p_mdis->catname_to_submedialist,
-        MediaListDictValueRelease, NULL );
-
     libvlc_release( p_mdis->p_libvlc_instance );
 
     free( p_mdis );


=====================================
modules/services_discovery/pulse.c
=====================================
@@ -52,6 +52,7 @@ vlc_module_end ()
 typedef struct
 {
     void                 *root;
+    void                 *root_card;
     pa_context           *context;
     pa_threaded_mainloop *mainloop;
 } services_discovery_sys_t;
@@ -81,6 +82,7 @@ static int Open (vlc_object_t *obj)
     sd->description = _("Audio capture");
     sys->context = ctx;
     sys->root = NULL;
+    sys->root_card = NULL;
 
     /* Subscribe for source events */
     const pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SOURCE;
@@ -115,6 +117,13 @@ struct device
     services_discovery_t *sd;
 };
 
+struct card
+{
+    input_item_t *item;
+    services_discovery_t *sd;
+    char name[];
+};
+
 static void DestroySource (void *data)
 {
     struct device *d = data;
@@ -124,6 +133,15 @@ static void DestroySource (void *data)
     free (d);
 }
 
+static void DestroyCard(void *data)
+{
+    struct card *c = data;
+
+    services_discovery_RemoveItem(c->sd, c->item);
+    input_item_Release(c->item);
+    free(c);
+}
+
 /**
  * Compares two devices (to support binary search).
  */
@@ -135,6 +153,54 @@ static int cmpsrc (const void *a, const void *b)
     return (idxa != idxb) ? ((idxa < idxb) ? -1 : +1) : 0;
 }
 
+static int cmpcard (const void *a, const void *b)
+{
+    const struct card *ca = a, *cb = b;
+    return strcmp(ca->name, cb->name);
+}
+
+static input_item_t *AddCard (services_discovery_t *sd, const pa_source_info *info)
+{
+    services_discovery_sys_t *sys = sd->p_sys;
+
+    const char *card_name = pa_proplist_gets(info->proplist, "device.product.name");
+    if (card_name == NULL)
+        card_name = N_("Generic");
+
+    struct card *c = malloc(sizeof(*c) + strlen(card_name) + 1);
+    if (unlikely(c == NULL))
+        return NULL;
+    strcpy(c->name, card_name);
+
+    void **cp = tsearch(c, &sys->root_card, cmpcard);
+    if (cp == NULL) /* Out-of-memory */
+    {
+        free(c);
+        return NULL;
+    }
+    if (*cp != c)
+    {
+        free(c);
+        c = *cp;
+        assert(c->item != NULL);
+        return c->item;
+    }
+
+    c->item = input_item_NewExt("vlc://nop", c->name,
+                                INPUT_DURATION_INDEFINITE,
+                                ITEM_TYPE_NODE, ITEM_LOCAL);
+
+    if (unlikely(c->item == NULL))
+    {
+        tdelete(c, &sys->root_card, cmpcard);
+        return NULL;
+    }
+    services_discovery_AddItem(sd, c->item);
+    c->sd = sd;
+
+    return c->item;
+}
+
 /**
  * Adds a source.
  */
@@ -179,9 +245,8 @@ static int AddSource (services_discovery_t *sd, const pa_source_info *info)
         return 0;
     }
 
-    const char *card = pa_proplist_gets(info->proplist, "device.product.name");
-    services_discovery_AddItemCat(sd, item,
-                                  (card != NULL) ? card : N_("Generic"));
+    input_item_t *card = AddCard(sd, info);
+    services_discovery_AddSubItem(sd, card, item);
     d->sd = sd;
     return 0;
 }
@@ -243,5 +308,6 @@ static void Close (vlc_object_t *obj)
 
     vlc_pa_disconnect (obj, sys->context, sys->mainloop);
     tdestroy (sys->root, DestroySource);
+    tdestroy (sys->root_card, DestroyCard);
     free (sys);
 }


=====================================
modules/services_discovery/sap.c
=====================================
@@ -59,6 +59,10 @@
 #   include <net/if.h>
 #endif
 
+#ifdef HAVE_SEARCH_H
+#   include <search.h>
+#endif
+
 #include "access/rtp/sdp.h"
 
 /************************************************************************
@@ -79,6 +83,23 @@
 #define SAP_V4_LINK_ADDRESS     "224.0.0.255"
 #define ADD_SESSION 1
 
+typedef struct
+{
+    vlc_thread_t thread;
+
+    /* Socket descriptors */
+    int i_fd;
+    int *pi_fd;
+
+    /* Table of announces */
+    int i_announces;
+    struct sap_announce_t **pp_announces;
+
+    vlc_tick_t i_timeout;
+
+    void *root_cat;
+} services_discovery_sys_t;
+
 static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i_len )
 {
 #ifdef HAVE_ZLIB
@@ -127,6 +148,66 @@ static int Decompress( const unsigned char *psz_src, unsigned char **_dst, int i
 #endif
 }
 
+struct category
+{
+    input_item_t *item;
+    services_discovery_t *sd;
+    char name[];
+};
+
+static void DestroyCategory(void *data)
+{
+    struct category *c = data;
+
+    services_discovery_RemoveItem(c->sd, c->item);
+    input_item_Release(c->item);
+    free(c);
+}
+
+static int cmpcat (const void *a, const void *b)
+{
+    const struct category *ca = a, *cb = b;
+    return strcmp(ca->name, cb->name);
+}
+
+static input_item_t *AddCategory (services_discovery_t *sd, const char *name)
+{
+    services_discovery_sys_t *sys = sd->p_sys;
+
+    struct category *c = malloc(sizeof(*c) + strlen(name) + 1);
+    if (unlikely(c == NULL))
+        return NULL;
+    strcpy(c->name, name);
+
+    void **cp = tsearch(c, &sys->root_cat, cmpcat);
+    if (cp == NULL) /* Out-of-memory */
+    {
+        free(c);
+        return NULL;
+    }
+    if (*cp != c)
+    {
+        free(c);
+        c = *cp;
+        assert(c->item != NULL);
+        return c->item;
+    }
+
+    c->item = input_item_NewExt("vlc://nop", c->name,
+                                INPUT_DURATION_INDEFINITE,
+                                ITEM_TYPE_NODE, ITEM_LOCAL);
+
+    if (unlikely(c->item == NULL))
+    {
+        tdelete(c, &sys->root_cat, cmpcat);
+        return NULL;
+    }
+    services_discovery_AddItem(sd, c->item);
+    c->sd = sd;
+
+    return c->item;
+}
+
 typedef struct sap_announce_t
 {
     vlc_tick_t i_last;
@@ -185,23 +266,27 @@ static sap_announce_t *CreateAnnounce(services_discovery_t *p_sd,
 
     /* Handle category */
     psz_value = vlc_sdp_attr_value(p_sdp, "cat");
+    char *str = NULL;
     if (psz_value != NULL)
     {
         /* a=cat provides a dot-separated hierarchy.
          * For the time being only replace dots with pipe. TODO: FIXME */
-        char *str = strdup(psz_value);
+        str = strdup(psz_value);
         if (likely(str != NULL))
+        {
             for (char *p = strchr(str, '.'); p != NULL; p = strchr(p, '.'))
                 *(p++) = '|';
-        services_discovery_AddItemCat(p_sd, p_input, str ? str : psz_value);
-        free(str);
+            psz_value = str;
+        }
     }
     else
     {
         /* backward compatibility with VLC 0.7.3-2.0.0 senders */
         psz_value = vlc_sdp_attr_value(p_sdp, "x-plgroup");
-        services_discovery_AddItemCat(p_sd, p_input, psz_value);
     }
+    input_item_t *cat = AddCategory(p_sd, psz_value);
+    free(str);
+    services_discovery_AddSubItem(p_sd, cat, p_input);
 
     vlc_sdp_free(p_sdp);
     return p_sap;
@@ -211,21 +296,6 @@ error:
     return NULL;
 }
 
-typedef struct
-{
-    vlc_thread_t thread;
-
-    /* Socket descriptors */
-    int i_fd;
-    int *pi_fd;
-
-    /* Table of announces */
-    int i_announces;
-    struct sap_announce_t **pp_announces;
-
-    vlc_tick_t i_timeout;
-} services_discovery_sys_t;
-
 static int RemoveAnnounce( services_discovery_t *p_sd,
                            sap_announce_t *p_announce )
 {
@@ -580,6 +650,7 @@ static int Open( vlc_object_t *p_this )
 
     p_sys->i_announces = 0;
     p_sys->pp_announces = NULL;
+    p_sys->root_cat = NULL;
     /* TODO: create sockets here, and fix racy sockets table */
     if (vlc_clone (&p_sys->thread, Run, p_sd))
     {
@@ -613,6 +684,7 @@ static void Close( vlc_object_t *p_this )
         RemoveAnnounce( p_sd, p_sys->pp_announces[i] );
     }
     FREENULL( p_sys->pp_announces );
+    tdestroy(p_sys->root_cat, DestroyCategory);
 
     free( p_sys );
 }


=====================================
src/media_source/media_source.c
=====================================
@@ -58,12 +58,8 @@ struct vlc_media_source_provider_t
 /* A new item has been added to a certain services discovery */
 static void
 services_discovery_item_added(services_discovery_t *sd,
-                              input_item_t *parent, input_item_t *media,
-                              const char *cat)
+                              input_item_t *parent, input_item_t *media)
 {
-    assert(!parent || !cat);
-    VLC_UNUSED(cat);
-
     vlc_media_source_t *ms = sd->owner.sys;
     vlc_media_tree_t *tree = ms->tree;
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/eb933a62ec3b3396deccf3e6b6c5ac1f600ec906...fd1444e89b52e41d6e0189e607bd0b0cc1656407

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/eb933a62ec3b3396deccf3e6b6c5ac1f600ec906...fd1444e89b52e41d6e0189e607bd0b0cc1656407
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list