summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Henningsson <david.henningsson@canonical.com>2014-03-21 10:19:19 +0100
committerWim Taymans <wtaymans@redhat.com>2014-08-22 12:46:18 +0200
commit5229819bbf79735a67e253bc7e7bbed943cfc886 (patch)
treed5ba2271de8a3eba383206cbce05a644fc2d39a1
parent898b04cfc537325edd5e5d052c544bc004f9918d (diff)
sink/source: Initialize port before fixate hook (fixes volume/mute not saved)
In case a port has not yet been saved, which is e g often the case if a sink/source has only one port, reading volume/mute will be done without port, whereas writing volume/mute will be done with port. Work around this by setting a default port before the fixate hook, so module-device-restore can read volume/mute for the correct port. BugLink: https://bugs.launchpad.net/bugs/1289515 Signed-off-by: David Henningsson <david.henningsson@canonical.com> Conflicts: src/pulsecore/sink.c src/pulsecore/source.c
-rw-r--r--src/pulsecore/device-port.c27
-rw-r--r--src/pulsecore/device-port.h2
-rw-r--r--src/pulsecore/sink.c18
-rw-r--r--src/pulsecore/source.c18
4 files changed, 49 insertions, 16 deletions
diff --git a/src/pulsecore/device-port.c b/src/pulsecore/device-port.c
index 9ea54e3d4..c3d0148b6 100644
--- a/src/pulsecore/device-port.c
+++ b/src/pulsecore/device-port.c
@@ -147,3 +147,30 @@ void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset) {
if (p == pa_hashmap_get(card->ports, p->name))
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE, card->index);
}
+
+pa_device_port *pa_device_port_find_best(pa_hashmap *ports)
+{
+ void *state;
+ pa_device_port *p, *best = NULL;
+
+ if (!ports)
+ return NULL;
+
+ /* First run: skip unavailable ports */
+ PA_HASHMAP_FOREACH(p, ports, state) {
+ if (p->available == PA_PORT_AVAILABLE_NO)
+ continue;
+
+ if (!best || p->priority > best->priority)
+ best = p;
+ }
+
+ /* Second run: if only unavailable ports exist, still suggest a port */
+ if (!best) {
+ PA_HASHMAP_FOREACH(p, ports, state)
+ if (!best || p->priority > best->priority)
+ best = p;
+ }
+
+ return best;
+}
diff --git a/src/pulsecore/device-port.h b/src/pulsecore/device-port.h
index a5c6420ba..62bb4478e 100644
--- a/src/pulsecore/device-port.h
+++ b/src/pulsecore/device-port.h
@@ -70,4 +70,6 @@ void pa_device_port_set_available(pa_device_port *p, pa_port_available_t availab
void pa_device_port_set_latency_offset(pa_device_port *p, int64_t offset);
+pa_device_port *pa_device_port_find_best(pa_hashmap *ports);
+
#endif
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 1522e60b2..7f21d9090 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -235,6 +235,12 @@ pa_sink* pa_sink_new(
pa_device_init_icon(data->proplist, TRUE);
pa_device_init_intended_roles(data->proplist);
+ if (!data->active_port) {
+ pa_device_port *p = pa_device_port_find_best(data->ports);
+ if (p)
+ pa_sink_new_data_set_port(data, p->name);
+ }
+
if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_FIXATE], data) < 0) {
pa_xfree(s);
pa_namereg_unregister(core, name);
@@ -300,14 +306,10 @@ pa_sink* pa_sink_new(
if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
s->save_port = data->save_port;
- if (!s->active_port) {
- void *state;
- pa_device_port *p;
-
- PA_HASHMAP_FOREACH(p, s->ports, state)
- if (!s->active_port || p->priority > s->active_port->priority)
- s->active_port = p;
- }
+ /* Hopefully the active port has already been assigned in the previous call
+ to pa_device_port_find_best, but better safe than sorry */
+ if (!s->active_port)
+ s->active_port = pa_device_port_find_best(s->ports);
if (s->active_port)
s->latency_offset = s->active_port->latency_offset;
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 5c264e0c1..cabbc68d0 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -222,6 +222,12 @@ pa_source* pa_source_new(
pa_device_init_icon(data->proplist, FALSE);
pa_device_init_intended_roles(data->proplist);
+ if (!data->active_port) {
+ pa_device_port *p = pa_device_port_find_best(data->ports);
+ if (p)
+ pa_source_new_data_set_port(data, p->name);
+ }
+
if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_FIXATE], data) < 0) {
pa_xfree(s);
pa_namereg_unregister(core, name);
@@ -288,14 +294,10 @@ pa_source* pa_source_new(
if ((s->active_port = pa_hashmap_get(s->ports, data->active_port)))
s->save_port = data->save_port;
- if (!s->active_port) {
- void *state;
- pa_device_port *p;
-
- PA_HASHMAP_FOREACH(p, s->ports, state)
- if (!s->active_port || p->priority > s->active_port->priority)
- s->active_port = p;
- }
+ /* Hopefully the active port has already been assigned in the previous call
+ to pa_device_port_find_best, but better safe than sorry */
+ if (!s->active_port)
+ s->active_port = pa_device_port_find_best(s->ports);
if (s->active_port)
s->latency_offset = s->active_port->latency_offset;