mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(bt): Fix compatibility with A2DP API legacy usage methods
- Modify the timing of API calls in the A2DP example - Closes https://github.com/espressif/esp-idf/issues/18786
This commit is contained in:
@@ -14,6 +14,13 @@
|
||||
|
||||
#if BTC_AV_INCLUDED
|
||||
|
||||
// indicate the first time to call the register SEP function (for sink)
|
||||
static bool s_a2dp_sink_first_call_reg_sep[ESP_A2D_MAX_SEPS] = { [0 ... (ESP_A2D_MAX_SEPS - 1)] = true };
|
||||
// indicate the first time to call the register SEP function (for source)
|
||||
static bool s_a2dp_src_first_call_reg_sep[ESP_A2D_MAX_SEPS] = { [0 ... (ESP_A2D_MAX_SEPS - 1)] = true };
|
||||
// indicate the first time to call the get delay value function
|
||||
static bool s_a2dp_first_call_get_delay = true;
|
||||
|
||||
esp_a2d_audio_buff_t *esp_a2d_audio_buff_alloc(uint16_t size)
|
||||
{
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
@@ -73,14 +80,21 @@ esp_err_t esp_a2d_sink_register_stream_endpoint(uint8_t seid, const esp_a2d_mcc_
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (g_a2dp_on_deinit || g_a2dp_sink_ongoing_deinit) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (mcc == NULL || seid >= ESP_A2D_MAX_SEPS) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* To be compatible with the legacy usage methods,
|
||||
use a flag indicating whether this is the first time the function has been called. */
|
||||
if (s_a2dp_sink_first_call_reg_sep[seid]) {
|
||||
s_a2dp_sink_first_call_reg_sep[seid] = false;
|
||||
if (g_a2dp_sink_ongoing_deinit) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else if (g_a2dp_on_deinit || g_a2dp_sink_ongoing_deinit) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
btc_msg_t msg;
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_A2DP;
|
||||
@@ -114,7 +128,15 @@ esp_err_t esp_a2d_sink_deinit(void)
|
||||
|
||||
/* Switch to BTC context */
|
||||
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL, NULL);
|
||||
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
if (stat == BT_STATUS_SUCCESS) {
|
||||
for (int i = 0; i < ESP_A2D_MAX_SEPS; i++) {
|
||||
s_a2dp_sink_first_call_reg_sep[i] = false;
|
||||
}
|
||||
s_a2dp_first_call_get_delay = false;
|
||||
return ESP_OK;
|
||||
} else {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_a2d_sink_register_data_callback(esp_a2d_sink_data_cb_t callback)
|
||||
@@ -248,7 +270,14 @@ esp_err_t esp_a2d_sink_get_delay_value(void)
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (g_a2dp_on_deinit || g_a2dp_sink_ongoing_deinit) {
|
||||
/* To be compatible with the legacy usage methods,
|
||||
use a flag indicating whether this is the first time the function has been called. */
|
||||
if (s_a2dp_first_call_get_delay) {
|
||||
s_a2dp_first_call_get_delay = false;
|
||||
if (g_a2dp_sink_ongoing_deinit) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else if (g_a2dp_on_deinit || g_a2dp_sink_ongoing_deinit) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
@@ -385,14 +414,21 @@ esp_err_t esp_a2d_source_register_stream_endpoint(uint8_t seid, const esp_a2d_mc
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (g_a2dp_on_deinit || g_a2dp_source_ongoing_deinit) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (mcc == NULL || seid >= ESP_A2D_MAX_SEPS) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* To be compatible with the legacy usage methods,
|
||||
use a flag indicating whether this is the first time the function has been called. */
|
||||
if (s_a2dp_src_first_call_reg_sep[seid]) {
|
||||
s_a2dp_src_first_call_reg_sep[seid] = false;
|
||||
if (g_a2dp_source_ongoing_deinit) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
} else if (g_a2dp_on_deinit || g_a2dp_source_ongoing_deinit) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
btc_msg_t msg;
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_A2DP;
|
||||
@@ -426,7 +462,14 @@ esp_err_t esp_a2d_source_deinit(void)
|
||||
|
||||
/* Switch to BTC context */
|
||||
bt_status_t stat = btc_transfer_context(&msg, NULL, 0, NULL, NULL);
|
||||
return (stat == BT_STATUS_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
if (stat == BT_STATUS_SUCCESS) {
|
||||
for (int i = 0; i < ESP_A2D_MAX_SEPS; i++) {
|
||||
s_a2dp_src_first_call_reg_sep[i] = false;
|
||||
}
|
||||
return ESP_OK;
|
||||
} else {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_a2d_source_connect(esp_bd_addr_t remote_bda)
|
||||
|
||||
Reference in New Issue
Block a user