Skip to content

Commit 3605848

Browse files
MariuszSkamracarlescufi
authored andcommitted
Bluetooth: audio: Improve stream coupling for CIS as the unicast client
Allow the streams to be paired when creating unicast group. This will allow to reuse the same ISO for the paired streams. Fixes: #51796 Signed-off-by: Mariusz Skamra <[email protected]>
1 parent 9400de3 commit 3605848

File tree

5 files changed

+217
-159
lines changed

5 files changed

+217
-159
lines changed

include/zephyr/bluetooth/audio/audio.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,32 +1946,33 @@ int bt_audio_stream_release(struct bt_audio_stream *stream);
19461946
int bt_audio_stream_send(struct bt_audio_stream *stream, struct net_buf *buf,
19471947
uint16_t seq_num, uint32_t ts);
19481948

1949-
/** @brief Parameter struct for the unicast group functions
1950-
*
1951-
* Parameter struct for the bt_audio_unicast_group_create() and
1952-
* bt_audio_unicast_group_add_streams() functions.
1953-
*/
19541949
struct bt_audio_unicast_group_stream_param {
19551950
/** Pointer to a stream object. */
19561951
struct bt_audio_stream *stream;
19571952

1958-
/** The QoS settings for the @ref bt_audio_unicast_group_stream_param.stream. */
1953+
/** The QoS settings for the stream object. */
19591954
struct bt_codec_qos *qos;
1955+
};
19601956

1961-
/** @brief The direction of the @ref bt_audio_unicast_group_stream_param.stream
1962-
*
1963-
* If two streams are being used for the same ACL connection but in
1964-
* different directions, they may use the same CIS.
1965-
*/
1966-
enum bt_audio_dir dir;
1957+
/** @brief Parameter struct for the unicast group functions
1958+
*
1959+
* Parameter struct for the bt_audio_unicast_group_create() and
1960+
* bt_audio_unicast_group_add_streams() functions.
1961+
*/
1962+
struct bt_audio_unicast_group_stream_pair_param {
1963+
/** Pointer to a receiving stream parameters. */
1964+
struct bt_audio_unicast_group_stream_param *rx_param;
1965+
1966+
/** Pointer to a transmiting stream parameters. */
1967+
struct bt_audio_unicast_group_stream_param *tx_param;
19671968
};
19681969

