Bluetooth: BAP: Add broadcast sink callback structs
These callbacks are trigger for changes that affect the entire broadcast sink, such as the BIG synced and terminated events. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
0ae976166f
commit
829519dd6f
3 changed files with 147 additions and 38 deletions
|
@ -48,6 +48,7 @@ CREATE_FLAG(flag_pa_sync_lost);
|
|||
CREATE_FLAG(flag_pa_request);
|
||||
CREATE_FLAG(flag_bis_sync_requested);
|
||||
CREATE_FLAG(flag_big_sync_mic_failure);
|
||||
CREATE_FLAG(flag_sink_started);
|
||||
|
||||
static struct bt_bap_broadcast_sink *g_sink;
|
||||
static struct bt_le_scan_recv_info broadcaster_info;
|
||||
|
@ -80,8 +81,8 @@ static const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
|
|||
SUPPORTED_MIN_OCTETS_PER_FRAME, SUPPORTED_MAX_OCTETS_PER_FRAME,
|
||||
SUPPORTED_MAX_FRAMES_PER_SDU, SUPPORTED_CONTEXTS);
|
||||
|
||||
static K_SEM_DEFINE(sem_started, 0U, ARRAY_SIZE(streams));
|
||||
static K_SEM_DEFINE(sem_stopped, 0U, ARRAY_SIZE(streams));
|
||||
static K_SEM_DEFINE(sem_stream_started, 0U, ARRAY_SIZE(streams));
|
||||
static K_SEM_DEFINE(sem_stream_stopped, 0U, ARRAY_SIZE(streams));
|
||||
|
||||
/* Create a mask for the maximum BIS we can sync to using the number of streams
|
||||
* we have. We add an additional 1 since the bis indexes start from 1 and not
|
||||
|
@ -257,9 +258,27 @@ static void syncable_cb(struct bt_bap_broadcast_sink *sink, const struct bt_iso_
|
|||
SET_FLAG(flag_syncable);
|
||||
}
|
||||
|
||||
static void broadcast_sink_started_cb(struct bt_bap_broadcast_sink *sink)
|
||||
{
|
||||
printk("Broadcast sink %p started\n", sink);
|
||||
SET_FLAG(flag_sink_started);
|
||||
}
|
||||
|
||||
static void broadcast_sink_stopped_cb(struct bt_bap_broadcast_sink *sink, uint8_t reason)
|
||||
{
|
||||
printk("Broadcast sink %p stopped with reason 0x%02X\n", sink, reason);
|
||||
UNSET_FLAG(flag_sink_started);
|
||||
|
||||
if (reason == BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL) {
|
||||
SET_FLAG(flag_big_sync_mic_failure);
|
||||
}
|
||||
}
|
||||
|
||||
static struct bt_bap_broadcast_sink_cb broadcast_sink_cbs = {
|
||||
.base_recv = base_recv_cb,
|
||||
.syncable = syncable_cb,
|
||||
.started = broadcast_sink_started_cb,
|
||||
.stopped = broadcast_sink_stopped_cb,
|
||||
};
|
||||
|
||||
static bool scan_check_and_sync_broadcast(struct bt_data *data, void *user_data)
|
||||
|
@ -526,7 +545,7 @@ static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
|
|||
}
|
||||
}
|
||||
|
||||
static void started_cb(struct bt_bap_stream *stream)
|
||||
static void stream_started_cb(struct bt_bap_stream *stream)
|
||||
{
|
||||
struct audio_test_stream *test_stream = audio_test_stream_from_bap_stream(stream);
|
||||
struct bt_bap_ep_info info;
|
||||
|
@ -567,24 +586,20 @@ static void started_cb(struct bt_bap_stream *stream)
|
|||
}
|
||||
|
||||
printk("Stream %p started\n", stream);
|
||||
k_sem_give(&sem_started);
|
||||
k_sem_give(&sem_stream_started);
|
||||
|
||||
validate_stream_codec_cfg(stream);
|
||||
}
|
||||
|
||||
static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
|
||||
static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
|
||||
{
|
||||
printk("Stream %p stopped with reason 0x%02X\n", stream, reason);
|
||||
k_sem_give(&sem_stopped);
|
||||
|
||||
if (reason == BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL) {
|
||||
SET_FLAG(flag_big_sync_mic_failure);
|
||||
}
|
||||
k_sem_give(&sem_stream_stopped);
|
||||
}
|
||||
|
||||
static struct bt_bap_stream_ops stream_ops = {
|
||||
.started = started_cb,
|
||||
.stopped = stopped_cb,
|
||||
.started = stream_started_cb,
|
||||
.stopped = stream_stopped_cb,
|
||||
.recv = bap_stream_rx_recv_cb,
|
||||
};
|
||||
|
||||
|
@ -707,6 +722,8 @@ static void test_broadcast_sink_create(void)
|
|||
FAIL("Unable to create the sink: %d\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Created broadcast sink %p\n", g_sink);
|
||||
}
|
||||
|
||||
static void test_broadcast_sink_create_inval(void)
|
||||
|
@ -736,7 +753,7 @@ static void test_broadcast_sync(const uint8_t broadcast_code[BT_ISO_BROADCAST_CO
|
|||
{
|
||||
int err;
|
||||
|
||||
printk("Syncing the sink\n");
|
||||
printk("Syncing sink %p\n", g_sink);
|
||||
err = bt_bap_broadcast_sink_sync(g_sink, bis_index_bitfield, streams, broadcast_code);
|
||||
if (err != 0) {
|
||||
FAIL("Unable to sync the sink: %d\n", err);
|
||||
|
@ -808,16 +825,20 @@ static void test_broadcast_stop(void)
|
|||
{
|
||||
int err;
|
||||
|
||||
printk("Stopping broadcast sink %p\n", g_sink);
|
||||
|
||||
err = bt_bap_broadcast_sink_stop(g_sink);
|
||||
if (err != 0) {
|
||||
FAIL("Unable to stop sink: %d", err);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Waiting for streams to be stopped\n");
|
||||
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams));
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
|
||||
k_sem_take(&sem_stopped, K_FOREVER);
|
||||
k_sem_take(&sem_stream_stopped, K_FOREVER);
|
||||
}
|
||||
|
||||
WAIT_FOR_UNSET_FLAG(flag_sink_started);
|
||||
}
|
||||
|
||||
static void test_broadcast_stop_inval(void)
|
||||
|
@ -914,10 +935,12 @@ static void test_common(void)
|
|||
test_broadcast_sync_inval();
|
||||
test_broadcast_sync(NULL);
|
||||
|
||||
WAIT_FOR_FLAG(flag_sink_started);
|
||||
|
||||
/* Wait for all to be started */
|
||||
printk("Waiting for streams to be started\n");
|
||||
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams));
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
|
||||
k_sem_take(&sem_started, K_FOREVER);
|
||||
k_sem_take(&sem_stream_started, K_FOREVER);
|
||||
}
|
||||
|
||||
printk("Waiting for data\n");
|
||||
|
@ -944,10 +967,11 @@ static void test_main(void)
|
|||
printk("Waiting for PA disconnected\n");
|
||||
WAIT_FOR_FLAG(flag_pa_sync_lost);
|
||||
|
||||
printk("Waiting for streams to be stopped\n");
|
||||
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams));
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
|
||||
k_sem_take(&sem_stopped, K_FOREVER);
|
||||
k_sem_take(&sem_stream_stopped, K_FOREVER);
|
||||
}
|
||||
WAIT_FOR_UNSET_FLAG(flag_sink_started);
|
||||
|
||||
PASS("Broadcast sink passed\n");
|
||||
}
|
||||
|
@ -962,10 +986,12 @@ static void test_sink_disconnect(void)
|
|||
/* Retry sync*/
|
||||
test_broadcast_sync(NULL);
|
||||
|
||||
WAIT_FOR_FLAG(flag_sink_started);
|
||||
|
||||
/* Wait for all to be started */
|
||||
printk("Waiting for streams to be started\n");
|
||||
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams));
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
|
||||
k_sem_take(&sem_started, K_FOREVER);
|
||||
k_sem_take(&sem_stream_started, K_FOREVER);
|
||||
}
|
||||
|
||||
test_broadcast_stop();
|
||||
|
@ -1001,10 +1027,12 @@ static void test_sink_encrypted(void)
|
|||
|
||||
test_broadcast_sync(BROADCAST_CODE);
|
||||
|
||||
WAIT_FOR_FLAG(flag_sink_started);
|
||||
|
||||
/* Wait for all to be started */
|
||||
printk("Waiting for streams to be started\n");
|
||||
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams));
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
|
||||
k_sem_take(&sem_started, K_FOREVER);
|
||||
k_sem_take(&sem_stream_started, K_FOREVER);
|
||||
}
|
||||
|
||||
printk("Waiting for data\n");
|
||||
|
@ -1021,9 +1049,9 @@ static void test_sink_encrypted(void)
|
|||
printk("Waiting for PA disconnected\n");
|
||||
WAIT_FOR_FLAG(flag_pa_sync_lost);
|
||||
|
||||
printk("Waiting for streams to be stopped\n");
|
||||
printk("Waiting for %zu streams to be stopped\n", ARRAY_SIZE(streams));
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
|
||||
k_sem_take(&sem_stopped, K_FOREVER);
|
||||
k_sem_take(&sem_stream_stopped, K_FOREVER);
|
||||
}
|
||||
|
||||
PASS("Broadcast sink encrypted passed\n");
|
||||
|
@ -1090,10 +1118,12 @@ static void broadcast_sink_with_assistant(void)
|
|||
WAIT_FOR_FLAG(flag_bis_sync_requested);
|
||||
test_broadcast_sync(NULL);
|
||||
|
||||
WAIT_FOR_FLAG(flag_sink_started);
|
||||
|
||||
/* Wait for all to be started */
|
||||
printk("Waiting for streams to be started\n");
|
||||
printk("Waiting for %zu streams to be started\n", ARRAY_SIZE(streams));
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(streams); i++) {
|
||||
k_sem_take(&sem_started, K_FOREVER);
|
||||
k_sem_take(&sem_stream_started, K_FOREVER);
|
||||
}
|
||||
|
||||
printk("Waiting for data\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue