Skip to content

Commit 8788f8b

Browse files
Thalleyfabiobaltieri
authored andcommitted
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]>
1 parent 1c9c0b0 commit 8788f8b

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

doc/releases/release-notes-4.3.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ New APIs and options
7979

8080
* :kconfig:option:`CONFIG_SRAM_SW_ISR_TABLE`
8181

82+
* Bluetooth
83+
84+
* Audio
85+
86+
* :c:struct:`bt_audio_codec_cfg` now contains a target_latency and a target_phy option
87+
8288
* Power management
8389

8490
* :c:func:`pm_device_driver_deinit`

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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,8 +1490,9 @@ static void ascs_cp_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
14901490
LOG_DBG("attr %p value 0x%04x", attr, value);
14911491
}
14921492

1493-
static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uint16_t vid,
1494-
const uint8_t *cc, uint8_t len, struct bt_bap_ascs_rsp *rsp)
1493+
static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t target_latency, uint8_t target_phy,
1494+
uint8_t id, uint16_t cid, uint16_t vid, const uint8_t *cc, uint8_t len,
1495+
struct bt_bap_ascs_rsp *rsp)
14951496
{
14961497
const struct bt_audio_codec_cap *codec_cap;
14971498
struct bt_audio_codec_cfg *codec_cfg;
@@ -1523,6 +1524,8 @@ static int ascs_ep_set_codec(struct bt_bap_ep *ep, uint8_t id, uint16_t cid, uin
15231524
return -ENOENT;
15241525
}
15251526

1527+
codec_cfg->target_latency = target_latency;
1528+
codec_cfg->target_phy = target_phy;
15261529
codec_cfg->id = id;
15271530
codec_cfg->cid = cid;
15281531
codec_cfg->vid = vid;
@@ -1589,9 +1592,9 @@ static int ase_config(struct bt_ascs_ase *ase, const struct bt_ascs_config *cfg)
15891592
*/
15901593
(void)memcpy(&codec_cfg, &ase->ep.codec_cfg, sizeof(codec_cfg));
15911594

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

subsys/bluetooth/audio/bap_unicast_client.c

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

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

0 commit comments

Comments
 (0)