Subject: [PATCH BlueZ v2 0/7] [PATCH BlueZ v2 0/7] Add support for multiple BISes on the bcast source

This patch adds support for multiple BISes in broadcast sources.

Example commands:
Create a local endpoint and an endpoint for BIS1:
endpoint.register 00001852-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] Max Transports (auto/value): a
[/local/endpoint/ep0] Locations: 0x03
[/local/endpoint/ep0] Supported Context (value): 0

Configure BIS1, create BIS1 transport and endpoint for BIS2:
endpoint.config /org/bluez/hci0/pac_bcast0 /local/endpoint/ep0 48_4_1
[/local/endpoint/ep0] BIG (auto/value): 0x01
[/local/endpoint/ep0] Enter channel location (value/no): 0x01
[/local/endpoint/ep0] Enter Metadata (value/no): n

Configure BIS2, create BIS2 transport and endpoint for BIS3:
endpoint.config /org/bluez/hci0/pac_bcast1 /local/endpoint/ep0 48_4_1
[/local/endpoint/ep0] BIG (auto/value): 0x01
[/local/endpoint/ep0] Enter channel location (value/no): 0x02
[/local/endpoint/ep0] Enter Metadata (value/no): n

For multiple BISes acquire must be called on all transports
before the BIG is created:
transport.acquire /org/bluez/hci0/pac_bcast0/fd0
transport.acquire /org/bluez/hci0/pac_bcast1/fd1
.....
transport.release /org/bluez/hci0/pac_bcast0/fd0
transport.release /org/bluez/hci0/pac_bcast1/fd1

Silviu Florian Barbulescu (7):
bap: Remove set lpac user data at bcast ep register
shared/bap: Add support to create multiple streams for the same pac
bap: Create a new endpoint available for the next BIS configuration
bap: Split bap_state and bap_connecting in two functions
shared/bap: Check the state of all the streams with the same BIG ID
bap: Set the generated BASE on all setups from the same BIG
shared/bap: Generate single BIS BASE for a config with BIG ID 0xFF

profiles/audio/bap.c | 318 +++++++++++++++++++++++++++++++++++--------
src/shared/bap.c | 78 +++++++++--
src/shared/bap.h | 2 +
3 files changed, 330 insertions(+), 68 deletions(-)


base-commit: c1851987ca2c6e41d1e0e166e959b754e369c254
--
2.39.2



Subject: [PATCH BlueZ v2 1/7] bap: Remove set lpac user data at bcast ep register

Remove set lpac user data at bcast ep register

---
profiles/audio/bap.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 88c93127b..38ee42894 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -1207,8 +1207,6 @@ static struct bap_ep *ep_register_bcast(struct bap_data *data,
*/
if (rpac)
bt_bap_pac_set_user_data(rpac, ep->path);
- else
- bt_bap_pac_set_user_data(lpac, ep->path);

DBG("ep %p lpac %p rpac %p path %s", ep, ep->lpac, ep->rpac, ep->path);

--
2.39.2


Subject: [PATCH BlueZ v2 3/7] bap: Create a new endpoint for the next BIS configuration

Add support to create a new endpoint to be available for the next
BIS configuration.
Broadcast source requires the creation of multiple endpoints, one
for each BIS for the multiple BISes scenario.
---
profiles/audio/bap.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 38ee42894..ffd742d7d 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -926,6 +926,10 @@ static void setup_free(void *data)
free(setup);
}

+static struct bap_ep *ep_register_bcast(struct bap_data *data,
+ struct bt_bap_pac *lpac,
+ struct bt_bap_pac *rpac);
+
static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
void *data)
{
@@ -982,6 +986,10 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
else {
setup->base = bt_bap_stream_get_base(setup->stream);
setup->id = 0;
+ /* Create a new endpoint for a new BIS */
+ if (!ep_register_bcast(ep->data, ep->lpac, ep->rpac))
+ error("Unable to register endpoint for pac %p",
+ ep->lpac);
}

if (ep->data->service)
@@ -1133,6 +1141,10 @@ static bool match_ep(const void *data, const void *user_data)
const struct bap_ep *ep = data;
const struct match_ep *match = user_data;

+ if ((!ep->lpac) || (!ep->rpac) ||
+ (!match->lpac) || (!match->rpac))
+ return false;
+
if (ep->lpac != match->lpac)
return false;

--
2.39.2


Subject: [PATCH BlueZ v2 4/7] bap: Split bap_state and bap_connecting in two functions

Split bap_state and bap_connecting in two specific functions
for unicast (bap_state, bap_connecting) and broadcast
(bap_state_bcast, bap_connecting_bcast).
---
profiles/audio/bap.c | 157 +++++++++++++++++++++++++++++--------------
1 file changed, 107 insertions(+), 50 deletions(-)

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index ffd742d7d..cf1c53b30 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -2110,25 +2110,19 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
return;
}

