static int calc_audiotime(struct a2dp_config cfg, int bytes)
{
int chan_count = popcount(cfg.channel_flags);
+ int bytes_per_sample = 4;
- ASSERTC(cfg.format == AUDIO_FORMAT_PCM_16_BIT,
+ ASSERTC(cfg.format == AUDIO_FORMAT_PCM_8_24_BIT,
"unsupported sample sz", cfg.format);
- return bytes*(1000000/(chan_count*2))/cfg.rate;
+ return (int)(((int64_t)bytes * (1000000 / (chan_count * bytes_per_sample))) / cfg.rate);
}
static void ts_error_log(char *tag, int val, int buff_size, struct a2dp_config cfg)
a2dp_stream_common_init(&out->common);
#endif
out->common.cfg.channel_flags = AUDIO_STREAM_DEFAULT_CHANNEL_FLAG;
- out->common.cfg.format = AUDIO_STREAM_DEFAULT_FORMAT;
+ out->common.cfg.format = AUDIO_FORMAT_PCM_8_24_BIT;
out->common.cfg.rate = AUDIO_STREAM_DEFAULT_RATE;
/* set output config values */
#include "osi/include/osi.h"
#include "osi/include/socket_utils/sockets.h"
-
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
#define LOG_TAG "bthost_ipc"
#include "osi/include/log.h"
int a2dp_get_multicast_status(struct a2dp_stream_common *common, uint8_t *mcast_status,
uint8_t *num_dev)
{
- char cmd = A2DP_CTRL_GET_MULTICAST_STATUS;
INFO("%s",__func__);
if (a2dp_command(common,A2DP_CTRL_GET_MULTICAST_STATUS) < 0)
{
INFO("control path is disconnected");
break;
}
- INFO("%s: a2dp stream not started,wait 100mse & retry");
+ INFO("%s: a2dp stream not started,wait 100mse & retry", __func__);
usleep(100000);
}
if (audio_stream.state != AUDIO_A2DP_STATE_STARTED)
void * audio_get_codec_config(uint8_t *multicast_status, uint8_t *num_dev,
audio_format_t *codec_type)
{
- char *p_common_cfg = &audio_stream.codec_cfg[0];
- int i;
-
INFO("%s: state = %s",__func__,dump_a2dp_hal_state(audio_stream.state));
a2dp_get_multicast_status(&audio_stream, multicast_status,num_dev);
int (*a2dp_read_audio_config)(struct a2dp_stream_common *common);
int (*skt_read)(int fd,void *buf, size_t bytes);
int (*skt_write)(int fd,const void *buf, size_t bytes);
- void (*skt_disconnect)(int fd);
+ int (*skt_disconnect)(int fd);
int (*a2dp_command)(struct a2dp_stream_common *common,char cmd);
int (*audio_stream_open)(void);
int (*audio_stream_close)(void);
$(LOCAL_PATH)/../udrv/include \
$(LOCAL_PATH)/../vnd/include \
$(LOCAL_PATH)/../utils/include \
- $(TARGET_OUT_HEADERS)/bt/hci_qcomm_init/aptX \
$(bluetooth_C_INCLUDES)
LOCAL_CFLAGS += $(bluetooth_CFLAGS) -DBUILDCFG
#include "avdt_api.h"
#include "bta_av_int.h"
#include "bt_utils.h"
+#include "a2d_aptx.h"
+#include "a2d_aptx_hd.h"
#include "l2cdefs.h"
#include "l2c_api.h"
#include "osi/include/properties.h"
static UINT8 bta_av_get_scb_handle(tBTA_AV_SCB *p_scb, UINT8 local_sep)
{
UINT8 xx =0;
- const int NON_A2DP = 0xFF;
for (xx = 0; xx<BTA_AV_MAX_SEPS; xx++)
{
if ((p_scb->seps[xx].tsep == local_sep) &&
(p_scb->seps[xx].codec_type == p_scb->codec_type))
{
- if (p_scb->seps[xx].codec_type != NON_A2DP)
+ if (p_scb->seps[xx].codec_type != A2D_NON_A2DP_MEDIA_CT)
return (p_scb->seps[xx].av_handle);
else {
- UINT8 vendorId = p_scb->cfg.codec_info[BTA_AV_VENDOR_ID_TYPE_IDX];
- UINT8 codecId = p_scb->cfg.codec_info[BTA_AV_CODEC_ID_TYPE_IDX];
-
- if (codecId == p_scb->seps[xx].codecId && vendorId == p_scb->seps[xx].vendorId)
- return (p_scb->seps[xx].av_handle);
+ UINT8 losc = p_scb->cfg.codec_info[0];
+ if (losc == A2D_APTX_CODEC_LEN)
+ {
+ tA2D_APTX_CIE aptx_config;
+ if (A2D_ParsAptxInfo(&aptx_config, p_scb->cfg.codec_info, FALSE) == A2D_SUCCESS)
+ if ((aptx_config.codecId == p_scb->seps[xx].codecId) &&
+ (aptx_config.vendorId == p_scb->seps[xx].vendorId))
+ return (p_scb->seps[xx].av_handle);
+ } else if (losc == A2D_APTX_HD_CODEC_LEN)
+ {
+ tA2D_APTX_HD_CIE aptx_config;
+ if (A2D_ParsAptx_hdInfo(&aptx_config, p_scb->cfg.codec_info, FALSE) == A2D_SUCCESS)
+ if ((aptx_config.codecId == p_scb->seps[xx].codecId) &&
+ (aptx_config.vendorId == p_scb->seps[xx].vendorId))
+ return (p_scb->seps[xx].av_handle);
+ } else
+ APPL_TRACE_DEBUG("%s: Invalid aptX Losc", __func__)
}
}
}
static void bta_av_adjust_seps_idx(tBTA_AV_SCB *p_scb, UINT8 avdt_handle)
{
int xx;
- const int NON_A2DP = 0xFF;
APPL_TRACE_DEBUG("bta_av_adjust_seps_idx codec_type: %d", p_scb->codec_type);
for(xx=0; xx<BTA_AV_MAX_SEPS; xx++)
{
if((p_scb->seps[xx].av_handle && p_scb->codec_type == p_scb->seps[xx].codec_type)
&& (p_scb->seps[xx].av_handle == avdt_handle))
{
- if (p_scb->seps[xx].codec_type != NON_A2DP)
+ if (p_scb->seps[xx].codec_type != A2D_NON_A2DP_MEDIA_CT)
{
p_scb->sep_idx = xx;
p_scb->avdt_handle = p_scb->seps[xx].av_handle;
break;
}
else {
- UINT8 vendorId = p_scb->cfg.codec_info[BTA_AV_VENDOR_ID_TYPE_IDX];
- UINT8 codecId = p_scb->cfg.codec_info[BTA_AV_CODEC_ID_TYPE_IDX];
- APPL_TRACE_DEBUG("%s vendorId: %x codecId: %x", __func__, p_scb->seps[xx].vendorId, p_scb->seps[xx].codecId);
- if (codecId == p_scb->seps[xx].codecId && vendorId == p_scb->seps[xx].vendorId)
+ UINT8 losc = p_scb->cfg.codec_info[0];
+ if (losc == A2D_APTX_CODEC_LEN)
{
- APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
- APPL_TRACE_DEBUG("%s vendorID: %x codecID: %x", __func__, vendorId, codecId);
- p_scb->sep_idx = xx;
- p_scb->avdt_handle = p_scb->seps[xx].av_handle;
- APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
- APPL_TRACE_DEBUG("%s p_scb->avdt_handle: %d", __func__, p_scb->avdt_handle);
- break;
- }
+ tA2D_APTX_CIE aptx_config;
+ if (A2D_ParsAptxInfo(&aptx_config, p_scb->cfg.codec_info, FALSE) == A2D_SUCCESS) {
+ APPL_TRACE_DEBUG("%s vendorId: %x codecId: %x", __func__, p_scb->seps[xx].vendorId, p_scb->seps[xx].codecId);
+ if ((aptx_config.codecId == p_scb->seps[xx].codecId) &&
+ (aptx_config.vendorId == p_scb->seps[xx].vendorId)) {
+ APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
+ p_scb->sep_idx = xx;
+ p_scb->avdt_handle = p_scb->seps[xx].av_handle;
+ APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
+ APPL_TRACE_DEBUG("%s p_scb->avdt_handle: %d", __func__, p_scb->avdt_handle);
+ break;
+ }
+ }
+ } else if (losc == A2D_APTX_HD_CODEC_LEN)
+ {
+ tA2D_APTX_HD_CIE aptx_config;
+ if (A2D_ParsAptx_hdInfo(&aptx_config, p_scb->cfg.codec_info, FALSE) == A2D_SUCCESS) {
+ APPL_TRACE_DEBUG("%s vendorId: %x codecId: %x", __func__, p_scb->seps[xx].vendorId, p_scb->seps[xx].codecId);
+ if ((aptx_config.codecId == p_scb->seps[xx].codecId) &&
+ (aptx_config.vendorId == p_scb->seps[xx].vendorId)) {
+ APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
+ p_scb->sep_idx = xx;
+ p_scb->avdt_handle = p_scb->seps[xx].av_handle;
+ APPL_TRACE_DEBUG("%s p_scb->sep_idx: %d", __func__, p_scb->sep_idx);
+ APPL_TRACE_DEBUG("%s p_scb->avdt_handle: %d", __func__, p_scb->avdt_handle);
+ break;
+ }
+ }
+ } else
+ APPL_TRACE_DEBUG("%s: Invalid aptX Losc", __func__)
}
}
}
}
/*******************************************************************************
**
-** Function bta_av_co_audio_get_codec_type
+** Function bta_av_get_codec_type
**
-** Description Gets the p_scb->codec_type
+** Description Returns the codec_type from the most recently used scb
**
** Returns bta_av_cb.codec_type
**
*******************************************************************************/
-UINT8 bta_av_co_audio_get_codec_type()
+UINT8 bta_av_get_codec_type()
{
APPL_TRACE_DEBUG("%s [bta_av_cb.codec_type] %x", __func__, bta_av_cb.codec_type);
return bta_av_cb.codec_type;
tBTA_AV_CODEC codec_type; /* codec type */
UINT8 tsep; /* SEP type of local SEP */
tBTA_AV_DATA_CBACK *p_app_data_cback; /* Application callback for media packets */
- UINT8 vendorId; /* vendorId type */
- UINT8 codecId; /* codecId type */
+ UINT32 vendorId; /* vendorId type */
+ UINT16 codecId; /* codecId type */
} tBTA_AV_SEP;
#include "bt_target.h"
#include "osi/include/log.h"
+#include <cutils/properties.h>
#if defined(BTA_AV_INCLUDED) && (BTA_AV_INCLUDED == TRUE)
#include "bta_av_co.h"
#endif
#include "a2d_aptx.h"
+#include "a2d_aptx_hd.h"
/*****************************************************************************
** Constants and types
(*bta_av_a2d_cos.init)(&codec_type, cs.cfg.codec_info,
&cs.cfg.num_protect, cs.cfg.protect_info, index) == TRUE)
{
+ UINT8* ptr = cs.cfg.codec_info;
+ tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
+ UINT32 vendorId = codecInfo->vendorId;
+ UINT16 codecId = codecInfo->codecId;
+
if ((*bta_av_a2d_cos.offload)() == TRUE)
{
if(codec_type == A2D_NON_A2DP_MEDIA_CT)
{
-
- UINT8* ptr = cs.cfg.codec_info;
- tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3];
- UINT8 vendorId = codecInfo->vendorId;
- UINT8 codecId = codecInfo->codecId;
-
if (vendorId == A2D_APTX_VENDOR_ID &&
codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
{
continue;
}
}
- }
- else if((codec_type == A2D_NON_A2DP_MEDIA_CT) && (A2D_check_and_init_aptX() == false))
- {
- index++;
- continue;
+ } else if (codec_type == A2D_NON_A2DP_MEDIA_CT) {
+ if ((codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
+ && (A2D_check_and_init_aptX() == false)) {
+ APPL_TRACE_WARNING("%s aptX not available ", __func__);
+ index++;
+ continue;
+
+ } else {
+ char value[PROPERTY_VALUE_MAX];
+ bool enableAptXHD = false;
+ if (property_get("persist.bt.enableAptXHD", value, "false") && strcmp(value, "true") == 0)
+ enableAptXHD = true;
+ else
+ APPL_TRACE_WARNING("%s enableAptXHD property is not set", __func__);
+
+ if ((codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID) &&
+ ((enableAptXHD == false) || (A2D_check_and_init_aptX_HD() == false))) {
+ APPL_TRACE_WARNING("%s aptX-HD not available", __func__);
+ index++;
+ continue;
+ }
+ }
}
if(AVDT_CreateStream(&p_scb->seps[index - startIndex].av_handle, &cs) ==
AVDT_SUCCESS)
{
if ((profile_initialized == UUID_SERVCLASS_AUDIO_SOURCE) &&
- (index == BTIF_SV_AV_AA_APTX_INDEX))
+ ((index == BTIF_SV_AV_AA_APTX_INDEX) || (index == BTIF_SV_AV_AA_APTX_HD_INDEX)))
{
- UINT8* ptr = cs.cfg.codec_info;
- tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3];
- UINT8 vendorId = codecInfo->vendorId;
- UINT8 codecId = codecInfo->codecId;
-
p_scb->seps[index - startIndex].vendorId = vendorId;
p_scb->seps[index - startIndex].codecId = codecId;
APPL_TRACE_DEBUG("%s audio[%x] vendorId: %x codecId: %x", __func__,
{
tBTA_AV_SCB *p_scb = bta_av_hndl_to_scb(p_data->hdr.layer_specific);
- // de-initialize aptX
- A2D_deinit_aptX();
+ A2D_close_aptX();
if(p_scb)
{
/* offset of codec type in codec info byte array */
#define BTA_AV_CODEC_TYPE_IDX AVDT_CODEC_TYPE_INDEX /* 2 */
-/* offset of vendorId type in vendorId info byte array */
-#define BTA_AV_VENDOR_ID_TYPE_IDX AVDT_VENDOR_ID_TYPE_INDEX /* 3 */
-
-/* offset of codecId type in codecId info byte array */
-#define BTA_AV_CODEC_ID_TYPE_IDX AVDT_CODEC_ID_TYPE_INDEX /* 7 */
-
/* maximum number of streams created: 1 for audio, 1 for video */
#ifndef BTA_AV_NUM_STRS
#define BTA_AV_NUM_STRS 2
#ifndef BTA_AV_MAX_SEPS
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
-#define BTA_AV_MAX_SEPS 3
+#define BTA_AV_MAX_SEPS 4
#else
-#define BTA_AV_MAX_SEPS 2
+#define BTA_AV_MAX_SEPS 3
#endif
#endif
/* Company ID in BT assigned numbers */
#define BTA_AV_BT_VENDOR_ID VDP_BT_VENDOR_ID /* Broadcom Corporation */
+/* Offset for codec configuration in codec info */
+#define BTA_AV_CFG_START_IDX 3
+
/* vendor specific codec ID */
#define BTA_AV_CODEC_ID_H264 VDP_CODEC_ID_H264 /* Non-VDP codec ID - H.264 */
#define BTA_AV_CODEC_ID_IMG VDP_CODEC_ID_IMG /* Non-VDP codec ID - images/slideshow */
*******************************************************************************/
void BTA_AvOffloadStartRsp(tBTA_AV_HNDL hndl, tBTA_AV_STATUS status);
+/*******************************************************************************
+**
+** Function bta_av_get_codec_type
+**
+** Description Returns the codec_type from the most recently used scb
+**
+** Returns A2D_NON_A2DP_MEDIA_CT or BTIF_AV_CODEC_SBC
+**
+*******************************************************************************/
+UINT8 bta_av_get_codec_type();
#ifdef __cplusplus
}
{
BTIF_SV_AV_AA_SBC_INDEX = 0,
BTIF_SV_AV_AA_APTX_INDEX,
+ BTIF_SV_AV_AA_APTX_HD_INDEX,
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
BTIF_SV_AV_AA_AAC_INDEX,
#endif
$(LOCAL_PATH)/../audio_a2dp_hw \
$(LOCAL_PATH)/../utils/include \
$(bluetooth_C_INCLUDES) \
- $(TARGET_OUT_HEADERS)/bt/hci_qcomm_init/aptX \
external/tinyxml2 \
- external/zlib
+ external/zlib \
+ $(call include-path-for, audio-utils)
ifneq ($(TARGET_SUPPORTS_WEARABLES),true)
btifCommonIncludes += \
#include "btif_media.h"
#include "sbc_encoder.h"
+#include "btif_av.h"
#include "btif_av_co.h"
#include "btif_util.h"
#include "osi/include/mutex.h"
#include "bt_utils.h"
#include "a2d_aptx.h"
+#include "a2d_aptx_hd.h"
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
#include "a2d_aac.h"
#include "bta_av_aac.h"
A2D_APTX_FUTURE_2
};
+const tA2D_APTX_HD_CIE bta_av_co_aptx_hd_caps =
+{
+ A2D_APTX_HD_VENDOR_ID,
+ A2D_APTX_HD_CODEC_ID_BLUETOOTH,
+ A2D_APTX_HD_SAMPLERATE_44100,
+ A2D_APTX_HD_CHANNELS_STEREO,
+ A2D_APTX_HD_ACL_SPRINT_RESERVED0,
+ A2D_APTX_HD_ACL_SPRINT_RESERVED1,
+ A2D_APTX_HD_ACL_SPRINT_RESERVED2,
+ A2D_APTX_HD_ACL_SPRINT_RESERVED3
+};
+
+/* Default aptX_hd codec configuration */
+const tA2D_APTX_HD_CIE btif_av_aptx_hd_default_config =
+{
+ A2D_APTX_HD_VENDOR_ID,
+ A2D_APTX_HD_CODEC_ID_BLUETOOTH,
+ A2D_APTX_HD_SAMPLERATE_44100,
+ A2D_APTX_HD_CHANNELS_STEREO,
+ A2D_APTX_HD_ACL_SPRINT_RESERVED0,
+ A2D_APTX_HD_ACL_SPRINT_RESERVED1,
+ A2D_APTX_HD_ACL_SPRINT_RESERVED2,
+ A2D_APTX_HD_ACL_SPRINT_RESERVED3
+};
+
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
const tA2D_AAC_CIE bta_av_co_aac_caps =
{
};
#endif
-
/*****************************************************************************
** Local data
*****************************************************************************/
tBTIF_AV_CODEC_INFO codec_cfg_sbc_setconfig; /* remote peer setconfig preference (SBC) */
tBTIF_AV_CODEC_INFO codec_cfg_aptx;
tBTIF_AV_CODEC_INFO codec_cfg_aptx_setconfig; /* remote peer setconfig preference (aptX)*/
+ tBTIF_AV_CODEC_INFO codec_cfg_aptx_hd;
+ tBTIF_AV_CODEC_INFO codec_cfg_aptx_hd_setconfig; /* remote peer setconfig preference (aptX HD) */
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
tBTIF_AV_CODEC_INFO codec_cfg_aac;
tBTIF_AV_CODEC_INFO codec_cfg_aac_setconfig; /* remote peer setconfig preference (AAC)*/
static BOOLEAN bta_av_co_audio_media_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg);
static BOOLEAN bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg);
static BOOLEAN bta_av_co_audio_peer_src_supports_codec(tBTA_AV_CO_PEER *p_peer, UINT8 *p_src_index);
-extern UINT8 bta_av_co_audio_get_codec_type();
#ifdef BTA_AV_SPLIT_A2DP_ENABLED
extern BOOLEAN btif_av_is_codec_offload_supported(int codec);
#else
*p_codec_type = A2D_NON_A2DP_MEDIA_CT;
A2D_BldAptxInfo(AVDT_MEDIA_AUDIO, (tA2D_APTX_CIE *) &bta_av_co_aptx_caps, p_codec_info);
return TRUE;
+
+ case BTIF_SV_AV_AA_APTX_HD_INDEX:
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ /* Set up for aptX HD codec */
+ *p_codec_type = A2D_NON_A2DP_MEDIA_CT;
+ A2D_BldAptx_hdInfo(AVDT_MEDIA_AUDIO, (tA2D_APTX_HD_CIE *) &bta_av_co_aptx_hd_caps, p_codec_info);
+ return TRUE;
+
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
case BTIF_SV_AV_AA_AAC_INDEX:
APPL_TRACE_DEBUG("%s AAC", __func__);
break;
case A2D_NON_A2DP_MEDIA_CT:
{
- UINT16 codecId = ((tA2D_APTX_CIE*)(&p_codec_info[3]))->codecId;
- UINT32 vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[3]))->vendorId;
+ UINT16 codecId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->codecId;
+ UINT32 vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->vendorId;
APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId );
APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId );
- if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
- {
+ if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID) {
/* aptX */
supported = TRUE;
+ } else if (codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID) {
+ /* aptX HD */
+ supported = TRUE;
}
break;
}
APPL_TRACE_DEBUG("%s p_codec_info[%d]: %x", __func__, i, p_codec_info[i]);
if (codec_type == A2D_NON_A2DP_MEDIA_CT)
- memcpy(p_sink->codec_caps, &p_codec_info[3], AVDT_CODEC_SIZE);
+ memcpy(p_sink->codec_caps, &p_codec_info[BTA_AV_CFG_START_IDX], AVDT_CODEC_SIZE);
else
memcpy(p_sink->codec_caps, p_codec_info, AVDT_CODEC_SIZE);
{
UINT16 codecId;
UINT32 vendorId;
- codecId = ((tA2D_APTX_CIE*)(&p_codec_info[3]))->codecId;
- vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[3]))->vendorId;
+ codecId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->codecId;
+ vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->vendorId;
APPL_TRACE_DEBUG("%s codec_type = %x", __func__, codec_type);
APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
recfg_needed = TRUE;
}
- if ((codecId == A2D_APTX_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_VENDOR_ID))
- {
+ if ((codecId == A2D_APTX_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_VENDOR_ID)) {
APPL_TRACE_DEBUG("%s aptX", __func__);
bta_av_co_cb.codec_cfg_aptx_setconfig.id = A2D_NON_A2DP_MEDIA_CT;
memcpy(bta_av_co_cb.codec_cfg_aptx_setconfig.info, p_codec_info, AVDT_CODEC_SIZE);
bta_av_co_cb.codec_cfg_setconfig = &bta_av_co_cb.codec_cfg_aptx_setconfig;
+ } else if ((codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_HD_VENDOR_ID)) {
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ bta_av_co_cb.codec_cfg_aptx_hd_setconfig.id = A2D_NON_A2DP_MEDIA_CT;
+ memcpy(bta_av_co_cb.codec_cfg_aptx_hd_setconfig.info, p_codec_info, AVDT_CODEC_SIZE);
+ bta_av_co_cb.codec_cfg_setconfig = &bta_av_co_cb.codec_cfg_aptx_hd_setconfig;
}
break;
}
UINT8 *p_codec_info, BOOLEAN *p_no_rtp_hdr)
{
UNUSED(hndl);
- UNUSED(codec_type);
- UNUSED(p_codec_info);
- UNUSED(p_no_rtp_hdr);
FUNC_TRACE();
APPL_TRACE_DEBUG("bta_av_co_audio_start");
+ if (codec_type == A2D_NON_A2DP_MEDIA_CT) {
+ UINT16 codecId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->codecId;
+ UINT32 vendorId = ((tA2D_APTX_CIE*)(&p_codec_info[BTA_AV_CFG_START_IDX]))->vendorId;
+
+ // for aptX, we only add RTP hdr along with CP
+ if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID) {
+ if (!bta_av_co_cb.cp.active)
+ *p_no_rtp_hdr = TRUE;
+ }
+ }
}
/*******************************************************************************
APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
- memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg->info, A2D_APTX_CODEC_LEN+1);
- APPL_TRACE_DEBUG("%s aptX",__func__);
+ if ((codecId == A2D_APTX_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_VENDOR_ID)) {
+ memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg->info, A2D_APTX_CODEC_LEN+1);
+ APPL_TRACE_DEBUG("%s aptX",__func__);
+ } else if ((codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH) && (vendorId == A2D_APTX_HD_VENDOR_ID)) {
+ memcpy(p_codec_cfg, bta_av_co_cb.codec_cfg->info, A2D_APTX_HD_CODEC_LEN+1);
+ APPL_TRACE_DEBUG("%s aptX HD",__func__);
+ }
break;
- }
+ }
default:
APPL_TRACE_ERROR("bta_av_co_audio_codec_build_config: unsupported codec id %d", bta_av_co_cb.codec_cfg->id);
APPL_TRACE_DEBUG("%s codecId = %d ", __func__, codecId);
APPL_TRACE_DEBUG("%s vendorId = %x ", __func__, vendorId);
- if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
- {
+ if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID) {
/* aptX Classic */
APPL_TRACE_DEBUG("%s aptX", __func__);
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);
break;
+ } else if (codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID) {
+ /* aptX HD */
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ 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);
+ break;
} else {
- APPL_TRACE_ERROR("%s incorrect aptX vendor and codec ID combination (codec ID: %d)", __func__, codecId);
- APPL_TRACE_ERROR("%s incorrect aptX vendor (%x) and codec ID combination ", __func__, vendorId);
+ APPL_TRACE_ERROR("%s incorrect codecId (%d)", __func__, codecId);
+ APPL_TRACE_ERROR("%s incorrect vendorId (%x)", __func__, vendorId);
break;
}
}
- default:
+ default:
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);
break;
}
/* Configure the codec type to look for */
codec_type = bta_av_co_cb.codec_cfg->id;
-/* Check for aptX as this is order of priority.
- * Check for aptX-HD, then aptX-LL before aptX Classic as
+/* Check for aptX HD before aptX Classic as
* this is order of priority, if supported return true.
+ * multicast is not supported for aptX
*/
- if ((!bt_split_a2dp_enabled && isA2dAptXEnabled && (btif_max_av_clients <= 1)) ||
+ if ((!bt_split_a2dp_enabled && isA2dAptXEnabled && (btif_av_is_multicast_supported() == FALSE)) ||
(bt_split_a2dp_enabled && btif_av_is_codec_offload_supported(APTX)))
{
- UINT16 codecId;
- UINT32 vendorId;
- UINT8* aptx_capabilities;
-
- for (index = 0; index < p_peer->num_sup_snks; index++)
- {
- if (p_peer->snks[index].codec_type == A2D_NON_A2DP_MEDIA_CT)
- {
- aptx_capabilities = &(p_peer->snks[index].codec_caps[0]);
- codecId = ((tA2D_APTX_CIE*)aptx_capabilities)->codecId;
- vendorId = ((tA2D_APTX_CIE*)aptx_capabilities)->vendorId;
- int i = 0;
- for ( i = 0 ; i < AVDT_CODEC_SIZE; i++) {
- APPL_TRACE_DEBUG("%s codec_caps[%d]: %x", __func__, i, p_peer->snks[index].codec_caps[i]);
- }
- APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
- APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
- APPL_TRACE_DEBUG("%s p_peer->snks[index].codec_type = %x", __func__, p_peer->snks[index].codec_type );
-
- if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
- {
- if (p_snk_index)
+ UINT16 codecId;
+ UINT32 vendorId;
+ UINT8* aptx_capabilities;
+
+ if (isA2dAptXHdEnabled) {
+ for (index = 0; index < p_peer->num_sup_snks; index++)
+ {
+ if (p_peer->snks[index].codec_type == A2D_NON_A2DP_MEDIA_CT)
+ {
+ aptx_capabilities = &(p_peer->snks[index].codec_caps[0]);
+ codecId = ((tA2D_APTX_HD_CIE*)aptx_capabilities)->codecId;
+ vendorId = ((tA2D_APTX_HD_CIE*)aptx_capabilities)->vendorId;
+ int i = 0;
+ for ( i = 0 ; i < AVDT_CODEC_SIZE; i++) {
+ APPL_TRACE_DEBUG("%s codec_caps[%d]: %x", __func__, i, p_peer->snks[index].codec_caps[i]);
+ }
+ APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
+ APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
+ APPL_TRACE_DEBUG("%s p_peer->snks[index].codec_type = %x", __func__, p_peer->snks[index].codec_type );
+
+ if (codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID )
+ {
+ if (p_snk_index)
+ *p_snk_index = index;
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+
+ if (bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps, A2D_NON_A2DP_MEDIA_CT))
+ {
+ #if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
+ if (bta_av_co_audio_sink_has_scmst(&p_peer->snks[index]))
+ #endif
+ {
+ bta_av_co_cb.current_codec_id = bta_av_co_cb.codec_cfg_aptx_hd.id;
+ bta_av_co_cb.codec_cfg = &bta_av_co_cb.codec_cfg_aptx_hd;
+ return TRUE;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ for (index = 0; index < p_peer->num_sup_snks; index++)
+ {
+ if (p_peer->snks[index].codec_type == A2D_NON_A2DP_MEDIA_CT)
+ {
+ aptx_capabilities = &(p_peer->snks[index].codec_caps[0]);
+ codecId = ((tA2D_APTX_CIE*)aptx_capabilities)->codecId;
+ vendorId = ((tA2D_APTX_CIE*)aptx_capabilities)->vendorId;
+ int i = 0;
+ for ( i = 0 ; i < AVDT_CODEC_SIZE; i++) {
+ APPL_TRACE_DEBUG("%s codec_caps[%d]: %x", __func__, i, p_peer->snks[index].codec_caps[i]);
+ }
+ APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecId);
+ APPL_TRACE_DEBUG("%s vendorId = %x", __func__, vendorId);
+ APPL_TRACE_DEBUG("%s p_peer->snks[index].codec_type = %x", __func__, p_peer->snks[index].codec_type );
+
+ if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
+ {
+ if (p_snk_index)
*p_snk_index = index;
- APPL_TRACE_DEBUG("%s aptX", __func__);
+ APPL_TRACE_DEBUG("%s aptX", __func__);
- if (bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps, A2D_NON_A2DP_MEDIA_CT))
- {
+ if (bta_av_co_audio_codec_match(p_peer->snks[index].codec_caps, A2D_NON_A2DP_MEDIA_CT))
+ {
#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
- if (bta_av_co_audio_sink_has_scmst(&p_peer->snks[index]))
+ if (bta_av_co_audio_sink_has_scmst(&p_peer->snks[index]))
#endif
- {
- bta_av_co_cb.current_codec_id = bta_av_co_cb.codec_cfg_aptx.id;
- bta_av_co_cb.codec_cfg = &bta_av_co_cb.codec_cfg_aptx;
- return TRUE;
- }
- }
+ {
+ bta_av_co_cb.current_codec_id = bta_av_co_cb.codec_cfg_aptx.id;
+ bta_av_co_cb.codec_cfg = &bta_av_co_cb.codec_cfg_aptx;
+ return TRUE;
+ }
+ }
}
- }
+ }
}
} else
APPL_TRACE_DEBUG("%s aptX is disabled", __func__);
APPL_TRACE_DEBUG("%s codecId = %d ", __func__, codecId);
APPL_TRACE_DEBUG("%s vendorId = %x ", __func__, vendorId);
- if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID)
- {
+ if (codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_HD_VENDOR_ID) {
+ APPL_TRACE_DEBUG("%s tA2D_APTX_CIE aptX HD", __func__);
+ if (a2d_av_aptx_hd_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_APTX_HD_CIE *)&bta_av_co_aptx_hd_caps)) {
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ return FALSE;
+ }
+ break;
+ } else if (codecId == A2D_APTX_CODEC_ID_BLUETOOTH && vendorId == A2D_APTX_VENDOR_ID) {
APPL_TRACE_DEBUG("%s tA2D_APTX_CIE aptX", __func__);
- if (a2d_av_aptx_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_APTX_CIE *)&bta_av_co_aptx_caps))
- {
+ if (a2d_av_aptx_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_APTX_CIE *)&bta_av_co_aptx_caps)) {
APPL_TRACE_DEBUG("%s aptX", __func__);
return FALSE;
}
/* Check if this sink supports SCMS */
cp_active = bta_av_co_audio_sink_has_scmst(p_sink);
#endif
- APPL_TRACE_DEBUG("%s %x", __func__, bta_av_co_cb.current_codec_id);
+ APPL_TRACE_DEBUG("%s current_codec_id: %x", __func__, bta_av_co_cb.current_codec_id);
APPL_TRACE_DEBUG("%s p_scb_codec_type: %x", __func__, p_scb_codec_type);
- p_scb_codec_type = bta_av_co_audio_get_codec_type();
+ p_scb_codec_type = bta_av_get_codec_type();
APPL_TRACE_DEBUG("%s p_scb_codec_type: %x", __func__, p_scb_codec_type);
/* Check if this is a new configuration (new sink or new config) */
if ((p_sink != p_peer->p_snk) ||
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)
APPL_TRACE_ERROR("%s A2D_BldAptxInfo failed", __func__);
+ /* Reset the Current configuration to aptX HD */
+ bta_av_co_cb.codec_cfg_aptx_hd.id = A2D_NON_A2DP_MEDIA_CT;
+ 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)
+ APPL_TRACE_ERROR("%s A2D_BldAptx_hdInfo failed", __func__);
+
mutex_global_unlock();
}
tBTIF_AV_CODEC_INFO new_cfg_sbc;
tA2D_APTX_CIE aptx_config;
tBTIF_AV_CODEC_INFO new_cfg_aptx;
+ tA2D_APTX_HD_CIE aptx_hd_config;
+ tBTIF_AV_CODEC_INFO new_cfg_aptx_hd;
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
tA2D_AAC_CIE aac_config;
tBTIF_AV_CODEC_INFO new_cfg_aac;
return FALSE;
}
if ((p_feeding->cfg.pcm.bit_per_sample != 8) &&
- (p_feeding->cfg.pcm.bit_per_sample != 16))
+ (p_feeding->cfg.pcm.bit_per_sample != 16) &&
+ (p_feeding->cfg.pcm.bit_per_sample != 32))
{
APPL_TRACE_ERROR("bta_av_co_audio_set_codec PCM sample size unsupported");
return FALSE;
}
new_cfg_aptx.id = A2D_NON_A2DP_MEDIA_CT;
aptx_config = btif_av_aptx_default_config;
+ new_cfg_aptx_hd.id = A2D_NON_A2DP_MEDIA_CT;
+ aptx_hd_config = btif_av_aptx_hd_default_config;
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
new_cfg_aac.id = BTIF_AV_CODEC_M24;
aac_config = btif_av_aac_default_config;
case 48000:
sbc_config.samp_freq = A2D_SBC_IE_SAMP_FREQ_48;
aptx_config.sampleRate = A2D_APTX_SAMPLERATE_48000;
+ aptx_hd_config.sampleRate = A2D_APTX_HD_SAMPLERATE_48000;
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
aac_config.samp_freq = A2D_AAC_IE_SAMP_FREQ_48000;
#endif
case 44100:
sbc_config.samp_freq = A2D_SBC_IE_SAMP_FREQ_44;
aptx_config.sampleRate = A2D_APTX_SAMPLERATE_44100;
+ aptx_hd_config.sampleRate = A2D_APTX_HD_SAMPLERATE_44100;
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
aac_config.samp_freq = A2D_AAC_IE_SAMP_FREQ_44100;
#endif
APPL_TRACE_ERROR("%s A2D_BldAptxInfo failed", __func__);
return FALSE;
}
+ if (A2D_BldAptx_hdInfo(A2D_MEDIA_TYPE_AUDIO, &aptx_hd_config, new_cfg_aptx_hd.info) != A2D_SUCCESS)
+ {
+ APPL_TRACE_ERROR("%s A2D_BldAptx_hdInfo failed", __func__);
+ return FALSE;
+ }
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
if (A2D_BldAacInfo(A2D_MEDIA_TYPE_AUDIO, &aac_config, new_cfg_aac.info) != A2D_SUCCESS)
{
bta_av_co_cb.codec_cfg_sbc = new_cfg_sbc;
bta_av_co_cb.codec_cfg = &bta_av_co_cb.codec_cfg_sbc;
bta_av_co_cb.codec_cfg_aptx= new_cfg_aptx;
+ bta_av_co_cb.codec_cfg_aptx_hd = new_cfg_aptx_hd;
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
bta_av_co_cb.codec_cfg_aac = new_cfg_aac;
#endif
UINT8 bta_av_select_codec(UINT8 hdl)
{
- // Some circumstances - bta_av_co functions are called before codec clock is initialised
if (NULL == bta_av_co_cb.codec_cfg)
{
+ // Some circumstances - bta_av_co functions are called before
+ // codec clock is initialised
+ APPL_TRACE_ERROR("%s hdl = %d, no codec configured", __func__, hdl);
return BTIF_AV_CODEC_NONE;
}
else
}
}
-UINT8 bta_av_get_current_codec()
+UINT8 bta_av_co_get_current_codec()
{
// Some circumstances - bta_av_co functions are called before codec clock is initialised
if (NULL == bta_av_co_cb.codec_cfg)
return bta_av_co_cb.codec_cfg->id;
}
-UINT8* bta_av_get_current_codecInfo()
+UINT8* bta_av_co_get_current_codecInfo()
{
// We assume that the configuration block is always valid when this is called.
return &bta_av_co_cb.codec_cfg->info[0];
result = TRUE;
else
memcpy((tA2D_SBC_CIE *) p_config, &btif_av_sbc_default_config, sizeof(tA2D_SBC_CIE));
- }
- 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)
- {
+ } 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) {
APPL_TRACE_DEBUG("%s aptX", __func__);
tA2D_APTX_CIE *aptx_config = (tA2D_APTX_CIE *)p_config;
if (A2D_ParsAptxInfo(aptx_config, bta_av_co_cb.codec_cfg_aptx.info, FALSE) == A2D_SUCCESS)
result = TRUE;
else
memcpy((tA2D_APTX_CIE *) p_config, &btif_av_aptx_default_config, sizeof(tA2D_APTX_CIE));
+ } 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) {
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ tA2D_APTX_HD_CIE *aptx_hd_config = (tA2D_APTX_HD_CIE *)p_config;
+ if (A2D_ParsAptx_hdInfo(aptx_hd_config, bta_av_co_cb.codec_cfg_aptx_hd.info, FALSE) == A2D_SUCCESS)
+ result = TRUE;
+ else
+ memcpy((tA2D_APTX_HD_CIE *) p_config, &btif_av_aptx_hd_default_config, sizeof(tA2D_APTX_HD_CIE));
} else {
APPL_TRACE_DEBUG("%s vendorId: %d codecId: %d\n", __func__, ((tA2D_APTX_CIE *)p_config)->vendorId, ((tA2D_APTX_CIE *)p_config)->codecId);
}
#define btif_av_get_peer_addr(peer_bda) (0)
#endif
+/*******************************************************************************
+**
+** Function btif_av_get_multicast_state
+**
+** Description Check if A2DP multicast is enabled
+**
+** Returns TRUE if a2dp multicast is enabled
+**
+*******************************************************************************/
+BOOLEAN btif_av_get_multicast_state();
+
+/*******************************************************************************
+**
+** Function btif_av_is_multicast_supported
+**
+** Description Check if A2DP multicast is supported
+**
+** Returns TRUE if a2dp multicast is supported
+**
+*******************************************************************************/
+BOOLEAN btif_av_is_multicast_supported();
+
#endif /* BTIF_AV_H */
/*******************************************************************************
**
- ** Function bta_av_get_current_codec
+ ** Function bta_av_co_get_current_codec
**
** Description Get the current codec type.
**
** Returns Codec Type Value
**
*******************************************************************************/
-UINT8 bta_av_get_current_codec();
+UINT8 bta_av_co_get_current_codec();
/*******************************************************************************
**
- ** Function bta_av_get_current_codecInfo
+ ** Function bta_av_co_get_current_codecInfo
**
** Description Get the current codec Info.
**
** Returns Returns pointer to Info
**
*******************************************************************************/
-UINT8* bta_av_get_current_codecInfo();
+UINT8* bta_av_co_get_current_codecInfo();
/*******************************************************************************
**
*******************************************************************************/
UINT8 bta_av_select_codec(tBTA_AV_HNDL hdl);
-/*******************************************************************************
- **
- ** Function bta_av_get_current_codec
- **
- ** Description Get current codec id selected for streaming.
- **
- ** Returns Return current codec id
- **
- *******************************************************************************/
-UINT8 bta_av_get_current_codec(void);
-
#endif
#define BTIF_MEDIA_TRSCD_OFF 0
#define BTIF_MEDIA_TRSCD_PCM_2_SBC 1 /* Tx */
#define BTIF_MEDIA_TRSCD_PCM_2_APTX 2
-
-extern int btif_max_av_clients; /* maximum number of AV clients supported */
+#define BTIF_MEDIA_TRSCD_PCM_2_APTX_HD 3
/*******************************************************************************
** Data types
UINT8 AllocationMethod; /* loudness or SNR*/
UINT16 MtuSize; /* peer mtu size */
UINT8 CodecType; /* SBC or Non-A2DP */
- UINT8 BluetoothVendorID; /* Bluetooth Vendor ID */
- UINT8 BluetoothCodecID; /* Bluetooth Codec ID */
+ UINT32 BluetoothVendorID; /* Bluetooth Vendor ID */
+ UINT16 BluetoothCodecID; /* Bluetooth Codec ID */
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
UINT8 ObjectType;
UINT32 bit_rate;
UINT8 MaxBitPool; /* Maximum peer bitpool */
UINT8 MinBitPool; /* Minimum peer bitpool */
UINT8 CodecType; /* SBC or Non-A2DP */
- UINT8 BluetoothVendorID; /* Bluetooth Vendor ID */
- UINT8 BluetoothCodecID; /* Bluetooth Codec ID */
+ UINT32 BluetoothVendorID; /* Bluetooth Vendor ID */
+ UINT16 BluetoothCodecID; /* Bluetooth Codec ID */
} tBTIF_MEDIA_UPDATE_AUDIO;
/* tBTIF_MEDIA_INIT_AUDIO_FEEDING msg structure */
/******************************************************************************
**
+** Function btif_av_is_multicast_supported
+**
+** Description Returns TRUE if multicast is supported
+**
+** Returns BOOLEAN
+******************************************************************************/
+BOOLEAN btif_av_is_multicast_supported()
+{
+ return is_multicast_supported;
+}
+
+/******************************************************************************
+**
** Function btif_av_is_offload_supported
**
** Description Returns split mode status
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
+#include <dlfcn.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
+#include <audio_utils/primitives.h>
+#include <audio_utils/format.h>
#include <hardware/bluetooth.h>
#include "a2d_int.h"
#include "a2d_sbc.h"
#include "a2d_aptx.h"
+#include "a2d_aptx_hd.h"
#include "a2d_aac.h"
#include "audio_a2dp_hw.h"
#include "bt_target.h"
#if (BTA_AV_CO_CP_SCMS_T == TRUE)
#define BTIF_MEDIA_AA_APTX_OFFSET (AVDT_MEDIA_OFFSET + 1)
+#define BTIF_MEDIA_AA_APTX_HD_OFFSET (AVDT_MEDIA_OFFSET + 1)
#else
#define BTIF_MEDIA_AA_APTX_OFFSET (AVDT_MEDIA_OFFSET - AVDT_MEDIA_HDR_SIZE) //no RTP header for aptX classic
+#define BTIF_MEDIA_AA_APTX_HD_OFFSET (AVDT_MEDIA_OFFSET) //there is an RTP header for aptX HD, but no CP byte
#endif
/* Define the bitrate step when trying to match bitpool value */
#ifndef BTIF_MEDIA_BITRATE_STEP
SBC_ENC_PARAMS encoder;
UINT16 offset;
A2D_APTX_ENC_PARAMS aptxEncoderParams;
+ A2D_APTX_HD_ENC_PARAMS aptxhdEncoderParams;
UINT16 as16PcmBuffer[1024];
+ UINT32 as32PcmBuffer[1024];
UINT8 busy_level;
void* av_sm_hdl;
UINT8 a2dp_cmd_pending; /* we can have max one command pending */
#endif
BOOLEAN bta_av_co_audio_get_codec_config(UINT8 *p_config, UINT16 *p_minmtu, UINT8 type);
-UINT8 bta_av_get_current_codec();
static thread_t *aptx_thread = NULL;
#if (BTA_AV_INCLUDED == TRUE)
static thread_t *worker_thread;
BOOLEAN bta_av_co_audio_get_codec_config(UINT8 *p_config, UINT16 *p_minmtu, UINT8 type);
-UINT8 bta_av_get_current_codec();
extern BOOLEAN bt_split_a2dp_enabled;
extern int btif_max_av_clients;
}
else //get playing device hdl
{
- codec_id = bta_av_get_current_codec();
+ codec_id = bta_av_co_get_current_codec();
}
a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
else if (codec_id == A2D_NON_A2DP_MEDIA_CT) //this is changed to non-a2dp VS codec
{
//ADD APTX support
- UINT8* ptr = bta_av_get_current_codecInfo();
+ UINT8* ptr = bta_av_co_get_current_codecInfo();
int j;
UINT8 *p_ptr = ptr;
for(j=0; j< (int)sizeof(tA2D_APTX_CIE);j++)
if (ptr)
{
tA2D_APTX_CIE* codecInfo = 0;
- codecInfo = (tA2D_APTX_CIE*) &ptr[3];
- if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID
+ codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
+ if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID
&& codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
{
tA2D_APTX_CIE aptx_config;
static BOOLEAN btif_media_task_is_aptx_configured()
{
BOOLEAN result = FALSE;
- UINT8 codectype = bta_av_get_current_codec();
-
- if (codectype == A2D_NON_A2DP_MEDIA_CT)
- {
- UINT8* ptr = bta_av_get_current_codecInfo();
- if (ptr)
- {
- tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3];
- if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
+ UINT8 codectype = bta_av_co_get_current_codec();
+
+ if (codectype == A2D_NON_A2DP_MEDIA_CT) {
+ UINT8* ptr = bta_av_co_get_current_codecInfo();
+ if (ptr) {
+ tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
+ if ((codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
+ || (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH))
+ APPL_TRACE_DEBUG("%s codecId %d", __func__, codecInfo->codecId);
+ APPL_TRACE_DEBUG("%s vendorId %x", __func__, codecInfo->vendorId);
result = TRUE;
}
}
A2D_AptXCodecType btif_media_task_get_aptX_codec_type()
{
A2D_AptXCodecType codec = APTX_CODEC_NONE;
- UINT8 a2dp_codectype = bta_av_get_current_codec();
+ UINT8 a2dp_codectype = bta_av_co_get_current_codec();
- if (a2dp_codectype == A2D_NON_A2DP_MEDIA_CT)
- {
- UINT8* ptr = bta_av_get_current_codecInfo();
- if (ptr)
- {
- tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[3];
+ if (a2dp_codectype == A2D_NON_A2DP_MEDIA_CT) {
+ UINT8* ptr = bta_av_co_get_current_codecInfo();
+ if (ptr) {
+ tA2D_APTX_CIE* codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
codec = APTX_CODEC;
+ else if (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH)
+ codec = APTX_HD_CODEC;
}
}
return codec;
UINT8 codectype;
codectype = bta_av_select_codec(hdl);
- if (A2D_NON_A2DP_MEDIA_CT == codectype)
- {
- UINT8* ptr = bta_av_get_current_codecInfo();
- if (ptr)
- {
+ if (A2D_NON_A2DP_MEDIA_CT == codectype) {
+ UINT8* ptr = bta_av_co_get_current_codecInfo();
+ if (ptr) {
//tA2D_APTX_CIE starts on 4th byte
- codecInfo = (tA2D_APTX_CIE*) &ptr[3];
+ codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
APPL_TRACE_DEBUG("%s codecId = %d", __func__, codecInfo->codecId);
APPL_TRACE_DEBUG("%s vendorId = %x", __func__, codecInfo->vendorId);
btif_media_task_enc_init_req(&msg);
return;
}
+
+ if (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID
+ && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH)
+ {
+ btif_media_cb.offset = BTIF_MEDIA_AA_APTX_HD_OFFSET;
+ tA2D_APTX_HD_CIE aptx_hd_config;
+ ALOGI("%s Selected Codec aptX HD", __func__);
+ aptx_hd_config.vendorId = codecInfo->vendorId;
+ aptx_hd_config.codecId = codecInfo->codecId;
+ bta_av_co_audio_get_codec_config((UINT8*)&aptx_hd_config, &minmtu, A2D_NON_A2DP_MEDIA_CT);
+ msg.CodecType = A2D_NON_A2DP_MEDIA_CT;
+ msg.SamplingFreq = aptx_hd_config.sampleRate;
+ msg.MtuSize = minmtu;
+ msg.ChannelMode = aptx_hd_config.channelMode;
+ msg.BluetoothVendorID = aptx_hd_config.vendorId;
+ msg.BluetoothCodecID = aptx_hd_config.codecId;
+ btif_media_task_enc_init_req(&msg);
+ return;
+ }
}
}/* if ( A2D_NON_A2DP_MEDIA_CT == codectype) */
APPL_TRACE_DEBUG("btif_a2dp_encoder_update");
UINT8 codectype = 0;
- codectype = bta_av_get_current_codec();
+ codectype = bta_av_co_get_current_codec();
if (codectype == A2D_NON_A2DP_MEDIA_CT)
{
- UINT8* ptr = bta_av_get_current_codecInfo();
+ UINT8* ptr = bta_av_co_get_current_codecInfo();
if (ptr)
{
- codecInfo = (tA2D_APTX_CIE*) &ptr[3];
+ codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH)
{
APPL_TRACE_DEBUG("%s aptX", __func__);
msg.BluetoothVendorID = aptx_config.vendorId;
msg.BluetoothCodecID = aptx_config.codecId;
}
+
+ if (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH)
+ {
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ tA2D_APTX_HD_CIE aptx_hd_config;
+ aptx_hd_config.vendorId = codecInfo->vendorId;
+ aptx_hd_config.codecId = codecInfo->codecId;
+ bta_av_co_audio_get_codec_config((UINT8*)&aptx_hd_config, &minmtu, A2D_NON_A2DP_MEDIA_CT );
+ msg.CodecType = A2D_NON_A2DP_MEDIA_CT;
+ msg.BluetoothVendorID = aptx_hd_config.vendorId;
+ msg.BluetoothCodecID = aptx_hd_config.codecId;
+ }
} /* if (ptr) */
}
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
/* for now hardcode 48 khz 16 bit stereo PCM format */
media_feeding.cfg.pcm.sampling_freq = 48000;
#else
- /* for now hardcode 44.1 khz 16 bit stereo PCM format */
+ /* for now hardcode 44.1 khz 32 bit stereo PCM format */
media_feeding.cfg.pcm.sampling_freq = BTIF_A2DP_SRC_SAMPLING_RATE;
#endif
media_feeding.cfg.pcm.bit_per_sample = BTIF_A2DP_SRC_BIT_DEPTH;
media_feeding.cfg.pcm.num_channel = BTIF_A2DP_SRC_NUM_CHANNELS;
media_feeding.format = BTIF_AV_CODEC_PCM;
+ /* 32 bits for AUDIO_FORMAT_PCM_8_24_BIT, all codecs affected. */
+ APPL_TRACE_EVENT("%s bit_per_sample %d", __func__, media_feeding.cfg.pcm.bit_per_sample);
+ APPL_TRACE_EVENT("%s sampling_freq %d", __func__, media_feeding.cfg.pcm.sampling_freq);
+
if (bta_av_co_audio_set_codec(&media_feeding, &status))
{
tBTIF_MEDIA_INIT_AUDIO_FEEDING mfeed;
*******************************************************************************/
BOOLEAN btif_media_task_clear_track(void)
{
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_AUDIO_SINK_CLEAR_TRACK;
if (btif_media_cmd_msg_queue != NULL)
*******************************************************************************/
BOOLEAN btif_media_task_send_cmd_evt(UINT16 Evt)
{
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = Evt;
*******************************************************************************/
BOOLEAN btif_media_task_start_aa_req(void)
{
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_START_AA_TX;
*******************************************************************************/
BOOLEAN btif_media_task_stop_aa_req(void)
{
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_STOP_AA_TX;
if (fixed_queue_is_empty(btif_media_cb.RxSbcQ)) /* Que is already empty */
return TRUE;
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_FLUSH_AA_RX;
if (btif_media_cmd_msg_queue != NULL)
*******************************************************************************/
BOOLEAN btif_media_task_aa_tx_flush_req(void)
{
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_FLUSH_AA_TX;
APPL_TRACE_EVENT("%s BluetoothVendorID %x, BluetoothCodecID %d", __func__,
pInitAudio->BluetoothVendorID, pInitAudio->BluetoothCodecID);
if ((pInitAudio->BluetoothVendorID == A2D_APTX_VENDOR_ID)
- && (pInitAudio->BluetoothCodecID == A2D_APTX_CODEC_ID_BLUETOOTH)) /* aptX Classic */
- {
+ && (pInitAudio->BluetoothCodecID == A2D_APTX_CODEC_ID_BLUETOOTH)) {
btif_media_cb.aptxEncoderParams.s16SamplingFreq= pInitAudio->SamplingFreq;
btif_media_cb.aptxEncoderParams.s16ChannelMode = pInitAudio->ChannelMode;
btif_media_cb.aptxEncoderParams.u16PacketLength = 4; // 32-bit word encoded by aptX encoder
< pInitAudio->MtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_OFFSET
- sizeof(BT_HDR)) : pInitAudio->MtuSize;
return;
+ } else if ((pInitAudio->BluetoothVendorID == A2D_APTX_HD_VENDOR_ID)
+ && (pInitAudio->BluetoothCodecID == A2D_APTX_HD_CODEC_ID_BLUETOOTH)) {
+ btif_media_cb.aptxhdEncoderParams.s16SamplingFreq= pInitAudio->SamplingFreq;
+ btif_media_cb.aptxhdEncoderParams.s16ChannelMode = pInitAudio->ChannelMode;
+ btif_media_cb.aptxhdEncoderParams.u16PacketLength = 6; // 48-bit word encoded by aptX encoder
+ btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_APTX_HD;
+ btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_HD_OFFSET-sizeof(BT_HDR))
+ < pInitAudio->MtuSize) ? (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_HD_OFFSET
+ - sizeof(BT_HDR)) : pInitAudio->MtuSize;
+ return;
} else {
/* do nothing, fall through to SBC */
}
pUpdateAudio->BluetoothVendorID, pUpdateAudio->BluetoothCodecID);
if ((pUpdateAudio->BluetoothVendorID == A2D_APTX_VENDOR_ID)
- && (pUpdateAudio->BluetoothCodecID == A2D_APTX_CODEC_ID_BLUETOOTH)) /* aptX Classic */
- {
+ && (pUpdateAudio->BluetoothCodecID == A2D_APTX_CODEC_ID_BLUETOOTH)) {
APPL_TRACE_DEBUG("%s aptX ", __func__);
btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_OFFSET - sizeof(BT_HDR)) < pUpdateAudio->MinMtuSize) ?
(BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_OFFSET - sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize;
APPL_TRACE_DEBUG("%s : aptX btif_media_cb.TxAaMtuSize %d", __func__, btif_media_cb.TxAaMtuSize);
return;
+ } else if ((pUpdateAudio->BluetoothVendorID == A2D_APTX_HD_VENDOR_ID)
+ && (pUpdateAudio->BluetoothCodecID == A2D_APTX_HD_CODEC_ID_BLUETOOTH)) {
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ btif_media_cb.TxAaMtuSize = ((BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_HD_OFFSET - sizeof(BT_HDR)) < pUpdateAudio->MinMtuSize) ?
+ (BTIF_MEDIA_AA_BUF_SIZE - BTIF_MEDIA_AA_APTX_HD_OFFSET - sizeof(BT_HDR)) : pUpdateAudio->MinMtuSize;
+ return;
} else {
/* do nothing, fall through to SBC */
}
/*******************************************************************************
**
+ ** Function btif_media_task_pcm2aptx_hd_init
+ **
+ ** Description Init encoding task for PCM to aptX according to feeding
+ **
+ ** Returns void
+ **
+ *******************************************************************************/
+static void btif_media_task_pcm2aptx_hd_init(tBTIF_MEDIA_INIT_AUDIO_FEEDING * p_feeding)
+{
+ BOOLEAN reconfig_needed = FALSE;
+
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ APPL_TRACE_DEBUG("%s PCM feeding:", __func__);
+ APPL_TRACE_DEBUG("%s sampling_freq:%d", __func__, p_feeding->feeding.cfg.pcm.sampling_freq);
+ APPL_TRACE_DEBUG("%s num_channel:%d", __func__, p_feeding->feeding.cfg.pcm.num_channel);
+ APPL_TRACE_DEBUG("%s bit_per_sample:%d", __func__, p_feeding->feeding.cfg.pcm.bit_per_sample);
+
+ /* Check the PCM feeding sampling_freq */
+ switch (p_feeding->feeding.cfg.pcm.sampling_freq)
+ {
+ case 8000:
+ case 12000:
+ case 16000:
+ case 24000:
+ case 32000:
+ case 48000:
+ /* For these sampling_freq the AV connection must be 48000 */
+ if (btif_media_cb.aptxhdEncoderParams.s16SamplingFreq != A2D_APTX_HD_SAMPLERATE_48000)
+ {
+ /* Reconfiguration needed at 48000 */
+ APPL_TRACE_DEBUG("%s Reconfiguration needed at 48000", __func__);
+ btif_media_cb.aptxhdEncoderParams.s16SamplingFreq = A2D_APTX_HD_SAMPLERATE_48000;
+ reconfig_needed = TRUE;
+ }
+ break;
+
+ case 11025:
+ case 22050:
+ case 44100:
+ /* For these sampling_freq the AV connection must be 44100 */
+ if (btif_media_cb.aptxhdEncoderParams.s16SamplingFreq != A2D_APTX_HD_SAMPLERATE_44100)
+ {
+ /* Reconfiguration needed at 44100 */
+ APPL_TRACE_DEBUG("%s Reconfiguration needed at 44100", __func__);
+ btif_media_cb.aptxhdEncoderParams.s16SamplingFreq = A2D_APTX_HD_SAMPLERATE_44100;
+ reconfig_needed = TRUE;
+ }
+ break;
+ default:
+ APPL_TRACE_DEBUG("%s Feeding PCM sampling_freq unsupported", __func__);
+ break;
+ }
+
+ /* Some AV Headsets do not support Mono => always ask for Stereo */
+ if (btif_media_cb.aptxhdEncoderParams.s16ChannelMode == A2D_APTX_HD_CHANNELS_MONO)
+ {
+ APPL_TRACE_DEBUG("%s Reconfiguration needed in Stereo", __func__);
+ btif_media_cb.aptxhdEncoderParams.s16ChannelMode = A2D_APTX_HD_CHANNELS_STEREO;
+ reconfig_needed = TRUE;
+ }
+
+ if (reconfig_needed != FALSE)
+ {
+ APPL_TRACE_DEBUG("%s calls APTX_HD_Encoder_Init", __func__);
+ APPL_TRACE_DEBUG("%s mtu %d", __func__, btif_media_cb.TxAaMtuSize);
+ APPL_TRACE_DEBUG("%s ch mode %d, Smp freq %d", __func__,
+ btif_media_cb.aptxhdEncoderParams.s16ChannelMode, btif_media_cb.aptxhdEncoderParams.s16SamplingFreq);
+ } else {
+ APPL_TRACE_DEBUG("%s No aptX HD reconfig needed", __func__);
+ }
+}
+
+/*******************************************************************************
+ **
** Function btif_media_task_pcm2aptx_init
**
** Description Init encoding task for PCM to aptX according to feeding
case BTIF_AV_CODEC_PCM:
{
UINT8 codectype;
- codectype = bta_av_get_current_codec();
+ codectype = bta_av_co_get_current_codec();
+
+ if (A2D_NON_A2DP_MEDIA_CT == codectype) {
+ UINT8* ptr = bta_av_co_get_current_codecInfo();
+ if (ptr) {
+ // tA2D_APTX_CIE starts on 4th byte
+ codecInfo = (tA2D_APTX_CIE*) &ptr[BTA_AV_CFG_START_IDX];
+ if (codecInfo) {
+ APPL_TRACE_DEBUG("%s codecId = %d ", __func__, codecInfo->codecId);
+ APPL_TRACE_DEBUG("%s vendorId = %x ", __func__, codecInfo->vendorId);
+ }
- if (A2D_NON_A2DP_MEDIA_CT == codectype)
- {
- UINT8* ptr = bta_av_get_current_codecInfo();
- if (ptr)
- {
- // tA2D_APTX_CIE starts on 4th byte
- codecInfo = (tA2D_APTX_CIE*) &ptr[3];
- if (codecInfo)
- {
- APPL_TRACE_DEBUG("%s codecId = %d ", __func__, codecInfo->codecId);
- APPL_TRACE_DEBUG("%s vendorId = %x ", __func__, codecInfo->vendorId);
- }
-
- if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH) /* aptX Classic */
- {
- APPL_TRACE_DEBUG("%s aptX", __func__);
- btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_APTX;
- btif_media_task_pcm2aptx_init(p_feeding);
- break;
- } else {
- /* do nothing, fall through to SBC */
- }
+ if (codecInfo && codecInfo->vendorId == A2D_APTX_VENDOR_ID && codecInfo->codecId == A2D_APTX_CODEC_ID_BLUETOOTH) {
+ APPL_TRACE_DEBUG("%s aptX", __func__);
+ btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_APTX;
+ btif_media_task_pcm2aptx_init(p_feeding);
+ break;
+ } else if (codecInfo && codecInfo->vendorId == A2D_APTX_HD_VENDOR_ID && codecInfo->codecId == A2D_APTX_HD_CODEC_ID_BLUETOOTH) {
+ APPL_TRACE_DEBUG("%s aptX HD", __func__);
+ btif_media_cb.TxTranscoding = BTIF_MEDIA_TRSCD_PCM_2_APTX_HD;
+ btif_media_task_pcm2aptx_hd_init(p_feeding);
+ break;
+ } else {
+ /* do nothing, fall through to SBC */
+ }
}
}
{
int bytes_per_frame = 2;
uint64_t timestamp_us = 0;
+ UINT8 codectype;
+ codectype = bta_av_co_get_current_codec();
+
+ if (btif_media_task_get_aptX_codec_type() == APTX_HD_CODEC) {
+ bytes_per_frame = 3;
+ }
if (length > 0 ) {
osi_free(fixed_queue_try_dequeue(btif_media_cb.TxAaQ));
}
- BT_HDR *p_buf = osi_malloc(BTIF_MEDIA_AA_BUF_SIZE);
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(BTIF_MEDIA_AA_BUF_SIZE);
int rtpTimestamp = (pcm_bytes_encoded / btif_media_cb.media_feeding.cfg.pcm.num_channel / bytes_per_frame);
BOOLEAN use_SCMS_T = false;
#endif
A2D_AptXCodecType aptX_codec_type = btif_media_task_get_aptX_codec_type();
- BOOLEAN is_24bit_audio = false;
+ BOOLEAN is_24bit_audio = true;
BOOLEAN test = false;
BOOLEAN trace = false;
BT_HDR *btif_media_aa_readbuf(void)
{
uint64_t now_us = time_now_us();
- BT_HDR *p_buf = fixed_queue_try_dequeue(btif_media_cb.TxAaQ);
+ BT_HDR *p_buf = (BT_HDR *)fixed_queue_try_dequeue(btif_media_cb.TxAaQ);
btif_media_cb.stats.tx_queue_total_readbuf_calls++;
btif_media_cb.stats.tx_queue_last_readbuf_us = now_us;
UINT16 bytes_needed = blocm_x_subband * btif_media_cb.encoder.s16NumOfChannels * \
btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
static UINT16 up_sampled_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
- * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2];
+ * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 4];
static UINT16 read_buffer[SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS
- * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
+ * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * 2];
UINT32 src_size_used;
UINT32 dst_size_used;
BOOLEAN fract_needed;
if (sbc_sampling == btif_media_cb.media_feeding.cfg.pcm.sampling_freq) {
read_size = bytes_needed - btif_media_cb.media_feeding_state.pcm.aa_feed_residue;
nb_byte_read = UIPC_Read(channel_id, &event,
- ((UINT8 *)btif_media_cb.encoder.as16PcmBuffer) +
+ ((UINT8 *)btif_media_cb.encoder.as32PcmBuffer) +
btif_media_cb.media_feeding_state.pcm.aa_feed_residue,
read_size);
if (nb_byte_read == read_size) {
if(btif_media_cb.media_feeding_state.pcm.aa_feed_residue >= bytes_needed)
{
/* Copy the output pcm samples in SBC encoding buffer */
- memcpy((UINT8 *)btif_media_cb.encoder.as16PcmBuffer,
+ memcpy((UINT8 *)btif_media_cb.encoder.as32PcmBuffer,
(UINT8 *)up_sampled_buffer,
bytes_needed);
/* update the residue */
btif_media_cb.encoder.s16NumOfBlocks;
while (nb_frame) {
- BT_HDR *p_buf = osi_malloc(BTIF_MEDIA_AA_BUF_SIZE);
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(BTIF_MEDIA_AA_BUF_SIZE);
/* Init buffer */
p_buf->offset = BTIF_MEDIA_AA_SBC_OFFSET;
/* Write @ of allocated buffer in encoder.pu8Packet */
btif_media_cb.encoder.pu8Packet = (UINT8 *) (p_buf + 1) + p_buf->offset + p_buf->len;
/* Fill allocated buffer with 0 */
- memset(btif_media_cb.encoder.as16PcmBuffer, 0, blocm_x_subband
- * btif_media_cb.encoder.s16NumOfChannels);
+ memset(btif_media_cb.encoder.as32PcmBuffer, 0, blocm_x_subband
+ * btif_media_cb.encoder.s16NumOfChannels * 2);
/* Read PCM data and upsample them if needed */
if (btif_media_aa_read_feeding(UIPC_CH_ID_AV_AUDIO))
{
+ size_t frames = blocm_x_subband * btif_media_cb.encoder.s16NumOfChannels;
+ 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);
SBC_Encoder(&(btif_media_cb.encoder));
/* Update SBC frame length */
void btif_media_send_reset_vendor_state()
{
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_RESET_VS_STATE;
if (btif_media_cmd_msg_queue != NULL)
void btif_media_on_start_vendor_command()
{
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_START_VS_CMD;
if (btif_media_cmd_msg_queue != NULL)
void btif_media_on_stop_vendor_command()
{
- BT_HDR *p_buf = osi_malloc(sizeof(BT_HDR));
+ BT_HDR *p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
APPL_TRACE_IMP("btif_media_on_stop_vendor_command");
p_buf->event = BTIF_MEDIA_STOP_VS_CMD;
}
APPL_TRACE_IMP("VS_QHCI_START_A2DP_MEDIA sent with error code: %u", status);
- p_buf = osi_malloc(sizeof(BT_HDR));
+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
if (!status)
p_buf->event = BTIF_MEDIA_VS_A2DP_START_SUCCESS;
}
APPL_TRACE_IMP("VS_QHCI_STOP_A2DP_MEDIA sent with error code: %u", status);
- p_buf = osi_malloc(sizeof(BT_HDR));
+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
if (!status)
p_buf->event = BTIF_MEDIA_VS_A2DP_STOP_SUCCESS;
if (!status)
{
- p_buf = osi_malloc(sizeof(BT_HDR));
+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_VS_A2DP_SELECTED_CODEC_SUCCESS;
if (btif_media_cmd_msg_queue != NULL)
fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
BOOLEAN btif_media_send_vendor_selected_codec()
{
- UINT8 param[12], codec_type = A2DP_CODEC_SBC;//bta_av_get_current_code();
+ UINT8 param[12], codec_type = A2DP_CODEC_SBC;
UINT16 index = 0;
- codec_type = bta_av_get_current_codec();
- if (codec_type == 0xFF)
+ codec_type = bta_av_co_get_current_codec();
+ if (codec_type == A2D_NON_A2DP_MEDIA_CT)
codec_type = A2DP_CODEC_APTX;
APPL_TRACE_IMP("btif_media_send_selected_codec: codec: %d", codec_type);
if (!status)
{
- p_buf = osi_malloc(sizeof(BT_HDR));
+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_VS_A2DP_TRANSPORT_CFG_SUCCESS;
if (btif_media_cmd_msg_queue != NULL)
fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
BOOLEAN btif_media_send_vendor_transport_cfg()
{
UINT8 param[3];
- UINT8 codec_type = bta_av_get_current_codec();
+ UINT8 codec_type = bta_av_co_get_current_codec();
UINT8 stream_type;
APPL_TRACE_IMP("btif_media_send_vendor_transport_cfg: codec: %d", codec_type);
stream_type = codec_type;
- if (codec_type == 0xFF)
+ if (codec_type == A2D_NON_A2DP_MEDIA_CT)
stream_type = A2DP_TRANSPORT_STREAM_TYPE_APTX;
param[0] = VS_QHCI_A2DP_TRANSPORT_CONFIGURATION;
param[1] = A2DP_TRANSPORT_TYPE_SLIMBUS;
if (!status)
{
- p_buf = osi_malloc(sizeof(BT_HDR));
+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_VS_A2DP_MEDIA_CHNL_CFG_SUCCESS;
if (btif_media_cmd_msg_queue != NULL)
fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
if (!status)
{
- p_buf = osi_malloc(sizeof(BT_HDR));
+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_VS_A2DP_WRITE_SBC_CFG_SUCCESS;
if (btif_media_cmd_msg_queue != NULL)
fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
if (!status)
{
- p_buf = osi_malloc(sizeof(BT_HDR));
+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_VS_A2DP_PREF_BIT_RATE_SUCCESS;
if (btif_media_cmd_msg_queue != NULL)
fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
if (!status)
{
- p_buf = osi_malloc(sizeof(BT_HDR));
+ p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTIF_MEDIA_VS_A2DP_SET_SCMST_HDR_SUCCESS;
if (btif_media_cmd_msg_queue != NULL)
fixed_queue_enqueue(btif_media_cmd_msg_queue, p_buf);
extern BOOLEAN btif_av_is_device_connected(BD_ADDR address);
extern void btif_av_trigger_dual_handoff(BOOLEAN handoff, BD_ADDR address);
extern BOOLEAN btif_hf_is_call_idle();
-extern BOOLEAN btif_av_get_multicast_state();
extern BOOLEAN btif_av_is_current_device(BD_ADDR address);
extern UINT16 btif_av_get_num_connected_devices(void);
extern UINT16 btif_av_get_num_playing_devices(void);
SINT16 *ps16PcmBuffer;
#else
SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
+ SINT32 as32PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
#endif
SINT16 s16ScartchMemForBitAlloc[16];
-/******************************************************************************
+ /******************************************************************************
* Copyright (c) 2016, The Linux Foundation. All rights reserved.
*
* Not a contribution.
#endif
#ifndef BTIF_A2DP_SRC_BIT_DEPTH
-#define BTIF_A2DP_SRC_BIT_DEPTH 16
+#define BTIF_A2DP_SRC_BIT_DEPTH 32
#endif
#ifndef BTIF_A2DP_SRC_NUM_CHANNELS
*/
#ifndef AVDT_NUM_SEPS
#if defined(AAC_ENCODER_INCLUDED) && (AAC_ENCODER_INCLUDED == TRUE)
-#define AVDT_NUM_SEPS 7
+#define AVDT_NUM_SEPS 9
#else
-#define AVDT_NUM_SEPS 5
+#define AVDT_NUM_SEPS 7
#endif
#endif
$(LOCAL_PATH)/../utils/include \
$(bluetooth_C_INCLUDES) \
external/tinyxml2 \
- external/zlib
+ external/zlib \
+ $(call include-path-for, audio-utils)
LOCAL_SHARED_LIBRARIES := \
libcutils \
libprotobuf-cpp-full \
libmedia \
libutils \
- libchrome
+ libchrome \
+ libaudioutils
LOCAL_STATIC_LIBRARIES := \
libtinyxml2 \
./a2dp/a2d_api.c \
./a2dp/a2d_sbc.c \
./a2dp/a2d_aptx.c \
+ ./a2dp/a2d_aptx_hd.c \
./a2dp/a2d_aac.c \
./avrc/avrc_api.c \
./avrc/avrc_sdp.c \
#include "a2d_api.h"
#include "a2d_int.h"
#include "a2d_aptx.h"
+#include "a2d_aptx_hd.h"
#include <utils/Log.h>
const char* A2D_APTX_SCHED_LIB_NAME = "libaptXScheduler.so";
if (isA2dAptXEnabled && A2dAptXSchedLibHandle)
{
- // remove aptX thread
- if (A2d_aptx_thread)
- {
- A2D_aptx_sched_stop();
- thread_free(A2d_aptx_thread);
- A2d_aptx_thread = NULL;
- }
-
- A2D_aptx_encoder_deinit();
- dlclose(A2dAptXSchedLibHandle);
- A2dAptXSchedLibHandle = NULL;
- isA2dAptXEnabled = false;
+ A2D_aptx_encoder_deinit();
+ isA2dAptXEnabled = false;
+ }
+
+ return;
+}
+
+/*******************************************************************************
+**
+** Function A2D_close_aptX
+**
+** Description This function close aptX
+**
+** Returns Nothing
+**
+*******************************************************************************/
+void A2D_close_aptX(void)
+{
+ A2D_TRACE_DEBUG("%s", __func__);
+
+ if (A2dAptXSchedLibHandle)
+ {
+ // remove aptX thread
+ if (A2d_aptx_thread)
+ {
+ A2D_aptx_sched_stop();
+ thread_free(A2d_aptx_thread);
+ A2d_aptx_thread = NULL;
+ }
}
+ // de-initialize aptX HD
+ A2D_deinit_aptX_HD();
+
+ // de-initialize aptX
+ A2D_deinit_aptX();
+
+ dlclose(A2dAptXSchedLibHandle);
+ A2dAptXSchedLibHandle = NULL;
+
return;
}
--- /dev/null
+/******************************************************************************
+
+ Copyright (c) 2016, The Linux Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ******************************************************************************/
+/******************************************************************************
+
+ Utility functions to help build and parse the aptX HD Codec Information
+ Element and Media Payload.
+
+******************************************************************************/
+
+#include "bt_target.h"
+
+#include <string.h>
+#include <dlfcn.h>
+#include "osi/include/thread.h"
+#include "bt_utils.h"
+#include "a2d_api.h"
+#include "a2d_int.h"
+#include "a2d_aptx.h"
+#include "a2d_aptx_hd.h"
+#include <utils/Log.h>
+
+
+BOOLEAN isA2dAptXHdEnabled = FALSE;
+
+int (*A2D_aptx_hd_encoder_init)(void);
+void (*A2D_aptx_hd_encoder_deinit)(void);
+
+/******************************************************************************
+**
+** Function A2D_BldAptx_hdInfo
+**
+******************************************************************************/
+UINT8 A2D_BldAptx_hdInfo(UINT8 media_type, tA2D_APTX_HD_CIE *p_ie, UINT8 *p_result)
+{
+ A2D_TRACE_API("%s: - MediaType:%d", __func__, media_type);
+
+ UINT8 status = 0;
+ status = A2D_SUCCESS;
+ *p_result++ = A2D_APTX_HD_CODEC_LEN;
+ *p_result++ = media_type;
+ *p_result++ = A2D_NON_A2DP_MEDIA_CT;
+ *p_result++ = (UINT8)(p_ie->vendorId & 0x000000FF);
+ *p_result++ = (UINT8)(p_ie->vendorId & 0x0000FF00)>> 8;
+ *p_result++ = (UINT8)(p_ie->vendorId & 0x00FF0000)>> 16;
+ *p_result++ = (UINT8)(p_ie->vendorId & 0xFF000000)>> 24;
+ *p_result++ = (UINT8)(p_ie->codecId & 0x00FF);
+ *p_result++ = (UINT8)(p_ie->codecId & 0xFF00) >> 8;
+ *p_result++ = p_ie->sampleRate | p_ie->channelMode;
+ *p_result++ = p_ie->acl_sprint_reserved0;
+ *p_result++ = p_ie->acl_sprint_reserved1;
+ *p_result++ = p_ie->acl_sprint_reserved2;
+ *p_result++ = p_ie->acl_sprint_reserved3;
+ return status;
+}
+
+/******************************************************************************
+**
+** Function A2D_ParsAptx_hdInfo
+**
+******************************************************************************/
+tA2D_STATUS A2D_ParsAptx_hdInfo(tA2D_APTX_HD_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps)
+{
+ tA2D_STATUS status;
+ UINT8 losc;
+ UINT8 mt;
+
+ A2D_TRACE_API("%s: - MediaType:%d", __func__, for_caps);
+
+ if (p_ie == NULL || p_info == NULL)
+ {
+ A2D_TRACE_ERROR("A2D_ParsAptx_hdInfo - Invalid Params");
+ status = A2D_INVALID_PARAMS;
+ }
+ else
+ {
+ losc = *p_info++;
+ mt = *p_info++;
+ A2D_TRACE_DEBUG("%s: losc %d, mt %02x", __func__, losc, mt);
+
+ /* If the function is called for the wrong Media Type or Media Codec Type */
+ if (losc != A2D_APTX_HD_CODEC_LEN || *p_info != A2D_NON_A2DP_MEDIA_CT) {
+ A2D_TRACE_ERROR("%s: wrong media type %02x", __func__, *p_info);
+ status = A2D_WRONG_CODEC;
+ }
+ else
+ {
+ p_info++;
+ p_ie->vendorId = (*p_info & 0x000000FF) |
+ (*(p_info+1) << 8 & 0x0000FF00) |
+ (*(p_info+2) << 16 & 0x00FF0000) |
+ (*(p_info+3) << 24 & 0xFF000000);
+ p_info = p_info+4;
+ p_ie->codecId = (*p_info & 0x00FF) | (*(p_info+1) << 8 & 0xFF00);
+ p_info = p_info+2;
+ p_ie->channelMode= *p_info & 0x0F;
+ p_ie->sampleRate = *p_info & 0xF0;
+ p_info = p_info+1;
+ p_ie->acl_sprint_reserved0 = *(p_info ++);
+ p_ie->acl_sprint_reserved1 = *(p_info ++);
+ p_ie->acl_sprint_reserved2 = *(p_info ++);
+ p_ie->acl_sprint_reserved3 = *(p_info ++);
+
+ status = A2D_SUCCESS;
+
+ if (for_caps == FALSE)
+ {
+ if (A2D_BitsSet(p_ie->sampleRate) != A2D_SET_ONE_BIT)
+ status = A2D_BAD_SAMP_FREQ;
+ if (A2D_BitsSet(p_ie->channelMode) != A2D_SET_ONE_BIT)
+ status = A2D_BAD_CH_MODE;
+ }
+ }
+ }
+ return status;
+}
+
+/*******************************************************************************
+**
+** Function a2d_av_aptx_hd_cfg_in_cap
+**
+** Description This function checks whether an aptX HD codec configuration
+** is allowable for the given codec capabilities.
+**
+** Returns 0 if ok, nonzero if error.
+**
+*******************************************************************************/
+UINT8 a2d_av_aptx_hd_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_HD_CIE *p_cap)
+{
+ UINT8 status = 0;
+ tA2D_APTX_HD_CIE cfg_cie;
+
+ A2D_TRACE_API("%s", __func__);
+
+ /* parse configuration */
+ if ((status = A2D_ParsAptx_hdInfo(&cfg_cie, p_cfg, FALSE)) != 0)
+ {
+ A2D_TRACE_ERROR("%s: aptX HD parse failed", __func__);
+ return status;
+ }
+
+ /* verify that each parameter is in range */
+
+ /* sampling frequency */
+ if ((cfg_cie.sampleRate & p_cap->sampleRate) == 0)
+ status = A2D_NS_SAMP_FREQ;
+ /* channel mode */
+ else if ((cfg_cie.channelMode & p_cap->channelMode) == 0)
+ status = A2D_NS_CH_MODE;
+
+ return status;
+}
+
+/*******************************************************************************
+**
+** Function A2D_check_and_init_aptX_HD
+**
+** Description This function checks if all the libraries required for
+** aptX HD are present and needed function pointers are resolved
+**
+** Returns returns true if aptX HD codec initialization succeeds
+**
+*******************************************************************************/
+BOOLEAN A2D_check_and_init_aptX_HD(void)
+{
+ A2D_TRACE_DEBUG("%s", __func__);
+
+ if (isA2dAptXEnabled && A2dAptXSchedLibHandle)
+ {
+ A2D_aptx_hd_encoder_init = (int (*)(void))dlsym(A2dAptXSchedLibHandle,
+ "aptx_hd_encoder_init");
+ if (!A2D_aptx_hd_encoder_init)
+ {
+ A2D_TRACE_ERROR("%s: aptX HD encoder init missing", __func__);
+ goto error_exit;
+ }
+
+ A2D_aptx_hd_encoder_deinit = (void (*)(void))dlsym(A2dAptXSchedLibHandle,
+ "aptx_hd_encoder_deinit");
+ if (!A2D_aptx_hd_encoder_deinit)
+ {
+ A2D_TRACE_ERROR("%s: aptX HD encoder deinit missing", __func__);
+ goto error_exit;
+ }
+
+ if (A2D_aptx_hd_encoder_init())
+ {
+ A2D_TRACE_ERROR("%s: aptX HD encoder init failed - %s", __func__, dlerror());
+ goto error_exit;
+ }
+ } else {
+ A2D_TRACE_ERROR("%s: isA2dAptXEnabled = false", __func__);
+ goto error_exit;
+ }
+ isA2dAptXHdEnabled = true;
+ return isA2dAptXHdEnabled;
+
+ error_exit:;
+ isA2dAptXHdEnabled = false;
+ return isA2dAptXHdEnabled;
+
+}
+
+/*******************************************************************************
+**
+** Function A2D_deinit_aptX_HD
+**
+** Description This function de-initialized aptX HD
+**
+** Returns Nothing
+**
+*******************************************************************************/
+void A2D_deinit_aptX_HD(void)
+{
+ A2D_TRACE_DEBUG("%s", __func__);
+
+ if (isA2dAptXHdEnabled && isA2dAptXEnabled && A2dAptXSchedLibHandle)
+ {
+ A2D_aptx_hd_encoder_deinit();
+ isA2dAptXHdEnabled = false;
+ }
+
+ return;
+}
AVDT_OPEN_CFM_EVT /* AVDT_OPEN_INT */
};
-extern UINT8* bta_av_get_current_codecInfo();
-#define NON_A2DP_MEDIA_CT 0xff
/*******************************************************************************
**
** Function avdt_scb_gen_ssrc
}
osi_free_and_reset((void **)&p_scb->p_pkt);
- /* build a media packet if the codec type is not aptX */
-#if defined(BTA_AV_CO_CP_SCMS_T) && (BTA_AV_CO_CP_SCMS_T == TRUE)
-#else
- if (p_data->apiwrite.m_pt != NON_A2DP_MEDIA_CT)
-#endif
+ /* build a media packet */
+ /* Add RTP header if required */
+ if ( !(p_data->apiwrite.opt & AVDT_DATA_OPT_NO_RTP) )
{
ssrc = avdt_scb_gen_ssrc(p_scb);
#define A2D_BAD_CP_FORMAT 0xE1 /* The format of Content Protection Service Capability/Content Protection Scheme Dependent Data is not correct. */
-#define A2D_NON_A2DP_MEDIA_CT 0xff /* NON A2DP media codec */
+#define A2D_NON_A2DP_MEDIA_CT 0xFF /* NON A2DP media codec */
typedef UINT8 tA2D_STATUS;
typedef enum {
APTX_CODEC_NONE=0,
APTX_CODEC,
- APTX_CODEC_LL,
- APTX_CODEC_HD,
+ APTX_HD_CODEC,
} A2D_AptXCodecType;
typedef void (*A2D_AptXThreadFn)(void *context);
extern UINT8 a2d_av_aptx_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_CIE *p_cap);
extern BOOLEAN A2D_check_and_init_aptX();
extern void A2D_deinit_aptX();
+extern void A2D_close_aptX();
#ifdef __cplusplus
}
--- /dev/null
+/******************************************************************************
+
+ Copyright (c) 2016, The Linux Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ******************************************************************************/
+/******************************************************************************
+ interface to aptX HD codec
+ ******************************************************************************/
+#ifndef A2D_APTX_HD_H
+#define A2D_APTX_HD_H
+
+/* aptX HD codec specific settings*/
+#define A2D_APTX_HD_CODEC_LEN 13
+
+#define A2D_APTX_HD_VENDOR_ID (0x000000D7)
+#define A2D_APTX_HD_CODEC_ID_BLUETOOTH ((UINT16) 0x0024)
+#define A2D_APTX_HD_SAMPLERATE_44100 (0x20)
+#define A2D_APTX_HD_SAMPLERATE_48000 (0x10)
+#define A2D_APTX_HD_CHANNELS_STEREO (0x02)
+#define A2D_APTX_HD_CHANNELS_MONO (0x01)
+#define A2D_APTX_HD_ACL_SPRINT_RESERVED0 (0x00)
+#define A2D_APTX_HD_ACL_SPRINT_RESERVED1 (0x00)
+#define A2D_APTX_HD_ACL_SPRINT_RESERVED2 (0x00)
+#define A2D_APTX_HD_ACL_SPRINT_RESERVED3 (0x00)
+#define A2D_APTX_HD_OTHER_FEATURES_NONE (0x00000000)
+#define A2D_APTX_HD_AV_AUDIO (0x00)
+#define A2D_APTX_HD_CODEC_ID (0xff)
+#define A2D_APTX_HD_CHANNEL (0x0001)
+#define A2D_APTX_HD_SAMPLERATE (0x22)
+
+/*****************************************************************************
+** Type Definitions
+*****************************************************************************/
+
+typedef struct {
+ UINT32 vendorId;
+ UINT16 codecId; /* Codec ID for aptX HD */
+ UINT8 sampleRate; /* Sampling Frequency */
+ UINT8 channelMode; /* STEREO/DUAL/MONO */
+ UINT8 acl_sprint_reserved0;
+ UINT8 acl_sprint_reserved1;
+ UINT8 acl_sprint_reserved2;
+ UINT8 acl_sprint_reserved3;
+} tA2D_APTX_HD_CIE;
+
+typedef struct {
+ INT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
+ INT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
+ UINT16 u16BitRate;
+ UINT16 *ps16NextPcmBuffer;
+ UINT8 *pu8Packet;
+ UINT8 *pu8NextPacket;
+ UINT16 u16PacketLength;
+ void* encoder;
+} A2D_APTX_HD_ENC_PARAMS;
+
+extern BOOLEAN isA2dAptXHdEnabled;
+
+/*****************************************************************************
+** external function declarations
+*****************************************************************************/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+extern UINT8 A2D_BldAptx_hdInfo(UINT8 media_type, tA2D_APTX_HD_CIE *p_ie,
+ UINT8 *p_result);
+extern UINT8 A2D_ParsAptx_hdInfo(tA2D_APTX_HD_CIE *p_ie, UINT8 *p_info,
+ BOOLEAN for_caps);
+extern int (*A2D_aptx_hd_encoder_init)(void);
+extern void (*A2D_aptx_hd_encoder_deinit)(void);
+extern UINT8 a2d_av_aptx_hd_cfg_in_cap(UINT8 *p_cfg, tA2D_APTX_HD_CIE *p_cap);
+extern BOOLEAN A2D_check_and_init_aptX_HD();
+extern void A2D_deinit_aptX_HD();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* A2D_APTX_HD_H */