2022-01-07 17:23:45 +01:00
|
|
|
/* @file
|
|
|
|
* @brief Internal APIs for Audio Endpoint handling
|
|
|
|
|
|
|
|
* Copyright (c) 2020 Intel Corporation
|
|
|
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ascs_internal.h"
|
|
|
|
#include "stream.h"
|
|
|
|
|
2022-01-10 13:57:08 +01:00
|
|
|
#if defined(CONFIG_BT_AUDIO_UNICAST_CLIENT) && defined(CONFIG_BT_AUDIO_UNICAST)
|
|
|
|
#define UNICAST_GROUP_CNT CONFIG_BT_AUDIO_UNICAST_CLIENT_GROUP_COUNT
|
|
|
|
#define UNICAST_GROUP_STREAM_CNT CONFIG_BT_AUDIO_UNICAST_CLIENT_GROUP_STREAM_COUNT
|
|
|
|
#else /* !(CONFIG_BT_AUDIO_UNICAST_CLIENT && CONFIG_BT_AUDIO_UNICAST) */
|
2022-01-07 17:23:45 +01:00
|
|
|
#define UNICAST_GROUP_CNT 0
|
|
|
|
#define UNICAST_GROUP_STREAM_CNT 0
|
2022-01-10 13:57:08 +01:00
|
|
|
#endif /* CONFIG_BT_AUDIO_UNICAST_CLIENT && CONFIG_BT_AUDIO_UNICAST */
|
2022-01-10 15:06:08 +01:00
|
|
|
#if defined(CONFIG_BT_AUDIO_BROADCAST_SOURCE)
|
|
|
|
#define BROADCAST_STREAM_CNT CONFIG_BT_AUDIO_BROADCAST_SRC_STREAM_COUNT
|
|
|
|
#else /* !CONFIG_BT_AUDIO_BROADCAST_SOURCE */
|
2022-01-07 17:23:45 +01:00
|
|
|
#define BROADCAST_STREAM_CNT 0
|
2022-01-10 15:06:08 +01:00
|
|
|
#endif /* CONFIG_BT_AUDIO_BROADCAST_SOURCE */
|
2022-01-07 17:23:45 +01:00
|
|
|
|
|
|
|
#define BT_AUDIO_EP_LOCAL 0x00
|
|
|
|
#define BT_AUDIO_EP_REMOTE 0x01
|
|
|
|
|
|
|
|
/* Temp struct declarations to handle circular dependencies */
|
|
|
|
struct bt_audio_unicast_group;
|
|
|
|
struct bt_audio_broadcast_source;
|
|
|
|
struct bt_audio_broadcast_sink;
|
|
|
|
|
|
|
|
struct bt_audio_ep {
|
|
|
|
uint8_t type;
|
|
|
|
uint16_t handle;
|
|
|
|
uint16_t cp_handle;
|
|
|
|
uint8_t cig_id;
|
|
|
|
uint8_t cis_id;
|
|
|
|
struct bt_ascs_ase_status status;
|
|
|
|
struct bt_audio_stream *stream;
|
|
|
|
struct bt_codec codec;
|
|
|
|
struct bt_codec_qos qos;
|
|
|
|
struct bt_codec_qos_pref qos_pref;
|
|
|
|
/* TODO: Remove iso from this struct. The reason is that a ASE
|
|
|
|
* (endpoint) may only be unidirectional, but a single bidirectional CIS
|
|
|
|
* may used for a sink ASE and a source ASE, so there is not a 1:1
|
|
|
|
* relationship between ISO and ASEs.
|
|
|
|
*/
|
|
|
|
struct bt_iso_chan iso;
|
|
|
|
struct bt_iso_chan_qos iso_qos;
|
|
|
|
struct bt_iso_chan_io_qos iso_tx;
|
|
|
|
struct bt_iso_chan_io_qos iso_rx;
|
|
|
|
struct bt_gatt_subscribe_params subscribe;
|
|
|
|
struct bt_gatt_discover_params discover;
|
|
|
|
|
|
|
|
/* TODO: Create a union to reduce memory usage */
|
|
|
|
struct bt_audio_unicast_group *unicast_group;
|
|
|
|
struct bt_audio_broadcast_source *broadcast_source;
|
|
|
|
struct bt_audio_broadcast_sink *broadcast_sink;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bt_audio_unicast_group {
|
|
|
|
/* QoS used to create the CIG */
|
|
|
|
struct bt_codec_qos *qos;
|
|
|
|
struct bt_iso_cig *cig;
|
|
|
|
/* The ISO API for CIG creation requires an array of pointers to ISO channels */
|
|
|
|
struct bt_iso_chan *cis[UNICAST_GROUP_STREAM_CNT];
|
|
|
|
sys_slist_t streams;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bt_audio_broadcast_source {
|
|
|
|
uint8_t stream_count;
|
|
|
|
uint8_t subgroup_count;
|
|
|
|
uint32_t pd; /** QoS Presentation Delay */
|
|
|
|
uint32_t broadcast_id; /* 24 bit */
|
|
|
|
|
|
|
|
struct bt_le_ext_adv *adv;
|
|
|
|
struct bt_iso_big *big;
|
|
|
|
struct bt_iso_chan *bis[BROADCAST_STREAM_CNT];
|
|
|
|
struct bt_codec_qos *qos;
|
|
|
|
/* The streams used to create the broadcast source */
|
|
|
|
struct bt_audio_stream *streams;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bt_audio_broadcast_sink {
|
|
|
|
uint8_t index; /* index of broadcast_snks array */
|
|
|
|
uint8_t stream_count;
|
|
|
|
uint8_t subgroup_count;
|
|
|
|
uint16_t pa_interval;
|
|
|
|
uint16_t iso_interval;
|
|
|
|
uint16_t biginfo_num_bis;
|
|
|
|
bool biginfo_received;
|
|
|
|
bool syncing;
|
|
|
|
bool big_encrypted;
|
|
|
|
uint32_t broadcast_id; /* 24 bit */
|
|
|
|
struct bt_le_per_adv_sync *pa_sync;
|
|
|
|
struct bt_codec *codec;
|
|
|
|
struct bt_iso_big *big;
|
|
|
|
struct bt_iso_chan *bis[BROADCAST_SNK_STREAM_CNT];
|
|
|
|
/* The streams used to create the broadcast sink */
|
|
|
|
struct bt_audio_stream *streams;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline const char *bt_audio_ep_state_str(uint8_t state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case BT_AUDIO_EP_STATE_IDLE:
|
|
|
|
return "idle";
|
|
|
|
case BT_AUDIO_EP_STATE_CODEC_CONFIGURED:
|
|
|
|
return "codec-configured";
|
|
|
|
case BT_AUDIO_EP_STATE_QOS_CONFIGURED:
|
|
|
|
return "qos-configured";
|
|
|
|
case BT_AUDIO_EP_STATE_ENABLING:
|
|
|
|
return "enabling";
|
|
|
|
case BT_AUDIO_EP_STATE_STREAMING:
|
|
|
|
return "streaming";
|
|
|
|
case BT_AUDIO_EP_STATE_DISABLING:
|
|
|
|
return "disabling";
|
|
|
|
case BT_AUDIO_EP_STATE_RELEASING:
|
|
|
|
return "releasing";
|
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bt_audio_ep_is_broadcast_snk(const struct bt_audio_ep *ep);
|
|
|
|
bool bt_audio_ep_is_broadcast_src(const struct bt_audio_ep *ep);
|