blob: 97b2e4064a1938228c4cdcc807b09c66015343ba [file] [log] [blame]
Patrick Williamsf1e5d692016-03-30 15:21:19 -05001From 6f814b40a01d03f93b36184c19339033949de472 Mon Sep 17 00:00:00 2001
2From: 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
12Upstream-Status: Submitted [http://lists.freedesktop.org/archives/pulseaudio-discuss/2015-October/024614.html]
13Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
14---
15 src/modules/alsa/alsa-mixer.c | 4 +++-
16 src/modules/alsa/alsa-ucm.c | 1 +
17 src/modules/bluetooth/module-bluez4-device.c | 6 ++++++
18 src/modules/bluetooth/module-bluez5-device.c | 6 ++++++
19 src/pulsecore/card.c | 16 ++++++++++++++++
20 src/pulsecore/card.h | 18 ++++++++++++------
21 src/pulsecore/device-port.c | 7 ++++++-
22 7 files changed, 50 insertions(+), 8 deletions(-)
23
24diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
25index 47cbd14..c5b82b0 100644
26--- a/src/modules/alsa/alsa-mixer.c
27+++ b/src/modules/alsa/alsa-mixer.c
28@@ -4654,8 +4654,10 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */
29 path->port = p;
30 }
31
32- if (cp)
33+ if (cp) {
34 pa_hashmap_put(p->profiles, cp->name, cp);
35+ pa_card_profile_add_port(cp, p);
36+ }
37
38 if (extra) {
39 pa_hashmap_put(extra, p->name, p);
40diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c
41index aa2d601..c8199d6 100644
42--- a/src/modules/alsa/alsa-ucm.c
43+++ b/src/modules/alsa/alsa-ucm.c
44@@ -761,6 +761,7 @@ static void ucm_add_port_combination(
45 if (cp) {
46 pa_log_debug("Adding profile %s to port %s.", cp->name, port->name);
47 pa_hashmap_put(port->profiles, cp->name, cp);
48+ pa_card_profile_add_port(cp, port);
49 }
50
51 if (hash) {
52diff --git a/src/modules/bluetooth/module-bluez4-device.c b/src/modules/bluetooth/module-bluez4-device.c
53index db69d34..b40c6a0 100644
54--- a/src/modules/bluetooth/module-bluez4-device.c
55+++ b/src/modules/bluetooth/module-bluez4-device.c
56@@ -2183,6 +2183,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
57 p->max_sink_channels = 2;
58 p->max_source_channels = 0;
59 pa_hashmap_put(output_port->profiles, p->name, p);
60+ pa_card_profile_add_port(p, output_port);
61
62 d = PA_CARD_PROFILE_DATA(p);
63 *d = PA_BLUEZ4_PROFILE_A2DP;
64@@ -2194,6 +2195,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
65 p->max_sink_channels = 0;
66 p->max_source_channels = 2;
67 pa_hashmap_put(input_port->profiles, p->name, p);
68+ pa_card_profile_add_port(p, input_port);
69
70 d = PA_CARD_PROFILE_DATA(p);
71 *d = PA_BLUEZ4_PROFILE_A2DP_SOURCE;
72@@ -2206,6 +2208,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
73 p->max_source_channels = 1;
74 pa_hashmap_put(input_port->profiles, p->name, p);
75 pa_hashmap_put(output_port->profiles, p->name, p);
76+ pa_card_profile_add_port(p, input_port);
77+ pa_card_profile_add_port(p, output_port);
78
79 d = PA_CARD_PROFILE_DATA(p);
80 *d = PA_BLUEZ4_PROFILE_HSP;
81@@ -2218,6 +2222,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
82 p->max_source_channels = 1;
83 pa_hashmap_put(input_port->profiles, p->name, p);
84 pa_hashmap_put(output_port->profiles, p->name, p);
85+ pa_card_profile_add_port(p, input_port);
86+ pa_card_profile_add_port(p, output_port);
87
88 d = PA_CARD_PROFILE_DATA(p);
89 *d = PA_BLUEZ4_PROFILE_HFGW;
90diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c
91index 7238e6f..3321785 100644
92--- a/src/modules/bluetooth/module-bluez5-device.c
93+++ b/src/modules/bluetooth/module-bluez5-device.c
94@@ -1790,6 +1790,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
95 cp->max_sink_channels = 2;
96 cp->max_source_channels = 0;
97 pa_hashmap_put(output_port->profiles, cp->name, cp);
98+ pa_card_profile_add_port(cp, output_port);
99
100 p = PA_CARD_PROFILE_DATA(cp);
101 *p = PA_BLUETOOTH_PROFILE_A2DP_SINK;
102@@ -1801,6 +1802,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
103 cp->max_sink_channels = 0;
104 cp->max_source_channels = 2;
105 pa_hashmap_put(input_port->profiles, cp->name, cp);
106+ pa_card_profile_add_port(cp, input_port);
107
108 p = PA_CARD_PROFILE_DATA(cp);
109 *p = PA_BLUETOOTH_PROFILE_A2DP_SOURCE;
110@@ -1813,6 +1815,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
111 cp->max_source_channels = 1;
112 pa_hashmap_put(input_port->profiles, cp->name, cp);
113 pa_hashmap_put(output_port->profiles, cp->name, cp);
114+ pa_card_profile_add_port(cp, input_port);
115+ pa_card_profile_add_port(cp, output_port);
116
117 p = PA_CARD_PROFILE_DATA(cp);
118 *p = PA_BLUETOOTH_PROFILE_HEADSET_HEAD_UNIT;
119@@ -1825,6 +1829,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid
120 cp->max_source_channels = 1;
121 pa_hashmap_put(input_port->profiles, cp->name, cp);
122 pa_hashmap_put(output_port->profiles, cp->name, cp);
123+ pa_card_profile_add_port(cp, input_port);
124+ pa_card_profile_add_port(cp, output_port);
125
126 p = PA_CARD_PROFILE_DATA(cp);
127 *p = PA_BLUETOOTH_PROFILE_HEADSET_AUDIO_GATEWAY;
128diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
129index 6f9391e..cc4c784 100644
130--- a/src/pulsecore/card.c
131+++ b/src/pulsecore/card.c
132@@ -50,6 +50,7 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
133 c->n_sinks = c->n_sources = 0;
134 c->max_sink_channels = c->max_source_channels = 0;
135 c->available = PA_AVAILABLE_UNKNOWN;
136+ c->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
137
138 return c;
139 }
140@@ -57,11 +58,25 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description,
141 void pa_card_profile_free(pa_card_profile *c) {
142 pa_assert(c);
143
144+ if (c->ports) {
145+ pa_device_port *port;
146+ void *state;
147+ PA_HASHMAP_FOREACH(port, c->ports, state)
148+ pa_hashmap_remove (port->profiles, c->name);
149+ pa_hashmap_free(c->ports);
150+ }
151+
152 pa_xfree(c->name);
153 pa_xfree(c->description);
154 pa_xfree(c);
155 }
156
157+void pa_card_profile_add_port(pa_card_profile *profile, pa_device_port *port) {
158+ pa_assert(profile);
159+
160+ pa_hashmap_put(profile->ports, port->name, port);
161+}
162+
163 void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available) {
164 pa_core *core;
165
166@@ -198,6 +213,7 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
167
168 c->userdata = NULL;
169 c->set_profile = NULL;
170+ c->active_profile = NULL;
171
172 pa_device_init_description(c->proplist, c);
173 pa_device_init_icon(c->proplist, true);
174diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h
175index 3e2c004..1c33958 100644
176--- a/src/pulsecore/card.h
177+++ b/src/pulsecore/card.h
178@@ -22,19 +22,21 @@
179
180 typedef struct pa_card pa_card;
181
182-#include <pulse/proplist.h>
183-#include <pulsecore/core.h>
184-#include <pulsecore/module.h>
185-#include <pulsecore/idxset.h>
186-
187 /* This enum replaces pa_port_available_t (defined in pulse/def.h) for
188- * internal use, so make sure both enum types stay in sync. */
189+ * internal use, so make sure both enum types stay in sync. This is defined
190+ * before the #includes, because device-port.h depends on this enum. */
191 typedef enum pa_available {
192 PA_AVAILABLE_UNKNOWN = 0,
193 PA_AVAILABLE_NO = 1,
194 PA_AVAILABLE_YES = 2,
195 } pa_available_t;
196
197+#include <pulse/proplist.h>
198+#include <pulsecore/core.h>
199+#include <pulsecore/device-port.h>
200+#include <pulsecore/module.h>
201+#include <pulsecore/idxset.h>
202+
203 typedef struct pa_card_profile {
204 pa_card *card;
205 char *name;
206@@ -43,6 +45,8 @@ typedef struct pa_card_profile {
207 unsigned priority;
208 pa_available_t available; /* PA_AVAILABLE_UNKNOWN, PA_AVAILABLE_NO or PA_AVAILABLE_YES */
209
210+ pa_hashmap *ports; /* port name -> pa_device_port */
211+
212 /* We probably want to have different properties later on here */
213 unsigned n_sinks;
214 unsigned n_sources;
215@@ -100,6 +104,8 @@ typedef struct pa_card_new_data {
216 pa_card_profile *pa_card_profile_new(const char *name, const char *description, size_t extra);
217 void pa_card_profile_free(pa_card_profile *c);
218
219+void pa_card_profile_add_port(pa_card_profile *profile, pa_device_port *port);
220+
221 /* The profile's available status has changed */
222 void pa_card_profile_set_available(pa_card_profile *c, pa_available_t available);
223
224diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
225index cfe2a80..f16ecef 100644
226--- a/src/pulsecore/device-port.c
227+++ b/src/pulsecore/device-port.c
228@@ -95,8 +95,13 @@ static void device_port_free(pa_object *o) {
229 if (p->proplist)
230 pa_proplist_free(p->proplist);
231
232- if (p->profiles)
233+ if (p->profiles) {
234+ pa_card_profile *profile;
235+ void *state;
236+ PA_HASHMAP_FOREACH(profile, p->profiles, state)
237+ pa_hashmap_remove (profile->ports, p->name);
238 pa_hashmap_free(p->profiles);
239+ }
240
241 pa_xfree(p->name);
242 pa_xfree(p->description);
243--
2442.1.4
245