[pulseaudio-commits] Branch 'next' - 2 commits - src/modules src/pulsecore

Tanu Kaskinen tanuk at kemper.freedesktop.org
Tue Jun 7 12:16:14 UTC 2016


 src/modules/alsa/alsa-mixer.c |    1 +
 src/modules/alsa/alsa-ucm.c   |   37 +++++++++++++++----------------------
 src/modules/alsa/alsa-ucm.h   |    1 -
 src/pulsecore/device-port.c   |    3 +++
 src/pulsecore/device-port.h   |    3 +++
 5 files changed, 22 insertions(+), 23 deletions(-)

New commits:
commit d2744955afae421c54af9ecfdeb3904018bdfa5a
Author: Arun Raghavan <git at arunraghavan.net>
Date:   Tue May 3 18:22:09 2016 +0530

    alsa: Use pa_device_port->impl_free() for freeing port data
    
    This allows us to clean up ucm port data associated with a port during
    port clean up, instead of having to track this separately using a
    dynarray.

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 8079147..3dbf6b1 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -4754,6 +4754,7 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
         pa_proplist_update(p->proplist, PA_UPDATE_REPLACE, path->proplist);
 
         data = PA_DEVICE_PORT_DATA(p);
+        /* Ownership of the path and setting is not transferred to the port data, so we don't deal with freeing them */
         data->path = path;
         data->setting = setting;
         path->port = p;
diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
index 42f3242..b42c040 100644
--- a/src/modules/alsa/alsa-ucm.c
+++ b/src/modules/alsa/alsa-ucm.c
@@ -90,9 +90,9 @@ struct ucm_port {
     pa_dynarray *devices; /* pa_alsa_ucm_device */
 };
 
