Skip to content

Commit 9906e50

Browse files
committed
applications: nrf_audio: Fixes to TX timestamp handling.
Fixes an issue where too many SDUs were lost when using an unsynchronized audio source (such as async USB). Reworked timestamp handling to be more robust and added better logging. OCT-3710 Signed-off-by: Kristoffer Skøien <kristoffer.skoien@nordicsemi.no>
1 parent 2cdebb6 commit 9906e50

9 files changed

Lines changed: 301 additions & 227 deletions

File tree

applications/nrf_audio/src/audio/le_audio_rx.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
LOG_MODULE_REGISTER(le_audio_rx, CONFIG_LE_AUDIO_RX_LOG_LEVEL);
2323

2424
struct rx_stats {
25-
uint32_t recv_cnt;
26-
uint32_t good_frame_cnt;
27-
uint32_t bad_frame_cnt;
28-
bool prev_bad_data;
25+
uint64_t good_frame_cnt;
26+
uint64_t bad_or_empty_frame_cnt;
2927
};
3028

3129
static bool initialized;
@@ -109,33 +107,37 @@ void le_audio_rx_data_handler(struct net_buf *audio_frame_rx, struct audio_metad
109107
static uint32_t num_overruns;
110108
static uint32_t num_thrown;
111109

110+
__ASSERT_NO_MSG(audio_frame_rx != NULL);
111+
__ASSERT_NO_MSG(meta != NULL);
112+
112113
if (!initialized) {
113114
ERR_CHK_MSG(-EPERM, "Data received but le_audio_rx is not initialized");
114115
}
115116

116-
rx_stats[location_index].recv_cnt++;
117-
118117
if (meta->bad_data) {
119-
rx_stats[location_index].bad_frame_cnt++;
118+
rx_stats[location_index].bad_or_empty_frame_cnt++;
120119
} else {
121120
rx_stats[location_index].good_frame_cnt++;
122121
}
123122

124-
if ((rx_stats[location_index].recv_cnt % 100) == 0 && rx_stats[location_index].recv_cnt) {
125-
/* NOTE: The string below is used by the Nordic CI system */
126-
LOG_DBG("ISO RX SDUs: Loc: %d Total: %d Bad: %d", location_index,
127-
rx_stats[location_index].recv_cnt, rx_stats[location_index].bad_frame_cnt);
128-
}
123+
uint64_t total_frames = rx_stats[location_index].good_frame_cnt +
124+
rx_stats[location_index].bad_or_empty_frame_cnt;
125+
double bad_frame_percentage =
126+
(total_frames > 0) ? (((double)rx_stats[location_index].bad_or_empty_frame_cnt /
127+
total_frames) *
128+
100)
129+
: 0.0;
129130

130-
if (meta->bad_data && !rx_stats[location_index].prev_bad_data) {
131-
LOG_INF_RATELIMIT_RATE(1000,
132-
"Bad or 0 SDU: Loc: %u Total: %u Bad: %u. (Prints "
133-
"good->bad transition)",
134-
location_index, rx_stats[location_index].recv_cnt,
135-
rx_stats[location_index].bad_frame_cnt);
131+
if ((total_frames % 100) == 0 && (total_frames != 0)) {
132+
/* NOTE: The string below is used by the Nordic CI system */
133+
LOG_DBG("ISO RX SDUs: Loc: %u Total: %llu Bad: %llu", location_index, total_frames,
134+
rx_stats[location_index].bad_or_empty_frame_cnt);
136135
}
137136

138-
rx_stats[location_index].prev_bad_data = meta->bad_data;
137+
LOG_DBG_RATELIMIT_RATE(
138+
10000, "Bad or 0 SDU: Loc: %u Total: %llu Empty/bad: %llu (%2.3f %%)",
139+
location_index, total_frames, rx_stats[location_index].bad_or_empty_frame_cnt,
140+
bad_frame_percentage);
139141

140142
if (stream_state_get() != STATE_STREAMING) {
141143
/* Throw away data */
@@ -264,6 +266,10 @@ void le_audio_rx_data_handler(struct net_buf *audio_frame_rx, struct audio_metad
264266
*/
265267
static void audio_datapath_thread(void *dummy1, void *dummy2, void *dummy3)
266268
{
269+
ARG_UNUSED(dummy1);
270+
ARG_UNUSED(dummy2);
271+
ARG_UNUSED(dummy3);
272+
267273
int ret;
268274
struct net_buf *audio_frame = NULL;
269275

applications/nrf_audio/src/bluetooth/bt_stream/bt_le_audio_tx/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config NRF_AUDIO_TX_TGT_LEAD_TIME_US
99
Used to make sure that the data is sent to controller just in time for the next SDU,
1010
which can help with reducing the overall latency and power consumption.
1111
Setting this too low may lead to flushed data, and too high will increase latency.
12+
Must be higher than HCI_ISO_TX_SDU_ARRIVAL_MARGIN_US + plus a margin depending on SoC.
1213

1314
config NRF_AUDIO_TX_LEAD_TIME_DEVIATION_US
1415
int

0 commit comments

Comments
 (0)