OSDN Git Service

AVDT: Use std map to store channel map
authorHansong Zhang <hsz@google.com>
Thu, 4 Feb 2021 00:45:45 +0000 (16:45 -0800)
committerHansong Zhang <hsz@google.com>
Thu, 4 Feb 2021 00:47:48 +0000 (16:47 -0800)
Instead of using legacy fixed size array

Test: Speaker
Bug: 179117950
Tag: #stability
Change-Id: I04cb875309ed5efc14acb34bbfdc10622eabf3be

stack/avdt/avdt_ad.cc
stack/avdt/avdt_int.h
stack/avdt/avdt_l2c.cc

index fed9cff..ff10254 100644 (file)
@@ -193,14 +193,11 @@ AvdtpTransportChannel* avdt_ad_tc_tbl_by_st(uint8_t type, AvdtpCcb* p_ccb,
  *
  ******************************************************************************/
 AvdtpTransportChannel* avdt_ad_tc_tbl_by_lcid(uint16_t lcid) {
-  uint8_t idx;
-
-  idx = avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID];
-
-  if (idx < AVDT_NUM_TC_TBL) {
+  if (avdtp_cb.ad.lcid_tbl.count(lcid) != 0) {
+    uint8_t idx = avdtp_cb.ad.lcid_tbl[lcid];
     return &avdtp_cb.ad.tc_tbl[idx];
   } else {
-    return NULL;
+    return nullptr;
   }
 }
 
@@ -553,10 +550,8 @@ void avdt_ad_open_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb,
         L2CA_ConnectReq2(AVDT_PSM, p_ccb->peer_addr, BTM_SEC_OUT_AUTHENTICATE);
     if (lcid != 0) {
       /* if connect req ok, store tcid in lcid table  */
-      avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] =
-          avdt_ad_tc_tbl_to_idx(p_tbl);
-      AVDT_TRACE_DEBUG("avdtp_cb.ad.lcid_tbl[%d] = %d",
-                       (lcid - L2CAP_BASE_APPL_CID),
+      avdtp_cb.ad.lcid_tbl[lcid] = avdt_ad_tc_tbl_to_idx(p_tbl);
+      AVDT_TRACE_DEBUG("avdtp_cb.ad.lcid_tbl[%d] = %d", (lcid),
                        avdt_ad_tc_tbl_to_idx(p_tbl));
 
       avdtp_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid;
index babf258..ce5a0db 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef AVDT_INT_H
 #define AVDT_INT_H
 
+#include <unordered_map>
+
 #include "avdt_api.h"
 #include "avdt_defs.h"
 #include "avdtc_api.h"
@@ -686,7 +688,7 @@ class AvdtpRoutingEntry {
  */
 class AvdtpAdaptationLayer {
  public:
-  AvdtpAdaptationLayer() : lcid_tbl{} {}
+  AvdtpAdaptationLayer() {}
 
   void Reset() {
     for (size_t i = 0; i < AVDT_NUM_LINKS; i++) {
@@ -697,7 +699,7 @@ class AvdtpAdaptationLayer {
     for (size_t i = 0; i < AVDT_NUM_TC_TBL; i++) {
       tc_tbl[i].Reset();
     }
-    memset(lcid_tbl, 0, sizeof(lcid_tbl));
+    lcid_tbl.clear();
   }
 
   /**
@@ -711,7 +713,8 @@ class AvdtpAdaptationLayer {
 
   AvdtpRoutingEntry rt_tbl[AVDT_NUM_LINKS][AVDT_NUM_RT_TBL];
   AvdtpTransportChannel tc_tbl[AVDT_NUM_TC_TBL];
-  uint8_t lcid_tbl[MAX_L2CAP_CHANNELS];  // Map LCID to tc_tbl index
+
+  std::unordered_map<uint16_t, uint8_t> lcid_tbl;  // Map LCID to tc_tbl index
 };
 
 /**
index 13b238a..10bef46 100644 (file)
@@ -77,8 +77,7 @@ static void avdt_sec_check_complete_term(const RawAddress* bd_addr,
   if (p_tbl == NULL) return;
 
   /* store idx in LCID table, store LCID in routing table */
-  avdtp_cb.ad.lcid_tbl[p_tbl->lcid - L2CAP_BASE_APPL_CID] =
-      avdt_ad_tc_tbl_to_idx(p_tbl);
+  avdtp_cb.ad.lcid_tbl[p_tbl->lcid] = avdt_ad_tc_tbl_to_idx(p_tbl);
   avdtp_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = p_tbl->lcid;
 
   /* transition to configuration state */
@@ -204,8 +203,7 @@ void avdt_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid,
 
   /* if result ok, proceed with connection */
   /* store idx in LCID table, store LCID in routing table */
-  avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] =
-      avdt_ad_tc_tbl_to_idx(p_tbl);
+  avdtp_cb.ad.lcid_tbl[lcid] = avdt_ad_tc_tbl_to_idx(p_tbl);
   avdtp_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid;
 
   /* transition to configuration state */