[pulseaudio-discuss] [PATCH 1/5] device-port: Add a card pointer to the ports.
poljar (Damir Jelić)
poljarinho at gmail.com
Thu Jan 17 11:55:14 PST 2013
This way we can directly access the card that owns the port instead of
iterating over all cards.
---
src/pulsecore/card.c | 10 +++++++++-
src/pulsecore/device-port.c | 1 +
src/pulsecore/device-port.h | 2 ++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index 1cde297..3077193 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -102,8 +102,10 @@ void pa_card_add_ports(pa_card *c, pa_hashmap *ports) {
pa_assert(ports);
/* take ownership of the ports */
- PA_HASHMAP_FOREACH(p, ports, state)
+ PA_HASHMAP_FOREACH(p, ports, state) {
+ p->card = c;
pa_assert_se(pa_hashmap_put(c->ports, p->name, p) >= 0);
+ }
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
@@ -145,6 +147,7 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
const char *name;
void *state;
pa_card_profile *profile;
+ pa_device_port *port;
pa_core_assert_ref(core);
pa_assert(data);
@@ -188,6 +191,11 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
profile->card = c;
}
+ if (c->ports) {
+ PA_HASHMAP_FOREACH(port, c->ports, state)
+ port->card = c;
+ }
+
c->active_profile = NULL;
c->save_profile = FALSE;
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 9ea54e3..cb6fa98 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -92,6 +92,7 @@ pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *des
p->name = pa_xstrdup(name);
p->description = pa_xstrdup(description);
p->core = c;
+ p->card = NULL;
p->priority = 0;
p->available = PA_PORT_AVAILABLE_UNKNOWN;
p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index a5c6420..cea00e6 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -36,10 +36,12 @@ typedef struct pa_device_port pa_device_port;
#include <pulsecore/object.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/core.h>
+#include <pulsecore/card.h>
struct pa_device_port {
pa_object parent; /* Needed for reference counting */
pa_core *core;
+ pa_card *card;
char *name;
char *description;
--
1.8.1.1
More information about the pulseaudio-discuss
mailing list