Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 1 | /* |
Mingming Yin | ddd610b | 2016-01-20 17:09:32 -0800 | [diff] [blame] | 2 | * Copyright (c) 2014, 2016, The Linux Foundation. All rights reserved. |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright (C) 2014 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | #define LOG_TAG "audio_hw_edid" |
| 21 | /*#define LOG_NDEBUG 0*/ |
| 22 | /*#define LOG_NDDEBUG 0*/ |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <cutils/properties.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <dlfcn.h> |
| 28 | #include <cutils/str_parms.h> |
| 29 | #include <cutils/log.h> |
| 30 | |
| 31 | #include "audio_hw.h" |
| 32 | #include "platform.h" |
| 33 | #include "platform_api.h" |
| 34 | #include "edid.h" |
| 35 | |
| 36 | static const char * edid_format_to_str(unsigned char format) |
| 37 | { |
| 38 | char * format_str = "??"; |
| 39 | |
| 40 | switch (format) { |
| 41 | case LPCM: |
| 42 | format_str = "Format:LPCM"; |
| 43 | break; |
| 44 | case AC3: |
| 45 | format_str = "Format:AC-3"; |
| 46 | break; |
| 47 | case MPEG1: |
| 48 | format_str = "Format:MPEG1 (Layers 1 & 2)"; |
| 49 | break; |
| 50 | case MP3: |
| 51 | format_str = "Format:MP3 (MPEG1 Layer 3)"; |
| 52 | break; |
| 53 | case MPEG2_MULTI_CHANNEL: |
| 54 | format_str = "Format:MPEG2 (multichannel)"; |
| 55 | break; |
| 56 | case AAC: |
| 57 | format_str = "Format:AAC"; |
| 58 | break; |
| 59 | case DTS: |
| 60 | format_str = "Format:DTS"; |
| 61 | break; |
| 62 | case ATRAC: |
| 63 | format_str = "Format:ATRAC"; |
| 64 | break; |
| 65 | case SACD: |
| 66 | format_str = "Format:One-bit audio aka SACD"; |
| 67 | break; |
| 68 | case DOLBY_DIGITAL_PLUS: |
| 69 | format_str = "Format:Dolby Digital +"; |
| 70 | break; |
| 71 | case DTS_HD: |
| 72 | format_str = "Format:DTS-HD"; |
| 73 | break; |
| 74 | case MAT: |
| 75 | format_str = "Format:MAT (MLP)"; |
| 76 | break; |
| 77 | case DST: |
| 78 | format_str = "Format:DST"; |
| 79 | break; |
| 80 | case WMA_PRO: |
| 81 | format_str = "Format:WMA Pro"; |
| 82 | break; |
| 83 | default: |
| 84 | break; |
| 85 | } |
| 86 | return format_str; |
| 87 | } |
| 88 | |
| 89 | static int get_edid_sf(unsigned char byte) |
| 90 | { |
| 91 | int nfreq = 0; |
| 92 | |
| 93 | if (byte & BIT(6)) { |
| 94 | ALOGV("192kHz"); |
| 95 | nfreq = 192000; |
| 96 | } else if (byte & BIT(5)) { |
| 97 | ALOGV("176kHz"); |
| 98 | nfreq = 176000; |
| 99 | } else if (byte & BIT(4)) { |
| 100 | ALOGV("96kHz"); |
| 101 | nfreq = 96000; |
| 102 | } else if (byte & BIT(3)) { |
| 103 | ALOGV("88.2kHz"); |
| 104 | nfreq = 88200; |
| 105 | } else if (byte & BIT(2)) { |
| 106 | ALOGV("48kHz"); |
| 107 | nfreq = 48000; |
| 108 | } else if (byte & BIT(1)) { |
| 109 | ALOGV("44.1kHz"); |
| 110 | nfreq = 44100; |
| 111 | } else if (byte & BIT(0)) { |
| 112 | ALOGV("32kHz"); |
| 113 | nfreq = 32000; |
| 114 | } |
| 115 | return nfreq; |
| 116 | } |
| 117 | |
| 118 | static int get_edid_bps(unsigned char byte, |
| 119 | unsigned char format) |
| 120 | { |
| 121 | int bits_per_sample = 0; |
| 122 | if (format == 1) { |
| 123 | if (byte & BIT(2)) { |
| 124 | ALOGV("24bit"); |
| 125 | bits_per_sample = 24; |
| 126 | } else if (byte & BIT(1)) { |
| 127 | ALOGV("20bit"); |
| 128 | bits_per_sample = 20; |
| 129 | } else if (byte & BIT(0)) { |
| 130 | ALOGV("16bit"); |
| 131 | bits_per_sample = 16; |
| 132 | } |
| 133 | } else { |
| 134 | ALOGV("not lpcm format, return 0"); |
| 135 | return 0; |
| 136 | } |
| 137 | return bits_per_sample; |
| 138 | } |
| 139 | |
| 140 | static void update_channel_map(edid_audio_info* info) |
| 141 | { |
| 142 | /* HDMI Cable follows CEA standard so SAD is received in CEA |
| 143 | * Input source file channel map is fed to ASM in WAV standard(audio.h) |
| 144 | * so upto 7.1 SAD bits are: |
| 145 | * in CEA convention: RLC/RRC,FLC/FRC,RC,RL/RR,FC,LFE,FL/FR |
| 146 | * in WAV convention: BL/BR,FLC/FRC,BC,SL/SR,FC,LFE,FL/FR |
| 147 | * Corresponding ADSP IDs (apr-audio_v2.h): |
| 148 | * PCM_CHANNEL_FL/PCM_CHANNEL_FR, |
| 149 | * PCM_CHANNEL_LFE, |
| 150 | * PCM_CHANNEL_FC, |
| 151 | * PCM_CHANNEL_LS/PCM_CHANNEL_RS, |
| 152 | * PCM_CHANNEL_CS, |
| 153 | * PCM_CHANNEL_FLC/PCM_CHANNEL_FRC |
| 154 | * PCM_CHANNEL_LB/PCM_CHANNEL_RB |
| 155 | */ |
| 156 | if (!info) |
| 157 | return; |
| 158 | memset(info->channel_map, 0, MAX_CHANNELS_SUPPORTED); |
| 159 | if(info->speaker_allocation[0] & BIT(0)) { |
| 160 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 161 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 162 | } |
| 163 | if(info->speaker_allocation[0] & BIT(1)) { |
| 164 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 165 | } |
| 166 | if(info->speaker_allocation[0] & BIT(2)) { |
| 167 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 168 | } |
| 169 | if(info->speaker_allocation[0] & BIT(3)) { |
| 170 | /* |
| 171 | * As per CEA(HDMI Cable) standard Bit 3 is equivalent |
| 172 | * to SideLeft/SideRight of WAV standard |
| 173 | */ |
| 174 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 175 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 176 | } |
| 177 | if(info->speaker_allocation[0] & BIT(4)) { |
| 178 | if(info->speaker_allocation[0] & BIT(3)) { |
| 179 | info->channel_map[6] = PCM_CHANNEL_CS; |
| 180 | info->channel_map[7] = 0; |
| 181 | } else if (info->speaker_allocation[1] & BIT(1)) { |
| 182 | info->channel_map[6] = PCM_CHANNEL_CS; |
| 183 | info->channel_map[7] = PCM_CHANNEL_TS; |
| 184 | } else if (info->speaker_allocation[1] & BIT(2)) { |
| 185 | info->channel_map[6] = PCM_CHANNEL_CS; |
| 186 | info->channel_map[7] = PCM_CHANNEL_CVH; |
| 187 | } else { |
| 188 | info->channel_map[4] = PCM_CHANNEL_CS; |
| 189 | info->channel_map[5] = 0; |
| 190 | } |
| 191 | } |
| 192 | if(info->speaker_allocation[0] & BIT(5)) { |
| 193 | info->channel_map[6] = PCM_CHANNEL_FLC; |
| 194 | info->channel_map[7] = PCM_CHANNEL_FRC; |
| 195 | } |
| 196 | if(info->speaker_allocation[0] & BIT(6)) { |
| 197 | // If RLC/RRC is present, RC is invalid as per specification |
| 198 | info->speaker_allocation[0] &= 0xef; |
| 199 | /* |
| 200 | * As per CEA(HDMI Cable) standard Bit 6 is equivalent |
| 201 | * to BackLeft/BackRight of WAV standard |
| 202 | */ |
| 203 | info->channel_map[6] = PCM_CHANNEL_LB; |
| 204 | info->channel_map[7] = PCM_CHANNEL_RB; |
| 205 | } |
| 206 | // higher channel are not defined by LPASS |
| 207 | //info->nSpeakerAllocation[0] &= 0x3f; |
| 208 | if(info->speaker_allocation[0] & BIT(7)) { |
| 209 | info->channel_map[6] = 0; // PCM_CHANNEL_FLW; but not defined by LPASS |
| 210 | info->channel_map[7] = 0; // PCM_CHANNEL_FRW; but not defined by LPASS |
| 211 | } |
| 212 | if(info->speaker_allocation[1] & BIT(0)) { |
| 213 | info->channel_map[6] = 0; // PCM_CHANNEL_FLH; but not defined by LPASS |
| 214 | info->channel_map[7] = 0; // PCM_CHANNEL_FRH; but not defined by LPASS |
| 215 | } |
| 216 | |
| 217 | ALOGI("%s channel map updated to [%d %d %d %d %d %d %d %d ] [%x %x %x]", __func__ |
| 218 | , info->channel_map[0], info->channel_map[1], info->channel_map[2] |
| 219 | , info->channel_map[3], info->channel_map[4], info->channel_map[5] |
| 220 | , info->channel_map[6], info->channel_map[7] |
| 221 | , info->speaker_allocation[0], info->speaker_allocation[1] |
| 222 | , info->speaker_allocation[2]); |
| 223 | } |
| 224 | |
| 225 | static void dump_speaker_allocation(edid_audio_info* info) |
| 226 | { |
| 227 | if (!info) |
| 228 | return; |
| 229 | |
| 230 | if (info->speaker_allocation[0] & BIT(7)) |
| 231 | ALOGV("FLW/FRW"); |
| 232 | if (info->speaker_allocation[0] & BIT(6)) |
| 233 | ALOGV("RLC/RRC"); |
| 234 | if (info->speaker_allocation[0] & BIT(5)) |
| 235 | ALOGV("FLC/FRC"); |
| 236 | if (info->speaker_allocation[0] & BIT(4)) |
| 237 | ALOGV("RC"); |
| 238 | if (info->speaker_allocation[0] & BIT(3)) |
| 239 | ALOGV("RL/RR"); |
| 240 | if (info->speaker_allocation[0] & BIT(2)) |
| 241 | ALOGV("FC"); |
| 242 | if (info->speaker_allocation[0] & BIT(1)) |
| 243 | ALOGV("LFE"); |
| 244 | if (info->speaker_allocation[0] & BIT(0)) |
| 245 | ALOGV("FL/FR"); |
| 246 | if (info->speaker_allocation[1] & BIT(2)) |
| 247 | ALOGV("FCH"); |
| 248 | if (info->speaker_allocation[1] & BIT(1)) |
| 249 | ALOGV("TC"); |
| 250 | if (info->speaker_allocation[1] & BIT(0)) |
| 251 | ALOGV("FLH/FRH"); |
| 252 | } |
| 253 | |
| 254 | static void update_channel_allocation(edid_audio_info* info) |
| 255 | { |
| 256 | int16_t ca; |
| 257 | int16_t spkr_alloc; |
| 258 | |
| 259 | if (!info) |
| 260 | return; |
| 261 | |
| 262 | /* Most common 5.1 SAD is 0xF, ca 0x0b |
| 263 | * and 7.1 SAD is 0x4F, ca 0x13 */ |
| 264 | spkr_alloc = ((info->speaker_allocation[1]) << 8) | |
| 265 | (info->speaker_allocation[0]); |
| 266 | ALOGV("info->nSpeakerAllocation %x %x\n", info->speaker_allocation[0], |
| 267 | info->speaker_allocation[1]); |
| 268 | ALOGV("spkr_alloc: %x", spkr_alloc); |
| 269 | |
| 270 | /* The below switch case calculates channel allocation values |
| 271 | as defined in CEA-861 section 6.6.2 */ |
| 272 | switch (spkr_alloc) { |
| 273 | case BIT(0): ca = 0x00; break; |
| 274 | case BIT(0)|BIT(1): ca = 0x01; break; |
| 275 | case BIT(0)|BIT(2): ca = 0x02; break; |
| 276 | case BIT(0)|BIT(1)|BIT(2): ca = 0x03; break; |
| 277 | case BIT(0)|BIT(4): ca = 0x04; break; |
| 278 | case BIT(0)|BIT(1)|BIT(4): ca = 0x05; break; |
| 279 | case BIT(0)|BIT(2)|BIT(4): ca = 0x06; break; |
| 280 | case BIT(0)|BIT(1)|BIT(2)|BIT(4): ca = 0x07; break; |
| 281 | case BIT(0)|BIT(3): ca = 0x08; break; |
| 282 | case BIT(0)|BIT(1)|BIT(3): ca = 0x09; break; |
| 283 | case BIT(0)|BIT(2)|BIT(3): ca = 0x0A; break; |
| 284 | case BIT(0)|BIT(1)|BIT(2)|BIT(3): ca = 0x0B; break; |
| 285 | case BIT(0)|BIT(3)|BIT(4): ca = 0x0C; break; |
| 286 | case BIT(0)|BIT(1)|BIT(3)|BIT(4): ca = 0x0D; break; |
| 287 | case BIT(0)|BIT(2)|BIT(3)|BIT(4): ca = 0x0E; break; |
| 288 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4): ca = 0x0F; break; |
| 289 | case BIT(0)|BIT(3)|BIT(6): ca = 0x10; break; |
| 290 | case BIT(0)|BIT(1)|BIT(3)|BIT(6): ca = 0x11; break; |
| 291 | case BIT(0)|BIT(2)|BIT(3)|BIT(6): ca = 0x12; break; |
| 292 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(6): ca = 0x13; break; |
| 293 | case BIT(0)|BIT(5): ca = 0x14; break; |
| 294 | case BIT(0)|BIT(1)|BIT(5): ca = 0x15; break; |
| 295 | case BIT(0)|BIT(2)|BIT(5): ca = 0x16; break; |
| 296 | case BIT(0)|BIT(1)|BIT(2)|BIT(5): ca = 0x17; break; |
| 297 | case BIT(0)|BIT(4)|BIT(5): ca = 0x18; break; |
| 298 | case BIT(0)|BIT(1)|BIT(4)|BIT(5): ca = 0x19; break; |
| 299 | case BIT(0)|BIT(2)|BIT(4)|BIT(5): ca = 0x1A; break; |
| 300 | case BIT(0)|BIT(1)|BIT(2)|BIT(4)|BIT(5): ca = 0x1B; break; |
| 301 | case BIT(0)|BIT(3)|BIT(5): ca = 0x1C; break; |
| 302 | case BIT(0)|BIT(1)|BIT(3)|BIT(5): ca = 0x1D; break; |
| 303 | case BIT(0)|BIT(2)|BIT(3)|BIT(5): ca = 0x1E; break; |
| 304 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(5): ca = 0x1F; break; |
| 305 | case BIT(0)|BIT(2)|BIT(3)|BIT(10): ca = 0x20; break; |
| 306 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(10): ca = 0x21; break; |
| 307 | case BIT(0)|BIT(2)|BIT(3)|BIT(9): ca = 0x22; break; |
| 308 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(9): ca = 0x23; break; |
| 309 | case BIT(0)|BIT(3)|BIT(8): ca = 0x24; break; |
| 310 | case BIT(0)|BIT(1)|BIT(3)|BIT(8): ca = 0x25; break; |
| 311 | case BIT(0)|BIT(3)|BIT(7): ca = 0x26; break; |
| 312 | case BIT(0)|BIT(1)|BIT(3)|BIT(7): ca = 0x27; break; |
| 313 | case BIT(0)|BIT(2)|BIT(3)|BIT(4)|BIT(9): ca = 0x28; break; |
| 314 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4)|BIT(9): ca = 0x29; break; |
| 315 | case BIT(0)|BIT(2)|BIT(3)|BIT(4)|BIT(10): ca = 0x2A; break; |
| 316 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4)|BIT(10): ca = 0x2B; break; |
| 317 | case BIT(0)|BIT(2)|BIT(3)|BIT(9)|BIT(10): ca = 0x2C; break; |
| 318 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(9)|BIT(10): ca = 0x2D; break; |
| 319 | case BIT(0)|BIT(2)|BIT(3)|BIT(8): ca = 0x2E; break; |
| 320 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(8): ca = 0x2F; break; |
| 321 | case BIT(0)|BIT(2)|BIT(3)|BIT(7): ca = 0x30; break; |
| 322 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(7): ca = 0x31; break; |
| 323 | default: ca = 0x0; break; |
| 324 | } |
| 325 | ALOGD("%s channel allocation: %x", __func__, ca); |
| 326 | info->channel_allocation = ca; |
| 327 | } |
| 328 | |
| 329 | static void update_channel_map_lpass(edid_audio_info* info) |
| 330 | { |
| 331 | if (!info) |
| 332 | return; |
| 333 | if (info->channel_allocation < 0 || info->channel_allocation > 0x1f) { |
| 334 | ALOGE("Channel allocation out of supported range"); |
| 335 | return; |
| 336 | } |
| 337 | ALOGV("channel_allocation 0x%x", info->channel_allocation); |
| 338 | memset(info->channel_map, 0, MAX_CHANNELS_SUPPORTED); |
| 339 | switch(info->channel_allocation) { |
| 340 | case 0x0: |
| 341 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 342 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 343 | break; |
| 344 | case 0x1: |
| 345 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 346 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 347 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 348 | break; |
| 349 | case 0x2: |
| 350 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 351 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 352 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 353 | break; |
| 354 | case 0x3: |
| 355 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 356 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 357 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 358 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 359 | break; |
| 360 | case 0x4: |
| 361 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 362 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 363 | info->channel_map[2] = PCM_CHANNEL_CS; |
| 364 | break; |
| 365 | case 0x5: |
| 366 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 367 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 368 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 369 | info->channel_map[3] = PCM_CHANNEL_CS; |
| 370 | break; |
| 371 | case 0x6: |
| 372 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 373 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 374 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 375 | info->channel_map[3] = PCM_CHANNEL_CS; |
| 376 | break; |
| 377 | case 0x7: |
| 378 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 379 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 380 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 381 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 382 | info->channel_map[4] = PCM_CHANNEL_CS; |
| 383 | break; |
| 384 | case 0x8: |
| 385 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 386 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 387 | info->channel_map[2] = PCM_CHANNEL_LS; |
| 388 | info->channel_map[3] = PCM_CHANNEL_RS; |
| 389 | break; |
| 390 | case 0x9: |
| 391 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 392 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 393 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 394 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 395 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 396 | break; |
| 397 | case 0xa: |
| 398 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 399 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 400 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 401 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 402 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 403 | break; |
| 404 | case 0xb: |
| 405 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 406 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 407 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 408 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 409 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 410 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 411 | break; |
| 412 | case 0xc: |
| 413 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 414 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 415 | info->channel_map[2] = PCM_CHANNEL_LS; |
| 416 | info->channel_map[3] = PCM_CHANNEL_RS; |
| 417 | info->channel_map[4] = PCM_CHANNEL_CS; |
| 418 | break; |
| 419 | case 0xd: |
| 420 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 421 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 422 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 423 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 424 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 425 | info->channel_map[5] = PCM_CHANNEL_CS; |
| 426 | break; |
| 427 | case 0xe: |
| 428 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 429 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 430 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 431 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 432 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 433 | info->channel_map[5] = PCM_CHANNEL_CS; |
| 434 | break; |
| 435 | case 0xf: |
| 436 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 437 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 438 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 439 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 440 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 441 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 442 | info->channel_map[6] = PCM_CHANNEL_CS; |
| 443 | break; |
| 444 | case 0x10: |
| 445 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 446 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 447 | info->channel_map[2] = PCM_CHANNEL_LS; |
| 448 | info->channel_map[3] = PCM_CHANNEL_RS; |
| 449 | info->channel_map[4] = PCM_CHANNEL_LB; |
| 450 | info->channel_map[5] = PCM_CHANNEL_RB; |
| 451 | break; |
| 452 | case 0x11: |
| 453 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 454 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 455 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 456 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 457 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 458 | info->channel_map[5] = PCM_CHANNEL_LB; |
| 459 | info->channel_map[6] = PCM_CHANNEL_RB; |
| 460 | break; |
| 461 | case 0x12: |
| 462 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 463 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 464 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 465 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 466 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 467 | info->channel_map[5] = PCM_CHANNEL_LB; |
| 468 | info->channel_map[6] = PCM_CHANNEL_RB; |
| 469 | break; |
| 470 | case 0x13: |
| 471 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 472 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 473 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 474 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 475 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 476 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 477 | info->channel_map[6] = PCM_CHANNEL_LB; |
| 478 | info->channel_map[7] = PCM_CHANNEL_RB; |
| 479 | break; |
| 480 | case 0x14: |
| 481 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 482 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 483 | info->channel_map[2] = PCM_CHANNEL_FLC; |
| 484 | info->channel_map[3] = PCM_CHANNEL_FRC; |
| 485 | break; |
| 486 | case 0x15: |
| 487 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 488 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 489 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 490 | info->channel_map[3] = PCM_CHANNEL_FLC; |
| 491 | info->channel_map[4] = PCM_CHANNEL_FRC; |
| 492 | break; |
| 493 | case 0x16: |
| 494 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 495 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 496 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 497 | info->channel_map[3] = PCM_CHANNEL_FLC; |
| 498 | info->channel_map[4] = PCM_CHANNEL_FRC; |
| 499 | break; |
| 500 | case 0x17: |
| 501 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 502 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 503 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 504 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 505 | info->channel_map[4] = PCM_CHANNEL_FLC; |
| 506 | info->channel_map[5] = PCM_CHANNEL_FRC; |
| 507 | break; |
| 508 | case 0x18: |
| 509 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 510 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 511 | info->channel_map[2] = PCM_CHANNEL_CS; |
| 512 | info->channel_map[3] = PCM_CHANNEL_FLC; |
| 513 | info->channel_map[4] = PCM_CHANNEL_FRC; |
| 514 | break; |
| 515 | case 0x19: |
| 516 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 517 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 518 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 519 | info->channel_map[3] = PCM_CHANNEL_CS; |
| 520 | info->channel_map[4] = PCM_CHANNEL_FLC; |
| 521 | info->channel_map[5] = PCM_CHANNEL_FRC; |
| 522 | break; |
| 523 | case 0x1a: |
| 524 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 525 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 526 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 527 | info->channel_map[3] = PCM_CHANNEL_CS; |
| 528 | info->channel_map[4] = PCM_CHANNEL_FLC; |
| 529 | info->channel_map[5] = PCM_CHANNEL_FRC; |
| 530 | break; |
| 531 | case 0x1b: |
| 532 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 533 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 534 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 535 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 536 | info->channel_map[4] = PCM_CHANNEL_CS; |
| 537 | info->channel_map[5] = PCM_CHANNEL_FLC; |
| 538 | info->channel_map[6] = PCM_CHANNEL_FRC; |
| 539 | break; |
| 540 | case 0x1c: |
| 541 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 542 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 543 | info->channel_map[2] = PCM_CHANNEL_LS; |
| 544 | info->channel_map[3] = PCM_CHANNEL_RS; |
| 545 | info->channel_map[4] = PCM_CHANNEL_FLC; |
| 546 | info->channel_map[5] = PCM_CHANNEL_FRC; |
| 547 | break; |
| 548 | case 0x1d: |
| 549 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 550 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 551 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 552 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 553 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 554 | info->channel_map[5] = PCM_CHANNEL_FLC; |
| 555 | info->channel_map[6] = PCM_CHANNEL_FRC; |
| 556 | break; |
| 557 | case 0x1e: |
| 558 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 559 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 560 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 561 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 562 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 563 | info->channel_map[5] = PCM_CHANNEL_FLC; |
| 564 | info->channel_map[6] = PCM_CHANNEL_FRC; |
| 565 | break; |
| 566 | case 0x1f: |
| 567 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 568 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 569 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 570 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 571 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 572 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 573 | info->channel_map[6] = PCM_CHANNEL_FLC; |
| 574 | info->channel_map[7] = PCM_CHANNEL_FRC; |
| 575 | break; |
| 576 | default: |
| 577 | break; |
| 578 | } |
| 579 | ALOGD("%s channel map updated to [%d %d %d %d %d %d %d %d ]", __func__ |
| 580 | , info->channel_map[0], info->channel_map[1], info->channel_map[2] |
| 581 | , info->channel_map[3], info->channel_map[4], info->channel_map[5] |
| 582 | , info->channel_map[6], info->channel_map[7]); |
| 583 | } |
| 584 | |
| 585 | static void dump_edid_data(edid_audio_info *info) |
| 586 | { |
| 587 | |
| 588 | int i; |
| 589 | for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) { |
| 590 | ALOGV("%s:FormatId:%d rate:%d bps:%d channels:%d", __func__, |
| 591 | info->audio_blocks_array[i].format_id, |
| 592 | info->audio_blocks_array[i].sampling_freq, |
| 593 | info->audio_blocks_array[i].bits_per_sample, |
| 594 | info->audio_blocks_array[i].channels); |
| 595 | } |
| 596 | ALOGV("%s:no of audio blocks:%d", __func__, info->audio_blocks); |
| 597 | ALOGV("%s:speaker allocation:[%x %x %x]", __func__, |
| 598 | info->speaker_allocation[0], info->speaker_allocation[1], |
| 599 | info->speaker_allocation[2]); |
| 600 | ALOGV("%s:channel map:[%x %x %x %x %x %x %x %x]", __func__, |
| 601 | info->channel_map[0], info->channel_map[1], |
| 602 | info->channel_map[2], info->channel_map[3], |
| 603 | info->channel_map[4], info->channel_map[5], |
| 604 | info->channel_map[6], info->channel_map[7]); |
| 605 | ALOGV("%s:channel allocation:%d", __func__, info->channel_allocation); |
| 606 | ALOGV("%s:[%d %d %d %d %d %d %d %d ]", __func__, |
| 607 | info->channel_map[0], info->channel_map[1], |
| 608 | info->channel_map[2], info->channel_map[3], |
| 609 | info->channel_map[4], info->channel_map[5], |
| 610 | info->channel_map[6], info->channel_map[7]); |
| 611 | } |
| 612 | |
| 613 | bool edid_get_sink_caps(edid_audio_info* info, char *edid_data) |
| 614 | { |
| 615 | unsigned char channels[MAX_EDID_BLOCKS]; |
| 616 | unsigned char formats[MAX_EDID_BLOCKS]; |
| 617 | unsigned char frequency[MAX_EDID_BLOCKS]; |
| 618 | unsigned char bitrate[MAX_EDID_BLOCKS]; |
| 619 | int i = 0; |
| 620 | int length, count_desc; |
| 621 | |
| 622 | if (!info || !edid_data) { |
| 623 | ALOGE("No valid EDID"); |
| 624 | return false; |
| 625 | } |
| 626 | |
| 627 | length = (int) *edid_data++; |
| 628 | ALOGV("Total length is %d",length); |
| 629 | |
| 630 | count_desc = length/MIN_AUDIO_DESC_LENGTH; |
| 631 | |
| 632 | if (!count_desc) { |
| 633 | ALOGE("insufficient descriptors"); |
| 634 | return false; |
| 635 | } |
| 636 | |
| 637 | memset(info, 0, sizeof(edid_audio_info)); |
| 638 | |
| 639 | info->audio_blocks = count_desc-1; |
| 640 | if (info->audio_blocks > MAX_EDID_BLOCKS) { |
| 641 | info->audio_blocks = MAX_EDID_BLOCKS; |
| 642 | } |
| 643 | |
| 644 | ALOGV("Total # of audio descriptors %d",count_desc); |
| 645 | |
| 646 | for (i=0; i<info->audio_blocks; i++) { |
| 647 | // last block for speaker allocation; |
| 648 | channels [i] = (*edid_data & 0x7) + 1; |
| 649 | formats [i] = (*edid_data++) >> 3; |
| 650 | frequency[i] = *edid_data++; |
| 651 | bitrate [i] = *edid_data++; |
| 652 | } |
| 653 | info->speaker_allocation[0] = *edid_data++; |
| 654 | info->speaker_allocation[1] = *edid_data++; |
| 655 | info->speaker_allocation[2] = *edid_data++; |
| 656 | |
| 657 | update_channel_map(info); |
| 658 | update_channel_allocation(info); |
| 659 | update_channel_map_lpass(info); |
| 660 | |
| 661 | for (i=0; i<info->audio_blocks; i++) { |
| 662 | ALOGV("AUDIO DESC BLOCK # %d\n",i); |
| 663 | |
| 664 | info->audio_blocks_array[i].channels = channels[i]; |
Ashish Jain | 957440f | 2015-08-28 10:47:13 +0530 | [diff] [blame] | 665 | ALOGD("info->audio_blocks_array[i].channels %d\n", |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 666 | info->audio_blocks_array[i].channels); |
| 667 | |
| 668 | ALOGV("Format Byte %d\n", formats[i]); |
| 669 | info->audio_blocks_array[i].format_id = (edid_audio_format_id)formats[i]; |
Ashish Jain | 957440f | 2015-08-28 10:47:13 +0530 | [diff] [blame] | 670 | ALOGD("info->audio_blocks_array[i].format_id %s", |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 671 | edid_format_to_str(formats[i])); |
| 672 | |
| 673 | ALOGV("Frequency Byte %d\n", frequency[i]); |
| 674 | info->audio_blocks_array[i].sampling_freq = get_edid_sf(frequency[i]); |
| 675 | ALOGV("info->audio_blocks_array[i].sampling_freq %d", |
| 676 | info->audio_blocks_array[i].sampling_freq); |
| 677 | |
| 678 | ALOGV("BitsPerSample Byte %d\n", bitrate[i]); |
| 679 | info->audio_blocks_array[i].bits_per_sample = |
| 680 | get_edid_bps(bitrate[i],formats[i]); |
| 681 | ALOGV("info->audio_blocks_array[i].bits_per_sample %d", |
| 682 | info->audio_blocks_array[i].bits_per_sample); |
| 683 | } |
| 684 | dump_speaker_allocation(info); |
| 685 | dump_edid_data(info); |
| 686 | return true; |
| 687 | } |
Mingming Yin | ddd610b | 2016-01-20 17:09:32 -0800 | [diff] [blame] | 688 | |
| 689 | bool edid_is_supported_sr(edid_audio_info* info, int sr) |
| 690 | { |
| 691 | int i = 0; |
| 692 | if (info != NULL && sr != 0) { |
| 693 | for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) { |
| 694 | if (info->audio_blocks_array[i].sampling_freq == sr) { |
| 695 | ALOGV("%s: returns true for sample rate [%d]", |
| 696 | __func__, sr); |
| 697 | return true; |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | ALOGV("%s: returns false for sample rate [%d]", |
| 702 | __func__, sr); |
| 703 | return false; |
| 704 | } |
| 705 | |
| 706 | bool edid_is_supported_bps(edid_audio_info* info, int bps) |
| 707 | { |
| 708 | int i = 0; |
| 709 | |
| 710 | if (bps == 16) { |
| 711 | //16 bit bps is always supported |
| 712 | //some oem may not update 16bit support in their edid info |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | if (info != NULL && bps != 0) { |
| 717 | for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) { |
| 718 | if (info->audio_blocks_array[i].bits_per_sample == bps) { |
| 719 | ALOGV("%s: returns true for bit width [%d]", |
| 720 | __func__, bps); |
| 721 | return true; |
| 722 | } |
| 723 | } |
| 724 | } |
| 725 | ALOGV("%s: returns false for bit width [%d]", |
| 726 | __func__, bps); |
| 727 | return false; |
| 728 | } |