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 May 7, 2024
1 parent cd42921 commit bec232b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
23 changes: 5 additions & 18 deletions applications/nrf5340_audio/src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ config AUDIO_MIN_PRES_DLY_US
int "The minimum presentation delay"
default 4000
help
The minimum presentation delay in micro seconds determined by
the audio system processing and the minimum buffering.
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 presentation delay in micro seconds.
The maximum allowable presentation delay in microseconds.
Increasing this will also increase the FIFO buffers to allow buffering.

choice AUDIO_SYSTEM_SAMPLE_RATE
prompt "System audio sample rate"
Expand Down Expand Up @@ -108,21 +110,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 @@ -161,6 +161,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 @@ -174,24 +186,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 @@ -932,6 +951,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 @@ -940,8 +962,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 bec232b

Please sign in to comment.