Просмотр исходного кода

fix ag example outgoing callback not triggered

Closes https://github.com/espressif/esp-idf/issues/4967
liqigan 5 лет назад
Родитель
Сommit
783c5ecee2

+ 1 - 1
components/bt/host/bluedroid/api/esp_hf_ag_api.c

@@ -522,7 +522,7 @@ esp_err_t esp_bt_hf_register_data_callback(esp_hf_incoming_data_cb_t recv, esp_h
 #if (BTM_SCO_HCI_INCLUDED == TRUE)
 void esp_hf_outgoing_data_ready(void)
 {
-    BTA_AgCiData();
+    btc_hf_ci_sco_data();
 }
 #endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE ) */
 

+ 4 - 2
components/bt/host/bluedroid/bta/hf_ag/bta_ag_api.c

@@ -307,11 +307,13 @@ void BTA_AgSetCodec(UINT16 handle, tBTA_AG_PEER_CODEC codec)
  *                  layer will invoke esp_hf_client_outgoing_data_cb_t to fetch data
  *
  ***********************************************************************************************/
-void BTA_AgCiData(void)
+void BTA_AgCiData(UINT16 handle)
 {
     BT_HDR *p_buf;
-    if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
+    tBTA_AG_SCB *p_scb;
+    if ((p_scb = bta_ag_scb_by_idx(handle)) != NULL && (p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR))) != NULL) {
         p_buf->event = BTA_AG_CI_SCO_DATA_EVT;
+        p_buf->layer_specific = handle;
         bta_sys_sendmsg(p_buf);
     }
 }

+ 7 - 9
components/bt/host/bluedroid/bta/hf_ag/bta_ag_sco.c

@@ -618,7 +618,8 @@ static void bta_ag_create_sco(tBTA_AG_SCB *p_scb, BOOLEAN is_orig)
 
     p_bd_addr = p_scb->peer_addr;
 
-    status = BTM_CreateSco(p_bd_addr, is_orig, params.packet_types, &p_scb->sco_idx,  bta_ag_sco_conn_cback, bta_ag_sco_disc_cback);
+    status = BTM_CreateSco(p_bd_addr, is_orig, params.packet_types, &p_scb->sco_idx, bta_ag_sco_conn_cback,
+                           bta_ag_sco_disc_cback);
 
     if (status == BTM_CMD_STARTED)
     {
@@ -760,21 +761,18 @@ static void bta_ag_sco_event(tBTA_AG_SCB *p_scb, UINT8 event)
             p_buf->offset = pkt_offset;
             len_to_send = bta_ag_sco_co_out_data(p_buf->data + pkt_offset);
             p_buf->len = len_to_send;
-            if (len_to_send == p_scb->out_pkt_len)
-            {
+            if (len_to_send == p_scb->out_pkt_len) {
                 if (p_sco->state == BTA_AG_SCO_OPEN_ST) {
                     tBTM_STATUS write_stat = BTM_WriteScoData(p_sco->p_curr_scb->sco_idx, p_buf);
                     if (write_stat != BTM_SUCCESS) {
                         break;
                     }
-                    else {
-                        osi_free(p_buf);
-                    }
-                }
-                else {
+                } else {
                     osi_free(p_buf);
-                    break;
                 }
+            } else {
+                osi_free(p_buf);
+                break;
             }
         }
         return;

+ 1 - 1
components/bt/host/bluedroid/bta/include/bta/bta_ag_api.h

@@ -582,7 +582,7 @@ void BTA_AgSetCodec(UINT16 handle, tBTA_AG_PEER_CODEC codec);
 ** Returns          void
 **
 *******************************************************************************/
-void BTA_AgCiData(void);
+void BTA_AgCiData(UINT16 handle);
 #endif /*#if (BTM_SCO_HCI_INCLUDED == TRUE ) */
 
 #ifdef __cplusplus

+ 16 - 0
components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c

@@ -873,6 +873,22 @@ update_call_states:
     return status;
 }
 
