mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-01 10:13:29 +00:00
test/le_audio_unicast_sink: rework plc
This commit is contained in:
parent
5965dbb84b
commit
87806d86dd
@ -76,6 +76,13 @@
|
||||
#include "wav_util.h"
|
||||
#endif
|
||||
|
||||
#define DEBUG_PLC
|
||||
#ifdef DEBUG_PLC
|
||||
#define printf_plc(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define printf_plc(...) (void)(0);
|
||||
#endif
|
||||
|
||||
// max config
|
||||
#define MAX_CHANNELS 2
|
||||
#define MAX_SAMPLES_PER_FRAME 480
|
||||
@ -138,6 +145,7 @@ static bool cis_established[MAX_CHANNELS];
|
||||
static unsigned int next_cis_index;
|
||||
|
||||
// analysis
|
||||
static bool last_packet_received[MAX_CHANNELS];
|
||||
static uint16_t last_packet_sequence[MAX_CHANNELS];
|
||||
static uint32_t last_packet_time_ms[MAX_CHANNELS];
|
||||
static uint8_t last_packet_prefix[MAX_CHANNELS * PACKET_PREFIX_LEN];
|
||||
@ -427,6 +435,10 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
printf("\n");
|
||||
next_cis_index = 0;
|
||||
|
||||
memset(last_packet_sequence, 0, sizeof(last_packet_sequence));
|
||||
memset(last_packet_received, 0, sizeof(last_packet_received));
|
||||
memset(pcm, 0, sizeof(pcm));
|
||||
|
||||
printf("Create CIS\n");
|
||||
hci_con_handle_t acl_connection_handles[MAX_CHANNELS];
|
||||
for (i=0; i < num_cis; i++){
|
||||
@ -479,13 +491,7 @@ static void store_samples_in_ringbuffer(void){
|
||||
}
|
||||
}
|
||||
|
||||
static void plc_timeout(btstack_timer_source_t * timer) {
|
||||
// set timer again
|
||||
uint32_t frame_duration_ms = frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? 8 : 10;
|
||||
btstack_run_loop_set_timer(&next_packet_timer, frame_duration_ms);
|
||||
btstack_run_loop_set_timer_handler(&next_packet_timer, plc_timeout);
|
||||
btstack_run_loop_add_timer(&next_packet_timer);
|
||||
|
||||
static void plc_do(void) {
|
||||
// inject packet
|
||||
uint8_t tmp_BEC_detect;
|
||||
uint8_t BFI = 1;
|
||||
@ -499,6 +505,17 @@ static void plc_timeout(btstack_timer_source_t * timer) {
|
||||
store_samples_in_ringbuffer();
|
||||
}
|
||||
|
||||
static void plc_timeout(btstack_timer_source_t * timer) {
|
||||
// set timer again
|
||||
uint32_t frame_duration_ms = frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? 8 : 10;
|
||||
btstack_run_loop_set_timer(&next_packet_timer, frame_duration_ms);
|
||||
btstack_run_loop_set_timer_handler(&next_packet_timer, plc_timeout);
|
||||
btstack_run_loop_add_timer(&next_packet_timer);
|
||||
|
||||
printf_plc("- ISO, PLC for timeout\n");
|
||||
plc_do();
|
||||
}
|
||||
|
||||
static void iso_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
|
||||
uint16_t header = little_endian_read_16(packet, 0);
|
||||
@ -514,6 +531,8 @@ static void iso_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
offset += 4;
|
||||
}
|
||||
|
||||
uint32_t receive_time_ms = btstack_run_loop_get_time_ms();
|
||||
|
||||
uint16_t packet_sequence_number = little_endian_read_16(packet, offset);
|
||||
offset += 2;
|
||||
|
||||
@ -562,6 +581,37 @@ static void iso_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
|
||||
} else {
|
||||
|
||||
if (last_packet_received[cis_channel]) {
|
||||
printf_plc("ISO, receive %u\n", packet_sequence_number);
|
||||
|
||||
int16_t packet_sequence_delta = btstack_time16_delta(packet_sequence_number,
|
||||
last_packet_sequence[cis_channel]);
|
||||
if (packet_sequence_delta < 1) {
|
||||
// drop delayed packet that had already been generated by PLC
|
||||
printf_plc("- dropping delayed packet. Current sequence number %u, last received or generated by PLC: %u\n",
|
||||
packet_sequence_number, last_packet_sequence[cis_channel]);
|
||||
return;
|
||||
}
|
||||
// simple check
|
||||
if (packet_sequence_number != last_packet_sequence[cis_channel] + 1) {
|
||||
printf_plc("- BIS #%u, missing %u\n", cis_channel, last_packet_sequence[cis_channel] + 1);
|
||||
}
|
||||
} else {
|
||||
printf_plc("BIS %u, first packet seq number %u\n", cis_channel, packet_sequence_number);
|
||||
last_packet_received[cis_channel] = true;
|
||||
}
|
||||
|
||||
// PLC for missing packets
|
||||
while (true) {
|
||||
uint16_t expected = last_packet_sequence[cis_channel]+1;
|
||||
if (expected == packet_sequence_number){
|
||||
break;
|
||||
}
|
||||
printf_plc("- ISO, PLC for %u\n", expected);
|
||||
plc_do();
|
||||
last_packet_sequence[cis_channel] = expected;
|
||||
}
|
||||
|
||||
uint8_t channel;
|
||||
for (channel = 0 ; channel < num_channels ; channel++){
|
||||
|
||||
@ -584,8 +634,9 @@ static void iso_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
// PLC
|
||||
cached_iso_sdu_len = iso_sdu_length;
|
||||
uint32_t frame_duration_ms = frame_duration == BTSTACK_LC3_FRAME_DURATION_7500US ? 8 : 10;
|
||||
uint32_t timeout_ms = frame_duration_ms * 5 / 2;
|
||||
btstack_run_loop_remove_timer(&next_packet_timer);
|
||||
btstack_run_loop_set_timer(&next_packet_timer, frame_duration_ms + PLC_GUARD_MS);
|
||||
btstack_run_loop_set_timer(&next_packet_timer, timeout_ms);
|
||||
btstack_run_loop_set_timer_handler(&next_packet_timer, plc_timeout);
|
||||
btstack_run_loop_add_timer(&next_packet_timer);
|
||||
|
||||
@ -602,6 +653,9 @@ static void iso_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
samples_received = 0;
|
||||
samples_dropped = 0;
|
||||
}
|
||||
|
||||
last_packet_time_ms[cis_channel] = receive_time_ms;
|
||||
last_packet_sequence[cis_channel] = packet_sequence_number;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user