Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | From d1c02971867bea10afcafc82c965414012c4d6bd Mon Sep 17 00:00:00 2001 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 2 | From: Tanu Kaskinen <tanuk@iki.fi> |
| 3 | Date: Fri, 23 Oct 2015 12:23:13 +0300 |
| 4 | Subject: [PATCH 1/4] card: add pa_card_profile.ports |
| 5 | |
| 6 | Having ports accessible from pa_card_profile allows checking whether all ports |
| 7 | of a profile are unavailable, and therefore helps with managing the profile |
| 8 | availability (implemented in a later patch). |
| 9 | |
| 10 | http://bugzilla.yoctoproject.org/show_bug.cgi?id=8448 |
| 11 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 12 | Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 13 | |
| 14 | Rebased on 8.0. |
| 15 | |
| 16 | Upstream-Status: Denied [The patch set needs some work to be accepted. |
| 17 | The review thread: |
| 18 | http://thread.gmane.org/gmane.comp.audio.pulseaudio.general/24301] |
| 19 | |
| 20 | Signed-off-by: Tanu Kaskinen <tanuk@iki.fi> |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 21 | --- |
| 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 26 | src/pulsecore/card.c | 15 +++++++++++++++ |
| 27 | src/pulsecore/card.h | 4 ++++ |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 28 | src/pulsecore/device-port.c | 7 ++++++- |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 29 | 7 files changed, 41 insertions(+), 2 deletions(-) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 30 | |
| 31 | diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 32 | index 1fe2a02..5b76b06 100644 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 33 | --- a/src/modules/alsa/alsa-mixer.c |
| 34 | +++ b/src/modules/alsa/alsa-mixer.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 35 | @@ -4783,8 +4783,10 @@ static pa_device_port* device_port_alsa_init(pa_hashmap *ports, /* card ports */ |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 36 | 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); |
| 47 | diff --git a/src/modules/alsa/alsa-ucm.c b/src/modules/alsa/alsa-ucm.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 48 | index 42f3242..68fcc26 100644 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 49 | --- a/src/modules/alsa/alsa-ucm.c |
| 50 | +++ b/src/modules/alsa/alsa-ucm.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 51 | @@ -791,6 +791,7 @@ static void ucm_add_port_combination( |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 52 | 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) { |
| 59 | diff --git a/src/modules/bluetooth/module-bluez4-device.c b/src/modules/bluetooth/module-bluez4-device.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 60 | index 9a921a5..adecb32 100644 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 61 | --- a/src/modules/bluetooth/module-bluez4-device.c |
| 62 | +++ b/src/modules/bluetooth/module-bluez4-device.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 63 | @@ -2180,6 +2180,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 64 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 71 | @@ -2191,6 +2192,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 72 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 79 | @@ -2203,6 +2205,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 80 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 88 | @@ -2215,6 +2219,8 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 89 | 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; |
| 97 | diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 98 | index 84e6d55..b015c67 100644 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 99 | --- 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; |
| 135 | diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 136 | index b6cbbf7..f92ac87 100644 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 137 | --- a/src/pulsecore/card.c |
| 138 | +++ b/src/pulsecore/card.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 139 | @@ -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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 142 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 147 | @@ -52,6 +53,14 @@ pa_card_profile *pa_card_profile_new(const char *name, const char *description, |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 148 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 159 | pa_xfree(c->input_name); |
| 160 | pa_xfree(c->output_name); |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 161 | pa_xfree(c->name); |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 162 | @@ -59,6 +68,12 @@ void pa_card_profile_free(pa_card_profile *c) { |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 163 | 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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 175 | diff --git a/src/pulsecore/card.h b/src/pulsecore/card.h |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 176 | index 30bfc0e..fff9057 100644 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 177 | --- a/src/pulsecore/card.h |
| 178 | +++ b/src/pulsecore/card.h |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 179 | @@ -50,6 +50,8 @@ struct pa_card_profile { |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 180 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 188 | @@ -107,6 +109,8 @@ typedef struct pa_card_new_data { |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 189 | 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 | |
| 197 | diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 198 | index 5807d3e..d12dfbc 100644 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 199 | --- a/src/pulsecore/device-port.c |
| 200 | +++ b/src/pulsecore/device-port.c |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 201 | @@ -107,8 +107,13 @@ static void device_port_free(pa_object *o) { |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 202 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 214 | pa_xfree(p->preferred_profile); |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 215 | pa_xfree(p->name); |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 216 | -- |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 217 | 2.7.0 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 218 | |