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" |
| 46 | #define MA_QDSP_SET_LR_SWAP "maxxaudio_qdsp_set_lr_swap" |
| 47 | #define MA_QDSP_SET_MODE "maxxaudio_qdsp_set_sound_mode" |
| 48 | #define MA_QDSP_SET_VOL "maxxaudio_qdsp_set_volume" |
| 49 | #define MA_QDSP_SET_VOLT "maxxaudio_qdsp_set_volume_table" |
| 50 | #define MA_QDSP_SET_PARAM "maxxaudio_qdsp_set_parameter" |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 51 | |
| 52 | #define SUPPORT_DEV "Blackbird" |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 53 | #define SUPPORTED_USB 0x01 |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 54 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 55 | typedef unsigned int effective_scope_flag_t; |
| 56 | const effective_scope_flag_t EFFECTIVE_SCOPE_RTC = 1 << 0; /* RTC */ |
| 57 | const effective_scope_flag_t EFFECTIVE_SCOPE_ACDB = 1 << 1; /* ACDB */ |
| 58 | const effective_scope_flag_t EFFECTIVE_SCOPE_ALL = EFFECTIVE_SCOPE_RTC | EFFECTIVE_SCOPE_ACDB; |
| 59 | const effective_scope_flag_t EFFECTIVE_SCOPE_NONE = 0; |
| 60 | const effective_scope_flag_t EFFECTIVE_SCOPE_DEFAULT = EFFECTIVE_SCOPE_NONE; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 61 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 62 | const unsigned int AUDIO_CAL_SETTINGS_VERSION_MAJOR = 2; |
| 63 | const unsigned int AUDIO_CAL_SETTINGS_VERSION_MINOR = 0; |
| 64 | const unsigned int AUDIO_CAL_SETTINGS_VERSION_MAJOR_DEFAULT = AUDIO_CAL_SETTINGS_VERSION_MAJOR; |
| 65 | const unsigned int AUDIO_CAL_SETTINGS_VERSION_MINOR_DEFAULT = AUDIO_CAL_SETTINGS_VERSION_MINOR; |
| 66 | |
| 67 | const unsigned int VALUE_AUTO = 0xFFFFFFFF; |
| 68 | const unsigned int APP_TYPE_AUTO = VALUE_AUTO; |
| 69 | const unsigned int APP_TYPE_DEFAULT = APP_TYPE_AUTO; |
| 70 | const unsigned int DEVICE_AUTO = VALUE_AUTO; |
| 71 | const unsigned int DEVICE_DEFAULT = DEVICE_AUTO; |
| 72 | |
| 73 | const unsigned int MAAP_OUTPUT_GAIN = 27; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 74 | |
| 75 | typedef enum MA_STREAM_TYPE { |
Jasmine Cha | fc63f34 | 2018-06-27 10:55:06 -0700 | [diff] [blame] | 76 | STREAM_MIN_TYPES = 0, |
| 77 | STREAM_VOICE = STREAM_MIN_TYPES, |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 78 | STREAM_SYSTEM, |
| 79 | STREAM_RING, |
| 80 | STREAM_MUSIC, |
| 81 | STREAM_ALARM, |
| 82 | STREAM_NOTIFICATION , |
| 83 | STREAM_MAX_TYPES, |
| 84 | } ma_stream_type_t; |
| 85 | |
| 86 | typedef enum MA_CMD { |
| 87 | MA_CMD_VOL, |
| 88 | MA_CMD_SWAP_ENABLE, |
| 89 | MA_CMD_SWAP_DISABLE, |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 90 | MA_CMD_SOFT_MUTE_ENABLE, |
| 91 | MA_CMD_SOFT_MUTE_DISABLE, |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 92 | } ma_cmd_t; |
| 93 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 94 | typedef struct ma_audio_cal_version { |
| 95 | unsigned int major; |
| 96 | unsigned int minor; |
| 97 | } ma_audio_cal_version_t; |
| 98 | |
| 99 | typedef struct ma_audio_cal_common_settings { |
| 100 | unsigned int app_type; |
| 101 | unsigned int device; |
| 102 | } ma_audio_cal_common_settings_t; |
| 103 | |
| 104 | struct ma_audio_cal_settings { |
| 105 | ma_audio_cal_version_t version; |
| 106 | ma_audio_cal_common_settings_t common; |
| 107 | effective_scope_flag_t effect_scope_flag; |
| 108 | }; |
| 109 | |
| 110 | struct ma_state { |
| 111 | float vol; |
| 112 | bool active; |
| 113 | }; |
| 114 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 115 | typedef void *ma_audio_cal_handle_t; |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 116 | typedef int (*set_audio_cal_t)(const char *); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 117 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 118 | typedef bool (*ma_param_init_t)(ma_audio_cal_handle_t *, const char *, |
| 119 | const char *, const char *, set_audio_cal_t); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 120 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 121 | typedef bool (*ma_param_deinit_t)(ma_audio_cal_handle_t *); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 122 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 123 | typedef bool (*ma_set_lr_swap_t)(ma_audio_cal_handle_t, |
| 124 | const struct ma_audio_cal_settings *, bool); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 125 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 126 | typedef bool (*ma_set_sound_mode_t)(ma_audio_cal_handle_t, |
| 127 | const struct ma_audio_cal_settings *, |
| 128 | unsigned int); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 129 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 130 | typedef bool (*ma_set_volume_t)(ma_audio_cal_handle_t, |
| 131 | const struct ma_audio_cal_settings *, double); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 132 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 133 | typedef bool (*ma_set_volume_table_t)(ma_audio_cal_handle_t, |
| 134 | const struct ma_audio_cal_settings *, |
| 135 | size_t, struct ma_state *); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 136 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 137 | typedef bool (*ma_set_param_t)(ma_audio_cal_handle_t, |
| 138 | const struct ma_audio_cal_settings *, |
| 139 | unsigned int, double); |
| 140 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 141 | struct ma_platform_data { |
| 142 | void *waves_handle; |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 143 | void *platform; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 144 | pthread_mutex_t lock; |
| 145 | ma_param_init_t ma_param_init; |
| 146 | ma_param_deinit_t ma_param_deinit; |
| 147 | ma_set_lr_swap_t ma_set_lr_swap; |
| 148 | ma_set_sound_mode_t ma_set_sound_mode; |
| 149 | ma_set_volume_t ma_set_volume; |
| 150 | ma_set_volume_table_t ma_set_volume_table; |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 151 | ma_set_param_t ma_set_param; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | ma_audio_cal_handle_t g_ma_audio_cal_handle = NULL; |
| 155 | static uint16_t g_supported_dev = 0; |
| 156 | static struct ma_state ma_cur_state_table[STREAM_MAX_TYPES]; |
| 157 | static struct ma_platform_data *my_data = NULL; |
| 158 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 159 | static int set_audio_cal(const char *audio_cal) |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 160 | { |
| 161 | ALOGV("set_audio_cal: %s", audio_cal); |
| 162 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 163 | return platform_set_parameters(my_data->platform, |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 164 | str_parms_create_str(audio_cal)); |
| 165 | } |
| 166 | |
| 167 | static bool ma_set_lr_swap_l( |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 168 | const struct ma_audio_cal_settings *audio_cal_settings, bool swap) |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 169 | { |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 170 | return my_data->ma_set_lr_swap(g_ma_audio_cal_handle, |
| 171 | audio_cal_settings, swap); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static bool ma_set_sound_mode_l( |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 175 | const struct ma_audio_cal_settings *audio_cal_settings, int sound_mode) |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 176 | { |
| 177 | return my_data->ma_set_sound_mode(g_ma_audio_cal_handle, |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 178 | audio_cal_settings, sound_mode); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static bool ma_set_volume_l( |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 182 | const struct ma_audio_cal_settings *audio_cal_settings, double volume) |
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_volume(g_ma_audio_cal_handle, audio_cal_settings, |
| 185 | volume); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | static bool ma_set_volume_table_l( |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 189 | const struct ma_audio_cal_settings *audio_cal_settings, |
| 190 | size_t num_streams, struct ma_state *volume_table) |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 191 | { |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 192 | return my_data->ma_set_volume_table(g_ma_audio_cal_handle, |
| 193 | audio_cal_settings, num_streams, |
| 194 | volume_table); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 195 | } |
| 196 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 197 | static bool ma_set_param_l( |
| 198 | const struct ma_audio_cal_settings *audio_cal_settings, |
| 199 | unsigned int index, double value) |
| 200 | { |
| 201 | return my_data->ma_set_param(g_ma_audio_cal_handle, |
| 202 | audio_cal_settings, index, value); |
| 203 | } |
| 204 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 205 | static inline bool valid_usecase(struct audio_usecase *usecase) |
| 206 | { |
| 207 | if ((usecase->type == PCM_PLAYBACK) && |
| 208 | /* supported usecases */ |
| 209 | ((usecase->id == USECASE_AUDIO_PLAYBACK_DEEP_BUFFER) || |
| 210 | (usecase->id == USECASE_AUDIO_PLAYBACK_LOW_LATENCY) || |
| 211 | (usecase->id == USECASE_AUDIO_PLAYBACK_OFFLOAD)) && |
| 212 | /* support devices */ |
| 213 | ((usecase->devices & AUDIO_DEVICE_OUT_SPEAKER) || |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 214 | (usecase->devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE))) |
| 215 | /* TODO: enable A2DP/USB when it is ready */ |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 216 | |
| 217 | return true; |
| 218 | |
| 219 | ALOGV("%s: not support type %d usecase %d device %d", |
| 220 | __func__, usecase->type, usecase->id, usecase->devices); |
| 221 | |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | // already hold lock |
| 226 | static inline bool is_active() |
| 227 | { |
| 228 | ma_stream_type_t i = 0; |
| 229 | |
| 230 | for (i = 0; i < STREAM_MAX_TYPES; i++) |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 231 | if (ma_cur_state_table[i].active) |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 232 | return true; |
| 233 | |
| 234 | return false; |
| 235 | } |
| 236 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 237 | static void ma_cal_init(struct ma_audio_cal_settings *ma_cal) |
| 238 | { |
| 239 | ma_cal->version.major = AUDIO_CAL_SETTINGS_VERSION_MAJOR_DEFAULT; |
| 240 | ma_cal->version.minor = AUDIO_CAL_SETTINGS_VERSION_MINOR_DEFAULT; |
| 241 | ma_cal->common.app_type = APP_TYPE_DEFAULT; |
| 242 | ma_cal->common.device = DEVICE_DEFAULT; |
| 243 | ma_cal->effect_scope_flag = EFFECTIVE_SCOPE_ALL; |
| 244 | } |
| 245 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 246 | static bool check_and_send_all_audio_cal(struct audio_device *adev, ma_cmd_t cmd) |
| 247 | { |
| 248 | int i = 0; |
| 249 | bool ret = false; |
| 250 | float vol = 0; |
| 251 | struct listnode *node; |
| 252 | struct audio_usecase *usecase; |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 253 | struct ma_audio_cal_settings ma_cal; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 254 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 255 | ma_cal_init(&ma_cal); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 256 | |
| 257 | list_for_each(node, &adev->usecase_list) { |
| 258 | usecase = node_to_item(node, struct audio_usecase, list); |
| 259 | if (valid_usecase(usecase)) { |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 260 | ma_cal.common.app_type = usecase->stream.out->app_type_cfg.app_type; |
| 261 | ma_cal.common.device = usecase->stream.out->devices; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 262 | ALOGV("%s: send usecase(%d) app_type(%d) device(%d)", |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 263 | __func__, usecase->id, ma_cal.common.app_type, |
| 264 | ma_cal.common.device); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 265 | |
| 266 | switch (cmd) { |
| 267 | case MA_CMD_VOL: |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 268 | ret = ma_set_volume_table_l(&ma_cal, STREAM_MAX_TYPES, |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 269 | ma_cur_state_table); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 270 | if (ret) |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 271 | ALOGV("ma_set_volume_table_l success"); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 272 | else |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 273 | ALOGE("ma_set_volume_table_l returned with error."); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 274 | |
| 275 | ALOGV("%s: send volume table === Start", __func__); |
| 276 | for (i = 0; i < STREAM_MAX_TYPES; i++) |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 277 | ALOGV("%s: stream(%d) volume(%f) active(%s)", __func__, |
| 278 | i, ma_cur_state_table[i].vol, |
| 279 | ma_cur_state_table[i].active ? "T" : "F"); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 280 | ALOGV("%s: send volume table === End", __func__); |
| 281 | break; |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 282 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 283 | case MA_CMD_SWAP_ENABLE: |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 284 | ret = ma_set_lr_swap_l(&ma_cal, true); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 285 | if (ret) |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 286 | ALOGV("ma_set_lr_swap_l enable returned with success."); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 287 | else |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 288 | ALOGE("ma_set_lr_swap_l enable returned with error."); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 289 | break; |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 290 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 291 | case MA_CMD_SWAP_DISABLE: |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 292 | ret = ma_set_lr_swap_l(&ma_cal, false); |
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_lr_swap_l disable returned with 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_lr_swap_l disable returned with error."); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 297 | break; |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 298 | |
| 299 | case MA_CMD_SOFT_MUTE_ENABLE: |
| 300 | if (usecase->id == USECASE_AUDIO_PLAYBACK_LOW_LATENCY) break; |
| 301 | |
| 302 | ma_cal.effect_scope_flag = EFFECTIVE_SCOPE_RTC; |
| 303 | ret = ma_set_param_l(&ma_cal, MAAP_OUTPUT_GAIN, -96); |
| 304 | if (!ret) |
| 305 | ALOGE("soft mute enable returned with error."); |
| 306 | break; |
| 307 | |
| 308 | case MA_CMD_SOFT_MUTE_DISABLE: |
| 309 | if (usecase->id == USECASE_AUDIO_PLAYBACK_LOW_LATENCY) break; |
| 310 | |
| 311 | ma_cal.effect_scope_flag = EFFECTIVE_SCOPE_RTC; |
| 312 | ret = ma_set_param_l(&ma_cal, MAAP_OUTPUT_GAIN, 0); |
| 313 | if (!ret) |
| 314 | ALOGE("soft mute disable returned with error."); |
| 315 | break; |
| 316 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 317 | default: |
| 318 | ALOGE("%s: unsupported cmd %d", __func__, cmd); |
| 319 | } |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 320 | } |
| 321 | } |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 322 | |
| 323 | return ret; |
| 324 | } |
| 325 | |
| 326 | static bool find_sup_dev(char *name) |
| 327 | { |
| 328 | char *token; |
| 329 | const char s[2] = ","; |
| 330 | bool ret = false; |
| 331 | char sup_devs[128]; |
| 332 | |
| 333 | // the rule of comforming suppored dev's name |
| 334 | // 1. Both string len are equal |
| 335 | // 2. Both string content are equal |
| 336 | |
| 337 | strncpy(sup_devs, SUPPORT_DEV, sizeof(sup_devs)); |
| 338 | token = strtok(sup_devs, s); |
| 339 | while (token != NULL) { |
| 340 | if (strncmp(token, name, strlen(token)) == 0 && |
| 341 | strlen(token) == strlen(name)) { |
| 342 | ALOGD("%s: support dev %s", __func__, token); |
| 343 | ret = true; |
| 344 | break; |
| 345 | } |
| 346 | token = strtok(NULL, s); |
| 347 | } |
| 348 | |
| 349 | return ret; |
| 350 | } |
| 351 | |
| 352 | static void ma_set_swap_l(struct audio_device *adev, bool enable) |
| 353 | { |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 354 | // do platform LR swap if it enables on Waves effect |
| 355 | // but there is no Waves implementation |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 356 | if (!my_data) { |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 357 | platform_check_and_set_swap_lr_channels(adev, enable); |
| 358 | ALOGV("%s: maxxaudio isn't initialized.", __func__); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 359 | return; |
| 360 | } |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 361 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 362 | if (enable) |
| 363 | check_and_send_all_audio_cal(adev, MA_CMD_SWAP_ENABLE); |
| 364 | else |
| 365 | check_and_send_all_audio_cal(adev, MA_CMD_SWAP_DISABLE); |
| 366 | } |
| 367 | |
| 368 | static void ma_support_usb(bool enable, int card) |
| 369 | { |
| 370 | char path[128]; |
| 371 | char id[32]; |
| 372 | int ret = 0; |
| 373 | int32_t fd = -1; |
| 374 | char *idd; |
| 375 | |
| 376 | if (enable) { |
| 377 | ret = snprintf(path, sizeof(path), "/proc/asound/card%u/id", card); |
| 378 | if (ret < 0) { |
| 379 | ALOGE("%s: failed on snprintf (%d) to path %s\n", |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 380 | __func__, ret, path); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 381 | goto done; |
| 382 | } |
| 383 | fd = open(path, O_RDONLY); |
| 384 | if (fd < 0) { |
| 385 | ALOGE("%s: error failed to open id file %s error: %d\n", |
| 386 | __func__, path, errno); |
| 387 | goto done; |
| 388 | } |
| 389 | if (read(fd, id, sizeof(id)) < 0) { |
| 390 | ALOGE("%s: file read error", __func__); |
| 391 | goto done; |
| 392 | } |
| 393 | //replace '\n' to '\0' |
| 394 | idd = strtok(id, "\n"); |
| 395 | |
| 396 | if (find_sup_dev(idd)) { |
| 397 | ALOGV("%s: support device name is %s", __func__, id); |
| 398 | g_supported_dev |= SUPPORTED_USB; |
| 399 | } else |
| 400 | ALOGV("%s: device %s isn't found from %s", __func__, id, SUPPORT_DEV); |
| 401 | } else { |
| 402 | g_supported_dev &= ~SUPPORTED_USB; |
| 403 | } |
| 404 | |
| 405 | done: |
| 406 | if (fd >= 0) close(fd); |
| 407 | } |
| 408 | |
| 409 | // adev_init lock held |
| 410 | void audio_extn_ma_init(void *platform) |
| 411 | { |
| 412 | ma_stream_type_t i = 0; |
| 413 | int ret = 0; |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 414 | char lib_path[128] = {0}; |
| 415 | char mps_path[128] = {0}; |
Jasmine Cha | 6d945d2 | 2018-06-19 09:49:04 -0700 | [diff] [blame] | 416 | char cnf_path[128] = {0}; |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 417 | struct snd_card_split *snd_split_handle = NULL; |
| 418 | snd_split_handle = audio_extn_get_snd_card_split(); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 419 | |
| 420 | if (platform == NULL) { |
| 421 | ALOGE("%s: platform is NULL", __func__); |
| 422 | goto error; |
| 423 | } |
| 424 | |
| 425 | if (my_data) { free(my_data); } |
| 426 | my_data = calloc(1, sizeof(struct ma_platform_data)); |
| 427 | if (my_data == NULL) { |
| 428 | ALOGE("%s: ma_cal alloct fail", __func__); |
| 429 | goto error; |
| 430 | } |
| 431 | |
| 432 | pthread_mutex_init(&my_data->lock, NULL); |
| 433 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 434 | my_data->platform = platform; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 435 | ret = snprintf(lib_path, sizeof(lib_path), "%s/%s", LIB_MA_PATH, LIB_MA_PARAM); |
| 436 | if (ret < 0) { |
| 437 | ALOGE("%s: snprintf failed for lib %s, ret %d", __func__, LIB_MA_PARAM, ret); |
| 438 | goto error; |
| 439 | } |
| 440 | |
| 441 | my_data->waves_handle = dlopen(lib_path, RTLD_NOW); |
| 442 | if (my_data->waves_handle == NULL) { |
| 443 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_MA_PARAM); |
| 444 | goto error; |
| 445 | } else { |
| 446 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_MA_PARAM); |
| 447 | |
| 448 | 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] | 449 | MA_QDSP_PARAM_INIT); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 450 | if (!my_data->ma_param_init) { |
| 451 | ALOGE("%s: dlsym error %s for ma_param_init", __func__, dlerror()); |
| 452 | goto error; |
| 453 | } |
| 454 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 455 | my_data->ma_param_deinit = (ma_param_deinit_t)dlsym( |
| 456 | my_data->waves_handle, MA_QDSP_PARAM_DEINIT); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 457 | if (!my_data->ma_param_deinit) { |
| 458 | ALOGE("%s: dlsym error %s for ma_param_deinit", __func__, dlerror()); |
| 459 | goto error; |
| 460 | } |
| 461 | |
| 462 | 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] | 463 | MA_QDSP_SET_LR_SWAP); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 464 | if (!my_data->ma_set_lr_swap) { |
| 465 | ALOGE("%s: dlsym error %s for ma_set_lr_swap", __func__, dlerror()); |
| 466 | goto error; |
| 467 | } |
| 468 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 469 | my_data->ma_set_sound_mode = (ma_set_sound_mode_t)dlsym( |
| 470 | my_data->waves_handle, MA_QDSP_SET_MODE); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 471 | if (!my_data->ma_set_sound_mode) { |
| 472 | ALOGE("%s: dlsym error %s for ma_set_sound_mode", __func__, dlerror()); |
| 473 | goto error; |
| 474 | } |
| 475 | |
| 476 | 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] | 477 | MA_QDSP_SET_VOL); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 478 | if (!my_data->ma_set_volume) { |
| 479 | ALOGE("%s: dlsym error %s for ma_set_volume", __func__, dlerror()); |
| 480 | goto error; |
| 481 | } |
| 482 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 483 | my_data->ma_set_volume_table = (ma_set_volume_table_t)dlsym( |
| 484 | my_data->waves_handle, MA_QDSP_SET_VOLT); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 485 | if (!my_data->ma_set_volume_table) { |
| 486 | ALOGE("%s: dlsym error %s for ma_set_volume_table", __func__, dlerror()); |
| 487 | goto error; |
| 488 | } |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 489 | |
| 490 | my_data->ma_set_param = (ma_set_param_t)dlsym( |
| 491 | my_data->waves_handle, MA_QDSP_SET_PARAM); |
| 492 | if (!my_data->ma_set_param) { |
| 493 | ALOGE("%s: dlsym error %s for ma_set_param", __func__, dlerror()); |
| 494 | goto error; |
| 495 | } |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 496 | } |
| 497 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 498 | /* get preset table */ |
| 499 | if (snd_split_handle == NULL) { |
| 500 | snprintf(mps_path, sizeof(mps_path), "%s/%s.mps", |
| 501 | PRESET_PATH, MPS_BASE_STRING); |
| 502 | } else { |
| 503 | snprintf(mps_path, sizeof(mps_path), "%s/%s_%s.mps", |
| 504 | PRESET_PATH, MPS_BASE_STRING, snd_split_handle->form_factor); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 505 | } |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 506 | |
Jasmine Cha | 6d945d2 | 2018-06-19 09:49:04 -0700 | [diff] [blame] | 507 | /* get config files */ |
| 508 | if (snd_split_handle == NULL) { |
| 509 | snprintf(cnf_path, sizeof(cnf_path), "%s/%s.ini", |
| 510 | PRESET_PATH, CONFIG_BASE_STRING); |
| 511 | } else { |
| 512 | snprintf(cnf_path, sizeof(cnf_path), "%s/%s_%s.ini", |
| 513 | PRESET_PATH, CONFIG_BASE_STRING, snd_split_handle->form_factor); |
| 514 | } |
| 515 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 516 | /* check file */ |
Jasmine Cha | 6d945d2 | 2018-06-19 09:49:04 -0700 | [diff] [blame] | 517 | if (access(mps_path, R_OK) < 0) { |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 518 | ALOGW("%s: file %s isn't existed.", __func__, mps_path); |
| 519 | goto error; |
| 520 | } else |
| 521 | ALOGD("%s: Loading mps file: %s", __func__, mps_path); |
| 522 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 523 | /* TODO: check user preset table once the feature is enabled |
| 524 | if (access(USER_PRESET_PATH, F_OK) < 0 ){ |
| 525 | ALOGW("%s: file %s isn't existed.", __func__, USER_PRESET_PATH); |
| 526 | goto error; |
| 527 | } |
| 528 | */ |
Jasmine Cha | 6d945d2 | 2018-06-19 09:49:04 -0700 | [diff] [blame] | 529 | |
| 530 | if (access(cnf_path, R_OK) < 0) { |
| 531 | ALOGW("%s: file %s isn't existed.", __func__, cnf_path); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 532 | goto error; |
Jasmine Cha | 6d945d2 | 2018-06-19 09:49:04 -0700 | [diff] [blame] | 533 | } else |
| 534 | ALOGD("%s: Loading ini file: %s", __func__, cnf_path); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 535 | |
| 536 | /* init ma parameter */ |
| 537 | if (my_data->ma_param_init(&g_ma_audio_cal_handle, |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 538 | mps_path, |
| 539 | USER_PRESET_PATH, /* unused */ |
Jasmine Cha | 6d945d2 | 2018-06-19 09:49:04 -0700 | [diff] [blame] | 540 | cnf_path, |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 541 | &set_audio_cal)) { |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 542 | if (!g_ma_audio_cal_handle) { |
| 543 | ALOGE("%s: ma parameters initialize failed", __func__); |
| 544 | my_data->ma_param_deinit(&g_ma_audio_cal_handle); |
| 545 | goto error; |
| 546 | } |
| 547 | ALOGD("%s: ma parameters initialize successful", __func__); |
| 548 | } else { |
| 549 | ALOGE("%s: ma parameters initialize failed", __func__); |
| 550 | goto error; |
| 551 | } |
| 552 | |
| 553 | /* init volume table */ |
| 554 | for (i = 0; i < STREAM_MAX_TYPES; i++) { |
| 555 | ma_cur_state_table[i].vol = 0.0; |
| 556 | ma_cur_state_table[i].active = false; |
| 557 | } |
| 558 | |
| 559 | return; |
| 560 | |
| 561 | error: |
| 562 | if (my_data) { free(my_data); } |
| 563 | my_data = NULL; |
| 564 | } |
| 565 | |
| 566 | //adev_init lock held |
| 567 | void audio_extn_ma_deinit() |
| 568 | { |
| 569 | if (my_data) { |
| 570 | /* deinit ma parameter */ |
| 571 | if (my_data->ma_param_deinit && |
| 572 | my_data->ma_param_deinit(&g_ma_audio_cal_handle)) |
| 573 | ALOGD("%s: ma parameters uninitialize successful", __func__); |
| 574 | else |
| 575 | ALOGD("%s: ma parameters uninitialize failed", __func__); |
| 576 | |
| 577 | pthread_mutex_destroy(&my_data->lock); |
| 578 | free(my_data); |
| 579 | my_data = NULL; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | // adev_init and adev lock held |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 584 | bool audio_extn_ma_set_state(struct audio_device *adev, int stream_type, |
| 585 | float vol, bool active) |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 586 | { |
| 587 | bool ret = false; |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 588 | bool first_enable = false; |
| 589 | struct ma_state pr_mstate; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 590 | |
Jasmine Cha | fc63f34 | 2018-06-27 10:55:06 -0700 | [diff] [blame] | 591 | if (stream_type >= STREAM_MAX_TYPES || |
| 592 | stream_type < STREAM_MIN_TYPES) { |
| 593 | ALOGE("%s: stream_type %d out of range.", __func__, stream_type); |
| 594 | return ret; |
| 595 | } |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 596 | |
| 597 | if (!my_data) { |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 598 | ALOGV("%s: maxxaudio isn't initialized.", __func__); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 599 | return ret; |
| 600 | } |
| 601 | |
Jasmine Cha | fc63f34 | 2018-06-27 10:55:06 -0700 | [diff] [blame] | 602 | ALOGV("%s: stream[%d] vol[%f] active[%s]", |
| 603 | __func__, stream_type, vol, active ? "true" : "false"); |
| 604 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 605 | pr_mstate.vol = ma_cur_state_table[(ma_stream_type_t)stream_type].vol; |
| 606 | 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] | 607 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 608 | // update condition: vol or active state changes |
| 609 | if (pr_mstate.vol != vol || pr_mstate.active != active) { |
| 610 | |
| 611 | pthread_mutex_lock(&my_data->lock); |
| 612 | // get active state before updating |
| 613 | first_enable = (!is_active()) && active; |
| 614 | |
| 615 | ma_cur_state_table[(ma_stream_type_t)stream_type].vol = vol; |
| 616 | ma_cur_state_table[(ma_stream_type_t)stream_type].active = active; |
| 617 | |
| 618 | if (first_enable) //all F -> one of T |
| 619 | ret = check_and_send_all_audio_cal(adev, MA_CMD_SOFT_MUTE_DISABLE); |
| 620 | else if (!is_active()) // all F |
| 621 | ret = check_and_send_all_audio_cal(adev, MA_CMD_SOFT_MUTE_ENABLE); |
| 622 | |
| 623 | ret = check_and_send_all_audio_cal(adev, MA_CMD_VOL); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 624 | |
| 625 | pthread_mutex_unlock(&my_data->lock); |
| 626 | } |
| 627 | |
| 628 | return ret; |
| 629 | } |
| 630 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 631 | void audio_extn_ma_set_device(struct audio_usecase *usecase) |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 632 | { |
| 633 | int i = 0; |
| 634 | int u_index = -1; |
| 635 | float vol = 0; |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 636 | struct ma_audio_cal_settings ma_cal; |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 637 | |
| 638 | if (!my_data) { |
| 639 | ALOGV("%s: maxxaudio isn't initialized.", __func__); |
| 640 | return; |
| 641 | } |
| 642 | |
| 643 | if (!valid_usecase(usecase)) { |
| 644 | ALOGV("%s: %d is not supported usecase", __func__, usecase->id); |
| 645 | return; |
| 646 | } |
| 647 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 648 | ma_cal_init(&ma_cal); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 649 | |
| 650 | /* update audio_cal and send it */ |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 651 | ma_cal.common.app_type = usecase->stream.out->app_type_cfg.app_type; |
| 652 | ma_cal.common.device = usecase->stream.out->devices; |
| 653 | ALOGV("%s: send usecase(%d) app_type(%d) device(%d)", |
| 654 | __func__, usecase->id, ma_cal.common.app_type, |
| 655 | ma_cal.common.device); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 656 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 657 | pthread_mutex_lock(&my_data->lock); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 658 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 659 | if (is_active()) { |
| 660 | ALOGV("%s: send volume table === Start", __func__); |
| 661 | for (i = 0; i < STREAM_MAX_TYPES; i++) |
| 662 | ALOGV("%s: stream(%d) volume(%f) active(%s)", __func__, i, |
| 663 | ma_cur_state_table[i].vol, |
| 664 | ma_cur_state_table[i].active ? "T" : "F"); |
| 665 | ALOGV("%s: send volume table === End", __func__); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 666 | |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 667 | if (!ma_set_volume_table_l(&ma_cal, |
| 668 | STREAM_MAX_TYPES, |
| 669 | ma_cur_state_table)) |
| 670 | ALOGE("ma_set_volume_table_l returned with error."); |
| 671 | else |
| 672 | ALOGV("ma_set_volume_table_l success"); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 673 | |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 674 | } |
Jasmine Cha | 25cd74d | 2018-10-01 10:06:11 +0800 | [diff] [blame^] | 675 | pthread_mutex_unlock(&my_data->lock); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 676 | } |
| 677 | |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 678 | void audio_extn_ma_set_parameters(struct audio_device *adev, |
| 679 | struct str_parms *parms) |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 680 | { |
| 681 | int ret; |
| 682 | bool ret_b; |
| 683 | int val; |
| 684 | char value[128]; |
| 685 | |
| 686 | // do LR swap and usb recognition |
| 687 | ret = str_parms_get_int(parms, "rotation", &val); |
| 688 | if (ret >= 0) { |
| 689 | switch (val) { |
| 690 | case 270: |
| 691 | ma_set_swap_l(adev, true); |
| 692 | break; |
| 693 | case 0: |
| 694 | case 90: |
| 695 | case 180: |
| 696 | ma_set_swap_l(adev, false); |
| 697 | break; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | // check connect status |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 702 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, |
| 703 | sizeof(value)); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 704 | if (ret >= 0) { |
| 705 | audio_devices_t device = (audio_devices_t)strtoul(value, NULL, 10); |
| 706 | if (audio_is_usb_out_device(device)) { |
| 707 | ret = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 708 | if (ret >= 0) { |
| 709 | const int card = atoi(value); |
| 710 | ma_support_usb(true, card); |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | // check disconnect status |
Jasmine Cha | 70771b6 | 2018-05-15 15:02:43 +0800 | [diff] [blame] | 716 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, |
| 717 | sizeof(value)); |
jasmine cha | 270b776 | 2018-03-30 15:41:33 +0800 | [diff] [blame] | 718 | if (ret >= 0) { |
| 719 | audio_devices_t device = (audio_devices_t)strtoul(value, NULL, 10); |
| 720 | if (audio_is_usb_out_device(device)) { |
| 721 | ret = str_parms_get_str(parms, "card", value, sizeof(value)); |
| 722 | if (ret >= 0) { |
| 723 | const int card = atoi(value); |
| 724 | ma_support_usb(false, card /*useless*/); |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | bool audio_extn_ma_supported_usb() |
| 731 | { |
| 732 | ALOGV("%s: current support 0x%x", __func__, g_supported_dev); |
| 733 | return (g_supported_dev & SUPPORTED_USB) ? true : false; |
| 734 | } |