-static struct ucm_port *ucm_port_new(pa_alsa_ucm_config *ucm, pa_device_port *core_port, pa_alsa_ucm_device **devices,
-                                     unsigned n_devices);
-static void ucm_port_free(struct ucm_port *port);
+static void ucm_port_init(struct ucm_port *port, pa_alsa_ucm_config *ucm, pa_device_port *core_port,
+                          pa_alsa_ucm_device **devices, unsigned n_devices);
+static void ucm_port_free(pa_device_port *port);
 static void ucm_port_update_available(struct ucm_port *port);
 
 static struct ucm_items item[] = {
@@ -576,8 +576,6 @@ int pa_alsa_ucm_query_profiles(pa_alsa_ucm_config *ucm, int card_index) {
     const char **verb_list;
     int num_verbs, i, err = 0;
 
-    ucm->ports = pa_dynarray_new((pa_free_cb_t) ucm_port_free);
-
     /* is UCM available for this card ? */
     err = snd_card_get_name(card_index, &card_name);
     if (err < 0) {
@@ -769,12 +767,12 @@ static void ucm_add_port_combination(
         pa_device_port_new_data_set_description(&port_data, desc);
         pa_device_port_new_data_set_direction(&port_data, is_sink ? PA_DIRECTION_OUTPUT : PA_DIRECTION_INPUT);
 
-        port = pa_device_port_new(core, &port_data, sizeof(struct ucm_port *));
+        port = pa_device_port_new(core, &port_data, sizeof(struct ucm_port));
+        port->impl_free = ucm_port_free;
         pa_device_port_new_data_done(&port_data);
 
-        ucm_port = ucm_port_new(context->ucm, port, pdevices, num);
-        pa_dynarray_append(context->ucm->ports, ucm_port);
-        *((struct ucm_port **) PA_DEVICE_PORT_DATA(port)) = ucm_port;
+        ucm_port = PA_DEVICE_PORT_DATA(port);
+        ucm_port_init(ucm_port, context->ucm, port, pdevices, num);
 
         pa_hashmap_put(ports, port->name, port);
         pa_log_debug("Add port %s: %s", port->name, port->description);
@@ -1681,9 +1679,6 @@ void pa_alsa_ucm_free(pa_alsa_ucm_config *ucm) {
     pa_alsa_ucm_verb *vi, *vn;
     pa_alsa_jack *ji, *jn;
 
-    if (ucm->ports)
-        pa_dynarray_free(ucm->ports);
-
     PA_LLIST_FOREACH_SAFE(vi, vn, ucm->verbs) {
         PA_LLIST_REMOVE(pa_alsa_ucm_verb, ucm->verbs, vi);
         free_verb(vi);
@@ -1838,16 +1833,14 @@ void pa_alsa_ucm_device_update_available(pa_alsa_ucm_device *device) {
     device_set_available(device, available);
 }
 
-static struct ucm_port *ucm_port_new(pa_alsa_ucm_config *ucm, pa_device_port *core_port, pa_alsa_ucm_device **devices,
-                                     unsigned n_devices) {
-    struct ucm_port *port;
+static void ucm_port_init(struct ucm_port *port, pa_alsa_ucm_config *ucm, pa_device_port *core_port,
+                          pa_alsa_ucm_device **devices, unsigned n_devices) {
     unsigned i;
 
     pa_assert(ucm);
     pa_assert(core_port);
     pa_assert(devices);
 
-    port = pa_xnew0(struct ucm_port, 1);
     port->ucm = ucm;
     port->core_port = core_port;
     port->devices = pa_dynarray_new(NULL);
@@ -1858,17 +1851,17 @@ static struct ucm_port *ucm_port_new(pa_alsa_ucm_config *ucm, pa_device_port *co
     }
 
     ucm_port_update_available(port);
-
-    return port;
 }
 
-static void ucm_port_free(struct ucm_port *port) {
+static void ucm_port_free(pa_device_port *port) {
+    struct ucm_port *ucm_port;
+
     pa_assert(port);
 
-    if (port->devices)
-        pa_dynarray_free(port->devices);
+    ucm_port = PA_DEVICE_PORT_DATA(port);
 
-    pa_xfree(port);
+    if (ucm_port->devices)
+        pa_dynarray_free(ucm_port->devices);
 }
 
 static void ucm_port_update_available(struct ucm_port *port) {
diff --git a/src/modules/alsa/alsa-ucm.h b/src/modules/alsa/alsa-ucm.h
index 0930303..53abf3f 100644
--- a/src/modules/alsa/alsa-ucm.h
+++ b/src/modules/alsa/alsa-ucm.h
@@ -196,7 +196,6 @@ struct pa_alsa_ucm_config {
 
     PA_LLIST_HEAD(pa_alsa_ucm_verb, verbs);
     PA_LLIST_HEAD(pa_alsa_jack, jacks);
-    pa_dynarray *ports; /* struct ucm_port */
 };
 
 struct pa_alsa_ucm_mapping_context {

commit f2d01baeda1ba9b56dc341f7049a7d72b5a4ac05
Author: Arun Raghavan <git at arunraghavan.net>
Date:   Tue May 3 18:22:08 2016 +0530

    device-port: Add mechanism to free implementation data
    
    This will be needed if the implementation data stores pointers to
    additional data that needs to be freed as well.

diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index ab3b2e8..7c9ddf3 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -104,6 +104,9 @@ static void device_port_free(pa_object *o) {
     pa_assert(p);
     pa_assert(pa_device_port_refcnt(p) == 0);
 
+    if (p->impl_free)
+        p->impl_free(p);
+
     if (p->proplist)
         pa_proplist_free(p->proplist);
 
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index 85c41fa..fbdce1a 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -52,6 +52,9 @@ struct pa_device_port {
     pa_direction_t direction;
     int64_t latency_offset;
 
+    /* Free the extra implementation specific data. Called before other members are freed. */
+    void (*impl_free)(pa_device_port *port);
+
     /* .. followed by some implementation specific data */
 };
 



More information about the pulseaudio-commits mailing list