From c7bf47cefc5446e99ff12b6cae45a0984e0b9999 Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Fri, 1 Sep 2017 16:40:59 -0700 Subject: [PATCH] Read the Tx Power level when flushing the A2DP Tx queue Also, minor renaming and cleanup (for consistency). Test: Streaming A2DP headset and trigger audio stutter Bug: 64038257 Change-Id: Id722342b596e0bf3c9c7664272b6d3e311bb82e9 --- btif/src/btif_a2dp_source.cc | 26 +++++++++- btif/src/btif_gatt_client.cc | 2 +- stack/btm/btm_acl.cc | 110 ++++++++++++++++++++++-------------------- stack/btm/btm_devctl.cc | 2 +- stack/btm/btm_inq.cc | 19 ++++---- stack/include/btm_api.h | 6 +-- stack/include/btm_api_types.h | 8 +-- 7 files changed, 101 insertions(+), 72 deletions(-) diff --git a/btif/src/btif_a2dp_source.cc b/btif/src/btif_a2dp_source.cc index 5f8cfd697..8d264cea3 100644 --- a/btif/src/btif_a2dp_source.cc +++ b/btif/src/btif_a2dp_source.cc @@ -190,6 +190,7 @@ static void update_scheduling_stats(scheduling_stats_t* stats, uint64_t now_us, static void btm_read_rssi_cb(void* data); static void btm_read_failed_contact_counter_cb(void* data); static void btm_read_automatic_flush_timeout_cb(void* data); +static void btm_read_tx_power_cb(void* data); UNUSED_ATTR static const char* dump_media_event(uint16_t event) { switch (event) { @@ -763,6 +764,12 @@ static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n) { LOG_WARN(LOG_TAG, "%s: Cannot read Automatic Flush Timeout: status %d", __func__, status); } + status = + BTM_ReadTxPower(peer_bda, BT_TRANSPORT_BR_EDR, btm_read_tx_power_cb); + if (status != BTM_CMD_STARTED) { + LOG_WARN(LOG_TAG, "%s: Cannot read Tx Power: status %d", __func__, + status); + } } /* Update the statistics */ @@ -1102,7 +1109,7 @@ static void btm_read_rssi_cb(void* data) { return; } - tBTM_RSSI_RESULTS* result = (tBTM_RSSI_RESULTS*)data; + tBTM_RSSI_RESULT* result = (tBTM_RSSI_RESULT*)data; if (result->status != BTM_SUCCESS) { LOG_ERROR(LOG_TAG, "%s unable to read remote RSSI (status %d)", __func__, result->status); @@ -1150,3 +1157,20 @@ static void btm_read_automatic_flush_timeout_cb(void* data) { LOG_WARN(LOG_TAG, "%s device: %s, Automatic Flush Timeout: %u", __func__, result->rem_bda.ToString().c_str(), result->automatic_flush_timeout); } + +static void btm_read_tx_power_cb(void* data) { + if (data == nullptr) { + LOG_ERROR(LOG_TAG, "%s Read Tx Power request timed out", __func__); + return; + } + + tBTM_TX_POWER_RESULT* result = (tBTM_TX_POWER_RESULT*)data; + if (result->status != BTM_SUCCESS) { + LOG_ERROR(LOG_TAG, "%s unable to read Tx Power (status %d)", __func__, + result->status); + return; + } + + LOG_WARN(LOG_TAG, "%s device: %s, Tx Power: %d", __func__, + result->rem_bda.ToString().c_str(), result->tx_power); +} diff --git a/btif/src/btif_gatt_client.cc b/btif/src/btif_gatt_client.cc index 69a166511..262234b19 100644 --- a/btif/src/btif_gatt_client.cc +++ b/btif/src/btif_gatt_client.cc @@ -203,7 +203,7 @@ void bta_gattc_cback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) { ASSERTC(status == BT_STATUS_SUCCESS, "Context transfer failed!", status); } -void btm_read_rssi_cb(tBTM_RSSI_RESULTS* p_result) { +void btm_read_rssi_cb(tBTM_RSSI_RESULT* p_result) { if (!p_result) return; CLI_CBACK_IN_JNI(read_remote_rssi_cb, rssi_request_client_if, diff --git a/stack/btm/btm_acl.cc b/stack/btm/btm_acl.cc index 2438eb636..19ad299a2 100644 --- a/stack/btm/btm_acl.cc +++ b/stack/btm/btm_acl.cc @@ -1250,8 +1250,9 @@ tBTM_STATUS BTM_SetLinkSuperTout(const RawAddress& remote_bda, btsnd_hcic_write_link_super_tout(LOCAL_BR_EDR_CONTROLLER_ID, p->hci_handle, timeout); return (BTM_CMD_STARTED); - } else + } else { return (BTM_SUCCESS); + } } /* If here, no BD Addr found */ @@ -1577,8 +1578,9 @@ bool BTM_FreeSCN(uint8_t scn) { if (scn <= BTM_MAX_SCN) { btm_cb.btm_scn[scn - 1] = false; return (true); - } else + } else { return (false); /* Illegal SCN passed in */ + } } /******************************************************************************* @@ -1887,7 +1889,7 @@ void btm_qos_setup_complete(uint8_t status, uint16_t handle, * Description This function is called to read the link policy settings. * The address of link policy results are returned in the * callback. - * (tBTM_RSSI_RESULTS) + * (tBTM_RSSI_RESULT) * * Returns BTM_CMD_STARTED if successfully initiated or error code * @@ -2006,7 +2008,7 @@ tBTM_STATUS BTM_ReadAutomaticFlushTimeout(const RawAddress& remote_bda, * * Description This function is called to read the link qulaity. * The value of the link quality is returned in the callback. - * (tBTM_LINK_QUALITY_RESULTS) + * (tBTM_LINK_QUALITY_RESULT) * * Returns BTM_CMD_STARTED if successfully initiated or error code * @@ -2040,7 +2042,7 @@ tBTM_STATUS BTM_ReadLinkQuality(const RawAddress& remote_bda, * Description This function is called to read the current * TX power of the connection. The tx power level results * are returned in the callback. - * (tBTM_RSSI_RESULTS) + * (tBTM_RSSI_RESULT) * * Returns BTM_CMD_STARTED if successfully initiated or error code * @@ -2104,10 +2106,8 @@ void btm_read_tx_power_timeout(UNUSED_ATTR void* data) { ******************************************************************************/ void btm_read_tx_power_complete(uint8_t* p, bool is_ble) { tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_tx_power_cmpl_cb; - tBTM_TX_POWER_RESULTS results; - uint16_t handle; + tBTM_TX_POWER_RESULT result; tACL_CONN* p_acl_cb = &btm_cb.acl_db[0]; - uint16_t index; BTM_TRACE_DEBUG("%s", __func__); alarm_cancel(btm_cb.devcb.read_tx_power_timer); @@ -2115,32 +2115,34 @@ void btm_read_tx_power_complete(uint8_t* p, bool is_ble) { /* If there was a registered callback, call it */ if (p_cb) { - STREAM_TO_UINT8(results.hci_status, p); + STREAM_TO_UINT8(result.hci_status, p); - if (results.hci_status == HCI_SUCCESS) { - results.status = BTM_SUCCESS; + if (result.hci_status == HCI_SUCCESS) { + result.status = BTM_SUCCESS; if (!is_ble) { + uint16_t handle; STREAM_TO_UINT16(handle, p); - STREAM_TO_UINT8(results.tx_power, p); + STREAM_TO_UINT8(result.tx_power, p); /* Search through the list of active channels for the correct BD Addr */ - for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { + for (uint16_t index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) { - results.rem_bda = p_acl_cb->remote_addr; + result.rem_bda = p_acl_cb->remote_addr; break; } } } else { - STREAM_TO_UINT8(results.tx_power, p); - results.rem_bda = btm_cb.devcb.read_tx_pwr_addr; + STREAM_TO_UINT8(result.tx_power, p); + result.rem_bda = btm_cb.devcb.read_tx_pwr_addr; } BTM_TRACE_DEBUG("BTM TX power Complete: tx_power %d, hci status 0x%02x", - results.tx_power, results.hci_status); - } else - results.status = BTM_ERR_PROCESSING; + result.tx_power, result.hci_status); + } else { + result.status = BTM_ERR_PROCESSING; + } - (*p_cb)(&results); + (*p_cb)(&result); } } @@ -2154,12 +2156,11 @@ void btm_read_tx_power_complete(uint8_t* p, bool is_ble) { * ******************************************************************************/ void btm_read_rssi_timeout(UNUSED_ATTR void* data) { - tBTM_RSSI_RESULTS results; + tBTM_RSSI_RESULT result; tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rssi_cmpl_cb; btm_cb.devcb.p_rssi_cmpl_cb = NULL; - results.status = BTM_DEVICE_TIMEOUT; - if (p_cb) - (*p_cb)(&results); + result.status = BTM_DEVICE_TIMEOUT; + if (p_cb) (*p_cb)(&result); } /******************************************************************************* @@ -2174,10 +2175,8 @@ void btm_read_rssi_timeout(UNUSED_ATTR void* data) { ******************************************************************************/ void btm_read_rssi_complete(uint8_t* p) { tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_rssi_cmpl_cb; - tBTM_RSSI_RESULTS results; - uint16_t handle; + tBTM_RSSI_RESULT result; tACL_CONN* p_acl_cb = &btm_cb.acl_db[0]; - uint16_t index; BTM_TRACE_DEBUG("%s", __func__); alarm_cancel(btm_cb.devcb.read_rssi_timer); @@ -2185,28 +2184,30 @@ void btm_read_rssi_complete(uint8_t* p) { /* If there was a registered callback, call it */ if (p_cb) { - STREAM_TO_UINT8(results.hci_status, p); + STREAM_TO_UINT8(result.hci_status, p); - if (results.hci_status == HCI_SUCCESS) { - results.status = BTM_SUCCESS; + if (result.hci_status == HCI_SUCCESS) { + uint16_t handle; + result.status = BTM_SUCCESS; STREAM_TO_UINT16(handle, p); - STREAM_TO_UINT8(results.rssi, p); + STREAM_TO_UINT8(result.rssi, p); BTM_TRACE_DEBUG("BTM RSSI Complete: rssi %d, hci status 0x%02x", - results.rssi, results.hci_status); + result.rssi, result.hci_status); /* Search through the list of active channels for the correct BD Addr */ - for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { + for (uint16_t index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) { - results.rem_bda = p_acl_cb->remote_addr; + result.rem_bda = p_acl_cb->remote_addr; break; } } - } else - results.status = BTM_ERR_PROCESSING; + } else { + result.status = BTM_ERR_PROCESSING; + } - (*p_cb)(&results); + (*p_cb)(&result); } } @@ -2371,10 +2372,8 @@ void btm_read_link_quality_timeout(UNUSED_ATTR void* data) { ******************************************************************************/ void btm_read_link_quality_complete(uint8_t* p) { tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_link_qual_cmpl_cb; - tBTM_LINK_QUALITY_RESULTS results; - uint16_t handle; + tBTM_LINK_QUALITY_RESULT result; tACL_CONN* p_acl_cb = &btm_cb.acl_db[0]; - uint16_t index; BTM_TRACE_DEBUG("%s", __func__); alarm_cancel(btm_cb.devcb.read_link_quality_timer); @@ -2382,29 +2381,31 @@ void btm_read_link_quality_complete(uint8_t* p) { /* If there was a registered callback, call it */ if (p_cb) { - STREAM_TO_UINT8(results.hci_status, p); + STREAM_TO_UINT8(result.hci_status, p); - if (results.hci_status == HCI_SUCCESS) { - results.status = BTM_SUCCESS; + if (result.hci_status == HCI_SUCCESS) { + uint16_t handle; + result.status = BTM_SUCCESS; STREAM_TO_UINT16(handle, p); - STREAM_TO_UINT8(results.link_quality, p); + STREAM_TO_UINT8(result.link_quality, p); BTM_TRACE_DEBUG( "BTM Link Quality Complete: Link Quality %d, hci status 0x%02x", - results.link_quality, results.hci_status); + result.link_quality, result.hci_status); /* Search through the list of active channels for the correct BD Addr */ - for (index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { + for (uint16_t index = 0; index < MAX_L2CAP_LINKS; index++, p_acl_cb++) { if ((p_acl_cb->in_use) && (handle == p_acl_cb->hci_handle)) { - results.rem_bda = p_acl_cb->remote_addr; + result.rem_bda = p_acl_cb->remote_addr; break; } } - } else - results.status = BTM_ERR_PROCESSING; + } else { + result.status = BTM_ERR_PROCESSING; + } - (*p_cb)(&results); + (*p_cb)(&result); } } @@ -2435,8 +2436,9 @@ tBTM_STATUS btm_remove_acl(const RawAddress& bd_addr, tBT_TRANSPORT transport) { if (hci_handle != 0xFFFF && p_dev_rec && p_dev_rec->sec_state != BTM_SEC_STATE_DISCONNECTING) { btsnd_hcic_disconnect(hci_handle, HCI_ERR_PEER_USER); - } else + } else { status = BTM_UNKNOWN_ADDR; + } } return status; @@ -2528,8 +2530,9 @@ void btm_acl_resubmit_page(void) { memcpy(btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p_buf); - } else + } else { btm_cb.paging = false; + } } /******************************************************************************* @@ -2609,8 +2612,9 @@ bool btm_acl_notif_conn_collision(const RawAddress& bda) { evt_data.conn.handle = BTM_INVALID_HCI_HANDLE; (*btm_cb.p_bl_changed_cb)(&evt_data); return true; - } else + } else { return false; + } } /******************************************************************************* diff --git a/stack/btm/btm_devctl.cc b/stack/btm/btm_devctl.cc index 477247fdc..3dcb381d0 100644 --- a/stack/btm/btm_devctl.cc +++ b/stack/btm/btm_devctl.cc @@ -133,7 +133,7 @@ static void btm_db_reset(void) { p_cb = btm_cb.devcb.p_rssi_cmpl_cb; btm_cb.devcb.p_rssi_cmpl_cb = NULL; - if (p_cb) (*p_cb)((tBTM_RSSI_RESULTS*)&status); + if (p_cb) (*p_cb)((tBTM_RSSI_RESULT*)&status); } if (btm_cb.devcb.p_failed_contact_counter_cmpl_cb) { diff --git a/stack/btm/btm_inq.cc b/stack/btm/btm_inq.cc index b048719ac..bd276d62b 100644 --- a/stack/btm/btm_inq.cc +++ b/stack/btm/btm_inq.cc @@ -2228,7 +2228,7 @@ void btm_read_inq_tx_power_timeout(UNUSED_ATTR void* data) { ******************************************************************************/ void btm_read_inq_tx_power_complete(uint8_t* p) { tBTM_CMPL_CB* p_cb = btm_cb.devcb.p_inq_tx_power_cmpl_cb; - tBTM_INQ_TXPWR_RESULTS results; + tBTM_INQ_TXPWR_RESULT result; BTM_TRACE_DEBUG("%s", __func__); alarm_cancel(btm_cb.devcb.read_inq_tx_power_timer); @@ -2236,19 +2236,20 @@ void btm_read_inq_tx_power_complete(uint8_t* p) { /* If there was a registered callback, call it */ if (p_cb) { - STREAM_TO_UINT8(results.hci_status, p); + STREAM_TO_UINT8(result.hci_status, p); - if (results.hci_status == HCI_SUCCESS) { - results.status = BTM_SUCCESS; + if (result.hci_status == HCI_SUCCESS) { + result.status = BTM_SUCCESS; - STREAM_TO_UINT8(results.tx_power, p); + STREAM_TO_UINT8(result.tx_power, p); BTM_TRACE_EVENT( "BTM INQ TX POWER Complete: tx_power %d, hci status 0x%02x", - results.tx_power, results.hci_status); - } else - results.status = BTM_ERR_PROCESSING; + result.tx_power, result.hci_status); + } else { + result.status = BTM_ERR_PROCESSING; + } - (*p_cb)(&results); + (*p_cb)(&result); } } /******************************************************************************* diff --git a/stack/include/btm_api.h b/stack/include/btm_api.h index 185e0513a..10f4f6583 100644 --- a/stack/include/btm_api.h +++ b/stack/include/btm_api.h @@ -820,7 +820,7 @@ extern tBTM_STATUS BTM_SwitchRole(const RawAddress& remote_bd_addr, * * Description This function is called to read the link policy settings. * The address of link policy results are returned in the - * callback. (tBTM_RSSI_RESULTS) + * callback. (tBTM_RSSI_RESULT) * * Returns BTM_CMD_STARTED if command issued to controller. * BTM_NO_RESOURCES if memory couldn't be allocated to issue @@ -875,7 +875,7 @@ extern tBTM_STATUS BTM_ReadAutomaticFlushTimeout(const RawAddress& remote_bda, * Description This function is called to read the current connection * TX power of the connection. The TX power level results * are returned in the callback. - * (tBTM_RSSI_RESULTS) + * (tBTM_RSSI_RESULT) * * Returns BTM_CMD_STARTED if command issued to controller. * BTM_NO_RESOURCES if memory couldn't be allocated to issue @@ -893,7 +893,7 @@ extern tBTM_STATUS BTM_ReadTxPower(const RawAddress& remote_bda, * * Description This function is called to read the link quality. * The value of the link quality is returned in the callback. - * (tBTM_LINK_QUALITY_RESULTS) + * (tBTM_LINK_QUALITY_RESULT) * * Returns BTM_CMD_STARTED if command issued to controller. * BTM_NO_RESOURCES if memory couldn't be allocated to issue diff --git a/stack/include/btm_api_types.h b/stack/include/btm_api_types.h index 88cb207a7..13238df29 100644 --- a/stack/include/btm_api_types.h +++ b/stack/include/btm_api_types.h @@ -776,7 +776,7 @@ typedef struct { uint8_t hci_status; int8_t rssi; RawAddress rem_bda; -} tBTM_RSSI_RESULTS; +} tBTM_RSSI_RESULT; /* Structure returned with read failed contact counter event * (in tBTM_CMPL_CB callback function) in response to @@ -808,7 +808,7 @@ typedef struct { uint8_t hci_status; int8_t tx_power; RawAddress rem_bda; -} tBTM_TX_POWER_RESULTS; +} tBTM_TX_POWER_RESULT; /* Structure returned with read link quality event (in tBTM_CMPL_CB callback * function) in response to BTM_ReadLinkQuality call. @@ -818,7 +818,7 @@ typedef struct { uint8_t hci_status; uint8_t link_quality; RawAddress rem_bda; -} tBTM_LINK_QUALITY_RESULTS; +} tBTM_LINK_QUALITY_RESULT; /* Structure returned with read inq tx power quality event (in tBTM_CMPL_CB * callback function) in response to BTM_ReadInquiryRspTxPower call. @@ -827,7 +827,7 @@ typedef struct { tBTM_STATUS status; uint8_t hci_status; int8_t tx_power; -} tBTM_INQ_TXPWR_RESULTS; +} tBTM_INQ_TXPWR_RESULT; enum { BTM_BL_CONN_EVT, -- 2.11.0