mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-11 13:30:07 -05:00
acp: add per device port list
Add the list of possible ports for a device. Pass the allowed devices in the routes. Store the active port in the device. Fixes enumeration of ports on devices with UCM.
This commit is contained in:
parent
5d90fe26f3
commit
374210c890
9 changed files with 64 additions and 22 deletions
|
|
@ -540,17 +540,13 @@ static void device_event_param(void *object, int seq,
|
|||
return;
|
||||
}
|
||||
|
||||
if (direction == SPA_DIRECTION_OUTPUT)
|
||||
g->card_info.active_port_output = index;
|
||||
else
|
||||
g->card_info.active_port_input = index;
|
||||
|
||||
pw_log_debug("device %d: active %s route %d", g->id,
|
||||
direction == SPA_DIRECTION_OUTPUT ? "output" : "input",
|
||||
index);
|
||||
|
||||
ng = find_node_for_route(c, g, device);
|
||||
if (props && ng) {
|
||||
ng->node_info.active_port = index;
|
||||
parse_props(ng, props, true);
|
||||
emit_event(c, ng, PA_SUBSCRIPTION_EVENT_CHANGE);
|
||||
}
|
||||
|
|
@ -684,6 +680,7 @@ static void device_sync_ports(struct global *g)
|
|||
n_ports = g->card_info.n_ports;
|
||||
i->ports = calloc(n_ports+1, sizeof(pa_card_port_info *));
|
||||
g->card_info.card_ports = calloc(n_ports, sizeof(pa_card_port_info));
|
||||
g->card_info.port_devices = calloc(n_ports, sizeof(struct port_device));
|
||||
i->n_ports = 0;
|
||||
|
||||
pw_log_debug("context %p: info for %d", g->context, g->id);
|
||||
|
|
@ -695,8 +692,9 @@ static void device_sync_ports(struct global *g)
|
|||
enum spa_direction direction;
|
||||
const char *name = NULL, *description = NULL;
|
||||
enum spa_param_availability available = SPA_PARAM_AVAILABILITY_unknown;
|
||||
struct spa_pod *profiles = NULL, *info = NULL;
|
||||
struct spa_pod *profiles = NULL, *info = NULL, *devices = NULL;
|
||||
pa_card_port_info *pi;
|
||||
struct port_device *pd;
|
||||
|
||||
if (spa_pod_parse_object(p->param,
|
||||
SPA_TYPE_OBJECT_ParamRoute, NULL,
|
||||
|
|
@ -707,6 +705,7 @@ static void device_sync_ports(struct global *g)
|
|||
SPA_PARAM_ROUTE_priority, SPA_POD_OPT_Int(&priority),
|
||||
SPA_PARAM_ROUTE_available, SPA_POD_OPT_Id(&available),
|
||||
SPA_PARAM_ROUTE_info, SPA_POD_OPT_Pod(&info),
|
||||
SPA_PARAM_ROUTE_devices, SPA_POD_OPT_Pod(&devices),
|
||||
SPA_PARAM_ROUTE_profiles, SPA_POD_OPT_Pod(&profiles)) < 0) {
|
||||
pw_log_warn("device %d: can't parse route", g->id);
|
||||
continue;
|
||||
|
|
@ -760,6 +759,11 @@ static void device_sync_ports(struct global *g)
|
|||
pi->profiles = (pa_card_profile_info **)pi->profiles2;
|
||||
break;
|
||||
}
|
||||
pd = &g->card_info.port_devices[j];
|
||||
pd->n_devices = 0;
|
||||
pd->devices = NULL;
|
||||
if (devices)
|
||||
pd->devices = spa_pod_get_array(devices, &pd->n_devices);
|
||||
j++;
|
||||
}
|
||||
i->ports[j] = NULL;
|
||||
|
|
@ -1083,8 +1087,6 @@ static int set_mask(pa_context *c, struct global *g)
|
|||
ginfo = &device_info;
|
||||
spa_list_init(&g->card_info.profiles);
|
||||
spa_list_init(&g->card_info.ports);
|
||||
g->card_info.active_port_output = SPA_ID_INVALID;
|
||||
g->card_info.active_port_input = SPA_ID_INVALID;
|
||||
} else if (strcmp(g->type, PW_TYPE_INTERFACE_Node) == 0) {
|
||||
if (g->props == NULL)
|
||||
return 0;
|
||||
|
|
@ -1136,6 +1138,7 @@ static int set_mask(pa_context *c, struct global *g)
|
|||
g->node_info.mute = false;
|
||||
g->node_info.base_volume = 1.0f;
|
||||
g->node_info.volume_step = 1.0f / (PA_VOLUME_NORM+1);
|
||||
g->node_info.active_port = SPA_ID_INVALID;
|
||||
} else if (strcmp(g->type, PW_TYPE_INTERFACE_Port) == 0) {
|
||||
if (g->props == NULL)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -230,6 +230,11 @@ struct param {
|
|||
#define PA_IDX_FLAG_DSP 0x800000U
|
||||
#define PA_IDX_MASK_DSP 0x7fffffU
|
||||
|
||||
struct port_device {
|
||||
uint32_t n_devices;
|
||||
uint32_t *devices;
|
||||
};
|
||||
|
||||
struct global;
|
||||
|
||||
struct global_info {
|
||||
|
|
@ -286,6 +291,7 @@ struct global {
|
|||
uint32_t profile_device_id; /* id in profile */
|
||||
float base_volume;
|
||||
float volume_step;
|
||||
uint32_t active_port;
|
||||
} node_info;
|
||||
struct {
|
||||
uint32_t node_id;
|
||||
|
|
@ -302,8 +308,7 @@ struct global {
|
|||
unsigned int pending_profiles:1;
|
||||
pa_card_port_info *card_ports;
|
||||
unsigned int pending_ports:1;
|
||||
uint32_t active_port_output;
|
||||
uint32_t active_port_input;
|
||||
struct port_device *port_devices;
|
||||
} card_info;
|
||||
struct {
|
||||
pa_module_info info;
|
||||
|
|
|
|||
|
|
@ -81,6 +81,19 @@ static int has_profile(pa_card_profile_info2 **list, pa_card_profile_info2 *acti
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
static int has_device(struct port_device *devices, uint32_t id)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
if (devices->devices == NULL || devices->n_devices == 0)
|
||||
return 1;
|
||||
|
||||
for (i = 0; i < devices->n_devices; i++) {
|
||||
if (devices->devices[i] == id)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sink_callback(pa_context *c, struct global *g, struct sink_data *d)
|
||||
{
|
||||
|
|
@ -150,12 +163,15 @@ static int sink_callback(pa_context *c, struct global *g, struct sink_data *d)
|
|||
continue;
|
||||
if (!has_profile(ci->ports[n]->profiles2, ci->active_profile2))
|
||||
continue;
|
||||
if (!has_device(&cg->card_info.port_devices[n], g->node_info.profile_device_id))
|
||||
continue;
|
||||
|
||||
i.ports[j] = &spi[j];
|
||||
spi[j].name = ci->ports[n]->name;
|
||||
spi[j].description = ci->ports[n]->description;
|
||||
spi[j].priority = ci->ports[n]->priority;
|
||||
spi[j].available = ci->ports[n]->available;
|
||||
if (n == cg->card_info.active_port_output)
|
||||
if (n == g->node_info.active_port)
|
||||
i.active_port = i.ports[j];
|
||||
j++;
|
||||
}
|
||||
|
|
@ -432,10 +448,7 @@ static int set_volume(pa_context *c, struct global *g, const pa_cvolume *volume,
|
|||
|
||||
if (SPA_FLAG_IS_SET(g->node_info.flags, NODE_FLAG_DEVICE_VOLUME | NODE_FLAG_DEVICE_MUTE) &&
|
||||
(cg = pa_context_find_global(c, card_id)) != NULL) {
|
||||
if (mask & PA_SUBSCRIPTION_MASK_SINK)
|
||||
id = cg->card_info.active_port_output;
|
||||
else if (mask & PA_SUBSCRIPTION_MASK_SOURCE)
|
||||
id = cg->card_info.active_port_input;
|
||||
id = cg->node_info.active_port;
|
||||
}
|
||||
if (id != SPA_ID_INVALID && device_id != SPA_ID_INVALID) {
|
||||
res = set_device_volume(c, g, cg, id, device_id, volume, mute);
|
||||
|
|
@ -877,12 +890,14 @@ static int source_callback(pa_context *c, struct global *g, struct source_data *
|
|||
continue;
|
||||
if (!has_profile(ci->ports[n]->profiles2, ci->active_profile2))
|
||||
continue;
|
||||
if (!has_device(&cg->card_info.port_devices[n], g->node_info.profile_device_id))
|
||||
continue;
|
||||
i.ports[j] = &spi[j];
|
||||
spi[j].name = ci->ports[n]->name;
|
||||
spi[j].description = ci->ports[n]->description;
|
||||
spi[j].priority = ci->ports[n]->priority;
|
||||
spi[j].available = ci->ports[n]->available;
|
||||
if (n == cg->card_info.active_port_input)
|
||||
if (n == g->node_info.active_port)
|
||||
i.active_port = i.ports[j];
|
||||
j++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue