Skip to content

Commit

Permalink
Bluetooth: BAP: Add can_recv to bt_bap_ep_info
Browse files Browse the repository at this point in the history
Similar to the can_send, the can_recv field indicates whether
or not this endpoint can receive data.

This commit also slightly refactors and optimized how the
can_send field is set.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley committed Feb 26, 2024
1 parent f0b9750 commit b1a3f23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions include/zephyr/bluetooth/audio/bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ struct bt_bap_ep_info {
/** @brief True if the stream associated with the endpoint is able to send data */
bool can_send;

/** @brief True if the stream associated with the endpoint is able to receive data */
bool can_recv;

/** Pointer to paired endpoint if the endpoint is part of a bidirectional CIS,
* otherwise NULL
*/
Expand Down
30 changes: 15 additions & 15 deletions subsys/bluetooth/audio/bap_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,25 @@ int bt_bap_ep_get_info(const struct bt_bap_ep *ep, struct bt_bap_ep_info *info)
}

info->can_send = false;
info->can_recv = false;
if (IS_ENABLED(CONFIG_BT_AUDIO_TX) && ep->stream != NULL) {
if (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SOURCE) && bt_bap_ep_is_broadcast_src(ep)) {
info->can_send = true;
} else if (IS_ENABLED(CONFIG_BT_CONN) && ep->stream->conn != NULL) {
struct bt_conn_info conn_info;
uint8_t role;
int err;

err = bt_conn_get_info(ep->stream->conn, &conn_info);
if (err != 0) {
LOG_DBG("Could not get conn info: %d", err);

return err;
} else if (IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SINK) &&
bt_bap_ep_is_broadcast_snk(ep)) {
info->can_recv = true;
} else if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) &&
bt_bap_ep_is_unicast_client(ep)) {
/* dir is not initialized before the connection is set */
if (ep->stream->conn != NULL) {
info->can_send = dir == BT_AUDIO_DIR_SINK;
info->can_recv = dir == BT_AUDIO_DIR_SOURCE;
}

role = conn_info.role;
if ((role == BT_CONN_ROLE_CENTRAL && dir == BT_AUDIO_DIR_SINK) ||
(role == BT_CONN_ROLE_PERIPHERAL && dir == BT_AUDIO_DIR_SOURCE)) {
info->can_send = true;
} else if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_SERVER)) {
/* dir is not initialized before the connection is set */
if (ep->stream->conn != NULL) {
info->can_send = dir == BT_AUDIO_DIR_SOURCE;
info->can_recv = dir == BT_AUDIO_DIR_SINK;
}
}
}
Expand Down

0 comments on commit b1a3f23

Please sign in to comment.