OSDN Git Service

Move aptX config parse to main code from the library
authorUmesh Vats <uvats@codeaurora.org>
Mon, 25 Jul 2016 18:19:25 +0000 (11:19 -0700)
committerLinux Build Service Account <lnxbuild@localhost>
Wed, 24 Aug 2016 14:10:03 +0000 (08:10 -0600)
For aptX offload feature, aptX config parsing and caps check
functions need to be included in open source

Change-Id: If31864374a3fa04720b03637c3dfb492f2cfacd1
CRs-Fixed: 1046053

btif/co/bta_av_co.c
btif/src/btif_media_task.c
stack/a2dp/a2d_aptx.c
stack/include/a2d_aptx.h

index 297ee19..a50f21c 100644 (file)
@@ -1688,7 +1688,7 @@ static BOOLEAN bta_av_co_audio_media_supports_config(UINT8 codec_type, const UIN
         if (codecId ==  A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
         {
             APPL_TRACE_DEBUG("%s tA2D_APTX_CIE aptX", __func__);
-            if (bta_av_aptx_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_APTX_CIE *)&bta_av_co_aptx_caps))
+            if (a2d_av_aptx_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_APTX_CIE *)&bta_av_co_aptx_caps))
             {
                 APPL_TRACE_DEBUG("%s aptX", __func__);
                 return FALSE;
index c904f86..66095fd 100644 (file)
@@ -450,9 +450,6 @@ A2D_AptXThreadFn (*A2D_aptx_sched_start)(void *encoder,
                    BOOLEAN trace);
 BOOLEAN (*A2D_aptx_sched_stop)(void);
 void (*A2D_aptx_sched_deinit)(void);
-UINT8 (*bta_av_aptx_cfg_in_cap)(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap);
-UINT8 (*A2D_ParsAptxInfo)(tA2D_APTX_CIE *p_ie, UINT8 *p_info,
-                              BOOLEAN for_caps);
 void *A2dAptXSchedLibHandle = NULL;
 BOOLEAN isA2dAptXEnabled = false;
 
@@ -1108,25 +1105,6 @@ BOOLEAN btif_check_and_init_aptX(void)
             goto error_exit;
         }
 
