[pulseaudio-discuss] [RFC PATCH 1/4] card: New API pa_card_profile_has_available_ports

João Paulo Rechi Vita jprvita at gmail.com
Wed Aug 8 05:00:49 UTC 2018


New function to check if a card has any ports with a certain
availability for a specific direction.

This was built uppon previous work by Mario Sanchez Prada.
---
 src/pulsecore/card.c | 18 ++++++++++++++++++
 src/pulsecore/card.h |  3 +++
 2 files changed, 21 insertions(+)

diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index c785f00a7..a3c732341 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -79,6 +79,24 @@ void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available)
     pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_PROFILE_AVAILABLE_CHANGED], c);
 }
 
+bool pa_card_profile_has_available_ports(pa_card_profile *c, pa_direction_t direction, pa_available_t available) {
+    pa_card *card;
+    pa_device_port *port;
+    void *state;
+
+    pa_assert(c);
+
+    card = c->card;
+    pa_assert(card);
+
+    PA_HASHMAP_FOREACH(port, card->ports, state) {
+        if (pa_hashmap_get(port->profiles, c->name) && port->direction == direction && port->available == available)
+            return true;
+    }
+
+    return false;
+}
+
 pa_card_new_data* pa_card_new_data_init(pa_card_new_data *data) {
     pa_assert(data);
 
diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h
index 09284f6ff..50f106c5e 100644
--- a/src/pulsecore/card.h
+++ b/src/pulsecore/card.h
@@ -119,6 +119,9 @@ void pa_card_profile_free(pa_card_profile *c);
 /* The profile's available status has changed */
 void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available);
 
+/* Check if card has any ports with a certain availability for a specific direction */
+bool pa_card_profile_has_available_ports(pa_card_profile *c, pa_direction_t direction, pa_available_t available);
+
 pa_card_new_data *pa_card_new_data_init(pa_card_new_data *data);
 void pa_card_new_data_set_name(pa_card_new_data *data, const char *name);
 void pa_card_new_data_set_preferred_port(pa_card_new_data *data, pa_direction_t direction, pa_device_port *port);
-- 
2.18.0



More information about the pulseaudio-discuss mailing list