[pulseaudio-commits] src/pulsecore

Tanu Kaskinen tanuk at kemper.freedesktop.org
Thu Oct 25 06:48:21 PDT 2012


 src/pulsecore/card.c |   23 ++++++++++++++++-------
 src/pulsecore/card.h |    1 +
 2 files changed, 17 insertions(+), 7 deletions(-)

New commits:
commit 43454bc48c5afee29a2b0c19e6fb80f9bd98ad58
Author: Tanu Kaskinen <tanu.kaskinen at digia.com>
Date:   Fri Jun 29 18:04:55 2012 +0300

    card: Store a pa_card pointer in pa_card_profile.

diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index b1daa63..1cde297 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -44,6 +44,7 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
     pa_assert(name);
 
     c = pa_xmalloc(PA_ALIGN(sizeof(pa_card_profile)) + extra);
+    c->card = NULL;
     c->name = pa_xstrdup(name);
     c->description = pa_xstrdup(description);
 
@@ -56,6 +57,7 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
 
 void pa_card_profile_free(pa_card_profile *c) {
     pa_assert(c);
+    pa_assert(!c->card); /* Card profiles shouldn't be freed before removing them from the card. */
 
     pa_xfree(c->name);
     pa_xfree(c->description);
@@ -85,6 +87,7 @@ void pa_card_add_profile(pa_card *c, pa_card_profile *profile) {
 
     /* take ownership of the profile */
     pa_assert_se(pa_hashmap_put(c->profiles, profile->name, profile) >= 0);
+    profile->card = c;
 
     pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
 
@@ -140,6 +143,8 @@ void pa_card_new_data_done(pa_card_new_data *data) {
 pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
     pa_card *c;
     const char *name;
+    void *state;
+    pa_card_profile *profile;
 
     pa_core_assert_ref(core);
     pa_assert(data);
@@ -178,6 +183,11 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
     c->ports = data->ports;
     data->ports = NULL;
 
+    if (c->profiles) {
+        PA_HASHMAP_FOREACH(profile, c->profiles, state)
+            profile->card = c;
+    }
+
     c->active_profile = NULL;
     c->save_profile = FALSE;
 
@@ -186,12 +196,9 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
             c->save_profile = data->save_profile;
 
     if (!c->active_profile) {
-        void *state;
-        pa_card_profile *p;
-
-        PA_HASHMAP_FOREACH(p, c->profiles, state)
-            if (!c->active_profile || p->priority > c->active_profile->priority)
-                c->active_profile = p;
+        PA_HASHMAP_FOREACH(profile, c->profiles, state)
+            if (!c->active_profile || profile->priority > c->active_profile->priority)
+                c->active_profile = profile;
     }
 
     c->userdata = NULL;
@@ -238,8 +245,10 @@ void pa_card_free(pa_card *c) {
     if (c->profiles) {
         pa_card_profile *p;
 
-        while ((p = pa_hashmap_steal_first(c->profiles)))
+        while ((p = pa_hashmap_steal_first(c->profiles))) {
+            p->card = NULL;
             pa_card_profile_free(p);
+        }
 
         pa_hashmap_free(c->profiles, NULL, NULL);
     }
diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h
index 5b5be81..d72a293 100644
--- a/src/pulsecore/card.h
+++ b/src/pulsecore/card.h
@@ -30,6 +30,7 @@ typedef struct pa_card pa_card;
 #include <pulsecore/idxset.h>
 
 typedef struct pa_card_profile {
+    pa_card *card;
     char *name;
     char *description;
 



More information about the pulseaudio-commits mailing list