mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-15 22:20:59 +00:00
hfp: send VRA activated event after audio is established
This commit is contained in:
parent
fd66594d81
commit
84fb9ac151
@ -632,6 +632,7 @@ typedef struct hfp_connection {
|
||||
uint8_t send_ag_indicators_segment;
|
||||
uint8_t send_response_and_hold_status; // 0 - don't send. BRTH:0 == 1, ..
|
||||
|
||||
bool emit_vra_enabled_after_audio_established;
|
||||
// AG only
|
||||
uint8_t change_in_band_ring_tone_setting;
|
||||
uint8_t ag_ring;
|
||||
|
@ -905,11 +905,16 @@ static uint8_t hfp_ag_vra_state_machine_two(hfp_connection_t * hfp_connection){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hfp_connection->vra_state = HFP_VRA_VOICE_RECOGNITION_ACTIVATED;
|
||||
hfp_connection->vra_state_requested = hfp_connection->vra_state;
|
||||
hfp_connection->enhanced_voice_recognition_enabled = hfp_ag_enhanced_vra_flag_supported(hfp_connection);
|
||||
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
|
||||
|
||||
if (hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED){
|
||||
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
|
||||
} else {
|
||||
hfp_connection->emit_vra_enabled_after_audio_established = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -2136,9 +2141,14 @@ static void hfp_ag_run_for_context(hfp_connection_t *hfp_connection){
|
||||
// during SDP query, RFCOMM CID is not set
|
||||
if (hfp_connection->rfcomm_cid == 0) return;
|
||||
|
||||
if (hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED && hfp_connection->emit_vra_enabled_after_audio_established){
|
||||
hfp_connection->emit_vra_enabled_after_audio_established = false;
|
||||
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
// assert command could be sent
|
||||
if (hci_can_send_command_packet_now() == 0) return;
|
||||
|
||||
|
||||
if ((hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED) && hfp_connection->release_audio_connection){
|
||||
hfp_connection->state = HFP_W4_SCO_DISCONNECTED;
|
||||
hfp_connection->release_audio_connection = 0;
|
||||
@ -2825,6 +2835,10 @@ uint8_t hfp_ag_activate_voice_recognition(hci_con_handle_t acl_handle){
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
}
|
||||
|
||||
if (hfp_connection->emit_vra_enabled_after_audio_established){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
bool enhanced_vra_supported = hfp_ag_enhanced_vra_flag_supported(hfp_connection);
|
||||
bool legacy_vra_supported = hfp_ag_vra_flag_supported(hfp_connection);
|
||||
if (!enhanced_vra_supported && !legacy_vra_supported){
|
||||
@ -2851,6 +2865,10 @@ uint8_t hfp_ag_deactivate_voice_recognition(hci_con_handle_t acl_handle){
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
}
|
||||
|
||||
if (hfp_connection->emit_vra_enabled_after_audio_established){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
bool enhanced_vra_supported = hfp_ag_enhanced_vra_flag_supported(hfp_connection);
|
||||
bool legacy_vra_supported = hfp_ag_vra_flag_supported(hfp_connection);
|
||||
|
||||
@ -2875,19 +2893,24 @@ static uint8_t hfp_ag_enhanced_voice_recognition_send_state(hci_con_handle_t acl
|
||||
if (!hfp_connection){
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
}
|
||||
|
||||
if (hfp_connection->emit_vra_enabled_after_audio_established){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (hfp_connection->state != HFP_AUDIO_CONNECTION_ESTABLISHED){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (hfp_connection->vra_state != HFP_VRA_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
bool enhanced_vra_supported = hfp_ag_enhanced_vra_flag_supported(hfp_connection);
|
||||
if (!enhanced_vra_supported ){
|
||||
return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
|
||||
}
|
||||
|
||||
if (hfp_connection->state != HFP_AUDIO_CONNECTION_ESTABLISHED){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (hfp_connection->vra_state != HFP_VRA_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
hfp_connection->ag_vra_state = state;
|
||||
hfp_connection->vra_state_requested = HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_STATUS;
|
||||
@ -2912,6 +2935,18 @@ uint8_t hfp_ag_enhanced_voice_recognition_send_message(hci_con_handle_t acl_hand
|
||||
if (!hfp_connection){
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
}
|
||||
|
||||
if (hfp_connection->emit_vra_enabled_after_audio_established){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (hfp_connection->state != HFP_AUDIO_CONNECTION_ESTABLISHED){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (hfp_connection->vra_state != HFP_VRA_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
bool enhanced_vra_supported = hfp_ag_enhanced_vra_flag_supported(hfp_connection);
|
||||
if (!enhanced_vra_supported ){
|
||||
@ -2923,14 +2958,6 @@ uint8_t hfp_ag_enhanced_voice_recognition_send_message(hci_con_handle_t acl_hand
|
||||
return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
|
||||
}
|
||||
|
||||
if (hfp_connection->state != HFP_AUDIO_CONNECTION_ESTABLISHED){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (hfp_connection->vra_state != HFP_VRA_ENHANCED_VOICE_RECOGNITION_READY_FOR_AUDIO){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
uint16_t message_len = strlen(msg.text);
|
||||
|
||||
if (message_len > HFP_MAX_VR_TEXT_SIZE){
|
||||
|
@ -630,7 +630,12 @@ static int hfp_hf_voice_recognition_state_machine(hfp_connection_t * hfp_connect
|
||||
hfp_hf_deactivate_voice_recognition(hfp_connection->acl_handle);
|
||||
} else {
|
||||
hfp_connection->enhanced_voice_recognition_enabled = hfp_hf_enhanced_vra_flag_supported(hfp_connection);
|
||||
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
|
||||
if (hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED){
|
||||
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
|
||||
} else {
|
||||
// postpone VRA event to simplify application logic
|
||||
hfp_connection->emit_vra_enabled_after_audio_established = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -731,6 +736,12 @@ static void hfp_hf_run_for_context(hfp_connection_t * hfp_connection){
|
||||
// during SDP query, RFCOMM CID is not set
|
||||
if (hfp_connection->rfcomm_cid == 0) return;
|
||||
|
||||
// emit postponed VRA event
|
||||
if (hfp_connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED && hfp_connection->emit_vra_enabled_after_audio_established){
|
||||
hfp_connection->emit_vra_enabled_after_audio_established = false;
|
||||
hfp_emit_voice_recognition_enabled(hfp_connection, ERROR_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
// assert command could be sent
|
||||
if (hci_can_send_command_packet_now() == 0) return;
|
||||
|
||||
@ -1903,6 +1914,11 @@ uint8_t hfp_hf_enhanced_voice_recognition_report_ready_for_audio(hci_con_handle_
|
||||
if (!hfp_connection) {
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
}
|
||||
|
||||
if (hfp_connection->emit_vra_enabled_after_audio_established){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (hfp_connection->state != HFP_AUDIO_CONNECTION_ESTABLISHED){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
@ -1932,6 +1948,10 @@ uint8_t hfp_hf_deactivate_voice_recognition(hci_con_handle_t acl_handle){
|
||||
if (!hfp_connection) {
|
||||
return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
}
|
||||
|
||||
if (hfp_connection->emit_vra_enabled_after_audio_established){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
|
||||
if (hfp_connection->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED ||
|
||||
hfp_connection->state > HFP_AUDIO_CONNECTION_ESTABLISHED){
|
||||
|
Loading…
x
Reference in New Issue
Block a user