diff mbox series

[BlueZ,v2,2/3] bass: Create BASS session with Broadcasters

Message ID 20250227151756.33772-3-iulia.tanasescu@nxp.com
State New
Headers show
Series bass: Register bis probe/remove callbacks | expand

Commit Message

Iulia Tanasescu Feb. 27, 2025, 3:17 p.m. UTC
In the BASS plugin, BAP sessions created with scanned Broadcasters are
notified in the bap attached callback. This creates BASS data for these
devices as well, to internally keep information about the sessions.
---
 profiles/audio/bass.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
diff mbox series

Patch

diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index 67ee847b8..96e767744 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -137,6 +137,10 @@  static struct queue *delegators;
 
 static const char *state2str(enum assistant_state state);
 
+static struct bass_data *bass_data_new(struct btd_device *device);
+static void bass_data_add(struct bass_data *data);
+static void bass_data_remove(struct bass_data *data);
+
 static void bass_debug(const char *str, void *user_data)
 {
 	DBG_IDX(0xffff, "%s", str);
@@ -560,9 +564,11 @@  static void confirm_cb(GIOChannel *io, void *user_data)
 static void bap_attached(struct bt_bap *bap, void *user_data)
 {
 	struct btd_service *service;
+	struct btd_profile *p;
 	struct btd_device *device;
 	struct btd_adapter *adapter;
 	struct bass_delegator *dg;
+	struct bass_data *data;
 	GError *err = NULL;
 
 	DBG("%p", bap);
@@ -571,9 +577,22 @@  static void bap_attached(struct bt_bap *bap, void *user_data)
 	if (!service)
 		return;
 
+	p = btd_service_get_profile(service);
+	if (!p)
+		return;
+
+	/* Only handle sessions with Broadcast Sources */
+	if (!g_str_equal(p->remote_uuid, BCAAS_UUID_STR))
+		return;
+
 	device = btd_service_get_device(service);
 	adapter = device_get_adapter(device);
 
+	/* Create BASS session with the Broadcast Source */
+	data = bass_data_new(device);
+
+	bass_data_add(data);
+
 	dg = queue_find(delegators, delegator_match_device, device);
 	if (!dg)
 		/* Only probe devices added via Broadcast Assistants */
@@ -625,11 +644,21 @@  static void setup_free(void *data)
 	bt_bass_clear_bis_sync(setup->dg->src, setup->bis);
 }
 
+static bool match_device(const void *data, const void *match_data)
+{
+	const struct bass_data *bdata = data;
+	const struct btd_device *device = match_data;
+
+	return bdata->device == device;
+}
+
 static void bap_detached(struct bt_bap *bap, void *user_data)
 {
 	struct btd_service *service;
+	struct btd_profile *p;
 	struct btd_device *device;
 	struct bass_delegator *dg;
+	struct bass_data *data;
 
 	DBG("%p", bap);
 
@@ -637,8 +666,21 @@  static void bap_detached(struct bt_bap *bap, void *user_data)
 	if (!service)
 		return;
 
+	p = btd_service_get_profile(service);
+	if (!p)
+		return;
+
+	/* Only handle sessions with Broadcast Sources */
+	if (!g_str_equal(p->remote_uuid, BCAAS_UUID_STR))
+		return;
+
 	device = btd_service_get_device(service);
 
+	/* Remove BASS session with the Broadcast Source device */
+	data = queue_find(sessions, match_device, device);
+	if (data)
+		bass_data_remove(data);
+
 	dg = queue_remove_if(delegators, delegator_match_device, device);
 	if (!dg)
 		return;