mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-11 00:44:27 +00:00
btstack_sbc_decoder_bluedroid: extract btstack_sbc_decoder_bluedroid_simulate_error and btstack_sbc_decoder_insert_missing_frames
This commit is contained in:
parent
371c4c5822
commit
5c7e2c7474
@ -208,6 +208,17 @@ static void append_received_sbc_data(bludroid_decoder_state_t * state, uint8_t *
|
||||
state->bytes_in_frame_buffer += size;
|
||||
}
|
||||
|
||||
void btstack_sbc_decoder_bluedroid_simulate_error(const OI_BYTE *frame_data) {
|
||||
static int frame_count = 0;
|
||||
if (corrupt_frame_period > 0){
|
||||
frame_count++;
|
||||
|
||||
if ((frame_count % corrupt_frame_period) == 0){
|
||||
*(uint8_t*)&frame_data[5] = 0;
|
||||
frame_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void btstack_sbc_decoder_process_sbc_data(btstack_sbc_decoder_state_t * state, uint8_t * buffer, int size){
|
||||
bludroid_decoder_state_t * decoder_state = (bludroid_decoder_state_t*)state->decoder_state;
|
||||
@ -236,15 +247,7 @@ static void btstack_sbc_decoder_process_sbc_data(btstack_sbc_decoder_state_t * s
|
||||
uint16_t bytes_processed = bytes_in_frame_buffer_before_decoding - frame_data_len;
|
||||
|
||||
// testing only - corrupt frame periodically
|
||||
static int frame_count = 0;
|
||||
if (corrupt_frame_period > 0){
|
||||
frame_count++;
|
||||
|
||||
if ((frame_count % corrupt_frame_period) == 0){
|
||||
*(uint8_t*)&frame_data[5] = 0;
|
||||
frame_count = 0;
|
||||
}
|
||||
}
|
||||
btstack_sbc_decoder_bluedroid_simulate_error(frame_data);
|
||||
|
||||
// Handle decoding result.
|
||||
switch(status){
|
||||
@ -319,14 +322,10 @@ static void btstack_sbc_decoder_process_sbc_data(btstack_sbc_decoder_state_t * s
|
||||
}
|
||||
|
||||
|
||||
static void btstack_sbc_decoder_process_msbc_data(btstack_sbc_decoder_state_t * state, int packet_status_flag, uint8_t * buffer, int size){
|
||||
void btstack_sbc_decoder_insert_missing_frames(btstack_sbc_decoder_state_t *state) {
|
||||
bludroid_decoder_state_t * decoder_state = (bludroid_decoder_state_t*)state->decoder_state;
|
||||
int input_bytes_to_process = size;
|
||||
unsigned int MSBC_FRAME_SIZE = 60;
|
||||
const unsigned int MSBC_FRAME_SIZE = 60;
|
||||
|
||||
while (input_bytes_to_process > 0){
|
||||
|
||||
// Use PLC to insert missing frames (after first sync found)
|
||||
while (decoder_state->first_good_frame_found && (decoder_state->msbc_bad_bytes >= MSBC_FRAME_SIZE)){
|
||||
|
||||
decoder_state->msbc_bad_bytes -= MSBC_FRAME_SIZE;
|
||||
@ -364,7 +363,17 @@ static void btstack_sbc_decoder_process_msbc_data(btstack_sbc_decoder_state_t *
|
||||
btstack_sbc_decoder_num_channels(state),
|
||||
btstack_sbc_decoder_sample_rate(state), state->context);
|
||||
}
|
||||
}
|
||||
|
||||
static void btstack_sbc_decoder_process_msbc_data(btstack_sbc_decoder_state_t * state, int packet_status_flag, uint8_t * buffer, int size){
|
||||
bludroid_decoder_state_t * decoder_state = (bludroid_decoder_state_t*)state->decoder_state;
|
||||
int input_bytes_to_process = size;
|
||||
const unsigned int MSBC_FRAME_SIZE = 60;
|
||||
|
||||
while (input_bytes_to_process > 0){
|
||||
|
||||
// Use PLC to insert missing frames (after first sync found)
|
||||
btstack_sbc_decoder_insert_missing_frames(state);
|
||||
|
||||
// fill buffer with new data
|
||||
int bytes_missing_for_complete_msbc_frame = MSBC_FRAME_SIZE - decoder_state->bytes_in_frame_buffer;
|
||||
@ -383,15 +392,7 @@ static void btstack_sbc_decoder_process_msbc_data(btstack_sbc_decoder_state_t *
|
||||
const OI_BYTE *frame_data = decoder_state->frame_buffer;
|
||||
|
||||
// testing only - corrupt frame periodically
|
||||
static int frame_count = 0;
|
||||
if (corrupt_frame_period > 0){
|
||||
frame_count++;
|
||||
|
||||
if ((frame_count % corrupt_frame_period) == 0){
|
||||
*(uint8_t*)&frame_data[5] = 0;
|
||||
frame_count = 0;
|
||||
}
|
||||
}
|
||||
btstack_sbc_decoder_bluedroid_simulate_error(frame_data);
|
||||
|
||||
// assert frame looks like this: 01 x8 AD [rest of frame 56 bytes] 00
|
||||
int h2_syncword = 0;
|
||||
@ -487,19 +488,6 @@ static void btstack_sbc_decoder_process_msbc_data(btstack_sbc_decoder_state_t *
|
||||
state->good_frames_nr++;
|
||||
continue;
|
||||
|
||||
case OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA:
|
||||
log_info("OI_CODEC_SBC_NOT_ENOUGH_HEADER_DATA");
|
||||
break;
|
||||
case OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA:
|
||||
log_debug("OI_CODEC_SBC_NOT_ENOUGH_BODY_DATA");
|
||||
break;
|
||||
case OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA:
|
||||
log_info("OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA");
|
||||
break;
|
||||
case OI_CODEC_SBC_NO_SYNCWORD:
|
||||
log_info("OI_CODEC_SBC_NO_SYNCWORD");
|
||||
break;
|
||||
|
||||
case OI_CODEC_SBC_CHECKSUM_MISMATCH:
|
||||
// The next frame is somehow corrupt.
|
||||
log_debug("OI_CODEC_SBC_CHECKSUM_MISMATCH");
|
||||
|
Loading…
x
Reference in New Issue
Block a user