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 30, 2024
1 parent e4bb53a commit 7316250
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
15 changes: 0 additions & 15 deletions applications/nrf5340_audio/src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,6 @@ config AUDIO_BIT_DEPTH_OCTETS
help
Bit depth of one sample in storage given in octets.

config AUDIO_MIN_PRES_DLY_US
int "The minimum presentation delay"
default 4000
help
The minimum allowable presentation delay in microseconds.
This needs to allow time for decoding and internal routing.
For 48kHz sampling rate and 96kbps bitrate this is about 4000 us.

config AUDIO_MAX_PRES_DLY_US
int "The maximum presentation delay"
default 60000
help
The maximum allowable presentation delay in microseconds.
Increasing this will also increase the FIFO buffers to allow buffering.

choice AUDIO_SOURCE_GATEWAY
prompt "Audio source for gateway"
default AUDIO_SOURCE_I2S if WALKIE_TALKIE_DEMO
Expand Down
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 7316250

Please sign in to comment.