Merge branch 'bugfix/fix_hfp_api_status_check_v6.1' into 'release/v6.1'

fix(bt/bluedroid): check HFP audio status before forwarding SCO data (v6.1)

See merge request espressif/esp-idf!52889
This commit is contained in:
Jiang Jiang Jian
2026-09-20 10:43:27 +08:00
6 changed files with 26 additions and 4 deletions

View File

@@ -645,9 +645,11 @@ esp_err_t esp_hf_client_audio_data_send(esp_hf_sync_conn_hdl_t sync_conn_hdl, es
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
BTA_HfClientAudioDataSend(sync_conn_hdl, (uint8_t *)audio_buf, audio_buf->data, audio_buf->data_len); if (btc_hf_client_audio_data_send(sync_conn_hdl, (uint8_t *)audio_buf, audio_buf->data, audio_buf->data_len) == BT_STATUS_SUCCESS) {
return ESP_OK; return ESP_OK;
} }
return ESP_FAIL;
}
esp_err_t esp_hf_client_pcm_resample_init(uint32_t src_sps, uint32_t bits, uint32_t channels) esp_err_t esp_hf_client_pcm_resample_init(uint32_t src_sps, uint32_t bits, uint32_t channels)
{ {

View File

@@ -689,6 +689,8 @@ void esp_hf_ag_audio_buff_free(esp_hf_audio_buff_t *audio_buf);
* If the length of the audio data is equal to preferred_frame_size indicated by * If the length of the audio data is equal to preferred_frame_size indicated by
* ESP_HF_AUDIO_STATE_EVT, then we can reduce one memory copy inside the Bluedroid stack. * ESP_HF_AUDIO_STATE_EVT, then we can reduce one memory copy inside the Bluedroid stack.
* This function is only used in the case that Voice Over HCI is enabled. * This function is only used in the case that Voice Over HCI is enabled.
* On success, the stack takes ownership of audio_buf and will free it internally.
* On failure, the caller is responsible for freeing audio_buf with esp_hf_ag_audio_buff_free.
* *
* @param[in] sync_conn_hdl: (e)SCO connection handle * @param[in] sync_conn_hdl: (e)SCO connection handle
* *

View File

@@ -715,6 +715,8 @@ void esp_hf_client_audio_buff_free(esp_hf_audio_buff_t *audio_buf);
* If the length of the audio data is equal to preferred_frame_size indicated by * If the length of the audio data is equal to preferred_frame_size indicated by
* ESP_HF_CLIENT_AUDIO_STATE_EVT, then we can reduce one memory copy inside the Bluedroid stack. * ESP_HF_CLIENT_AUDIO_STATE_EVT, then we can reduce one memory copy inside the Bluedroid stack.
* This function is only used in the case that Voice Over HCI is enabled. * This function is only used in the case that Voice Over HCI is enabled.
* On success, the stack takes ownership of audio_buf and will free it internally.
* On failure, the caller is responsible for freeing audio_buf with esp_hf_client_audio_buff_free.
* *
* @param[in] sync_conn_hdl: (e)SCO connection handle * @param[in] sync_conn_hdl: (e)SCO connection handle
* *
@@ -724,6 +726,7 @@ void esp_hf_client_audio_buff_free(esp_hf_audio_buff_t *audio_buf);
* - ESP_OK: success * - ESP_OK: success
* - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled * - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
* - ESP_ERR_INVALID_ARG: invalid parameter * - ESP_ERR_INVALID_ARG: invalid parameter
* - ESP_FAIL: others
* *
*/ */
esp_err_t esp_hf_client_audio_data_send(esp_hf_sync_conn_hdl_t sync_conn_hdl, esp_hf_audio_buff_t *audio_buf); esp_err_t esp_hf_client_audio_data_send(esp_hf_sync_conn_hdl_t sync_conn_hdl, esp_hf_audio_buff_t *audio_buf);

View File

@@ -964,10 +964,10 @@ bt_status_t btc_hf_ci_sco_data(void)
bt_status_t btc_hf_ag_audio_data_send(uint16_t sync_conn_hdl, uint8_t *p_buff_start, uint8_t *p_data, uint8_t data_len) bt_status_t btc_hf_ag_audio_data_send(uint16_t sync_conn_hdl, uint8_t *p_buff_start, uint8_t *p_data, uint8_t data_len)
{ {
#if (BTM_SCO_HCI_INCLUDED == TRUE) && (BTA_HFP_EXT_CODEC == TRUE) #if (BTM_SCO_HCI_INCLUDED == TRUE) && (BTA_HFP_EXT_CODEC == TRUE)
/* currently, sync_conn_hdl is not used */
int idx = btc_hf_latest_connected_idx(); int idx = btc_hf_latest_connected_idx();
CHECK_HF_SLC_CONNECTED(idx); CHECK_HF_SLC_CONNECTED(idx);
if (idx != BTC_HF_INVALID_IDX) {
if (sync_conn_hdl != ESP_INVALID_CONN_HANDLE && hf_local_param.btc_hf_cb[idx].sync_conn_hdl == sync_conn_hdl) {
BTA_AgAudioDataSend(hf_local_param.btc_hf_cb[idx].handle, p_buff_start, p_data, data_len); BTA_AgAudioDataSend(hf_local_param.btc_hf_cb[idx].handle, p_buff_start, p_data, data_len);
return BT_STATUS_SUCCESS; return BT_STATUS_SUCCESS;
} }

View File

@@ -352,6 +352,19 @@ bt_status_t btc_hf_client_disconnect_audio( bt_bdaddr_t *bd_addr )
return BT_STATUS_FAIL; return BT_STATUS_FAIL;
} }
bt_status_t btc_hf_client_audio_data_send(uint16_t sync_conn_hdl, uint8_t *p_buff_start, uint8_t *p_data, uint8_t data_len)
{
#if (BTM_SCO_HCI_INCLUDED == TRUE) && (BTA_HFP_EXT_CODEC == TRUE)
CHECK_HF_CLIENT_SLC_CONNECTED();
if (sync_conn_hdl != ESP_INVALID_CONN_HANDLE && hf_client_local_param.btc_hf_client_cb.sync_conn_hdl == sync_conn_hdl) {
BTA_HfClientAudioDataSend(sync_conn_hdl, p_buff_start, p_data, data_len);
return BT_STATUS_SUCCESS;
}
#endif
return BT_STATUS_FAIL;
}
/******************************************************************************* /*******************************************************************************
** **
** Function btc_hf_client_start_voice_recognition ** Function btc_hf_client_start_voice_recognition

View File

@@ -176,6 +176,8 @@ void btc_hf_client_incoming_data_cb_to_app(const uint8_t *data, uint32_t len);
uint32_t btc_hf_client_outgoing_data_cb_to_app(uint8_t *data, uint32_t len); uint32_t btc_hf_client_outgoing_data_cb_to_app(uint8_t *data, uint32_t len);
bt_status_t btc_hf_client_audio_data_send(uint16_t sync_conn_hdl, uint8_t *p_buff_start, uint8_t *p_data, uint8_t data_len);
void btc_hf_client_get_profile_status(esp_hf_client_profile_status_t *param); void btc_hf_client_get_profile_status(esp_hf_client_profile_status_t *param);
#endif ///BTC_HF_CLIENT_INCLUDED == TRUE #endif ///BTC_HF_CLIENT_INCLUDED == TRUE