mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
bluez5-device: Refactor device_set_update for ASHA & BAP
This commit is contained in:
parent
445ca819ce
commit
a419f69bbb
1 changed files with 111 additions and 64 deletions
|
|
@ -966,7 +966,7 @@ static const struct spa_bt_transport_events device_set_transport_events = {
|
||||||
.destroy = device_set_transport_destroy,
|
.destroy = device_set_transport_destroy,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void device_set_update(struct impl *this, struct device_set *dset)
|
static void device_set_update_asha(struct impl *this, struct device_set *dset)
|
||||||
{
|
{
|
||||||
struct spa_bt_device *device = this->bt_dev;
|
struct spa_bt_device *device = this->bt_dev;
|
||||||
struct spa_bt_set_membership *set;
|
struct spa_bt_set_membership *set;
|
||||||
|
|
@ -992,32 +992,24 @@ static void device_set_update(struct impl *this, struct device_set *dset)
|
||||||
spa_list_for_each(set, membership_list, link) {
|
spa_list_for_each(set, membership_list, link) {
|
||||||
struct spa_bt_set_membership *s;
|
struct spa_bt_set_membership *s;
|
||||||
int num_devices = 0;
|
int num_devices = 0;
|
||||||
bool is_asha_member = false;
|
|
||||||
|
|
||||||
device_set_clear(this, dset);
|
device_set_clear(this, dset);
|
||||||
|
|
||||||
spa_bt_for_each_set_member(s, set) {
|
spa_bt_for_each_set_member(s, set) {
|
||||||
struct spa_bt_transport *t;
|
struct spa_bt_transport *t;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
uint32_t source_id = DEVICE_ID_SOURCE;
|
|
||||||
uint32_t sink_id = DEVICE_ID_SINK;
|
uint32_t sink_id = DEVICE_ID_SINK;
|
||||||
bool bap_duplex = s->device->connected_profiles & SPA_BT_PROFILE_BAP_DUPLEX;
|
|
||||||
bool is_asha = s->device->connected_profiles & SPA_BT_PROFILE_ASHA_SINK;
|
|
||||||
|
|
||||||
if (!bap_duplex && !is_asha)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (is_asha) {
|
|
||||||
spa_list_for_each(t, &s->device->transport_list, device_link) {
|
|
||||||
if (!(s->device->connected_profiles & SPA_BT_PROFILE_ASHA_SINK))
|
if (!(s->device->connected_profiles & SPA_BT_PROFILE_ASHA_SINK))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
spa_list_for_each(t, &s->device->transport_list, device_link) {
|
||||||
if (!transport_enabled(t, SPA_BT_PROFILE_ASHA_SINK))
|
if (!transport_enabled(t, SPA_BT_PROFILE_ASHA_SINK))
|
||||||
continue;
|
continue;
|
||||||
if (dset->sinks >= SPA_N_ELEMENTS(dset->sink))
|
if (dset->sinks >= SPA_N_ELEMENTS(dset->sink))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
active = true;
|
active = true;
|
||||||
is_asha_member = true;
|
|
||||||
dset->leader = set->leader = t->asha_right_side;
|
dset->leader = set->leader = t->asha_right_side;
|
||||||
dset->path = strdup(set->path);
|
dset->path = strdup(set->path);
|
||||||
dset->sink[dset->sinks].impl = this;
|
dset->sink[dset->sinks].impl = this;
|
||||||
|
|
@ -1028,9 +1020,59 @@ static void device_set_update(struct impl *this, struct device_set *dset)
|
||||||
&device_set_transport_events, &dset->sink[dset->sinks]);
|
&device_set_transport_events, &dset->sink[dset->sinks]);
|
||||||
++dset->sinks;
|
++dset->sinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (active)
|
||||||
|
++num_devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bap_duplex) {
|
spa_log_debug(this->log, "%p: %s belongs to ASHA set %s leader:%d", this,
|
||||||
|
device->path, set->path, set->leader);
|
||||||
|
|
||||||
|
if (num_devices > 1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dset->sink_enabled = dset->path && (dset->sinks > 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void device_set_update_bap(struct impl *this, struct device_set *dset)
|
||||||
|
{
|
||||||
|
struct spa_bt_device *device = this->bt_dev;
|
||||||
|
struct spa_bt_set_membership *set;
|
||||||
|
struct spa_bt_set_membership tmp_set = {
|
||||||
|
.device = device,
|
||||||
|
.rank = 0,
|
||||||
|
.leader = true,
|
||||||
|
.path = device->path,
|
||||||
|
.others = SPA_LIST_INIT(&tmp_set.others),
|
||||||
|
};
|
||||||
|
struct spa_list tmp_set_list = SPA_LIST_INIT(&tmp_set_list);
|
||||||
|
struct spa_list *membership_list = &device->set_membership_list;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If no device set, use a dummy one, so that we can handle also those devices
|
||||||
|
* here (they may have multiple transports regardless).
|
||||||
|
*/
|
||||||
|
if (spa_list_is_empty(membership_list)) {
|
||||||
|
spa_list_append(&tmp_set_list, &tmp_set.link);
|
||||||
|
membership_list = &tmp_set_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
spa_list_for_each(set, membership_list, link) {
|
||||||
|
struct spa_bt_set_membership *s;
|
||||||
|
int num_devices = 0;
|
||||||
|
|
||||||
|
device_set_clear(this, dset);
|
||||||
|
|
||||||
|
spa_bt_for_each_set_member(s, set) {
|
||||||
|
struct spa_bt_transport *t;
|
||||||
|
bool active = false;
|
||||||
|
uint32_t source_id = DEVICE_ID_SOURCE;
|
||||||
|
uint32_t sink_id = DEVICE_ID_SINK;
|
||||||
|
|
||||||
|
if (!(s->device->connected_profiles & SPA_BT_PROFILE_BAP_DUPLEX))
|
||||||
|
continue;
|
||||||
|
|
||||||
spa_list_for_each(t, &s->device->transport_list, device_link) {
|
spa_list_for_each(t, &s->device->transport_list, device_link) {
|
||||||
if (!(s->device->connected_profiles & SPA_BT_PROFILE_BAP_SOURCE))
|
if (!(s->device->connected_profiles & SPA_BT_PROFILE_BAP_SOURCE))
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1066,7 +1108,6 @@ static void device_set_update(struct impl *this, struct device_set *dset)
|
||||||
&device_set_transport_events, &dset->sink[dset->sinks]);
|
&device_set_transport_events, &dset->sink[dset->sinks]);
|
||||||
++dset->sinks;
|
++dset->sinks;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (active)
|
if (active)
|
||||||
++num_devices;
|
++num_devices;
|
||||||
|
|
@ -1082,11 +1123,9 @@ static void device_set_update(struct impl *this, struct device_set *dset)
|
||||||
/* XXX: device set nodes for BAP server not supported,
|
/* XXX: device set nodes for BAP server not supported,
|
||||||
* XXX: it'll appear as multiple streams
|
* XXX: it'll appear as multiple streams
|
||||||
*/
|
*/
|
||||||
if (!is_asha_member) {
|
|
||||||
dset->path = NULL;
|
dset->path = NULL;
|
||||||
dset->leader = false;
|
dset->leader = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (num_devices > 1)
|
if (num_devices > 1)
|
||||||
break;
|
break;
|
||||||
|
|
@ -1096,6 +1135,14 @@ static void device_set_update(struct impl *this, struct device_set *dset)
|
||||||
dset->source_enabled = dset->path && (dset->sources > 1);
|
dset->source_enabled = dset->path && (dset->sources > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void device_set_update(struct impl *this, struct device_set *dset)
|
||||||
|
{
|
||||||
|
if (this->profile == DEVICE_PROFILE_BAP)
|
||||||
|
device_set_update_bap(this, dset);
|
||||||
|
else if (this->profile == DEVICE_PROFILE_ASHA)
|
||||||
|
device_set_update_asha(this, dset);
|
||||||
|
}
|
||||||
|
|
||||||
static bool device_set_equal(struct device_set *a, struct device_set *b)
|
static bool device_set_equal(struct device_set *a, struct device_set *b)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue