blob: 84c951940be395b8075462b3cfb67cea7c184f8c [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001From d1c02971867bea10afcafc82c965414012c4d6bd Mon Sep 17 00:00:00 2001
Patrick Williamsf1e5d692016-03-30 15:21:19 -05002From: Tanu Kaskinen <tanuk@iki.fi>
3Date: Fri, 23 Oct 2015 12:23:13 +0300
4Subject: [PATCH 1/4] card: add pa_card_profile.ports
5
6Having ports accessible from pa_card_profile allows checking whether all ports
7of a profile are unavailable, and therefore helps with managing the profile
8availability (implemented in a later patch).
9
10http://bugzilla.yoctoproject.org/show_bug.cgi?id=8448
11
Patrick Williamsf1e5d692016-03-30 15:21:19 -050012Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050013
14Rebased on 8.0.
15
16Upstream-Status: Denied [The patch set needs some work to be accepted.
17The review thread:
18http://thread.gmane.org/gmane.comp.audio.pulseaudio.general/24301]
19
20Signed-off-by: Tanu Kaskinen <tanuk@iki.fi>
Patrick Williamsf1e5d692016-03-30 15:21:19 -050021---
22 src/modules/alsa/alsa-mixer.c | 4 +++-
23 src/modules/alsa/alsa-ucm.c | 1 +
24 src/modules/bluetooth/module-bluez4-device.c | 6 ++++++
25 src/modules/bluetooth/module-bluez5-device.c | 6 ++++++
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050026 src/pulsecore/card.c | 15 +++++++++++++++
27 src/pulsecore/card.h | 4 ++++
Patrick Williamsf1e5d692016-03-30 15:21:19 -050028 src/pulsecore/device-port.c | 7 ++++++-
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050029 7 files changed, 41 insertions(+), 2 deletions(-)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050030
31diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050032index 1fe2a02..5b76b06 100644
Patrick Williamsf1e5d692016-03-30 15:21:19 -050033--- a/src/modules/alsa/alsa-mixer.c
34+++ b/src/modules/alsa/alsa-mixer.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050035@@ -4783,8 +4783,10 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
Patrick Williamsf1e5d692016-03-30 15:21:19 -050036 path->port = p;
37 }
38
39- if (cp)
40+ if (cp) {
41 pa_hashmap_put(p->profiles, cp->name, cp);
42+ pa_card_profile_add_port(cp, p);
43+ }
44
45 if (extra) {
46 pa_hashmap_put(extra, p->name, p);
47diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050048index 42f3242..68fcc26 100644
Patrick Williamsf1e5d692016-03-30 15:21:19 -050049--- a/src/modules/alsa/alsa-ucm.c
50+++ b/src/modules/alsa/alsa-ucm.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050051@@ -791,6 +791,7 @@ static void ucm_add_port_combination(
Patrick Williamsf1e5d692016-03-30 15:21:19 -050052 if (cp) {
53 pa_log_debug("Adding profile %s to port %s.", cp->name, port->name);
54 pa_hashmap_put(port->profiles, cp->name, cp);
55+ pa_card_profile_add_port(cp, port);
56 }
57
58 if (hash) {
59diff --git a/src/modules/bluetooth/module-bluez4-device.c b/src/modules/bluetooth/module-bluez4-device.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050060index 9a921a5..adecb32 100644
Patrick Williamsf1e5d692016-03-30 15:21:19 -050061--- a/src/modules/bluetooth/module-bluez4-device.c
62+++ b/src/modules/bluetooth/module-bluez4-device.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063@@ -2180,6 +2180,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
Patrick Williamsf1e5d692016-03-30 15:21:19 -050064 p->max_sink_channels = 2;
65 p->max_source_channels = 0;
66 pa_hashmap_put(output_port->profiles, p->name, p);
67+ pa_card_profile_add_port(p, output_port);
68
69 d = PA_CARD_PROFILE_DATA(p);
70 *d = PA_BLUEZ4_PROFILE_A2DP;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071@@ -2191,6 +2192,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
Patrick Williamsf1e5d692016-03-30 15:21:19 -050072 p->max_sink_channels = 0;
73 p->max_source_channels = 2;
74 pa_hashmap_put(input_port->profiles, p->name, p);
75+ pa_card_profile_add_port(p, input_port);
76
77 d = PA_CARD_PROFILE_DATA(p);
78 *d = PA_BLUEZ4_PROFILE_A2DP_SOURCE;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050079@@ -2203,6 +2205,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
Patrick Williamsf1e5d692016-03-30 15:21:19 -050080 p->max_source_channels = 1;
81 pa_hashmap_put(input_port->profiles, p->name, p);
82 pa_hashmap_put(output_port->profiles, p->name, p);
83+ pa_card_profile_add_port(p, input_port);
84+ pa_card_profile_add_port(p, output_port);
85
86 d = PA_CARD_PROFILE_DATA(p);
87 *d = PA_BLUEZ4_PROFILE_HSP;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050088@@ -2215,6 +2219,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
Patrick Williamsf1e5d692016-03-30 15:21:19 -050089 p->max_source_channels = 1;
90 pa_hashmap_put(input_port->profiles, p->name, p);
91 pa_hashmap_put(output_port->profiles, p->name, p);
92+ pa_card_profile_add_port(p, input_port);
93+ pa_card_profile_add_port(p, output_port);
94
95 d = PA_CARD_PROFILE_DATA(p);
96 *d = PA_BLUEZ4_PROFILE_HFGW;
97diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050098index 84e6d55..b015c67 100644
Patrick Williamsf1e5d692016-03-30 15:21:19 -050099--- a/src/modules/bluetooth/module-bluez5-device.c
100+++ b/src/modules/bluetooth/module-bluez5-device.c
101@@ -1790,6 +1790,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
102 cp->max_sink_channels = 2;
103 cp->max_source_channels = 0;
104 pa_hashmap_put(output_port->profiles, cp->name, cp);
105+ pa_card_profile_add_port(cp, output_port);
106
107 p = PA_CARD_PROFILE_DATA(cp);
108 *p = PA_BLUETOOTH_PROFILE_A2DP_SINK;
109@@ -1801,6 +1802,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
110 cp->max_sink_channels = 0;
111 cp->max_source_channels = 2;
112 pa_hashmap_put(input_port->profiles, cp->name, cp);
113+ pa_card_profile_add_port(cp, input_port);
114
115 p = PA_CARD_PROFILE_DATA(cp);
116 *p = PA_BLUETOOTH_PROFILE_A2DP_SOURCE;
117@@ -1813,6 +1815,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
118 cp->max_source_channels = 1;
119 pa_hashmap_put(input_port->profiles, cp->name, cp);
120 pa_hashmap_put(output_port->profiles, cp->name, cp);
121+ pa_card_profile_add_port(cp, input_port);
122+ pa_card_profile_add_port(cp, output_port);
123
124 p = PA_CARD_PROFILE_DATA(cp);
125 *p = PA_BLUETOOTH_PROFILE_HEADSET_HEAD_UNIT;
126@@ -1825,6 +1829,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
127 cp->max_source_channels = 1;
128 pa_hashmap_put(input_port->profiles, cp->name, cp);
129 pa_hashmap_put(output_port->profiles, cp->name, cp);
130+ pa_card_profile_add_port(cp, input_port);
131+ pa_card_profile_add_port(cp, output_port);
132
133 p = PA_CARD_PROFILE_DATA(cp);
134 *p = PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY;
135diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500136index b6cbbf7..f92ac87 100644
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500137--- a/src/pulsecore/card.c
138+++ b/src/pulsecore/card.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500139@@ -45,6 +45,7 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
140 c->name = pa_xstrdup(name);
141 c->description = pa_xstrdup(description);
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500142 c->available = PA_AVAILABLE_UNKNOWN;
143+ c->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
144
145 return c;
146 }
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500147@@ -52,6 +53,14 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500148 void pa_card_profile_free(pa_card_profile *c) {
149 pa_assert(c);
150
151+ if (c->ports) {
152+ pa_device_port *port;
153+ void *state;
154+ PA_HASHMAP_FOREACH(port, c->ports, state)
155+ pa_hashmap_remove (port->profiles, c->name);
156+ pa_hashmap_free(c->ports);
157+ }
158+
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500159 pa_xfree(c->input_name);
160 pa_xfree(c->output_name);
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500161 pa_xfree(c->name);
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500162@@ -59,6 +68,12 @@ void pa_card_profile_free(pa_card_profile *c) {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500163 pa_xfree(c);
164 }
165
166+void pa_card_profile_add_port(pa_card_profile *profile, pa_device_port *port) {
167+ pa_assert(profile);
168+
169+ pa_hashmap_put(profile->ports, port->name, port);
170+}
171+
172 void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available) {
173 pa_core *core;
174
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500175diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500176index 30bfc0e..fff9057 100644
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500177--- a/src/pulsecore/card.h
178+++ b/src/pulsecore/card.h
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500179@@ -50,6 +50,8 @@ struct pa_card_profile {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500180 unsigned priority;
181 pa_available_t available; /* PA_AVAILABLE_UNKNOWN, PA_AVAILABLE_NO or PA_AVAILABLE_YES */
182
183+ pa_hashmap *ports; /* port name -> pa_device_port */
184+
185 /* We probably want to have different properties later on here */
186 unsigned n_sinks;
187 unsigned n_sources;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500188@@ -107,6 +109,8 @@ typedef struct pa_card_new_data {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500189 pa_card_profile *pa_card_profile_new(const char *name, const char *description, size_t extra);
190 void pa_card_profile_free(pa_card_profile *c);
191
192+void pa_card_profile_add_port(pa_card_profile *profile, pa_device_port *port);
193+
194 /* The profile's available status has changed */
195 void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available);
196
197diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500198index 5807d3e..d12dfbc 100644
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500199--- a/src/pulsecore/device-port.c
200+++ b/src/pulsecore/device-port.c
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500201@@ -107,8 +107,13 @@ static void device_port_free(pa_object *o) {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500202 if (p->proplist)
203 pa_proplist_free(p->proplist);
204
205- if (p->profiles)
206+ if (p->profiles) {
207+ pa_card_profile *profile;
208+ void *state;
209+ PA_HASHMAP_FOREACH(profile, p->profiles, state)
210+ pa_hashmap_remove (profile->ports, p->name);
211 pa_hashmap_free(p->profiles);
212+ }
213
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500214 pa_xfree(p->preferred_profile);
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500215 pa_xfree(p->name);
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500216--
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05002172.7.0
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500218