mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-03 07:13:51 +00:00
hfp: extract hfp_next_link_setting
This commit is contained in:
parent
ebc6f15b2a
commit
e453c1d946
@ -1640,25 +1640,29 @@ uint16_t hfp_get_sco_packet_types(void){
|
||||
return hfp_accept_sco_packet_types;
|
||||
}
|
||||
|
||||
void hfp_init_link_settings(hfp_connection_t * hfp_connection, uint8_t esco_s4_supported){
|
||||
// determine highest possible link setting
|
||||
hfp_connection->link_setting = HFP_LINK_SETTINGS_D1;
|
||||
// anything else requires eSCO support on both sides
|
||||
if (hci_extended_sco_link_supported() && hci_remote_esco_supported(hfp_connection->acl_handle)){
|
||||
switch (hfp_connection->negotiated_codec){
|
||||
case HFP_CODEC_CVSD:
|
||||
hfp_connection->link_setting = HFP_LINK_SETTINGS_S3;
|
||||
if (esco_s4_supported){
|
||||
hfp_connection->link_setting = HFP_LINK_SETTINGS_S4;
|
||||
}
|
||||
break;
|
||||
case HFP_CODEC_MSBC:
|
||||
hfp_connection->link_setting = HFP_LINK_SETTINGS_T2;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
hfp_link_settings_t hfp_next_link_setting(hfp_link_settings_t current_setting, bool local_eSCO_supported, bool remote_eSCO_supported, bool eSCO_S4_supported, uint8_t negotiated_codec){
|
||||
int8_t setting = (int8_t) current_setting;
|
||||
bool can_use_eSCO = local_eSCO_supported && remote_eSCO_supported;
|
||||
while (setting > 0){
|
||||
setting--;
|
||||
// skip if eSCO required but not available
|
||||
if (hfp_link_settings[setting].eSCO && !can_use_eSCO) continue;
|
||||
// skip if S4 but not supported
|
||||
if ((setting == (int8_t) HFP_LINK_SETTINGS_S4) && !eSCO_S4_supported) continue;
|
||||
// skip wrong codec
|
||||
if ( hfp_link_settings[setting].codec != negotiated_codec) continue;
|
||||
// found matching setting
|
||||
return (hfp_link_settings_t) setting;
|
||||
}
|
||||
return HFP_LINK_SETTINGS_NONE;
|
||||
}
|
||||
|
||||
void hfp_init_link_settings(hfp_connection_t * hfp_connection, uint8_t eSCO_S4_supported){
|
||||
bool local_eSCO_supported = hci_extended_sco_link_supported();
|
||||
bool remote_eSCO_supported = hci_remote_esco_supported(hfp_connection->acl_handle);
|
||||
uint8_t negotiated_codec = hfp_connection->negotiated_codec;
|
||||
// get highest possible link setting
|
||||
hfp_connection->link_setting = hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, local_eSCO_supported, remote_eSCO_supported, eSCO_S4_supported, negotiated_codec);
|
||||
log_info("hfp_init_link_settings: %u", hfp_connection->link_setting);
|
||||
}
|
||||
|
||||
|
@ -692,7 +692,8 @@ void hfp_release_audio_connection(hfp_connection_t * connection);
|
||||
void hfp_setup_synchronous_connection(hfp_connection_t * connection);
|
||||
int hfp_supports_codec(uint8_t codec, int codecs_nr, uint8_t * codecs);
|
||||
void hfp_hf_drop_mSBC_if_eSCO_not_supported(uint8_t * codecs, uint8_t * codecs_nr);
|
||||
void hfp_init_link_settings(hfp_connection_t * hfp_connection, uint8_t esco_s4_supported);
|
||||
void hfp_init_link_settings(hfp_connection_t * hfp_connection, uint8_t eSCO_S4_supported);
|
||||
hfp_link_settings_t hfp_next_link_setting(hfp_link_settings_t current_setting, bool local_eSCO_supported, bool remote_eSCO_supported, bool eSCO_s4_supported, uint8_t negotiated_codec);
|
||||
|
||||
const char * hfp_hf_feature(int index);
|
||||
const char * hfp_ag_feature(int index);
|
||||
|
@ -55,7 +55,7 @@ CFLAGS += -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/src/classic -I${POS
|
||||
# CFLAGS += -fprofile-arcs -ftest-coverage -fsanitize=address
|
||||
LDFLAGS_CPPUTEST += -lCppUTest -lCppUTestExt
|
||||
|
||||
EXAMPLES = hfp_at_parser_test hfp_ag_client_test hfp_hf_client_test cvsd_plc_test pklg_cvsd_test
|
||||
EXAMPLES = hfp_at_parser_test hfp_ag_client_test hfp_hf_client_test cvsd_plc_test pklg_cvsd_test hfp_link_settings_test
|
||||
|
||||
all: ${EXAMPLES}
|
||||
|
||||
@ -78,12 +78,16 @@ cvsd_plc_test: ${COMMON_OBJ} btstack_cvsd_plc.o wav_util.o cvsd_plc_test.c
|
||||
pklg_cvsd_test: hci_dump.o btstack_util.o btstack_cvsd_plc.o wav_util.o pklg_cvsd_test.o
|
||||
${CC} $^ ${CFLAGS} -o $@
|
||||
|
||||
hfp_link_settings_test: ${MOCK_OBJ} hfp_hf.o hfp.o hfp_link_settings_test.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS_CPPUTEST} -o $@
|
||||
|
||||
test: all
|
||||
mkdir -p results
|
||||
./hfp_at_parser_test
|
||||
./hfp_ag_client_test
|
||||
./hfp_hf_client_test
|
||||
./cvsd_plc_test
|
||||
./hfp_link_settings_test
|
||||
|
||||
pklg-test: pklg_cvsd_test
|
||||
./pklg_cvsd_test pklg/test1
|
||||
|
38
test/hfp/hfp_link_settings_test.c
Normal file
38
test/hfp/hfp_link_settings_test.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
|
||||
#include "classic/hfp.h"
|
||||
|
||||
#include "mock.h"
|
||||
|
||||
TEST_GROUP(HFPLinkSettings){
|
||||
void setup(void){
|
||||
}
|
||||
void teardown(void){
|
||||
}
|
||||
};
|
||||
|
||||
TEST(HFPLinkSettings, NONE){
|
||||
CHECK_EQUAL(HFP_LINK_SETTINGS_NONE, hfp_next_link_setting(HFP_LINK_SETTINGS_D1, false, true, true, HFP_CODEC_MSBC));
|
||||
}
|
||||
|
||||
TEST(HFPLinkSettings, D1){
|
||||
CHECK_EQUAL(HFP_LINK_SETTINGS_D1, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, false, true, true, HFP_CODEC_CVSD));
|
||||
CHECK_EQUAL(HFP_LINK_SETTINGS_D1, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, false, true, HFP_CODEC_CVSD));
|
||||
}
|
||||
|
||||
TEST(HFPLinkSettings, S3){
|
||||
CHECK_EQUAL(HFP_LINK_SETTINGS_S3, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, false, HFP_CODEC_CVSD));
|
||||
}
|
||||
|
||||
TEST(HFPLinkSettings, S4){
|
||||
CHECK_EQUAL(HFP_LINK_SETTINGS_S4, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, true, HFP_CODEC_CVSD));
|
||||
}
|
||||
|
||||
TEST(HFPLinkSettings, T2){
|
||||
CHECK_EQUAL(HFP_LINK_SETTINGS_T2, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, true, HFP_CODEC_MSBC));
|
||||
}
|
||||
|
||||
int main (int argc, const char * argv[]){
|
||||
return CommandLineTestRunner::RunAllTests(argc, argv);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user