Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2013 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 "msm8960_platform" |
| 18 | /*#define LOG_NDEBUG 0*/ |
| 19 | #define LOG_NDDEBUG 0 |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <dlfcn.h> |
| 23 | #include <cutils/log.h> |
| 24 | #include <cutils/properties.h> |
| 25 | #include <audio_hw.h> |
| 26 | #include <platform_api.h> |
| 27 | #include "platform.h" |
| 28 | |
| 29 | #define LIB_ACDB_LOADER "libacdbloader.so" |
| 30 | #define LIB_CSD_CLIENT "libcsd-client.so" |
| 31 | |
| 32 | #define DUALMIC_CONFIG_NONE 0 /* Target does not contain 2 mics */ |
| 33 | #define DUALMIC_CONFIG_ENDFIRE 1 |
| 34 | #define DUALMIC_CONFIG_BROADSIDE 2 |
| 35 | |
| 36 | /* |
| 37 | * This is the sysfs path for the HDMI audio data block |
| 38 | */ |
| 39 | #define AUDIO_DATA_BLOCK_PATH "/sys/class/graphics/fb1/audio_data_block" |
| 40 | |
| 41 | /* |
| 42 | * This file will have a maximum of 38 bytes: |
| 43 | * |
| 44 | * 4 bytes: number of audio blocks |
| 45 | * 4 bytes: total length of Short Audio Descriptor (SAD) blocks |
| 46 | * Maximum 10 * 3 bytes: SAD blocks |
| 47 | */ |
| 48 | #define MAX_SAD_BLOCKS 10 |
| 49 | #define SAD_BLOCK_SIZE 3 |
| 50 | |
| 51 | /* EDID format ID for LPCM audio */ |
| 52 | #define EDID_FORMAT_LPCM 1 |
| 53 | |
| 54 | struct audio_block_header |
| 55 | { |
| 56 | int reserved; |
| 57 | int length; |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | typedef void (*acdb_deallocate_t)(); |
| 62 | typedef int (*acdb_init_t)(); |
| 63 | typedef void (*acdb_send_audio_cal_t)(int, int); |
| 64 | typedef void (*acdb_send_voice_cal_t)(int, int); |
| 65 | |
| 66 | typedef int (*csd_client_init_t)(); |
| 67 | typedef int (*csd_client_deinit_t)(); |
| 68 | typedef int (*csd_disable_device_t)(); |
| 69 | typedef int (*csd_enable_device_t)(int, int, uint32_t); |
| 70 | typedef int (*csd_volume_t)(int); |
| 71 | typedef int (*csd_mic_mute_t)(int); |
| 72 | typedef int (*csd_start_voice_t)(); |
| 73 | typedef int (*csd_stop_voice_t)(); |
| 74 | |
| 75 | |
| 76 | /* Audio calibration related functions */ |
| 77 | struct platform_data { |
| 78 | struct audio_device *adev; |
| 79 | bool fluence_in_spkr_mode; |
| 80 | bool fluence_in_voice_call; |
| 81 | bool fluence_in_voice_rec; |
| 82 | int dualmic_config; |
| 83 | |
| 84 | void *acdb_handle; |
| 85 | acdb_init_t acdb_init; |
| 86 | acdb_deallocate_t acdb_deallocate; |
| 87 | acdb_send_audio_cal_t acdb_send_audio_cal; |
| 88 | acdb_send_voice_cal_t acdb_send_voice_cal; |
| 89 | |
| 90 | /* CSD Client related functions for voice call */ |
| 91 | void *csd_client; |
| 92 | csd_client_init_t csd_client_init; |
| 93 | csd_client_deinit_t csd_client_deinit; |
| 94 | csd_disable_device_t csd_disable_device; |
| 95 | csd_enable_device_t csd_enable_device; |
| 96 | csd_volume_t csd_volume; |
| 97 | csd_mic_mute_t csd_mic_mute; |
| 98 | csd_start_voice_t csd_start_voice; |
| 99 | csd_stop_voice_t csd_stop_voice; |
| 100 | }; |
| 101 | |
| 102 | static const int pcm_device_table[AUDIO_USECASE_MAX][2] = { |
| 103 | [USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = {0, 0}, |
| 104 | [USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = {14, 14}, |
| 105 | [USECASE_AUDIO_PLAYBACK_MULTI_CH] = {1, 1}, |
| 106 | [USECASE_AUDIO_RECORD] = {0, 0}, |
| 107 | [USECASE_AUDIO_RECORD_LOW_LATENCY] = {14, 14}, |
| 108 | [USECASE_VOICE_CALL] = {12, 12}, |
| 109 | }; |
| 110 | |
| 111 | /* Array to store sound devices */ |
| 112 | static const char * const device_table[SND_DEVICE_MAX] = { |
| 113 | [SND_DEVICE_NONE] = "none", |
| 114 | /* Playback sound devices */ |
| 115 | [SND_DEVICE_OUT_HANDSET] = "handset", |
| 116 | [SND_DEVICE_OUT_SPEAKER] = "speaker", |
| 117 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = "speaker-reverse", |
| 118 | [SND_DEVICE_OUT_HEADPHONES] = "headphones", |
| 119 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = "speaker-and-headphones", |
| 120 | [SND_DEVICE_OUT_VOICE_SPEAKER] = "voice-speaker", |
| 121 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = "voice-headphones", |
| 122 | [SND_DEVICE_OUT_HDMI] = "hdmi", |
| 123 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = "speaker-and-hdmi", |
| 124 | [SND_DEVICE_OUT_BT_SCO] = "bt-sco-headset", |
| 125 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = "voice-handset-tmus", |
| 126 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = "voice-tty-full-headphones", |
| 127 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = "voice-tty-vco-headphones", |
| 128 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = "voice-tty-hco-handset", |
| 129 | |
| 130 | /* Capture sound devices */ |
| 131 | [SND_DEVICE_IN_HANDSET_MIC] = "handset-mic", |
| 132 | [SND_DEVICE_IN_SPEAKER_MIC] = "speaker-mic", |
| 133 | [SND_DEVICE_IN_HEADSET_MIC] = "headset-mic", |
| 134 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = "handset-mic", |
| 135 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = "voice-speaker-mic", |
| 136 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = "headset-mic", |
| 137 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = "voice-speaker-mic", |
| 138 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = "voice-headset-mic", |
| 139 | [SND_DEVICE_IN_HDMI_MIC] = "hdmi-mic", |
| 140 | [SND_DEVICE_IN_BT_SCO_MIC] = "bt-sco-mic", |
| 141 | [SND_DEVICE_IN_CAMCORDER_MIC] = "camcorder-mic", |
| 142 | [SND_DEVICE_IN_VOICE_DMIC_EF] = "voice-dmic-ef", |
| 143 | [SND_DEVICE_IN_VOICE_DMIC_BS] = "voice-dmic-bs", |
| 144 | [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = "voice-dmic-ef-tmus", |
| 145 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = "voice-speaker-dmic-ef", |
| 146 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = "voice-speaker-dmic-bs", |
| 147 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = "voice-tty-full-headset-mic", |
| 148 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = "voice-tty-vco-handset-mic", |
| 149 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = "voice-tty-hco-headset-mic", |
| 150 | [SND_DEVICE_IN_VOICE_REC_MIC] = "voice-rec-mic", |
| 151 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = "voice-rec-dmic-ef", |
| 152 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = "voice-rec-dmic-bs", |
| 153 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = "voice-rec-dmic-ef-fluence", |
| 154 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = "voice-rec-dmic-bs-fluence", |
| 155 | }; |
| 156 | |
| 157 | /* ACDB IDs (audio DSP path configuration IDs) for each sound device */ |
| 158 | static const int acdb_device_table[SND_DEVICE_MAX] = { |
| 159 | [SND_DEVICE_NONE] = -1, |
| 160 | [SND_DEVICE_OUT_HANDSET] = 7, |
| 161 | [SND_DEVICE_OUT_SPEAKER] = 14, |
| 162 | [SND_DEVICE_OUT_SPEAKER_REVERSE] = 14, |
| 163 | [SND_DEVICE_OUT_HEADPHONES] = 10, |
| 164 | [SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES] = 10, |
| 165 | [SND_DEVICE_OUT_VOICE_SPEAKER] = 14, |
| 166 | [SND_DEVICE_OUT_VOICE_HEADPHONES] = 10, |
| 167 | [SND_DEVICE_OUT_HDMI] = 18, |
| 168 | [SND_DEVICE_OUT_SPEAKER_AND_HDMI] = 14, |
| 169 | [SND_DEVICE_OUT_BT_SCO] = 22, |
| 170 | [SND_DEVICE_OUT_VOICE_HANDSET_TMUS] = 81, |
| 171 | [SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES] = 17, |
| 172 | [SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES] = 17, |
| 173 | [SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET] = 37, |
| 174 | |
| 175 | [SND_DEVICE_IN_HANDSET_MIC] = 4, |
| 176 | [SND_DEVICE_IN_SPEAKER_MIC] = 4, |
| 177 | [SND_DEVICE_IN_HEADSET_MIC] = 8, |
| 178 | [SND_DEVICE_IN_HANDSET_MIC_AEC] = 40, |
| 179 | [SND_DEVICE_IN_SPEAKER_MIC_AEC] = 42, |
| 180 | [SND_DEVICE_IN_HEADSET_MIC_AEC] = 47, |
| 181 | [SND_DEVICE_IN_VOICE_SPEAKER_MIC] = 11, |
| 182 | [SND_DEVICE_IN_VOICE_HEADSET_MIC] = 8, |
| 183 | [SND_DEVICE_IN_HDMI_MIC] = 4, |
| 184 | [SND_DEVICE_IN_BT_SCO_MIC] = 21, |
| 185 | [SND_DEVICE_IN_CAMCORDER_MIC] = 61, |
| 186 | [SND_DEVICE_IN_VOICE_DMIC_EF] = 6, |
| 187 | [SND_DEVICE_IN_VOICE_DMIC_BS] = 5, |
| 188 | [SND_DEVICE_IN_VOICE_DMIC_EF_TMUS] = 91, |
| 189 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF] = 13, |
| 190 | [SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS] = 12, |
| 191 | [SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC] = 16, |
| 192 | [SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC] = 36, |
| 193 | [SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC] = 16, |
| 194 | [SND_DEVICE_IN_VOICE_REC_MIC] = 62, |
| 195 | /* TODO: Update with proper acdb ids */ |
| 196 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF] = 62, |
| 197 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS] = 62, |
| 198 | [SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE] = 6, |
| 199 | [SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE] = 5, |
| 200 | }; |
| 201 | |
| 202 | static pthread_once_t check_op_once_ctl = PTHREAD_ONCE_INIT; |
| 203 | static bool is_tmus = false; |
| 204 | |
| 205 | static void check_operator() |
| 206 | { |
| 207 | char value[PROPERTY_VALUE_MAX]; |
| 208 | int mccmnc; |
| 209 | property_get("gsm.sim.operator.numeric",value,"0"); |
| 210 | mccmnc = atoi(value); |
| 211 | ALOGD("%s: tmus mccmnc %d", __func__, mccmnc); |
| 212 | switch(mccmnc) { |
| 213 | /* TMUS MCC(310), MNC(490, 260, 026) */ |
| 214 | case 310490: |
| 215 | case 310260: |
| 216 | case 310026: |
| 217 | is_tmus = true; |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | bool is_operator_tmus() |
| 223 | { |
| 224 | pthread_once(&check_op_once_ctl, check_operator); |
| 225 | return is_tmus; |
| 226 | } |
| 227 | |
| 228 | static int set_echo_reference(struct mixer *mixer, const char* ec_ref) |
| 229 | { |
| 230 | struct mixer_ctl *ctl; |
| 231 | const char *mixer_ctl_name = "EC_REF_RX"; |
| 232 | |
| 233 | ctl = mixer_get_ctl_by_name(mixer, mixer_ctl_name); |
| 234 | if (!ctl) { |
| 235 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 236 | __func__, mixer_ctl_name); |
| 237 | return -EINVAL; |
| 238 | } |
| 239 | ALOGV("Setting EC Reference: %s", ec_ref); |
| 240 | mixer_ctl_set_enum_by_string(ctl, ec_ref); |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | void *platform_init(struct audio_device *adev) |
| 245 | { |
| 246 | char platform[PROPERTY_VALUE_MAX]; |
| 247 | char baseband[PROPERTY_VALUE_MAX]; |
| 248 | char value[PROPERTY_VALUE_MAX]; |
| 249 | struct platform_data *my_data; |
| 250 | |
| 251 | my_data = calloc(1, sizeof(struct platform_data)); |
| 252 | |
| 253 | my_data->adev = adev; |
| 254 | my_data->dualmic_config = DUALMIC_CONFIG_NONE; |
| 255 | my_data->fluence_in_spkr_mode = false; |
| 256 | my_data->fluence_in_voice_call = false; |
| 257 | my_data->fluence_in_voice_rec = false; |
| 258 | |
| 259 | property_get("persist.audio.dualmic.config",value,""); |
| 260 | if (!strcmp("broadside", value)) { |
| 261 | my_data->dualmic_config = DUALMIC_CONFIG_BROADSIDE; |
| 262 | adev->acdb_settings |= DMIC_FLAG; |
| 263 | } else if (!strcmp("endfire", value)) { |
| 264 | my_data->dualmic_config = DUALMIC_CONFIG_ENDFIRE; |
| 265 | adev->acdb_settings |= DMIC_FLAG; |
| 266 | } |
| 267 | |
| 268 | if (my_data->dualmic_config != DUALMIC_CONFIG_NONE) { |
| 269 | property_get("persist.audio.fluence.voicecall",value,""); |
| 270 | if (!strcmp("true", value)) { |
| 271 | my_data->fluence_in_voice_call = true; |
| 272 | } |
| 273 | |
| 274 | property_get("persist.audio.fluence.voicerec",value,""); |
| 275 | if (!strcmp("true", value)) { |
| 276 | my_data->fluence_in_voice_rec = true; |
| 277 | } |
| 278 | |
| 279 | property_get("persist.audio.fluence.speaker",value,""); |
| 280 | if (!strcmp("true", value)) { |
| 281 | my_data->fluence_in_spkr_mode = true; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | my_data->acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 286 | if (my_data->acdb_handle == NULL) { |
| 287 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_ACDB_LOADER); |
| 288 | } else { |
| 289 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_ACDB_LOADER); |
| 290 | my_data->acdb_deallocate = (acdb_deallocate_t)dlsym(my_data->acdb_handle, |
| 291 | "acdb_loader_deallocate_ACDB"); |
| 292 | my_data->acdb_send_audio_cal = (acdb_send_audio_cal_t)dlsym(my_data->acdb_handle, |
| 293 | "acdb_loader_send_audio_cal"); |
| 294 | if (!my_data->acdb_send_audio_cal) |
| 295 | ALOGW("%s: Could not find the symbol acdb_send_audio_cal from %s", |
| 296 | __func__, LIB_ACDB_LOADER); |
| 297 | my_data->acdb_send_voice_cal = (acdb_send_voice_cal_t)dlsym(my_data->acdb_handle, |
| 298 | "acdb_loader_send_voice_cal"); |
| 299 | my_data->acdb_init = (acdb_init_t)dlsym(my_data->acdb_handle, |
| 300 | "acdb_loader_init_ACDB"); |
| 301 | if (my_data->acdb_init == NULL) |
| 302 | ALOGE("%s: dlsym error %s for acdb_loader_init_ACDB", __func__, dlerror()); |
| 303 | else |
| 304 | my_data->acdb_init(); |
| 305 | } |
| 306 | |
| 307 | /* If platform is Fusion3, load CSD Client specific symbols |
| 308 | * Voice call is handled by MDM and apps processor talks to |
| 309 | * MDM through CSD Client |
| 310 | */ |
| 311 | property_get("ro.board.platform", platform, ""); |
| 312 | property_get("ro.baseband", baseband, ""); |
| 313 | if (!strcmp("msm8960", platform) && !strcmp("mdm", baseband)) { |
| 314 | my_data->csd_client = dlopen(LIB_CSD_CLIENT, RTLD_NOW); |
| 315 | if (my_data->csd_client == NULL) |
| 316 | ALOGE("%s: DLOPEN failed for %s", __func__, LIB_CSD_CLIENT); |
| 317 | } |
| 318 | |
| 319 | if (my_data->csd_client) { |
| 320 | ALOGV("%s: DLOPEN successful for %s", __func__, LIB_CSD_CLIENT); |
| 321 | my_data->csd_client_deinit = (csd_client_deinit_t)dlsym(my_data->csd_client, |
| 322 | "csd_client_deinit"); |
| 323 | my_data->csd_disable_device = (csd_disable_device_t)dlsym(my_data->csd_client, |
| 324 | "csd_client_disable_device"); |
| 325 | my_data->csd_enable_device = (csd_enable_device_t)dlsym(my_data->csd_client, |
| 326 | "csd_client_enable_device"); |
| 327 | my_data->csd_start_voice = (csd_start_voice_t)dlsym(my_data->csd_client, |
| 328 | "csd_client_start_voice"); |
| 329 | my_data->csd_stop_voice = (csd_stop_voice_t)dlsym(my_data->csd_client, |
| 330 | "csd_client_stop_voice"); |
| 331 | my_data->csd_volume = (csd_volume_t)dlsym(my_data->csd_client, |
| 332 | "csd_client_volume"); |
| 333 | my_data->csd_mic_mute = (csd_mic_mute_t)dlsym(my_data->csd_client, |
| 334 | "csd_client_mic_mute"); |
| 335 | my_data->csd_client_init = (csd_client_init_t)dlsym(my_data->csd_client, |
| 336 | "csd_client_init"); |
| 337 | |
| 338 | if (my_data->csd_client_init == NULL) { |
| 339 | ALOGE("%s: dlsym error %s for csd_client_init", __func__, dlerror()); |
| 340 | } else { |
| 341 | my_data->csd_client_init(); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | return my_data; |
| 346 | } |
| 347 | |
| 348 | void platform_deinit(void *platform) |
| 349 | { |
| 350 | free(platform); |
| 351 | } |
| 352 | |
| 353 | const char *platform_get_snd_device_name(snd_device_t snd_device) |
| 354 | { |
| 355 | if (snd_device >= SND_DEVICE_MIN && snd_device < SND_DEVICE_MAX) |
| 356 | return device_table[snd_device]; |
| 357 | else |
| 358 | return ""; |
| 359 | } |
| 360 | |
| 361 | void platform_add_backend_name(char *mixer_path, snd_device_t snd_device) |
| 362 | { |
| 363 | if (snd_device == SND_DEVICE_IN_BT_SCO_MIC) |
| 364 | strcat(mixer_path, " bt-sco"); |
| 365 | else if(snd_device == SND_DEVICE_OUT_BT_SCO) |
| 366 | strcat(mixer_path, " bt-sco"); |
| 367 | else if (snd_device == SND_DEVICE_OUT_HDMI) |
| 368 | strcat(mixer_path, " hdmi"); |
| 369 | else if (snd_device == SND_DEVICE_OUT_SPEAKER_AND_HDMI) |
| 370 | strcat(mixer_path, " speaker-and-hdmi"); |
| 371 | } |
| 372 | |
| 373 | int platform_get_pcm_device_id(audio_usecase_t usecase, int device_type) |
| 374 | { |
| 375 | int device_id; |
| 376 | if (device_type == PCM_PLAYBACK) |
| 377 | device_id = pcm_device_table[usecase][0]; |
| 378 | else |
| 379 | device_id = pcm_device_table[usecase][1]; |
| 380 | return device_id; |
| 381 | } |
| 382 | |
| 383 | int platform_send_audio_calibration(void *platform, snd_device_t snd_device) |
| 384 | { |
| 385 | struct platform_data *my_data = (struct platform_data *)platform; |
| 386 | int acdb_dev_id, acdb_dev_type; |
| 387 | |
| 388 | acdb_dev_id = acdb_device_table[snd_device]; |
| 389 | if (acdb_dev_id < 0) { |
| 390 | ALOGE("%s: Could not find acdb id for device(%d)", |
| 391 | __func__, snd_device); |
| 392 | return -EINVAL; |
| 393 | } |
| 394 | if (my_data->acdb_send_audio_cal) { |
| 395 | ALOGD("%s: sending audio calibration for snd_device(%d) acdb_id(%d)", |
| 396 | __func__, snd_device, acdb_dev_id); |
| 397 | if (snd_device >= SND_DEVICE_OUT_BEGIN && |
| 398 | snd_device < SND_DEVICE_OUT_END) |
| 399 | acdb_dev_type = ACDB_DEV_TYPE_OUT; |
| 400 | else |
| 401 | acdb_dev_type = ACDB_DEV_TYPE_IN; |
| 402 | my_data->acdb_send_audio_cal(acdb_dev_id, acdb_dev_type); |
| 403 | } |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | int platform_switch_voice_call_device_pre(void *platform) |
| 408 | { |
| 409 | struct platform_data *my_data = (struct platform_data *)platform; |
| 410 | int ret = 0; |
| 411 | |
| 412 | if (my_data->csd_client != NULL) { |
| 413 | /* This must be called before disabling the mixer controls on APQ side */ |
| 414 | if (my_data->csd_disable_device == NULL) { |
| 415 | ALOGE("%s: dlsym error for csd_disable_device", __func__); |
| 416 | } else { |
| 417 | ret = my_data->csd_disable_device(); |
| 418 | if (ret < 0) { |
| 419 | ALOGE("%s: csd_client_disable_device, failed, error %d", |
| 420 | __func__, ret); |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | return ret; |
| 425 | } |
| 426 | |
| 427 | int platform_switch_voice_call_device_post(void *platform, |
| 428 | snd_device_t out_snd_device, |
| 429 | snd_device_t in_snd_device) |
| 430 | { |
| 431 | struct platform_data *my_data = (struct platform_data *)platform; |
| 432 | int acdb_rx_id, acdb_tx_id; |
| 433 | int ret = 0; |
| 434 | |
| 435 | if (my_data->csd_client) { |
| 436 | if (my_data->csd_enable_device == NULL) { |
| 437 | ALOGE("%s: dlsym error for csd_enable_device", |
| 438 | __func__); |
| 439 | } else { |
| 440 | acdb_rx_id = acdb_device_table[out_snd_device]; |
| 441 | acdb_tx_id = acdb_device_table[in_snd_device]; |
| 442 | |
| 443 | if (acdb_rx_id > 0 || acdb_tx_id > 0) { |
| 444 | ret = my_data->csd_enable_device(acdb_rx_id, acdb_tx_id, |
| 445 | my_data->adev->acdb_settings); |
| 446 | if (ret < 0) { |
| 447 | ALOGE("%s: csd_enable_device, failed, error %d", |
| 448 | __func__, ret); |
| 449 | } |
| 450 | } else { |
| 451 | ALOGE("%s: Incorrect ACDB IDs (rx: %d tx: %d)", __func__, |
| 452 | acdb_rx_id, acdb_tx_id); |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | int platform_start_voice_call(void *platform) |
| 461 | { |
| 462 | struct platform_data *my_data = (struct platform_data *)platform; |
| 463 | int ret = 0; |
| 464 | |
| 465 | if (my_data->csd_client) { |
| 466 | if (my_data->csd_start_voice == NULL) { |
| 467 | ALOGE("dlsym error for csd_client_start_voice"); |
| 468 | ret = -ENOSYS; |
| 469 | } else { |
| 470 | ret = my_data->csd_start_voice(); |
| 471 | if (ret < 0) { |
| 472 | ALOGE("%s: csd_start_voice error %d\n", __func__, ret); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | return ret; |
| 478 | } |
| 479 | |
| 480 | int platform_stop_voice_call(void *platform) |
| 481 | { |
| 482 | struct platform_data *my_data = (struct platform_data *)platform; |
| 483 | int ret = 0; |
| 484 | |
| 485 | if (my_data->csd_client) { |
| 486 | if (my_data->csd_stop_voice == NULL) { |
| 487 | ALOGE("dlsym error for csd_stop_voice"); |
| 488 | } else { |
| 489 | ret = my_data->csd_stop_voice(); |
| 490 | if (ret < 0) { |
| 491 | ALOGE("%s: csd_stop_voice error %d\n", __func__, ret); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | return ret; |
| 497 | } |
| 498 | |
| 499 | int platform_set_voice_volume(void *platform, int volume) |
| 500 | { |
| 501 | struct platform_data *my_data = (struct platform_data *)platform; |
| 502 | int ret = 0; |
| 503 | |
| 504 | if (my_data->csd_client) { |
| 505 | if (my_data->csd_volume == NULL) { |
| 506 | ALOGE("%s: dlsym error for csd_volume", __func__); |
| 507 | } else { |
| 508 | ret = my_data->csd_volume(volume); |
| 509 | if (ret < 0) { |
| 510 | ALOGE("%s: csd_volume error %d", __func__, ret); |
| 511 | } |
| 512 | } |
| 513 | } else { |
| 514 | ALOGE("%s: No CSD Client present", __func__); |
| 515 | } |
| 516 | |
| 517 | return ret; |
| 518 | } |
| 519 | |
| 520 | int platform_set_mic_mute(void *platform, bool state) |
| 521 | { |
| 522 | struct platform_data *my_data = (struct platform_data *)platform; |
| 523 | int ret = 0; |
| 524 | |
| 525 | if (my_data->adev->mode == AUDIO_MODE_IN_CALL) { |
| 526 | if (my_data->csd_client) { |
| 527 | if (my_data->csd_mic_mute == NULL) { |
| 528 | ALOGE("%s: dlsym error for csd_mic_mute", __func__); |
| 529 | } else { |
| 530 | ret = my_data->csd_mic_mute(state); |
| 531 | if (ret < 0) { |
| 532 | ALOGE("%s: csd_mic_mute error %d", __func__, ret); |
| 533 | } |
| 534 | } |
| 535 | } else { |
| 536 | ALOGE("%s: No CSD Client present", __func__); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | return ret; |
| 541 | } |
| 542 | |
| 543 | snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devices) |
| 544 | { |
| 545 | struct platform_data *my_data = (struct platform_data *)platform; |
| 546 | struct audio_device *adev = my_data->adev; |
| 547 | audio_mode_t mode = adev->mode; |
| 548 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 549 | |
| 550 | ALOGV("%s: enter: output devices(%#x)", __func__, devices); |
| 551 | if (devices == AUDIO_DEVICE_NONE || |
| 552 | devices & AUDIO_DEVICE_BIT_IN) { |
| 553 | ALOGV("%s: Invalid output devices (%#x)", __func__, devices); |
| 554 | goto exit; |
| 555 | } |
| 556 | |
| 557 | if (mode == AUDIO_MODE_IN_CALL) { |
| 558 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 559 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 560 | if (adev->tty_mode == TTY_MODE_FULL) |
| 561 | snd_device = SND_DEVICE_OUT_VOICE_TTY_FULL_HEADPHONES; |
| 562 | else if (adev->tty_mode == TTY_MODE_VCO) |
| 563 | snd_device = SND_DEVICE_OUT_VOICE_TTY_VCO_HEADPHONES; |
| 564 | else if (adev->tty_mode == TTY_MODE_HCO) |
| 565 | snd_device = SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET; |
| 566 | else |
| 567 | snd_device = SND_DEVICE_OUT_VOICE_HEADPHONES; |
| 568 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
| 569 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 570 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 571 | snd_device = SND_DEVICE_OUT_VOICE_SPEAKER; |
| 572 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 573 | if (is_operator_tmus()) |
| 574 | snd_device = SND_DEVICE_OUT_VOICE_HANDSET_TMUS; |
| 575 | else |
| 576 | snd_device = SND_DEVICE_OUT_HANDSET; |
| 577 | } |
| 578 | if (snd_device != SND_DEVICE_NONE) { |
| 579 | goto exit; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | if (popcount(devices) == 2) { |
| 584 | if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | |
| 585 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 586 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 587 | } else if (devices == (AUDIO_DEVICE_OUT_WIRED_HEADSET | |
| 588 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 589 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES; |
| 590 | } else if (devices == (AUDIO_DEVICE_OUT_AUX_DIGITAL | |
| 591 | AUDIO_DEVICE_OUT_SPEAKER)) { |
| 592 | snd_device = SND_DEVICE_OUT_SPEAKER_AND_HDMI; |
| 593 | } else { |
| 594 | ALOGE("%s: Invalid combo device(%#x)", __func__, devices); |
| 595 | goto exit; |
| 596 | } |
| 597 | if (snd_device != SND_DEVICE_NONE) { |
| 598 | goto exit; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | if (popcount(devices) != 1) { |
| 603 | ALOGE("%s: Invalid output devices(%#x)", __func__, devices); |
| 604 | goto exit; |
| 605 | } |
| 606 | |
| 607 | if (devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 608 | devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 609 | snd_device = SND_DEVICE_OUT_HEADPHONES; |
| 610 | } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) { |
| 611 | if (adev->speaker_lr_swap) |
| 612 | snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE; |
| 613 | else |
| 614 | snd_device = SND_DEVICE_OUT_SPEAKER; |
| 615 | } else if (devices & AUDIO_DEVICE_OUT_ALL_SCO) { |
| 616 | snd_device = SND_DEVICE_OUT_BT_SCO; |
| 617 | } else if (devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 618 | snd_device = SND_DEVICE_OUT_HDMI ; |
| 619 | } else if (devices & AUDIO_DEVICE_OUT_EARPIECE) { |
| 620 | snd_device = SND_DEVICE_OUT_HANDSET; |
| 621 | } else { |
| 622 | ALOGE("%s: Unknown device(s) %#x", __func__, devices); |
| 623 | } |
| 624 | exit: |
| 625 | ALOGV("%s: exit: snd_device(%s)", __func__, device_table[snd_device]); |
| 626 | return snd_device; |
| 627 | } |
| 628 | |
| 629 | snd_device_t platform_get_input_snd_device(void *platform, audio_devices_t out_device) |
| 630 | { |
| 631 | struct platform_data *my_data = (struct platform_data *)platform; |
| 632 | struct audio_device *adev = my_data->adev; |
| 633 | audio_source_t source = (adev->active_input == NULL) ? |
| 634 | AUDIO_SOURCE_DEFAULT : adev->active_input->source; |
| 635 | |
| 636 | audio_mode_t mode = adev->mode; |
| 637 | audio_devices_t in_device = ((adev->active_input == NULL) ? |
| 638 | AUDIO_DEVICE_NONE : adev->active_input->device) |
| 639 | & ~AUDIO_DEVICE_BIT_IN; |
| 640 | audio_channel_mask_t channel_mask = (adev->active_input == NULL) ? |
| 641 | AUDIO_CHANNEL_IN_MONO : adev->active_input->channel_mask; |
| 642 | snd_device_t snd_device = SND_DEVICE_NONE; |
| 643 | |
| 644 | ALOGV("%s: enter: out_device(%#x) in_device(%#x)", |
| 645 | __func__, out_device, in_device); |
| 646 | if (mode == AUDIO_MODE_IN_CALL) { |
| 647 | if (out_device == AUDIO_DEVICE_NONE) { |
| 648 | ALOGE("%s: No output device set for voice call", __func__); |
| 649 | goto exit; |
| 650 | } |
| 651 | if (adev->tty_mode != TTY_MODE_OFF) { |
| 652 | if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
| 653 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 654 | switch (adev->tty_mode) { |
| 655 | case TTY_MODE_FULL: |
| 656 | snd_device = SND_DEVICE_IN_VOICE_TTY_FULL_HEADSET_MIC; |
| 657 | break; |
| 658 | case TTY_MODE_VCO: |
| 659 | snd_device = SND_DEVICE_IN_VOICE_TTY_VCO_HANDSET_MIC; |
| 660 | break; |
| 661 | case TTY_MODE_HCO: |
| 662 | snd_device = SND_DEVICE_IN_VOICE_TTY_HCO_HEADSET_MIC; |
| 663 | break; |
| 664 | default: |
| 665 | ALOGE("%s: Invalid TTY mode (%#x)", __func__, adev->tty_mode); |
| 666 | } |
| 667 | goto exit; |
| 668 | } |
| 669 | } |
| 670 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE || |
| 671 | out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
| 672 | if (my_data->fluence_in_voice_call == false) { |
| 673 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 674 | } else { |
| 675 | if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
| 676 | if (is_operator_tmus()) |
| 677 | snd_device = SND_DEVICE_IN_VOICE_DMIC_EF_TMUS; |
| 678 | else |
| 679 | snd_device = SND_DEVICE_IN_VOICE_DMIC_EF; |
| 680 | } else if(my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) |
| 681 | snd_device = SND_DEVICE_IN_VOICE_DMIC_BS; |
| 682 | else |
| 683 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 684 | } |
| 685 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 686 | snd_device = SND_DEVICE_IN_VOICE_HEADSET_MIC; |
| 687 | } else if (out_device & AUDIO_DEVICE_OUT_ALL_SCO) { |
| 688 | snd_device = SND_DEVICE_IN_BT_SCO_MIC ; |
| 689 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
| 690 | if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode && |
| 691 | my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
| 692 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_EF; |
| 693 | } else if (my_data->fluence_in_voice_call && my_data->fluence_in_spkr_mode && |
| 694 | my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) { |
| 695 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_DMIC_BS; |
| 696 | } else { |
| 697 | snd_device = SND_DEVICE_IN_VOICE_SPEAKER_MIC; |
| 698 | } |
| 699 | } |
| 700 | } else if (source == AUDIO_SOURCE_CAMCORDER) { |
| 701 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC || |
| 702 | in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 703 | snd_device = SND_DEVICE_IN_CAMCORDER_MIC; |
| 704 | } |
| 705 | } else if (source == AUDIO_SOURCE_VOICE_RECOGNITION) { |
| 706 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 707 | if (my_data->dualmic_config == DUALMIC_CONFIG_ENDFIRE) { |
| 708 | if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) |
| 709 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF; |
| 710 | else if (my_data->fluence_in_voice_rec) |
| 711 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_EF_FLUENCE; |
| 712 | } else if (my_data->dualmic_config == DUALMIC_CONFIG_BROADSIDE) { |
| 713 | if (channel_mask == AUDIO_CHANNEL_IN_FRONT_BACK) |
| 714 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS; |
| 715 | else if (my_data->fluence_in_voice_rec) |
| 716 | snd_device = SND_DEVICE_IN_VOICE_REC_DMIC_BS_FLUENCE; |
| 717 | } |
| 718 | |
| 719 | if (snd_device == SND_DEVICE_NONE) { |
| 720 | snd_device = SND_DEVICE_IN_VOICE_REC_MIC; |
| 721 | } |
| 722 | } |
| 723 | } else if (source == AUDIO_SOURCE_VOICE_COMMUNICATION) { |
| 724 | if (out_device & AUDIO_DEVICE_OUT_SPEAKER) |
| 725 | in_device = AUDIO_DEVICE_IN_BACK_MIC; |
| 726 | if (adev->active_input) { |
| 727 | if (adev->active_input->enable_aec) { |
| 728 | if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 729 | snd_device = SND_DEVICE_IN_SPEAKER_MIC_AEC; |
| 730 | } else if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 731 | snd_device = SND_DEVICE_IN_HANDSET_MIC_AEC; |
| 732 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 733 | snd_device = SND_DEVICE_IN_HEADSET_MIC_AEC; |
| 734 | } |
| 735 | set_echo_reference(adev->mixer, "SLIM_RX"); |
| 736 | } else |
| 737 | set_echo_reference(adev->mixer, "NONE"); |
| 738 | } |
| 739 | } else if (source == AUDIO_SOURCE_DEFAULT) { |
| 740 | goto exit; |
| 741 | } |
| 742 | |
| 743 | |
| 744 | if (snd_device != SND_DEVICE_NONE) { |
| 745 | goto exit; |
| 746 | } |
| 747 | |
| 748 | if (in_device != AUDIO_DEVICE_NONE && |
| 749 | !(in_device & AUDIO_DEVICE_IN_VOICE_CALL) && |
| 750 | !(in_device & AUDIO_DEVICE_IN_COMMUNICATION)) { |
| 751 | if (in_device & AUDIO_DEVICE_IN_BUILTIN_MIC) { |
| 752 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 753 | } else if (in_device & AUDIO_DEVICE_IN_BACK_MIC) { |
| 754 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 755 | } else if (in_device & AUDIO_DEVICE_IN_WIRED_HEADSET) { |
| 756 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 757 | } else if (in_device & AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) { |
| 758 | snd_device = SND_DEVICE_IN_BT_SCO_MIC ; |
| 759 | } else if (in_device & AUDIO_DEVICE_IN_AUX_DIGITAL) { |
| 760 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
| 761 | } else { |
| 762 | ALOGE("%s: Unknown input device(s) %#x", __func__, in_device); |
| 763 | ALOGW("%s: Using default handset-mic", __func__); |
| 764 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 765 | } |
| 766 | } else { |
| 767 | if (out_device & AUDIO_DEVICE_OUT_EARPIECE) { |
| 768 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 769 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET) { |
| 770 | snd_device = SND_DEVICE_IN_HEADSET_MIC; |
| 771 | } else if (out_device & AUDIO_DEVICE_OUT_SPEAKER) { |
| 772 | snd_device = SND_DEVICE_IN_SPEAKER_MIC; |
| 773 | } else if (out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) { |
| 774 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 775 | } else if (out_device & AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET) { |
| 776 | snd_device = SND_DEVICE_IN_BT_SCO_MIC; |
| 777 | } else if (out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 778 | snd_device = SND_DEVICE_IN_HDMI_MIC; |
| 779 | } else { |
| 780 | ALOGE("%s: Unknown output device(s) %#x", __func__, out_device); |
| 781 | ALOGW("%s: Using default handset-mic", __func__); |
| 782 | snd_device = SND_DEVICE_IN_HANDSET_MIC; |
| 783 | } |
| 784 | } |
| 785 | exit: |
| 786 | ALOGV("%s: exit: in_snd_device(%s)", __func__, device_table[snd_device]); |
| 787 | return snd_device; |
| 788 | } |
| 789 | |
| 790 | int platform_set_hdmi_channels(void *platform, int channel_count) |
| 791 | { |
| 792 | struct platform_data *my_data = (struct platform_data *)platform; |
| 793 | struct audio_device *adev = my_data->adev; |
| 794 | struct mixer_ctl *ctl; |
| 795 | const char *channel_cnt_str = NULL; |
| 796 | const char *mixer_ctl_name = "HDMI_RX Channels"; |
| 797 | switch (channel_count) { |
| 798 | case 8: |
| 799 | channel_cnt_str = "Eight"; break; |
| 800 | case 7: |
| 801 | channel_cnt_str = "Seven"; break; |
| 802 | case 6: |
| 803 | channel_cnt_str = "Six"; break; |
| 804 | case 5: |
| 805 | channel_cnt_str = "Five"; break; |
| 806 | case 4: |
| 807 | channel_cnt_str = "Four"; break; |
| 808 | case 3: |
| 809 | channel_cnt_str = "Three"; break; |
| 810 | default: |
| 811 | channel_cnt_str = "Two"; break; |
| 812 | } |
| 813 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 814 | if (!ctl) { |
| 815 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 816 | __func__, mixer_ctl_name); |
| 817 | return -EINVAL; |
| 818 | } |
| 819 | ALOGV("HDMI channel count: %s", channel_cnt_str); |
| 820 | mixer_ctl_set_enum_by_string(ctl, channel_cnt_str); |
| 821 | return 0; |
| 822 | } |
| 823 | |
| 824 | int platform_edid_get_max_channels(void) |
| 825 | { |
| 826 | FILE *file; |
| 827 | struct audio_block_header header; |
| 828 | char block[MAX_SAD_BLOCKS * SAD_BLOCK_SIZE]; |
| 829 | char *sad = block; |
| 830 | int num_audio_blocks; |
| 831 | int channel_count; |
| 832 | int max_channels = 0; |
| 833 | int i; |
| 834 | |
| 835 | file = fopen(AUDIO_DATA_BLOCK_PATH, "rb"); |
| 836 | if (file == NULL) { |
| 837 | ALOGE("Unable to open '%s'", AUDIO_DATA_BLOCK_PATH); |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | /* Read audio block header */ |
| 842 | fread(&header, 1, sizeof(header), file); |
| 843 | |
| 844 | /* Read SAD blocks, clamping the maximum size for safety */ |
| 845 | if (header.length > (int)sizeof(block)) |
| 846 | header.length = (int)sizeof(block); |
| 847 | fread(&block, header.length, 1, file); |
| 848 | |
| 849 | fclose(file); |
| 850 | |
| 851 | /* Calculate the number of SAD blocks */ |
| 852 | num_audio_blocks = header.length / SAD_BLOCK_SIZE; |
| 853 | |
| 854 | for (i = 0; i < num_audio_blocks; i++) { |
| 855 | /* Only consider LPCM blocks */ |
| 856 | if ((sad[0] >> 3) != EDID_FORMAT_LPCM) |
| 857 | continue; |
| 858 | |
| 859 | channel_count = (sad[0] & 0x7) + 1; |
| 860 | if (channel_count > max_channels) |
| 861 | max_channels = channel_count; |
| 862 | |
| 863 | /* Advance to next block */ |
| 864 | sad += 3; |
| 865 | } |
| 866 | |
| 867 | return max_channels; |
| 868 | } |