bass: Register bis probe/remove callbacks
v2 cover bass: Register bis probe/remove callbacks
This removes the bass_add_stream and bass_remove_stream APIs and implements a method to register bis probe/remove callbacks with shared/bap, to avoid making direct plugin calls between BAP and BASS.
Iulia Tanasescu (3):
shared/bap: Add support to register bis callbacks
bass: Create BASS session with Broadcasters
bass: Register bis probe/remove callbacks
profiles/audio/bap.c | 6 +-- profiles/audio/bass.c | 62 +++++++++++++++++++++-- profiles/audio/bass.h | 5 -- src/shared/bap.c | 113 ++++++++++++++++++++++++++++++++++++++++++ src/shared/bap.h | 12 ++++- 5 files changed, 185 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/3 shared/bap: Add support to register bis callbacks
This adds support for registering BIS probe/remove calllbacks with shared/bap. This is needed by the BAP Broadcast Assistant (BASS Client) implementation, so that the BAP plugin can notify BISes discovered after parsing the BASE to BASS, avoiding direct function calls between plugins.
--- src/shared/bap.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/bap.h | 12 ++++- 2 files changed, 124 insertions(+), 1 deletion(-)
src/shared/bap.c +113 -0
@@ -80,6 +80,14 @@ struct bt_bap_state {void *data; }; +struct bt_bap_bis_cb { +unsigned int id; +bt_bap_bis_func_t probe; +bt_bap_func_t remove; +bt_bap_destroy_func_t destroy; +void *data; +}; +struct bt_bap_cb {unsigned int id;bt_bap_func_t attached;
@@ -180,6 +188,7 @@ struct bt_bap {struct queue *pac_cbs;struct queue *ready_cbs;struct queue *state_cbs; +struct queue *bis_cbs;bt_bap_debug_func_t debug_func;bt_bap_destroy_func_t debug_destroy;
@@ -4190,6 +4199,16 @@ static void bap_state_free(void *data)free (state); } +static void bap_bis_cb_free (void *data) +{ +struct bt_bap_bis_cb *bis_cb = data; + +if (bis_cb->destroy) + bis_cb->destroy (bis_cb->data); + +free (bis_cb); +} +static void bap_ep_free (void *data) {struct bt_bap_endpoint *ep = data;
@@ -4228,6 +4247,7 @@ static void bap_free(void *data)queue_destroy (bap->pac_cbs, pac_changed_free);queue_destroy (bap->ready_cbs, bap_ready_free);queue_destroy (bap->state_cbs, bap_state_free); +queue_destroy (bap->bis_cbs, bap_bis_cb_free);queue_destroy (bap->local_eps, free);queue_destroy (bap->remote_eps, bap_ep_free);
@@ -4310,6 +4330,7 @@ struct bt_bap *bt_bap_new(struct gatt_db *ldb, struct gatt_db *rdb) bap->ready_cbs =queue_new (); bap->streams =queue_new (); bap->state_cbs =queue_new (); + bap->bis_cbs =queue_new (); bap->local_eps =queue_new ();if (!rdb)
@@ -5519,6 +5540,98 @@ bool bt_bap_state_unregister(struct bt_bap *bap, unsigned int id)return false; } +unsigned int bt_bap_bis_cb_register (struct bt_bap *bap, +bt_bap_bis_func_t probe, +bt_bap_func_t remove, +void *user_data, +bt_bap_destroy_func_t destroy) +{ +struct bt_bap_bis_cb *bis_cb; +static unsigned int id; + +if (!bap) +return 0 ; + + bis_cb = new0(struct bt_bap_bis_cb, 1); + bis_cb->id = ++id ? id : ++id; + bis_cb->probe = probe; + bis_cb->remove = remove; + bis_cb->destroy = destroy; + bis_cb->data = user_data; + +queue_push_tail (bap->bis_cbs, bis_cb); + +return bis_cb->id; +} + +static bool match_bis_cb_id (const void *data,const void *match_data) +{ +const struct bt_bap_bis_cb *bis_cb = data; +unsigned int id =PTR_TO_UINT (match_data); + +return (bis_cb->id == id); +} + +bool bt_bap_bis_cb_unregister (struct bt_bap *bap,unsigned int id) +{ +struct bt_bap_bis_cb *bis_cb; + +if (!bap) +return false; + + bis_cb =queue_remove_if (bap->bis_cbs, match_bis_cb_id, +UINT_TO_PTR (id)); +if (!bis_cb) +return false; + +bap_bis_cb_free (bis_cb); + +return false; +} + +void bt_bap_bis_probe (struct bt_bap *bap,uint8_t bis,uint8_t sgrp, +struct iovec *caps,struct iovec *meta,struct bt_bap_qos *qos) +{ +const struct queue_entry *entry; + +if (!bt_bap_ref_safe (bap)) +return ; + + entry =queue_get_entries (bap->bis_cbs); + +while (entry) { +struct bt_bap_bis_cb *cb = entry->data; + + entry = entry->next; + +if (cb->probe) + cb->probe (bis, sgrp, caps, meta, qos, cb->data); + } + +bt_bap_unref (bap); +} + +void bt_bap_bis_remove (struct bt_bap *bap) +{ +const struct queue_entry *entry; + +if (!bt_bap_ref_safe (bap)) +return ; + + entry =queue_get_entries (bap->bis_cbs); + +while (entry) { +struct bt_bap_bis_cb *cb = entry->data; + + entry = entry->next; + +if (cb->remove) + cb->remove (bap, cb->data); + } + +bt_bap_unref (bap); +} +const char *bt_bap_stream_statestr (uint8_t state) {switch (state) {
src/shared/bap.h +11 -1
@@ -4,7 +4,7 @@* BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2022 Intel Corporation. All rights reserved. -* Copyright 2023-2024 NXP +* Copyright 2023-2025 NXP * */
@@ -269,3 +269,13 @@ bool bt_bap_parse_base(struct iovec *base,bt_bap_bis_func_t handler, void *user_data); +unsigned int bt_bap_bis_cb_register (struct bt_bap *bap, +bt_bap_bis_func_t probe, +bt_bap_func_t remove, +void *user_data, +bt_bap_destroy_func_t destroy); +bool bt_bap_bis_cb_unregister (struct bt_bap *bap,unsigned int id); + +void bt_bap_bis_probe (struct bt_bap *bap,uint8_t bis,uint8_t sgrp, +struct iovec *caps,struct iovec *meta,struct bt_bap_qos *qos); +void bt_bap_bis_remove (struct bt_bap *bap);
Signature · 1 line
2.43.0
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=938583
---Test result---
Test Summary:
CheckPatch PENDING 0.25 seconds GitLint PENDING 0.26 seconds BuildEll PASS 20.50 seconds BluezMake PASS 1466.21 seconds MakeCheck PASS 13.22 seconds MakeDistcheck PASS 161.59 seconds CheckValgrind PASS 215.91 seconds CheckSmatch WARNING 284.21 seconds bluezmakeextell PASS 97.36 seconds IncrementalBuild PENDING 0.33 seconds ScanBuild PASS 854.38 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:src/shared/bap.c:305:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:305:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:305:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structures
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:
---
Regards,
Linux Bluetooth
PATCH v2 2/3 bass: Create BASS session with Broadcasters
In reply to Iulia TanasescuIn 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(+)
profiles/audio/bass.c +42 -0
@@ -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 ;
Signature · 1 line
2.43.0
PATCH v2 3/3 bass: Register bis probe/remove callbacks
In reply to Iulia TanasescuThis removes the BASS add/remove stream APIs and uses shared/bap to register BIS probe/remove callbacks instead, to avoid making direct calls between plugins.
--- profiles/audio/bap.c | 6 +++--- profiles/audio/bass.c | 22 +++++++++++++++++----- profiles/audio/bass.h | 5 ----- 3 files changed, 20 insertions(+), 13 deletions(-)
profiles/audio/bap.c +3 -3
@@ -1178,7 +1178,7 @@ static void bis_handler(uint8_t bis, uint8_t sgrp, struct iovec *caps,struct bt_bap_pac *lpac;char *path; -bass_add_stream (data->device, meta, caps, qos, sgrp, bis); +bt_bap_bis_probe (data->bap, bis, sgrp, caps, meta, qos);/* Check if this BIS matches any local PAC */ bt_bap_verify_bis(data->bap, bis,
@@ -3128,9 +3128,9 @@ static void bap_bcast_remove(struct btd_service *service)return ; } -bap_data_remove (data); +bt_bap_bis_remove (data->bap); -bass_remove_stream (device); +bap_data_remove (data); }static int bap_probe (struct btd_service *service)
profiles/audio/bass.c +17 -5
@@ -86,6 +86,7 @@ struct bass_data {struct bt_bass *bass;unsigned int src_id;unsigned int cp_id; +unsigned int bis_id; };struct bass_assistant {
@@ -141,6 +142,11 @@ 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 bis_probe (uint8_t bis,uint8_t sgrp,struct iovec *caps, +struct iovec *meta,struct bt_bap_qos *qos,void *user_data); +static void bis_remove (struct bt_bap *bap,void *user_data); + +static void bass_debug (const char *str,void *user_data) {DBG_IDX (0xffff ,"%s" , str);
@@ -590,6 +596,8 @@ static void bap_attached(struct bt_bap *bap, void *user_data)/* Create BASS session with the Broadcast Source */ data =bass_data_new (device); + data->bis_id =bt_bap_bis_cb_register (bap, bis_probe, + bis_remove, device,NULL );bass_data_add (data);
@@ -678,8 +686,10 @@ static void bap_detached(struct bt_bap *bap, void *user_data)/* Remove BASS session with the Broadcast Source device */ data =queue_find (sessions, match_device, device); -if (data) +if (data) { +bt_bap_bis_cb_unregister (bap, data->bis_id);bass_data_remove (data); + } dg =queue_remove_if (delegators, delegator_match_device, device);if (!dg)
@@ -1077,10 +1087,10 @@ static struct bass_assistant *assistant_new(struct btd_adapter *adapter,return assistant; } -void bass_add_stream (struct btd_device *device,struct iovec *meta, -struct iovec *caps,struct bt_bap_qos *qos, -uint8_t sgrp,uint8_t bis) +static void bis_probe (uint8_t bis,uint8_t sgrp,struct iovec *caps, +struct iovec *meta,struct bt_bap_qos *qos,void *user_data) { +struct btd_device *device = user_data;const struct queue_entry *entry;struct bt_bap *bap;struct bt_bap_pac *pac;
@@ -1142,8 +1152,10 @@ static void unregister_assistant(void *data) assistant->path, MEDIA_ASSISTANT_INTERFACE); } -void bass_remove_stream (struct btd_device *device) +static void bis_remove (struct bt_bap *bap,void *user_data) { +struct btd_device *device = user_data; +queue_remove_all (assistants, assistant_match_device, device, unregister_assistant); }
profiles/audio/bass.h +0 -5
@@ -7,11 +7,6 @@* */ -void bass_add_stream (struct btd_device *device,struct iovec *meta, -struct iovec *caps,struct bt_bap_qos *qos, -uint8_t sgrp,uint8_t bis); -void bass_remove_stream (struct btd_device *device); -typedef void (*bt_bass_bcode_func_t )(void *user_data,int err); void bass_req_bcode(struct bt_bap_stream *stream,
Signature · 1 line
2.43.0
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 11 lines · On Thu, 27 Feb 2025 17:17:53 +0200 you wrote:
This removes the
bass_add_streamandbass_remove_streamAPIs and implements a method to register bis probe/remove callbacks with shared/bap, to avoid making direct plugin calls between BAP and BASS.Iulia Tanasescu (3):
shared/bap: Add support to register bis callbacks
bass: Create BASS session with Broadcasters
bass: Register bis probe/remove callbacks[...]
Here is the summary with links:
- [BlueZ,v2,1/3] shared/bap: Add support to register bis callbacks
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=4b4c9383d58a - [BlueZ,v2,2/3] bass: Create BASS session with Broadcasters https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f49953d96fab - [BlueZ,v2,3/3] bass: Register bis probe/remove callbacks https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d68dc1fd03bc
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html