summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2020-09-09 14:08:15 +0200
committerWim Taymans <wtaymans@redhat.com>2020-09-09 14:08:15 +0200
commit6e339200afbec038278516a5a01f4865af6172d7 (patch)
treebad898de9513eb0490f792b7851e41c14585fd78
parent5f38562d38e72fa76f8dfe7e1bd1ead853f82ce8 (diff)
acp: improve port and profile index select
Keep 3 options, the available ports, unknown and highest priority other ports.
-rw-r--r--spa/plugins/alsa/acp/acp.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/spa/plugins/alsa/acp/acp.c b/spa/plugins/alsa/acp/acp.c
index b9332443..1684beb5 100644
--- a/spa/plugins/alsa/acp/acp.c
+++ b/spa/plugins/alsa/acp/acp.c
@@ -622,9 +622,11 @@ static void init_eld_ctls(pa_card *impl)
uint32_t acp_card_find_best_profile_index(struct acp_card *card, const char *name)
{
uint32_t i;
- uint32_t best_alt = ACP_INVALID_INDEX, best = ACP_INVALID_INDEX;
+ uint32_t best, best2, best3;
struct acp_card_profile **profiles = card->profiles;
+ best = best2 = best3 = ACP_INVALID_INDEX;
+
for (i = 0; i < card->n_profiles; i++) {
struct acp_card_profile *p = profiles[i];
@@ -633,16 +635,21 @@ uint32_t acp_card_find_best_profile_index(struct acp_card *card, const char *nam
best = i;
continue;
}
- if (p->available != ACP_AVAILABLE_NO) {
+ if (p->available == ACP_AVAILABLE_YES) {
if (best == ACP_INVALID_INDEX || p->priority > profiles[best]->priority)
best = i;
+ } else if (p->available != ACP_AVAILABLE_NO) {
+ if (best2 == ACP_INVALID_INDEX || p->priority > profiles[best2]->priority)
+ best2 = i;
} else {
- if (best_alt == ACP_INVALID_INDEX || p->priority > profiles[best_alt]->priority)
- best_alt = i;
+ if (best3 == ACP_INVALID_INDEX || p->priority > profiles[best3]->priority)
+ best3 = i;
}
}
if (best == ACP_INVALID_INDEX)
- best = best_alt;
+ best = best2;
+ if (best == ACP_INVALID_INDEX)
+ best = best3;
if (best == ACP_INVALID_INDEX)
best = 0;
return best;
@@ -988,7 +995,7 @@ static int device_enable(pa_card *impl, pa_alsa_mapping *mapping, pa_alsa_device
port_index = acp_device_find_best_port_index(&dev->device, NULL);
- dev->active_port = (pa_device_port*)dev->device.ports[port_index];
+ dev->active_port = (pa_device_port*)impl->card.ports[port_index];
if (dev->active_port)
dev->active_port->port.flags |= ACP_PORT_ACTIVE;
@@ -1295,9 +1302,11 @@ static void sync_mixer(pa_alsa_device *d, pa_device_port *port)
uint32_t acp_device_find_best_port_index(struct acp_device *dev, const char *name)
{
uint32_t i;
- uint32_t best_alt = ACP_INVALID_INDEX, best = ACP_INVALID_INDEX;
+ uint32_t best, best2, best3;
struct acp_port **ports = dev->ports;
+ best = best2 = best3 = ACP_INVALID_INDEX;
+
for (i = 0; i < dev->n_ports; i++) {
struct acp_port *p = ports[i];
@@ -1306,19 +1315,24 @@ uint32_t acp_device_find_best_port_index(struct acp_device *dev, const char *nam
best = i;
continue;
}
- if (p->available != ACP_AVAILABLE_NO) {
+ if (p->available == ACP_AVAILABLE_YES) {
if (best == ACP_INVALID_INDEX || p->priority > ports[best]->priority)
best = i;
+ } else if (p->available != ACP_AVAILABLE_NO) {
+ if (best2 == ACP_INVALID_INDEX || p->priority > ports[best2]->priority)
+ best2 = i;
} else {
- if (best_alt == ACP_INVALID_INDEX || p->priority > ports[best_alt]->priority)
- best_alt = i;
+ if (best3 == ACP_INVALID_INDEX || p->priority > ports[best3]->priority)
+ best3 = i;
}
}
if (best == ACP_INVALID_INDEX)
- best = best_alt;
+ best = best2;
+ if (best == ACP_INVALID_INDEX)
+ best = best3;
if (best == ACP_INVALID_INDEX)
best = 0;
- return best;
+ return ports[best]->index;
}
int acp_device_set_port(struct acp_device *dev, uint32_t port_index)