-        A2D_ParsAptxInfo = (UINT8 (*)(tA2D_APTX_CIE *,
-                                      UINT8 *,
-                                      BOOLEAN))dlsym(A2dAptXSchedLibHandle,
-                                      "A2D_ParsAptxInfo");
-        if (!A2D_ParsAptxInfo)
-        {
-            APPL_TRACE_ERROR("btif_check_and_init_aptX: parse aptx info missing");
-            goto error_exit;
-        }
-
-        bta_av_aptx_cfg_in_cap = (UINT8 (*)(UINT8 *,
-                                            tA2D_APTX_CIE *))dlsym(A2dAptXSchedLibHandle,
-                                                                   "bta_av_aptx_cfg_in_cap");
-        if (!bta_av_aptx_cfg_in_cap)
-        {
-            APPL_TRACE_ERROR("btif_check_and_init_aptX: aptX cfg in cap missing");
-            goto error_exit;
-        }
-
         if (A2D_aptx_sched_init())
         {
             APPL_TRACE_ERROR("btif_check_and_init_aptX: aptX scheduler init failed");
index af26dd3..fe81852 100644 (file)
 ** Function         A2D_BldAptxInfo
 **
 ******************************************************************************/
-
 UINT8 A2D_BldAptxInfo(UINT8 media_type, tA2D_APTX_CIE *p_ie, UINT8 *p_result)
 {
-    A2D_TRACE_API("A2D_BldAptxInfo - MediaType:%d", media_type);
+    A2D_TRACE_API("%s: - MediaType:%d", __func__, media_type);
 
     UINT8 status = 0;
     status = A2D_SUCCESS;
@@ -69,3 +68,95 @@ UINT8 A2D_BldAptxInfo(UINT8 media_type, tA2D_APTX_CIE *p_ie, UINT8 *p_result)
 
     return status;
 }
+
+/******************************************************************************
+**
+** Function         A2D_ParsAptxInfo
+**
+******************************************************************************/
+tA2D_STATUS A2D_ParsAptxInfo(tA2D_APTX_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps)
+{
+    tA2D_STATUS status;
+    UINT8   losc;
+    UINT8   mt;
+
+    A2D_TRACE_API("%s: - MediaType:%d", __func__, for_caps);
+
+    if (p_ie == NULL || p_info == NULL)
+    {
+        A2D_TRACE_ERROR("A2D_ParsAptxInfo - Invalid Params");
+        status = A2D_INVALID_PARAMS;
+    }
+    else
+    {
+        losc    = *p_info++;
+        mt      = *p_info++;
+        A2D_TRACE_DEBUG("%s: losc %d, mt %02x", __func__, losc, mt);
+
+        /* If the function is called for the wrong Media Type or Media Codec Type */
+        if (losc != A2D_APTX_CODEC_LEN || *p_info != A2D_NON_A2DP_MEDIA_CT) {
+            A2D_TRACE_ERROR("%s: wrong media type %02x", __func__, *p_info);
+            status = A2D_WRONG_CODEC;
+        }
+        else
+        {
+            p_info++;
+            p_ie->vendorId = (*p_info & 0x000000FF) |
+                             (*(p_info+1) << 8    & 0x0000FF00) |
+                             (*(p_info+2) << 16  & 0x00FF0000) |
+                             (*(p_info+3) << 24  & 0xFF000000);
+            p_info = p_info+4;
+            p_ie->codecId = (*p_info & 0x00FF) |(*(p_info+1) << 8 & 0xFF00);
+            p_info = p_info+2;
+            p_ie->channelMode= *p_info & 0x0F;
+            p_ie->sampleRate = *p_info & 0xF0;
+
+            status = A2D_SUCCESS;
+
+            if (for_caps == FALSE)
+            {
+                if (A2D_BitsSet(p_ie->sampleRate) != A2D_SET_ONE_BIT)
+                    status = A2D_BAD_SAMP_FREQ;
+                if (A2D_BitsSet(p_ie->channelMode) != A2D_SET_ONE_BIT)
+                    status = A2D_BAD_CH_MODE;
+            }
+        }
+    }
+    return status;
+}
+
+/*******************************************************************************
+**
+** Function         a2d_av_aptx_cfg_in_cap
+**
+** Description      This function checks whether an aptX codec configuration
+**                  is allowable for the given codec capabilities.
+**
+** Returns          0 if ok, nonzero if error.
+**
+*******************************************************************************/
+UINT8 a2d_av_aptx_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap)
+{
+    UINT8           status = 0;
+    tA2D_APTX_CIE   cfg_cie;
+
+    A2D_TRACE_API("%s", __func__);
+
+    /* parse configuration */
+    if ((status = A2D_ParsAptxInfo(&cfg_cie, p_cfg, FALSE)) != 0)
+    {
+        A2D_TRACE_ERROR("%s:, aptx parse failed", __func__);
+        return status;
+    }
+
+    /* verify that each parameter is in range */
+
+    /* sampling frequency */
+    if ((cfg_cie.sampleRate & p_cap->sampleRate) == 0)
+        status = A2D_NS_SAMP_FREQ;
+    /* channel mode */
+    else if ((cfg_cie.channelMode & p_cap->channelMode) == 0)
+        status = A2D_NS_CH_MODE;
+
+    return status;
+}
index 5d61c9c..c20faf2 100644 (file)
@@ -105,7 +105,7 @@ extern "C"
 #endif
 extern UINT8 A2D_BldAptxInfo(UINT8 media_type, tA2D_APTX_CIE *p_ie,
                              UINT8 *p_result);
-extern UINT8 (*A2D_ParsAptxInfo)(tA2D_APTX_CIE *p_ie, UINT8 *p_info,
+extern UINT8 A2D_ParsAptxInfo(tA2D_APTX_CIE *p_ie, UINT8 *p_info,
                               BOOLEAN for_caps);
 extern int (*A2D_aptx_sched_init)(void);
 extern A2D_AptXThreadFn (*A2D_aptx_sched_start)(void *encoder,
@@ -118,7 +118,7 @@ extern A2D_AptXThreadFn (*A2D_aptx_sched_start)(void *encoder,
                           BOOLEAN test, BOOLEAN trace);
 extern BOOLEAN (*A2D_aptx_sched_stop)(void);
 extern void (*A2D_aptx_sched_deinit)(void);
-extern UINT8 (*bta_av_aptx_cfg_in_cap)(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap);
+extern UINT8 a2d_av_aptx_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap);
 
 #ifdef __cplusplus
 }