• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/bt


Commit MetaInfo

Revision1944dc968f191d8233f71cf02f640bd57ba4cf8f (tree)
Zeit2016-09-28 19:20:11
AutorLinux Build Service Account <lnxbuild@loca...>
CommiterLinux Build Service Account

Log Message

Promotion of bt.lnx.2.1-00015.

CRs Change ID Subject


1050999 Idf8e2bebdc2ca7621aef06dd5f2075ef2c5fa08c Bluetooth: Set alarm's queue to NULL on alarm expired
1070444 Ie5b8b89b5d499e999167ad599fa587cea5dde2e7 GAP: Host sending two sdp req during legacy pairing
1063748 1069656 Iba694e2547abc8e6161997cd136064fe3a411abc aptXHD codec support
1069198 I4a2e429484378d23c996caffb6495407793548d2 SDP: Crash in sdp due to invalid length

Change-Id: I2d4755c678374e1233d3663262894780b25f3340
CRs-Fixed: 1069656, 1050999, 1070444, 1063748, 1069198

Ändern Zusammenfassung

Diff

--- a/audio_a2dp_hw/audio_a2dp_hw.c
+++ b/audio_a2dp_hw/audio_a2dp_hw.c
@@ -172,11 +172,12 @@ static const char* dump_a2dp_ctrl_event(char event)
172172 static int calc_audiotime(struct a2dp_config cfg, int bytes)
173173 {
174174 int chan_count = popcount(cfg.channel_flags);
175+ int bytes_per_sample = 4;
175176
176- ASSERTC(cfg.format == AUDIO_FORMAT_PCM_16_BIT,
177+ ASSERTC(cfg.format == AUDIO_FORMAT_PCM_8_24_BIT,
177178 "unsupported sample sz", cfg.format);
178179
179- return bytes*(1000000/(chan_count*2))/cfg.rate;
180+ return (int)(((int64_t)bytes * (1000000 / (chan_count * bytes_per_sample))) / cfg.rate);
180181 }
181182
182183 static void ts_error_log(char *tag, int val, int buff_size, struct a2dp_config cfg)
@@ -1382,7 +1383,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
13821383 a2dp_stream_common_init(&out->common);
13831384 #endif
13841385 out->common.cfg.channel_flags = AUDIO_STREAM_DEFAULT_CHANNEL_FLAG;
1385- out->common.cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
1386+ out->common.cfg.format = AUDIO_FORMAT_PCM_8_24_BIT;
13861387 out->common.cfg.rate = AUDIO_STREAM_DEFAULT_RATE;
13871388
13881389 /* set output config values */
--- a/audio_a2dp_hw/bthost_ipc.c
+++ b/audio_a2dp_hw/bthost_ipc.c
@@ -49,7 +49,9 @@
4949 #include "osi/include/osi.h"
5050 #include "osi/include/socket_utils/sockets.h"
5151
52-
52+#ifdef LOG_TAG
53+#undef LOG_TAG
54+#endif
5355 #define LOG_TAG "bthost_ipc"
5456 #include "osi/include/log.h"
5557
@@ -720,7 +722,6 @@ int a2dp_read_codec_config(struct a2dp_stream_common *common,uint8_t idx)
720722 int a2dp_get_multicast_status(struct a2dp_stream_common *common, uint8_t *mcast_status,
721723 uint8_t *num_dev)
722724 {
723- char cmd = A2DP_CTRL_GET_MULTICAST_STATUS;
724725 INFO("%s",__func__);
725726 if (a2dp_command(common,A2DP_CTRL_GET_MULTICAST_STATUS) < 0)
726727 {
@@ -977,7 +978,7 @@ int audio_start_stream()
977978 INFO("control path is disconnected");
978979 break;
979980 }
980- INFO("%s: a2dp stream not started,wait 100mse & retry");
981+ INFO("%s: a2dp stream not started,wait 100mse & retry", __func__);
981982 usleep(100000);
982983 }
983984 if (audio_stream.state != AUDIO_A2DP_STATE_STARTED)
@@ -1067,9 +1068,6 @@ void clear_a2dpsuspend_flag()
10671068 void * audio_get_codec_config(uint8_t *multicast_status, uint8_t *num_dev,
10681069 audio_format_t *codec_type)
10691070 {
1070- char *p_common_cfg = &audio_stream.codec_cfg[0];
1071- int i;
1072-
10731071 INFO("%s: state = %s",__func__,dump_a2dp_hal_state(audio_stream.state));
10741072
10751073 a2dp_get_multicast_status(&audio_stream, multicast_status,num_dev);
--- a/audio_a2dp_hw/bthost_ipc.h
+++ b/audio_a2dp_hw/bthost_ipc.h
@@ -154,7 +154,7 @@ typedef struct {
154154 int (*a2dp_read_audio_config)(struct a2dp_stream_common *common);
155155 int (*skt_read)(int fd,void *buf, size_t bytes);
156156 int (*skt_write)(int fd,const void *buf, size_t bytes);
157- void (*skt_disconnect)(int fd);
157+ int (*skt_disconnect)(int fd);
158158 int (*a2dp_command)(struct a2dp_stream_common *common,char cmd);
159159 int (*audio_stream_open)(void);
160160 int (*audio_stream_close)(void);
--- a/bta/Android.mk
+++ b/bta/Android.mk
@@ -96,7 +96,6 @@ LOCAL_C_INCLUDES+= . \
9696 $(LOCAL_PATH)/../udrv/include \
9797 $(LOCAL_PATH)/../vnd/include \
9898 $(LOCAL_PATH)/../utils/include \
99- $(TARGET_OUT_HEADERS)/bt/hci_qcomm_init/aptX \
10099 $(bluetooth_C_INCLUDES)
101100
102101 LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DBUILDCFG
--- a/bta/av/bta_av_aact.c
+++ b/bta/av/bta_av_aact.c
@@ -38,6 +38,8 @@
3838 #include "avdt_api.h"
3939 #include "bta_av_int.h"
4040 #include "bt_utils.h"
41+#include "a2d_aptx.h"
42+#include "a2d_aptx_hd.h"
4143 #include "l2cdefs.h"
4244 #include "l2c_api.h"
4345 #include "osi/include/properties.h"
@@ -266,20 +268,31 @@ tAVDT_CTRL_CBACK * const bta_av_dt_cback[] =
266268 static UINT8 bta_av_get_scb_handle(tBTA_AV_SCB *p_scb, UINT8 local_sep)
267269 {
268270 UINT8 xx =0;
269- const int NON_A2DP = 0xFF;
270271 for (xx = 0; xx<BTA_AV_MAX_SEPS; xx++)
271272 {
272273 if ((p_scb->seps[xx].tsep == local_sep) &&
273274 (p_scb->seps[xx].codec_type == p_scb->codec_type))
274275 {
275- if (p_scb->seps[xx].codec_type != NON_A2DP)
276+ if (p_scb->seps[xx].codec_type != A2D_NON_A2DP_MEDIA_CT)
276277 return (p_scb->seps[xx].av_handle);
277278 else {
278- UINT8 vendorId = p_scb->cfg.codec_info[BTA_AV_VENDOR_ID_TYPE_IDX];
279- UINT8 codecId = p_scb->cfg.codec_info[BTA_AV_CODEC_ID_TYPE_IDX];
280-
281- if (codecId == p_scb->seps[xx].codecId && vendorId == p_scb->seps[xx].vendorId)
282- return (p_scb->seps[xx].av_handle);
279+ UINT8 losc = p_scb->cfg.codec_info[0];
280+ if (losc == A2D_APTX_CODEC_LEN)
281+ {
282+ tA2D_APTX_CIE aptx_config;
283+ if (A2D_ParsAptxInfo(&aptx_config, p_scb->cfg.codec_info, FALSE) == A2D_SUCCESS)
284+ if ((aptx_config.codecId == p_scb->seps[xx].codecId) &&
285+ (aptx_config.vendorId == p_scb->seps[xx].vendorId))
286+ return (p_scb->seps[xx].av_handle);
287+ } else if (losc == A2D_APTX_HD_CODEC_LEN)
288+ {
289+ tA2D_APTX_HD_CIE aptx_config;
290+ if (A2D_ParsAptx_hdInfo(&aptx_config, p_scb->cfg.codec_info, FALSE) == A2D_SUCCESS)
291+ if ((aptx_config.codecId == p_scb->seps[xx].codecId) &&
292+ (aptx_config.vendorId == p_scb->seps[xx].vendorId))
293+ return (p_scb->seps[xx].av_handle);
294+ } else
295+ APPL_TRACE_DEBUG("%s: Invalid aptX Losc", __func__)
283296 }
284297 }
285298 }
@@ -784,7 +797,6 @@ static void bta_av_a2d_sdp_cback(BOOLEAN found, tA2D_Service *p_service)
784797 static void bta_av_adjust_seps_idx(tBTA_AV_SCB *p_scb, UINT8 avdt_handle)
785798 {
786799 int xx;
787- const int NON_A2DP = 0xFF;
788800 APPL_TRACE_DEBUG("bta_av_adjust_seps_idx codec_type: %d", p_scb->codec_type);
789801 for(xx=0; xx<BTA_AV_MAX_SEPS; xx++)
790802 {
@@ -793,26 +805,46 @@ static void bta_av_adjust_seps_idx(tBTA_AV_SCB *p_scb, UINT8 avdt_handle)
793805 if((p_scb->seps[xx].av_handle && p_scb->codec_type == p_scb->seps[xx].codec_type)
794806 && (p_scb->seps[xx].av_handle == avdt_handle))
795807 {
796- if (p_scb->seps[xx].codec_type != NON_A2DP)
808+ if (p_scb->seps[xx].codec_type != A2D_NON_A2DP_MEDIA_CT)
797809 {
798810 p_scb->sep_idx = xx;
799811 p_scb->avdt_handle = p_scb->seps[xx].av_handle;
800812 break;
801813 }
802814 else {
803- UINT8 vendorId = p_scb->cfg.codec_info[BTA_AV_VENDOR_ID_TYPE_IDX];
804- UINT8 codecId = p_scb->cfg.codec_info[BTA_AV_CODEC_ID_TYPE_IDX];
805- APPL_TRACE_DEBUG("%s vendorId: %x codecId: %x", __func__, p_scb->seps[xx].vendorId, p_scb->seps[xx].codecId);
806- if (codecId == p_scb->seps[xx].codecId && vendorId == p_scb->seps[xx].vendorId)
815+ UINT8 losc = p_scb->cfg.codec_info[0];
816+ if (losc == A2D_APTX_CODEC_LEN)
807817 {
808- APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
809- APPL_TRACE_DEBUG("%s vendorID: %x codecID: %x", __func__, vendorId, codecId);
810- p_scb->sep_idx = xx;
811- p_scb->avdt_handle = p_scb->seps[xx].av_handle;
812- APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
813- APPL_TRACE_DEBUG("%s p_scb->avdt_handle: %d", __func__, p_scb->avdt_handle);
814- break;
815- }
818+ tA2D_APTX_CIE aptx_config;
819+ if (A2D_ParsAptxInfo(&aptx_config, p_scb->cfg.codec_info, FALSE) == A2D_SUCCESS) {
820+ APPL_TRACE_DEBUG("%s vendorId: %x codecId: %x", __func__, p_scb->seps[xx].vendorId, p_scb->seps[xx].codecId);
821+ if ((aptx_config.codecId == p_scb->seps[xx].codecId) &&
822+ (aptx_config.vendorId == p_scb->seps[xx].vendorId)) {
823+ APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
824+ p_scb->sep_idx = xx;
825+ p_scb->avdt_handle = p_scb->seps[xx].av_handle;
826+ APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
827+ APPL_TRACE_DEBUG("%s p_scb->avdt_handle: %d", __func__, p_scb->avdt_handle);
828+ break;
829+ }
830+ }
831+ } else if (losc == A2D_APTX_HD_CODEC_LEN)
832+ {
833+ tA2D_APTX_HD_CIE aptx_config;
834+ if (A2D_ParsAptx_hdInfo(&aptx_config, p_scb->cfg.codec_info, FALSE) == A2D_SUCCESS) {
835+ APPL_TRACE_DEBUG("%s vendorId: %x codecId: %x", __func__, p_scb->seps[xx].vendorId, p_scb->seps[xx].codecId);
836+ if ((aptx_config.codecId == p_scb->seps[xx].codecId) &&
837+ (aptx_config.vendorId == p_scb->seps[xx].vendorId)) {
838+ APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
839+ p_scb->sep_idx = xx;
840+ p_scb->avdt_handle = p_scb->seps[xx].av_handle;
841+ APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
842+ APPL_TRACE_DEBUG("%s p_scb->avdt_handle: %d", __func__, p_scb->avdt_handle);
843+ break;
844+ }
845+ }
846+ } else
847+ APPL_TRACE_DEBUG("%s: Invalid aptX Losc", __func__)
816848 }
817849 }
818850 }
@@ -1572,14 +1604,14 @@ void bta_av_str_opened (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
15721604 }
15731605 /*******************************************************************************
15741606 **
1575-** Function bta_av_co_audio_get_codec_type
1607+** Function bta_av_get_codec_type
15761608 **
1577-** Description Gets the p_scb->codec_type
1609+** Description Returns the codec_type from the most recently used scb
15781610 **
15791611 ** Returns bta_av_cb.codec_type
15801612 **
15811613 *******************************************************************************/
1582-UINT8 bta_av_co_audio_get_codec_type()
1614+UINT8 bta_av_get_codec_type()
15831615 {
15841616 APPL_TRACE_DEBUG("%s [bta_av_cb.codec_type] %x", __func__, bta_av_cb.codec_type);
15851617 return bta_av_cb.codec_type;
--- a/bta/av/bta_av_int.h
+++ b/bta/av/bta_av_int.h
@@ -422,8 +422,8 @@ typedef struct
422422 tBTA_AV_CODEC codec_type; /* codec type */
423423 UINT8 tsep; /* SEP type of local SEP */
424424 tBTA_AV_DATA_CBACK *p_app_data_cback; /* Application callback for media packets */
425- UINT8 vendorId; /* vendorId type */
426- UINT8 codecId; /* codecId type */
425+ UINT32 vendorId; /* vendorId type */
426+ UINT16 codecId; /* codecId type */
427427 } tBTA_AV_SEP;
428428
429429
--- a/bta/av/bta_av_main.c
+++ b/bta/av/bta_av_main.c
@@ -34,6 +34,7 @@
3434
3535 #include "bt_target.h"
3636 #include "osi/include/log.h"
37+#include <cutils/properties.h>
3738
3839 #if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE)
3940 #include "bta_av_co.h"
@@ -48,6 +49,7 @@
4849 #endif
4950
5051 #include "a2d_aptx.h"
52+#include "a2d_aptx_hd.h"
5153
5254 /*****************************************************************************
5355 ** Constants and types
@@ -693,16 +695,15 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)
693695 (*bta_av_a2d_cos.init)(&codec_type, cs.cfg.codec_info,
694696 &cs.cfg.num_protect, cs.cfg.protect_info, index) == TRUE)
695697 {
698+ UINT8* ptr = cs.cfg.codec_info;
699+ tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
700+ UINT32 vendorId = codecInfo->vendorId;
701+ UINT16 codecId = codecInfo->codecId;
702+
696703 if ((*bta_av_a2d_cos.offload)() == TRUE)
697704 {
698705 if(codec_type == A2D_NON_A2DP_MEDIA_CT)
699706 {
700-
701- UINT8* ptr = cs.cfg.codec_info;
702- tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3];
703- UINT8 vendorId = codecInfo->vendorId;
704- UINT8 codecId = codecInfo->codecId;
705-
706707 if (vendorId == A2D_APTX_VENDOR_ID &&
707708 codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
708709 {
@@ -723,24 +724,36 @@ static void bta_av_api_register(tBTA_AV_DATA *p_data)
723724 continue;
724725 }
725726 }
726- }
727- else if((codec_type == A2D_NON_A2DP_MEDIA_CT) && (A2D_check_and_init_aptX() == false))
728- {
729- index++;
730- continue;
727+ } else if (codec_type == A2D_NON_A2DP_MEDIA_CT) {
728+ if ((codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
729+ && (A2D_check_and_init_aptX() == false)) {
730+ APPL_TRACE_WARNING("%s aptX not available ", __func__);
731+ index++;
732+ continue;
733+
734+ } else {
735+ char value[PROPERTY_VALUE_MAX];
736+ bool enableAptXHD = false;
737+ if (property_get("persist.bt.enableAptXHD", value, "false") && strcmp(value, "true") == 0)
738+ enableAptXHD = true;
739+ else
740+ APPL_TRACE_WARNING("%s enableAptXHD property is not set", __func__);
741+
742+ if ((codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID) &&
743+ ((enableAptXHD == false) || (A2D_check_and_init_aptX_HD() == false))) {
744+ APPL_TRACE_WARNING("%s aptX-HD not available", __func__);
745+ index++;
746+ continue;
747+ }
748+ }
731749 }
732750
733751 if(AVDT_CreateStream(&p_scb->seps[index - startIndex].av_handle, &cs) ==
734752 AVDT_SUCCESS)
735753 {
736754 if ((profile_initialized == UUID_SERVCLASS_AUDIO_SOURCE) &&
737- (index == BTIF_SV_AV_AA_APTX_INDEX))
755+ ((index == BTIF_SV_AV_AA_APTX_INDEX) || (index == BTIF_SV_AV_AA_APTX_HD_INDEX)))
738756 {
739- UINT8* ptr = cs.cfg.codec_info;
740- tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3];
741- UINT8 vendorId = codecInfo->vendorId;
742- UINT8 codecId = codecInfo->codecId;
743-
744757 p_scb->seps[index - startIndex].vendorId = vendorId;
745758 p_scb->seps[index - startIndex].codecId = codecId;
746759 APPL_TRACE_DEBUG("%s audio[%x] vendorId: %x codecId: %x", __func__,
@@ -854,8 +867,7 @@ void bta_av_api_deregister(tBTA_AV_DATA *p_data)
854867 {
855868 tBTA_AV_SCB *p_scb = bta_av_hndl_to_scb(p_data->hdr.layer_specific);
856869
857- // de-initialize aptX
858- A2D_deinit_aptX();
870+ A2D_close_aptX();
859871
860872 if(p_scb)
861873 {
--- a/bta/include/bta_av_api.h
+++ b/bta/include/bta_av_api.h
@@ -97,12 +97,6 @@ typedef UINT8 tBTA_AV_HNDL;
9797 /* offset of codec type in codec info byte array */
9898 #define BTA_AV_CODEC_TYPE_IDX AVDT_CODEC_TYPE_INDEX /* 2 */
9999
100-/* offset of vendorId type in vendorId info byte array */
101-#define BTA_AV_VENDOR_ID_TYPE_IDX AVDT_VENDOR_ID_TYPE_INDEX /* 3 */
102-
103-/* offset of codecId type in codecId info byte array */
104-#define BTA_AV_CODEC_ID_TYPE_IDX AVDT_CODEC_ID_TYPE_INDEX /* 7 */
105-
106100 /* maximum number of streams created: 1 for audio, 1 for video */
107101 #ifndef BTA_AV_NUM_STRS
108102 #define BTA_AV_NUM_STRS 2
@@ -110,9 +104,9 @@ typedef UINT8 tBTA_AV_HNDL;
110104
111105 #ifndef BTA_AV_MAX_SEPS
112106 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
113-#define BTA_AV_MAX_SEPS 3
107+#define BTA_AV_MAX_SEPS 4
114108 #else
115-#define BTA_AV_MAX_SEPS 2
109+#define BTA_AV_MAX_SEPS 3
116110 #endif
117111 #endif
118112
@@ -142,6 +136,9 @@ typedef UINT8 tBTA_AV_CODEC;
142136 /* Company ID in BT assigned numbers */
143137 #define BTA_AV_BT_VENDOR_ID VDP_BT_VENDOR_ID /* Broadcom Corporation */
144138
139+/* Offset for codec configuration in codec info */
140+#define BTA_AV_CFG_START_IDX 3
141+
145142 /* vendor specific codec ID */
146143 #define BTA_AV_CODEC_ID_H264 VDP_CODEC_ID_H264 /* Non-VDP codec ID - H.264 */
147144 #define BTA_AV_CODEC_ID_IMG VDP_CODEC_ID_IMG /* Non-VDP codec ID - images/slideshow */
@@ -896,6 +893,16 @@ void BTA_AvOffloadStart(tBTA_AV_HNDL hndl);
896893 *******************************************************************************/
897894 void BTA_AvOffloadStartRsp(tBTA_AV_HNDL hndl, tBTA_AV_STATUS status);
898895
896+/*******************************************************************************
897+**
898+** Function bta_av_get_codec_type
899+**
900+** Description Returns the codec_type from the most recently used scb
901+**
902+** Returns A2D_NON_A2DP_MEDIA_CT or BTIF_AV_CODEC_SBC
903+**
904+*******************************************************************************/
905+UINT8 bta_av_get_codec_type();
899906
900907 #ifdef __cplusplus
901908 }
--- a/bta/include/bta_av_co.h
+++ b/bta/include/bta_av_co.h
@@ -63,6 +63,7 @@ enum
6363 {
6464 BTIF_SV_AV_AA_SBC_INDEX = 0,
6565 BTIF_SV_AV_AA_APTX_INDEX,
66+ BTIF_SV_AV_AA_APTX_HD_INDEX,
6667 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
6768 BTIF_SV_AV_AA_AAC_INDEX,
6869 #endif
--- a/btif/Android.mk
+++ b/btif/Android.mk
@@ -114,9 +114,9 @@ btifCommonIncludes := \
114114 $(LOCAL_PATH)/../audio_a2dp_hw \
115115 $(LOCAL_PATH)/../utils/include \
116116 $(bluetooth_C_INCLUDES) \
117- $(TARGET_OUT_HEADERS)/bt/hci_qcomm_init/aptX \
118117 external/tinyxml2 \
119- external/zlib
118+ external/zlib \
119+ $(call include-path-for, audio-utils)
120120
121121 ifneq ($(TARGET_SUPPORTS_WEARABLES),true)
122122 btifCommonIncludes += \
--- a/btif/co/bta_av_co.c
+++ b/btif/co/bta_av_co.c
@@ -39,12 +39,14 @@
3939
4040 #include "btif_media.h"
4141 #include "sbc_encoder.h"
42+#include "btif_av.h"
4243 #include "btif_av_co.h"
4344 #include "btif_util.h"
4445 #include "osi/include/mutex.h"
4546
4647 #include "bt_utils.h"
4748 #include "a2d_aptx.h"
49+#include "a2d_aptx_hd.h"
4850 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
4951 #include "a2d_aac.h"
5052 #include "bta_av_aac.h"
@@ -164,6 +166,31 @@ const tA2D_APTX_CIE btif_av_aptx_default_config =
164166 A2D_APTX_FUTURE_2
165167 };
166168
169+const tA2D_APTX_HD_CIE bta_av_co_aptx_hd_caps =
170+{
171+ A2D_APTX_HD_VENDOR_ID,
172+ A2D_APTX_HD_CODEC_ID_BLUETOOTH,
173+ A2D_APTX_HD_SAMPLERATE_44100,
174+ A2D_APTX_HD_CHANNELS_STEREO,
175+ A2D_APTX_HD_ACL_SPRINT_RESERVED0,
176+ A2D_APTX_HD_ACL_SPRINT_RESERVED1,
177+ A2D_APTX_HD_ACL_SPRINT_RESERVED2,
178+ A2D_APTX_HD_ACL_SPRINT_RESERVED3
179+};
180+
181+/* Default aptX_hd codec configuration */
182+const tA2D_APTX_HD_CIE btif_av_aptx_hd_default_config =
183+{
184+ A2D_APTX_HD_VENDOR_ID,
185+ A2D_APTX_HD_CODEC_ID_BLUETOOTH,
186+ A2D_APTX_HD_SAMPLERATE_44100,
187+ A2D_APTX_HD_CHANNELS_STEREO,
188+ A2D_APTX_HD_ACL_SPRINT_RESERVED0,
189+ A2D_APTX_HD_ACL_SPRINT_RESERVED1,
190+ A2D_APTX_HD_ACL_SPRINT_RESERVED2,
191+ A2D_APTX_HD_ACL_SPRINT_RESERVED3
192+};
193+
167194 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
168195 const tA2D_AAC_CIE bta_av_co_aac_caps =
169196 {
@@ -193,7 +220,6 @@ const tA2D_AAC_CIE btif_av_aac_default_config =
193220 };
194221 #endif
195222
196-
197223 /*****************************************************************************
198224 ** Local data
199225 *****************************************************************************/
@@ -250,6 +276,8 @@ typedef struct
250276 tBTIF_AV_CODEC_INFO codec_cfg_sbc_setconfig; /* remote peer setconfig preference (SBC) */
251277 tBTIF_AV_CODEC_INFO codec_cfg_aptx;
252278 tBTIF_AV_CODEC_INFO codec_cfg_aptx_setconfig; /* remote peer setconfig preference (aptX)*/
279+ tBTIF_AV_CODEC_INFO codec_cfg_aptx_hd;
280+ tBTIF_AV_CODEC_INFO codec_cfg_aptx_hd_setconfig; /* remote peer setconfig preference (aptX HD) */
253281 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
254282 tBTIF_AV_CODEC_INFO codec_cfg_aac;
255283 tBTIF_AV_CODEC_INFO codec_cfg_aac_setconfig; /* remote peer setconfig preference (AAC)*/
@@ -268,7 +296,6 @@ static BOOLEAN bta_av_co_audio_peer_supports_codec(tBTA_AV_CO_PEER *p_peer, UINT
268296 static BOOLEAN bta_av_co_audio_media_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg);
269297 static BOOLEAN bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg);
270298 static BOOLEAN bta_av_co_audio_peer_src_supports_codec(tBTA_AV_CO_PEER *p_peer, UINT8 *p_src_index);
271-extern UINT8 bta_av_co_audio_get_codec_type();
272299 #ifdef BTA_AV_SPLIT_A2DP_ENABLED
273300 extern BOOLEAN btif_av_is_codec_offload_supported(int codec);
274301 #else
@@ -418,6 +445,14 @@ BOOLEAN bta_av_co_audio_init(UINT8 *p_codec_type, UINT8 *p_codec_info, UINT8 *p_
418445 *p_codec_type = A2D_NON_A2DP_MEDIA_CT;
419446 A2D_BldAptxInfo(AVDT_MEDIA_AUDIO, (tA2D_APTX_CIE *) &bta_av_co_aptx_caps, p_codec_info);
420447 return TRUE;
448+
449+ case BTIF_SV_AV_AA_APTX_HD_INDEX:
450+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
451+ /* Set up for aptX HD codec */
452+ *p_codec_type = A2D_NON_A2DP_MEDIA_CT;
453+ A2D_BldAptx_hdInfo(AVDT_MEDIA_AUDIO, (tA2D_APTX_HD_CIE *) &bta_av_co_aptx_hd_caps, p_codec_info);
454+ return TRUE;
455+
421456 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
422457 case BTIF_SV_AV_AA_AAC_INDEX:
423458 APPL_TRACE_DEBUG("%s AAC", __func__);
@@ -739,15 +774,17 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
739774 break;
740775 case A2D_NON_A2DP_MEDIA_CT:
741776 {
742- UINT16 codecId = ((tA2D_APTX_CIE*)(&p_codec_info[3]))->codecId;
743- UINT32 vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[3]))->vendorId;
777+ UINT16 codecId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->codecId;
778+ UINT32 vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->vendorId;
744779 APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId );
745780 APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId );
746781
747- if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
748- {
782+ if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID) {
749783 /* aptX */
750784 supported = TRUE;
785+ } else if (codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID) {
786+ /* aptX HD */
787+ supported = TRUE;
751788 }
752789 break;
753790 }
@@ -777,7 +814,7 @@ UINT8 bta_av_co_audio_getconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
777814 APPL_TRACE_DEBUG("%s p_codec_info[%d]: %x", __func__, i, p_codec_info[i]);
778815
779816 if (codec_type == A2D_NON_A2DP_MEDIA_CT)
780- memcpy(p_sink->codec_caps, &p_codec_info[3], AVDT_CODEC_SIZE);
817+ memcpy(p_sink->codec_caps, &p_codec_info[BTA_AV_CFG_START_IDX], AVDT_CODEC_SIZE);
781818 else
782819 memcpy(p_sink->codec_caps, p_codec_info, AVDT_CODEC_SIZE);
783820
@@ -998,8 +1035,8 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
9981035 {
9991036 UINT16 codecId;
10001037 UINT32 vendorId;
1001- codecId = ((tA2D_APTX_CIE*)(&p_codec_info[3]))->codecId;
1002- vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[3]))->vendorId;
1038+ codecId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->codecId;
1039+ vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->vendorId;
10031040 APPL_TRACE_DEBUG("%s codec_type = %x", __func__, codec_type);
10041041 APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
10051042 APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
@@ -1018,12 +1055,16 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
10181055 recfg_needed = TRUE;
10191056 }
10201057
1021- if ((codecId == A2D_APTX_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_VENDOR_ID))
1022- {
1058+ if ((codecId == A2D_APTX_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_VENDOR_ID)) {
10231059 APPL_TRACE_DEBUG("%s aptX", __func__);
10241060 bta_av_co_cb.codec_cfg_aptx_setconfig.id = A2D_NON_A2DP_MEDIA_CT;
10251061 memcpy(bta_av_co_cb.codec_cfg_aptx_setconfig.info, p_codec_info, AVDT_CODEC_SIZE);
10261062 bta_av_co_cb.codec_cfg_setconfig = &bta_av_co_cb.codec_cfg_aptx_setconfig;
1063+ } else if ((codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_HD_VENDOR_ID)) {
1064+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
1065+ bta_av_co_cb.codec_cfg_aptx_hd_setconfig.id = A2D_NON_A2DP_MEDIA_CT;
1066+ memcpy(bta_av_co_cb.codec_cfg_aptx_hd_setconfig.info, p_codec_info, AVDT_CODEC_SIZE);
1067+ bta_av_co_cb.codec_cfg_setconfig = &bta_av_co_cb.codec_cfg_aptx_hd_setconfig;
10271068 }
10281069 break;
10291070 }
@@ -1160,14 +1201,21 @@ void bta_av_co_audio_start(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
11601201 UINT8 *p_codec_info, BOOLEAN *p_no_rtp_hdr)
11611202 {
11621203 UNUSED(hndl);
1163- UNUSED(codec_type);
1164- UNUSED(p_codec_info);
1165- UNUSED(p_no_rtp_hdr);
11661204
11671205 FUNC_TRACE();
11681206
11691207 APPL_TRACE_DEBUG("bta_av_co_audio_start");
11701208
1209+ if (codec_type == A2D_NON_A2DP_MEDIA_CT) {
1210+ UINT16 codecId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->codecId;
1211+ UINT32 vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->vendorId;
1212+
1213+ // for aptX, we only add RTP hdr along with CP
1214+ if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID) {
1215+ if (!bta_av_co_cb.cp.active)
1216+ *p_no_rtp_hdr = TRUE;
1217+ }
1218+ }
11711219 }
11721220
11731221 /*******************************************************************************
@@ -1336,10 +1384,15 @@ static BOOLEAN bta_av_co_audio_codec_build_config(const UINT8 *p_codec_caps, UIN
13361384 APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
13371385 APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
13381386
1339- memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg->info, A2D_APTX_CODEC_LEN+1);
1340- APPL_TRACE_DEBUG("%s aptX",__func__);
1387+ if ((codecId == A2D_APTX_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_VENDOR_ID)) {
1388+ memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg->info, A2D_APTX_CODEC_LEN+1);
1389+ APPL_TRACE_DEBUG("%s aptX",__func__);
1390+ } else if ((codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_HD_VENDOR_ID)) {
1391+ memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg->info, A2D_APTX_HD_CODEC_LEN+1);
1392+ APPL_TRACE_DEBUG("%s aptX HD",__func__);
1393+ }
13411394 break;
1342- }
1395+ }
13431396
13441397 default:
13451398 APPL_TRACE_ERROR("bta_av_co_audio_codec_build_config: unsupported codec id %d", bta_av_co_cb.codec_cfg->id);
@@ -1495,19 +1548,23 @@ static BOOLEAN bta_av_co_audio_codec_match(const UINT8 *p_codec_caps, UINT8 code
14951548 APPL_TRACE_DEBUG("%s codecId = %d ", __func__, codecId);
14961549 APPL_TRACE_DEBUG("%s vendorId = %x ", __func__, vendorId);
14971550
1498- if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
1499- {
1551+ if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID) {
15001552 /* aptX Classic */
15011553 APPL_TRACE_DEBUG("%s aptX", __func__);
15021554 return bta_av_co_audio_codec_cfg_matches_caps(bta_av_co_cb.codec_cfg_aptx.id, p_codec_caps, bta_av_co_cb.codec_cfg_aptx.info);
15031555 break;
1556+ } else if (codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID) {
1557+ /* aptX HD */
1558+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
1559+ return bta_av_co_audio_codec_cfg_matches_caps(bta_av_co_cb.codec_cfg_aptx_hd.id, p_codec_caps, bta_av_co_cb.codec_cfg_aptx_hd.info);
1560+ break;
15041561 } else {
1505- APPL_TRACE_ERROR("%s incorrect aptX vendor and codec ID combination (codec ID: %d)", __func__, codecId);
1506- APPL_TRACE_ERROR("%s incorrect aptX vendor (%x) and codec ID combination ", __func__, vendorId);
1562+ APPL_TRACE_ERROR("%s incorrect codecId (%d)", __func__, codecId);
1563+ APPL_TRACE_ERROR("%s incorrect vendorId (%x)", __func__, vendorId);
15071564 break;
15081565 }
15091566 }
1510- default:
1567+ default:
15111568 return bta_av_co_audio_codec_cfg_matches_caps(bta_av_co_cb.codec_cfg_sbc.id, p_codec_caps, bta_av_co_cb.codec_cfg_sbc.info);
15121569 break;
15131570 }
@@ -1636,51 +1693,89 @@ static BOOLEAN bta_av_co_audio_peer_supports_codec(tBTA_AV_CO_PEER *p_peer, UINT
16361693 /* Configure the codec type to look for */
16371694 codec_type = bta_av_co_cb.codec_cfg->id;
16381695
1639-/* Check for aptX as this is order of priority.
1640- * Check for aptX-HD, then aptX-LL before aptX Classic as
1696+/* Check for aptX HD before aptX Classic as
16411697 * this is order of priority, if supported return true.
1698+ * multicast is not supported for aptX
16421699 */
1643- if ((!bt_split_a2dp_enabled && isA2dAptXEnabled && (btif_max_av_clients <= 1)) ||
1700+ if ((!bt_split_a2dp_enabled && isA2dAptXEnabled && (btif_av_is_multicast_supported() == FALSE)) ||
16441701 (bt_split_a2dp_enabled && btif_av_is_codec_offload_supported(APTX)))
16451702 {
1646- UINT16 codecId;
1647- UINT32 vendorId;
1648- UINT8* aptx_capabilities;
1649-
1650- for (index = 0; index < p_peer->num_sup_snks; index++)
1651- {
1652- if (p_peer->snks[index].codec_type == A2D_NON_A2DP_MEDIA_CT)
1653- {
1654- aptx_capabilities = &(p_peer->snks[index].codec_caps[0]);
1655- codecId = ((tA2D_APTX_CIE*)aptx_capabilities)->codecId;
1656- vendorId = ((tA2D_APTX_CIE*)aptx_capabilities)->vendorId;
1657- int i = 0;
1658- for ( i = 0 ; i < AVDT_CODEC_SIZE; i++) {
1659- APPL_TRACE_DEBUG("%s codec_caps[%d]: %x", __func__, i, p_peer->snks[index].codec_caps[i]);
1660- }
1661- APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
1662- APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
1663- APPL_TRACE_DEBUG("%s p_peer->snks[index].codec_type = %x", __func__, p_peer->snks[index].codec_type );
1664-
1665- if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
1666- {
1667- if (p_snk_index)
1703+ UINT16 codecId;
1704+ UINT32 vendorId;
1705+ UINT8* aptx_capabilities;
1706+
1707+ if (isA2dAptXHdEnabled) {
1708+ for (index = 0; index < p_peer->num_sup_snks; index++)
1709+ {
1710+ if (p_peer->snks[index].codec_type == A2D_NON_A2DP_MEDIA_CT)
1711+ {
1712+ aptx_capabilities = &(p_peer->snks[index].codec_caps[0]);
1713+ codecId = ((tA2D_APTX_HD_CIE*)aptx_capabilities)->codecId;
1714+ vendorId = ((tA2D_APTX_HD_CIE*)aptx_capabilities)->vendorId;
1715+ int i = 0;
1716+ for ( i = 0 ; i < AVDT_CODEC_SIZE; i++) {
1717+ APPL_TRACE_DEBUG("%s codec_caps[%d]: %x", __func__, i, p_peer->snks[index].codec_caps[i]);
1718+ }
1719+ APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
1720+ APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
1721+ APPL_TRACE_DEBUG("%s p_peer->snks[index].codec_type = %x", __func__, p_peer->snks[index].codec_type );
1722+
1723+ if (codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID )
1724+ {
1725+ if (p_snk_index)
1726+ *p_snk_index = index;
1727+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
1728+
1729+ if (bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps, A2D_NON_A2DP_MEDIA_CT))
1730+ {
1731+ #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
1732+ if (bta_av_co_audio_sink_has_scmst(&p_peer->snks[index]))
1733+ #endif
1734+ {
1735+ bta_av_co_cb.current_codec_id = bta_av_co_cb.codec_cfg_aptx_hd.id;
1736+ bta_av_co_cb.codec_cfg = &bta_av_co_cb.codec_cfg_aptx_hd;
1737+ return TRUE;
1738+ }
1739+ }
1740+ }
1741+ }
1742+ }
1743+ }
1744+
1745+ for (index = 0; index < p_peer->num_sup_snks; index++)
1746+ {
1747+ if (p_peer->snks[index].codec_type == A2D_NON_A2DP_MEDIA_CT)
1748+ {
1749+ aptx_capabilities = &(p_peer->snks[index].codec_caps[0]);
1750+ codecId = ((tA2D_APTX_CIE*)aptx_capabilities)->codecId;
1751+ vendorId = ((tA2D_APTX_CIE*)aptx_capabilities)->vendorId;
1752+ int i = 0;
1753+ for ( i = 0 ; i < AVDT_CODEC_SIZE; i++) {
1754+ APPL_TRACE_DEBUG("%s codec_caps[%d]: %x", __func__, i, p_peer->snks[index].codec_caps[i]);
1755+ }
1756+ APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
1757+ APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
1758+ APPL_TRACE_DEBUG("%s p_peer->snks[index].codec_type = %x", __func__, p_peer->snks[index].codec_type );
1759+
1760+ if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
1761+ {
1762+ if (p_snk_index)
16681763 *p_snk_index = index;
1669- APPL_TRACE_DEBUG("%s aptX", __func__);
1764+ APPL_TRACE_DEBUG("%s aptX", __func__);
16701765
1671- if (bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps, A2D_NON_A2DP_MEDIA_CT))
1672- {
1766+ if (bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps, A2D_NON_A2DP_MEDIA_CT))
1767+ {
16731768 #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
1674- if (bta_av_co_audio_sink_has_scmst(&p_peer->snks[index]))
1769+ if (bta_av_co_audio_sink_has_scmst(&p_peer->snks[index]))
16751770 #endif
1676- {
1677- bta_av_co_cb.current_codec_id = bta_av_co_cb.codec_cfg_aptx.id;
1678- bta_av_co_cb.codec_cfg = &bta_av_co_cb.codec_cfg_aptx;
1679- return TRUE;
1680- }
1681- }
1771+ {
1772+ bta_av_co_cb.current_codec_id = bta_av_co_cb.codec_cfg_aptx.id;
1773+ bta_av_co_cb.codec_cfg = &bta_av_co_cb.codec_cfg_aptx;
1774+ return TRUE;
1775+ }
1776+ }
16821777 }
1683- }
1778+ }
16841779 }
16851780 } else
16861781 APPL_TRACE_DEBUG("%s aptX is disabled", __func__);
@@ -1879,11 +1974,16 @@ static BOOLEAN bta_av_co_audio_media_supports_config(UINT8 codec_type, const UIN
18791974 APPL_TRACE_DEBUG("%s codecId = %d ", __func__, codecId);
18801975 APPL_TRACE_DEBUG("%s vendorId = %x ", __func__, vendorId);
18811976
1882- if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
1883- {
1977+ if (codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID) {
1978+ APPL_TRACE_DEBUG("%s tA2D_APTX_CIE aptX HD", __func__);
1979+ if (a2d_av_aptx_hd_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_APTX_HD_CIE *)&bta_av_co_aptx_hd_caps)) {
1980+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
1981+ return FALSE;
1982+ }
1983+ break;
1984+ } else if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID) {
18841985 APPL_TRACE_DEBUG("%s tA2D_APTX_CIE aptX", __func__);
1885- if (a2d_av_aptx_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_APTX_CIE *)&bta_av_co_aptx_caps))
1886- {
1986+ if (a2d_av_aptx_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_APTX_CIE *)&bta_av_co_aptx_caps)) {
18871987 APPL_TRACE_DEBUG("%s aptX", __func__);
18881988 return FALSE;
18891989 }
@@ -1962,9 +2062,9 @@ BOOLEAN bta_av_co_audio_codec_supported(tBTIF_STATUS *p_status)
19622062 /* Check if this sink supports SCMS */
19632063 cp_active = bta_av_co_audio_sink_has_scmst(p_sink);
19642064 #endif
1965- APPL_TRACE_DEBUG("%s %x", __func__, bta_av_co_cb.current_codec_id);
2065+ APPL_TRACE_DEBUG("%s current_codec_id: %x", __func__, bta_av_co_cb.current_codec_id);
19662066 APPL_TRACE_DEBUG("%s p_scb_codec_type: %x", __func__, p_scb_codec_type);
1967- p_scb_codec_type = bta_av_co_audio_get_codec_type();
2067+ p_scb_codec_type = bta_av_get_codec_type();
19682068 APPL_TRACE_DEBUG("%s p_scb_codec_type: %x", __func__, p_scb_codec_type);
19692069 /* Check if this is a new configuration (new sink or new config) */
19702070 if ((p_sink != p_peer->p_snk) ||
@@ -2042,6 +2142,11 @@ void bta_av_co_audio_codec_reset(void)
20422142 if (A2D_BldAptxInfo(A2D_MEDIA_TYPE_AUDIO, (tA2D_APTX_CIE *)&btif_av_aptx_default_config, bta_av_co_cb.codec_cfg_aptx.info) != A2D_SUCCESS)
20432143 APPL_TRACE_ERROR("%s A2D_BldAptxInfo failed", __func__);
20442144
2145+ /* Reset the Current configuration to aptX HD */
2146+ bta_av_co_cb.codec_cfg_aptx_hd.id = A2D_NON_A2DP_MEDIA_CT;
2147+ if (A2D_BldAptx_hdInfo(A2D_MEDIA_TYPE_AUDIO, (tA2D_APTX_HD_CIE *)&btif_av_aptx_hd_default_config, bta_av_co_cb.codec_cfg_aptx_hd.info) != A2D_SUCCESS)
2148+ APPL_TRACE_ERROR("%s A2D_BldAptx_hdInfo failed", __func__);
2149+
20452150 mutex_global_unlock();
20462151 }
20472152
@@ -2062,6 +2167,8 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
20622167 tBTIF_AV_CODEC_INFO new_cfg_sbc;
20632168 tA2D_APTX_CIE aptx_config;
20642169 tBTIF_AV_CODEC_INFO new_cfg_aptx;
2170+ tA2D_APTX_HD_CIE aptx_hd_config;
2171+ tBTIF_AV_CODEC_INFO new_cfg_aptx_hd;
20652172 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
20662173 tA2D_AAC_CIE aac_config;
20672174 tBTIF_AV_CODEC_INFO new_cfg_aac;
@@ -2087,13 +2194,16 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
20872194 return FALSE;
20882195 }
20892196 if ((p_feeding->cfg.pcm.bit_per_sample != 8) &&
2090- (p_feeding->cfg.pcm.bit_per_sample != 16))
2197+ (p_feeding->cfg.pcm.bit_per_sample != 16) &&
2198+ (p_feeding->cfg.pcm.bit_per_sample != 32))
20912199 {
20922200 APPL_TRACE_ERROR("bta_av_co_audio_set_codec PCM sample size unsupported");
20932201 return FALSE;
20942202 }
20952203 new_cfg_aptx.id = A2D_NON_A2DP_MEDIA_CT;
20962204 aptx_config = btif_av_aptx_default_config;
2205+ new_cfg_aptx_hd.id = A2D_NON_A2DP_MEDIA_CT;
2206+ aptx_hd_config = btif_av_aptx_hd_default_config;
20972207 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
20982208 new_cfg_aac.id = BTIF_AV_CODEC_M24;
20992209 aac_config = btif_av_aac_default_config;
@@ -2108,6 +2218,7 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
21082218 case 48000:
21092219 sbc_config.samp_freq = A2D_SBC_IE_SAMP_FREQ_48;
21102220 aptx_config.sampleRate = A2D_APTX_SAMPLERATE_48000;
2221+ aptx_hd_config.sampleRate = A2D_APTX_HD_SAMPLERATE_48000;
21112222 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
21122223 aac_config.samp_freq = A2D_AAC_IE_SAMP_FREQ_48000;
21132224 #endif
@@ -2118,6 +2229,7 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
21182229 case 44100:
21192230 sbc_config.samp_freq = A2D_SBC_IE_SAMP_FREQ_44;
21202231 aptx_config.sampleRate = A2D_APTX_SAMPLERATE_44100;
2232+ aptx_hd_config.sampleRate = A2D_APTX_HD_SAMPLERATE_44100;
21212233 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
21222234 aac_config.samp_freq = A2D_AAC_IE_SAMP_FREQ_44100;
21232235 #endif
@@ -2138,6 +2250,11 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
21382250 APPL_TRACE_ERROR("%s A2D_BldAptxInfo failed", __func__);
21392251 return FALSE;
21402252 }
2253+ if (A2D_BldAptx_hdInfo(A2D_MEDIA_TYPE_AUDIO, &aptx_hd_config, new_cfg_aptx_hd.info) != A2D_SUCCESS)
2254+ {
2255+ APPL_TRACE_ERROR("%s A2D_BldAptx_hdInfo failed", __func__);
2256+ return FALSE;
2257+ }
21412258 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
21422259 if (A2D_BldAacInfo(A2D_MEDIA_TYPE_AUDIO, &aac_config, new_cfg_aac.info) != A2D_SUCCESS)
21432260 {
@@ -2158,6 +2275,7 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
21582275 bta_av_co_cb.codec_cfg_sbc = new_cfg_sbc;
21592276 bta_av_co_cb.codec_cfg = &bta_av_co_cb.codec_cfg_sbc;
21602277 bta_av_co_cb.codec_cfg_aptx= new_cfg_aptx;
2278+ bta_av_co_cb.codec_cfg_aptx_hd = new_cfg_aptx_hd;
21612279 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
21622280 bta_av_co_cb.codec_cfg_aac = new_cfg_aac;
21632281 #endif
@@ -2169,9 +2287,11 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
21692287
21702288 UINT8 bta_av_select_codec(UINT8 hdl)
21712289 {
2172- // Some circumstances - bta_av_co functions are called before codec clock is initialised
21732290 if (NULL == bta_av_co_cb.codec_cfg)
21742291 {
2292+ // Some circumstances - bta_av_co functions are called before
2293+ // codec clock is initialised
2294+ APPL_TRACE_ERROR("%s hdl = %d, no codec configured", __func__, hdl);
21752295 return BTIF_AV_CODEC_NONE;
21762296 }
21772297 else
@@ -2194,7 +2314,7 @@ UINT8 bta_av_select_codec(UINT8 hdl)
21942314 }
21952315 }
21962316
2197-UINT8 bta_av_get_current_codec()
2317+UINT8 bta_av_co_get_current_codec()
21982318 {
21992319 // Some circumstances - bta_av_co functions are called before codec clock is initialised
22002320 if (NULL == bta_av_co_cb.codec_cfg)
@@ -2203,7 +2323,7 @@ UINT8 bta_av_get_current_codec()
22032323 return bta_av_co_cb.codec_cfg->id;
22042324 }
22052325
2206-UINT8* bta_av_get_current_codecInfo()
2326+UINT8* bta_av_co_get_current_codecInfo()
22072327 {
22082328 // We assume that the configuration block is always valid when this is called.
22092329 return &bta_av_co_cb.codec_cfg->info[0];
@@ -2244,15 +2364,20 @@ BOOLEAN bta_av_co_audio_get_codec_config(UINT8 *p_config, UINT16 *p_minmtu, UINT
22442364 result = TRUE;
22452365 else
22462366 memcpy((tA2D_SBC_CIE *) p_config, &btif_av_sbc_default_config, sizeof(tA2D_SBC_CIE));
2247- }
2248- if (type == A2D_NON_A2DP_MEDIA_CT && ((tA2D_APTX_CIE *)p_config)->vendorId == A2D_APTX_VENDOR_ID && ((tA2D_APTX_CIE *)p_config)->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
2249- {
2367+ } else if (type == A2D_NON_A2DP_MEDIA_CT && ((tA2D_APTX_CIE *)p_config)->vendorId == A2D_APTX_VENDOR_ID && ((tA2D_APTX_CIE *)p_config)->codecId == A2D_APTX_CODEC_ID_BLUETOOTH) {
22502368 APPL_TRACE_DEBUG("%s aptX", __func__);
22512369 tA2D_APTX_CIE *aptx_config = (tA2D_APTX_CIE *)p_config;
22522370 if (A2D_ParsAptxInfo(aptx_config, bta_av_co_cb.codec_cfg_aptx.info, FALSE) == A2D_SUCCESS)
22532371 result = TRUE;
22542372 else
22552373 memcpy((tA2D_APTX_CIE *) p_config, &btif_av_aptx_default_config, sizeof(tA2D_APTX_CIE));
2374+ } else if (type == A2D_NON_A2DP_MEDIA_CT && ((tA2D_APTX_HD_CIE *)p_config)->vendorId == A2D_APTX_HD_VENDOR_ID && ((tA2D_APTX_HD_CIE *)p_config)->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH) {
2375+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
2376+ tA2D_APTX_HD_CIE *aptx_hd_config = (tA2D_APTX_HD_CIE *)p_config;
2377+ if (A2D_ParsAptx_hdInfo(aptx_hd_config, bta_av_co_cb.codec_cfg_aptx_hd.info, FALSE) == A2D_SUCCESS)
2378+ result = TRUE;
2379+ else
2380+ memcpy((tA2D_APTX_HD_CIE *) p_config, &btif_av_aptx_hd_default_config, sizeof(tA2D_APTX_HD_CIE));
22562381 } else {
22572382 APPL_TRACE_DEBUG("%s vendorId: %d codecId: %d\n", __func__, ((tA2D_APTX_CIE *)p_config)->vendorId, ((tA2D_APTX_CIE *)p_config)->codecId);
22582383 }
--- a/btif/include/btif_av.h
+++ b/btif/include/btif_av.h
@@ -257,4 +257,26 @@ void btif_av_get_peer_addr(bt_bdaddr_t *peer_bda);
257257 #define btif_av_get_peer_addr(peer_bda) (0)
258258 #endif
259259
260+/*******************************************************************************
261+**
262+** Function btif_av_get_multicast_state
263+**
264+** Description Check if A2DP multicast is enabled
265+**
266+** Returns TRUE if a2dp multicast is enabled
267+**
268+*******************************************************************************/
269+BOOLEAN btif_av_get_multicast_state();
270+
271+/*******************************************************************************
272+**
273+** Function btif_av_is_multicast_supported
274+**
275+** Description Check if A2DP multicast is supported
276+**
277+** Returns TRUE if a2dp multicast is supported
278+**
279+*******************************************************************************/
280+BOOLEAN btif_av_is_multicast_supported();
281+
260282 #endif /* BTIF_AV_H */
--- a/btif/include/btif_av_co.h
+++ b/btif/include/btif_av_co.h
@@ -111,25 +111,25 @@ BOOLEAN bta_av_co_audio_set_codec(const tBTIF_AV_MEDIA_FEEDINGS *p_feeding, tBTI
111111
112112 /*******************************************************************************
113113 **
114- ** Function bta_av_get_current_codec
114+ ** Function bta_av_co_get_current_codec
115115 **
116116 ** Description Get the current codec type.
117117 **
118118 ** Returns Codec Type Value
119119 **
120120 *******************************************************************************/
121-UINT8 bta_av_get_current_codec();
121+UINT8 bta_av_co_get_current_codec();
122122
123123 /*******************************************************************************
124124 **
125- ** Function bta_av_get_current_codecInfo
125+ ** Function bta_av_co_get_current_codecInfo
126126 **
127127 ** Description Get the current codec Info.
128128 **
129129 ** Returns Returns pointer to Info
130130 **
131131 *******************************************************************************/
132-UINT8* bta_av_get_current_codecInfo();
132+UINT8* bta_av_co_get_current_codecInfo();
133133
134134 /*******************************************************************************
135135 **
@@ -227,15 +227,4 @@ BOOLEAN bta_av_co_get_remote_bitpool_pref(UINT8 *min, UINT8 *max);
227227 *******************************************************************************/
228228 UINT8 bta_av_select_codec(tBTA_AV_HNDL hdl);
229229
230-/*******************************************************************************
231- **
232- ** Function bta_av_get_current_codec
233- **
234- ** Description Get current codec id selected for streaming.
235- **
236- ** Returns Return current codec id
237- **
238- *******************************************************************************/
239-UINT8 bta_av_get_current_codec(void);
240-
241230 #endif
--- a/btif/include/btif_media.h
+++ b/btif/include/btif_media.h
@@ -62,8 +62,7 @@
6262 #define BTIF_MEDIA_TRSCD_OFF 0
6363 #define BTIF_MEDIA_TRSCD_PCM_2_SBC 1 /* Tx */
6464 #define BTIF_MEDIA_TRSCD_PCM_2_APTX 2
65-
66-extern int btif_max_av_clients; /* maximum number of AV clients supported */
65+#define BTIF_MEDIA_TRSCD_PCM_2_APTX_HD 3
6766
6867 /*******************************************************************************
6968 ** Data types
@@ -82,8 +81,8 @@ typedef struct
8281 UINT8 AllocationMethod; /* loudness or SNR*/
8382 UINT16 MtuSize; /* peer mtu size */
8483 UINT8 CodecType; /* SBC or Non-A2DP */
85- UINT8 BluetoothVendorID; /* Bluetooth Vendor ID */
86- UINT8 BluetoothCodecID; /* Bluetooth Codec ID */
84+ UINT32 BluetoothVendorID; /* Bluetooth Vendor ID */
85+ UINT16 BluetoothCodecID; /* Bluetooth Codec ID */
8786 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
8887 UINT8 ObjectType;
8988 UINT32 bit_rate;
@@ -100,8 +99,8 @@ typedef struct
10099 UINT8 MaxBitPool; /* Maximum peer bitpool */
101100 UINT8 MinBitPool; /* Minimum peer bitpool */
102101 UINT8 CodecType; /* SBC or Non-A2DP */
103- UINT8 BluetoothVendorID; /* Bluetooth Vendor ID */
104- UINT8 BluetoothCodecID; /* Bluetooth Codec ID */
102+ UINT32 BluetoothVendorID; /* Bluetooth Vendor ID */
103+ UINT16 BluetoothCodecID; /* Bluetooth Codec ID */
105104 } tBTIF_MEDIA_UPDATE_AUDIO;
106105
107106 /* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */
--- a/btif/src/btif_av.c
+++ b/btif/src/btif_av.c
@@ -3493,6 +3493,19 @@ BOOLEAN btif_av_get_ongoing_multicast()
34933493
34943494 /******************************************************************************
34953495 **
3496+** Function btif_av_is_multicast_supported
3497+**
3498+** Description Returns TRUE if multicast is supported
3499+**
3500+** Returns BOOLEAN
3501+******************************************************************************/
3502+BOOLEAN btif_av_is_multicast_supported()
3503+{
3504+ return is_multicast_supported;
3505+}
3506+
3507+/******************************************************************************
3508+**
34963509 ** Function btif_av_is_offload_supported
34973510 **
34983511 ** Description Returns split mode status
--- a/btif/src/btif_media_task.c
+++ b/btif/src/btif_media_task.c
@@ -42,11 +42,14 @@
4242 #include <pthread.h>
4343 #include <stdint.h>
4444 #include <stdio.h>
45+#include <dlfcn.h>
4546 #include <string.h>
4647 #include <sys/stat.h>
4748 #include <sys/time.h>
4849 #include <sys/types.h>
4950 #include <unistd.h>
51+#include <audio_utils/primitives.h>
52+#include <audio_utils/format.h>
5053
5154 #include <hardware/bluetooth.h>
5255
@@ -61,6 +64,7 @@
6164 #include "a2d_int.h"
6265 #include "a2d_sbc.h"
6366 #include "a2d_aptx.h"
67+#include "a2d_aptx_hd.h"
6468 #include "a2d_aac.h"
6569 #include "audio_a2dp_hw.h"
6670 #include "bt_target.h"
@@ -193,8 +197,10 @@ enum {
193197
194198 #if (BTA_AV_CO_CP_SCMS_T == TRUE)
195199 #define BTIF_MEDIA_AA_APTX_OFFSET (AVDT_MEDIA_OFFSET + 1)
200+#define BTIF_MEDIA_AA_APTX_HD_OFFSET (AVDT_MEDIA_OFFSET + 1)
196201 #else
197202 #define BTIF_MEDIA_AA_APTX_OFFSET (AVDT_MEDIA_OFFSET - AVDT_MEDIA_HDR_SIZE) //no RTP header for aptX classic
203+#define BTIF_MEDIA_AA_APTX_HD_OFFSET (AVDT_MEDIA_OFFSET) //there is an RTP header for aptX HD, but no CP byte
198204 #endif
199205 /* Define the bitrate step when trying to match bitpool value */
200206 #ifndef BTIF_MEDIA_BITRATE_STEP
@@ -372,7 +378,9 @@ typedef struct
372378 SBC_ENC_PARAMS encoder;
373379 UINT16 offset;
374380 A2D_APTX_ENC_PARAMS aptxEncoderParams;
381+ A2D_APTX_HD_ENC_PARAMS aptxhdEncoderParams;
375382 UINT16 as16PcmBuffer[1024];
383+ UINT32 as32PcmBuffer[1024];
376384 UINT8 busy_level;
377385 void* av_sm_hdl;
378386 UINT8 a2dp_cmd_pending; /* we can have max one command pending */
@@ -446,7 +454,6 @@ static void btif_media_task_handle_inc_media(tBT_SBC_HDR*p_msg);
446454 #endif
447455
448456 BOOLEAN bta_av_co_audio_get_codec_config(UINT8 *p_config, UINT16 *p_minmtu, UINT8 type);
449-UINT8 bta_av_get_current_codec();
450457 static thread_t *aptx_thread = NULL;
451458
452459 #if (BTA_AV_INCLUDED == TRUE)
@@ -518,7 +525,6 @@ static fixed_queue_t *btif_media_cmd_msg_queue;
518525 static thread_t *worker_thread;
519526
520527 BOOLEAN bta_av_co_audio_get_codec_config(UINT8 *p_config, UINT16 *p_minmtu, UINT8 type);
521-UINT8 bta_av_get_current_codec();
522528
523529 extern BOOLEAN bt_split_a2dp_enabled;
524530 extern int btif_max_av_clients;
@@ -895,7 +901,7 @@ static void btif_recv_ctrl_data(void)
895901 }
896902 else //get playing device hdl
897903 {
898- codec_id = bta_av_get_current_codec();
904+ codec_id = bta_av_co_get_current_codec();
899905 }
900906
901907 a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
@@ -918,7 +924,7 @@ static void btif_recv_ctrl_data(void)
918924 else if (codec_id == A2D_NON_A2DP_MEDIA_CT) //this is changed to non-a2dp VS codec
919925 {
920926 //ADD APTX support
921- UINT8* ptr = bta_av_get_current_codecInfo();
927+ UINT8* ptr = bta_av_co_get_current_codecInfo();
922928 int j;
923929 UINT8 *p_ptr = ptr;
924930 for(j=0; j< (int)sizeof(tA2D_APTX_CIE);j++)
@@ -928,8 +934,8 @@ static void btif_recv_ctrl_data(void)
928934 if (ptr)
929935 {
930936 tA2D_APTX_CIE* codecInfo = 0;
931- codecInfo = (tA2D_APTX_CIE*) &ptr[3];
932- if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID
937+ codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
938+ if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID
933939 && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
934940 {
935941 tA2D_APTX_CIE aptx_config;
@@ -1075,15 +1081,16 @@ static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
10751081 static BOOLEAN btif_media_task_is_aptx_configured()
10761082 {
10771083 BOOLEAN result = FALSE;
1078- UINT8 codectype = bta_av_get_current_codec();
1079-
1080- if (codectype == A2D_NON_A2DP_MEDIA_CT)
1081- {
1082- UINT8* ptr = bta_av_get_current_codecInfo();
1083- if (ptr)
1084- {
1085- tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3];
1086- if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
1084+ UINT8 codectype = bta_av_co_get_current_codec();
1085+
1086+ if (codectype == A2D_NON_A2DP_MEDIA_CT) {
1087+ UINT8* ptr = bta_av_co_get_current_codecInfo();
1088+ if (ptr) {
1089+ tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
1090+ if ((codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
1091+ || (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH))
1092+ APPL_TRACE_DEBUG("%s codecId %d", __func__, codecInfo->codecId);
1093+ APPL_TRACE_DEBUG("%s vendorId %x", __func__, codecInfo->vendorId);
10871094 result = TRUE;
10881095 }
10891096 }
@@ -1093,16 +1100,16 @@ static BOOLEAN btif_media_task_is_aptx_configured()
10931100 A2D_AptXCodecType btif_media_task_get_aptX_codec_type()
10941101 {
10951102 A2D_AptXCodecType codec = APTX_CODEC_NONE;
1096- UINT8 a2dp_codectype = bta_av_get_current_codec();
1103+ UINT8 a2dp_codectype = bta_av_co_get_current_codec();
10971104
1098- if (a2dp_codectype == A2D_NON_A2DP_MEDIA_CT)
1099- {
1100- UINT8* ptr = bta_av_get_current_codecInfo();
1101- if (ptr)
1102- {
1103- tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3];
1105+ if (a2dp_codectype == A2D_NON_A2DP_MEDIA_CT) {
1106+ UINT8* ptr = bta_av_co_get_current_codecInfo();
1107+ if (ptr) {
1108+ tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
11041109 if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
11051110 codec = APTX_CODEC;
1111+ else if (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH)
1112+ codec = APTX_HD_CODEC;
11061113 }
11071114 }
11081115 return codec;
@@ -1156,13 +1163,11 @@ static void btif_a2dp_encoder_init(tBTA_AV_HNDL hdl)
11561163
11571164 UINT8 codectype;
11581165 codectype = bta_av_select_codec(hdl);
1159- if (A2D_NON_A2DP_MEDIA_CT == codectype)
1160- {
1161- UINT8* ptr = bta_av_get_current_codecInfo();
1162- if (ptr)
1163- {
1166+ if (A2D_NON_A2DP_MEDIA_CT == codectype) {
1167+ UINT8* ptr = bta_av_co_get_current_codecInfo();
1168+ if (ptr) {
11641169 //tA2D_APTX_CIE starts on 4th byte
1165- codecInfo = (tA2D_APTX_CIE*) &ptr[3];
1170+ codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
11661171 APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecInfo->codecId);
11671172 APPL_TRACE_DEBUG("%s vendorId = %x", __func__, codecInfo->vendorId);
11681173
@@ -1184,6 +1189,25 @@ static void btif_a2dp_encoder_init(tBTA_AV_HNDL hdl)
11841189 btif_media_task_enc_init_req(&msg);
11851190 return;
11861191 }
1192+
1193+ if (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID
1194+ && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH)
1195+ {
1196+ btif_media_cb.offset = BTIF_MEDIA_AA_APTX_HD_OFFSET;
1197+ tA2D_APTX_HD_CIE aptx_hd_config;
1198+ ALOGI("%s Selected Codec aptX HD", __func__);
1199+ aptx_hd_config.vendorId = codecInfo->vendorId;
1200+ aptx_hd_config.codecId = codecInfo->codecId;
1201+ bta_av_co_audio_get_codec_config((UINT8*)&aptx_hd_config, &minmtu, A2D_NON_A2DP_MEDIA_CT);
1202+ msg.CodecType = A2D_NON_A2DP_MEDIA_CT;
1203+ msg.SamplingFreq = aptx_hd_config.sampleRate;
1204+ msg.MtuSize = minmtu;
1205+ msg.ChannelMode = aptx_hd_config.channelMode;
1206+ msg.BluetoothVendorID = aptx_hd_config.vendorId;
1207+ msg.BluetoothCodecID = aptx_hd_config.codecId;
1208+ btif_media_task_enc_init_req(&msg);
1209+ return;
1210+ }
11871211 }
11881212 }/* if ( A2D_NON_A2DP_MEDIA_CT == codectype) */
11891213
@@ -1236,13 +1260,13 @@ static void btif_a2dp_encoder_update(void)
12361260 APPL_TRACE_DEBUG("btif_a2dp_encoder_update");
12371261
12381262 UINT8 codectype = 0;
1239- codectype = bta_av_get_current_codec();
1263+ codectype = bta_av_co_get_current_codec();
12401264 if (codectype == A2D_NON_A2DP_MEDIA_CT)
12411265 {
1242- UINT8* ptr = bta_av_get_current_codecInfo();
1266+ UINT8* ptr = bta_av_co_get_current_codecInfo();
12431267 if (ptr)
12441268 {
1245- codecInfo = (tA2D_APTX_CIE*) &ptr[3];
1269+ codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
12461270 if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
12471271 {
12481272 APPL_TRACE_DEBUG("%s aptX", __func__);
@@ -1254,6 +1278,18 @@ static void btif_a2dp_encoder_update(void)
12541278 msg.BluetoothVendorID = aptx_config.vendorId;
12551279 msg.BluetoothCodecID = aptx_config.codecId;
12561280 }
1281+
1282+ if (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH)
1283+ {
1284+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
1285+ tA2D_APTX_HD_CIE aptx_hd_config;
1286+ aptx_hd_config.vendorId = codecInfo->vendorId;
1287+ aptx_hd_config.codecId = codecInfo->codecId;
1288+ bta_av_co_audio_get_codec_config((UINT8*)&aptx_hd_config, &minmtu, A2D_NON_A2DP_MEDIA_CT );
1289+ msg.CodecType = A2D_NON_A2DP_MEDIA_CT;
1290+ msg.BluetoothVendorID = aptx_hd_config.vendorId;
1291+ msg.BluetoothCodecID = aptx_hd_config.codecId;
1292+ }
12571293 } /* if (ptr) */
12581294 }
12591295 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
@@ -1445,13 +1481,17 @@ tBTIF_STATUS btif_a2dp_setup_codec(tBTA_AV_HNDL hdl)
14451481 /* for now hardcode 48 khz 16 bit stereo PCM format */
14461482 media_feeding.cfg.pcm.sampling_freq = 48000;
14471483 #else
1448- /* for now hardcode 44.1 khz 16 bit stereo PCM format */
1484+ /* for now hardcode 44.1 khz 32 bit stereo PCM format */
14491485 media_feeding.cfg.pcm.sampling_freq = BTIF_A2DP_SRC_SAMPLING_RATE;
14501486 #endif
14511487 media_feeding.cfg.pcm.bit_per_sample = BTIF_A2DP_SRC_BIT_DEPTH;
14521488 media_feeding.cfg.pcm.num_channel = BTIF_A2DP_SRC_NUM_CHANNELS;
14531489 media_feeding.format = BTIF_AV_CODEC_PCM;
14541490
1491+ /* 32 bits for AUDIO_FORMAT_PCM_8_24_BIT, all codecs affected. */
1492+ APPL_TRACE_EVENT("%s bit_per_sample %d", __func__, media_feeding.cfg.pcm.bit_per_sample);
1493+ APPL_TRACE_EVENT("%s sampling_freq %d", __func__, media_feeding.cfg.pcm.sampling_freq);
1494+
14551495 if (bta_av_co_audio_set_codec(&media_feeding, &status))
14561496 {
14571497 tBTIF_MEDIA_INIT_AUDIO_FEEDING mfeed;
@@ -1559,7 +1599,7 @@ void btif_a2dp_on_open(void)
15591599 *******************************************************************************/
15601600 BOOLEAN btif_media_task_clear_track(void)
15611601 {
1562- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
1602+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
15631603
15641604 p_buf->event = BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK;
15651605 if (btif_media_cmd_msg_queue != NULL)
@@ -2006,7 +2046,7 @@ static void btif_media_thread_cleanup(UNUSED_ATTR void *context) {
20062046 *******************************************************************************/
20072047 BOOLEAN btif_media_task_send_cmd_evt(UINT16 Evt)
20082048 {
2009- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
2049+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
20102050
20112051 p_buf->event = Evt;
20122052
@@ -2339,7 +2379,7 @@ BOOLEAN btif_media_task_audio_feeding_init_req(tBTIF_MEDIA_INIT_AUDIO_FEEDING *p
23392379 *******************************************************************************/
23402380 BOOLEAN btif_media_task_start_aa_req(void)
23412381 {
2342- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
2382+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
23432383
23442384 p_buf->event = BTIF_MEDIA_START_AA_TX;
23452385
@@ -2359,7 +2399,7 @@ BOOLEAN btif_media_task_start_aa_req(void)
23592399 *******************************************************************************/
23602400 BOOLEAN btif_media_task_stop_aa_req(void)
23612401 {
2362- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
2402+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
23632403
23642404 p_buf->event = BTIF_MEDIA_STOP_AA_TX;
23652405
@@ -2392,7 +2432,7 @@ BOOLEAN btif_media_task_aa_rx_flush_req(void)
23922432 if (fixed_queue_is_empty(btif_media_cb.RxSbcQ)) /* Que is already empty */
23932433 return TRUE;
23942434
2395- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
2435+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
23962436 p_buf->event = BTIF_MEDIA_FLUSH_AA_RX;
23972437
23982438 if (btif_media_cmd_msg_queue != NULL)
@@ -2411,7 +2451,7 @@ BOOLEAN btif_media_task_aa_rx_flush_req(void)
24112451 *******************************************************************************/
24122452 BOOLEAN btif_media_task_aa_tx_flush_req(void)
24132453 {
2414- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
2454+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
24152455
24162456 p_buf->event = BTIF_MEDIA_FLUSH_AA_TX;
24172457
@@ -2497,8 +2537,7 @@ static void btif_media_task_enc_init(BT_HDR *p_msg)
24972537 APPL_TRACE_EVENT("%s BluetoothVendorID %x, BluetoothCodecID %d", __func__,
24982538 pInitAudio->BluetoothVendorID, pInitAudio->BluetoothCodecID);
24992539 if ((pInitAudio->BluetoothVendorID == A2D_APTX_VENDOR_ID)
2500- && (pInitAudio->BluetoothCodecID == A2D_APTX_CODEC_ID_BLUETOOTH)) /* aptX Classic */
2501- {
2540+ && (pInitAudio->BluetoothCodecID == A2D_APTX_CODEC_ID_BLUETOOTH)) {
25022541 btif_media_cb.aptxEncoderParams.s16SamplingFreq= pInitAudio->SamplingFreq;
25032542 btif_media_cb.aptxEncoderParams.s16ChannelMode = pInitAudio->ChannelMode;
25042543 btif_media_cb.aptxEncoderParams.u16PacketLength = 4; // 32-bit word encoded by aptX encoder
@@ -2507,6 +2546,16 @@ static void btif_media_task_enc_init(BT_HDR *p_msg)
25072546 < pInitAudio->MtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_OFFSET
25082547 - sizeof(BT_HDR)) : pInitAudio->MtuSize;
25092548 return;
2549+ } else if ((pInitAudio->BluetoothVendorID == A2D_APTX_HD_VENDOR_ID)
2550+ && (pInitAudio->BluetoothCodecID == A2D_APTX_HD_CODEC_ID_BLUETOOTH)) {
2551+ btif_media_cb.aptxhdEncoderParams.s16SamplingFreq= pInitAudio->SamplingFreq;
2552+ btif_media_cb.aptxhdEncoderParams.s16ChannelMode = pInitAudio->ChannelMode;
2553+ btif_media_cb.aptxhdEncoderParams.u16PacketLength = 6; // 48-bit word encoded by aptX encoder
2554+ btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_APTX_HD;
2555+ btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_HD_OFFSET-sizeof(BT_HDR))
2556+ < pInitAudio->MtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_HD_OFFSET
2557+ - sizeof(BT_HDR)) : pInitAudio->MtuSize;
2558+ return;
25102559 } else {
25112560 /* do nothing, fall through to SBC */
25122561 }
@@ -2586,13 +2635,18 @@ static void btif_media_task_enc_update(BT_HDR *p_msg)
25862635 pUpdateAudio->BluetoothVendorID, pUpdateAudio->BluetoothCodecID);
25872636
25882637 if ((pUpdateAudio->BluetoothVendorID == A2D_APTX_VENDOR_ID)
2589- && (pUpdateAudio->BluetoothCodecID == A2D_APTX_CODEC_ID_BLUETOOTH)) /* aptX Classic */
2590- {
2638+ && (pUpdateAudio->BluetoothCodecID == A2D_APTX_CODEC_ID_BLUETOOTH)) {
25912639 APPL_TRACE_DEBUG("%s aptX ", __func__);
25922640 btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_OFFSET - sizeof(BT_HDR)) < pUpdateAudio->MinMtuSize) ?
25932641 (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_OFFSET - sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize;
25942642 APPL_TRACE_DEBUG("%s : aptX btif_media_cb.TxAaMtuSize %d", __func__, btif_media_cb.TxAaMtuSize);
25952643 return;
2644+ } else if ((pUpdateAudio->BluetoothVendorID == A2D_APTX_HD_VENDOR_ID)
2645+ && (pUpdateAudio->BluetoothCodecID == A2D_APTX_HD_CODEC_ID_BLUETOOTH)) {
2646+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
2647+ btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_HD_OFFSET - sizeof(BT_HDR)) < pUpdateAudio->MinMtuSize) ?
2648+ (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_HD_OFFSET - sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize;
2649+ return;
25962650 } else {
25972651 /* do nothing, fall through to SBC */
25982652 }
@@ -2832,6 +2886,80 @@ static void btif_media_task_pcm2sbc_init(tBTIF_MEDIA_INIT_AUDIO_FEEDING * p_feed
28322886
28332887 /*******************************************************************************
28342888 **
2889+ ** Function btif_media_task_pcm2aptx_hd_init
2890+ **
2891+ ** Description Init encoding task for PCM to aptX according to feeding
2892+ **
2893+ ** Returns void
2894+ **
2895+ *******************************************************************************/
2896+static void btif_media_task_pcm2aptx_hd_init(tBTIF_MEDIA_INIT_AUDIO_FEEDING * p_feeding)
2897+{
2898+ BOOLEAN reconfig_needed = FALSE;
2899+
2900+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
2901+ APPL_TRACE_DEBUG("%s PCM feeding:", __func__);
2902+ APPL_TRACE_DEBUG("%s sampling_freq:%d", __func__, p_feeding->feeding.cfg.pcm.sampling_freq);
2903+ APPL_TRACE_DEBUG("%s num_channel:%d", __func__, p_feeding->feeding.cfg.pcm.num_channel);
2904+ APPL_TRACE_DEBUG("%s bit_per_sample:%d", __func__, p_feeding->feeding.cfg.pcm.bit_per_sample);
2905+
2906+ /* Check the PCM feeding sampling_freq */
2907+ switch (p_feeding->feeding.cfg.pcm.sampling_freq)
2908+ {
2909+ case 8000:
2910+ case 12000:
2911+ case 16000:
2912+ case 24000:
2913+ case 32000:
2914+ case 48000:
2915+ /* For these sampling_freq the AV connection must be 48000 */
2916+ if (btif_media_cb.aptxhdEncoderParams.s16SamplingFreq != A2D_APTX_HD_SAMPLERATE_48000)
2917+ {
2918+ /* Reconfiguration needed at 48000 */
2919+ APPL_TRACE_DEBUG("%s Reconfiguration needed at 48000", __func__);
2920+ btif_media_cb.aptxhdEncoderParams.s16SamplingFreq = A2D_APTX_HD_SAMPLERATE_48000;
2921+ reconfig_needed = TRUE;
2922+ }
2923+ break;
2924+
2925+ case 11025:
2926+ case 22050:
2927+ case 44100:
2928+ /* For these sampling_freq the AV connection must be 44100 */
2929+ if (btif_media_cb.aptxhdEncoderParams.s16SamplingFreq != A2D_APTX_HD_SAMPLERATE_44100)
2930+ {
2931+ /* Reconfiguration needed at 44100 */
2932+ APPL_TRACE_DEBUG("%s Reconfiguration needed at 44100", __func__);
2933+ btif_media_cb.aptxhdEncoderParams.s16SamplingFreq = A2D_APTX_HD_SAMPLERATE_44100;
2934+ reconfig_needed = TRUE;
2935+ }
2936+ break;
2937+ default:
2938+ APPL_TRACE_DEBUG("%s Feeding PCM sampling_freq unsupported", __func__);
2939+ break;
2940+ }
2941+
2942+ /* Some AV Headsets do not support Mono => always ask for Stereo */
2943+ if (btif_media_cb.aptxhdEncoderParams.s16ChannelMode == A2D_APTX_HD_CHANNELS_MONO)
2944+ {
2945+ APPL_TRACE_DEBUG("%s Reconfiguration needed in Stereo", __func__);
2946+ btif_media_cb.aptxhdEncoderParams.s16ChannelMode = A2D_APTX_HD_CHANNELS_STEREO;
2947+ reconfig_needed = TRUE;
2948+ }
2949+
2950+ if (reconfig_needed != FALSE)
2951+ {
2952+ APPL_TRACE_DEBUG("%s calls APTX_HD_Encoder_Init", __func__);
2953+ APPL_TRACE_DEBUG("%s mtu %d", __func__, btif_media_cb.TxAaMtuSize);
2954+ APPL_TRACE_DEBUG("%s ch mode %d, Smp freq %d", __func__,
2955+ btif_media_cb.aptxhdEncoderParams.s16ChannelMode, btif_media_cb.aptxhdEncoderParams.s16SamplingFreq);
2956+ } else {
2957+ APPL_TRACE_DEBUG("%s No aptX HD reconfig needed", __func__);
2958+ }
2959+}
2960+
2961+/*******************************************************************************
2962+ **
28352963 ** Function btif_media_task_pcm2aptx_init
28362964 **
28372965 ** Description Init encoding task for PCM to aptX according to feeding
@@ -2928,30 +3056,31 @@ static void btif_media_task_audio_feeding_init(BT_HDR *p_msg)
29283056 case BTIF_AV_CODEC_PCM:
29293057 {
29303058 UINT8 codectype;
2931- codectype = bta_av_get_current_codec();
3059+ codectype = bta_av_co_get_current_codec();
3060+
3061+ if (A2D_NON_A2DP_MEDIA_CT == codectype) {
3062+ UINT8* ptr = bta_av_co_get_current_codecInfo();
3063+ if (ptr) {
3064+ // tA2D_APTX_CIE starts on 4th byte
3065+ codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
3066+ if (codecInfo) {
3067+ APPL_TRACE_DEBUG("%s codecId = %d ", __func__, codecInfo->codecId);
3068+ APPL_TRACE_DEBUG("%s vendorId = %x ", __func__, codecInfo->vendorId);
3069+ }
29323070
2933- if (A2D_NON_A2DP_MEDIA_CT == codectype)
2934- {
2935- UINT8* ptr = bta_av_get_current_codecInfo();
2936- if (ptr)
2937- {
2938- // tA2D_APTX_CIE starts on 4th byte
2939- codecInfo = (tA2D_APTX_CIE*) &ptr[3];
2940- if (codecInfo)
2941- {
2942- APPL_TRACE_DEBUG("%s codecId = %d ", __func__, codecInfo->codecId);
2943- APPL_TRACE_DEBUG("%s vendorId = %x ", __func__, codecInfo->vendorId);
2944- }
2945-
2946- if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH) /* aptX Classic */
2947- {
2948- APPL_TRACE_DEBUG("%s aptX", __func__);
2949- btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_APTX;
2950- btif_media_task_pcm2aptx_init(p_feeding);
2951- break;
2952- } else {
2953- /* do nothing, fall through to SBC */
2954- }
3071+ if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH) {
3072+ APPL_TRACE_DEBUG("%s aptX", __func__);
3073+ btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_APTX;
3074+ btif_media_task_pcm2aptx_init(p_feeding);
3075+ break;
3076+ } else if (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH) {
3077+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
3078+ btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_APTX_HD;
3079+ btif_media_task_pcm2aptx_hd_init(p_feeding);
3080+ break;
3081+ } else {
3082+ /* do nothing, fall through to SBC */
3083+ }
29553084 }
29563085 }
29573086
@@ -3249,6 +3378,12 @@ int btif_media_task_cb_packet_send(uint8_t* packet, int length, int pcm_bytes_en
32493378 {
32503379 int bytes_per_frame = 2;
32513380 uint64_t timestamp_us = 0;
3381+ UINT8 codectype;
3382+ codectype = bta_av_co_get_current_codec();
3383+
3384+ if (btif_media_task_get_aptX_codec_type() == APTX_HD_CODEC) {
3385+ bytes_per_frame = 3;
3386+ }
32523387
32533388 if (length > 0 ) {
32543389
@@ -3267,7 +3402,7 @@ int btif_media_task_cb_packet_send(uint8_t* packet, int length, int pcm_bytes_en
32673402 osi_free(fixed_queue_try_dequeue(btif_media_cb.TxAaQ));
32683403 }
32693404
3270- BT_HDR *p_buf = osi_malloc(BTIF_MEDIA_AA_BUF_SIZE);
3405+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(BTIF_MEDIA_AA_BUF_SIZE);
32713406
32723407 int rtpTimestamp = (pcm_bytes_encoded / btif_media_cb.media_feeding.cfg.pcm.num_channel / bytes_per_frame);
32733408
@@ -3340,7 +3475,7 @@ static void btif_media_task_aa_start_tx(void)
33403475 BOOLEAN use_SCMS_T = false;
33413476 #endif
33423477 A2D_AptXCodecType aptX_codec_type = btif_media_task_get_aptX_codec_type();
3343- BOOLEAN is_24bit_audio = false;
3478+ BOOLEAN is_24bit_audio = true;
33443479
33453480 BOOLEAN test = false;
33463481 BOOLEAN trace = false;
@@ -3743,7 +3878,7 @@ UINT8 btif_media_sink_enque_buf(BT_HDR *p_pkt)
37433878 BT_HDR *btif_media_aa_readbuf(void)
37443879 {
37453880 uint64_t now_us = time_now_us();
3746- BT_HDR *p_buf = fixed_queue_try_dequeue(btif_media_cb.TxAaQ);
3881+ BT_HDR *p_buf = (BT_HDR *)fixed_queue_try_dequeue(btif_media_cb.TxAaQ);
37473882
37483883 btif_media_cb.stats.tx_queue_total_readbuf_calls++;
37493884 btif_media_cb.stats.tx_queue_last_readbuf_us = now_us;
@@ -3777,9 +3912,9 @@ BOOLEAN btif_media_aa_read_feeding(tUIPC_CH_ID channel_id)
37773912 UINT16 bytes_needed = blocm_x_subband * btif_media_cb.encoder.s16NumOfChannels * \
37783913 btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
37793914 static UINT16 up_sampled_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
3780- * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2];
3915+ * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 4];
37813916 static UINT16 read_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
3782- * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
3917+ * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2];
37833918 UINT32 src_size_used;
37843919 UINT32 dst_size_used;
37853920 BOOLEAN fract_needed;
@@ -3810,7 +3945,7 @@ BOOLEAN btif_media_aa_read_feeding(tUIPC_CH_ID channel_id)
38103945 if (sbc_sampling == btif_media_cb.media_feeding.cfg.pcm.sampling_freq) {
38113946 read_size = bytes_needed - btif_media_cb.media_feeding_state.pcm.aa_feed_residue;
38123947 nb_byte_read = UIPC_Read(channel_id, &event,
3813- ((UINT8 *)btif_media_cb.encoder.as16PcmBuffer) +
3948+ ((UINT8 *)btif_media_cb.encoder.as32PcmBuffer) +
38143949 btif_media_cb.media_feeding_state.pcm.aa_feed_residue,
38153950 read_size);
38163951 if (nb_byte_read == read_size) {
@@ -3929,7 +4064,7 @@ BOOLEAN btif_media_aa_read_feeding(tUIPC_CH_ID channel_id)
39294064 if(btif_media_cb.media_feeding_state.pcm.aa_feed_residue >= bytes_needed)
39304065 {
39314066 /* Copy the output pcm samples in SBC encoding buffer */
3932- memcpy((UINT8 *)btif_media_cb.encoder.as16PcmBuffer,
4067+ memcpy((UINT8 *)btif_media_cb.encoder.as32PcmBuffer,
39334068 (UINT8 *)up_sampled_buffer,
39344069 bytes_needed);
39354070 /* update the residue */
@@ -3964,7 +4099,7 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame,
39644099 btif_media_cb.encoder.s16NumOfBlocks;
39654100
39664101 while (nb_frame) {
3967- BT_HDR *p_buf = osi_malloc(BTIF_MEDIA_AA_BUF_SIZE);
4102+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(BTIF_MEDIA_AA_BUF_SIZE);
39684103
39694104 /* Init buffer */
39704105 p_buf->offset = BTIF_MEDIA_AA_SBC_OFFSET;
@@ -3976,12 +4111,14 @@ static void btif_media_aa_prep_sbc_2_send(UINT8 nb_frame,
39764111 /* Write @ of allocated buffer in encoder.pu8Packet */
39774112 btif_media_cb.encoder.pu8Packet = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len;
39784113 /* Fill allocated buffer with 0 */
3979- memset(btif_media_cb.encoder.as16PcmBuffer, 0, blocm_x_subband
3980- * btif_media_cb.encoder.s16NumOfChannels);
4114+ memset(btif_media_cb.encoder.as32PcmBuffer, 0, blocm_x_subband
4115+ * btif_media_cb.encoder.s16NumOfChannels * 2);
39814116
39824117 /* Read PCM data and upsample them if needed */
39834118 if (btif_media_aa_read_feeding(UIPC_CH_ID_AV_AUDIO))
39844119 {
4120+ size_t frames = blocm_x_subband * btif_media_cb.encoder.s16NumOfChannels;
4121+ memcpy_by_audio_format(btif_media_cb.encoder.as16PcmBuffer, AUDIO_FORMAT_PCM_16_BIT, btif_media_cb.encoder.as32PcmBuffer, AUDIO_FORMAT_PCM_8_24_BIT, frames);
39854122 SBC_Encoder(&(btif_media_cb.encoder));
39864123
39874124 /* Update SBC frame length */
@@ -4199,7 +4336,7 @@ void disconnect_a2dp_on_vendor_start_failure()
41994336
42004337 void btif_media_send_reset_vendor_state()
42014338 {
4202- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
4339+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
42034340
42044341 p_buf->event = BTIF_MEDIA_RESET_VS_STATE;
42054342 if (btif_media_cmd_msg_queue != NULL)
@@ -4227,7 +4364,7 @@ void btif_media_start_vendor_command()
42274364
42284365 void btif_media_on_start_vendor_command()
42294366 {
4230- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
4367+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
42314368
42324369 p_buf->event = BTIF_MEDIA_START_VS_CMD;
42334370 if (btif_media_cmd_msg_queue != NULL)
@@ -4236,7 +4373,7 @@ void btif_media_on_start_vendor_command()
42364373
42374374 void btif_media_on_stop_vendor_command()
42384375 {
4239- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
4376+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
42404377
42414378 APPL_TRACE_IMP("btif_media_on_stop_vendor_command");
42424379 p_buf->event = BTIF_MEDIA_STOP_VS_CMD;
@@ -4255,7 +4392,7 @@ void btif_media_a2dp_start_cb(tBTM_VSC_CMPL *param)
42554392 }
42564393 APPL_TRACE_IMP("VS_QHCI_START_A2DP_MEDIA sent with error code: %u", status);
42574394
4258- p_buf = osi_malloc(sizeof(BT_HDR));
4395+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
42594396
42604397 if (!status)
42614398 p_buf->event = BTIF_MEDIA_VS_A2DP_START_SUCCESS;
@@ -4300,7 +4437,7 @@ void btif_media_a2dp_stop_cb(tBTM_VSC_CMPL *param)
43004437 }
43014438 APPL_TRACE_IMP("VS_QHCI_STOP_A2DP_MEDIA sent with error code: %u", status);
43024439
4303- p_buf = osi_malloc(sizeof(BT_HDR));
4440+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
43044441
43054442 if (!status)
43064443 p_buf->event = BTIF_MEDIA_VS_A2DP_STOP_SUCCESS;
@@ -4348,7 +4485,7 @@ void btif_media_selected_codec_cb(tBTM_VSC_CMPL *param)
43484485
43494486 if (!status)
43504487 {
4351- p_buf = osi_malloc(sizeof(BT_HDR));
4488+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
43524489 p_buf->event = BTIF_MEDIA_VS_A2DP_SELECTED_CODEC_SUCCESS;
43534490 if (btif_media_cmd_msg_queue != NULL)
43544491 fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
@@ -4365,11 +4502,11 @@ void btif_media_selected_codec_cb(tBTM_VSC_CMPL *param)
43654502
43664503 BOOLEAN btif_media_send_vendor_selected_codec()
43674504 {
4368- UINT8 param[12], codec_type = A2DP_CODEC_SBC;//bta_av_get_current_code();
4505+ UINT8 param[12], codec_type = A2DP_CODEC_SBC;
43694506 UINT16 index = 0;
43704507
4371- codec_type = bta_av_get_current_codec();
4372- if (codec_type == 0xFF)
4508+ codec_type = bta_av_co_get_current_codec();
4509+ if (codec_type == A2D_NON_A2DP_MEDIA_CT)
43734510 codec_type = A2DP_CODEC_APTX;
43744511
43754512 APPL_TRACE_IMP("btif_media_send_selected_codec: codec: %d", codec_type);
@@ -4408,7 +4545,7 @@ void btif_media_transport_cfg_cb(tBTM_VSC_CMPL *param)
44084545
44094546 if (!status)
44104547 {
4411- p_buf = osi_malloc(sizeof(BT_HDR));
4548+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
44124549 p_buf->event = BTIF_MEDIA_VS_A2DP_TRANSPORT_CFG_SUCCESS;
44134550 if (btif_media_cmd_msg_queue != NULL)
44144551 fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
@@ -4425,11 +4562,11 @@ void btif_media_transport_cfg_cb(tBTM_VSC_CMPL *param)
44254562 BOOLEAN btif_media_send_vendor_transport_cfg()
44264563 {
44274564 UINT8 param[3];
4428- UINT8 codec_type = bta_av_get_current_codec();
4565+ UINT8 codec_type = bta_av_co_get_current_codec();
44294566 UINT8 stream_type;
44304567 APPL_TRACE_IMP("btif_media_send_vendor_transport_cfg: codec: %d", codec_type);
44314568 stream_type = codec_type;
4432- if (codec_type == 0xFF)
4569+ if (codec_type == A2D_NON_A2DP_MEDIA_CT)
44334570 stream_type = A2DP_TRANSPORT_STREAM_TYPE_APTX;
44344571 param[0] = VS_QHCI_A2DP_TRANSPORT_CONFIGURATION;
44354572 param[1] = A2DP_TRANSPORT_TYPE_SLIMBUS;
@@ -4453,7 +4590,7 @@ void btif_media_a2dp_media_chn_cfg_cb(tBTM_VSC_CMPL *param)
44534590
44544591 if (!status)
44554592 {
4456- p_buf = osi_malloc(sizeof(BT_HDR));
4593+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
44574594 p_buf->event = BTIF_MEDIA_VS_A2DP_MEDIA_CHNL_CFG_SUCCESS;
44584595 if (btif_media_cmd_msg_queue != NULL)
44594596 fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
@@ -4506,7 +4643,7 @@ void btif_media_a2dp_write_sbc_cfg_cb(tBTM_VSC_CMPL *param)
45064643
45074644 if (!status)
45084645 {
4509- p_buf = osi_malloc(sizeof(BT_HDR));
4646+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
45104647 p_buf->event = BTIF_MEDIA_VS_A2DP_WRITE_SBC_CFG_SUCCESS;
45114648 if (btif_media_cmd_msg_queue != NULL)
45124649 fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
@@ -4576,7 +4713,7 @@ void btif_media_pref_bit_rate_cb(tBTM_VSC_CMPL *param)
45764713
45774714 if (!status)
45784715 {
4579- p_buf = osi_malloc(sizeof(BT_HDR));
4716+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
45804717 p_buf->event = BTIF_MEDIA_VS_A2DP_PREF_BIT_RATE_SUCCESS;
45814718 if (btif_media_cmd_msg_queue != NULL)
45824719 fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
@@ -4618,7 +4755,7 @@ void btif_media_scmst_cb(tBTM_VSC_CMPL *param)
46184755
46194756 if (!status)
46204757 {
4621- p_buf = osi_malloc(sizeof(BT_HDR));
4758+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
46224759 p_buf->event = BTIF_MEDIA_VS_A2DP_SET_SCMST_HDR_SUCCESS;
46234760 if (btif_media_cmd_msg_queue != NULL)
46244761 fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
--- a/btif/src/btif_rc.c
+++ b/btif/src/btif_rc.c
@@ -401,7 +401,6 @@ extern BOOLEAN btif_av_is_playing();
401401 extern BOOLEAN btif_av_is_device_connected(BD_ADDR address);
402402 extern void btif_av_trigger_dual_handoff(BOOLEAN handoff, BD_ADDR address);
403403 extern BOOLEAN btif_hf_is_call_idle();
404-extern BOOLEAN btif_av_get_multicast_state();
405404 extern BOOLEAN btif_av_is_current_device(BD_ADDR address);
406405 extern UINT16 btif_av_get_num_connected_devices(void);
407406 extern UINT16 btif_av_get_num_playing_devices(void);
--- a/embdrv/sbc/encoder/include/sbc_encoder.h
+++ b/embdrv/sbc/encoder/include/sbc_encoder.h
@@ -175,6 +175,7 @@ typedef struct SBC_ENC_PARAMS_TAG
175175 SINT16 *ps16PcmBuffer;
176176 #else
177177 SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
178+ SINT32 as32PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
178179 #endif
179180
180181 SINT16 s16ScartchMemForBitAlloc[16];
--- a/include/bt_target.h
+++ b/include/bt_target.h
@@ -1,4 +1,4 @@
1-/******************************************************************************
1+ /******************************************************************************
22 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
33 *
44 * Not a contribution.
@@ -138,7 +138,7 @@
138138 #endif
139139
140140 #ifndef BTIF_A2DP_SRC_BIT_DEPTH
141-#define BTIF_A2DP_SRC_BIT_DEPTH 16
141+#define BTIF_A2DP_SRC_BIT_DEPTH 32
142142 #endif
143143
144144 #ifndef BTIF_A2DP_SRC_NUM_CHANNELS
@@ -1210,9 +1210,9 @@
12101210 */
12111211 #ifndef AVDT_NUM_SEPS
12121212 #if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
1213-#define AVDT_NUM_SEPS 7
1213+#define AVDT_NUM_SEPS 9
12141214 #else
1215-#define AVDT_NUM_SEPS 5
1215+#define AVDT_NUM_SEPS 7
12161216 #endif
12171217 #endif
12181218
--- a/main/Android.mk
+++ b/main/Android.mk
@@ -53,7 +53,8 @@ LOCAL_C_INCLUDES+= . \
5353 $(LOCAL_PATH)/../utils/include \
5454 $(bluetooth_C_INCLUDES) \
5555 external/tinyxml2 \
56- external/zlib
56+ external/zlib \
57+ $(call include-path-for, audio-utils)
5758
5859 LOCAL_SHARED_LIBRARIES := \
5960 libcutils \
@@ -64,7 +65,8 @@ LOCAL_SHARED_LIBRARIES := \
6465 libprotobuf-cpp-full \
6566 libmedia \
6667 libutils \
67- libchrome
68+ libchrome \
69+ libaudioutils
6870
6971 LOCAL_STATIC_LIBRARIES := \
7072 libtinyxml2 \
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -607,6 +607,7 @@ static void alarm_queue_ready(fixed_queue_t *queue,
607607 alarm->deadline = 0;
608608 alarm->callback = NULL;
609609 alarm->data = NULL;
610+ alarm->queue = NULL;
610611 }
611612
612613 pthread_mutex_lock(&alarm->callback_lock);
--- a/stack/Android.mk
+++ b/stack/Android.mk
@@ -39,6 +39,7 @@ LOCAL_SRC_FILES:= \
3939 ./a2dp/a2d_api.c \
4040 ./a2dp/a2d_sbc.c \
4141 ./a2dp/a2d_aptx.c \
42+ ./a2dp/a2d_aptx_hd.c \
4243 ./a2dp/a2d_aac.c \
4344 ./avrc/avrc_api.c \
4445 ./avrc/avrc_sdp.c \
--- a/stack/a2dp/a2d_aptx.c
+++ b/stack/a2dp/a2d_aptx.c
@@ -44,6 +44,7 @@
4444 #include "a2d_api.h"
4545 #include "a2d_int.h"
4646 #include "a2d_aptx.h"
47+#include "a2d_aptx_hd.h"
4748 #include <utils/Log.h>
4849
4950 const char* A2D_APTX_SCHED_LIB_NAME = "libaptXScheduler.so";
@@ -277,19 +278,45 @@ void A2D_deinit_aptX(void)
277278
278279 if (isA2dAptXEnabled && A2dAptXSchedLibHandle)
279280 {
280- // remove aptX thread
281- if (A2d_aptx_thread)
282- {
283- A2D_aptx_sched_stop();
284- thread_free(A2d_aptx_thread);
285- A2d_aptx_thread = NULL;
286- }
287-
288- A2D_aptx_encoder_deinit();
289- dlclose(A2dAptXSchedLibHandle);
290- A2dAptXSchedLibHandle = NULL;
291- isA2dAptXEnabled = false;
281+ A2D_aptx_encoder_deinit();
282+ isA2dAptXEnabled = false;
283+ }
284+
285+ return;
286+}
287+
288+/*******************************************************************************
289+**
290+** Function A2D_close_aptX
291+**
292+** Description This function close aptX
293+**
294+** Returns Nothing
295+**
296+*******************************************************************************/
297+void A2D_close_aptX(void)
298+{
299+ A2D_TRACE_DEBUG("%s", __func__);
300+
301+ if (A2dAptXSchedLibHandle)
302+ {
303+ // remove aptX thread
304+ if (A2d_aptx_thread)
305+ {
306+ A2D_aptx_sched_stop();
307+ thread_free(A2d_aptx_thread);
308+ A2d_aptx_thread = NULL;
309+ }
292310 }
293311
312+ // de-initialize aptX HD
313+ A2D_deinit_aptX_HD();
314+
315+ // de-initialize aptX
316+ A2D_deinit_aptX();
317+
318+ dlclose(A2dAptXSchedLibHandle);
319+ A2dAptXSchedLibHandle = NULL;
320+
294321 return;
295322 }
--- /dev/null
+++ b/stack/a2dp/a2d_aptx_hd.c
@@ -0,0 +1,251 @@
1+/******************************************************************************
2+
3+ Copyright (c) 2016, The Linux Foundation. All rights reserved.
4+
5+ Redistribution and use in source and binary forms, with or without
6+ modification, are permitted provided that the following conditions are
7+ met:
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+ * Redistributions in binary form must reproduce the above
11+ copyright notice, this list of conditions and the following
12+ disclaimer in the documentation and/or other materials provided
13+ with the distribution.
14+ * Neither the name of The Linux Foundation nor the names of its
15+ contributors may be used to endorse or promote products derived
16+ from this software without specific prior written permission.
17+
18+ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
19+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
21+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+ ******************************************************************************/
31+/******************************************************************************
32+
33+ Utility functions to help build and parse the aptX HD Codec Information
34+ Element and Media Payload.
35+
36+******************************************************************************/
37+
38+#include "bt_target.h"
39+
40+#include <string.h>
41+#include <dlfcn.h>
42+#include "osi/include/thread.h"
43+#include "bt_utils.h"
44+#include "a2d_api.h"
45+#include "a2d_int.h"
46+#include "a2d_aptx.h"
47+#include "a2d_aptx_hd.h"
48+#include <utils/Log.h>
49+
50+
51+BOOLEAN isA2dAptXHdEnabled = FALSE;
52+
53+int (*A2D_aptx_hd_encoder_init)(void);
54+void (*A2D_aptx_hd_encoder_deinit)(void);
55+
56+/******************************************************************************
57+**
58+** Function A2D_BldAptx_hdInfo
59+**
60+******************************************************************************/
61+UINT8 A2D_BldAptx_hdInfo(UINT8 media_type, tA2D_APTX_HD_CIE *p_ie, UINT8 *p_result)
62+{
63+ A2D_TRACE_API("%s: - MediaType:%d", __func__, media_type);
64+
65+ UINT8 status = 0;
66+ status = A2D_SUCCESS;
67+ *p_result++ = A2D_APTX_HD_CODEC_LEN;
68+ *p_result++ = media_type;
69+ *p_result++ = A2D_NON_A2DP_MEDIA_CT;
70+ *p_result++ = (UINT8)(p_ie->vendorId & 0x000000FF);
71+ *p_result++ = (UINT8)(p_ie->vendorId & 0x0000FF00)>> 8;
72+ *p_result++ = (UINT8)(p_ie->vendorId & 0x00FF0000)>> 16;
73+ *p_result++ = (UINT8)(p_ie->vendorId & 0xFF000000)>> 24;
74+ *p_result++ = (UINT8)(p_ie->codecId & 0x00FF);
75+ *p_result++ = (UINT8)(p_ie->codecId & 0xFF00) >> 8;
76+ *p_result++ = p_ie->sampleRate | p_ie->channelMode;
77+ *p_result++ = p_ie->acl_sprint_reserved0;
78+ *p_result++ = p_ie->acl_sprint_reserved1;
79+ *p_result++ = p_ie->acl_sprint_reserved2;
80+ *p_result++ = p_ie->acl_sprint_reserved3;
81+ return status;
82+}
83+
84+/******************************************************************************
85+**
86+** Function A2D_ParsAptx_hdInfo
87+**
88+******************************************************************************/
89+tA2D_STATUS A2D_ParsAptx_hdInfo(tA2D_APTX_HD_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps)
90+{
91+ tA2D_STATUS status;
92+ UINT8 losc;
93+ UINT8 mt;
94+
95+ A2D_TRACE_API("%s: - MediaType:%d", __func__, for_caps);
96+
97+ if (p_ie == NULL || p_info == NULL)
98+ {
99+ A2D_TRACE_ERROR("A2D_ParsAptx_hdInfo - Invalid Params");
100+ status = A2D_INVALID_PARAMS;
101+ }
102+ else
103+ {
104+ losc = *p_info++;
105+ mt = *p_info++;
106+ A2D_TRACE_DEBUG("%s: losc %d, mt %02x", __func__, losc, mt);
107+
108+ /* If the function is called for the wrong Media Type or Media Codec Type */
109+ if (losc != A2D_APTX_HD_CODEC_LEN || *p_info != A2D_NON_A2DP_MEDIA_CT) {
110+ A2D_TRACE_ERROR("%s: wrong media type %02x", __func__, *p_info);
111+ status = A2D_WRONG_CODEC;
112+ }
113+ else
114+ {
115+ p_info++;
116+ p_ie->vendorId = (*p_info & 0x000000FF) |
117+ (*(p_info+1) << 8 & 0x0000FF00) |
118+ (*(p_info+2) << 16 & 0x00FF0000) |
119+ (*(p_info+3) << 24 & 0xFF000000);
120+ p_info = p_info+4;
121+ p_ie->codecId = (*p_info & 0x00FF) | (*(p_info+1) << 8 & 0xFF00);
122+ p_info = p_info+2;
123+ p_ie->channelMode= *p_info & 0x0F;
124+ p_ie->sampleRate = *p_info & 0xF0;
125+ p_info = p_info+1;
126+ p_ie->acl_sprint_reserved0 = *(p_info ++);
127+ p_ie->acl_sprint_reserved1 = *(p_info ++);
128+ p_ie->acl_sprint_reserved2 = *(p_info ++);
129+ p_ie->acl_sprint_reserved3 = *(p_info ++);
130+
131+ status = A2D_SUCCESS;
132+
133+ if (for_caps == FALSE)
134+ {
135+ if (A2D_BitsSet(p_ie->sampleRate) != A2D_SET_ONE_BIT)
136+ status = A2D_BAD_SAMP_FREQ;
137+ if (A2D_BitsSet(p_ie->channelMode) != A2D_SET_ONE_BIT)
138+ status = A2D_BAD_CH_MODE;
139+ }
140+ }
141+ }
142+ return status;
143+}
144+
145+/*******************************************************************************
146+**
147+** Function a2d_av_aptx_hd_cfg_in_cap
148+**
149+** Description This function checks whether an aptX HD codec configuration
150+** is allowable for the given codec capabilities.
151+**
152+** Returns 0 if ok, nonzero if error.
153+**
154+*******************************************************************************/
155+UINT8 a2d_av_aptx_hd_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_HD_CIE *p_cap)
156+{
157+ UINT8 status = 0;
158+ tA2D_APTX_HD_CIE cfg_cie;
159+
160+ A2D_TRACE_API("%s", __func__);
161+
162+ /* parse configuration */
163+ if ((status = A2D_ParsAptx_hdInfo(&cfg_cie, p_cfg, FALSE)) != 0)
164+ {
165+ A2D_TRACE_ERROR("%s: aptX HD parse failed", __func__);
166+ return status;
167+ }
168+
169+ /* verify that each parameter is in range */
170+
171+ /* sampling frequency */
172+ if ((cfg_cie.sampleRate & p_cap->sampleRate) == 0)
173+ status = A2D_NS_SAMP_FREQ;
174+ /* channel mode */
175+ else if ((cfg_cie.channelMode & p_cap->channelMode) == 0)
176+ status = A2D_NS_CH_MODE;
177+
178+ return status;
179+}
180+
181+/*******************************************************************************
182+**
183+** Function A2D_check_and_init_aptX_HD
184+**
185+** Description This function checks if all the libraries required for
186+** aptX HD are present and needed function pointers are resolved
187+**
188+** Returns returns true if aptX HD codec initialization succeeds
189+**
190+*******************************************************************************/
191+BOOLEAN A2D_check_and_init_aptX_HD(void)
192+{
193+ A2D_TRACE_DEBUG("%s", __func__);
194+
195+ if (isA2dAptXEnabled && A2dAptXSchedLibHandle)
196+ {
197+ A2D_aptx_hd_encoder_init = (int (*)(void))dlsym(A2dAptXSchedLibHandle,
198+ "aptx_hd_encoder_init");
199+ if (!A2D_aptx_hd_encoder_init)
200+ {
201+ A2D_TRACE_ERROR("%s: aptX HD encoder init missing", __func__);
202+ goto error_exit;
203+ }
204+
205+ A2D_aptx_hd_encoder_deinit = (void (*)(void))dlsym(A2dAptXSchedLibHandle,
206+ "aptx_hd_encoder_deinit");
207+ if (!A2D_aptx_hd_encoder_deinit)
208+ {
209+ A2D_TRACE_ERROR("%s: aptX HD encoder deinit missing", __func__);
210+ goto error_exit;
211+ }
212+
213+ if (A2D_aptx_hd_encoder_init())
214+ {
215+ A2D_TRACE_ERROR("%s: aptX HD encoder init failed - %s", __func__, dlerror());
216+ goto error_exit;
217+ }
218+ } else {
219+ A2D_TRACE_ERROR("%s: isA2dAptXEnabled = false", __func__);
220+ goto error_exit;
221+ }
222+ isA2dAptXHdEnabled = true;
223+ return isA2dAptXHdEnabled;
224+
225+ error_exit:;
226+ isA2dAptXHdEnabled = false;
227+ return isA2dAptXHdEnabled;
228+
229+}
230+
231+/*******************************************************************************
232+**
233+** Function A2D_deinit_aptX_HD
234+**
235+** Description This function de-initialized aptX HD
236+**
237+** Returns Nothing
238+**
239+*******************************************************************************/
240+void A2D_deinit_aptX_HD(void)
241+{
242+ A2D_TRACE_DEBUG("%s", __func__);
243+
244+ if (isA2dAptXHdEnabled && isA2dAptXEnabled && A2dAptXSchedLibHandle)
245+ {
246+ A2D_aptx_hd_encoder_deinit();
247+ isA2dAptXHdEnabled = false;
248+ }
249+
250+ return;
251+}
--- a/stack/avdt/avdt_scb_act.c
+++ b/stack/avdt/avdt_scb_act.c
@@ -69,9 +69,7 @@ const UINT8 avdt_scb_role_evt[] = {
6969 AVDT_OPEN_CFM_EVT /* AVDT_OPEN_INT */
7070 };
7171
72-extern UINT8* bta_av_get_current_codecInfo();
7372
74-#define NON_A2DP_MEDIA_CT 0xff
7573 /*******************************************************************************
7674 **
7775 ** Function avdt_scb_gen_ssrc
@@ -1239,11 +1237,9 @@ void avdt_scb_hdl_write_req_no_frag(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
12391237 }
12401238 osi_free_and_reset((void **)&p_scb->p_pkt);
12411239
1242- /* build a media packet if the codec type is not aptX */
1243-#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
1244-#else
1245- if (p_data->apiwrite.m_pt != NON_A2DP_MEDIA_CT)
1246-#endif
1240+ /* build a media packet */
1241+ /* Add RTP header if required */
1242+ if ( !(p_data->apiwrite.opt & AVDT_DATA_OPT_NO_RTP) )
12471243 {
12481244 ssrc = avdt_scb_gen_ssrc(p_scb);
12491245
--- a/stack/include/a2d_api.h
+++ b/stack/include/a2d_api.h
@@ -86,7 +86,7 @@
8686 #define A2D_BAD_CP_FORMAT 0xE1 /* The format of Content Protection Service Capability/Content Protection Scheme Dependent Data is not correct. */
8787
8888
89-#define A2D_NON_A2DP_MEDIA_CT 0xff /* NON A2DP media codec */
89+#define A2D_NON_A2DP_MEDIA_CT 0xFF /* NON A2DP media codec */
9090
9191 typedef UINT8 tA2D_STATUS;
9292
--- a/stack/include/a2d_aptx.h
+++ b/stack/include/a2d_aptx.h
@@ -60,8 +60,7 @@
6060 typedef enum {
6161 APTX_CODEC_NONE=0,
6262 APTX_CODEC,
63- APTX_CODEC_LL,
64- APTX_CODEC_HD,
63+ APTX_HD_CODEC,
6564 } A2D_AptXCodecType;
6665
6766 typedef void (*A2D_AptXThreadFn)(void *context);
@@ -122,6 +121,7 @@ extern void (*A2D_aptx_encoder_deinit)(void);
122121 extern UINT8 a2d_av_aptx_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap);
123122 extern BOOLEAN A2D_check_and_init_aptX();
124123 extern void A2D_deinit_aptX();
124+extern void A2D_close_aptX();
125125
126126 #ifdef __cplusplus
127127 }
--- /dev/null
+++ b/stack/include/a2d_aptx_hd.h
@@ -0,0 +1,105 @@
1+/******************************************************************************
2+
3+ Copyright (c) 2016, The Linux Foundation. All rights reserved.
4+
5+ Redistribution and use in source and binary forms, with or without
6+ modification, are permitted provided that the following conditions are
7+ met:
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+ * Redistributions in binary form must reproduce the above
11+ copyright notice, this list of conditions and the following
12+ disclaimer in the documentation and/or other materials provided
13+ with the distribution.
14+ * Neither the name of The Linux Foundation nor the names of its
15+ contributors may be used to endorse or promote products derived
16+ from this software without specific prior written permission.
17+
18+ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
19+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
21+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+
30+ ******************************************************************************/
31+/******************************************************************************
32+ interface to aptX HD codec
33+ ******************************************************************************/
34+#ifndef A2D_APTX_HD_H
35+#define A2D_APTX_HD_H
36+
37+/* aptX HD codec specific settings*/
38+#define A2D_APTX_HD_CODEC_LEN 13
39+
40+#define A2D_APTX_HD_VENDOR_ID (0x000000D7)
41+#define A2D_APTX_HD_CODEC_ID_BLUETOOTH ((UINT16) 0x0024)
42+#define A2D_APTX_HD_SAMPLERATE_44100 (0x20)
43+#define A2D_APTX_HD_SAMPLERATE_48000 (0x10)
44+#define A2D_APTX_HD_CHANNELS_STEREO (0x02)
45+#define A2D_APTX_HD_CHANNELS_MONO (0x01)
46+#define A2D_APTX_HD_ACL_SPRINT_RESERVED0 (0x00)
47+#define A2D_APTX_HD_ACL_SPRINT_RESERVED1 (0x00)
48+#define A2D_APTX_HD_ACL_SPRINT_RESERVED2 (0x00)
49+#define A2D_APTX_HD_ACL_SPRINT_RESERVED3 (0x00)
50+#define A2D_APTX_HD_OTHER_FEATURES_NONE (0x00000000)
51+#define A2D_APTX_HD_AV_AUDIO (0x00)
52+#define A2D_APTX_HD_CODEC_ID (0xff)
53+#define A2D_APTX_HD_CHANNEL (0x0001)
54+#define A2D_APTX_HD_SAMPLERATE (0x22)
55+
56+/*****************************************************************************
57+** Type Definitions
58+*****************************************************************************/
59+
60+typedef struct {
61+ UINT32 vendorId;
62+ UINT16 codecId; /* Codec ID for aptX HD */
63+ UINT8 sampleRate; /* Sampling Frequency */
64+ UINT8 channelMode; /* STEREO/DUAL/MONO */
65+ UINT8 acl_sprint_reserved0;
66+ UINT8 acl_sprint_reserved1;
67+ UINT8 acl_sprint_reserved2;
68+ UINT8 acl_sprint_reserved3;
69+} tA2D_APTX_HD_CIE;
70+
71+typedef struct {
72+ INT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
73+ INT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
74+ UINT16 u16BitRate;
75+ UINT16 *ps16NextPcmBuffer;
76+ UINT8 *pu8Packet;
77+ UINT8 *pu8NextPacket;
78+ UINT16 u16PacketLength;
79+ void* encoder;
80+} A2D_APTX_HD_ENC_PARAMS;
81+
82+extern BOOLEAN isA2dAptXHdEnabled;
83+
84+/*****************************************************************************
85+** external function declarations
86+*****************************************************************************/
87+#ifdef __cplusplus
88+extern "C"
89+{
90+#endif
91+extern UINT8 A2D_BldAptx_hdInfo(UINT8 media_type, tA2D_APTX_HD_CIE *p_ie,
92+ UINT8 *p_result);
93+extern UINT8 A2D_ParsAptx_hdInfo(tA2D_APTX_HD_CIE *p_ie, UINT8 *p_info,
94+ BOOLEAN for_caps);
95+extern int (*A2D_aptx_hd_encoder_init)(void);
96+extern void (*A2D_aptx_hd_encoder_deinit)(void);
97+extern UINT8 a2d_av_aptx_hd_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_HD_CIE *p_cap);
98+extern BOOLEAN A2D_check_and_init_aptX_HD();
99+extern void A2D_deinit_aptX_HD();
100+
101+#ifdef __cplusplus
102+}
103+#endif
104+
105+#endif /* A2D_APTX_HD_H */
--- a/stack/l2cap/l2c_csm.c
+++ b/stack/l2cap/l2c_csm.c
@@ -234,7 +234,7 @@ Event uninit_use_in_call: Using uninitialized value "settings.min" in call to fu
234234 p_ccb->chnl_state = CST_W4_L2CAP_CONNECT_RSP;
235235
236236 /* Wait for the info resp in this state before sending connect req (if needed) */
237- if ((!p_ccb->p_lcb->w4_info_rsp) || (BT_PSM_SDP == p_ccb->p_rcb->psm))
237+ if (!p_ccb->p_lcb->w4_info_rsp)
238238 {
239239 /* Need to have at least one compatible channel to continue */
240240 if (!l2c_fcr_chk_chan_modes(p_ccb))
--- a/stack/sdp/sdp_discovery.c
+++ b/stack/sdp/sdp_discovery.c
@@ -347,7 +347,7 @@ static void process_service_search_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
347347 #if (SDP_RAW_DATA_INCLUDED == TRUE)
348348 static void sdp_copy_raw_data (tCONN_CB *p_ccb, BOOLEAN offset)
349349 {
350- unsigned int cpy_len;
350+ unsigned int cpy_len, rem_len;
351351 UINT32 list_len;
352352 UINT8 *p;
353353 UINT8 type;
@@ -378,6 +378,12 @@ static void sdp_copy_raw_data (tCONN_CB *p_ccb, BOOLEAN offset)
378378 {
379379 cpy_len = list_len;
380380 }
381+ rem_len = SDP_MAX_LIST_BYTE_COUNT - (unsigned int) (p - &p_ccb->rsp_list[0]);
382+ if (cpy_len > rem_len)
383+ {
384+ SDP_TRACE_WARNING("rem_len :%d less than cpy_len:%d", rem_len, cpy_len);
385+ cpy_len = rem_len;
386+ }
381387 #if (SDP_DEBUG_RAW == TRUE)
382388 SDP_TRACE_WARNING("list_len :%d cpy_len:%d raw_size:%d raw_used:%d",
383389 list_len, cpy_len, p_ccb->p_db->raw_size, p_ccb->p_db->raw_used);