jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 1 | /* |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 2 | * Copyright (C) 2018-2019 The Android Open Source Project |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "audio_hw_waves" |
| 18 | /*#define LOG_NDEBUG 0*/ |
| 19 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 20 | #include <audio_hw.h> |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 21 | #include <cutils/str_parms.h> |
| 22 | #include <dlfcn.h> |
| 23 | #include <log/log.h> |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 24 | #include <math.h> |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 25 | #include <platform_api.h> |
| 26 | #include <pthread.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <system/audio.h> |
| 30 | #include <unistd.h> |
| 31 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 32 | #include "audio_extn.h" |
| 33 | #include "maxxaudio.h" |
| 34 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 35 | #define LIB_MA_PARAM "libmaxxaudioqdsp.so" |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 36 | #define LIB_MA_PATH "vendor/lib/" |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 37 | #define PRESET_PATH "/vendor/etc" |
| 38 | #define MPS_BASE_STRING "default" |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 39 | #define USER_PRESET_PATH "" |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 40 | #define CONFIG_BASE_STRING "maxx_conf" |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 41 | #define CAL_PRESIST_STR "cal_persist" |
| 42 | #define CAL_SAMPLERATE_STR "cal_samplerate" |
| 43 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 44 | #define MA_QDSP_PARAM_INIT "maxxaudio_qdsp_initialize" |
| 45 | #define MA_QDSP_PARAM_DEINIT "maxxaudio_qdsp_uninitialize" |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 46 | #define MA_QDSP_IS_FEATURE_USED "maxxaudio_qdsp_is_feature_supported" |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 47 | #define MA_QDSP_SET_LR_SWAP "maxxaudio_qdsp_set_lr_swap" |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 48 | #define MA_QDSP_SET_ORIENTATION "maxxaudio_qdsp_set_orientation" |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 49 | #define MA_QDSP_SET_MODE "maxxaudio_qdsp_set_sound_mode" |
| 50 | #define MA_QDSP_SET_VOL "maxxaudio_qdsp_set_volume" |
| 51 | #define MA_QDSP_SET_VOLT "maxxaudio_qdsp_set_volume_table" |
| 52 | #define MA_QDSP_SET_PARAM "maxxaudio_qdsp_set_parameter" |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 53 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 54 | #define SUPPORT_DEV "18d1:5033" // Blackbird usbid |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 55 | #define SUPPORTED_USB 0x01 |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 56 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 57 | typedef unsigned int effective_scope_flag_t; |
| 58 | const effective_scope_flag_t EFFECTIVE_SCOPE_RTC = 1 << 0; /* RTC */ |
| 59 | const effective_scope_flag_t EFFECTIVE_SCOPE_ACDB = 1 << 1; /* ACDB */ |
| 60 | const effective_scope_flag_t EFFECTIVE_SCOPE_ALL = EFFECTIVE_SCOPE_RTC | EFFECTIVE_SCOPE_ACDB; |
| 61 | const effective_scope_flag_t EFFECTIVE_SCOPE_NONE = 0; |
| 62 | const effective_scope_flag_t EFFECTIVE_SCOPE_DEFAULT = EFFECTIVE_SCOPE_NONE; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 63 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 64 | const unsigned int AUDIO_CAL_SETTINGS_VERSION_MAJOR = 2; |
| 65 | const unsigned int AUDIO_CAL_SETTINGS_VERSION_MINOR = 0; |
| 66 | const unsigned int AUDIO_CAL_SETTINGS_VERSION_MAJOR_DEFAULT = AUDIO_CAL_SETTINGS_VERSION_MAJOR; |
| 67 | const unsigned int AUDIO_CAL_SETTINGS_VERSION_MINOR_DEFAULT = AUDIO_CAL_SETTINGS_VERSION_MINOR; |
| 68 | |
| 69 | const unsigned int VALUE_AUTO = 0xFFFFFFFF; |
| 70 | const unsigned int APP_TYPE_AUTO = VALUE_AUTO; |
| 71 | const unsigned int APP_TYPE_DEFAULT = APP_TYPE_AUTO; |
| 72 | const unsigned int DEVICE_AUTO = VALUE_AUTO; |
| 73 | const unsigned int DEVICE_DEFAULT = DEVICE_AUTO; |
| 74 | |
| 75 | const unsigned int MAAP_OUTPUT_GAIN = 27; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 76 | |
| 77 | typedef enum MA_STREAM_TYPE { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 78 | STREAM_MIN_TYPES = 0, |
| 79 | STREAM_VOICE = STREAM_MIN_TYPES, |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 80 | STREAM_SYSTEM, |
| 81 | STREAM_RING, |
| 82 | STREAM_MUSIC, |
| 83 | STREAM_ALARM, |
| 84 | STREAM_NOTIFICATION , |
| 85 | STREAM_MAX_TYPES, |
| 86 | } ma_stream_type_t; |
| 87 | |
| 88 | typedef enum MA_CMD { |
| 89 | MA_CMD_VOL, |
| 90 | MA_CMD_SWAP_ENABLE, |
| 91 | MA_CMD_SWAP_DISABLE, |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 92 | MA_CMD_ROTATE_ENABLE, |
| 93 | MA_CMD_ROTATE_DISABLE, |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 94 | MA_CMD_SOFT_MUTE_ENABLE, |
| 95 | MA_CMD_SOFT_MUTE_DISABLE, |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 96 | } ma_cmd_t; |
| 97 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 98 | typedef struct ma_audio_cal_version { |
| 99 | unsigned int major; |
| 100 | unsigned int minor; |
| 101 | } ma_audio_cal_version_t; |
| 102 | |
| 103 | typedef struct ma_audio_cal_common_settings { |
| 104 | unsigned int app_type; |
| 105 | unsigned int device; |
| 106 | } ma_audio_cal_common_settings_t; |
| 107 | |
| 108 | struct ma_audio_cal_settings { |
| 109 | ma_audio_cal_version_t version; |
| 110 | ma_audio_cal_common_settings_t common; |
| 111 | effective_scope_flag_t effect_scope_flag; |
| 112 | }; |
| 113 | |
| 114 | struct ma_state { |
| 115 | float vol; |
| 116 | bool active; |
| 117 | }; |
| 118 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 119 | typedef void *ma_audio_cal_handle_t; |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 120 | typedef int (*set_audio_cal_t)(const char *); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 121 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 122 | typedef bool (*ma_param_init_t)(ma_audio_cal_handle_t *, const char *, |
| 123 | const char *, const char *, set_audio_cal_t); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 124 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 125 | typedef bool (*ma_param_deinit_t)(ma_audio_cal_handle_t *); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 126 | |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 127 | typedef bool (*ma_is_feature_used_t)(ma_audio_cal_handle_t, const char *); |
| 128 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 129 | typedef bool (*ma_set_lr_swap_t)(ma_audio_cal_handle_t, |
| 130 | const struct ma_audio_cal_settings *, bool); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 131 | |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 132 | typedef bool (*ma_set_orientation_t)(ma_audio_cal_handle_t, |
| 133 | const struct ma_audio_cal_settings *, int); |
| 134 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 135 | typedef bool (*ma_set_sound_mode_t)(ma_audio_cal_handle_t, |
| 136 | const struct ma_audio_cal_settings *, |
| 137 | unsigned int); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 138 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 139 | typedef bool (*ma_set_volume_t)(ma_audio_cal_handle_t, |
| 140 | const struct ma_audio_cal_settings *, double); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 141 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 142 | typedef bool (*ma_set_volume_table_t)(ma_audio_cal_handle_t, |
| 143 | const struct ma_audio_cal_settings *, |
| 144 | size_t, struct ma_state *); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 145 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 146 | typedef bool (*ma_set_param_t)(ma_audio_cal_handle_t, |
| 147 | const struct ma_audio_cal_settings *, |
| 148 | unsigned int, double); |
| 149 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 150 | struct ma_platform_data { |
| 151 | void *waves_handle; |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 152 | void *platform; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 153 | pthread_mutex_t lock; |
| 154 | ma_param_init_t ma_param_init; |
| 155 | ma_param_deinit_t ma_param_deinit; |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 156 | ma_is_feature_used_t ma_is_feature_used; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 157 | ma_set_lr_swap_t ma_set_lr_swap; |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 158 | ma_set_orientation_t ma_set_orientation; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 159 | ma_set_sound_mode_t ma_set_sound_mode; |
| 160 | ma_set_volume_t ma_set_volume; |
| 161 | ma_set_volume_table_t ma_set_volume_table; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 162 | ma_set_param_t ma_set_param; |
| 163 | bool speaker_lr_swap; |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 164 | bool orientation_used; |
| 165 | int dispaly_orientation; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | ma_audio_cal_handle_t g_ma_audio_cal_handle = NULL; |
| 169 | static uint16_t g_supported_dev = 0; |
| 170 | static struct ma_state ma_cur_state_table[STREAM_MAX_TYPES]; |
| 171 | static struct ma_platform_data *my_data = NULL; |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 172 | // --- external function dependency --- |
| 173 | fp_platform_set_parameters_t fp_platform_set_parameters; |
| 174 | fp_audio_extn_get_snd_card_split_t fp_audio_extn_get_snd_card_split; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 175 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 176 | static int set_audio_cal(const char *audio_cal) |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 177 | { |
| 178 | ALOGV("set_audio_cal: %s", audio_cal); |
| 179 | |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 180 | return fp_platform_set_parameters(my_data->platform, |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 181 | str_parms_create_str(audio_cal)); |
| 182 | } |
| 183 | |
| 184 | static bool ma_set_lr_swap_l( |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 185 | const struct ma_audio_cal_settings *audio_cal_settings, bool swap) |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 186 | { |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 187 | return my_data->ma_set_lr_swap(g_ma_audio_cal_handle, |
| 188 | audio_cal_settings, swap); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 189 | } |
| 190 | |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 191 | static bool ma_set_orientation_l( |
| 192 | const struct ma_audio_cal_settings *audio_cal_settings, int orientation) |
| 193 | { |
| 194 | return my_data->ma_set_orientation(g_ma_audio_cal_handle, |
| 195 | audio_cal_settings, orientation); |
| 196 | } |
| 197 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 198 | static bool ma_set_volume_table_l( |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 199 | const struct ma_audio_cal_settings *audio_cal_settings, |
| 200 | size_t num_streams, struct ma_state *volume_table) |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 201 | { |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 202 | return my_data->ma_set_volume_table(g_ma_audio_cal_handle, |
| 203 | audio_cal_settings, num_streams, |
| 204 | volume_table); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 205 | } |
| 206 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 207 | static bool ma_set_param_l( |
| 208 | const struct ma_audio_cal_settings *audio_cal_settings, |
| 209 | unsigned int index, double value) |
| 210 | { |
| 211 | return my_data->ma_set_param(g_ma_audio_cal_handle, |
| 212 | audio_cal_settings, index, value); |
| 213 | } |
| 214 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 215 | static inline bool valid_usecase(struct audio_usecase *usecase) |
| 216 | { |
| 217 | if ((usecase->type == PCM_PLAYBACK) && |
| 218 | /* supported usecases */ |
| 219 | ((usecase->id == USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) || |
| 220 | (usecase->id == USECASE_AUDIO_PLAYBACK_LOW_LATENCY) || |
| 221 | (usecase->id == USECASE_AUDIO_PLAYBACK_OFFLOAD)) && |
| 222 | /* support devices */ |
| 223 | ((usecase->devices & AUDIO_DEVICE_OUT_SPEAKER) || |
| 224 | (usecase->devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) || |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 225 | (audio_is_usb_out_device(usecase->devices) && |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 226 | ma_supported_usb()))) |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 227 | /* TODO: enable A2DP when it is ready */ |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 228 | |
| 229 | return true; |
| 230 | |
| 231 | ALOGV("%s: not support type %d usecase %d device %d", |
| 232 | __func__, usecase->type, usecase->id, usecase->devices); |
| 233 | |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | // already hold lock |
| 238 | static inline bool is_active() |
| 239 | { |
| 240 | ma_stream_type_t i = 0; |
| 241 | |
| 242 | for (i = 0; i < STREAM_MAX_TYPES; i++) |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 243 | if (ma_cur_state_table[i].active) |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 244 | return true; |
| 245 | |
| 246 | return false; |
| 247 | } |
| 248 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 249 | static void ma_cal_init(struct ma_audio_cal_settings *ma_cal) |
| 250 | { |
| 251 | ma_cal->version.major = AUDIO_CAL_SETTINGS_VERSION_MAJOR_DEFAULT; |
| 252 | ma_cal->version.minor = AUDIO_CAL_SETTINGS_VERSION_MINOR_DEFAULT; |
| 253 | ma_cal->common.app_type = APP_TYPE_DEFAULT; |
| 254 | ma_cal->common.device = DEVICE_DEFAULT; |
| 255 | ma_cal->effect_scope_flag = EFFECTIVE_SCOPE_ALL; |
| 256 | } |
| 257 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 258 | static bool check_and_send_all_audio_cal(struct audio_device *adev, ma_cmd_t cmd) |
| 259 | { |
| 260 | int i = 0; |
| 261 | bool ret = false; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 262 | struct listnode *node; |
| 263 | struct audio_usecase *usecase; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 264 | struct ma_audio_cal_settings ma_cal; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 265 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 266 | ma_cal_init(&ma_cal); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 267 | |
| 268 | list_for_each(node, &adev->usecase_list) { |
| 269 | usecase = node_to_item(node, struct audio_usecase, list); |
| 270 | if (valid_usecase(usecase)) { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 271 | ma_cal.common.app_type = usecase->stream.out->app_type_cfg.app_type; |
| 272 | ma_cal.common.device = usecase->stream.out->devices; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 273 | ALOGV("%s: send usecase(%d) app_type(%d) device(%d)", |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 274 | __func__, usecase->id, ma_cal.common.app_type, |
| 275 | ma_cal.common.device); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 276 | |
| 277 | switch (cmd) { |
| 278 | case MA_CMD_VOL: |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 279 | ret = ma_set_volume_table_l(&ma_cal, STREAM_MAX_TYPES, |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 280 | ma_cur_state_table); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 281 | if (ret) |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 282 | ALOGV("ma_set_volume_table_l success"); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 283 | else |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 284 | ALOGE("ma_set_volume_table_l returned with error."); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 285 | |
| 286 | ALOGV("%s: send volume table === Start", __func__); |
| 287 | for (i = 0; i < STREAM_MAX_TYPES; i++) |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 288 | ALOGV("%s: stream(%d) volume(%f) active(%s)", __func__, |
| 289 | i, ma_cur_state_table[i].vol, |
| 290 | ma_cur_state_table[i].active ? "T" : "F"); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 291 | ALOGV("%s: send volume table === End", __func__); |
| 292 | break; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 293 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 294 | case MA_CMD_SWAP_ENABLE: |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 295 | /* lr swap only enable for speaker path */ |
| 296 | if (ma_cal.common.device & AUDIO_DEVICE_OUT_SPEAKER) { |
| 297 | ret = ma_set_lr_swap_l(&ma_cal, true); |
| 298 | if (ret) |
| 299 | ALOGV("ma_set_lr_swap_l enable returned with success."); |
| 300 | else |
| 301 | ALOGE("ma_set_lr_swap_l enable returned with error."); |
| 302 | } |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 303 | break; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 304 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 305 | case MA_CMD_SWAP_DISABLE: |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 306 | ret = ma_set_lr_swap_l(&ma_cal, false); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 307 | if (ret) |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 308 | ALOGV("ma_set_lr_swap_l disable returned with success."); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 309 | else |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 310 | ALOGE("ma_set_lr_swap_l disable returned with error."); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 311 | break; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 312 | |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 313 | case MA_CMD_ROTATE_ENABLE: |
| 314 | if (ma_cal.common.device & AUDIO_DEVICE_OUT_SPEAKER) { |
| 315 | ret = ma_set_orientation_l(&ma_cal, my_data->dispaly_orientation); |
| 316 | if (ret) |
| 317 | ALOGV("ma_set_orientation_l %d returned with success.", my_data->dispaly_orientation); |
| 318 | else |
| 319 | ALOGE("ma_set_orientation_l %d returned with error.", my_data->dispaly_orientation); |
| 320 | } |
| 321 | break; |
| 322 | |
| 323 | case MA_CMD_ROTATE_DISABLE: |
| 324 | ret = ma_set_orientation_l(&ma_cal, 0); |
| 325 | if (ret) |
| 326 | ALOGV("ma_set_orientation_l 0 returned with success."); |
| 327 | else |
| 328 | ALOGE("ma_set_orientation_l 0 returned with error."); |
| 329 | break; |
| 330 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 331 | case MA_CMD_SOFT_MUTE_ENABLE: |
| 332 | if (usecase->id == USECASE_AUDIO_PLAYBACK_LOW_LATENCY) break; |
| 333 | |
| 334 | ma_cal.effect_scope_flag = EFFECTIVE_SCOPE_RTC; |
| 335 | ret = ma_set_param_l(&ma_cal, MAAP_OUTPUT_GAIN, -96); |
| 336 | if (!ret) |
| 337 | ALOGE("soft mute enable returned with error."); |
| 338 | break; |
| 339 | |
| 340 | case MA_CMD_SOFT_MUTE_DISABLE: |
| 341 | if (usecase->id == USECASE_AUDIO_PLAYBACK_LOW_LATENCY) break; |
| 342 | |
| 343 | ma_cal.effect_scope_flag = EFFECTIVE_SCOPE_RTC; |
| 344 | ret = ma_set_param_l(&ma_cal, MAAP_OUTPUT_GAIN, 0); |
| 345 | if (!ret) |
| 346 | ALOGE("soft mute disable returned with error."); |
| 347 | break; |
| 348 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 349 | default: |
| 350 | ALOGE("%s: unsupported cmd %d", __func__, cmd); |
| 351 | } |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 352 | } |
| 353 | } |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 354 | |
| 355 | return ret; |
| 356 | } |
| 357 | |
| 358 | static bool find_sup_dev(char *name) |
| 359 | { |
| 360 | char *token; |
| 361 | const char s[2] = ","; |
| 362 | bool ret = false; |
| 363 | char sup_devs[128]; |
| 364 | |
| 365 | // the rule of comforming suppored dev's name |
| 366 | // 1. Both string len are equal |
| 367 | // 2. Both string content are equal |
| 368 | |
| 369 | strncpy(sup_devs, SUPPORT_DEV, sizeof(sup_devs)); |
| 370 | token = strtok(sup_devs, s); |
| 371 | while (token != NULL) { |
| 372 | if (strncmp(token, name, strlen(token)) == 0 && |
| 373 | strlen(token) == strlen(name)) { |
| 374 | ALOGD("%s: support dev %s", __func__, token); |
| 375 | ret = true; |
| 376 | break; |
| 377 | } |
| 378 | token = strtok(NULL, s); |
| 379 | } |
| 380 | |
| 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | static void ma_set_swap_l(struct audio_device *adev, bool enable) |
| 385 | { |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 386 | if (enable) |
| 387 | check_and_send_all_audio_cal(adev, MA_CMD_SWAP_ENABLE); |
| 388 | else |
| 389 | check_and_send_all_audio_cal(adev, MA_CMD_SWAP_DISABLE); |
| 390 | } |
| 391 | |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 392 | static void ma_set_rotation_l(struct audio_device *adev, int orientation) |
| 393 | { |
| 394 | if (orientation != 0) |
| 395 | check_and_send_all_audio_cal(adev, MA_CMD_ROTATE_ENABLE); |
| 396 | else |
| 397 | check_and_send_all_audio_cal(adev, MA_CMD_ROTATE_DISABLE); |
| 398 | } |
| 399 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 400 | static void ma_support_usb(bool enable, int card) |
| 401 | { |
| 402 | char path[128]; |
| 403 | char id[32]; |
| 404 | int ret = 0; |
| 405 | int32_t fd = -1; |
| 406 | char *idd; |
| 407 | |
| 408 | if (enable) { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 409 | ret = snprintf(path, sizeof(path), "/proc/asound/card%u/usbid", card); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 410 | if (ret < 0) { |
| 411 | ALOGE("%s: failed on snprintf (%d) to path %s\n", |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 412 | __func__, ret, path); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 413 | goto done; |
| 414 | } |
| 415 | fd = open(path, O_RDONLY); |
| 416 | if (fd < 0) { |
| 417 | ALOGE("%s: error failed to open id file %s error: %d\n", |
| 418 | __func__, path, errno); |
| 419 | goto done; |
| 420 | } |
| 421 | if (read(fd, id, sizeof(id)) < 0) { |
| 422 | ALOGE("%s: file read error", __func__); |
| 423 | goto done; |
| 424 | } |
| 425 | //replace '\n' to '\0' |
| 426 | idd = strtok(id, "\n"); |
| 427 | |
| 428 | if (find_sup_dev(idd)) { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 429 | ALOGV("%s: support usbid is %s", __func__, id); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 430 | g_supported_dev |= SUPPORTED_USB; |
| 431 | } else |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 432 | ALOGV("%s: usbid %s isn't found from %s", __func__, id, SUPPORT_DEV); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 433 | } else { |
| 434 | g_supported_dev &= ~SUPPORTED_USB; |
| 435 | } |
| 436 | |
| 437 | done: |
| 438 | if (fd >= 0) close(fd); |
| 439 | } |
| 440 | |
| 441 | // adev_init lock held |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 442 | void ma_init(void *platform, maxx_audio_init_config_t init_config) |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 443 | { |
| 444 | ma_stream_type_t i = 0; |
| 445 | int ret = 0; |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 446 | char lib_path[128] = {0}; |
| 447 | char mps_path[128] = {0}; |
| 448 | char cnf_path[128] = {0}; |
| 449 | struct snd_card_split *snd_split_handle = NULL; |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 450 | |
| 451 | fp_platform_set_parameters = init_config.fp_platform_set_parameters; |
| 452 | fp_audio_extn_get_snd_card_split = init_config.fp_audio_extn_get_snd_card_split; |
| 453 | |
| 454 | snd_split_handle = fp_audio_extn_get_snd_card_split(); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 455 | |
| 456 | if (platform == NULL) { |
| 457 | ALOGE("%s: platform is NULL", __func__); |
| 458 | goto error; |
| 459 | } |
| 460 | |
| 461 | if (my_data) { free(my_data); } |
| 462 | my_data = calloc(1, sizeof(struct ma_platform_data)); |
| 463 | if (my_data == NULL) { |
| 464 | ALOGE("%s: ma_cal alloct fail", __func__); |
| 465 | goto error; |
| 466 | } |
| 467 | |
| 468 | pthread_mutex_init(&my_data->lock, NULL); |
| 469 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 470 | my_data->platform = platform; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 471 | ret = snprintf(lib_path, sizeof(lib_path), "%s/%s", LIB_MA_PATH, LIB_MA_PARAM); |
| 472 | if (ret < 0) { |
| 473 | ALOGE("%s: snprintf failed for lib %s, ret %d", __func__, LIB_MA_PARAM, ret); |
| 474 | goto error; |
| 475 | } |
| 476 | |
| 477 | my_data->waves_handle = dlopen(lib_path, RTLD_NOW); |
| 478 | if (my_data->waves_handle == NULL) { |
| 479 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_MA_PARAM); |
| 480 | goto error; |
| 481 | } else { |
| 482 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_MA_PARAM); |
| 483 | |
| 484 | my_data->ma_param_init = (ma_param_init_t)dlsym(my_data->waves_handle, |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 485 | MA_QDSP_PARAM_INIT); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 486 | if (!my_data->ma_param_init) { |
| 487 | ALOGE("%s: dlsym error %s for ma_param_init", __func__, dlerror()); |
| 488 | goto error; |
| 489 | } |
| 490 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 491 | my_data->ma_param_deinit = (ma_param_deinit_t)dlsym( |
| 492 | my_data->waves_handle, MA_QDSP_PARAM_DEINIT); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 493 | if (!my_data->ma_param_deinit) { |
| 494 | ALOGE("%s: dlsym error %s for ma_param_deinit", __func__, dlerror()); |
| 495 | goto error; |
| 496 | } |
| 497 | |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 498 | my_data->ma_is_feature_used = (ma_is_feature_used_t)dlsym(my_data->waves_handle, |
| 499 | MA_QDSP_IS_FEATURE_USED); |
| 500 | if (!my_data->ma_is_feature_used) { |
| 501 | ALOGV("%s: dlsym error %s for ma_is_feature_used", __func__, dlerror()); |
| 502 | } |
| 503 | |
| 504 | my_data->ma_set_orientation = (ma_set_orientation_t)dlsym(my_data->waves_handle, |
| 505 | MA_QDSP_SET_ORIENTATION); |
| 506 | if (!my_data->ma_set_orientation) { |
| 507 | ALOGV("%s: dlsym error %s for ma_set_orientation", __func__, dlerror()); |
| 508 | } |
| 509 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 510 | my_data->ma_set_lr_swap = (ma_set_lr_swap_t)dlsym(my_data->waves_handle, |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 511 | MA_QDSP_SET_LR_SWAP); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 512 | if (!my_data->ma_set_lr_swap) { |
| 513 | ALOGE("%s: dlsym error %s for ma_set_lr_swap", __func__, dlerror()); |
| 514 | goto error; |
| 515 | } |
| 516 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 517 | my_data->ma_set_sound_mode = (ma_set_sound_mode_t)dlsym( |
| 518 | my_data->waves_handle, MA_QDSP_SET_MODE); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 519 | if (!my_data->ma_set_sound_mode) { |
| 520 | ALOGE("%s: dlsym error %s for ma_set_sound_mode", __func__, dlerror()); |
| 521 | goto error; |
| 522 | } |
| 523 | |
| 524 | my_data->ma_set_volume = (ma_set_volume_t)dlsym(my_data->waves_handle, |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 525 | MA_QDSP_SET_VOL); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 526 | if (!my_data->ma_set_volume) { |
| 527 | ALOGE("%s: dlsym error %s for ma_set_volume", __func__, dlerror()); |
| 528 | goto error; |
| 529 | } |
| 530 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 531 | my_data->ma_set_volume_table = (ma_set_volume_table_t)dlsym( |
| 532 | my_data->waves_handle, MA_QDSP_SET_VOLT); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 533 | if (!my_data->ma_set_volume_table) { |
| 534 | ALOGE("%s: dlsym error %s for ma_set_volume_table", __func__, dlerror()); |
| 535 | goto error; |
| 536 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 537 | |
| 538 | my_data->ma_set_param = (ma_set_param_t)dlsym( |
| 539 | my_data->waves_handle, MA_QDSP_SET_PARAM); |
| 540 | if (!my_data->ma_set_param) { |
| 541 | ALOGE("%s: dlsym error %s for ma_set_param", __func__, dlerror()); |
| 542 | goto error; |
| 543 | } |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 544 | } |
| 545 | |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 546 | /* get preset table */ |
| 547 | if (snd_split_handle == NULL) { |
| 548 | snprintf(mps_path, sizeof(mps_path), "%s/%s.mps", |
| 549 | PRESET_PATH, MPS_BASE_STRING); |
| 550 | } else { |
| 551 | snprintf(mps_path, sizeof(mps_path), "%s/%s_%s.mps", |
| 552 | PRESET_PATH, MPS_BASE_STRING, snd_split_handle->form_factor); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 553 | } |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 554 | |
| 555 | /* get config files */ |
| 556 | if (snd_split_handle == NULL) { |
| 557 | snprintf(cnf_path, sizeof(cnf_path), "%s/%s.ini", |
| 558 | PRESET_PATH, CONFIG_BASE_STRING); |
| 559 | } else { |
| 560 | snprintf(cnf_path, sizeof(cnf_path), "%s/%s_%s.ini", |
| 561 | PRESET_PATH, CONFIG_BASE_STRING, snd_split_handle->form_factor); |
| 562 | } |
| 563 | |
| 564 | /* check file */ |
| 565 | if (access(mps_path, R_OK) < 0) { |
| 566 | ALOGW("%s: file %s isn't existed.", __func__, mps_path); |
| 567 | goto error; |
| 568 | } else |
| 569 | ALOGD("%s: Loading mps file: %s", __func__, mps_path); |
| 570 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 571 | /* TODO: check user preset table once the feature is enabled |
| 572 | if (access(USER_PRESET_PATH, F_OK) < 0 ){ |
| 573 | ALOGW("%s: file %s isn't existed.", __func__, USER_PRESET_PATH); |
| 574 | goto error; |
| 575 | } |
| 576 | */ |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 577 | |
| 578 | if (access(cnf_path, R_OK) < 0) { |
| 579 | ALOGW("%s: file %s isn't existed.", __func__, cnf_path); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 580 | goto error; |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 581 | } else |
| 582 | ALOGD("%s: Loading ini file: %s", __func__, cnf_path); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 583 | |
| 584 | /* init ma parameter */ |
| 585 | if (my_data->ma_param_init(&g_ma_audio_cal_handle, |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 586 | mps_path, |
| 587 | USER_PRESET_PATH, /* unused */ |
| 588 | cnf_path, |
| 589 | &set_audio_cal)) { |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 590 | if (!g_ma_audio_cal_handle) { |
| 591 | ALOGE("%s: ma parameters initialize failed", __func__); |
| 592 | my_data->ma_param_deinit(&g_ma_audio_cal_handle); |
| 593 | goto error; |
| 594 | } |
| 595 | ALOGD("%s: ma parameters initialize successful", __func__); |
| 596 | } else { |
| 597 | ALOGE("%s: ma parameters initialize failed", __func__); |
| 598 | goto error; |
| 599 | } |
| 600 | |
| 601 | /* init volume table */ |
| 602 | for (i = 0; i < STREAM_MAX_TYPES; i++) { |
| 603 | ma_cur_state_table[i].vol = 0.0; |
| 604 | ma_cur_state_table[i].active = false; |
| 605 | } |
| 606 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 607 | my_data->speaker_lr_swap = false; |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 608 | my_data->orientation_used = false; |
| 609 | my_data->dispaly_orientation = 0; |
| 610 | |
| 611 | if (g_ma_audio_cal_handle && my_data->ma_is_feature_used) { |
| 612 | my_data->orientation_used = my_data->ma_is_feature_used(g_ma_audio_cal_handle, "SET_ORIENTATION"); |
| 613 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 614 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 615 | return; |
| 616 | |
| 617 | error: |
| 618 | if (my_data) { free(my_data); } |
| 619 | my_data = NULL; |
| 620 | } |
| 621 | |
| 622 | //adev_init lock held |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 623 | void ma_deinit() |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 624 | { |
| 625 | if (my_data) { |
| 626 | /* deinit ma parameter */ |
| 627 | if (my_data->ma_param_deinit && |
| 628 | my_data->ma_param_deinit(&g_ma_audio_cal_handle)) |
| 629 | ALOGD("%s: ma parameters uninitialize successful", __func__); |
| 630 | else |
| 631 | ALOGD("%s: ma parameters uninitialize failed", __func__); |
| 632 | |
| 633 | pthread_mutex_destroy(&my_data->lock); |
| 634 | free(my_data); |
| 635 | my_data = NULL; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | // adev_init and adev lock held |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 640 | bool ma_set_state(struct audio_device *adev, int stream_type, |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 641 | float vol, bool active) |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 642 | { |
| 643 | bool ret = false; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 644 | bool first_enable = false; |
| 645 | struct ma_state pr_mstate; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 646 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 647 | if (stream_type >= STREAM_MAX_TYPES || |
| 648 | stream_type < STREAM_MIN_TYPES) { |
| 649 | ALOGE("%s: stream_type %d out of range.", __func__, stream_type); |
| 650 | return ret; |
| 651 | } |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 652 | |
| 653 | if (!my_data) { |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 654 | ALOGV("%s: maxxaudio isn't initialized.", __func__); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 655 | return ret; |
| 656 | } |
| 657 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 658 | ALOGV("%s: stream[%d] vol[%f] active[%s]", |
| 659 | __func__, stream_type, vol, active ? "true" : "false"); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 660 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 661 | pr_mstate.vol = ma_cur_state_table[(ma_stream_type_t)stream_type].vol; |
| 662 | pr_mstate.active = ma_cur_state_table[(ma_stream_type_t)stream_type].active; |
| 663 | |
| 664 | // update condition: vol or active state changes |
| 665 | if (pr_mstate.vol != vol || pr_mstate.active != active) { |
| 666 | |
| 667 | pthread_mutex_lock(&my_data->lock); |
| 668 | // get active state before updating |
| 669 | first_enable = (!is_active()) && active; |
| 670 | |
| 671 | ma_cur_state_table[(ma_stream_type_t)stream_type].vol = vol; |
| 672 | ma_cur_state_table[(ma_stream_type_t)stream_type].active = active; |
| 673 | |
| 674 | if (first_enable) //all F -> one of T |
| 675 | ret = check_and_send_all_audio_cal(adev, MA_CMD_SOFT_MUTE_DISABLE); |
| 676 | else if (!is_active()) // all F |
| 677 | ret = check_and_send_all_audio_cal(adev, MA_CMD_SOFT_MUTE_ENABLE); |
| 678 | |
| 679 | ret = check_and_send_all_audio_cal(adev, MA_CMD_VOL); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 680 | |
| 681 | pthread_mutex_unlock(&my_data->lock); |
| 682 | } |
| 683 | |
| 684 | return ret; |
| 685 | } |
| 686 | |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 687 | void ma_set_device(struct audio_usecase *usecase) |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 688 | { |
| 689 | int i = 0; |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 690 | struct ma_audio_cal_settings ma_cal; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 691 | |
| 692 | if (!my_data) { |
| 693 | ALOGV("%s: maxxaudio isn't initialized.", __func__); |
| 694 | return; |
| 695 | } |
| 696 | |
| 697 | if (!valid_usecase(usecase)) { |
| 698 | ALOGV("%s: %d is not supported usecase", __func__, usecase->id); |
| 699 | return; |
| 700 | } |
| 701 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 702 | ma_cal_init(&ma_cal); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 703 | |
| 704 | /* update audio_cal and send it */ |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 705 | ma_cal.common.app_type = usecase->stream.out->app_type_cfg.app_type; |
| 706 | ma_cal.common.device = usecase->stream.out->devices; |
| 707 | ALOGV("%s: send usecase(%d) app_type(%d) device(%d)", |
| 708 | __func__, usecase->id, ma_cal.common.app_type, |
| 709 | ma_cal.common.device); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 710 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 711 | pthread_mutex_lock(&my_data->lock); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 712 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 713 | if (is_active()) { |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 714 | |
| 715 | if (ma_cal.common.device & AUDIO_DEVICE_OUT_SPEAKER) { |
| 716 | if (my_data->orientation_used) |
| 717 | ma_set_rotation_l(usecase->stream.out->dev, my_data->dispaly_orientation); |
| 718 | else |
| 719 | ma_set_swap_l(usecase->stream.out->dev, my_data->speaker_lr_swap); |
| 720 | } else { |
| 721 | if (my_data->orientation_used) |
| 722 | ma_set_rotation_l(usecase->stream.out->dev, 0); |
| 723 | else |
| 724 | ma_set_swap_l(usecase->stream.out->dev, false); |
| 725 | } |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 726 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 727 | ALOGV("%s: send volume table === Start", __func__); |
| 728 | for (i = 0; i < STREAM_MAX_TYPES; i++) |
| 729 | ALOGV("%s: stream(%d) volume(%f) active(%s)", __func__, i, |
| 730 | ma_cur_state_table[i].vol, |
| 731 | ma_cur_state_table[i].active ? "T" : "F"); |
| 732 | ALOGV("%s: send volume table === End", __func__); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 733 | |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 734 | if (!ma_set_volume_table_l(&ma_cal, |
| 735 | STREAM_MAX_TYPES, |
| 736 | ma_cur_state_table)) |
| 737 | ALOGE("ma_set_volume_table_l returned with error."); |
| 738 | else |
| 739 | ALOGV("ma_set_volume_table_l success"); |
| 740 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 741 | } |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 742 | pthread_mutex_unlock(&my_data->lock); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 743 | } |
| 744 | |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 745 | void ma_set_parameters(struct audio_device *adev, |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 746 | struct str_parms *parms) |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 747 | { |
| 748 | int ret; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 749 | int val; |
| 750 | char value[128]; |
| 751 | |
| 752 | // do LR swap and usb recognition |
| 753 | ret = str_parms_get_int(parms, "rotation", &val); |
| 754 | if (ret >= 0) { |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 755 | if (!my_data) { |
| 756 | ALOGV("%s: maxxaudio isn't initialized.", __func__); |
| 757 | return; |
| 758 | } |
| 759 | |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 760 | switch (val) { |
| 761 | case 270: |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 762 | my_data->speaker_lr_swap = true; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 763 | break; |
| 764 | case 0: |
| 765 | case 90: |
| 766 | case 180: |
Arun Mirpuri | b1bec9c | 2019-01-29 16:42:45 -0800 | [diff] [blame] | 767 | my_data->speaker_lr_swap = false; |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 768 | break; |
| 769 | } |
justinweng | bbffa62 | 2019-01-11 14:38:06 +0800 | [diff] [blame^] | 770 | my_data->dispaly_orientation = val; |
| 771 | |
| 772 | if (my_data->orientation_used) |
| 773 | ma_set_rotation_l(adev, my_data->dispaly_orientation); |
| 774 | else |
| 775 | ma_set_swap_l(adev, my_data->speaker_lr_swap); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | // check connect status |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 779 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, |
| 780 | sizeof(value)); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 781 | if (ret >= 0) { |
| 782 | audio_devices_t device = (audio_devices_t)strtoul(value, NULL, 10); |
| 783 | if (audio_is_usb_out_device(device)) { |
| 784 | ret = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 785 | if (ret >= 0) { |
| 786 | const int card = atoi(value); |
| 787 | ma_support_usb(true, card); |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | // check disconnect status |
Aalique Grahame | 5ce7fbe | 2019-01-28 12:08:13 -0800 | [diff] [blame] | 793 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, |
| 794 | sizeof(value)); |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 795 | if (ret >= 0) { |
| 796 | audio_devices_t device = (audio_devices_t)strtoul(value, NULL, 10); |
| 797 | if (audio_is_usb_out_device(device)) { |
| 798 | ret = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 799 | if (ret >= 0) { |
| 800 | const int card = atoi(value); |
| 801 | ma_support_usb(false, card /*useless*/); |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
Arun Mirpuri | d750ac5 | 2019-04-12 18:33:55 -0700 | [diff] [blame] | 807 | bool ma_supported_usb() |
jasmine cha | 75fa6f0 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 808 | { |
| 809 | ALOGV("%s: current support 0x%x", __func__, g_supported_dev); |
| 810 | return (g_supported_dev & SUPPORTED_USB) ? true : false; |
| 811 | } |