+bt_status_t btc_hf_ci_sco_data(void)
+{
+    bt_status_t status = BT_STATUS_SUCCESS;
+#if (BTM_SCO_HCI_INCLUDED == TRUE)
+    int idx = btc_hf_latest_connected_idx();
+    CHECK_HF_SLC_CONNECTED();
+
+    if (idx != BTC_HF_INVALID_IDX) {
+        BTA_AgCiData(hf_local_param[idx].btc_hf_cb.handle);
+        return status;
+    }
+    status = BT_STATUS_FAIL;
+#endif /*#if (BTM_SCO_HCI_INCLUDED == TRUE ) */
+    return status;
+}
+
 /************************************************************************************
 **  Memory malloc and release
 ************************************************************************************/

+ 2 - 0
components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h

@@ -253,6 +253,8 @@ void btc_hf_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
 
 void btc_hf_arg_deep_free(btc_msg_t *msg);
 
+bt_status_t btc_hf_ci_sco_data(void);
+
 #endif  // BTC_HF_INCLUDED == TRUE
 
 #endif /* __BTC_HF_AG_H__ */

+ 4 - 1
components/bt/host/bluedroid/stack/btm/btm_sco.c

@@ -441,6 +441,9 @@ tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf)
             p_buf->len += HCI_SCO_PREAMBLE_SIZE;
 
             if (fixed_queue_length(p_ccb->xmit_data_q) < BTM_SCO_XMIT_QUEUE_THRS) {
+                if (fixed_queue_length(p_ccb->xmit_data_q) >= BTM_SCO_XMIT_QUEUE_HIGH_WM) {
+                    status = BTM_NO_RESOURCES;
+                }
                 fixed_queue_enqueue(p_ccb->xmit_data_q, p_buf, FIXED_QUEUE_MAX_TIMEOUT);
                 btm_sco_check_send_pkts (sco_inx);
             } else {
@@ -454,7 +457,7 @@ tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf)
         status = BTM_UNKNOWN_ADDR;
     }
 
-    if (status != BTM_SUCCESS) {
+    if (status != BTM_SUCCESS && status!= BTM_NO_RESOURCES) {
         BTM_TRACE_WARNING ("stat %d", status);
         osi_free(p_buf);
     }

+ 2 - 1
components/bt/host/bluedroid/stack/btm/include/btm_int.h

@@ -389,7 +389,8 @@ typedef struct {
 typedef struct {
     tBTM_ESCO_INFO   esco;              /* Current settings             */
 #if BTM_SCO_HCI_INCLUDED == TRUE
-#define BTM_SCO_XMIT_QUEUE_THRS     20
+#define BTM_SCO_XMIT_QUEUE_THRS     30
+#define BTM_SCO_XMIT_QUEUE_HIGH_WM  20
     fixed_queue_t   *xmit_data_q;       /* SCO data transmitting queue  */
     INT16           sent_not_acked;
 #endif

+ 3 - 3
examples/bluetooth/bluedroid/classic_bt/hfp_ag/main/bt_app_hf.c

@@ -119,9 +119,9 @@ static const int16_t sine_int16[] = {
 #define TABLE_SIZE_CVSD   100
 static uint32_t bt_app_hf_outgoing_cb(uint8_t *p_buf, uint32_t sz)
 {
-    int sine_phase = esp_random();
+    static int sine_phase = 0;
 
-    for (int i = 0; i < TABLE_SIZE_CVSD; i++) {
+    for (int i = 0; i * 2 + 1 < sz; i++) {
         p_buf[i * 2]     = sine_int16[sine_phase];
         p_buf[i * 2 + 1] = sine_int16[sine_phase];
         ++sine_phase;
@@ -131,7 +131,7 @@ static uint32_t bt_app_hf_outgoing_cb(uint8_t *p_buf, uint32_t sz)
     }
     return sz;
 }
- 
+
 static void bt_app_hf_incoming_cb(const uint8_t *buf, uint32_t sz)
 {
     // direct to i2s