[PATCH v2 03/10] card: Add pa_card_new_data_add_profile()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently the function doesn't do anything fancy, but I'll need the
function for automatically adding the device prototypes in the card
profile to the card.
---
 src/modules/alsa/module-alsa-card.c             | 24 +++++++++++++-----------
 src/modules/bluetooth/module-bluetooth-device.c |  4 ++--
 src/modules/macosx/module-coreaudio-device.c    |  2 +-
 src/pulsecore/card.c                            |  7 +++++++
 src/pulsecore/card.h                            |  1 +
 5 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index e6e426e..7934064 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -137,12 +137,12 @@ struct profile_data {
     pa_alsa_profile *profile;
 };
 
-static void add_profiles(struct userdata *u, pa_hashmap *h, pa_hashmap *ports) {
+static void add_profiles(struct userdata *u, pa_card_new_data *data) {
     pa_alsa_profile *ap;
     void *state;
 
     pa_assert(u);
-    pa_assert(h);
+    pa_assert(data);
 
     PA_HASHMAP_FOREACH(ap, u->profile_set->profiles, state) {
         struct profile_data *d;
@@ -158,9 +158,9 @@ static void add_profiles(struct userdata *u, pa_hashmap *h, pa_hashmap *ports) {
 
             PA_IDXSET_FOREACH(m, ap->output_mappings, idx) {
                 if (u->use_ucm)
-                    pa_alsa_ucm_add_ports_combination(NULL, &m->ucm_context, true, ports, cp, u->core);
+                    pa_alsa_ucm_add_ports_combination(NULL, &m->ucm_context, true, data->ports, cp, u->core);
                 else
-                    pa_alsa_path_set_add_ports(m->output_path_set, cp, ports, NULL, u->core);
+                    pa_alsa_path_set_add_ports(m->output_path_set, cp, data->ports, NULL, u->core);
                 if (m->channel_map.channels > cp->max_sink_channels)
                     cp->max_sink_channels = m->channel_map.channels;
             }
@@ -171,9 +171,9 @@ static void add_profiles(struct userdata *u, pa_hashmap *h, pa_hashmap *ports) {
 
             PA_IDXSET_FOREACH(m, ap->input_mappings, idx) {
                 if (u->use_ucm)
-                    pa_alsa_ucm_add_ports_combination(NULL, &m->ucm_context, false, ports, cp, u->core);
+                    pa_alsa_ucm_add_ports_combination(NULL, &m->ucm_context, false, data->ports, cp, u->core);
                 else
-                    pa_alsa_path_set_add_ports(m->input_path_set, cp, ports, NULL, u->core);
+                    pa_alsa_path_set_add_ports(m->input_path_set, cp, data->ports, NULL, u->core);
                 if (m->channel_map.channels > cp->max_source_channels)
                     cp->max_source_channels = m->channel_map.channels;
             }
@@ -182,20 +182,22 @@ static void add_profiles(struct userdata *u, pa_hashmap *h, pa_hashmap *ports) {
         d = PA_CARD_PROFILE_DATA(cp);
         d->profile = ap;
 
-        pa_hashmap_put(h, cp->name, cp);
+        pa_card_new_data_add_profile(data, cp);
     }
 }
 
-static void add_disabled_profile(pa_hashmap *profiles) {
+static void add_disabled_profile(pa_card_new_data *data) {
     pa_card_profile *p;
     struct profile_data *d;
 
+    pa_assert(data);
+
     p = pa_card_profile_new("off", _("Off"), sizeof(struct profile_data));
 
     d = PA_CARD_PROFILE_DATA(p);
     d->profile = NULL;
 
-    pa_hashmap_put(profiles, p->name, p);
+    pa_card_new_data_add_profile(data, p);
 }
 
 static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
@@ -721,7 +723,7 @@ int pa__init(pa_module *m) {
         if ((description = pa_proplist_gets(data.proplist, PA_PROP_DEVICE_DESCRIPTION)))
             pa_reserve_wrapper_set_application_device_name(reserve, description);
 
-    add_profiles(u, data.profiles, data.ports);
+    add_profiles(u, &data);
 
     if (pa_hashmap_isempty(data.profiles)) {
         pa_log("Failed to find a working profile.");
@@ -729,7 +731,7 @@ int pa__init(pa_module *m) {
         goto fail;
     }
 
-    add_disabled_profile(data.profiles);
+    add_disabled_profile(&data);
 
     if (pa_modargs_get_proplist(ma, "card_properties", data.proplist, PA_UPDATE_REPLACE) < 0) {
         pa_log("Invalid properties");
diff --git a/src/modules/bluetooth/module-bluetooth-device.c b/src/modules/bluetooth/module-bluetooth-device.c
index e51da4d..77826d0 100644
--- a/src/modules/bluetooth/module-bluetooth-device.c
+++ b/src/modules/bluetooth/module-bluetooth-device.c
@@ -2309,7 +2309,7 @@ static int add_card(struct userdata *u) {
             continue;
         }
 
-        pa_hashmap_put(data.profiles, p->name, p);
+        pa_card_new_data_add_profile(&data, p);
     }
 
     pa_assert(!pa_hashmap_isempty(data.profiles));
@@ -2318,7 +2318,7 @@ static int add_card(struct userdata *u) {
     p->available = PA_AVAILABLE_YES;
     d = PA_CARD_PROFILE_DATA(p);
     *d = PROFILE_OFF;
-    pa_hashmap_put(data.profiles, p->name, p);
+    pa_card_new_data_add_profile(&data, p);
 
     if ((default_profile = pa_modargs_get_value(u->modargs, "profile", NULL))) {
         if (pa_hashmap_get(data.profiles, default_profile))
diff --git a/src/modules/macosx/module-coreaudio-device.c b/src/modules/macosx/module-coreaudio-device.c
index 7b3a002..da730eb 100644
--- a/src/modules/macosx/module-coreaudio-device.c
+++ b/src/modules/macosx/module-coreaudio-device.c
@@ -754,7 +754,7 @@ int pa__init(pa_module *m) {
 
     /* add on profile */
     p = pa_card_profile_new("on", _("On"), 0);
-    pa_hashmap_put(card_new_data.profiles, p->name, p);
+    pa_card_new_data_add_profile(&card_new_data, p);
 
     /* create the card object */
     u->card = pa_card_new(m->core, &card_new_data);
diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
index fb28ff9..92804d0 100644
--- a/src/pulsecore/card.c
+++ b/src/pulsecore/card.c
@@ -102,6 +102,13 @@ void pa_card_new_data_set_name(pa_card_new_data *data, const char *name) {
     data->name = pa_xstrdup(name);
 }
 
+void pa_card_new_data_add_profile(pa_card_new_data *data, pa_card_profile *profile) {
+    pa_assert(data);
+    pa_assert(profile);
+
+    pa_assert_se(pa_hashmap_put(data->profiles, profile->name, profile) >= 0);
+}
+
 void pa_card_new_data_set_profile(pa_card_new_data *data, const char *profile) {
     pa_assert(data);
 
diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h
index 950fe68..8fa0623 100644
--- a/src/pulsecore/card.h
+++ b/src/pulsecore/card.h
@@ -124,6 +124,7 @@ void pa_card_profile_set_available(pa_card_profile *c, 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_add_profile(pa_card_new_data *data, pa_card_profile *profile);
 void pa_card_new_data_set_profile(pa_card_new_data *data, const char *profile);
 void pa_card_new_data_set_recreate_devices_on_profile_switch(pa_card_new_data *data, bool recreate);
 void pa_card_new_data_done(pa_card_new_data *data);
-- 
1.8.3.1



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux