Loading Android.mk +1 −1 Original line number Diff line number Diff line # TODO: Find a better way to separate build configs for ADP vs non-ADP devices ifneq ($(TARGET_BOARD_AUTO),true) ifneq ($(filter msm8960 msm8226 msm8x26 msm8x84 msm8084 msm8992 msm8994 msm8996 msm8909 msm8952 msm8998 sdm845 sdm710 sm8150,$(TARGET_BOARD_PLATFORM)),) ifneq ($(filter msm8960 msm8226 msm8x26 msm8x84 msm8084 msm8992 msm8994 msm8996 msm8909 msm8952 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),) MY_LOCAL_PATH := $(call my-dir) Loading hal/Android.mk +11 −3 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ AUDIO_PLATFORM := $(TARGET_BOARD_PLATFORM) ifneq ($(filter msm8960,$(TARGET_BOARD_PLATFORM)),) LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="2" endif ifneq ($(filter msm8974 msm8226 msm8084 msm8992 msm8994 msm8996 msm8998 sdm845 sdm710 sm8150,$(TARGET_BOARD_PLATFORM)),) ifneq ($(filter msm8974 msm8226 msm8084 msm8992 msm8994 msm8996 msm8998 sdm845 sdm710 msmnile,$(TARGET_BOARD_PLATFORM)),) # B-family platform uses msm8974 code base AUDIO_PLATFORM = msm8974 ifneq ($(filter msm8974,$(TARGET_BOARD_PLATFORM)),) Loading Loading @@ -62,7 +62,7 @@ ifneq ($(filter sdm710,$(TARGET_BOARD_PLATFORM)),) LOCAL_CFLAGS += -DINCALL_STEREO_CAPTURE_ENABLED MULTIPLE_HW_VARIANTS_ENABLED := true endif ifneq ($(filter sm8150,$(TARGET_BOARD_PLATFORM)),) ifneq ($(filter msmnile,$(TARGET_BOARD_PLATFORM)),) LOCAL_CFLAGS := -DPLATFORM_SM8150 LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="4" LOCAL_CFLAGS += -DINCALL_MUSIC_ENABLED Loading Loading @@ -198,7 +198,6 @@ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_SND_MONITOR)), true) LOCAL_SRC_FILES += audio_extn/sndmonitor.c endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_USB_SERVICE_INTERVAL)), true) LOCAL_CFLAGS += -DUSB_SERVICE_INTERVAL_ENABLED endif Loading @@ -208,6 +207,11 @@ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_MAXX_AUDIO)), true) LOCAL_SRC_FILES += audio_extn/maxxaudio.c endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_AUDIO_ZOOM)), true) LOCAL_CFLAGS += -DAUDIOZOOM_QDSP_ENABLED LOCAL_SRC_FILES += audio_extn/audiozoom.c endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_24BITS_CAMCORDER)), true) LOCAL_CFLAGS += -DENABLED_24BITS_CAMCORDER endif Loading @@ -216,6 +220,10 @@ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_BG_CAL)),true) LOCAL_CFLAGS += -DBG_CODEC_CAL endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_DYNAMIC_ECNS)),true) LOCAL_CFLAGS += -DDYNAMIC_ECNS_ENABLED endif LOCAL_SHARED_LIBRARIES += libbase libhidlbase libhwbinder libutils android.hardware.power@1.2 liblog LOCAL_SRC_FILES += audio_perf.cpp Loading hal/audio_extn/a2dp.c +36 −19 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ #ifdef A2DP_OFFLOAD_ENABLED #define BT_IPC_LIB_NAME "libbthost_if.so" #define BTAUDIO_OFFLOAD_LIB_NAME "btaudio_offload_if.so" // Media format definitions #define ENC_MEDIA_FMT_AAC 0x00010DA6 Loading Loading @@ -78,6 +79,7 @@ // System properties used for A2DP Offload #define SYSPROP_A2DP_OFFLOAD_SUPPORTED "ro.bluetooth.a2dp_offload.supported" #define SYSPROP_A2DP_OFFLOAD_DISABLED "persist.bluetooth.a2dp_offload.disabled" #define SYSPROP_BLUETOOTH_AUDIO_HAL_DISABLED "persist.bluetooth.bluetooth_audio_hal.disabled" #define SYSPROP_A2DP_CODEC_LATENCIES "vendor.audio.a2dp.codec.latency" // Default encoder bit width Loading Loading @@ -141,6 +143,7 @@ typedef void * (*audio_get_codec_config_t)(uint8_t *multicast_status, uint8_t *n enc_codec_t *codec_type); typedef int (*audio_check_a2dp_ready_t)(void); typedef int (*audio_is_scrambling_enabled_t)(void); typedef uint16_t (*audio_get_a2dp_sink_latency_t)(void); enum A2DP_STATE { A2DP_STATE_CONNECTED, Loading Loading @@ -221,6 +224,8 @@ struct a2dp_data { audio_check_a2dp_ready_t audio_check_a2dp_ready; /* Check if scrambling is enabled on BTSoC */ audio_is_scrambling_enabled_t audio_is_scrambling_enabled; /* Get sink latency from Bluetooth stack */ audio_get_a2dp_sink_latency_t audio_get_a2dp_sink_latency; /* Internal A2DP state identifier */ enum A2DP_STATE bt_state; /* A2DP codec type configured */ Loading Loading @@ -673,8 +678,9 @@ fail: static int open_a2dp_output() { int ret = 0; ALOGD("%s: Open A2DP output start", __func__); bool hal_v2_enabled = !property_get_bool(SYSPROP_BLUETOOTH_AUDIO_HAL_DISABLED, false); if (a2dp.bt_state != A2DP_STATE_DISCONNECTED) { ALOGD("%s: Called A2DP open with improper state, Ignoring request state %d", Loading @@ -683,9 +689,13 @@ static int open_a2dp_output() } if (a2dp.bt_lib_handle == NULL) { ALOGD("%s: Requesting for Bluetooth IPC lib handle", __func__); ALOGD("%s: Requesting for Bluetooth IPC lib handle [%s]", __func__, hal_v2_enabled ? BTAUDIO_OFFLOAD_LIB_NAME : BT_IPC_LIB_NAME); if (hal_v2_enabled) { a2dp.bt_lib_handle = dlopen(BTAUDIO_OFFLOAD_LIB_NAME, RTLD_NOW); } else { a2dp.bt_lib_handle = dlopen(BT_IPC_LIB_NAME, RTLD_NOW); } if (a2dp.bt_lib_handle == NULL) { ret = -errno; ALOGE("%s: DLOPEN failed for %s errno %d strerror %s", __func__, Loading Loading @@ -713,6 +723,8 @@ static int open_a2dp_output() dlsym(a2dp.bt_lib_handle,"audio_check_a2dp_ready"); a2dp.audio_is_scrambling_enabled = (audio_is_scrambling_enabled_t) dlsym(a2dp.bt_lib_handle,"audio_is_scrambling_enabled"); a2dp.audio_get_a2dp_sink_latency = (audio_get_a2dp_sink_latency_t) dlsym(a2dp.bt_lib_handle,"audio_get_a2dp_sink_latency"); } } Loading Loading @@ -1714,7 +1726,7 @@ void audio_extn_a2dp_init(void *adev) uint32_t audio_extn_a2dp_get_encoder_latency() { uint32_t latency = 0; uint32_t latency_ms = 0; int avsync_runtime_prop = 0; int sbc_offset = 0, aptx_offset = 0, aptxhd_offset = 0, aac_offset = 0, ldac_offset = 0; Loading @@ -1731,36 +1743,41 @@ uint32_t audio_extn_a2dp_get_encoder_latency() } } uint32_t slatency_ms = 0; if (a2dp.audio_get_a2dp_sink_latency && a2dp.bt_state != A2DP_STATE_DISCONNECTED) { slatency_ms = a2dp.audio_get_a2dp_sink_latency(); } switch (a2dp.bt_encoder_format) { case ENC_CODEC_TYPE_SBC: latency = (avsync_runtime_prop > 0) ? sbc_offset : ENCODER_LATENCY_SBC; latency += DEFAULT_SINK_LATENCY_SBC; latency_ms = (avsync_runtime_prop > 0) ? sbc_offset : ENCODER_LATENCY_SBC; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_SBC : slatency_ms; break; case ENC_CODEC_TYPE_APTX: latency = (avsync_runtime_prop > 0) ? aptx_offset : ENCODER_LATENCY_APTX; latency += DEFAULT_SINK_LATENCY_APTX; latency_ms = (avsync_runtime_prop > 0) ? aptx_offset : ENCODER_LATENCY_APTX; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_APTX : slatency_ms; break; case ENC_CODEC_TYPE_APTX_HD: latency = (avsync_runtime_prop > 0) ? aptxhd_offset : ENCODER_LATENCY_APTX_HD; latency += DEFAULT_SINK_LATENCY_APTX_HD; latency_ms = (avsync_runtime_prop > 0) ? aptxhd_offset : ENCODER_LATENCY_APTX_HD; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_APTX_HD : slatency_ms; break; case ENC_CODEC_TYPE_AAC: latency = (avsync_runtime_prop > 0) ? aac_offset : ENCODER_LATENCY_AAC; latency += DEFAULT_SINK_LATENCY_AAC; latency_ms = (avsync_runtime_prop > 0) ? aac_offset : ENCODER_LATENCY_AAC; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_AAC : slatency_ms; break; case ENC_CODEC_TYPE_LDAC: latency = (avsync_runtime_prop > 0) ? ldac_offset : ENCODER_LATENCY_LDAC; latency += DEFAULT_SINK_LATENCY_LDAC; latency_ms = (avsync_runtime_prop > 0) ? ldac_offset : ENCODER_LATENCY_LDAC; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_LDAC : slatency_ms; break; case ENC_CODEC_TYPE_PCM: latency = ENCODER_LATENCY_PCM; latency += DEFAULT_SINK_LATENCY_PCM; latency_ms = ENCODER_LATENCY_PCM; latency_ms += DEFAULT_SINK_LATENCY_PCM; break; default: latency = DEFAULT_ENCODER_LATENCY; latency_ms = DEFAULT_ENCODER_LATENCY; break; } return latency; return latency_ms; } int audio_extn_a2dp_get_parameters(struct str_parms *query, Loading hal/audio_extn/audio_extn.h +2 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ int audio_extn_hfp_set_mic_mute(struct audio_device *adev, bool state); #define audio_extn_usb_alive(adev) (false) #define audio_extn_usb_find_service_interval(m, p) ((m), (p), 0) /* fix unused warn */ #define audio_extn_usb_altset_for_service_interval(p, si, bw, sr, ch) (-1) #define audio_extn_usb_usbid() (NULL) #else void audio_extn_usb_init(void *adev); void audio_extn_usb_deinit(); Loading @@ -109,6 +110,7 @@ int audio_extn_usb_altset_for_service_interval(bool is_playback, uint32_t *bit_width, uint32_t *sample_rate, uint32_t *channel_count); char *audio_extn_usb_usbid(void); #endif Loading hal/audio_extn/audiozoom.c 0 → 100644 +257 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "audio_hw_audiozoom" /*#define LOG_NDEBUG 0*/ #include <errno.h> #include <log/log.h> #include <stdlib.h> #include <expat.h> #include <audio_hw.h> #include <system/audio.h> #include <platform_api.h> #include "audio_extn.h" #include "audiozoom.h" #include <resolv.h> #define AUDIOZOOM_PRESET_FILE "/vendor/etc/audiozoom.xml" typedef struct qdsp_audiozoom_cfg { uint32_t topo_id; uint32_t module_id; uint32_t instance_id; uint32_t zoom_param_id; uint32_t wide_param_id; uint32_t dir_param_id; uint32_t app_type; } qdsp_audiozoom_cfg_t; static qdsp_audiozoom_cfg_t qdsp_audiozoom; static void start_tag(void *userdata __unused, const XML_Char *tag_name, const XML_Char **attr) { uint32_t index = 0; if (!attr) { ALOGE("%s: NULL platform/tag_name/attr", __func__); return; } if (strcmp(tag_name, "topo") == 0) { if (strcmp(attr[0], "id") == 0) { if (attr[1]) qdsp_audiozoom.topo_id = atoi(attr[1]); } } else if (strcmp(tag_name, "module") == 0) { if (strcmp(attr[0], "id") == 0) { if (attr[1]) qdsp_audiozoom.module_id = atoi(attr[1]); } } else if (strcmp(tag_name, "param") == 0) { while (attr[index] != NULL) { if (strcmp(attr[index], "zoom_id") == 0) { index++; if (attr[index]) qdsp_audiozoom.zoom_param_id = atoi(attr[index]); else break; } else if (strcmp(attr[index], "wide_id") == 0) { index++; if (attr[index]) qdsp_audiozoom.wide_param_id = atoi(attr[index]); else break; } else if (strcmp(attr[index], "dir_id") == 0) { index++; if (attr[index]) qdsp_audiozoom.dir_param_id = atoi(attr[index]); else break; } index++; } } else if (strcmp(tag_name, "app_type") == 0) { if (strcmp(attr[0], "id") == 0) { if (attr[1]) qdsp_audiozoom.app_type = atoi(attr[1]); } } else if (strcmp(tag_name, "instance") == 0) { if (strcmp(attr[0], "id") == 0) { if (attr[1]) qdsp_audiozoom.instance_id = atoi(attr[1]); } } else { ALOGE("%s: %s is not a supported tag", __func__, tag_name); } return; } static void end_tag(void *userdata __unused, const XML_Char *tag_name) { if (strcmp(tag_name, "topo") == 0) { } else if (strcmp(tag_name, "module") == 0) { } else if (strcmp(tag_name, "param") == 0) { } else if (strcmp(tag_name, "app_type") == 0) { } else if (strcmp(tag_name, "instance") == 0) { } else { ALOGE("%s: %s is not a supported tag", __func__, tag_name); } } static int audio_extn_audiozoom_parse_info(const char *filename) { XML_Parser parser; FILE *file; int ret = 0; int bytes_read; void *buf; static const uint32_t kBufSize = 1024; file = fopen(filename, "r"); if (!file) { ALOGE("%s: Failed to open %s", __func__, filename); ret = -ENODEV; goto done; } parser = XML_ParserCreate(NULL); if (!parser) { ALOGE("%s: Failed to create XML parser!", __func__); ret = -ENODEV; goto err_close_file; } XML_SetElementHandler(parser, start_tag, end_tag); while (1) { buf = XML_GetBuffer(parser, kBufSize); if (buf == NULL) { ALOGE("%s: XML_GetBuffer failed", __func__); ret = -ENOMEM; goto err_free_parser; } bytes_read = fread(buf, 1, kBufSize, file); if (bytes_read < 0) { ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); ret = bytes_read; goto err_free_parser; } if (XML_ParseBuffer(parser, bytes_read, bytes_read == 0) == XML_STATUS_ERROR) { ALOGE("%s: XML_ParseBuffer failed, for %s", __func__, filename); ret = -EINVAL; goto err_free_parser; } if (bytes_read == 0) break; } err_free_parser: XML_ParserFree(parser); err_close_file: fclose(file); done: return ret; } int audio_extn_audiozoom_set_microphone_direction( struct stream_in *in, audio_microphone_direction_t dir) { (void)in; (void)dir; return 0; } static int audio_extn_audiozoom_set_microphone_field_dimension_zoom( struct stream_in *in, float zoom) { struct audio_device *adev = in->dev; struct str_parms *parms = str_parms_create(); /* The encoding process in b64_ntop represents 24-bit groups of input bits as output strings of 4 encoded characters. */ char data[((sizeof(zoom) + 2) / 3) * 4 + 1] = {0}; int32_t ret; if (zoom > 1.0 || zoom < 0) return -EINVAL; if (qdsp_audiozoom.topo_id == 0 || qdsp_audiozoom.module_id == 0 || qdsp_audiozoom.zoom_param_id == 0) return -ENOSYS; str_parms_add_int(parms, "cal_devid", in->device); str_parms_add_int(parms, "cal_apptype", in->app_type_cfg.app_type); str_parms_add_int(parms, "cal_topoid", qdsp_audiozoom.topo_id); str_parms_add_int(parms, "cal_moduleid", qdsp_audiozoom.module_id); str_parms_add_int(parms, "cal_instanceid", qdsp_audiozoom.instance_id); str_parms_add_int(parms, "cal_paramid", qdsp_audiozoom.zoom_param_id); ret = b64_ntop((uint8_t*)&zoom, sizeof(zoom), data, sizeof(data)); if (ret > 0) { str_parms_add_str(parms, "cal_data", data); platform_set_parameters(adev->platform, parms); } else { ALOGE("%s: failed to convert data to string, ret %d", __func__, ret); } str_parms_destroy(parms); return 0; } static int audio_extn_audiozoom_set_microphone_field_dimension_wide_angle( struct stream_in *in, float zoom) { (void)in; (void)zoom; return 0; } int audio_extn_audiozoom_set_microphone_field_dimension( struct stream_in *in, float zoom) { if (zoom > 1.0 || zoom < -1.0) return -EINVAL; if (zoom >= 0 && zoom <= 1.0) return audio_extn_audiozoom_set_microphone_field_dimension_zoom(in, zoom); if (zoom >= -1.0 && zoom <= 0) return audio_extn_audiozoom_set_microphone_field_dimension_wide_angle(in, zoom); return 0; } int audio_extn_audiozoom_init() { audio_extn_audiozoom_parse_info(AUDIOZOOM_PRESET_FILE); ALOGV("%s: topo_id=%d, module_id=%d, instance_id=%d, zoom__id=%d, dir_id=%d, app_type=%d", __func__, qdsp_audiozoom.topo_id, qdsp_audiozoom.module_id, qdsp_audiozoom.instance_id, qdsp_audiozoom.zoom_param_id, qdsp_audiozoom.dir_param_id,qdsp_audiozoom.app_type); return 0; } Loading
Android.mk +1 −1 Original line number Diff line number Diff line # TODO: Find a better way to separate build configs for ADP vs non-ADP devices ifneq ($(TARGET_BOARD_AUTO),true) ifneq ($(filter msm8960 msm8226 msm8x26 msm8x84 msm8084 msm8992 msm8994 msm8996 msm8909 msm8952 msm8998 sdm845 sdm710 sm8150,$(TARGET_BOARD_PLATFORM)),) ifneq ($(filter msm8960 msm8226 msm8x26 msm8x84 msm8084 msm8992 msm8994 msm8996 msm8909 msm8952 msm8998 sdm845 sdm710,$(TARGET_BOARD_PLATFORM)),) MY_LOCAL_PATH := $(call my-dir) Loading
hal/Android.mk +11 −3 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ AUDIO_PLATFORM := $(TARGET_BOARD_PLATFORM) ifneq ($(filter msm8960,$(TARGET_BOARD_PLATFORM)),) LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="2" endif ifneq ($(filter msm8974 msm8226 msm8084 msm8992 msm8994 msm8996 msm8998 sdm845 sdm710 sm8150,$(TARGET_BOARD_PLATFORM)),) ifneq ($(filter msm8974 msm8226 msm8084 msm8992 msm8994 msm8996 msm8998 sdm845 sdm710 msmnile,$(TARGET_BOARD_PLATFORM)),) # B-family platform uses msm8974 code base AUDIO_PLATFORM = msm8974 ifneq ($(filter msm8974,$(TARGET_BOARD_PLATFORM)),) Loading Loading @@ -62,7 +62,7 @@ ifneq ($(filter sdm710,$(TARGET_BOARD_PLATFORM)),) LOCAL_CFLAGS += -DINCALL_STEREO_CAPTURE_ENABLED MULTIPLE_HW_VARIANTS_ENABLED := true endif ifneq ($(filter sm8150,$(TARGET_BOARD_PLATFORM)),) ifneq ($(filter msmnile,$(TARGET_BOARD_PLATFORM)),) LOCAL_CFLAGS := -DPLATFORM_SM8150 LOCAL_CFLAGS += -DMAX_TARGET_SPECIFIC_CHANNEL_CNT="4" LOCAL_CFLAGS += -DINCALL_MUSIC_ENABLED Loading Loading @@ -198,7 +198,6 @@ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_SND_MONITOR)), true) LOCAL_SRC_FILES += audio_extn/sndmonitor.c endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_USB_SERVICE_INTERVAL)), true) LOCAL_CFLAGS += -DUSB_SERVICE_INTERVAL_ENABLED endif Loading @@ -208,6 +207,11 @@ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_MAXX_AUDIO)), true) LOCAL_SRC_FILES += audio_extn/maxxaudio.c endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_AUDIO_ZOOM)), true) LOCAL_CFLAGS += -DAUDIOZOOM_QDSP_ENABLED LOCAL_SRC_FILES += audio_extn/audiozoom.c endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_24BITS_CAMCORDER)), true) LOCAL_CFLAGS += -DENABLED_24BITS_CAMCORDER endif Loading @@ -216,6 +220,10 @@ ifeq ($(strip $(AUDIO_FEATURE_ENABLED_BG_CAL)),true) LOCAL_CFLAGS += -DBG_CODEC_CAL endif ifeq ($(strip $(AUDIO_FEATURE_ENABLED_DYNAMIC_ECNS)),true) LOCAL_CFLAGS += -DDYNAMIC_ECNS_ENABLED endif LOCAL_SHARED_LIBRARIES += libbase libhidlbase libhwbinder libutils android.hardware.power@1.2 liblog LOCAL_SRC_FILES += audio_perf.cpp Loading
hal/audio_extn/a2dp.c +36 −19 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ #ifdef A2DP_OFFLOAD_ENABLED #define BT_IPC_LIB_NAME "libbthost_if.so" #define BTAUDIO_OFFLOAD_LIB_NAME "btaudio_offload_if.so" // Media format definitions #define ENC_MEDIA_FMT_AAC 0x00010DA6 Loading Loading @@ -78,6 +79,7 @@ // System properties used for A2DP Offload #define SYSPROP_A2DP_OFFLOAD_SUPPORTED "ro.bluetooth.a2dp_offload.supported" #define SYSPROP_A2DP_OFFLOAD_DISABLED "persist.bluetooth.a2dp_offload.disabled" #define SYSPROP_BLUETOOTH_AUDIO_HAL_DISABLED "persist.bluetooth.bluetooth_audio_hal.disabled" #define SYSPROP_A2DP_CODEC_LATENCIES "vendor.audio.a2dp.codec.latency" // Default encoder bit width Loading Loading @@ -141,6 +143,7 @@ typedef void * (*audio_get_codec_config_t)(uint8_t *multicast_status, uint8_t *n enc_codec_t *codec_type); typedef int (*audio_check_a2dp_ready_t)(void); typedef int (*audio_is_scrambling_enabled_t)(void); typedef uint16_t (*audio_get_a2dp_sink_latency_t)(void); enum A2DP_STATE { A2DP_STATE_CONNECTED, Loading Loading @@ -221,6 +224,8 @@ struct a2dp_data { audio_check_a2dp_ready_t audio_check_a2dp_ready; /* Check if scrambling is enabled on BTSoC */ audio_is_scrambling_enabled_t audio_is_scrambling_enabled; /* Get sink latency from Bluetooth stack */ audio_get_a2dp_sink_latency_t audio_get_a2dp_sink_latency; /* Internal A2DP state identifier */ enum A2DP_STATE bt_state; /* A2DP codec type configured */ Loading Loading @@ -673,8 +678,9 @@ fail: static int open_a2dp_output() { int ret = 0; ALOGD("%s: Open A2DP output start", __func__); bool hal_v2_enabled = !property_get_bool(SYSPROP_BLUETOOTH_AUDIO_HAL_DISABLED, false); if (a2dp.bt_state != A2DP_STATE_DISCONNECTED) { ALOGD("%s: Called A2DP open with improper state, Ignoring request state %d", Loading @@ -683,9 +689,13 @@ static int open_a2dp_output() } if (a2dp.bt_lib_handle == NULL) { ALOGD("%s: Requesting for Bluetooth IPC lib handle", __func__); ALOGD("%s: Requesting for Bluetooth IPC lib handle [%s]", __func__, hal_v2_enabled ? BTAUDIO_OFFLOAD_LIB_NAME : BT_IPC_LIB_NAME); if (hal_v2_enabled) { a2dp.bt_lib_handle = dlopen(BTAUDIO_OFFLOAD_LIB_NAME, RTLD_NOW); } else { a2dp.bt_lib_handle = dlopen(BT_IPC_LIB_NAME, RTLD_NOW); } if (a2dp.bt_lib_handle == NULL) { ret = -errno; ALOGE("%s: DLOPEN failed for %s errno %d strerror %s", __func__, Loading Loading @@ -713,6 +723,8 @@ static int open_a2dp_output() dlsym(a2dp.bt_lib_handle,"audio_check_a2dp_ready"); a2dp.audio_is_scrambling_enabled = (audio_is_scrambling_enabled_t) dlsym(a2dp.bt_lib_handle,"audio_is_scrambling_enabled"); a2dp.audio_get_a2dp_sink_latency = (audio_get_a2dp_sink_latency_t) dlsym(a2dp.bt_lib_handle,"audio_get_a2dp_sink_latency"); } } Loading Loading @@ -1714,7 +1726,7 @@ void audio_extn_a2dp_init(void *adev) uint32_t audio_extn_a2dp_get_encoder_latency() { uint32_t latency = 0; uint32_t latency_ms = 0; int avsync_runtime_prop = 0; int sbc_offset = 0, aptx_offset = 0, aptxhd_offset = 0, aac_offset = 0, ldac_offset = 0; Loading @@ -1731,36 +1743,41 @@ uint32_t audio_extn_a2dp_get_encoder_latency() } } uint32_t slatency_ms = 0; if (a2dp.audio_get_a2dp_sink_latency && a2dp.bt_state != A2DP_STATE_DISCONNECTED) { slatency_ms = a2dp.audio_get_a2dp_sink_latency(); } switch (a2dp.bt_encoder_format) { case ENC_CODEC_TYPE_SBC: latency = (avsync_runtime_prop > 0) ? sbc_offset : ENCODER_LATENCY_SBC; latency += DEFAULT_SINK_LATENCY_SBC; latency_ms = (avsync_runtime_prop > 0) ? sbc_offset : ENCODER_LATENCY_SBC; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_SBC : slatency_ms; break; case ENC_CODEC_TYPE_APTX: latency = (avsync_runtime_prop > 0) ? aptx_offset : ENCODER_LATENCY_APTX; latency += DEFAULT_SINK_LATENCY_APTX; latency_ms = (avsync_runtime_prop > 0) ? aptx_offset : ENCODER_LATENCY_APTX; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_APTX : slatency_ms; break; case ENC_CODEC_TYPE_APTX_HD: latency = (avsync_runtime_prop > 0) ? aptxhd_offset : ENCODER_LATENCY_APTX_HD; latency += DEFAULT_SINK_LATENCY_APTX_HD; latency_ms = (avsync_runtime_prop > 0) ? aptxhd_offset : ENCODER_LATENCY_APTX_HD; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_APTX_HD : slatency_ms; break; case ENC_CODEC_TYPE_AAC: latency = (avsync_runtime_prop > 0) ? aac_offset : ENCODER_LATENCY_AAC; latency += DEFAULT_SINK_LATENCY_AAC; latency_ms = (avsync_runtime_prop > 0) ? aac_offset : ENCODER_LATENCY_AAC; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_AAC : slatency_ms; break; case ENC_CODEC_TYPE_LDAC: latency = (avsync_runtime_prop > 0) ? ldac_offset : ENCODER_LATENCY_LDAC; latency += DEFAULT_SINK_LATENCY_LDAC; latency_ms = (avsync_runtime_prop > 0) ? ldac_offset : ENCODER_LATENCY_LDAC; latency_ms += (slatency_ms == 0) ? DEFAULT_SINK_LATENCY_LDAC : slatency_ms; break; case ENC_CODEC_TYPE_PCM: latency = ENCODER_LATENCY_PCM; latency += DEFAULT_SINK_LATENCY_PCM; latency_ms = ENCODER_LATENCY_PCM; latency_ms += DEFAULT_SINK_LATENCY_PCM; break; default: latency = DEFAULT_ENCODER_LATENCY; latency_ms = DEFAULT_ENCODER_LATENCY; break; } return latency; return latency_ms; } int audio_extn_a2dp_get_parameters(struct str_parms *query, Loading
hal/audio_extn/audio_extn.h +2 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ int audio_extn_hfp_set_mic_mute(struct audio_device *adev, bool state); #define audio_extn_usb_alive(adev) (false) #define audio_extn_usb_find_service_interval(m, p) ((m), (p), 0) /* fix unused warn */ #define audio_extn_usb_altset_for_service_interval(p, si, bw, sr, ch) (-1) #define audio_extn_usb_usbid() (NULL) #else void audio_extn_usb_init(void *adev); void audio_extn_usb_deinit(); Loading @@ -109,6 +110,7 @@ int audio_extn_usb_altset_for_service_interval(bool is_playback, uint32_t *bit_width, uint32_t *sample_rate, uint32_t *channel_count); char *audio_extn_usb_usbid(void); #endif Loading
hal/audio_extn/audiozoom.c 0 → 100644 +257 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "audio_hw_audiozoom" /*#define LOG_NDEBUG 0*/ #include <errno.h> #include <log/log.h> #include <stdlib.h> #include <expat.h> #include <audio_hw.h> #include <system/audio.h> #include <platform_api.h> #include "audio_extn.h" #include "audiozoom.h" #include <resolv.h> #define AUDIOZOOM_PRESET_FILE "/vendor/etc/audiozoom.xml" typedef struct qdsp_audiozoom_cfg { uint32_t topo_id; uint32_t module_id; uint32_t instance_id; uint32_t zoom_param_id; uint32_t wide_param_id; uint32_t dir_param_id; uint32_t app_type; } qdsp_audiozoom_cfg_t; static qdsp_audiozoom_cfg_t qdsp_audiozoom; static void start_tag(void *userdata __unused, const XML_Char *tag_name, const XML_Char **attr) { uint32_t index = 0; if (!attr) { ALOGE("%s: NULL platform/tag_name/attr", __func__); return; } if (strcmp(tag_name, "topo") == 0) { if (strcmp(attr[0], "id") == 0) { if (attr[1]) qdsp_audiozoom.topo_id = atoi(attr[1]); } } else if (strcmp(tag_name, "module") == 0) { if (strcmp(attr[0], "id") == 0) { if (attr[1]) qdsp_audiozoom.module_id = atoi(attr[1]); } } else if (strcmp(tag_name, "param") == 0) { while (attr[index] != NULL) { if (strcmp(attr[index], "zoom_id") == 0) { index++; if (attr[index]) qdsp_audiozoom.zoom_param_id = atoi(attr[index]); else break; } else if (strcmp(attr[index], "wide_id") == 0) { index++; if (attr[index]) qdsp_audiozoom.wide_param_id = atoi(attr[index]); else break; } else if (strcmp(attr[index], "dir_id") == 0) { index++; if (attr[index]) qdsp_audiozoom.dir_param_id = atoi(attr[index]); else break; } index++; } } else if (strcmp(tag_name, "app_type") == 0) { if (strcmp(attr[0], "id") == 0) { if (attr[1]) qdsp_audiozoom.app_type = atoi(attr[1]); } } else if (strcmp(tag_name, "instance") == 0) { if (strcmp(attr[0], "id") == 0) { if (attr[1]) qdsp_audiozoom.instance_id = atoi(attr[1]); } } else { ALOGE("%s: %s is not a supported tag", __func__, tag_name); } return; } static void end_tag(void *userdata __unused, const XML_Char *tag_name) { if (strcmp(tag_name, "topo") == 0) { } else if (strcmp(tag_name, "module") == 0) { } else if (strcmp(tag_name, "param") == 0) { } else if (strcmp(tag_name, "app_type") == 0) { } else if (strcmp(tag_name, "instance") == 0) { } else { ALOGE("%s: %s is not a supported tag", __func__, tag_name); } } static int audio_extn_audiozoom_parse_info(const char *filename) { XML_Parser parser; FILE *file; int ret = 0; int bytes_read; void *buf; static const uint32_t kBufSize = 1024; file = fopen(filename, "r"); if (!file) { ALOGE("%s: Failed to open %s", __func__, filename); ret = -ENODEV; goto done; } parser = XML_ParserCreate(NULL); if (!parser) { ALOGE("%s: Failed to create XML parser!", __func__); ret = -ENODEV; goto err_close_file; } XML_SetElementHandler(parser, start_tag, end_tag); while (1) { buf = XML_GetBuffer(parser, kBufSize); if (buf == NULL) { ALOGE("%s: XML_GetBuffer failed", __func__); ret = -ENOMEM; goto err_free_parser; } bytes_read = fread(buf, 1, kBufSize, file); if (bytes_read < 0) { ALOGE("%s: fread failed, bytes read = %d", __func__, bytes_read); ret = bytes_read; goto err_free_parser; } if (XML_ParseBuffer(parser, bytes_read, bytes_read == 0) == XML_STATUS_ERROR) { ALOGE("%s: XML_ParseBuffer failed, for %s", __func__, filename); ret = -EINVAL; goto err_free_parser; } if (bytes_read == 0) break; } err_free_parser: XML_ParserFree(parser); err_close_file: fclose(file); done: return ret; } int audio_extn_audiozoom_set_microphone_direction( struct stream_in *in, audio_microphone_direction_t dir) { (void)in; (void)dir; return 0; } static int audio_extn_audiozoom_set_microphone_field_dimension_zoom( struct stream_in *in, float zoom) { struct audio_device *adev = in->dev; struct str_parms *parms = str_parms_create(); /* The encoding process in b64_ntop represents 24-bit groups of input bits as output strings of 4 encoded characters. */ char data[((sizeof(zoom) + 2) / 3) * 4 + 1] = {0}; int32_t ret; if (zoom > 1.0 || zoom < 0) return -EINVAL; if (qdsp_audiozoom.topo_id == 0 || qdsp_audiozoom.module_id == 0 || qdsp_audiozoom.zoom_param_id == 0) return -ENOSYS; str_parms_add_int(parms, "cal_devid", in->device); str_parms_add_int(parms, "cal_apptype", in->app_type_cfg.app_type); str_parms_add_int(parms, "cal_topoid", qdsp_audiozoom.topo_id); str_parms_add_int(parms, "cal_moduleid", qdsp_audiozoom.module_id); str_parms_add_int(parms, "cal_instanceid", qdsp_audiozoom.instance_id); str_parms_add_int(parms, "cal_paramid", qdsp_audiozoom.zoom_param_id); ret = b64_ntop((uint8_t*)&zoom, sizeof(zoom), data, sizeof(data)); if (ret > 0) { str_parms_add_str(parms, "cal_data", data); platform_set_parameters(adev->platform, parms); } else { ALOGE("%s: failed to convert data to string, ret %d", __func__, ret); } str_parms_destroy(parms); return 0; } static int audio_extn_audiozoom_set_microphone_field_dimension_wide_angle( struct stream_in *in, float zoom) { (void)in; (void)zoom; return 0; } int audio_extn_audiozoom_set_microphone_field_dimension( struct stream_in *in, float zoom) { if (zoom > 1.0 || zoom < -1.0) return -EINVAL; if (zoom >= 0 && zoom <= 1.0) return audio_extn_audiozoom_set_microphone_field_dimension_zoom(in, zoom); if (zoom >= -1.0 && zoom <= 0) return audio_extn_audiozoom_set_microphone_field_dimension_wide_angle(in, zoom); return 0; } int audio_extn_audiozoom_init() { audio_extn_audiozoom_parse_info(AUDIOZOOM_PRESET_FILE); ALOGV("%s: topo_id=%d, module_id=%d, instance_id=%d, zoom__id=%d, dir_id=%d, app_type=%d", __func__, qdsp_audiozoom.topo_id, qdsp_audiozoom.module_id, qdsp_audiozoom.instance_id, qdsp_audiozoom.zoom_param_id, qdsp_audiozoom.dir_param_id,qdsp_audiozoom.app_type); return 0; }