Skip to content

Commit 6ecc6c3

Browse files
Thalleycarlescufi
authored andcommitted
tests: Bluetooth: Audio: Add start stream to unicast tests
Add support for starting streams as the unicast client, which will connect the CISes. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 9a2997f commit 6ecc6c3

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

tests/bluetooth/bsim/audio/src/unicast_client_test.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CREATE_FLAG(flag_sink_discovered);
2929
CREATE_FLAG(flag_stream_codec_configured);
3030
static atomic_t flag_stream_qos_configured;
3131
CREATE_FLAG(flag_stream_enabled);
32+
CREATE_FLAG(flag_stream_started);
3233
CREATE_FLAG(flag_stream_released);
3334

3435
static void stream_configured(struct bt_audio_stream *stream,
@@ -60,6 +61,8 @@ static void stream_enabled(struct bt_audio_stream *stream)
6061
static void stream_started(struct bt_audio_stream *stream)
6162
{
6263
printk("Started stream %p\n", stream);
64+
65+
SET_FLAG(flag_stream_started);
6366
}
6467

6568
static void stream_metadata_updated(struct bt_audio_stream *stream)
@@ -360,6 +363,39 @@ static void enable_streams(size_t stream_cnt)
360363
}
361364
}
362365

366+
static int start_stream(struct bt_audio_stream *stream)
367+
{
368+
int err;
369+
370+
UNSET_FLAG(flag_stream_started);
371+
372+
err = bt_audio_stream_start(stream);
373+
if (err != 0) {
374+
FAIL("Could not start stream: %d\n", err);
375+
376+
return err;
377+
}
378+
379+
WAIT_FOR_FLAG(flag_stream_started);
380+
381+
return 0;
382+
}
383+
384+
static void start_streams(size_t stream_cnt)
385+
{
386+
for (size_t i = 0U; i < 1; i++) {
387+
struct bt_audio_stream *stream = &g_streams[i];
388+
int err;
389+
390+
err = start_stream(stream);
391+
if (err != 0) {
392+
FAIL("Unable to start stream[%zu]: %d", i, err);
393+
394+
return;
395+
}
396+
}
397+
}
398+
363399
static size_t release_streams(size_t stream_cnt)
364400
{
365401
for (size_t i = 0; i < stream_cnt; i++) {
@@ -472,8 +508,10 @@ static void test_main(void)
472508
printk("Enabling streams\n");
473509
enable_streams(stream_cnt);
474510

475-
/* TODO: When babblesim supports CIS connection start Audio streams */
511+
printk("Starting streams\n");
512+
start_streams(stream_cnt);
476513

514+
printk("Releasing streams\n");
477515
release_streams(stream_cnt);
478516

479517
/* Test removing streams from group after creation */

tests/bluetooth/bsim/audio/src/unicast_server_test.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,30 @@ static const struct bt_audio_unicast_server_cb unicast_server_cb = {
210210
.release = lc3_release,
211211
};
212212

213+
static void stream_enabled_cb(struct bt_audio_stream *stream)
214+
{
215+
struct bt_audio_ep_info ep_info;
216+
int err;
217+
218+
printk("Enabled: stream %p\n", stream);
219+
220+
err = bt_audio_ep_get_info(stream->ep, &ep_info);
221+
if (err != 0) {
222+
FAIL("Failed to get ep info: %d\n", err);
223+
return;
224+
}
225+
226+
if (ep_info.dir == BT_AUDIO_DIR_SINK) {
227+
/* Automatically do the receiver start ready operation */
228+
err = bt_audio_stream_start(stream);
229+
230+
if (err != 0) {
231+
FAIL("Failed to start stream: %d\n", err);
232+
return;
233+
}
234+
}
235+
}
236+
213237
static void stream_recv(struct bt_audio_stream *stream,
214238
const struct bt_iso_recv_info *info,
215239
struct net_buf *buf)
@@ -218,6 +242,7 @@ static void stream_recv(struct bt_audio_stream *stream,
218242
}
219243

220244
static struct bt_audio_stream_ops stream_ops = {
245+
.enabled = stream_enabled_cb,
221246
.recv = stream_recv
222247
};
223248

0 commit comments

Comments
 (0)