components/bt: Fix AVRCP command will not be executed while playing music

This commit is contained in:
baohongde 2019-07-05 19:53:56 +08:00 committed by bot
parent 596209de69
commit f048be924c
9 changed files with 126 additions and 10 deletions

View File

@ -166,7 +166,7 @@ static bt_status_t btc_task_post(btc_msg_t *msg, uint32_t timeout)
memcpy(lmsg, msg, sizeof(btc_msg_t));
if (osi_thread_post(btc_thread, btc_thread_handler, lmsg, 2, timeout) == false) {
if (osi_thread_post(btc_thread, btc_thread_handler, lmsg, 0, timeout) == false) {
return BT_STATUS_BUSY;
}
@ -359,7 +359,7 @@ void btc_deinit(void)
bool btc_check_queue_is_congest(void)
{
if (osi_thread_queue_wait_size(btc_thread, 2) >= BT_QUEUE_CONGEST_SIZE) {
if (osi_thread_queue_wait_size(btc_thread, 0) >= BT_QUEUE_CONGEST_SIZE) {
return true;
}

View File

@ -182,7 +182,7 @@ static bool btc_a2dp_sink_ctrl_post(uint32_t sig, void *param)
evt->sig = sig;
evt->param = param;
return osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_ctrl_handler, evt, 0, OSI_THREAD_MAX_TIMEOUT);
return osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_ctrl_handler, evt, 1, OSI_THREAD_MAX_TIMEOUT);
}
static void btc_a2dp_sink_ctrl_handler(void *arg)
@ -322,7 +322,7 @@ void btc_a2dp_sink_on_suspended(tBTA_AV_SUSPEND *p_av)
static void btc_a2dp_sink_data_post(void)
{
osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 1, OSI_THREAD_MAX_TIMEOUT);
osi_thread_post(a2dp_sink_local_param.btc_aa_snk_task_hdl, btc_a2dp_sink_data_ready, NULL, 2, OSI_THREAD_MAX_TIMEOUT);
}
/*******************************************************************************

View File

@ -249,7 +249,7 @@ static bool btc_a2dp_source_ctrl_post(uint32_t sig, void *param)
evt->sig = sig;
evt->param = param;
return osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_ctrl_handler, evt, 0, OSI_THREAD_MAX_TIMEOUT);
return osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_ctrl_handler, evt, 1, OSI_THREAD_MAX_TIMEOUT);
}
static void btc_a2dp_source_ctrl_handler(void *arg)
@ -421,7 +421,7 @@ void btc_a2dp_source_on_suspended(tBTA_AV_SUSPEND *p_av)
static void btc_a2dp_source_data_post(void)
{
osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_handle_timer, NULL, 1, OSI_THREAD_MAX_TIMEOUT);
osi_thread_post(a2dp_source_local_param.btc_aa_src_task_hdl, btc_a2dp_source_handle_timer, NULL, 2, OSI_THREAD_MAX_TIMEOUT);
}
static UINT64 time_now_us()

View File

@ -69,8 +69,7 @@ void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len)
{
size_t bytes_written;
i2s_write(0, data, len, &bytes_written, portMAX_DELAY);
write_ringbuf(data, len);
if (++s_pkt_cnt % 100 == 0) {
ESP_LOGI(BT_AV_TAG, "Audio packet count %u", s_pkt_cnt);
}
@ -134,8 +133,10 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
s_a2d_conn_state_str[a2d->conn_stat.state], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
bt_i2s_task_shut_down();
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_CONNECTED){
esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE);
bt_i2s_task_start_up();
}
break;
}

View File

@ -16,6 +16,8 @@
#include "freertos/task.h"
#include "esp_log.h"
#include "bt_app_core.h"
#include "driver/i2s.h"
#include "freertos/ringbuf.h"
static void bt_app_task_handler(void *arg);
static bool bt_app_send_msg(bt_app_msg_t *msg);
@ -23,6 +25,8 @@ static void bt_app_work_dispatched(bt_app_msg_t *msg);
static xQueueHandle s_bt_app_task_queue = NULL;
static xTaskHandle s_bt_app_task_handle = NULL;
static xTaskHandle s_bt_i2s_task_handle = NULL;
static RingbufHandle_t ringbuf_i2s = NULL;;
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
{
@ -111,3 +115,50 @@ void bt_app_task_shut_down(void)
s_bt_app_task_queue = NULL;
}
}
static void bt_i2s_task_handler(void *arg)
{
uint8_t *data = NULL;
size_t item_size = 0;
size_t bytes_written = 0;
for (;;) {
data = (uint8_t *)xRingbufferReceive(ringbuf_i2s, &item_size, (portTickType)portMAX_DELAY);
if (item_size != 0){
i2s_write(0, data, item_size, &bytes_written, portMAX_DELAY);
vRingbufferReturnItem(ringbuf_i2s,(void *)data);
}
}
}
void bt_i2s_task_start_up(void)
{
ringbuf_i2s = xRingbufferCreate(8 * 1024, RINGBUF_TYPE_BYTEBUF);
if(ringbuf_i2s == NULL){
return;
}
xTaskCreate(bt_i2s_task_handler, "BtI2ST", 1024, NULL, configMAX_PRIORITIES - 3, &s_bt_i2s_task_handle);
return;
}
void bt_i2s_task_shut_down(void)
{
if (s_bt_i2s_task_handle) {
vTaskDelete(s_bt_i2s_task_handle);
s_bt_i2s_task_handle = NULL;
}
vRingbufferDelete(ringbuf_i2s);
ringbuf_i2s = NULL;
}
size_t write_ringbuf(const uint8_t *data, size_t size)
{
BaseType_t done = xRingbufferSend(ringbuf_i2s, (void *)data, size, (portTickType)portMAX_DELAY);
if(done){
return size;
} else {
return 0;
}
}

View File

@ -44,4 +44,10 @@ void bt_app_task_start_up(void);
void bt_app_task_shut_down(void);
void bt_i2s_task_start_up(void);
void bt_i2s_task_shut_down(void);
size_t write_ringbuf(const uint8_t *data, size_t size);
#endif /* __BT_APP_CORE_H__ */

