audio: Changes to support Aptx decoder in offload mode
Add support to send license key value and bt device address
to DSP. Add Aptx format related changes. Also add support for
struct based set params using set api.
CRs-Fixed: 1081424
Change-Id: I2877239e61d3841e6ae90af2d39fb0b93cc2b6db
diff --git a/hal/Makefile.am b/hal/Makefile.am
index ba53446..e72d350 100644
--- a/hal/Makefile.am
+++ b/hal/Makefile.am
@@ -148,6 +148,10 @@
c_sources += audio_extn/gef.c
endif
+if APTX_DECODER
+AM_CFLAGS += -DAPTX_DECODER_ENABLED
+endif
+
h_sources = audio_extn/audio_defs.h \
audio_extn/audio_extn.h \
audio_hw.h \
diff --git a/hal/audio_extn/audio_defs.h b/hal/audio_extn/audio_defs.h
index 94b43ba..ae90cb3 100644
--- a/hal/audio_extn/audio_defs.h
+++ b/hal/audio_extn/audio_defs.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2015, 2017, 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
@@ -128,14 +128,26 @@
uint16_t gain_step;
};
+struct aptx_dec_bt_addr {
+ uint32_t nap;
+ uint32_t uap;
+ uint32_t lap;
+};
+
+struct aptx_dec_param {
+ struct aptx_dec_bt_addr bt_addr;
+};
+
typedef union {
struct source_tracking_param st_params;
struct sound_focus_param sf_params;
+ struct aptx_dec_param aptx_params;
} audio_extn_param_payload;
typedef enum {
AUDIO_EXTN_PARAM_SOURCE_TRACK,
- AUDIO_EXTN_PARAM_SOUND_FOCUS
+ AUDIO_EXTN_PARAM_SOUND_FOCUS,
+ AUDIO_EXTN_PARAM_APTX_DEC
} audio_extn_param_id;
#endif /* AUDIO_DEFS_H */
diff --git a/hal/audio_extn/audio_extn.c b/hal/audio_extn/audio_extn.c
index fe6c9a4..5a244e5 100644
--- a/hal/audio_extn/audio_extn.c
+++ b/hal/audio_extn/audio_extn.c
@@ -66,6 +66,7 @@
bool vbat_enabled;
bool hifi_audio_enabled;
bool ras_enabled;
+ struct aptx_dec_bt_addr addr;
};
static struct audio_extn_module aextnmod;
@@ -77,6 +78,7 @@
/* Query offload playback instances count */
#define AUDIO_PARAMETER_OFFLOAD_NUM_ACTIVE "offload_num_active"
#define AUDIO_PARAMETER_HPX "HPX"
+#define AUDIO_PARAMETER_APTX_DEC_BT_ADDR "bt_addr"
/*
* update sysfs node hdmi_audio_cb to enable notification acknowledge feature
@@ -771,8 +773,12 @@
aextnmod.hpx_enabled = 0;
aextnmod.vbat_enabled = 0;
aextnmod.hifi_audio_enabled = 0;
+ aextnmod.addr.nap = 0;
+ aextnmod.addr.uap = 0;
+ aextnmod.addr.lap = 0;
audio_extn_dolby_set_license(adev);
+ audio_extn_aptx_dec_set_license(adev);
}
void audio_extn_set_parameters(struct audio_device *adev,
@@ -800,6 +806,7 @@
audio_extn_qaf_set_parameters(adev, parms);
if (adev->offload_effects_set_parameters != NULL)
adev->offload_effects_set_parameters(parms);
+ audio_extn_set_aptx_dec_bt_addr(adev, parms);
}
void audio_extn_get_parameters(const struct audio_device *adev,
@@ -1219,3 +1226,83 @@
update_params);
}
}
+
+#ifdef APTX_DECODER_ENABLED
+static void audio_extn_aptx_dec_set_license(struct audio_device *adev)
+{
+ int ret, key = 0;
+ char value[128] = {0};
+ struct mixer_ctl *ctl;
+ const char *mixer_ctl_name = "APTX Dec License";
+
+ ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name);
+ if (!ctl) {
+ ALOGE("%s: Could not get ctl for mixer cmd - %s",
+ __func__, mixer_ctl_name);
+ return;
+ }
+ key = platform_get_meta_info_key_from_list(adev->platform, "aptx");
+
+ ALOGD("%s Setting APTX License with key:0x%x",__func__, key);
+ ret = mixer_ctl_set_value(ctl, 0, key);
+ if (ret)
+ ALOGE("%s: cannot set license, error:%d",__func__, ret);
+}
+
+static void audio_extn_set_aptx_dec_bt_addr(struct audio_device *adev, struct str_parms *parms)
+{
+ int ret = 0;
+ char value[256];
+
+ ret = str_parms_get_str(parms, AUDIO_PARAMETER_APTX_DEC_BT_ADDR, value,
+ sizeof(value));
+ if (ret >= 0) {
+ audio_extn_parse_aptx_dec_bt_addr(value);
+ }
+}
+
+int audio_extn_set_aptx_dec_params(struct aptx_dec_param *payload)
+{
+ struct aptx_dec_param *aptx_cfg = payload;
+
+ aextnmod.addr.nap = aptx_cfg->bt_addr.nap;
+ aextnmod.addr.uap = aptx_cfg->bt_addr.uap;
+ aextnmod.addr.lap = aptx_cfg->bt_addr.lap;
+}
+
+static void audio_extn_parse_aptx_dec_bt_addr(char *value)
+{
+ int ba[6];
+ char *str, *tok;
+ uint32_t addr[3];
+ int i = 0;
+
+ ALOGV("%s: value %s", __func__, value);
+ tok = strtok_r(value, ":", &str);
+ while (tok != NULL) {
+ ba[i] = strtol(tok, NULL, 16);
+ i++;
+ tok = strtok_r(NULL, ":", &str);
+ }
+ addr[0] = (ba[0] << 8) | ba[1];
+ addr[1] = ba[2];
+ addr[2] = (ba[3] << 16) | (ba[4] << 8) | ba[5];
+
+ aextnmod.addr.nap = addr[0];
+ aextnmod.addr.uap = addr[1];
+ aextnmod.addr.lap = addr[2];
+}
+
+void audio_extn_send_aptx_dec_bt_addr_to_dsp(struct stream_out *out)
+{
+ char mixer_ctl_name[128];
+ struct mixer_ctl *ctl;
+ uint32_t addr[3];
+
+ ALOGV("%s", __func__);
+ out->compr_config.codec->options.aptx_dec.nap = aextnmod.addr.nap;
+ out->compr_config.codec->options.aptx_dec.uap = aextnmod.addr.uap;
+ out->compr_config.codec->options.aptx_dec.lap = aextnmod.addr.lap;
+}
+
+#endif //APTX_DECODER_ENABLED
diff --git a/hal/audio_extn/audio_extn.h b/hal/audio_extn/audio_extn.h
index 6eb3f76..dab53ed 100644
--- a/hal/audio_extn/audio_extn.h
+++ b/hal/audio_extn/audio_extn.h
@@ -801,4 +801,18 @@
struct sound_focus_param *payload);
#endif
+#ifndef APTX_DECODER_ENABLED
+#define audio_extn_aptx_dec_set_license(adev); (0)
+#define audio_extn_set_aptx_dec_bt_addr(adev, parms); (0)
+#define audio_extn_send_aptx_dec_bt_addr_to_dsp(out); (0)
+#define audio_extn_parse_aptx_dec_bt_addr(value); (0)
+#define audio_extn_set_aptx_dec_params(payload); (0)
+#else
+static void audio_extn_aptx_dec_set_license(struct audio_device *adev);
+static void audio_extn_set_aptx_dec_bt_addr(struct audio_device *adev, struct str_parms *parms);
+void audio_extn_send_aptx_dec_bt_addr_to_dsp(struct stream_out *out);
+static void audio_extn_parse_aptx_dec_bt_addr(char *value);
+int audio_extn_set_aptx_dec_params(struct aptx_dec_param *payload);
+#endif
+
#endif /* AUDIO_EXTN_H */
diff --git a/hal/audio_extn/utils.c b/hal/audio_extn/utils.c
index 17fe4c9..7a4a0ed 100644
--- a/hal/audio_extn/utils.c
+++ b/hal/audio_extn/utils.c
@@ -151,6 +151,7 @@
STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_LC),
STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V1),
STRING_TO_ENUM(AUDIO_FORMAT_AAC_LATM_HE_V2),
+ STRING_TO_ENUM(AUDIO_FORMAT_APTX),
#endif
};
@@ -1160,6 +1161,9 @@
case AUDIO_FORMAT_DSD:
id = SND_AUDIOCODEC_DSD;
break;
+ case AUDIO_FORMAT_APTX:
+ id = SND_AUDIOCODEC_APTX;
+ break;
default:
ALOGE("%s: Unsupported audio format :%x", __func__, format);
}
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index d7b5f3a..e554d86 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -521,7 +521,8 @@
format == AUDIO_FORMAT_DSD ||
format == AUDIO_FORMAT_VORBIS ||
format == AUDIO_FORMAT_WMA ||
- format == AUDIO_FORMAT_WMA_PRO)
+ format == AUDIO_FORMAT_WMA_PRO ||
+ format == AUDIO_FORMAT_APTX)
return true;
return false;
@@ -4052,6 +4053,10 @@
if (config->offload_info.format == AUDIO_FORMAT_FLAC)
out->compr_config.codec->options.flac_dec.sample_size = AUDIO_OUTPUT_BIT_WIDTH;
+ if (config->offload_info.format == AUDIO_FORMAT_APTX) {
+ audio_extn_send_aptx_dec_bt_addr_to_dsp(out);
+ }
+
if (flags & AUDIO_OUTPUT_FLAG_NON_BLOCKING)
out->non_blocking = 1;
diff --git a/hal/audio_hw_extn_api.c b/hal/audio_hw_extn_api.c
index 39d81fb..f36d85d 100644
--- a/hal/audio_hw_extn_api.c
+++ b/hal/audio_hw_extn_api.c
@@ -104,6 +104,9 @@
ret = audio_extn_set_soundfocus_data(dev,
(struct sound_focus_param *)payload);
break;
+ case AUDIO_EXTN_PARAM_APTX_DEC:
+ audio_extn_set_aptx_dec_params((struct aptx_dec_param *)payload);
+ break;
default:
ALOGE("%s::INVALID PARAM ID:%d\n",__func__,param_id);
ret = -EINVAL;