Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 1 addition & 214 deletions include/zephyr/bluetooth/audio/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,225 +19,12 @@ extern "C" {
/* Get list of capabilities by type */
sys_slist_t *bt_audio_capability_get(enum bt_audio_dir dir);


/** @brief Audio Capability type */
enum bt_audio_capability_framing {
BT_AUDIO_CAPABILITY_UNFRAMED_SUPPORTED = 0x00,
BT_AUDIO_CAPABILITY_UNFRAMED_NOT_SUPPORTED = 0x01,
};

/**
* @brief Helper to declare elements of @ref bt_audio_capability_pref
*
* @param _framing Framing Support
* @param _phy Preferred Target PHY
* @param _rtn Preferred Retransmission number
* @param _latency Preferred Maximum Transport Latency (msec)
* @param _pd_min Minimum Presentation Delay (usec)
* @param _pd_max Maximum Presentation Delay (usec)
* @param _pref_pd_min Preferred Minimum Presentation Delay (usec)
* @param _pref_pd_max Preferred Maximum Presentation Delay (usec)
*/
#define BT_AUDIO_CAPABILITY_PREF(_framing, _phy, _rtn, _latency, _pd_min, \
_pd_max, _pref_pd_min, _pref_pd_max) \
{ \
.framing = _framing, \
.phy = _phy, \
.rtn = _rtn, \
.latency = _latency, \
.pd_min = _pd_min, \
.pd_max = _pd_max, \
.pref_pd_min = _pref_pd_min, \
.pref_pd_max = _pref_pd_max, \
}

/** @brief Audio Capability Preference structure. */
struct bt_audio_capability_pref {
/** @brief Framing support value
*
* Unlike the other fields, this is not a preference but whether
* the capability supports unframed ISOAL PDUs.
*
* Possible values: BT_AUDIO_CAPABILITY_UNFRAMED_SUPPORTED and
* BT_AUDIO_CAPABILITY_UNFRAMED_NOT_SUPPORTED.
*/
uint8_t framing;

/** Preferred PHY */
uint8_t phy;

/** Preferred Retransmission Number */
uint8_t rtn;

/** Preferred Transport Latency in ms */
uint16_t latency;

/** @brief Minimum Presentation Delay in us
*
* Unlike the other fields, this is not a preference but a minimum
* requirement.
*/
uint32_t pd_min;

/** @brief Maximum Presentation Delay in us
*
* Unlike the other fields, this is not a preference but a maximum
* requirement.
*/
uint32_t pd_max;

/** @brief Preferred minimum Presentation Delay in us*/
uint32_t pref_pd_min;

/** @brief Preferred maximum Presentation Delay in us */
uint32_t pref_pd_max;
};

struct bt_audio_capability; /* Handle circular dependency */

