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