19691970
struct bt_audio_unicast_group_param {
19701971
/** The number of parameters in @p params */
19711972
size_t params_count;
19721973

19731974
/** Array of stream parameters */
1974-
struct bt_audio_unicast_group_stream_param *params;
1975+
struct bt_audio_unicast_group_stream_pair_param *params;
19751976

19761977
/** @brief Unicast Group packing mode.
19771978
*
@@ -2020,7 +2021,7 @@ int bt_audio_unicast_group_create(struct bt_audio_unicast_group_param *param,
20202021
* @return 0 in case of success or negative value in case of error.
20212022
*/
20222023
int bt_audio_unicast_group_add_streams(struct bt_audio_unicast_group *unicast_group,
2023-
struct bt_audio_unicast_group_stream_param params[],
2024+
struct bt_audio_unicast_group_stream_pair_param params[],
20242025
size_t num_param);
20252026

20262027
/** @brief Delete audio unicast group.

samples/bluetooth/unicast_audio_client/src/main.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ NET_BUF_POOL_FIXED_DEFINE(tx_pool, CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT,
3333
static struct bt_audio_stream streams[CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SNK_COUNT +
3434
CONFIG_BT_AUDIO_UNICAST_CLIENT_ASE_SRC_COUNT];
3535
static size_t configured_sink_stream_count;
36-
static size_t configured_stream_count;
36+
static size_t configured_source_stream_count;
3737

38+
#define configured_stream_count (configured_sink_stream_count + \
39+
configured_source_stream_count)
3840

3941
/* Select a codec configuration to apply that is mandatory to support by both client and server.
4042
* Allows this sample application to work without logic to parse the codec capabilities of the
@@ -329,25 +331,6 @@ static void audio_timer_timeout(struct k_work *work)
329331

330332
#endif
331333

332-
333-
static enum bt_audio_dir stream_dir(const struct bt_audio_stream *stream)
334-
{
335-
for (size_t i = 0U; i < ARRAY_SIZE(sinks); i++) {
336-
if (sinks[i].ep != NULL && stream->ep == sinks[i].ep) {
337-
return BT_AUDIO_DIR_SINK;
338-
}
339-
}
340-
341-
for (size_t i = 0U; i < ARRAY_SIZE(sources); i++) {
342-
if (sources[i] != NULL && stream->ep == sources[i]) {
343-
return BT_AUDIO_DIR_SOURCE;
344-
}
345-
}
346-
347-
__ASSERT(false, "Invalid stream");
348-
return 0;
349-
}
350-
351334
static void print_hex(const uint8_t *ptr, size_t len)
352335
{
353336
while (len-- != 0) {
@@ -880,7 +863,6 @@ static int configure_streams(void)
880863
}
881864

882865
printk("Configured sink stream[%zu]\n", i);
883-
configured_stream_count++;
884866
configured_sink_stream_count++;
885867
}
886868

@@ -900,26 +882,42 @@ static int configure_streams(void)
900882
}
901883

902884
printk("Configured source stream[%zu]\n", i);
903-
configured_stream_count++;
885+
configured_source_stream_count++;
904886
}
905887

906888
return 0;
907889
}
908890

909891
static int create_group(void)
910892
{
911-
struct bt_audio_unicast_group_stream_param stream_params[ARRAY_SIZE(streams)];
893+
const size_t params_count = MAX(configured_sink_stream_count,
894+
configured_source_stream_count);
895+
struct bt_audio_unicast_group_stream_pair_param pair_params[params_count];
896+
struct bt_audio_unicast_group_stream_param stream_params[configured_stream_count];
912897
struct bt_audio_unicast_group_param param;
913898
int err;
914899

915900
for (size_t i = 0U; i < configured_stream_count; i++) {
916901
stream_params[i].stream = &streams[i];
917902
stream_params[i].qos = &codec_configuration.qos;
918-
stream_params[i].dir = stream_dir(stream_params[i].stream);
919903
}
920904

921-
param.params = stream_params;
922-
param.params_count = configured_stream_count;
905+
for (size_t i = 0U; i < params_count; i++) {
906+
if (i < configured_sink_stream_count) {
907+
pair_params[i].tx_param = &stream_params[i];
908+
} else {
909+
pair_params[i].tx_param = NULL;
910+
}
911+
912+
if (i < configured_source_stream_count) {
913+
pair_params[i].rx_param = &stream_params[i + configured_sink_stream_count];
914+
} else {
915+
pair_params[i].rx_param = NULL;
916+
}
917+
}
918+
919+
param.params = pair_params;
920+
param.params_count = params_count;
923921
param.packing = BT_ISO_PACKING_SEQUENTIAL;
924922

925923
err = bt_audio_unicast_group_create(&param, &unicast_group);
@@ -969,7 +967,7 @@ static int enable_streams(void)
969967
init_lc3();
970968
}
971969

972-
for (size_t i = 0; i < configured_stream_count; i++) {
970+
for (size_t i = 0U; i < configured_stream_count; i++) {
973971
int err;
974972

975973
err = bt_audio_stream_enable(&streams[i],
@@ -992,7 +990,7 @@ static int enable_streams(void)
992990

993991
static int start_streams(void)
994992
{
995-
for (size_t i = 0; i < configured_stream_count; i++) {
993+
for (size_t i = 0U; i < configured_stream_count; i++) {
996994
int err;
997995

998996
err = bt_audio_stream_start(&streams[i]);
@@ -1025,7 +1023,7 @@ static void reset_data(void)
10251023
k_sem_reset(&sem_stream_started);
10261024

10271025
configured_sink_stream_count = 0;
1028-
configured_stream_count = 0;
1026+
configured_source_stream_count = 0;
10291027
}
10301028

10311029
void main(void)

0 commit comments

Comments
 (0)