- if (bt_bap_stream_get_type(stream) ==
- BT_BAP_STREAM_TYPE_UCAST) {
- /* Wait QoS response to respond */
- setup->id = bt_bap_stream_qos(stream,
- &setup->qos,
- qos_cb, setup);
- if (!setup->id) {
- error("Failed to Configure QoS");
- bt_bap_stream_release(stream,
- NULL, NULL);
- }
+ /* Wait QoS response to respond */
+ setup->id = bt_bap_stream_qos(stream,
+ &setup->qos,
+ qos_cb, setup);
+ if (!setup->id) {
+ error("Failed to Configure QoS");
+ bt_bap_stream_release(stream,
+ NULL, NULL);
}
}
break;
case BT_BAP_STREAM_STATE_QOS:
- if (bt_bap_stream_get_type(stream) ==
- BT_BAP_STREAM_TYPE_UCAST) {
setup_create_io(data, setup, stream, true);
- }
break;
case BT_BAP_STREAM_STATE_ENABLING:
if (setup)
@@ -2139,6 +2133,45 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
}
}

+static void bap_state_bcast(struct bt_bap_stream *stream, uint8_t old_state,
+ uint8_t new_state, void *user_data)
+{
+ struct bap_data *data = user_data;
+ struct bap_setup *setup;
+
+ DBG("stream %p: %s(%u) -> %s(%u)", stream,
+ bt_bap_stream_statestr(old_state), old_state,
+ bt_bap_stream_statestr(new_state), new_state);
+
+ /* Ignore transitions back to same state */
+ if (new_state == old_state)
+ return;
+
+ setup = bap_find_setup_by_stream(data, stream);
+
+ switch (new_state) {
+ case BT_BAP_STREAM_STATE_IDLE:
+ /* Release stream if idle */
+ if (setup)
+ setup_free(setup);
+ else
+ queue_remove(data->streams, stream);
+ break;
+ case BT_BAP_STREAM_STATE_CONFIG:
+ if (setup && !setup->id) {
+ setup_create_io(data, setup, stream, true);
+ if (!setup->io) {
+ error("Unable to create io");
+ if (old_state != BT_BAP_STREAM_STATE_RELEASING)
+ bt_bap_stream_release(stream, NULL,
+ NULL);
+ return;
+ }
+ }
+ break;
+ }
+}
+
static void pac_added(struct bt_bap_pac *pac, void *user_data)
{
struct btd_service *service = user_data;
@@ -2332,45 +2365,69 @@ static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd,

g_io_channel_set_close_on_unref(io, FALSE);

- switch (bt_bap_stream_get_type(setup->stream)) {
- case BT_BAP_STREAM_TYPE_UCAST:
- /* Attempt to get CIG/CIS if they have not been set */
- if (qos->ucast.cig_id == BT_ISO_QOS_CIG_UNSET ||
- qos->ucast.cis_id == BT_ISO_QOS_CIS_UNSET) {
- struct bt_iso_qos iso_qos;
+ /* Attempt to get CIG/CIS if they have not been set */
+ if (qos->ucast.cig_id == BT_ISO_QOS_CIG_UNSET ||
+ qos->ucast.cis_id == BT_ISO_QOS_CIS_UNSET) {
+ struct bt_iso_qos iso_qos;

- if (!io_get_qos(io, &iso_qos)) {
- g_io_channel_unref(io);
- return;
- }
-
- qos->ucast.cig_id = iso_qos.ucast.cig;
- qos->ucast.cis_id = iso_qos.ucast.cis;
+ if (!io_get_qos(io, &iso_qos)) {
+ g_io_channel_unref(io);
+ return;
}

- DBG("stream %p fd %d: CIG 0x%02x CIS 0x%02x", stream, fd,
- qos->ucast.cig_id, qos->ucast.cis_id);
- break;
- case BT_BAP_STREAM_TYPE_BCAST:
- /* Attempt to get BIG/BIS if they have not been set */
- if (setup->qos.bcast.big == BT_ISO_QOS_BIG_UNSET ||
- setup->qos.bcast.bis == BT_ISO_QOS_BIS_UNSET) {
- struct bt_iso_qos iso_qos;
+ qos->ucast.cig_id = iso_qos.ucast.cig;
+ qos->ucast.cis_id = iso_qos.ucast.cis;
+ }

- if (!io_get_qos(io, &iso_qos)) {
- g_io_channel_unref(io);
- return;
- }
+ DBG("stream %p fd %d: CIG 0x%02x CIS 0x%02x", stream, fd,
+ qos->ucast.cig_id, qos->ucast.cis_id);
+}

- qos->bcast.big = iso_qos.bcast.big;
- qos->bcast.bis = iso_qos.bcast.bis;
- bt_bap_stream_config(setup->stream, qos, setup->caps,
- NULL, NULL);
+static void bap_connecting_bcast(struct bt_bap_stream *stream, bool state,
+ int fd, void *user_data)
+{
+ struct bap_data *data = user_data;
+ struct bap_setup *setup;
+ GIOChannel *io;
+
+ if (!state)
+ return;
+
+ setup = bap_find_setup_by_stream(data, stream);
+ if (!setup)
+ return;
+
+ setup->recreate = false;
+
+ if (!setup->io) {
+ io = g_io_channel_unix_new(fd);
+ setup->io_id = g_io_add_watch(io,
+ G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+ setup_io_disconnected, setup);
+ setup->io = io;
+ } else
+ io = setup->io;
+
+ g_io_channel_set_close_on_unref(io, FALSE);
+
+ /* Attempt to get BIG/BIS if they have not been set */
+ if (setup->qos.bcast.big == BT_ISO_QOS_BIG_UNSET ||
+ setup->qos.bcast.bis == BT_ISO_QOS_BIS_UNSET) {
+ struct bt_iso_qos iso_qos;
+
+ if (!io_get_qos(io, &iso_qos)) {
+ g_io_channel_unref(io);
+ return;
}

- DBG("stream %p fd %d: BIG 0x%02x BIS 0x%02x", stream, fd,
- qos->bcast.big, qos->bcast.bis);
+ setup->qos.bcast.big = iso_qos.bcast.big;
+ setup->qos.bcast.bis = iso_qos.bcast.bis;
+ bt_bap_stream_config(setup->stream, &setup->qos, setup->caps,
+ NULL, NULL);
}
+
+ DBG("stream %p fd %d: BIG 0x%02x BIS 0x%02x", stream, fd,
+ setup->qos.bcast.big, setup->qos.bcast.bis);
}

static void bap_attached(struct bt_bap *bap, void *user_data)
@@ -2468,10 +2525,10 @@ static int bap_bcast_probe(struct btd_service *service)

data->ready_id = bt_bap_ready_register(data->bap, bap_ready, service,
NULL);
- data->state_id = bt_bap_state_register(data->bap, bap_state,
- bap_connecting, data, NULL);
+ data->state_id = bt_bap_state_register(data->bap, bap_state_bcast,
+ bap_connecting_bcast, data, NULL);
data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast,
- pac_removed_broadcast, data, NULL);
+ pac_removed_broadcast, data, NULL);

bt_bap_set_user_data(data->bap, service);

@@ -2623,8 +2680,8 @@ static int bap_adapter_probe(struct btd_profile *p,
return -EINVAL;
}

- data->state_id = bt_bap_state_register(data->bap, bap_state,
- bap_connecting, data, NULL);
+ data->state_id = bt_bap_state_register(data->bap, bap_state_bcast,
+ bap_connecting_bcast, data, NULL);
data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast,
pac_removed_broadcast, data, NULL);