/** @brief Capability operations structure.
*
* These are only used for unicast streams and broadcast sink streams.
*/
struct bt_audio_capability_ops {
/** @brief Capability config callback
*
* Config callback is called whenever a new Audio Stream needs to be
* allocated.
*
* @param conn Connection object
* @param ep Remote Audio Endpoint being configured
* @param dir Direction of the endpoint.
* @param cap Local Audio Capability being configured
* @param codec Codec configuration
*
* @return Allocated Audio Stream object or NULL in case of error.
*/
struct bt_audio_stream *(*config)(struct bt_conn *conn,
struct bt_audio_ep *ep,
enum bt_audio_dir dir,
struct bt_audio_capability *cap,
struct bt_codec *codec);

/** @brief Capability reconfig callback
*
* Reconfig callback is called whenever an Audio Stream needs to be
* reconfigured with different codec configuration.
*
* @param stream Stream object being reconfigured.
* @param cap Local Audio Capability being reconfigured
* @param codec Codec configuration
*
* @return 0 in case of success or negative value in case of error.
*/
int (*reconfig)(struct bt_audio_stream *stream,
struct bt_audio_capability *cap,
struct bt_codec *codec);

/** @brief Capability QoS callback
*
* QoS callback is called whenever an Audio Stream Quality of
* Service needs to be configured.
*
* @param stream Stream object being reconfigured.
* @param QoS Quality of Service configuration
*
* @return 0 in case of success or negative value in case of error.
*/
int (*qos)(struct bt_audio_stream *stream, struct bt_codec_qos *qos);

/** @brief Capability Enable callback
*
* Enable callback is called whenever an Audio Stream is about to be
* enabled.
*
* @param stream Stream object being enabled.
* @param meta_count Number of metadata entries
* @param meta Metadata entries
*
* @return 0 in case of success or negative value in case of error.
*/
int (*enable)(struct bt_audio_stream *stream,
struct bt_codec_data *meta,
size_t meta_count);

/** @brief Capability Start callback
*
* Start callback is called whenever an Audio Stream is about to
* start streaming.
*
* @param stream Stream object.
*
* @return 0 in case of success or negative value in case of error.
*/
int (*start)(struct bt_audio_stream *stream);

/** @brief Capability Metadata callback
*
* Metadata callback is called whenever an Audio Stream needs to
* update its metadata.
*
* @param stream Stream object.
* @param meta_count Number of metadata entries
* @param meta Metadata entries
*
* @return 0 in case of success or negative value in case of error.
*/
int (*metadata)(struct bt_audio_stream *stream,
struct bt_codec_data *meta,
size_t meta_count);

/** @brief Capability Disable callback
*
* Disable callback is called whenever an Audio Stream is about to be
* disabled.
*
* @param stream Stream object being disabled.
*
* @return 0 in case of success or negative value in case of error.
*/
int (*disable)(struct bt_audio_stream *stream);

/** @brief Capability Stop callback
*
* Stop callback is called whenever an Audio Stream is about to
* stop streaming.
*
* @param stream Stream object.
*
* @return 0 in case of success or negative value in case of error.
*/
int (*stop)(struct bt_audio_stream *stream);

/** @brief Capability release callback
*
* Release callback is called whenever a new Audio Stream needs to be
* deallocated.
*
* @param stream Stream object.
*
* @return 0 in case of success or negative value in case of error.
*/
int (*release)(struct bt_audio_stream *stream);
};

/** @brief Audio Capability structure.
*
* Audio Capability represents a Local Codec including its preferrable
* Quality of service.
*
*/
/** @brief Audio Capability structure. */
struct bt_audio_capability {
/** Capability direction */
enum bt_audio_dir dir;
/** Capability codec reference */
struct bt_codec *codec;
#if defined(CONFIG_BT_AUDIO_UNICAST_SERVER)
/** Capability preferences */
struct bt_audio_capability_pref pref;
/** Capability operations reference */
struct bt_audio_capability_ops *ops;
#endif /* CONFIG_BT_AUDIO_UNICAST_SERVER */

/* Internally used list node */
sys_snode_t _node;
Expand Down
73 changes: 40 additions & 33 deletions samples/bluetooth/hap_ha/src/bap_unicast_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ static struct bt_audio_source {
} source_streams[CONFIG_BT_ASCS_ASE_SRC_COUNT];
static size_t configured_source_stream_count;

static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_LE_PHY_2M, 0x02,
10, 20000, 40000, 20000, 40000);

static uint32_t get_and_incr_seq_num(const struct bt_audio_stream *stream)
{
for (size_t i = 0U; i < configured_source_stream_count; i++) {
Expand Down Expand Up @@ -98,7 +101,7 @@ static void print_codec(const struct bt_codec *codec)
}
}

static void print_qos(struct bt_codec_qos *qos)
static void print_qos(const struct bt_codec_qos *qos)
{
printk("QoS: interval %u framing 0x%02x phy 0x%02x sdu %u "
"rtn %u latency %u pd %u\n",
Expand Down Expand Up @@ -170,45 +173,57 @@ static void audio_timer_timeout(struct k_work *work)
}
}

static struct bt_audio_stream *lc3_config(struct bt_conn *conn, struct bt_audio_ep *ep,
enum bt_audio_dir dir, struct bt_audio_capability *cap,
struct bt_codec *codec)
static struct bt_audio_stream *stream_alloc(void)
{
printk("ASE Codec Config: conn %p ep %p dir %u, cap %p\n",
conn, ep, dir, cap);

print_codec(codec);

for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
struct bt_audio_stream *stream = &streams[i];

if (!stream->conn) {
printk("ASE Codec Config stream %p\n", stream);
if (dir == BT_AUDIO_DIR_SOURCE) {
source_streams[configured_source_stream_count++].stream = stream;
}

return stream;
}
}

