replace common qcom sources with samsung ones
This commit is contained in:
98
qcom/opensource/pal/plugins/codecs/Android.mk
Normal file
98
qcom/opensource/pal/plugins/codecs/Android.mk
Normal file
@@ -0,0 +1,98 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
LOCAL_CFLAGS += -Wall -Werror
|
||||
|
||||
#--------------------------------------------
|
||||
# Build bt_bundle LIB
|
||||
#--------------------------------------------
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
ifeq (true,$(call spf_check,SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD,TRUE))
|
||||
ifeq ($(BOARD_HAVE_BLUETOOTH_QCOM),true)
|
||||
LOCAL_CFLAGS += -DQCA_OFFLOAD
|
||||
endif #BOARD_HAVE_BLUETOOTH_QCOM
|
||||
endif
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
bt_base.c \
|
||||
bt_bundle.c
|
||||
|
||||
LOCAL_CFLAGS += -O2 -fvisibility=hidden
|
||||
|
||||
ifeq ($(strip $(AUDIO_FEATURE_ENABLE_BT_A2DP_LPI)),true)
|
||||
LOCAL_CFLAGS += -DBT_A2DP_LPI_ENABLED
|
||||
endif
|
||||
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libcutils \
|
||||
liblog \
|
||||
libdl
|
||||
|
||||
LOCAL_C_INCLUDES += $(TOP)/system/media/audio/include
|
||||
|
||||
LOCAL_HEADER_LIBRARIES := \
|
||||
libspf-headers \
|
||||
libarosal_headers
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE := lib_bt_bundle
|
||||
LOCAL_MODULE_OWNER := qti
|
||||
LOCAL_VENDOR_MODULE := true
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
#--------------------------------------------
|
||||
# Build bt_aptx LIB
|
||||
#--------------------------------------------
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
bt_base.c \
|
||||
bt_aptx.c
|
||||
|
||||
LOCAL_CFLAGS += -O2 -fvisibility=hidden
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libcutils \
|
||||
liblog \
|
||||
libdl
|
||||
|
||||
LOCAL_C_INCLUDES += $(TOP)/system/media/audio/include
|
||||
|
||||
LOCAL_HEADER_LIBRARIES := \
|
||||
libspf-headers \
|
||||
libarosal_headers
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE := lib_bt_aptx
|
||||
LOCAL_MODULE_OWNER := qti
|
||||
LOCAL_VENDOR_MODULE := true
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
#--------------------------------------------
|
||||
# Build bt_ble LIB
|
||||
#--------------------------------------------
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
bt_base.c \
|
||||
bt_ble.c
|
||||
|
||||
LOCAL_CFLAGS += -O2 -fvisibility=hidden
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libcutils \
|
||||
liblog \
|
||||
libdl
|
||||
|
||||
LOCAL_C_INCLUDES += $(TOP)/system/media/audio/include
|
||||
|
||||
LOCAL_HEADER_LIBRARIES := \
|
||||
libspf-headers \
|
||||
libarosal_headers
|
||||
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_MODULE := lib_bt_ble
|
||||
LOCAL_MODULE_OWNER := qti
|
||||
LOCAL_VENDOR_MODULE := true
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
684
qcom/opensource/pal/plugins/codecs/bt_aptx.c
Normal file
684
qcom/opensource/pal/plugins/codecs/bt_aptx.c
Normal file
@@ -0,0 +1,684 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "PAL: bt_aptx"
|
||||
//#define LOG_NDEBUG 0
|
||||
|
||||
#include <log/log.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "bt_aptx.h"
|
||||
#include "bt_base.h"
|
||||
#include <aptx_classic_encoder_api.h>
|
||||
#include <aptx_hd_encoder_api.h>
|
||||
#include <aptx_adaptive_encoder_api.h>
|
||||
#include <aptx_adaptive_swb_encoder_api.h>
|
||||
#include <aptx_adaptive_swb_decoder_api.h>
|
||||
|
||||
typedef enum {
|
||||
SWAP_DISABLE,
|
||||
SWAP_ENABLE,
|
||||
} swap_status_t;
|
||||
|
||||
#define DEFAULT_FADE_DURATION 255
|
||||
|
||||
static int aptx_pack_enc_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
audio_aptx_encoder_config_t *aptx_bt_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
int ret = 0, num_blks = 1, i = 0;
|
||||
custom_block_t *blk[1] = {NULL};
|
||||
|
||||
ALOGV("%s", __func__);
|
||||
if ((src == NULL) || (dst == NULL)) {
|
||||
ALOGE("%s: invalid input parameters", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
aptx_bt_cfg = (audio_aptx_encoder_config_t *)src;
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
enc_payload->bit_format = aptx_bt_cfg->bits_per_sample;
|
||||
enc_payload->sample_rate = aptx_bt_cfg->sampling_rate;
|
||||
enc_payload->channel_count = aptx_bt_cfg->channels;
|
||||
enc_payload->num_blks = num_blks;
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_REAL_MODULE_ID */
|
||||
ret = bt_base_populate_real_module_id(blk[0], MODULE_ID_APTX_CLASSIC_ENC);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int aptx_dual_mono_pack_enc_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
audio_aptx_dual_mono_config_t *aptx_dm_bt_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
param_id_aptx_classic_sync_mode_payload_t *aptx_sync_mode = NULL;
|
||||
int ret = 0, num_blks = 2, i = 0;
|
||||
custom_block_t *blk[2] = {NULL};
|
||||
|
||||
ALOGV("%s", __func__);
|
||||
if ((src == NULL) || (dst == NULL)) {
|
||||
ALOGE("%s: invalid input parameters", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
aptx_dm_bt_cfg = (audio_aptx_dual_mono_config_t*)src;
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
enc_payload->bit_format = ENCODER_BIT_FORMAT_DEFAULT;
|
||||
enc_payload->sample_rate = aptx_dm_bt_cfg->sampling_rate;
|
||||
enc_payload->channel_count = aptx_dm_bt_cfg->channels;
|
||||
enc_payload->num_blks = num_blks;
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_REAL_MODULE_ID */
|
||||
ret = bt_base_populate_real_module_id(blk[0], MODULE_ID_APTX_CLASSIC_ENC);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
/* populate payload for PARAM_ID_APTX_CLASSIC_SET_SYNC_MODE */
|
||||
aptx_sync_mode = (param_id_aptx_classic_sync_mode_payload_t*)calloc(1,
|
||||
sizeof(param_id_aptx_classic_sync_mode_payload_t));
|
||||
if (aptx_sync_mode == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
|
||||
/* Sync mode should be DUAL AUTOSYNC (1) for TWS+ */
|
||||
aptx_sync_mode->sync_mode = aptx_dm_bt_cfg->sync_mode;
|
||||
if (enc_payload->channel_count == 1)
|
||||
aptx_sync_mode->startup_mode = 1; /* (L + R)/2 input */
|
||||
else
|
||||
aptx_sync_mode->startup_mode = 0; /* L and R separate input */
|
||||
|
||||
aptx_sync_mode->cvr_fade_duration = DEFAULT_FADE_DURATION;
|
||||
|
||||
ret = bt_base_populate_enc_cmn_param(blk[1], PARAM_ID_APTX_CLASSIC_SET_SYNC_MODE,
|
||||
aptx_sync_mode, sizeof(param_id_aptx_classic_sync_mode_payload_t));
|
||||
free(aptx_sync_mode);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
enc_payload->blocks[1] = blk[1];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int bt_apt_ad_populate_enc_audiosrc_info(custom_block_t *blk, uint16_t sample_rate)
|
||||
{
|
||||
struct param_id_aptx_adaptive_enc_original_samplerate_t *param = NULL;
|
||||
|
||||
blk->param_id = PARAM_ID_APTX_ADAPTIVE_ENC_AUDIOSRC_INFO;
|
||||
blk->payload_sz = sizeof(struct param_id_aptx_adaptive_enc_original_samplerate_t);
|
||||
blk->payload = calloc(1, blk->payload_sz);
|
||||
if (!blk->payload) {
|
||||
blk->payload_sz = 0;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
param = (struct param_id_aptx_adaptive_enc_original_samplerate_t*) blk->payload;
|
||||
param->original_sample_rate = sample_rate;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int aptx_ad_pack_enc_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
audio_aptx_ad_encoder_config_t *aptx_ad_bt_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
struct param_id_aptx_adaptive_enc_init_t *enc_init = NULL;
|
||||
struct param_id_aptx_adaptive_enc_profile_t *enc_profile = NULL;
|
||||
int ret = 0, num_blks = 3, i = 0;
|
||||
custom_block_t *blk[3] = {NULL};
|
||||
|
||||
ALOGV("%s", __func__);
|
||||
if ((src == NULL) || (dst == NULL)) {
|
||||
ALOGE("%s: invalid input parameters", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
aptx_ad_bt_cfg = (audio_aptx_ad_encoder_config_t*)src;
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
/* ABR is always enabled for APTx Adaptive */
|
||||
enc_payload->is_abr_enabled = true;
|
||||
enc_payload->bit_format = aptx_ad_bt_cfg->bits_per_sample;
|
||||
enc_payload->num_blks = num_blks;
|
||||
|
||||
switch(aptx_ad_bt_cfg->sampling_rate) {
|
||||
case APTX_AD_SR_UNCHANGED:
|
||||
case APTX_AD_48:
|
||||
default:
|
||||
enc_payload->sample_rate = SAMPLING_RATE_48K;
|
||||
break;
|
||||
case APTX_AD_44_1:
|
||||
enc_payload->sample_rate = SAMPLING_RATE_44K;
|
||||
break;
|
||||
case APTX_AD_96:
|
||||
enc_payload->sample_rate = SAMPLING_RATE_96K;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (aptx_ad_bt_cfg->channel_mode) {
|
||||
case APTX_AD_CHANNEL_MONO:
|
||||
enc_payload->channel_count = 1;
|
||||
break;
|
||||
default:
|
||||
enc_payload->channel_count = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_APTX_ADAPTIVE_ENC_INIT */
|
||||
enc_init = (struct param_id_aptx_adaptive_enc_init_t*)calloc(1, sizeof(struct param_id_aptx_adaptive_enc_init_t));
|
||||
if (enc_init == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
enc_init->sampleRate = aptx_ad_bt_cfg->sampling_rate;
|
||||
enc_init->mtulink0 = aptx_ad_bt_cfg->mtu;
|
||||
enc_init->channelMode0 = aptx_ad_bt_cfg->channel_mode;
|
||||
enc_init->minsinkBufLL = aptx_ad_bt_cfg->min_sink_modeA;
|
||||
enc_init->maxsinkBufLL = aptx_ad_bt_cfg->max_sink_modeA;
|
||||
enc_init->minsinkBufHQ = aptx_ad_bt_cfg->min_sink_modeB;
|
||||
enc_init->maxsinkBufHQ = aptx_ad_bt_cfg->max_sink_modeB;
|
||||
enc_init->minsinkBufTws = aptx_ad_bt_cfg->min_sink_modeC;
|
||||
enc_init->maxsinkBufTws = aptx_ad_bt_cfg->max_sink_modeC;
|
||||
enc_init->profile = aptx_ad_bt_cfg->encoder_mode;
|
||||
enc_init->twsplusDualMonoMode = aptx_ad_bt_cfg->input_mode;
|
||||
enc_init->twsplusFadeDuration = aptx_ad_bt_cfg->fade_duration;
|
||||
for (int i = 0; i < sizeof(enc_init->sinkCapability); i++)
|
||||
enc_init->sinkCapability[i] = aptx_ad_bt_cfg->sink_cap[i];
|
||||
|
||||
ret = bt_base_populate_enc_cmn_param(blk[0], PARAM_ID_APTX_ADAPTIVE_ENC_INIT,
|
||||
enc_init, sizeof(struct param_id_aptx_adaptive_enc_init_t));
|
||||
free(enc_init);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
/* populate payload for PARAM_ID_APTX_ADAPTIVE_ENC_PROFILE */
|
||||
enc_profile = (struct param_id_aptx_adaptive_enc_profile_t*)calloc(1, sizeof(struct param_id_aptx_adaptive_enc_profile_t));
|
||||
if (enc_profile == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
enc_profile->primprofile = 0;
|
||||
enc_profile->secprofile = 0;
|
||||
enc_profile->LLModeLatTarget0 = aptx_ad_bt_cfg->TTP_modeA_low;
|
||||
enc_profile->LLModeLatTarget1 = aptx_ad_bt_cfg->TTP_modeA_high;
|
||||
enc_profile->hQLatTarget0 = aptx_ad_bt_cfg->TTP_modeB_low;
|
||||
enc_profile->hQLatTarget1 = aptx_ad_bt_cfg->TTP_modeB_high;
|
||||
|
||||
ret = bt_base_populate_enc_cmn_param(blk[1], PARAM_ID_APTX_ADAPTIVE_ENC_PROFILE,
|
||||
enc_profile, sizeof(struct param_id_aptx_adaptive_enc_profile_t));
|
||||
free(enc_profile);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
/* populate payload for PARAM_ID_APTX_ADAPTIVE_ENC_AUDIOSRC_INFO */
|
||||
//TODO: hard coded sample rate as 0 - same as system setting
|
||||
ret = bt_apt_ad_populate_enc_audiosrc_info(blk[2], 0);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
enc_payload->blocks[1] = blk[1];
|
||||
enc_payload->blocks[2] = blk[2];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int aptx_hd_pack_enc_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
audio_aptx_hd_encoder_config_t *aptx_hd_bt_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
int ret = 0, num_blks = 1, i = 0;
|
||||
custom_block_t *blk[1] = {NULL};
|
||||
|
||||
ALOGV("%s", __func__);
|
||||
if ((src == NULL) || (dst == NULL)) {
|
||||
ALOGE("%s: invalid input parameters", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
aptx_hd_bt_cfg = (audio_aptx_hd_encoder_config_t*)src;
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
enc_payload->bit_format = aptx_hd_bt_cfg->bits_per_sample;
|
||||
enc_payload->sample_rate = aptx_hd_bt_cfg->sampling_rate;
|
||||
enc_payload->channel_count = aptx_hd_bt_cfg->channels;
|
||||
enc_payload->num_blks = num_blks;
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_REAL_MODULE_ID */
|
||||
ret = bt_base_populate_real_module_id(blk[0], MODULE_ID_APTX_HD_ENC);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int aptx_ad_speech_pack_enc_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
param_id_aptx_adaptive_speech_enc_init_t *aptx_ad_speech_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
uint32_t *mode;
|
||||
int ret = 0, num_blks = 1, i = 0;
|
||||
custom_block_t *blk[1] = {NULL};
|
||||
|
||||
ALOGV("%s", __func__);
|
||||
if ((src == NULL) || (dst == NULL)) {
|
||||
ALOGE("%s: invalid input parameters", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mode = (uint32_t *)src;
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
enc_payload->bit_format = ENCODER_BIT_FORMAT_DEFAULT;
|
||||
enc_payload->sample_rate = SAMPLING_RATE_32K;
|
||||
enc_payload->channel_count = CH_MONO;
|
||||
enc_payload->num_blks = num_blks;
|
||||
enc_payload->is_abr_enabled = true;
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_APTX_ADAPTIVE_SPEECH_ENC_INIT */
|
||||
aptx_ad_speech_cfg = (param_id_aptx_adaptive_speech_enc_init_t *)calloc(1,
|
||||
sizeof(param_id_aptx_adaptive_speech_enc_init_t));
|
||||
if (aptx_ad_speech_cfg == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
aptx_ad_speech_cfg->speechMode = *mode;
|
||||
aptx_ad_speech_cfg->byteSwap = SWAP_ENABLE;
|
||||
|
||||
ret = bt_base_populate_enc_cmn_param(blk[0], PARAM_ID_APTX_ADAPTIVE_SPEECH_ENC_INIT,
|
||||
aptx_ad_speech_cfg, sizeof(param_id_aptx_adaptive_speech_enc_init_t));
|
||||
free(aptx_ad_speech_cfg);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int aptx_ad_speech_pack_dec_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
param_id_aptx_adaptive_speech_dec_init_t *aptx_ad_speech_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
uint32_t *mode;
|
||||
int ret = 0, num_blks = 1, i = 0;
|
||||
custom_block_t *blk[1] = {NULL};
|
||||
|
||||
ALOGV("%s", __func__);
|
||||
if ((src == NULL) || (dst == NULL)) {
|
||||
ALOGE("%s: invalid input parameters", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mode = (uint32_t *)src;
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
enc_payload->bit_format = ENCODER_BIT_FORMAT_DEFAULT;
|
||||
enc_payload->sample_rate = SAMPLING_RATE_32K;
|
||||
enc_payload->channel_count = CH_MONO;
|
||||
enc_payload->num_blks = num_blks;
|
||||
enc_payload->is_abr_enabled = true;
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_APTX_ADAPTIVE_SPEECH_DEC_INIT */
|
||||
aptx_ad_speech_cfg = (param_id_aptx_adaptive_speech_dec_init_t *)calloc(1,
|
||||
sizeof(param_id_aptx_adaptive_speech_dec_init_t));
|
||||
if (aptx_ad_speech_cfg == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
aptx_ad_speech_cfg->speechMode = *mode;
|
||||
aptx_ad_speech_cfg->byteSwap = SWAP_ENABLE;
|
||||
|
||||
ret = bt_base_populate_enc_cmn_param(blk[0], PARAM_ID_APTX_ADAPTIVE_SPEECH_DEC_INIT,
|
||||
aptx_ad_speech_cfg, sizeof(param_id_aptx_adaptive_speech_dec_init_t));
|
||||
free(aptx_ad_speech_cfg);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bt_aptx_populate_payload(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
config_fn_t config_fn = NULL;
|
||||
|
||||
if (codec->payload)
|
||||
free(codec->payload);
|
||||
|
||||
switch (codec->codecFmt) {
|
||||
case CODEC_TYPE_APTX:
|
||||
config_fn = ((codec->direction == ENC) ? &aptx_pack_enc_config :
|
||||
NULL);
|
||||
break;
|
||||
case CODEC_TYPE_APTX_AD:
|
||||
config_fn = ((codec->direction == ENC) ? &aptx_ad_pack_enc_config :
|
||||
NULL);
|
||||
break;
|
||||
case CODEC_TYPE_APTX_HD:
|
||||
config_fn = ((codec->direction == ENC) ? &aptx_hd_pack_enc_config :
|
||||
NULL);
|
||||
break;
|
||||
case CODEC_TYPE_APTX_DUAL_MONO:
|
||||
config_fn = ((codec->direction == ENC) ? &aptx_dual_mono_pack_enc_config :
|
||||
NULL);
|
||||
break;
|
||||
case CODEC_TYPE_APTX_AD_SPEECH:
|
||||
config_fn = ((codec->direction == ENC) ? &aptx_ad_speech_pack_enc_config :
|
||||
&aptx_ad_speech_pack_dec_config);
|
||||
break;
|
||||
default:
|
||||
ALOGD("%s unsupported codecFmt %d\n", __func__, codec->codecFmt);
|
||||
}
|
||||
|
||||
if (config_fn != NULL) {
|
||||
return config_fn(codec, src, dst);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static uint64_t bt_aptx_get_decoder_latency(bt_codec_t *codec)
|
||||
{
|
||||
uint32_t latency = 0;
|
||||
|
||||
switch (codec->codecFmt) {
|
||||
case CODEC_TYPE_APTX:
|
||||
case CODEC_TYPE_APTX_HD:
|
||||
case CODEC_TYPE_APTX_AD:
|
||||
case CODEC_TYPE_APTX_DUAL_MONO:
|
||||
default:
|
||||
latency = 200;
|
||||
ALOGD("No valid decoder defined, setting latency to %dms", latency);
|
||||
break;
|
||||
}
|
||||
return (uint64_t)latency;
|
||||
}
|
||||
|
||||
static uint64_t bt_aptx_get_encoder_latency(bt_codec_t *codec)
|
||||
{
|
||||
uint32_t latency = 0;
|
||||
|
||||
switch (codec->codecFmt) {
|
||||
case CODEC_TYPE_APTX:
|
||||
latency = ENCODER_LATENCY_APTX;
|
||||
break;
|
||||
case CODEC_TYPE_APTX_HD:
|
||||
latency = ENCODER_LATENCY_APTX_HD;
|
||||
break;
|
||||
case CODEC_TYPE_APTX_AD:
|
||||
/* for aptx adaptive the latency depends on the mode (HQ/LL) and
|
||||
* BT IPC will take care of accomodating the mode factor and return latency
|
||||
*/
|
||||
latency = 0;
|
||||
break;
|
||||
default:
|
||||
latency = 200;
|
||||
break;
|
||||
}
|
||||
ALOGV("%s: codecFmt %u, direction %d, latency %u",
|
||||
__func__, codec->codecFmt, codec->direction, latency);
|
||||
return latency;
|
||||
}
|
||||
|
||||
static uint64_t bt_aptx_get_codec_latency(bt_codec_t *codec)
|
||||
{
|
||||
|
||||
if (codec->direction == ENC)
|
||||
return bt_aptx_get_encoder_latency(codec);
|
||||
else
|
||||
return bt_aptx_get_decoder_latency(codec);
|
||||
}
|
||||
|
||||
int bt_aptx_query_num_codecs(bt_codec_t *codec __unused) {
|
||||
ALOGV("%s", __func__);
|
||||
return NUM_CODEC;
|
||||
}
|
||||
|
||||
void bt_aptx_close(bt_codec_t *codec)
|
||||
{
|
||||
bt_enc_payload_t *payload = codec->payload;
|
||||
int num_blks, i;
|
||||
custom_block_t *blk;
|
||||
|
||||
if (payload) {
|
||||
num_blks = payload->num_blks;
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk = payload->blocks[i];
|
||||
if (blk) {
|
||||
if (blk->payload)
|
||||
free(blk->payload);
|
||||
free(blk);
|
||||
blk = NULL;
|
||||
}
|
||||
}
|
||||
free(payload);
|
||||
}
|
||||
free(codec);
|
||||
}
|
||||
|
||||
__attribute__ ((visibility ("default")))
|
||||
int plugin_open(bt_codec_t **codec, uint32_t codecFmt, codec_type direction)
|
||||
{
|
||||
bt_codec_t *bt_codec = NULL;
|
||||
|
||||
|
||||
bt_codec = calloc(1, sizeof(bt_codec_t));
|
||||
if (!bt_codec) {
|
||||
ALOGE("%s: Memory allocation failed\n", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
bt_codec->codecFmt = codecFmt;
|
||||
bt_codec->direction = direction;
|
||||
bt_codec->plugin_populate_payload = bt_aptx_populate_payload;
|
||||
bt_codec->plugin_get_codec_latency = bt_aptx_get_codec_latency;
|
||||
bt_codec->plugin_query_num_codecs = bt_aptx_query_num_codecs;
|
||||
bt_codec->close_plugin = bt_aptx_close;
|
||||
|
||||
*codec = bt_codec;
|
||||
return 0;
|
||||
}
|
||||
125
qcom/opensource/pal/plugins/codecs/bt_aptx.h
Normal file
125
qcom/opensource/pal/plugins/codecs/bt_aptx.h
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.
|
||||
*/
|
||||
|
||||
#ifndef _BT_APTX_H_
|
||||
#define _BT_APTX_H_
|
||||
|
||||
#include "bt_intf.h"
|
||||
|
||||
#define ENCODER_LATENCY_APTX 40
|
||||
#define ENCODER_LATENCY_APTX_HD 20
|
||||
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
|
||||
#define DEFAULT_SINK_LATENCY_APTX 110
|
||||
#else
|
||||
#define DEFAULT_SINK_LATENCY_APTX 160
|
||||
#endif
|
||||
#define DEFAULT_SINK_LATENCY_APTX_HD 180
|
||||
#define MODULE_ID_APTX_CLASSIC_ENC 0x0700107E
|
||||
#define MODULE_ID_APTX_CLASSIC_DEC 0x0700107D
|
||||
#define MODULE_ID_APTX_HD_DEC 0x0700107F
|
||||
#define MODULE_ID_APTX_HD_ENC 0x07001080
|
||||
#define MODULE_ID_APTX_ADAPTIVE_ENC 0x07001082
|
||||
#define MODULE_ID_APTX_ADAPTIVE_SWB_DEC 0x07001083
|
||||
#define MODULE_ID_APTX_ADAPTIVE_SWB_ENC 0x07001084
|
||||
#define NUM_CODEC 4
|
||||
|
||||
/*
|
||||
* enums which describes the APTX Adaptive
|
||||
* channel mode, these values are used by encoder
|
||||
*/
|
||||
typedef enum {
|
||||
APTX_AD_CHANNEL_UNCHANGED = -1,
|
||||
APTX_AD_CHANNEL_JOINT_STEREO = 0, // default
|
||||
APTX_AD_CHANNEL_MONO = 1,
|
||||
APTX_AD_CHANNEL_DUAL_MONO = 2,
|
||||
APTX_AD_CHANNEL_STEREO_TWS = 4,
|
||||
APTX_AD_CHANNEL_EARBUD = 8,
|
||||
} enc_aptx_ad_channel_mode;
|
||||
|
||||
/*
|
||||
* enums which describes the APTX Adaptive
|
||||
* sampling frequency, these values are used
|
||||
* by encoder
|
||||
*/
|
||||
typedef enum {
|
||||
APTX_AD_SR_UNCHANGED = 0x0,
|
||||
APTX_AD_48 = 0x1, // 48 KHz default
|
||||
APTX_AD_44_1 = 0x2, // 44.1kHz
|
||||
APTX_AD_96 = 0x3, // 96KHz
|
||||
} enc_aptx_ad_s_rate;
|
||||
|
||||
/* Information about BT APTX encoder configuration
|
||||
* This data is used between audio HAL module and
|
||||
* BT IPC library to configure DSP encoder
|
||||
*/
|
||||
typedef struct audio_aptx_encoder_config_s {
|
||||
uint16_t sampling_rate;
|
||||
uint8_t channels;
|
||||
uint32_t bitrate;
|
||||
uint32_t bits_per_sample;
|
||||
} audio_aptx_encoder_config_t;
|
||||
|
||||
typedef struct audio_aptx_hd_encoder_config_s {
|
||||
uint16_t sampling_rate;
|
||||
uint8_t channels;
|
||||
uint32_t bitrate;
|
||||
uint32_t bits_per_sample;
|
||||
} audio_aptx_hd_encoder_config_t;
|
||||
|
||||
typedef struct audio_aptx_dual_mono_config_s {
|
||||
uint16_t sampling_rate;
|
||||
uint8_t channels;
|
||||
uint32_t bitrate;
|
||||
uint8_t sync_mode;
|
||||
} audio_aptx_dual_mono_config_t;
|
||||
|
||||
typedef struct audio_aptx_ad_encoder_config_s {
|
||||
uint32_t sampling_rate;
|
||||
uint32_t mtu;
|
||||
int32_t channel_mode;
|
||||
uint32_t min_sink_modeA;
|
||||
uint32_t max_sink_modeA;
|
||||
uint32_t min_sink_modeB;
|
||||
uint32_t max_sink_modeB;
|
||||
uint32_t min_sink_modeC;
|
||||
uint32_t max_sink_modeC;
|
||||
uint32_t encoder_mode;
|
||||
uint8_t TTP_modeA_low;
|
||||
uint8_t TTP_modeA_high;
|
||||
uint8_t TTP_modeB_low;
|
||||
uint8_t TTP_modeB_high;
|
||||
uint8_t TTP_TWS_low;
|
||||
uint8_t TTP_TWS_high;
|
||||
uint32_t bits_per_sample;
|
||||
uint32_t input_mode;
|
||||
uint32_t fade_duration;
|
||||
uint8_t sink_cap[11];
|
||||
} audio_aptx_ad_encoder_config_t;
|
||||
|
||||
#endif /* _BT_APTX_H_ */
|
||||
108
qcom/opensource/pal/plugins/codecs/bt_base.c
Normal file
108
qcom/opensource/pal/plugins/codecs/bt_base.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2020, 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.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "PAL: bt_base"
|
||||
|
||||
#include "bt_base.h"
|
||||
#include <common_enc_dec_api.h>
|
||||
#include <media_fmt_api.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int bt_base_populate_real_module_id(custom_block_t *blk, int32_t real_module_id)
|
||||
{
|
||||
struct param_id_placeholder_real_module_id_t *param = NULL;
|
||||
|
||||
blk->param_id = PARAM_ID_REAL_MODULE_ID;
|
||||
blk->payload_sz = sizeof(struct param_id_placeholder_real_module_id_t);
|
||||
blk->payload = calloc(1, blk->payload_sz);
|
||||
if (!blk->payload) {
|
||||
blk->payload_sz = 0;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
param = (struct param_id_placeholder_real_module_id_t*) blk->payload;
|
||||
param->real_module_id = real_module_id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_base_populate_enc_bitrate(custom_block_t *blk, int32_t bit_rate)
|
||||
{
|
||||
struct param_id_enc_bitrate_param_t *param = NULL;
|
||||
|
||||
blk->param_id = PARAM_ID_ENC_BITRATE;
|
||||
blk->payload_sz = sizeof(struct param_id_enc_bitrate_param_t);
|
||||
blk->payload = calloc(1, blk->payload_sz);
|
||||
if (!blk->payload) {
|
||||
blk->payload_sz = 0;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
param = (struct param_id_enc_bitrate_param_t*) blk->payload;
|
||||
param->bitrate = bit_rate;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_base_populate_enc_output_cfg(custom_block_t *blk, uint32_t fmt_id,
|
||||
void *payload, size_t size)
|
||||
{
|
||||
struct param_id_encoder_output_config_t *param = NULL;
|
||||
void *enc_payload;
|
||||
|
||||
blk->param_id = PARAM_ID_ENCODER_OUTPUT_CONFIG;
|
||||
blk->payload_sz = sizeof(struct param_id_encoder_output_config_t) + size;
|
||||
blk->payload = (uint8_t *)calloc(1, blk->payload_sz);
|
||||
if (!blk->payload) {
|
||||
blk->payload_sz = 0;
|
||||
return -ENOMEM;
|
||||
}
|
||||
param = (struct param_id_encoder_output_config_t *) blk->payload;
|
||||
param->data_format = DATA_FORMAT_FIXED_POINT;
|
||||
param->fmt_id = fmt_id;
|
||||
param->payload_size = size;
|
||||
enc_payload = (void *)(blk->payload + sizeof(struct param_id_encoder_output_config_t));
|
||||
memcpy(enc_payload, payload, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_base_populate_enc_cmn_param(custom_block_t *blk, uint32_t param_id,
|
||||
void *payload, size_t size)
|
||||
{
|
||||
blk->param_id = param_id;
|
||||
blk->payload_sz = size;
|
||||
blk->payload = (uint8_t *)calloc(1, blk->payload_sz);
|
||||
if (!blk->payload) {
|
||||
blk->payload_sz = 0;
|
||||
return -ENOMEM;
|
||||
}
|
||||
memcpy(blk->payload, payload, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
94
qcom/opensource/pal/plugins/codecs/bt_base.h
Normal file
94
qcom/opensource/pal/plugins/codecs/bt_base.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2020, 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.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _BT_BASE_H_
|
||||
#define _BT_BASE_H_
|
||||
|
||||
#include "bt_intf.h"
|
||||
|
||||
#define CH_MONO 1
|
||||
#define CH_STEREO 2
|
||||
#define SAMPLING_RATE_16K 16000 // SS_BT_HFP - H_127 : RVP
|
||||
#define SAMPLING_RATE_32K 32000
|
||||
#define SAMPLING_RATE_44K 44100
|
||||
#define SAMPLING_RATE_48K 48000
|
||||
#define SAMPLING_RATE_96K 96000
|
||||
#define ENCODER_BIT_FORMAT_DEFAULT 16
|
||||
#define ENCODER_BIT_FORMAT_PCM_24 24
|
||||
|
||||
|
||||
enum {
|
||||
AUDIO_LOCATION_NONE = 0x00000000, // Mono/Unspecified
|
||||
AUDIO_LOCATION_FRONT_LEFT = 0x00000001,
|
||||
AUDIO_LOCATION_FRONT_RIGHT = 0x00000002,
|
||||
AUDIO_LOCATION_FRONT_CENTER = 0x00000004,
|
||||
AUDIO_LOCATION_LOW_FREQUENCY = 0x00000008,
|
||||
AUDIO_LOCATION_BACK_LEFT = 0x00000010,
|
||||
AUDIO_LOCATION_BACK_RIGHT = 0x00000020,
|
||||
AUDIO_LOCATION_FRONT_LEFT_OF_CENTER = 0x00000040,
|
||||
AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER = 0x00000080,
|
||||
AUDIO_LOCATION_BACK_CENTER = 0x00000100,
|
||||
AUDIO_LOCATION_LOW_FREQUENCY_2 = 0x00000200,
|
||||
AUDIO_LOCATION_SIDE_LEFT = 0x00000400,
|
||||
AUDIO_LOCATION_SIDE_RIGHT = 0x00000800,
|
||||
AUDIO_LOCATION_TOP_FRONT_LEFT = 0x00001000,
|
||||
AUDIO_LOCATION_TOP_FRONT_RIGHT = 0x00002000,
|
||||
AUDIO_LOCATION_TOP_FRONT_CENTER = 0x00004000,
|
||||
AUDIO_LOCATION_TOP_CENTER = 0x00008000,
|
||||
AUDIO_LOCATION_TOP_BACK_LEFT = 0x00010000,
|
||||
AUDIO_LOCATION_TOP_BACK_RIGHT = 0x00020000,
|
||||
AUDIO_LOCATION_TOP_SIDE_LEFT = 0x00040000,
|
||||
AUDIO_LOCATION_TOP_SIDE_RIGHT = 0x00080000,
|
||||
AUDIO_LOCATION_TOP_BACK_CENTER = 0x00100000,
|
||||
AUDIO_LOCATION_BOTTOM_FRONT_CENTER = 0x00200000,
|
||||
AUDIO_LOCATION_BOTTOM_FRONT_LEFT = 0x00400000,
|
||||
AUDIO_LOCATION_BOTTOM_FRONT_RIGHT = 0x00800000,
|
||||
AUDIO_LOCATION_FRONT_LEFT_WIDE = 0x01000000,
|
||||
AUDIO_LOCATION_FRONT_RIGHT_WIDE = 0x02000000,
|
||||
AUDIO_LOCATION_LEFT_SURROUND = 0x04000000,
|
||||
AUDIO_LOCATION_RIGHT_SURROUND = 0x08000000,
|
||||
AUDIO_LOCATION_RESERVED_1 = 0x10000000,
|
||||
AUDIO_LOCATION_RESERVED_2 = 0x20000000,
|
||||
AUDIO_LOCATION_RESERVED_3 = 0x40000000,
|
||||
AUDIO_LOCATION_RESERVED_4 = 0x80000000,
|
||||
};
|
||||
|
||||
|
||||
int bt_base_populate_real_module_id(custom_block_t *blk, int32_t real_module_id);
|
||||
|
||||
int bt_base_populate_enc_bitrate(custom_block_t *blk, int32_t bit_rate);
|
||||
|
||||
int bt_base_populate_enc_output_cfg(custom_block_t *blk, uint32_t fmt_id,
|
||||
void *payload, size_t size);
|
||||
|
||||
int bt_base_populate_enc_cmn_param(custom_block_t *blk, uint32_t param_id,
|
||||
void *payload, size_t size);
|
||||
|
||||
#endif /* _BT_BASE_H_ */
|
||||
458
qcom/opensource/pal/plugins/codecs/bt_ble.c
Normal file
458
qcom/opensource/pal/plugins/codecs/bt_ble.c
Normal file
@@ -0,0 +1,458 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#define LOG_TAG "PAL: bt_ble"
|
||||
//#define LOG_NDEBUG 0
|
||||
|
||||
#include <log/log.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "bt_ble.h"
|
||||
#include <lc3_encoder_api.h>
|
||||
#include <lc3_decoder_api.h>
|
||||
|
||||
static int ble_pack_def_enc_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
audio_lc3_codec_cfg_t *ble_bt_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
struct param_id_lc3_encoder_config_payload_t *enc_init = NULL;
|
||||
int ret = 0, num_blks = 1, payload_sz = 0, i = 0;
|
||||
custom_block_t *blk[1] = {NULL};
|
||||
|
||||
ble_bt_cfg = (audio_lc3_codec_cfg_t *)src;
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
enc_payload->bit_format = def_toair_cfg.bit_depth;
|
||||
enc_payload->sample_rate = def_toair_cfg.sampling_freq;
|
||||
enc_payload->num_blks = def_toair_cfg.num_blocks;
|
||||
enc_payload->channel_count = CH_STEREO;
|
||||
|
||||
enc_payload->is_abr_enabled = true;
|
||||
enc_payload->is_enc_config_set = ble_bt_cfg->is_enc_config_set;
|
||||
enc_payload->is_dec_config_set = ble_bt_cfg->is_dec_config_set;
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_LC3_ENC_INIT */
|
||||
payload_sz = sizeof(struct param_id_lc3_encoder_config_payload_t) +
|
||||
sizeof(stream_map_t) * DEF_STREAM_MAP_SZ;
|
||||
enc_init = (struct param_id_lc3_encoder_config_payload_t *)calloc(1, payload_sz);
|
||||
if (enc_init == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
|
||||
enc_init->stream_map_size = DEF_STREAM_MAP_SZ;
|
||||
enc_init->toAirConfig.num_blocks = def_toair_cfg.num_blocks;
|
||||
enc_init->toAirConfig.api_version = def_toair_cfg.api_version;
|
||||
enc_init->toAirConfig.sampling_Frequency = def_toair_cfg.sampling_freq;
|
||||
enc_init->toAirConfig.max_octets_per_frame = def_toair_cfg.max_octets_per_frame;
|
||||
enc_init->toAirConfig.frame_duration = def_toair_cfg.frame_duration;
|
||||
enc_init->toAirConfig.bit_depth = def_toair_cfg.bit_depth;
|
||||
enc_init->toAirConfig.mode = def_toair_cfg.mode;
|
||||
for (i = 0; i < 16; i++) {
|
||||
enc_init->toAirConfig.vendor_specific[i] =
|
||||
ble_bt_cfg->enc_cfg.toAirConfig.vendor_specific[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < enc_init->stream_map_size; i++) {
|
||||
enc_init->streamMapOut[i].audio_location = def_stream_map_out[i].audio_location;
|
||||
enc_init->streamMapOut[i].stream_id = def_stream_map_out[i].stream_id;
|
||||
enc_init->streamMapOut[i].direction = def_stream_map_out[i].direction;
|
||||
}
|
||||
ret = bt_base_populate_enc_cmn_param(blk[0], PARAM_ID_LC3_ENC_INIT,
|
||||
enc_init, payload_sz);
|
||||
free(enc_init);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ble_pack_enc_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
audio_lc3_codec_cfg_t *ble_bt_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
struct param_id_lc3_encoder_config_payload_t *enc_init = NULL;
|
||||
int ret = 0, num_blks = 1, payload_sz = 0, i = 0;
|
||||
custom_block_t *blk[1] = {NULL};
|
||||
|
||||
ALOGV("%s", __func__);
|
||||
if ((src == NULL) || (dst == NULL)) {
|
||||
ALOGE("%s: invalid input parameters", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ble_bt_cfg = (audio_lc3_codec_cfg_t *)src;
|
||||
|
||||
if (!ble_bt_cfg->is_enc_config_set) {
|
||||
ALOGI("%s: is_enc_config_set is false; setting default enc params",
|
||||
__func__);
|
||||
return ble_pack_def_enc_config(codec, src, dst);
|
||||
}
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
enc_payload->bit_format = ble_bt_cfg->enc_cfg.toAirConfig.bit_depth;
|
||||
enc_payload->sample_rate = ble_bt_cfg->enc_cfg.toAirConfig.sampling_freq;
|
||||
enc_payload->num_blks = num_blks;
|
||||
if (ble_bt_cfg->enc_cfg.stream_map_size) {
|
||||
if ((1 == ble_bt_cfg->enc_cfg.stream_map_size) &&
|
||||
(ble_bt_cfg->enc_cfg.streamMapOut[0].audio_location != 3))
|
||||
enc_payload->channel_count = CH_MONO;
|
||||
else
|
||||
enc_payload->channel_count = CH_STEREO;
|
||||
}
|
||||
|
||||
enc_payload->is_abr_enabled = true;
|
||||
enc_payload->is_enc_config_set = ble_bt_cfg->is_enc_config_set;
|
||||
enc_payload->is_dec_config_set = ble_bt_cfg->is_dec_config_set;
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_LC3_ENC_INIT */
|
||||
payload_sz = sizeof(struct param_id_lc3_encoder_config_payload_t) +
|
||||
sizeof(stream_map_t) * ble_bt_cfg->enc_cfg.stream_map_size;
|
||||
enc_init = (struct param_id_lc3_encoder_config_payload_t *)calloc(1, payload_sz);
|
||||
if (enc_init == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
|
||||
enc_init->stream_map_size = ble_bt_cfg->enc_cfg.stream_map_size;
|
||||
enc_init->toAirConfig.api_version = ble_bt_cfg->enc_cfg.toAirConfig.api_version;
|
||||
enc_init->toAirConfig.sampling_Frequency = ble_bt_cfg->enc_cfg.toAirConfig.sampling_freq;
|
||||
enc_init->toAirConfig.max_octets_per_frame = ble_bt_cfg->enc_cfg.toAirConfig.max_octets_per_frame;
|
||||
enc_init->toAirConfig.frame_duration = ble_bt_cfg->enc_cfg.toAirConfig.frame_duration;
|
||||
enc_init->toAirConfig.bit_depth = ble_bt_cfg->enc_cfg.toAirConfig.bit_depth;
|
||||
enc_init->toAirConfig.num_blocks = ble_bt_cfg->enc_cfg.toAirConfig.num_blocks;
|
||||
enc_init->toAirConfig.default_q_level = ble_bt_cfg->enc_cfg.toAirConfig.default_q_level;
|
||||
enc_init->toAirConfig.mode = ble_bt_cfg->enc_cfg.toAirConfig.mode;
|
||||
for (i = 0; i < 16; i++) {
|
||||
enc_init->toAirConfig.vendor_specific[i] =
|
||||
ble_bt_cfg->enc_cfg.toAirConfig.vendor_specific[i];
|
||||
if (i == VERSION_IDX)
|
||||
enc_payload->codec_version = enc_init->toAirConfig.vendor_specific[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < enc_init->stream_map_size; i++) {
|
||||
enc_init->streamMapOut[i].audio_location = ble_bt_cfg->enc_cfg.streamMapOut[i].audio_location;
|
||||
enc_init->streamMapOut[i].stream_id = ble_bt_cfg->enc_cfg.streamMapOut[i].stream_id;
|
||||
enc_init->streamMapOut[i].direction = ble_bt_cfg->enc_cfg.streamMapOut[i].direction;
|
||||
}
|
||||
|
||||
ret = bt_base_populate_enc_cmn_param(blk[0], PARAM_ID_LC3_ENC_INIT,
|
||||
enc_init, payload_sz);
|
||||
free(enc_init);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ble_pack_dec_config(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
audio_lc3_codec_cfg_t *ble_bt_cfg = NULL;
|
||||
bt_enc_payload_t *enc_payload = NULL;
|
||||
struct param_id_lc3_decoder_config_payload_t *dec_init = NULL;
|
||||
int ret = 0, num_blks = 1, payload_sz = 0, i = 0;
|
||||
custom_block_t *blk[1] = {NULL};
|
||||
|
||||
ALOGV("%s", __func__);
|
||||
if ((src == NULL) || (dst == NULL)) {
|
||||
ALOGE("%s: invalid input parameters", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ble_bt_cfg = (audio_lc3_codec_cfg_t *)src;
|
||||
|
||||
enc_payload = (bt_enc_payload_t *)calloc(1, sizeof(bt_enc_payload_t) +
|
||||
num_blks * sizeof(custom_block_t *));
|
||||
if (enc_payload == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
enc_payload->bit_format = ble_bt_cfg->dec_cfg.fromAirConfig.bit_depth;
|
||||
enc_payload->sample_rate = ble_bt_cfg->dec_cfg.fromAirConfig.sampling_freq;
|
||||
enc_payload->channel_count = ble_bt_cfg->dec_cfg.decoder_output_channel;
|
||||
enc_payload->num_blks = num_blks;
|
||||
enc_payload->is_abr_enabled = true;
|
||||
enc_payload->is_enc_config_set = ble_bt_cfg->is_enc_config_set;
|
||||
enc_payload->is_dec_config_set = ble_bt_cfg->is_dec_config_set;
|
||||
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk[i] = (custom_block_t *)calloc(1, sizeof(custom_block_t));
|
||||
if (!blk[i]) {
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
}
|
||||
|
||||
/* populate payload for PARAM_ID_LC3_DEC_INIT */
|
||||
payload_sz = sizeof(struct param_id_lc3_decoder_config_payload_t) +
|
||||
sizeof(stream_map_t) * ble_bt_cfg->dec_cfg.stream_map_size;
|
||||
dec_init = (struct param_id_lc3_decoder_config_payload_t *)calloc(1, payload_sz);
|
||||
if (dec_init == NULL) {
|
||||
ALOGE("%s: fail to allocate memory", __func__);
|
||||
ret = -ENOMEM;
|
||||
goto free_payload;
|
||||
}
|
||||
|
||||
dec_init->decoder_output_channel = ble_bt_cfg->dec_cfg.decoder_output_channel;
|
||||
dec_init->stream_map_size = ble_bt_cfg->dec_cfg.stream_map_size;
|
||||
dec_init->fromAirConfig.api_version = ble_bt_cfg->dec_cfg.fromAirConfig.api_version;
|
||||
dec_init->fromAirConfig.sampling_Frequency = ble_bt_cfg->dec_cfg.fromAirConfig.sampling_freq;
|
||||
dec_init->fromAirConfig.max_octets_per_frame = ble_bt_cfg->dec_cfg.fromAirConfig.max_octets_per_frame;
|
||||
dec_init->fromAirConfig.frame_duration = ble_bt_cfg->dec_cfg.fromAirConfig.frame_duration;
|
||||
dec_init->fromAirConfig.bit_depth = ble_bt_cfg->dec_cfg.fromAirConfig.bit_depth;
|
||||
dec_init->fromAirConfig.num_blocks = ble_bt_cfg->dec_cfg.fromAirConfig.num_blocks;
|
||||
dec_init->fromAirConfig.default_q_level = ble_bt_cfg->dec_cfg.fromAirConfig.default_q_level;
|
||||
dec_init->fromAirConfig.mode = ble_bt_cfg->dec_cfg.fromAirConfig.mode;
|
||||
for (i = 0; i < 16; i++) {
|
||||
dec_init->fromAirConfig.vendor_specific[i] =
|
||||
ble_bt_cfg->dec_cfg.fromAirConfig.vendor_specific[i];
|
||||
if (i == VERSION_IDX)
|
||||
enc_payload->codec_version = dec_init->fromAirConfig.vendor_specific[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < dec_init->stream_map_size; i++) {
|
||||
dec_init->streamMapIn[i].audio_location = ble_bt_cfg->dec_cfg.streamMapIn[i].audio_location;
|
||||
dec_init->streamMapIn[i].stream_id = ble_bt_cfg->dec_cfg.streamMapIn[i].stream_id;
|
||||
dec_init->streamMapIn[i].direction = ble_bt_cfg->dec_cfg.streamMapIn[i].direction;
|
||||
}
|
||||
|
||||
ret = bt_base_populate_enc_cmn_param(blk[0], PARAM_ID_LC3_DEC_INIT,
|
||||
dec_init, payload_sz);
|
||||
free(dec_init);
|
||||
if (ret)
|
||||
goto free_payload;
|
||||
|
||||
enc_payload->blocks[0] = blk[0];
|
||||
*dst = enc_payload;
|
||||
codec->payload = enc_payload;
|
||||
|
||||
return ret;
|
||||
free_payload:
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
if (blk[i]) {
|
||||
if (blk[i]->payload)
|
||||
free(blk[i]->payload);
|
||||
free(blk[i]);
|
||||
}
|
||||
}
|
||||
if (enc_payload)
|
||||
free(enc_payload);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bt_ble_populate_payload(bt_codec_t *codec, void *src, void **dst)
|
||||
{
|
||||
config_fn_t config_fn = NULL;
|
||||
|
||||
if (codec->payload)
|
||||
free(codec->payload);
|
||||
|
||||
switch (codec->codecFmt) {
|
||||
case CODEC_TYPE_LC3:
|
||||
case CODEC_TYPE_APTX_AD_R4:
|
||||
config_fn = ((codec->direction == ENC) ? &ble_pack_enc_config :
|
||||
&ble_pack_dec_config);
|
||||
break;
|
||||
case CODEC_TYPE_APTX_AD_QLEA:
|
||||
config_fn = ((codec->direction == ENC) ? &ble_pack_enc_config :
|
||||
NULL);
|
||||
break;
|
||||
default:
|
||||
ALOGD("%s unsupported codecFmt %d\n", __func__, codec->codecFmt);
|
||||
}
|
||||
|
||||
if (config_fn != NULL) {
|
||||
return config_fn(codec, src, dst);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static uint64_t bt_ble_get_decoder_latency(bt_codec_t *codec)
|
||||
{
|
||||
uint32_t latency = 0;
|
||||
|
||||
switch (codec->codecFmt) {
|
||||
case CODEC_TYPE_LC3:
|
||||
latency = 0;
|
||||
break;
|
||||
default:
|
||||
latency = 200;
|
||||
ALOGD("No valid decoder defined, setting latency to %dms", latency);
|
||||
break;
|
||||
}
|
||||
return (uint64_t)latency;
|
||||
}
|
||||
|
||||
static uint64_t bt_ble_get_encoder_latency(bt_codec_t *codec)
|
||||
{
|
||||
uint32_t latency = 0;
|
||||
|
||||
switch (codec->codecFmt) {
|
||||
case CODEC_TYPE_LC3:
|
||||
case CODEC_TYPE_APTX_AD_QLEA:
|
||||
case CODEC_TYPE_APTX_AD_R4:
|
||||
/* for BLE, the latency depends on the mode (HQ/LL) and
|
||||
* BT IPC will take care of accomodating the mode factor and return latency
|
||||
*/
|
||||
latency = 0;
|
||||
break;
|
||||
default:
|
||||
latency = 200;
|
||||
break;
|
||||
}
|
||||
ALOGV("%s: codecFmt %u, direction %d, latency %u",
|
||||
__func__, codec->codecFmt, codec->direction, latency);
|
||||
return latency;
|
||||
}
|
||||
|
||||
static uint64_t bt_ble_get_codec_latency(bt_codec_t *codec)
|
||||
{
|
||||
if (codec->direction == ENC)
|
||||
return bt_ble_get_encoder_latency(codec);
|
||||
else
|
||||
return bt_ble_get_decoder_latency(codec);
|
||||
}
|
||||
|
||||
int bt_ble_query_num_codecs(bt_codec_t *codec __unused) {
|
||||
ALOGV("%s", __func__);
|
||||
return NUM_CODEC;
|
||||
}
|
||||
|
||||
void bt_ble_close(bt_codec_t *codec)
|
||||
{
|
||||
bt_enc_payload_t *payload = codec->payload;
|
||||
int num_blks, i;
|
||||
custom_block_t *blk;
|
||||
|
||||
if (payload) {
|
||||
num_blks = payload->num_blks;
|
||||
for (i = 0; i < num_blks; i++) {
|
||||
blk = payload->blocks[i];
|
||||
if (blk) {
|
||||
if (blk->payload)
|
||||
free(blk->payload);
|
||||
free(blk);
|
||||
blk = NULL;
|
||||
}
|
||||
}
|
||||
free(payload);
|
||||
}
|
||||
free(codec);
|
||||
}
|
||||
|
||||
__attribute__ ((visibility ("default")))
|
||||
int plugin_open(bt_codec_t **codec, uint32_t codecFmt, codec_type direction)
|
||||
{
|
||||
bt_codec_t *bt_codec = NULL;
|
||||
|
||||
|
||||
bt_codec = calloc(1, sizeof(bt_codec_t));
|
||||
if (!bt_codec) {
|
||||
ALOGE("%s: Memory allocation failed\n", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
bt_codec->codecFmt = codecFmt;
|
||||
bt_codec->direction = direction;
|
||||
bt_codec->plugin_populate_payload = bt_ble_populate_payload;
|
||||
bt_codec->plugin_get_codec_latency = bt_ble_get_codec_latency;
|
||||
bt_codec->plugin_query_num_codecs = bt_ble_query_num_codecs;
|
||||
bt_codec->close_plugin = bt_ble_close;
|
||||
|
||||
*codec = bt_codec;
|
||||
return 0;
|
||||
}
|
||||
204
qcom/opensource/pal/plugins/codecs/bt_ble.h
Normal file
204
qcom/opensource/pal/plugins/codecs/bt_ble.h
Normal file
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 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.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef _BT_BLE_H_
|
||||
#define _BT_BLE_H_
|
||||
|
||||
#include "bt_intf.h"
|
||||
#include "bt_base.h"
|
||||
|
||||
#define NUM_CODEC 2
|
||||
#define AUDIO_LOCATION_MAX 28
|
||||
#define VERSION_IDX 7
|
||||
|
||||
|
||||
/* Information about BT LC3 encoder configuration
|
||||
* This data is used between audio HAL module and
|
||||
* BT IPC library to configure DSP encoder
|
||||
*/
|
||||
typedef struct lc3_cfg_s {
|
||||
uint32_t api_version;
|
||||
uint32_t sampling_freq;
|
||||
uint32_t max_octets_per_frame;
|
||||
uint32_t frame_duration; // 7.5msec, 10msec
|
||||
uint32_t bit_depth;
|
||||
uint32_t num_blocks;
|
||||
uint8_t default_q_level;
|
||||
uint8_t vendor_specific[16]; // this indicates LC3/LC3Q. 0 => LC3 1.0 , 1 => LC3 1.1
|
||||
uint32_t mode;
|
||||
} lc3_cfg_t;
|
||||
|
||||
typedef struct lc3_stream_map_s {
|
||||
uint32_t audio_location;
|
||||
uint8_t stream_id;
|
||||
uint8_t direction;
|
||||
} lc3_stream_map_t;
|
||||
|
||||
typedef struct lc3_encoder_cfg_s {
|
||||
lc3_cfg_t toAirConfig;
|
||||
uint8_t stream_map_size;
|
||||
uint8_t actual_stream_map_size; // SS_BT_LEA - A_041 : Stereo audio for SingleDev_OneChanStereoSnk
|
||||
lc3_stream_map_t *streamMapOut;
|
||||
} lc3_encoder_cfg_t;
|
||||
|
||||
typedef struct lc3_decoder_cfg_s {
|
||||
lc3_cfg_t fromAirConfig;
|
||||
uint32_t decoder_output_channel;
|
||||
uint8_t stream_map_size;
|
||||
lc3_stream_map_t *streamMapIn;
|
||||
} lc3_decoder_cfg_t;
|
||||
|
||||
typedef struct audio_lc3_codec_cfg_s {
|
||||
lc3_encoder_cfg_t enc_cfg;
|
||||
lc3_decoder_cfg_t dec_cfg;
|
||||
bool is_enc_config_set;
|
||||
bool is_dec_config_set;
|
||||
} audio_lc3_codec_cfg_t;
|
||||
|
||||
static uint32_t audio_location_map_array[] = {
|
||||
AUDIO_LOCATION_FRONT_LEFT,
|
||||
AUDIO_LOCATION_FRONT_RIGHT,
|
||||
AUDIO_LOCATION_FRONT_CENTER,
|
||||
AUDIO_LOCATION_LOW_FREQUENCY,
|
||||
AUDIO_LOCATION_BACK_LEFT,
|
||||
AUDIO_LOCATION_BACK_RIGHT,
|
||||
AUDIO_LOCATION_FRONT_LEFT_OF_CENTER,
|
||||
AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER,
|
||||
AUDIO_LOCATION_BACK_CENTER,
|
||||
AUDIO_LOCATION_LOW_FREQUENCY_2,
|
||||
AUDIO_LOCATION_SIDE_LEFT,
|
||||
AUDIO_LOCATION_SIDE_RIGHT,
|
||||
AUDIO_LOCATION_TOP_FRONT_LEFT,
|
||||
AUDIO_LOCATION_TOP_FRONT_RIGHT,
|
||||
AUDIO_LOCATION_TOP_FRONT_CENTER,
|
||||
AUDIO_LOCATION_TOP_CENTER,
|
||||
AUDIO_LOCATION_TOP_BACK_LEFT,
|
||||
AUDIO_LOCATION_TOP_BACK_RIGHT,
|
||||
AUDIO_LOCATION_TOP_SIDE_LEFT,
|
||||
AUDIO_LOCATION_TOP_SIDE_RIGHT,
|
||||
AUDIO_LOCATION_TOP_BACK_CENTER,
|
||||
AUDIO_LOCATION_BOTTOM_FRONT_CENTER,
|
||||
AUDIO_LOCATION_BOTTOM_FRONT_LEFT,
|
||||
AUDIO_LOCATION_BOTTOM_FRONT_RIGHT,
|
||||
AUDIO_LOCATION_FRONT_LEFT_WIDE,
|
||||
AUDIO_LOCATION_FRONT_RIGHT_WIDE,
|
||||
AUDIO_LOCATION_LEFT_SURROUND,
|
||||
AUDIO_LOCATION_RIGHT_SURROUND
|
||||
};
|
||||
|
||||
static int channel_map_array[] = {
|
||||
PCM_CHANNEL_L,
|
||||
PCM_CHANNEL_R,
|
||||
PCM_CHANNEL_C,
|
||||
PCM_CHANNEL_LFE,
|
||||
PCM_CHANNEL_LB,
|
||||
PCM_CHANNEL_RB,
|
||||
PCM_CHANNEL_FLC,
|
||||
PCM_CHANNEL_FRC,
|
||||
PCM_CHANNEL_CB,
|
||||
PCM_CHANNEL_RS,
|
||||
PCM_CHANNEL_SL,
|
||||
PCM_CHANNEL_SR,
|
||||
PCM_CHANNEL_TFL,
|
||||
PCM_CHANNEL_TFR,
|
||||
PCM_CHANNEL_TFC,
|
||||
PCM_CHANNEL_TC,
|
||||
PCM_CHANNEL_TBL,
|
||||
PCM_CHANNEL_TBR,
|
||||
PCM_CHANNEL_TSL,
|
||||
PCM_CHANNEL_TSR,
|
||||
PCM_CHANNEL_TBC,
|
||||
PCM_CHANNEL_BFC,
|
||||
PCM_CHANNEL_BFL,
|
||||
PCM_CHANNEL_BFR,
|
||||
PCM_CHANNEL_LW,
|
||||
PCM_CHANNEL_RW,
|
||||
PCM_CHANNEL_LS,
|
||||
PCM_CHANNEL_RS
|
||||
};
|
||||
|
||||
__attribute__((unused))
|
||||
static uint64_t convert_channel_map(uint32_t audio_location)
|
||||
{
|
||||
int i;
|
||||
uint64_t channel_mask = (uint64_t) 0x00000000;
|
||||
if (!audio_location) {
|
||||
channel_mask |= 1ULL << PCM_CHANNEL_C;
|
||||
return channel_mask;
|
||||
}
|
||||
|
||||
for (i = 0; i < AUDIO_LOCATION_MAX; i++) {
|
||||
if (audio_location & audio_location_map_array[i])
|
||||
channel_mask |= 1ULL << channel_map_array[i];
|
||||
}
|
||||
|
||||
return channel_mask;
|
||||
}
|
||||
|
||||
struct codec_specific_config {
|
||||
uint32_t sampling_freq;
|
||||
uint32_t frame_duration;
|
||||
uint32_t max_octets_per_frame;
|
||||
uint32_t bit_depth;
|
||||
};
|
||||
|
||||
#define LC3_CSC_TBL_SIZE 6
|
||||
static struct codec_specific_config LC3_CSC[LC3_CSC_TBL_SIZE] = {
|
||||
{8000, 7500, 26, 24},
|
||||
{8000, 10000, 30, 24},
|
||||
{16000, 7500, 30, 24},
|
||||
{16000, 10000, 40, 24},
|
||||
{32000, 7500, 60, 24},
|
||||
{32000, 10000, 80, 24},
|
||||
};
|
||||
|
||||
#define DEF_STREAM_MAP_SZ 2
|
||||
static lc3_stream_map_t def_stream_map_out[DEF_STREAM_MAP_SZ] = {
|
||||
{2, 0, 0},
|
||||
{1, 1, 0},
|
||||
};
|
||||
|
||||
static lc3_cfg_t def_toair_cfg = {
|
||||
33,
|
||||
16000,
|
||||
40,
|
||||
10000,
|
||||
24,
|
||||
1,
|
||||
0,
|
||||
{0},
|
||||
1,
|
||||
};
|
||||
|
||||
#endif /* _BT_BLE_H_ */
|
||||
1066
qcom/opensource/pal/plugins/codecs/bt_bundle.c
Normal file
1066
qcom/opensource/pal/plugins/codecs/bt_bundle.c
Normal file
File diff suppressed because it is too large
Load Diff
206
qcom/opensource/pal/plugins/codecs/bt_bundle.h
Normal file
206
qcom/opensource/pal/plugins/codecs/bt_bundle.h
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2021, 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.
|
||||
*/
|
||||
|
||||
#ifndef _BT_BUNDLE_H_
|
||||
#define _BT_BUNDLE_H_
|
||||
|
||||
#include "bt_intf.h"
|
||||
|
||||
#define ENCODER_LATENCY_SBC 10
|
||||
#define ENCODER_LATENCY_AAC 70
|
||||
#define ENCODER_LATENCY_CELT 40
|
||||
#define ENCODER_LATENCY_LDAC 40
|
||||
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
|
||||
#define ENCODER_LATENCY_SSC 10
|
||||
#define DEFAULT_SINK_LATENCY_SBC 100
|
||||
#define DEFAULT_SINK_LATENCY_SSC 160
|
||||
#else
|
||||
#define DEFAULT_SINK_LATENCY_SBC 140
|
||||
#endif
|
||||
#define DEFAULT_SINK_LATENCY_AAC 180
|
||||
#define DEFAULT_SINK_LATENCY_CELT 180
|
||||
#define DEFAULT_SINK_LATENCY_LDAC 180
|
||||
#define MODULE_ID_AAC_ENC 0x0700101E
|
||||
#define MODULE_ID_AAC_DEC 0x0700101F
|
||||
#define MODULE_ID_SBC_DEC 0x07001039
|
||||
#define MODULE_ID_SBC_ENC 0x0700103A
|
||||
#define MODULE_ID_LDAC_ENC 0x0700107A
|
||||
#define MODULE_ID_CELT_ENC 0x07001090
|
||||
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
|
||||
#define MODULE_ID_SS_SBC_ENC 0x10010BF5
|
||||
#define MODULE_ID_SSC_ENC 0x10010BF3
|
||||
#define NUM_CODEC 5
|
||||
#define PCM_CHANNEL_L 1
|
||||
#define PCM_CHANNEL_R 2
|
||||
#define PCM_CHANNEL_C 3
|
||||
#else
|
||||
#define NUM_CODEC 4
|
||||
#endif
|
||||
|
||||
/* Information about BT AAC encoder configuration
|
||||
* This data is used between audio HAL module and
|
||||
* BT IPC library to configure DSP encoder
|
||||
*/
|
||||
|
||||
#define MAX_ABR_QUALITY_LEVELS 5
|
||||
typedef struct bit_rate_level_map_s {
|
||||
uint32_t link_quality_level;
|
||||
uint32_t bitrate;
|
||||
} bit_rate_level_map_t;
|
||||
|
||||
struct quality_level_to_bitrate_info {
|
||||
uint32_t num_levels;
|
||||
bit_rate_level_map_t bit_rate_level_map[MAX_ABR_QUALITY_LEVELS];
|
||||
};
|
||||
|
||||
/* Structure to control frame size of AAC encoded frames. */
|
||||
enum {
|
||||
MTU_SIZE = 0,
|
||||
PEAK_BIT_RATE,
|
||||
BIT_RATE_MODE,
|
||||
};
|
||||
|
||||
struct aac_frame_size_control_t {
|
||||
/* Type of frame size control: MTU_SIZE / PEAK_BIT_RATE*/
|
||||
uint32_t ctl_type;
|
||||
/* Control value
|
||||
* MTU_SIZE: MTU size in bytes
|
||||
* PEAK_BIT_RATE: Peak bitrate in bits per second.
|
||||
* BIT_RATE_MODE: Bit rate mode such as CBR or VBR
|
||||
*/
|
||||
uint32_t ctl_value;
|
||||
};
|
||||
|
||||
struct aac_abr_control_t {
|
||||
bool is_abr_enabled;
|
||||
struct quality_level_to_bitrate_info level_to_bitrate_map;
|
||||
};
|
||||
|
||||
typedef struct audio_aac_encoder_config_s {
|
||||
uint32_t enc_mode; /* LC, SBR, PS */
|
||||
uint16_t format_flag; /* RAW, ADTS */
|
||||
uint16_t channels; /* 1-Mono, 2-Stereo */
|
||||
uint32_t sampling_rate;
|
||||
uint32_t bitrate;
|
||||
uint32_t bits_per_sample;
|
||||
struct aac_frame_size_control_t frame_ctl;
|
||||
uint8_t size_control_struct;
|
||||
struct aac_frame_size_control_t* frame_ctl_ptr;
|
||||
uint8_t abr_size_control_struct;
|
||||
struct aac_abr_control_t* abr_ctl_ptr;
|
||||
} audio_aac_encoder_config_t;
|
||||
|
||||
/* Information about BT SBC encoder configuration
|
||||
* This data is used between audio HAL module and
|
||||
* BT IPC library to configure DSP encoder
|
||||
*/
|
||||
typedef struct audio_sbc_encoder_config_s {
|
||||
uint32_t subband; /* 4, 8 */
|
||||
uint32_t blk_len; /* 4, 8, 12, 16 */
|
||||
uint16_t sampling_rate; /* 44.1khz,48khz */
|
||||
uint8_t channels; /* 0(Mono),1(Dual_mono),2(Stereo),3(JS) */
|
||||
uint8_t alloc; /* 0(Loudness),1(SNR) */
|
||||
uint8_t min_bitpool; /* 2 */
|
||||
uint8_t max_bitpool; /* 53(44.1khz),51 (48khz) */
|
||||
uint32_t bitrate; /* 320kbps to 512kbps */
|
||||
uint32_t bits_per_sample;
|
||||
} audio_sbc_encoder_config_t;
|
||||
|
||||
/* Information about BT CELT encoder configuration
|
||||
* This data is used between audio HAL module and
|
||||
* BT IPC library to configure DSP encoder
|
||||
*/
|
||||
typedef struct audio_celt_encoder_config_s {
|
||||
uint32_t sampling_rate; /* 32000 - 48000, 48000 */
|
||||
uint16_t channels; /* 1-Mono, 2-Stereo, 2 */
|
||||
uint16_t frame_size; /* 64-128-256-512, 512 */
|
||||
uint16_t complexity; /* 0-10, 1 */
|
||||
uint16_t prediction_mode; /* 0-1-2, 0 */
|
||||
uint16_t vbr_flag; /* 0-1, 0 */
|
||||
uint32_t bitrate; /* 32000 - 1536000, 139500 */
|
||||
uint32_t bits_per_sample;
|
||||
} audio_celt_encoder_config_t;
|
||||
|
||||
/* Information about BT LDAC encoder configuration
|
||||
* This data is used between audio HAL module and
|
||||
* BT IPC library to configure DSP encoder
|
||||
*/
|
||||
typedef struct audio_ldac_encoder_config_s {
|
||||
uint32_t sampling_rate; /* 44100,48000,88200,96000 */
|
||||
uint32_t bit_rate; /* 303000,606000,909000(in bits per second) */
|
||||
uint16_t channel_mode; /* 0, 4, 2, 1 */
|
||||
uint16_t mtu; /* 679 */
|
||||
uint32_t bits_per_sample;
|
||||
bool is_abr_enabled;
|
||||
struct quality_level_to_bitrate_info level_to_bitrate_map;
|
||||
} audio_ldac_encoder_config_t;
|
||||
|
||||
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
|
||||
/* Information about BT SS SBC encoder configuration
|
||||
* This data is used between audio HAL module and
|
||||
* BT IPC library to configure DSP encoder
|
||||
*/
|
||||
typedef struct audio_ss_sbc_encoder_config_s {
|
||||
uint32_t subband; /* 4, 8 */
|
||||
uint32_t blk_len; /* 4, 8, 12, 16 */
|
||||
uint16_t sampling_rate; /* 44.1khz,48khz */
|
||||
uint8_t channels; /* 0(Mono),1(Dual_mono),2(Stereo),3(JS) */
|
||||
uint8_t alloc; /* 0(Loudness),1(SNR) */
|
||||
uint8_t min_bitpool; /* 2 */
|
||||
uint8_t max_bitpool; /* 53(44.1khz),51 (48khz) */
|
||||
uint32_t bitrate; /* 320kbps to 512kbps */
|
||||
uint32_t bits_per_sample;
|
||||
bool is_abr_enabled;
|
||||
#ifdef QCA_OFFLOAD
|
||||
struct quality_level_to_bitrate_info level_to_bitrate_map;
|
||||
#endif
|
||||
} audio_ss_sbc_encoder_config_t;
|
||||
|
||||
// [ADD_FOR_SAMSUNG - For samsung bt codec
|
||||
/* Information about BT SCALABLE encoder configuration
|
||||
* This data is used between audio HAL module and
|
||||
* BT IPC library to configure DSP encoder
|
||||
*/
|
||||
typedef struct audio_ssc_encoder_config_s {
|
||||
uint32_t sampling_rate;
|
||||
uint8_t channels;
|
||||
uint32_t bitrate;
|
||||
uint32_t bits_per_sample;
|
||||
bool is_abr_enabled;
|
||||
#ifdef QCA_OFFLOAD
|
||||
struct quality_level_to_bitrate_info level_to_bitrate_map;
|
||||
#endif
|
||||
} audio_ssc_encoder_config_t;
|
||||
|
||||
enum SS_CodecType : uint32_t {
|
||||
SSC = 0x20,
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* _BT_PLUGIN_BUNDLE_H_ */
|
||||
163
qcom/opensource/pal/plugins/codecs/bt_intf.h
Normal file
163
qcom/opensource/pal/plugins/codecs/bt_intf.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2021, 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.
|
||||
*
|
||||
* Changes from Qualcomm Innovation Center are provided under the following license:
|
||||
*
|
||||
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef _BT_PLUGIN_INTF_H_
|
||||
#define _BT_PLUGIN_INTF_H_
|
||||
|
||||
// import data definition expected from Spf
|
||||
#include <ar_osal_types.h>
|
||||
#include <common_enc_dec_api.h>
|
||||
#include <media_fmt_api.h>
|
||||
|
||||
#include "SecProductFeature_BLUETOOTH.h"
|
||||
|
||||
/*
|
||||
* Below enum values are extended from audio_base.h to
|
||||
* to keep encoder and decoder type local to bthost_ipc
|
||||
* and audio_hal as these are intended only for handshake
|
||||
* between IPC lib and Audio HAL.
|
||||
*/
|
||||
typedef enum {
|
||||
CODEC_TYPE_INVALID = 0xFFFFFFFFu,
|
||||
CODEC_TYPE_AAC = 0x04000000u,
|
||||
CODEC_TYPE_SBC = 0x1F000000u,
|
||||
CODEC_TYPE_APTX = 0x20000000u,
|
||||
CODEC_TYPE_APTX_HD = 0x21000000u,
|
||||
CODEC_TYPE_APTX_DUAL_MONO = 0x22000000u,
|
||||
CODEC_TYPE_LDAC = 0x23000000u,
|
||||
CODEC_TYPE_CELT = 0x24000000u,
|
||||
CODEC_TYPE_APTX_AD = 0x25000000u,
|
||||
CODEC_TYPE_APTX_AD_SPEECH = 0x26000000u,
|
||||
CODEC_TYPE_RVP = 0x28000000u, // SS_BT_HFP - H_127 : RVP
|
||||
CODEC_TYPE_LC3 = 0x2B000000u,
|
||||
CODEC_TYPE_PCM = 0x1u,
|
||||
CODEC_TYPE_APTX_AD_QLEA = 0x30000000u,
|
||||
CODEC_TYPE_APTX_AD_R4 = 0x31000000u,
|
||||
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
|
||||
CODEC_TYPE_SSC = 0x27000000UL,
|
||||
#endif
|
||||
} codec_format_t;
|
||||
|
||||
/*
|
||||
* Update the below lookup table as well when new codec formats get added
|
||||
* This will be used by Payload Builder to popualte the Graph KVs
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
#include <map>
|
||||
#include <string>
|
||||
const std::map<uint32_t, std::string> btCodecFormatLUT {
|
||||
{CODEC_TYPE_INVALID, std::string{ "CODEC_TYPE_INVALID"} },
|
||||
{CODEC_TYPE_AAC, std::string{ "CODEC_TYPE_AAC"} },
|
||||
{CODEC_TYPE_SBC, std::string{ "CODEC_TYPE_SBC"} },
|
||||
{CODEC_TYPE_APTX, std::string{ "CODEC_TYPE_APTX"} },
|
||||
{CODEC_TYPE_APTX_HD, std::string{ "CODEC_TYPE_APTX_HD"} },
|
||||
{CODEC_TYPE_APTX_DUAL_MONO, std::string{ "CODEC_TYPE_APTX_DUAL_MONO"} },
|
||||
{CODEC_TYPE_LDAC, std::string{ "CODEC_TYPE_LDAC"} },
|
||||
{CODEC_TYPE_CELT, std::string{ "CODEC_TYPE_CELT"} },
|
||||
{CODEC_TYPE_APTX_AD, std::string{ "CODEC_TYPE_APTX_AD"} },
|
||||
{CODEC_TYPE_APTX_AD_SPEECH, std::string{ "CODEC_TYPE_APTX_AD_SPEECH"} },
|
||||
{CODEC_TYPE_RVP, std::string{ "CODEC_TYPE_RVP"} }, // SS_BT_HFP - H_127 : RVP
|
||||
{CODEC_TYPE_LC3, std::string{ "CODEC_TYPE_LC3"} },
|
||||
{CODEC_TYPE_PCM, std::string{ "CODEC_TYPE_PCM"} },
|
||||
{CODEC_TYPE_APTX_AD_QLEA, std::string{ "CODEC_TYPE_APTX_AD_QLEA"} },
|
||||
{CODEC_TYPE_APTX_AD_R4, std::string{ "CODEC_TYPE_APTX_AD_R4"} },
|
||||
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
|
||||
{CODEC_TYPE_SSC, std::string{ "CODEC_TYPE_SSC"} },
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ENC = 1,
|
||||
DEC
|
||||
} codec_type;
|
||||
|
||||
typedef enum {
|
||||
V1=1,
|
||||
V2
|
||||
}codec_version_t;
|
||||
|
||||
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
|
||||
#define DEFAULT_SINK_LATENCY_SBC 100
|
||||
#define DEFAULT_SINK_LATENCY_SSC 160
|
||||
#else
|
||||
#define DEFAULT_SINK_LATENCY_SBC 140
|
||||
#endif
|
||||
#define DEFAULT_SINK_LATENCY_AAC 180
|
||||
#define DEFAULT_SINK_LATENCY_CELT 180
|
||||
#define DEFAULT_SINK_LATENCY_LDAC 180
|
||||
#ifdef SEC_PRODUCT_FEATURE_BLUETOOTH_SUPPORT_A2DP_OFFLOAD
|
||||
#define DEFAULT_SINK_LATENCY_APTX 110
|
||||
#else
|
||||
#define DEFAULT_SINK_LATENCY_APTX 160
|
||||
#endif
|
||||
#define DEFAULT_SINK_LATENCY_APTX_HD 180
|
||||
#define DEFAULT_SINK_LATENCY 200
|
||||
|
||||
/* encoder payload sent for BT device */
|
||||
typedef struct custom_block_s {
|
||||
uint32_t param_id;
|
||||
uint32_t payload_sz;
|
||||
uint8_t *payload;
|
||||
} custom_block_t;
|
||||
|
||||
typedef struct bt_enc_payload {
|
||||
uint32_t channel_count;
|
||||
uint32_t bit_format;
|
||||
uint32_t sample_rate;
|
||||
bool is_abr_enabled;
|
||||
uint32_t num_blks;
|
||||
bool is_enc_config_set;
|
||||
bool is_dec_config_set;
|
||||
codec_version_t codec_version;
|
||||
custom_block_t *blocks[];
|
||||
} bt_enc_payload_t;
|
||||
|
||||
typedef struct bt_codec_library_s bt_codec_t;
|
||||
|
||||
struct bt_codec_library_s {
|
||||
const char *name;
|
||||
uint32_t codecFmt;
|
||||
codec_type direction;
|
||||
bt_enc_payload_t *payload;
|
||||
int (*plugin_populate_payload)(bt_codec_t *codec, void *src, void **dst);
|
||||
uint64_t (*plugin_get_codec_latency)(bt_codec_t *codec);
|
||||
int (*plugin_query_num_codecs)(bt_codec_t *codec);
|
||||
void (*close_plugin) (bt_codec_t *codec);
|
||||
};
|
||||
|
||||
typedef int (*config_fn_t) (bt_codec_t *codec, void *src, void **dst);
|
||||
typedef int (*open_fn_t) (bt_codec_t **codec, uint32_t codecFmt, codec_type direction);
|
||||
|
||||
#endif /* _BT_PLUGIN_INTF_H_ */
|
||||
Reference in New Issue
Block a user