diff --git a/applications/nrf5340_audio/src/bluetooth/bt_stream/unicast/unicast_client.c b/applications/nrf5340_audio/src/bluetooth/bt_stream/unicast/unicast_client.c index 3a5622ad3ce6..cf13e7bdcd50 100644 --- a/applications/nrf5340_audio/src/bluetooth/bt_stream/unicast/unicast_client.c +++ b/applications/nrf5340_audio/src/bluetooth/bt_stream/unicast/unicast_client.c @@ -256,6 +256,18 @@ static int headset_pres_delay_find(uint8_t index, uint32_t *pres_dly_us) } } + if (pref_dly_min > pref_dly_max) { + LOG_ERR("Min pref delay, %d, greater than max pref delay, %d", pref_dly_min, + pref_dly_max); + return -ENOTSUP; + } + + if (pres_dly_min > pres_dly_max) { + LOG_ERR("Min pres delay, %d, greater than max pres delay, %d", pres_dly_min, + pres_dly_max); + return -ENOTSUP; + } + if (IS_ENABLED(CONFIG_BT_AUDIO_PRES_DELAY_SRCH_MIN)) { *pres_dly_us = pres_dly_min; @@ -269,24 +281,31 @@ static int headset_pres_delay_find(uint8_t index, uint32_t *pres_dly_us) } if (IS_ENABLED(CONFIG_BT_AUDIO_PRES_DELAY_SRCH_PREF_MIN)) { - /* Preferred min is 0, so we set min supported */ - if (pref_dly_min == 0) { + if (pref_dly_min == 0 || pref_dly_min < pres_dly_min) { *pres_dly_us = pres_dly_min; - } else { + } else if (pref_dly_min <= pres_dly_max) { *pres_dly_us = pref_dly_min; + } else { + LOG_ERR("Min pref delay, %d, greater than max pres delay, %d", pref_dly_min, + pres_dly_max); + + return -ENOTSUP; } return 0; } if (IS_ENABLED(CONFIG_BT_AUDIO_PRES_DELAY_SRCH_PREF_MAX)) { - /* Preferred max is 0, so we set max supported */ - if (pref_dly_max == 0) { + if (pref_dly_max == 0 || pref_dly_max > pres_dly_max) { *pres_dly_us = pres_dly_max; - } else { + } else if (pref_dly_max < pres_dly_min) { *pres_dly_us = pref_dly_max; - } + } else { + LOG_ERR("Max pref delay, %d, is less than min pres delay, %d", pref_dly_max, + pres_dly_max); + return -ENOTSUP; + } return 0; } @@ -1020,6 +1039,9 @@ static void stream_configured_cb(struct bt_bap_stream *stream, LOG_INF("%s sink stream configured", headsets[channel_index].ch_name); le_audio_print_codec(headsets[channel_index].sink_stream.codec_cfg, stream->ep->dir); + LOG_DBG("Configured Stream info: %s, %p, dir %d", headsets[channel_index].ch_name, + (void *)stream, stream->ep->dir); + } else if (stream->ep->dir == BT_AUDIO_DIR_SOURCE) { LOG_INF("%s source stream configured", headsets[channel_index].ch_name); le_audio_print_codec(headsets[channel_index].source_stream.codec_cfg, @@ -1028,8 +1050,6 @@ static void stream_configured_cb(struct bt_bap_stream *stream, LOG_WRN("Endpoint direction not recognized: %d", stream->ep->dir); return; } - LOG_DBG("Configured Stream info: %s, %p, dir %d", headsets[channel_index].ch_name, - (void *)stream, stream->ep->dir); ret = headset_pres_delay_find(channel_index, &new_pres_dly_us); if (ret) {