Skip to content

Commit

Permalink
Bluetooth: BAP: Overwrite Receive State in the Scan Delegator
Browse files Browse the repository at this point in the history
Kconfig option BT_BAP_SCAN_DELEGATOR_OVERWRITE_OLDEST
allows the Scan Delegator to overwrite the oldest inactive
receive state if there aren't any free receive states.

A inactive receive state is a receive state that has neither a
Periodic Advertising or Broadcast Isochronous Group (BIG) sync.

There is also a recv_state_add_fail callback function added
which can notify an application if all receive states
are not inactive and can't be freed.

Signed-off-by: Paul Mulligan <[email protected]>
  • Loading branch information
pmullt committed Oct 18, 2023
1 parent c99f7ec commit 76083d7
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 33 deletions.
29 changes: 29 additions & 0 deletions include/zephyr/bluetooth/audio/bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,26 @@ struct bt_bap_scan_delegator_recv_state {
};

struct bt_bap_scan_delegator_cb {

/**
* @brief Attempt to add a new source to a receive state failed
*
* An attempt to add a new broadcast source to a receive state
* failed.
*
* @param conn Pointer to the connection to a remote device if
* the change was caused by it, otherwise NULL.
* @param state_info Pointer to the receive state that was
* attempted to be added.
* @param err errno explaining why adding the source failed
*
* return true if operation was successful, or false if unsuccessful
*
*/
bool (*recv_state_add_failed)(struct bt_conn *conn,
const struct bt_bap_scan_delegator_recv_state *state_info,
int err);

/**
* @brief Receive state updated
*
Expand Down Expand Up @@ -1817,6 +1837,15 @@ void bt_bap_scan_delegator_foreach_state(bt_bap_scan_delegator_state_func_t func
const struct bt_bap_scan_delegator_recv_state *bt_bap_scan_delegator_find_state(
bt_bap_scan_delegator_state_func_t func, void *user_data);

/**
* @brief Find a broadcast sink by its BASS Source ID
*
* @param bass_src_id
*
* @return Pointer to the broadcast sink found
*/
struct bt_bap_broadcast_sink *bt_bap_broadcast_sink_get_by_bass_src_id(uint8_t bass_src_id);

/******************************** CLIENT API ********************************/

/**
Expand Down
2 changes: 2 additions & 0 deletions samples/bluetooth/broadcast_audio_sink/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ CONFIG_BT_ISO_MAX_CHAN=2
CONFIG_BT_BAP_BROADCAST_SNK_SUBGROUP_COUNT=2
CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT=2
CONFIG_BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS=2
CONFIG_BT_BAP_SCAN_DELEGATOR_OVERWRITE_OLDEST=y

CONFIG_BT_DEVICE_NAME="Broadcast Audio Sink"

8 changes: 8 additions & 0 deletions subsys/bluetooth/audio/Kconfig.bap
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ config BT_BAP_SCAN_DELEGATOR_MAX_SUBGROUPS
help
The maximum number of BIS subgroups supported.

config BT_BAP_SCAN_DELEGATOR_OVERWRITE_OLDEST
bool "Overwrite oldest inactive receive state"
help
If enabled, if there are no available free receive states,
the oldest inactive receive state will be overwritten. An
inactive receive state is a receive state that has neither a
Periodic Advertising or Broadcast Isochronous Group (BIG) sync.

endif # BT_BAP_SCAN_DELEGATOR

config BT_BAP_BROADCAST_ASSISTANT
Expand Down
13 changes: 12 additions & 1 deletion subsys/bluetooth/audio/bap_broadcast_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ static struct bt_bap_broadcast_sink *broadcast_sink_get_by_pa(struct bt_le_per_a

static void broadcast_sink_add_src(struct bt_bap_broadcast_sink *sink)
{
struct bt_bap_scan_delegator_add_src_param add_src_param;
struct bt_bap_scan_delegator_add_src_param add_src_param = {0};
int err;

add_src_param.pa_sync = sink->pa_sync;
Expand Down Expand Up @@ -1116,6 +1116,17 @@ int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink)
return 0;
}

struct bt_bap_broadcast_sink *bt_bap_broadcast_sink_get_by_bass_src_id(uint8_t bass_src_id)
{
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_sinks); i++) {
if (broadcast_sinks[i].bass_src_id == bass_src_id) {
return &broadcast_sinks[i];
}
}

Check warning on line 1125 in subsys/bluetooth/audio/bap_broadcast_sink.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SUSPECT_CODE_INDENT

subsys/bluetooth/audio/bap_broadcast_sink.c:1125 suspect code indent for conditional statements (16, 16)

return NULL;
}

static int broadcast_sink_init(void)
{
static struct bt_le_per_adv_sync_cb cb = {
Expand Down
Loading

0 comments on commit 76083d7

Please sign in to comment.