--
2.39.2


Subject: [PATCH BlueZ v2 6/7] bap: Set generated BASE on all setups from the same BIG

Set the BASE generated in BlueZ on all setups from the same BIG,
and use defer to inform the kernel when to create the BIG.
---
profiles/audio/bap.c | 159 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 145 insertions(+), 14 deletions(-)

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index cf1c53b30..3a53873e5 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -926,6 +926,29 @@ static void setup_free(void *data)
free(setup);
}

+static void iterate_setup_update_base(void *data, void *user_data)
+{
+ struct bap_setup *setup = data;
+ struct bap_setup *data_setup = user_data;
+
+ if ((setup->stream != data_setup->stream) &&
+ (setup->qos.bcast.big == data_setup->qos.bcast.big)) {
+
+ if (setup->base)
+ util_iov_free(setup->base, 1);
+
+ setup->base = util_iov_dup(data_setup->base, 1);
+ }
+}
+
+static void iterate_endpoints(void *data, void *user_data)
+{
+ struct bap_ep *ep = data;
+ struct bap_setup *setup = user_data;
+
+ queue_foreach(ep->setups, iterate_setup_update_base, setup);
+}
+
static struct bap_ep *ep_register_bcast(struct bap_data *data,
struct bt_bap_pac *lpac,
struct bt_bap_pac *rpac);
@@ -984,7 +1007,6 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK)
setup->msg = dbus_message_ref(msg);
else {
- setup->base = bt_bap_stream_get_base(setup->stream);
setup->id = 0;
/* Create a new endpoint for a new BIS */
if (!ep_register_bcast(ep->data, ep->lpac, ep->rpac))
@@ -1858,7 +1880,7 @@ static void setup_connect_io(struct bap_data *data, struct bap_setup *setup,
static void setup_connect_io_broadcast(struct bap_data *data,
struct bap_setup *setup,
struct bt_bap_stream *stream,
- struct bt_iso_qos *qos)
+ struct bt_iso_qos *qos, int defer)
{
struct btd_adapter *adapter = data->user_data;
GIOChannel *io = NULL;
@@ -1895,7 +1917,7 @@ static void setup_connect_io_broadcast(struct bap_data *data,
BT_IO_OPT_MODE, BT_IO_MODE_ISO,
BT_IO_OPT_QOS, qos,
BT_IO_OPT_BASE, &base,
- BT_IO_OPT_DEFER_TIMEOUT, false,
+ BT_IO_OPT_DEFER_TIMEOUT, defer,
BT_IO_OPT_INVALID);

if (!io) {
@@ -2024,9 +2046,6 @@ static void setup_create_bcast_io(struct bap_data *data,

memset(&iso_qos, 0, sizeof(iso_qos));

- if (!defer)
- goto done;
-
iso_qos.bcast.big = setup->qos.bcast.big;
iso_qos.bcast.bis = setup->qos.bcast.bis;
iso_qos.bcast.sync_factor = setup->qos.bcast.sync_factor;
@@ -2043,9 +2062,10 @@ static void setup_create_bcast_io(struct bap_data *data,
iso_qos.bcast.timeout = setup->qos.bcast.timeout;
memcpy(&iso_qos.bcast.out, &setup->qos.bcast.io_qos,
sizeof(struct bt_iso_io_qos));
-done:
+
if (bt_bap_pac_get_type(setup->ep->lpac) == BT_BAP_BCAST_SOURCE)
- setup_connect_io_broadcast(data, setup, stream, &iso_qos);
+ setup_connect_io_broadcast(data, setup, stream, &iso_qos,
+ defer);
else
setup_listen_io_broadcast(data, setup, stream, &iso_qos);
}
@@ -2132,12 +2152,60 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
break;
}
}
+/*
+ * Function receives a list of streams ordered by BIS index
+ * and calls setup_create_io with defer true on all but the
+ * last one.
+ */
+static bool create_io_in_bis_order(struct bap_data *data,
+ struct queue *order_queue)
+{
+ const struct queue_entry *entry;
+ struct bt_bap_stream *stream;
+ struct bap_setup *setup;
+ bool defer = true;
+ uint8_t length = queue_length(order_queue);
+
+ for (entry = queue_get_entries(order_queue);
+ entry; entry = entry->next) {
+ stream = entry->data;
+ setup = bap_find_setup_by_stream(data, stream);
+
+ if (bt_bap_stream_get_qos(stream)->bcast.bis == length)
+ defer = false;
+
+ setup_create_io(data, setup, stream, defer);
+ if (!setup->io) {
+ error("Unable to create io");
+ goto fail;
+ }
+ }
+
+ return true;
+
+fail:
+ /* Clear the io of the created sockets if one
+ * socket creation fails.
+ */
+ for (entry = queue_get_entries(order_queue);
+ entry; entry = entry->next) {
+ stream = entry->data;
+ setup = bap_find_setup_by_stream(data, stream);
+
+ if (setup->io)
+ g_io_channel_unref(setup->io);
+ }
+
+ return false;
+}

static void bap_state_bcast(struct bt_bap_stream *stream, uint8_t old_state,
uint8_t new_state, void *user_data)
{
struct bap_data *data = user_data;
struct bap_setup *setup;
+ bool defer = false;
+ struct queue *order_queue = NULL;

DBG("stream %p: %s(%u) -> %s(%u)", stream,
bt_bap_stream_statestr(old_state), old_state,
@@ -2158,14 +2226,77 @@ static void bap_state_bcast(struct bt_bap_stream *stream, uint8_t old_state,
queue_remove(data->streams, stream);
break;
case BT_BAP_STREAM_STATE_CONFIG:
- if (setup && !setup->id) {
- setup_create_io(data, setup, stream, true);
+ if (!setup || setup->id)
+ break;
+ /* If the stream is attached to a
+ * broadcast sink endpoint.
+ */
+ if (bt_bap_stream_io_dir(stream) ==
+ BT_BAP_BCAST_SOURCE) {
+ setup_create_io(data, setup, stream, defer);
if (!setup->io) {
error("Unable to create io");
- if (old_state != BT_BAP_STREAM_STATE_RELEASING)
- bt_bap_stream_release(stream, NULL,
- NULL);
- return;
+ if (old_state !=
+ BT_BAP_STREAM_STATE_RELEASING)
+ bt_bap_stream_release(stream,
+ NULL, NULL);
+ }
+ } else {
+ /* If the stream attached to a broadcast
+ * source endpoint generate the base.
+ */
+ if (setup->base == NULL) {
+ setup->base = bt_bap_stream_get_base(
+ setup->stream);
+ /* Set the generated BASE on all setups
+ * from the same BIG.
+ */
+ queue_foreach(data->bcast,
+ iterate_endpoints, setup);
+ }
+ /* If there is only one BIS create the io
+ * with defer false
+ */
+ if (setup->qos.bcast.big == 0xFF) {
+ setup_create_io(data, setup,
+ stream, defer);
+ if (!setup->io) {
+ error("Unable to create io");
+ if (old_state !=
+ BT_BAP_STREAM_STATE_RELEASING)
+ bt_bap_stream_release(stream,
+ NULL, NULL);
+ }
+ } else {
+ /* The kernel has 2 requirements when handling
+ * multiple BIS connections for the same BIG:
+ * 1 - setup_create_io for all but the last BIS
+ * must be with defer true so we can inform the
+ * kernel when to start the BIG.
+ * 2 - The order in which the setup_create_io
+ * are called must be in the order of BIS
+ * indexes in BASE from first to last.
+ * To address this requirement we will call
+ * setup_create_io on all BISes only when all
+ * transport acquire have been received and will
+ * send it in the order of the BIS index
+ * from BASE.
+ */
+ order_queue = bt_bap_get_streams_by_state(
+ setup->stream,
+ BT_BAP_STREAM_STATE_CONFIG);
+ if (!order_queue)
+ break;
+
+ if (!create_io_in_bis_order(data,
+ order_queue)) {
+ if (old_state !=
+ BT_BAP_STREAM_STATE_RELEASING)
+ bt_bap_stream_release(stream,
+ NULL, NULL);
+ }
+
+ queue_destroy(order_queue, NULL);
}
}
break;
--
2.39.2


Subject: [PATCH BlueZ v2 7/7] shared/bap: Generate one BIS BASE for config BIG ID 0xFF

Generate single BIS BASE for a config with BIG ID 0xFF

---
src/shared/bap.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 2c5979b96..31f8f2ef4 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -6114,11 +6114,16 @@ struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream)
base.next_bis_index = 1;
base.big_id = stream->qos.bcast.big;

- /*
- * Create subgroups with each different Metadata and Codec
- * Specific Configuration from all streams having the same BIG ID.
+ /* If the BIG ID was explicitly set, create a BASE with information
+ * from all streams belonging to this BIG. Otherwise, create a BASE
+ * with only this BIS.
*/
- queue_foreach(stream->bap->streams, set_base_subgroup, &base);
+ if (stream->qos.bcast.big != 0xFF)
+ queue_foreach(stream->bap->streams, set_base_subgroup, &base);
+ else {
+ base.pres_delay = stream->qos.bcast.delay;
+ set_base_subgroup(stream, &base);
+ }

base_iov = generate_base(&base);

--
2.39.2


Subject: [PATCH BlueZ v2 2/7] shared/bap: Create multiple streams for the same pac

Broadcast source requires to create multiple streams for one pac.
This is required for multiple BISes support.
---
src/shared/bap.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index e26dbf944..f0ffdebfe 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -5156,7 +5156,7 @@ struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap,
struct iovec *data)
{
struct bt_bap_stream *stream;
- struct bt_bap_endpoint *ep;
+ struct bt_bap_endpoint *ep = NULL;
struct match_pac match;

if (!bap)
@@ -5212,12 +5212,32 @@ struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap,
match.lpac = lpac;
match.rpac = rpac;

- /* Check for existing stream */
- ep = queue_find(bap->remote_eps, find_ep_pacs, &match);
+ /* Broadcast source supports multiple endpoints (multiple BISes)
+ * for one pac so allow it to register a new endpoint even if
+ * others already exist.
+ */
+ if (lpac->type != BT_BAP_BCAST_SOURCE) {
+ /* Check for existing stream */
+ ep = queue_find(bap->remote_eps, find_ep_pacs, &match);
+ }
+
if (!ep) {
/* Check for unused ASE */
ep = queue_find(bap->remote_eps, find_ep_unused, &match);
- if (!ep) {
+ if (!ep && lpac->type == BT_BAP_BCAST_SOURCE) {
+ /* Push a new remote endpoint with direction
+ * broadcast source
+ */
+ ep = bap_endpoint_new_broadcast(bap->rdb,
+ BT_BAP_BCAST_SOURCE);
+
+ if (ep)
+ queue_push_tail(bap->remote_eps, ep);
+ else {
+ DBG(bap, "Unable to create endpoint");
+ return NULL;
+ }
+ } else if (!ep) {
DBG(bap, "Unable to find unused ASE");
return NULL;
}
--
2.39.2


Subject: [PATCH BlueZ v2 5/7] shared/bap: Check state of all streams with same BIG ID

The function is used to verify if all the streams from a BIG are in the
same state, and if so it returns a new queue with all these streams.
This queue will be used to iterate through all configured streams in order
of their creation, and create the IOs.

---
src/shared/bap.c | 37 +++++++++++++++++++++++++++++++++++++
src/shared/bap.h | 2 ++
2 files changed, 39 insertions(+)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index f0ffdebfe..2c5979b96 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -6126,3 +6126,40 @@ struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream)

return base_iov;
}
+
+/*
+ * Check the state of all streams with the same BIG ID.
+ * If all the streams are in the checked state, return
+ * a queue with this streams.
+ * Else, return NULL.
+ */
+struct queue *bt_bap_get_streams_by_state(struct bt_bap_stream *stream,
+ uint8_t test_state)
+{
+ const struct queue_entry *entry;
+ struct bt_bap_stream *e_str;
+ struct queue *return_queue = queue_new();
+
+ for (entry = queue_get_entries(stream->bap->streams);
+ entry; entry = entry->next) {
+ e_str = entry->data;
+
+ if ((e_str->lpac->type != BT_BAP_BCAST_SOURCE) ||
+ (e_str->qos.bcast.big != stream->qos.bcast.big))
+ continue;
+
+ if (e_str == stream) {
+ queue_push_tail(return_queue, e_str);
+ continue;
+ }
+
+ if (e_str->ep->state != test_state) {
+ queue_destroy(return_queue, NULL);
+ return NULL;
+ }
+
+ queue_push_tail(return_queue, e_str);
+ }
+
+ return return_queue;
+}
diff --git a/src/shared/bap.h b/src/shared/bap.h
index 2c3550921..ad6bf2d97 100644
--- a/src/shared/bap.h
+++ b/src/shared/bap.h
@@ -323,3 +323,5 @@ void bt_bap_update_bcast_source(struct bt_bap_pac *pac,
bool bt_bap_pac_bcast_is_local(struct bt_bap *bap, struct bt_bap_pac *pac);

struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream);
+struct queue *bt_bap_get_streams_by_state(struct bt_bap_stream *stream,
+ uint8_t test_state);
--
2.39.2


2024-02-12 17:40:40

by bluez.test.bot

[permalink] [raw]
Subject: RE: Add support for multiple BISes on the bcast source

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=825253

---Test result---

Test Summary:
CheckPatch PASS 2.12 seconds
GitLint PASS 1.38 seconds
BuildEll PASS 24.54 seconds
BluezMake PASS 725.68 seconds
MakeCheck PASS 11.46 seconds
MakeDistcheck PASS 162.50 seconds
CheckValgrind PASS 225.71 seconds
CheckSmatch PASS 327.98 seconds
bluezmakeextell PASS 106.55 seconds
IncrementalBuild PASS 4766.47 seconds
ScanBuild PASS 940.66 seconds



---
Regards,
Linux Bluetooth

2024-02-12 22:18:15

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ v2 2/7] shared/bap: Create multiple streams for the same pac

Hi Silviu,

On Mon, Feb 12, 2024 at 10:32 AM Silviu Florian Barbulescu
<[email protected]> wrote:
>
> Broadcast source requires to create multiple streams for one pac.
> This is required for multiple BISes support.
> ---
> src/shared/bap.c | 28 ++++++++++++++++++++++++----
> 1 file changed, 24 insertions(+), 4 deletions(-)
>
> diff --git a/src/shared/bap.c b/src/shared/bap.c
> index e26dbf944..f0ffdebfe 100644
> --- a/src/shared/bap.c
> +++ b/src/shared/bap.c
> @@ -5156,7 +5156,7 @@ struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap,
> struct iovec *data)
> {
> struct bt_bap_stream *stream;
> - struct bt_bap_endpoint *ep;
> + struct bt_bap_endpoint *ep = NULL;
> struct match_pac match;
>
> if (!bap)
> @@ -5212,12 +5212,32 @@ struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap,
> match.lpac = lpac;
> match.rpac = rpac;
>
> - /* Check for existing stream */
> - ep = queue_find(bap->remote_eps, find_ep_pacs, &match);
> + /* Broadcast source supports multiple endpoints (multiple BISes)
> + * for one pac so allow it to register a new endpoint even if
> + * others already exist.
> + */
> + if (lpac->type != BT_BAP_BCAST_SOURCE) {
> + /* Check for existing stream */
> + ep = queue_find(bap->remote_eps, find_ep_pacs, &match);
> + }
> +
> if (!ep) {
> /* Check for unused ASE */
> ep = queue_find(bap->remote_eps, find_ep_unused, &match);
> - if (!ep) {
> + if (!ep && lpac->type == BT_BAP_BCAST_SOURCE) {
> + /* Push a new remote endpoint with direction
> + * broadcast source
> + */
> + ep = bap_endpoint_new_broadcast(bap->rdb,
> + BT_BAP_BCAST_SOURCE);
> +
> + if (ep)
> + queue_push_tail(bap->remote_eps, ep);
> + else {
> + DBG(bap, "Unable to create endpoint");
> + return NULL;
> + }
> + } else if (!ep) {

Perhaps we need a dedicated callback from creating streams to avoid
having to add such checks everywhere, that said I don't quite
understand why we have Broadcast Source to find a remote endpoint, it
shall use a local one instead and perhaps have the ep struct support
multiple streams to be attached so we don't have to create dummy
endpoints just to be able to create new streams.

> DBG(bap, "Unable to find unused ASE");
> return NULL;
> }
> --
> 2.39.2
>


--
Luiz Augusto von Dentz