diff mbox series

[BlueZ,4/6] bass: Create setups for all BISes in BASE

Message ID 20241220143106.27443-5-iulia.tanasescu@nxp.com
State New
Headers show
Series bass: Handle Modify Source opcode | expand

Commit Message

Iulia Tanasescu Dec. 20, 2024, 2:31 p.m. UTC
A BAP Scan Delegator (BASS Server) might be instructed by BAP Broadcast
Assistants (BASS Clients) to change sync between streams, via the Modify
Source operation. A Scan Delegator should create setups for all BISes
discovered in the BASE of a Broadcast Source, and create associated
streams based on Add Source/Modify Source commands received from
Assistants.
---
 profiles/audio/bass.c | 49 +++++++++++++++++++++++++++----------------
 1 file changed, 31 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index 21f708ba6..2984d7697 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -118,9 +118,11 @@  struct bass_delegator {
 struct bass_setup {
 	struct bass_delegator *dg;
 	struct bt_bap_stream *stream;
+	uint8_t bis;
 	struct bt_bap_qos qos;
 	struct iovec *meta;
 	struct iovec *config;
+	struct bt_bap_pac *lpac;
 };
 
 struct bass_bcode_req {
@@ -376,31 +378,47 @@  static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
 	}
 }
 
+static void setup_configure_stream(struct bass_setup *setup)
+{
+	char *path;
+
+	setup->stream = bt_bap_stream_new(setup->dg->bap, setup->lpac, NULL,
+					&setup->qos, setup->config);
+	if (!setup->stream)
+		return;
+
+	if (asprintf(&path, "%s/bis%d",
+			device_get_path(setup->dg->device),
+			setup->bis) < 0)
+		return;
+
+	bt_bap_stream_set_user_data(setup->stream, path);
+
+	bt_bap_stream_config(setup->stream, &setup->qos,
+			setup->config, NULL, NULL);
+	bt_bap_stream_metadata(setup->stream, setup->meta,
+			NULL, NULL);
+}
+
 static void bis_handler(uint8_t bis, uint8_t sgrp, struct iovec *caps,
 	struct iovec *meta, struct bt_bap_qos *qos, void *user_data)
 {
 	struct bass_delegator *dg = user_data;
 	struct bt_bap_pac *lpac;
-	char *path;
 	struct bass_setup *setup;
 
-	/* Only handle streams required by the Brodcast Assistant. */
-	if (!bt_bass_check_bis(dg->src, bis))
-		return;
-
 	/* Check if this stream caps match any local PAC */
 	bt_bap_verify_bis(dg->bap, bis, caps, &lpac);
 	if (!lpac)
 		return;
 
-	if (asprintf(&path, "%s/bis%d", device_get_path(dg->device), bis) < 0)
-		return;
-
 	setup = new0(struct bass_setup, 1);
 	if (!setup)
 		return;
 
 	setup->dg = dg;
+	setup->bis = bis;
+	setup->lpac = lpac;
 
 	setup->qos = *qos;
 	setup->qos.bcast.bcode = util_iov_dup(qos->bcast.bcode, 1);
@@ -408,18 +426,13 @@  static void bis_handler(uint8_t bis, uint8_t sgrp, struct iovec *caps,
 	setup->meta = util_iov_dup(meta, 1);
 	setup->config = util_iov_dup(caps, 1);
 
-	setup->stream = bt_bap_stream_new(dg->bap, lpac, NULL,
-					&setup->qos, setup->config);
-	if (!setup->stream)
-		return;
+	queue_push_tail(setup->dg->setups, setup);
 
-	queue_push_tail(dg->setups, setup);
+	/* Only handle streams required by the Brodcast Assistant. */
+	if (!bt_bass_check_bis(dg->src, bis))
+		return;
 
-	bt_bap_stream_set_user_data(setup->stream, path);
-	bt_bap_stream_config(setup->stream, &setup->qos,
-			setup->config, NULL, NULL);
-	bt_bap_stream_metadata(setup->stream, setup->meta,
-			NULL, NULL);
+	setup_configure_stream(setup);
 }
 
 static gboolean big_info_cb(GIOChannel *io, GIOCondition cond,