View File

@ -69,8 +69,7 @@ void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len)
{
size_t bytes_written;
i2s_write(0, data, len, &bytes_written, portMAX_DELAY);
write_ringbuf(data, len);
if (++s_pkt_cnt % 100 == 0) {
ESP_LOGI(BT_AV_TAG, "Audio packet count %u", s_pkt_cnt);
}
@ -134,8 +133,10 @@ static void bt_av_hdl_a2d_evt(uint16_t event, void *p_param)
s_a2d_conn_state_str[a2d->conn_stat.state], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) {
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
bt_i2s_task_shut_down();
} else if (a2d->conn_stat.state == ESP_A2D_CONNECTION_STATE_CONNECTED){
esp_bt_gap_set_scan_mode(ESP_BT_NON_CONNECTABLE, ESP_BT_NON_DISCOVERABLE);
bt_i2s_task_start_up();
}
break;
}

View File

@ -16,6 +16,8 @@
#include "freertos/task.h"
#include "esp_log.h"
#include "bt_app_core.h"
#include "driver/i2s.h"
#include "freertos/ringbuf.h"
static void bt_app_task_handler(void *arg);
static bool bt_app_send_msg(bt_app_msg_t *msg);
@ -23,6 +25,8 @@ static void bt_app_work_dispatched(bt_app_msg_t *msg);
static xQueueHandle s_bt_app_task_queue = NULL;
static xTaskHandle s_bt_app_task_handle = NULL;
static xTaskHandle s_bt_i2s_task_handle = NULL;
static RingbufHandle_t ringbuf_i2s = NULL;;
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
{
@ -111,3 +115,50 @@ void bt_app_task_shut_down(void)
s_bt_app_task_queue = NULL;
}
}
static void bt_i2s_task_handler(void *arg)
{
uint8_t *data = NULL;
size_t item_size = 0;
size_t bytes_written = 0;
for (;;) {
data = (uint8_t *)xRingbufferReceive(ringbuf_i2s, &item_size, (portTickType)portMAX_DELAY);
if (item_size != 0){
i2s_write(0, data, item_size, &bytes_written, portMAX_DELAY);
vRingbufferReturnItem(ringbuf_i2s,(void *)data);
}
}
}
void bt_i2s_task_start_up(void)
{
ringbuf_i2s = xRingbufferCreate(8 * 1024, RINGBUF_TYPE_BYTEBUF);
if(ringbuf_i2s == NULL){
return;
}
xTaskCreate(bt_i2s_task_handler, "BtI2ST", 1024, NULL, configMAX_PRIORITIES - 3, &s_bt_i2s_task_handle);
return;
}
void bt_i2s_task_shut_down(void)
{
if (s_bt_i2s_task_handle) {
vTaskDelete(s_bt_i2s_task_handle);
s_bt_i2s_task_handle = NULL;
}
vRingbufferDelete(ringbuf_i2s);
ringbuf_i2s = NULL;
}
size_t write_ringbuf(const uint8_t *data, size_t size)
{
BaseType_t done = xRingbufferSend(ringbuf_i2s, (void *)data, size, (portTickType)portMAX_DELAY);
if(done){
return size;
} else {
return 0;
}
}

View File

@ -44,4 +44,10 @@ void bt_app_task_start_up(void);
void bt_app_task_shut_down(void);
void bt_i2s_task_start_up(void);
void bt_i2s_task_shut_down(void);
size_t write_ringbuf(const uint8_t *data, size_t size);
#endif /* __BT_APP_CORE_H__ */