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 Nov 10, 2023
1 parent c99f7ec commit a2f9362
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 31 deletions.
28 changes: 28 additions & 0 deletions include/zephyr/bluetooth/audio/bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,25 @@ 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 @@ -1665,6 +1684,15 @@ int bt_bap_broadcast_sink_stop(struct bt_bap_broadcast_sink *sink);
*/
int bt_bap_broadcast_sink_delete(struct bt_bap_broadcast_sink *sink);

/**
* @brief Find a broadcast sink by its BASS Source ID
*
* @param src_id which comes from of the @ref bt_bap_scan_delegator_recv_state
*
* @return Pointer to the broadcast sink found
*/
struct bt_bap_broadcast_sink *bt_bap_broadcast_sink_get_by_src_id(uint8_t src_id);

/** @} */ /* End of group bt_bap_broadcast_sink */

/**
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
11 changes: 11 additions & 0 deletions subsys/bluetooth/audio/bap_broadcast_sink.c
Original file line number Diff line number Diff line change
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_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];
}
}

return NULL;
}

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

0 comments on commit a2f9362

Please sign in to comment.