Skip to content

Commit

Permalink
applications: nrf5340_audio: Rail the presentation delay.
Browse files Browse the repository at this point in the history
	Ensure the preferred presentation delay is within the range of the
	min and max delays, rail if not.
	Search for the presentation delay function updated to search over
	the end points for the direction.

Signed-off-by: Graham Wacey <[email protected]>
  • Loading branch information
gWacey committed Apr 29, 2024
1 parent e4bb53a commit 48857e8
Showing 1 changed file with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 48857e8

Please sign in to comment.