printk("No streams available\n");

return NULL;
}

static int lc3_reconfig(struct bt_audio_stream *stream, struct bt_audio_capability *cap,
struct bt_codec *codec)
static int lc3_config(struct bt_conn *conn, const struct bt_audio_ep *ep, enum bt_audio_dir dir,
const struct bt_codec *codec, struct bt_audio_stream **stream,
struct bt_codec_qos_pref *const pref)
{
printk("ASE Codec Config: conn %p ep %p dir %u\n", conn, ep, dir);

print_codec(codec);

*stream = stream_alloc();
if (*stream == NULL) {
printk("No streams available\n");

return -ENOMEM;
}

printk("ASE Codec Config stream %p\n", *stream);

if (dir == BT_AUDIO_DIR_SOURCE) {
source_streams[configured_source_stream_count++].stream = *stream;
}

*pref = qos_pref;

return 0;
}

static int lc3_reconfig(struct bt_audio_stream *stream, enum bt_audio_dir dir,
const struct bt_codec *codec, struct bt_codec_qos_pref *const pref)
{
printk("ASE Codec Reconfig: stream %p cap %p\n", stream, cap);
printk("ASE Codec Reconfig: stream %p\n", stream);

print_codec(codec);

/* We only support one QoS at the moment, reject changes */
return -ENOEXEC;
}

static int lc3_qos(struct bt_audio_stream *stream, struct bt_codec_qos *qos)
static int lc3_qos(struct bt_audio_stream *stream, const struct bt_codec_qos *qos)
{
printk("QoS: stream %p qos %p\n", stream, qos);

Expand All @@ -217,7 +232,7 @@ static int lc3_qos(struct bt_audio_stream *stream, struct bt_codec_qos *qos)
return 0;
}

static int lc3_enable(struct bt_audio_stream *stream, struct bt_codec_data *meta,
static int lc3_enable(struct bt_audio_stream *stream, const struct bt_codec_data *meta,
size_t meta_count)
{
printk("Enable: stream %p meta_count %u\n", stream, meta_count);
Expand Down Expand Up @@ -291,7 +306,7 @@ static bool valid_metadata_type(uint8_t type, uint8_t len)
}
}

static int lc3_metadata(struct bt_audio_stream *stream, struct bt_codec_data *meta,
static int lc3_metadata(struct bt_audio_stream *stream, const struct bt_codec_data *meta,
size_t meta_count)
{
printk("Metadata: stream %p meta_count %u\n", stream, meta_count);
Expand Down Expand Up @@ -328,7 +343,7 @@ static int lc3_release(struct bt_audio_stream *stream)
return 0;
}

static struct bt_audio_capability_ops lc3_ops = {
static const struct bt_audio_unicast_server_cb unicast_server_cb = {
.config = lc3_config,
.reconfig = lc3_reconfig,
.qos = lc3_qos,
Expand Down Expand Up @@ -399,28 +414,20 @@ BT_CONN_CB_DEFINE(conn_callbacks) = {
static struct bt_audio_capability caps[] = {
{
.dir = BT_AUDIO_DIR_SINK,
.pref = BT_AUDIO_CAPABILITY_PREF(
BT_AUDIO_CAPABILITY_UNFRAMED_SUPPORTED,
BT_GAP_LE_PHY_2M, 0x02, 10, 20000, 40000,
20000, 40000),
.codec = &lc3_codec,
.ops = &lc3_ops,
},
#if defined(CONFIG_BT_ASCS_ASE_SRC)
{
.dir = BT_AUDIO_DIR_SOURCE,
.pref = BT_AUDIO_CAPABILITY_PREF(
BT_AUDIO_CAPABILITY_UNFRAMED_SUPPORTED,
BT_GAP_LE_PHY_2M, 0x02, 10, 20000, 40000,
20000, 40000),
.codec = &lc3_codec,
.ops = &lc3_ops,
}
#endif /* CONFIG_BT_ASCS_ASE_SRC */
};

int bap_unicast_sr_init(void)
{
bt_audio_unicast_server_register_cb(&unicast_server_cb);

for (size_t i = 0; i < ARRAY_SIZE(caps); i++) {
bt_audio_capability_register(&caps[i]);
}
Expand Down
Loading