Skip to content

Commit 5b82f31

Browse files
Thalleycarlescufi
authored andcommitted
[nrf noup] Bluetooth: BAP: Add target latency and phy to codec_cfg
The codec configuration operation for unicast (ASCS) contain both a target PHY and a target latency value that was previously just hardcoded by the client and unavailable by the server. This commit adds them to the bt_audio_codec_cfg struct so that applications can both set and get these values. The default values used by BT_AUDIO_CODEC_CFG use the same values as the client would previously set. Signed-off-by: Emil Gydesen <[email protected]> (cherry picked from commit 8788f8b)
1 parent 787001e commit 5b82f31

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

include/zephyr/bluetooth/audio/audio.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ enum bt_audio_metadata_type {
550550
/* Use HCI data path as default, can be overwritten by application */ \
551551
.path_id = BT_ISO_DATA_PATH_HCI, \
552552
.ctlr_transcode = false, \
553+
COND_CODE_1(IS_ENABLED(CONFIG_BT_BAP_UNICAST), \
554+
(.target_latency = BT_AUDIO_CODEC_CFG_TARGET_LATENCY_BALANCED, \
555+
.target_phy = BT_AUDIO_CODEC_CFG_TARGET_PHY_2M,), \
556+
()) \
553557
.id = _id, \
554558
.cid = _cid, \
555559
.vid = _vid, \
@@ -714,6 +718,39 @@ struct bt_audio_codec_cap {
714718
#endif /* CONFIG_BT_AUDIO_CODEC_CAP_MAX_METADATA_SIZE */
715719
};
716720

721+
/**
722+
* @brief Codec configuration target latency
723+
*
724+
* Set by the BAP Unicast Client to provide context for the BAP Unicast Server for the server to
725+
* set its QoS preferences.
726+
*/
727+
enum bt_audio_codec_cfg_target_latency {
728+
/** Target low latency */
729+
BT_AUDIO_CODEC_CFG_TARGET_LATENCY_LOW = 0x01,
730+
731+
/** Target balanced latency */
732+
BT_AUDIO_CODEC_CFG_TARGET_LATENCY_BALANCED = 0x02,
733+
734+
/** Target high latency */
735+
BT_AUDIO_CODEC_CFG_TARGET_LATENCY_HIGH = 0x03,
736+
};
737+
738+
/**
739+
* @brief Codec configuration target PHY
740+
*
741+
* The target PHY to achieve the target latency (@ref bt_audio_codec_cfg_target_latency).
742+
*/
743+
enum bt_audio_codec_cfg_target_phy {
744+
/** LE 1M PHY */
745+
BT_AUDIO_CODEC_CFG_TARGET_PHY_1M = 0x01,
746+
747+
/** LE 2M PHY */
748+
BT_AUDIO_CODEC_CFG_TARGET_PHY_2M = 0x02,
749+
750+
/** LE Coded PHY */
751+
BT_AUDIO_CODEC_CFG_TARGET_PHY_CODED = 0x03,
752+
};
753+
717754
/** @brief Codec specific configuration structure. */
718755
struct bt_audio_codec_cfg {
719756
/** Data path ID
@@ -728,6 +765,18 @@ struct bt_audio_codec_cfg {
728765
* BT_HCI_CODING_FORMAT_TRANSPARENT if false, else uses the @ref bt_audio_codec_cfg.id.
729766
*/
730767
bool ctlr_transcode;
768+
#if defined(CONFIG_BT_BAP_UNICAST)
769+
/** Target latency
770+
*
771+
* Unused for broadcast streams.
772+
*/
773+
enum bt_audio_codec_cfg_target_latency target_latency;
774+
/** Target PHY
775+
*
776+
* Unused for broadcast streams.
777+
*/
778+
enum bt_audio_codec_cfg_target_phy target_phy;
779+
#endif /* CONFIG_BT_BAP_UNICAST */
731780
/** Codec ID */
732781
uint8_t id;
733782
/** Codec Company ID */

subsys/bluetooth/audio/ascs.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,9 @@ static void ascs_cp_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
14871487
LOG_DBG("attr %p value 0x%04x", attr, value);
14881488
}
14891489

1490-
static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uint16_t vid,
1491-
uint8_t *cc, uint8_t len, struct bt_bap_ascs_rsp *rsp)
1490+
static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t target_latency, uint8_t target_phy,
1491+
uint8_t id, uint16_t cid, uint16_t vid, const uint8_t *cc, uint8_t len,
1492+
struct bt_bap_ascs_rsp *rsp)
14921493
{
14931494
const struct bt_audio_codec_cap *codec_cap;
14941495
struct bt_audio_codec_cfg *codec_cfg;
@@ -1520,6 +1521,8 @@ static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uin
15201521
return -ENOENT;
15211522
}
15221523

1524+
codec_cfg->target_latency = target_latency;
1525+
codec_cfg->target_phy = target_phy;
15231526
codec_cfg->id = id;
15241527
codec_cfg->cid = cid;
15251528
codec_cfg->vid = vid;
@@ -1588,10 +1591,10 @@ static int ase_config(struct bt_ascs_ase *ase, const struct bt_ascs_config *cfg)
15881591
*/
15891592
(void)memcpy(&codec_cfg, &ase->ep.codec_cfg, sizeof(codec_cfg));
15901593

1591-
err = ascs_ep_set_codec(&ase->ep, cfg->codec.id, sys_le16_to_cpu(cfg->codec.cid),
1592-
sys_le16_to_cpu(cfg->codec.vid), (uint8_t *)cfg->cc, cfg->cc_len,
1593-
&rsp);
1594-
if (err) {
1594+
err = ascs_ep_set_codec(&ase->ep, cfg->latency, cfg->phy, cfg->codec.id,
1595+
sys_le16_to_cpu(cfg->codec.cid), sys_le16_to_cpu(cfg->codec.vid),
1596+
(const uint8_t *)cfg->cc, cfg->cc_len, &rsp);
1597+
if (err != 0) {
15951598
ascs_app_rsp_warn_valid(&rsp);
15961599
(void)memcpy(&ase->ep.codec_cfg, &codec_cfg, sizeof(codec_cfg));
15971600
ascs_cp_rsp_add(ASE_ID(ase), rsp.code, rsp.reason);

subsys/bluetooth/audio/bap_unicast_client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,8 +1936,8 @@ static int unicast_client_ep_config(struct bt_bap_ep *ep, struct net_buf_simple
19361936

19371937
req = net_buf_simple_add(buf, sizeof(*req));
19381938
req->ase = ep->status.id;
1939-
req->latency = 0x02; /* TODO: Select target latency based on additional input? */
1940-
req->phy = 0x02; /* TODO: Select target PHY based on additional input? */
1939+
req->latency = codec_cfg->target_latency;
1940+
req->phy = codec_cfg->target_phy;
19411941
req->codec.id = codec_cfg->id;
19421942
req->codec.cid = codec_cfg->cid;
19431943
req->codec.vid = codec_cfg->vid;

0 commit comments

Comments
 (0)