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 | |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 89 | static bool is_supported_sr(unsigned char sr_byte, int sampling_rate ) |
| 90 | { |
| 91 | int result = 0; |
| 92 | |
| 93 | ALOGV("%s: sr_byte: %d, sampling_freq: %d",__func__, sr_byte, sampling_rate); |
| 94 | switch (sampling_rate) { |
| 95 | case 192000: |
| 96 | result = (sr_byte & BIT(6)); |
| 97 | break; |
| 98 | case 176400: |
| 99 | result = (sr_byte & BIT(5)); |
| 100 | break; |
| 101 | case 96000: |
| 102 | result = (sr_byte & BIT(4)); |
| 103 | break; |
| 104 | case 88200: |
| 105 | result = (sr_byte & BIT(3)); |
| 106 | break; |
| 107 | case 48000: |
| 108 | result = (sr_byte & BIT(2)); |
| 109 | break; |
| 110 | case 44100: |
| 111 | result = (sr_byte & BIT(1)); |
| 112 | break; |
| 113 | case 32000: |
| 114 | result = (sr_byte & BIT(0)); |
| 115 | break; |
| 116 | default: |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | if (result) |
| 121 | return true; |
| 122 | |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | static unsigned char get_edid_bps_byte(unsigned char byte, |
| 127 | unsigned char format) |
| 128 | { |
| 129 | if (format == 0) { |
| 130 | ALOGV("%s: not lpcm format, return 0",__func__); |
| 131 | return 0; |
| 132 | } |
| 133 | return byte; |
| 134 | } |
| 135 | |
| 136 | static bool is_supported_bps(unsigned char bps_byte, int bps) |
| 137 | { |
| 138 | int result = 0; |
| 139 | |
| 140 | switch (bps) { |
| 141 | case 24: |
| 142 | ALOGV("24bit"); |
| 143 | result = (bps_byte & BIT(2)); |
| 144 | break; |
| 145 | case 20: |
| 146 | ALOGV("20bit"); |
| 147 | result = (bps_byte & BIT(1)); |
| 148 | break; |
| 149 | case 16: |
| 150 | ALOGV("16bit"); |
| 151 | result = (bps_byte & BIT(0)); |
| 152 | break; |
| 153 | default: |
| 154 | break; |
| 155 | } |
| 156 | |
| 157 | if (result) |
| 158 | return true; |
| 159 | |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | static int get_highest_edid_sf(unsigned char byte) |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 164 | { |
| 165 | int nfreq = 0; |
| 166 | |
| 167 | if (byte & BIT(6)) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 168 | ALOGV("Highest: 192kHz"); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 169 | nfreq = 192000; |
| 170 | } else if (byte & BIT(5)) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 171 | ALOGV("Highest: 176kHz"); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 172 | nfreq = 176000; |
| 173 | } else if (byte & BIT(4)) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 174 | ALOGV("Highest: 96kHz"); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 175 | nfreq = 96000; |
| 176 | } else if (byte & BIT(3)) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 177 | ALOGV("Highest: 88.2kHz"); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 178 | nfreq = 88200; |
| 179 | } else if (byte & BIT(2)) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 180 | ALOGV("Highest: 48kHz"); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 181 | nfreq = 48000; |
| 182 | } else if (byte & BIT(1)) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 183 | ALOGV("Highest: 44.1kHz"); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 184 | nfreq = 44100; |
| 185 | } else if (byte & BIT(0)) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 186 | ALOGV("Highest: 32kHz"); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 187 | nfreq = 32000; |
| 188 | } |
| 189 | return nfreq; |
| 190 | } |
| 191 | |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 192 | static void update_channel_map(edid_audio_info* info) |
| 193 | { |
| 194 | /* HDMI Cable follows CEA standard so SAD is received in CEA |
| 195 | * Input source file channel map is fed to ASM in WAV standard(audio.h) |
| 196 | * so upto 7.1 SAD bits are: |
| 197 | * in CEA convention: RLC/RRC,FLC/FRC,RC,RL/RR,FC,LFE,FL/FR |
| 198 | * in WAV convention: BL/BR,FLC/FRC,BC,SL/SR,FC,LFE,FL/FR |
| 199 | * Corresponding ADSP IDs (apr-audio_v2.h): |
| 200 | * PCM_CHANNEL_FL/PCM_CHANNEL_FR, |
| 201 | * PCM_CHANNEL_LFE, |
| 202 | * PCM_CHANNEL_FC, |
| 203 | * PCM_CHANNEL_LS/PCM_CHANNEL_RS, |
| 204 | * PCM_CHANNEL_CS, |
| 205 | * PCM_CHANNEL_FLC/PCM_CHANNEL_FRC |
| 206 | * PCM_CHANNEL_LB/PCM_CHANNEL_RB |
| 207 | */ |
| 208 | if (!info) |
| 209 | return; |
| 210 | memset(info->channel_map, 0, MAX_CHANNELS_SUPPORTED); |
| 211 | if(info->speaker_allocation[0] & BIT(0)) { |
| 212 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 213 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 214 | } |
| 215 | if(info->speaker_allocation[0] & BIT(1)) { |
| 216 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 217 | } |
| 218 | if(info->speaker_allocation[0] & BIT(2)) { |
| 219 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 220 | } |
| 221 | if(info->speaker_allocation[0] & BIT(3)) { |
| 222 | /* |
| 223 | * As per CEA(HDMI Cable) standard Bit 3 is equivalent |
| 224 | * to SideLeft/SideRight of WAV standard |
| 225 | */ |
| 226 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 227 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 228 | } |
| 229 | if(info->speaker_allocation[0] & BIT(4)) { |
| 230 | if(info->speaker_allocation[0] & BIT(3)) { |
| 231 | info->channel_map[6] = PCM_CHANNEL_CS; |
| 232 | info->channel_map[7] = 0; |
| 233 | } else if (info->speaker_allocation[1] & BIT(1)) { |
| 234 | info->channel_map[6] = PCM_CHANNEL_CS; |
| 235 | info->channel_map[7] = PCM_CHANNEL_TS; |
| 236 | } else if (info->speaker_allocation[1] & BIT(2)) { |
| 237 | info->channel_map[6] = PCM_CHANNEL_CS; |
| 238 | info->channel_map[7] = PCM_CHANNEL_CVH; |
| 239 | } else { |
| 240 | info->channel_map[4] = PCM_CHANNEL_CS; |
| 241 | info->channel_map[5] = 0; |
| 242 | } |
| 243 | } |
| 244 | if(info->speaker_allocation[0] & BIT(5)) { |
| 245 | info->channel_map[6] = PCM_CHANNEL_FLC; |
| 246 | info->channel_map[7] = PCM_CHANNEL_FRC; |
| 247 | } |
| 248 | if(info->speaker_allocation[0] & BIT(6)) { |
| 249 | // If RLC/RRC is present, RC is invalid as per specification |
| 250 | info->speaker_allocation[0] &= 0xef; |
| 251 | /* |
| 252 | * As per CEA(HDMI Cable) standard Bit 6 is equivalent |
| 253 | * to BackLeft/BackRight of WAV standard |
| 254 | */ |
| 255 | info->channel_map[6] = PCM_CHANNEL_LB; |
| 256 | info->channel_map[7] = PCM_CHANNEL_RB; |
| 257 | } |
| 258 | // higher channel are not defined by LPASS |
| 259 | //info->nSpeakerAllocation[0] &= 0x3f; |
| 260 | if(info->speaker_allocation[0] & BIT(7)) { |
| 261 | info->channel_map[6] = 0; // PCM_CHANNEL_FLW; but not defined by LPASS |
| 262 | info->channel_map[7] = 0; // PCM_CHANNEL_FRW; but not defined by LPASS |
| 263 | } |
| 264 | if(info->speaker_allocation[1] & BIT(0)) { |
| 265 | info->channel_map[6] = 0; // PCM_CHANNEL_FLH; but not defined by LPASS |
| 266 | info->channel_map[7] = 0; // PCM_CHANNEL_FRH; but not defined by LPASS |
| 267 | } |
| 268 | |
| 269 | ALOGI("%s channel map updated to [%d %d %d %d %d %d %d %d ] [%x %x %x]", __func__ |
| 270 | , info->channel_map[0], info->channel_map[1], info->channel_map[2] |
| 271 | , info->channel_map[3], info->channel_map[4], info->channel_map[5] |
| 272 | , info->channel_map[6], info->channel_map[7] |
| 273 | , info->speaker_allocation[0], info->speaker_allocation[1] |
| 274 | , info->speaker_allocation[2]); |
| 275 | } |
| 276 | |
| 277 | static void dump_speaker_allocation(edid_audio_info* info) |
| 278 | { |
| 279 | if (!info) |
| 280 | return; |
| 281 | |
| 282 | if (info->speaker_allocation[0] & BIT(7)) |
| 283 | ALOGV("FLW/FRW"); |
| 284 | if (info->speaker_allocation[0] & BIT(6)) |
| 285 | ALOGV("RLC/RRC"); |
| 286 | if (info->speaker_allocation[0] & BIT(5)) |
| 287 | ALOGV("FLC/FRC"); |
| 288 | if (info->speaker_allocation[0] & BIT(4)) |
| 289 | ALOGV("RC"); |
| 290 | if (info->speaker_allocation[0] & BIT(3)) |
| 291 | ALOGV("RL/RR"); |
| 292 | if (info->speaker_allocation[0] & BIT(2)) |
| 293 | ALOGV("FC"); |
| 294 | if (info->speaker_allocation[0] & BIT(1)) |
| 295 | ALOGV("LFE"); |
| 296 | if (info->speaker_allocation[0] & BIT(0)) |
| 297 | ALOGV("FL/FR"); |
| 298 | if (info->speaker_allocation[1] & BIT(2)) |
| 299 | ALOGV("FCH"); |
| 300 | if (info->speaker_allocation[1] & BIT(1)) |
| 301 | ALOGV("TC"); |
| 302 | if (info->speaker_allocation[1] & BIT(0)) |
| 303 | ALOGV("FLH/FRH"); |
| 304 | } |
| 305 | |
| 306 | static void update_channel_allocation(edid_audio_info* info) |
| 307 | { |
| 308 | int16_t ca; |
| 309 | int16_t spkr_alloc; |
| 310 | |
| 311 | if (!info) |
| 312 | return; |
| 313 | |
| 314 | /* Most common 5.1 SAD is 0xF, ca 0x0b |
| 315 | * and 7.1 SAD is 0x4F, ca 0x13 */ |
| 316 | spkr_alloc = ((info->speaker_allocation[1]) << 8) | |
| 317 | (info->speaker_allocation[0]); |
| 318 | ALOGV("info->nSpeakerAllocation %x %x\n", info->speaker_allocation[0], |
| 319 | info->speaker_allocation[1]); |
| 320 | ALOGV("spkr_alloc: %x", spkr_alloc); |
| 321 | |
| 322 | /* The below switch case calculates channel allocation values |
| 323 | as defined in CEA-861 section 6.6.2 */ |
| 324 | switch (spkr_alloc) { |
| 325 | case BIT(0): ca = 0x00; break; |
| 326 | case BIT(0)|BIT(1): ca = 0x01; break; |
| 327 | case BIT(0)|BIT(2): ca = 0x02; break; |
| 328 | case BIT(0)|BIT(1)|BIT(2): ca = 0x03; break; |
| 329 | case BIT(0)|BIT(4): ca = 0x04; break; |
| 330 | case BIT(0)|BIT(1)|BIT(4): ca = 0x05; break; |
| 331 | case BIT(0)|BIT(2)|BIT(4): ca = 0x06; break; |
| 332 | case BIT(0)|BIT(1)|BIT(2)|BIT(4): ca = 0x07; break; |
| 333 | case BIT(0)|BIT(3): ca = 0x08; break; |
| 334 | case BIT(0)|BIT(1)|BIT(3): ca = 0x09; break; |
| 335 | case BIT(0)|BIT(2)|BIT(3): ca = 0x0A; break; |
| 336 | case BIT(0)|BIT(1)|BIT(2)|BIT(3): ca = 0x0B; break; |
| 337 | case BIT(0)|BIT(3)|BIT(4): ca = 0x0C; break; |
| 338 | case BIT(0)|BIT(1)|BIT(3)|BIT(4): ca = 0x0D; break; |
| 339 | case BIT(0)|BIT(2)|BIT(3)|BIT(4): ca = 0x0E; break; |
| 340 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4): ca = 0x0F; break; |
| 341 | case BIT(0)|BIT(3)|BIT(6): ca = 0x10; break; |
| 342 | case BIT(0)|BIT(1)|BIT(3)|BIT(6): ca = 0x11; break; |
| 343 | case BIT(0)|BIT(2)|BIT(3)|BIT(6): ca = 0x12; break; |
| 344 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(6): ca = 0x13; break; |
| 345 | case BIT(0)|BIT(5): ca = 0x14; break; |
| 346 | case BIT(0)|BIT(1)|BIT(5): ca = 0x15; break; |
| 347 | case BIT(0)|BIT(2)|BIT(5): ca = 0x16; break; |
| 348 | case BIT(0)|BIT(1)|BIT(2)|BIT(5): ca = 0x17; break; |
| 349 | case BIT(0)|BIT(4)|BIT(5): ca = 0x18; break; |
| 350 | case BIT(0)|BIT(1)|BIT(4)|BIT(5): ca = 0x19; break; |
| 351 | case BIT(0)|BIT(2)|BIT(4)|BIT(5): ca = 0x1A; break; |
| 352 | case BIT(0)|BIT(1)|BIT(2)|BIT(4)|BIT(5): ca = 0x1B; break; |
| 353 | case BIT(0)|BIT(3)|BIT(5): ca = 0x1C; break; |
| 354 | case BIT(0)|BIT(1)|BIT(3)|BIT(5): ca = 0x1D; break; |
| 355 | case BIT(0)|BIT(2)|BIT(3)|BIT(5): ca = 0x1E; break; |
| 356 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(5): ca = 0x1F; break; |
| 357 | case BIT(0)|BIT(2)|BIT(3)|BIT(10): ca = 0x20; break; |
| 358 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(10): ca = 0x21; break; |
| 359 | case BIT(0)|BIT(2)|BIT(3)|BIT(9): ca = 0x22; break; |
| 360 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(9): ca = 0x23; break; |
| 361 | case BIT(0)|BIT(3)|BIT(8): ca = 0x24; break; |
| 362 | case BIT(0)|BIT(1)|BIT(3)|BIT(8): ca = 0x25; break; |
| 363 | case BIT(0)|BIT(3)|BIT(7): ca = 0x26; break; |
| 364 | case BIT(0)|BIT(1)|BIT(3)|BIT(7): ca = 0x27; break; |
| 365 | case BIT(0)|BIT(2)|BIT(3)|BIT(4)|BIT(9): ca = 0x28; break; |
| 366 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4)|BIT(9): ca = 0x29; break; |
| 367 | case BIT(0)|BIT(2)|BIT(3)|BIT(4)|BIT(10): ca = 0x2A; break; |
| 368 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(4)|BIT(10): ca = 0x2B; break; |
| 369 | case BIT(0)|BIT(2)|BIT(3)|BIT(9)|BIT(10): ca = 0x2C; break; |
| 370 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(9)|BIT(10): ca = 0x2D; break; |
| 371 | case BIT(0)|BIT(2)|BIT(3)|BIT(8): ca = 0x2E; break; |
| 372 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(8): ca = 0x2F; break; |
| 373 | case BIT(0)|BIT(2)|BIT(3)|BIT(7): ca = 0x30; break; |
| 374 | case BIT(0)|BIT(1)|BIT(2)|BIT(3)|BIT(7): ca = 0x31; break; |
| 375 | default: ca = 0x0; break; |
| 376 | } |
| 377 | ALOGD("%s channel allocation: %x", __func__, ca); |
| 378 | info->channel_allocation = ca; |
| 379 | } |
| 380 | |
| 381 | static void update_channel_map_lpass(edid_audio_info* info) |
| 382 | { |
| 383 | if (!info) |
| 384 | return; |
| 385 | if (info->channel_allocation < 0 || info->channel_allocation > 0x1f) { |
| 386 | ALOGE("Channel allocation out of supported range"); |
| 387 | return; |
| 388 | } |
| 389 | ALOGV("channel_allocation 0x%x", info->channel_allocation); |
| 390 | memset(info->channel_map, 0, MAX_CHANNELS_SUPPORTED); |
| 391 | switch(info->channel_allocation) { |
| 392 | case 0x0: |
| 393 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 394 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 395 | break; |
| 396 | case 0x1: |
| 397 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 398 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 399 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 400 | break; |
| 401 | case 0x2: |
| 402 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 403 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 404 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 405 | break; |
| 406 | case 0x3: |
| 407 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 408 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 409 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 410 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 411 | break; |
| 412 | case 0x4: |
| 413 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 414 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 415 | info->channel_map[2] = PCM_CHANNEL_CS; |
| 416 | break; |
| 417 | case 0x5: |
| 418 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 419 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 420 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 421 | info->channel_map[3] = PCM_CHANNEL_CS; |
| 422 | break; |
| 423 | case 0x6: |
| 424 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 425 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 426 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 427 | info->channel_map[3] = PCM_CHANNEL_CS; |
| 428 | break; |
| 429 | case 0x7: |
| 430 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 431 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 432 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 433 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 434 | info->channel_map[4] = PCM_CHANNEL_CS; |
| 435 | break; |
| 436 | case 0x8: |
| 437 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 438 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 439 | info->channel_map[2] = PCM_CHANNEL_LS; |
| 440 | info->channel_map[3] = PCM_CHANNEL_RS; |
| 441 | break; |
| 442 | case 0x9: |
| 443 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 444 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 445 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 446 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 447 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 448 | break; |
| 449 | case 0xa: |
| 450 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 451 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 452 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 453 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 454 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 455 | break; |
| 456 | case 0xb: |
| 457 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 458 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 459 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 460 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 461 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 462 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 463 | break; |
| 464 | case 0xc: |
| 465 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 466 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 467 | info->channel_map[2] = PCM_CHANNEL_LS; |
| 468 | info->channel_map[3] = PCM_CHANNEL_RS; |
| 469 | info->channel_map[4] = PCM_CHANNEL_CS; |
| 470 | break; |
| 471 | case 0xd: |
| 472 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 473 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 474 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 475 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 476 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 477 | info->channel_map[5] = PCM_CHANNEL_CS; |
| 478 | break; |
| 479 | case 0xe: |
| 480 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 481 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 482 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 483 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 484 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 485 | info->channel_map[5] = PCM_CHANNEL_CS; |
| 486 | break; |
| 487 | case 0xf: |
| 488 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 489 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 490 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 491 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 492 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 493 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 494 | info->channel_map[6] = PCM_CHANNEL_CS; |
| 495 | break; |
| 496 | case 0x10: |
| 497 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 498 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 499 | info->channel_map[2] = PCM_CHANNEL_LS; |
| 500 | info->channel_map[3] = PCM_CHANNEL_RS; |
| 501 | info->channel_map[4] = PCM_CHANNEL_LB; |
| 502 | info->channel_map[5] = PCM_CHANNEL_RB; |
| 503 | break; |
| 504 | case 0x11: |
| 505 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 506 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 507 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 508 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 509 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 510 | info->channel_map[5] = PCM_CHANNEL_LB; |
| 511 | info->channel_map[6] = PCM_CHANNEL_RB; |
| 512 | break; |
| 513 | case 0x12: |
| 514 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 515 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 516 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 517 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 518 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 519 | info->channel_map[5] = PCM_CHANNEL_LB; |
| 520 | info->channel_map[6] = PCM_CHANNEL_RB; |
| 521 | break; |
| 522 | case 0x13: |
| 523 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 524 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 525 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 526 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 527 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 528 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 529 | info->channel_map[6] = PCM_CHANNEL_LB; |
| 530 | info->channel_map[7] = PCM_CHANNEL_RB; |
| 531 | break; |
| 532 | case 0x14: |
| 533 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 534 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 535 | info->channel_map[2] = PCM_CHANNEL_FLC; |
| 536 | info->channel_map[3] = PCM_CHANNEL_FRC; |
| 537 | break; |
| 538 | case 0x15: |
| 539 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 540 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 541 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 542 | info->channel_map[3] = PCM_CHANNEL_FLC; |
| 543 | info->channel_map[4] = PCM_CHANNEL_FRC; |
| 544 | break; |
| 545 | case 0x16: |
| 546 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 547 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 548 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 549 | info->channel_map[3] = PCM_CHANNEL_FLC; |
| 550 | info->channel_map[4] = PCM_CHANNEL_FRC; |
| 551 | break; |
| 552 | case 0x17: |
| 553 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 554 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 555 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 556 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 557 | info->channel_map[4] = PCM_CHANNEL_FLC; |
| 558 | info->channel_map[5] = PCM_CHANNEL_FRC; |
| 559 | break; |
| 560 | case 0x18: |
| 561 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 562 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 563 | info->channel_map[2] = PCM_CHANNEL_CS; |
| 564 | info->channel_map[3] = PCM_CHANNEL_FLC; |
| 565 | info->channel_map[4] = PCM_CHANNEL_FRC; |
| 566 | break; |
| 567 | case 0x19: |
| 568 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 569 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 570 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 571 | info->channel_map[3] = PCM_CHANNEL_CS; |
| 572 | info->channel_map[4] = PCM_CHANNEL_FLC; |
| 573 | info->channel_map[5] = PCM_CHANNEL_FRC; |
| 574 | break; |
| 575 | case 0x1a: |
| 576 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 577 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 578 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 579 | info->channel_map[3] = PCM_CHANNEL_CS; |
| 580 | info->channel_map[4] = PCM_CHANNEL_FLC; |
| 581 | info->channel_map[5] = PCM_CHANNEL_FRC; |
| 582 | break; |
| 583 | case 0x1b: |
| 584 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 585 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 586 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 587 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 588 | info->channel_map[4] = PCM_CHANNEL_CS; |
| 589 | info->channel_map[5] = PCM_CHANNEL_FLC; |
| 590 | info->channel_map[6] = PCM_CHANNEL_FRC; |
| 591 | break; |
| 592 | case 0x1c: |
| 593 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 594 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 595 | info->channel_map[2] = PCM_CHANNEL_LS; |
| 596 | info->channel_map[3] = PCM_CHANNEL_RS; |
| 597 | info->channel_map[4] = PCM_CHANNEL_FLC; |
| 598 | info->channel_map[5] = PCM_CHANNEL_FRC; |
| 599 | break; |
| 600 | case 0x1d: |
| 601 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 602 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 603 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 604 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 605 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 606 | info->channel_map[5] = PCM_CHANNEL_FLC; |
| 607 | info->channel_map[6] = PCM_CHANNEL_FRC; |
| 608 | break; |
| 609 | case 0x1e: |
| 610 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 611 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 612 | info->channel_map[2] = PCM_CHANNEL_FC; |
| 613 | info->channel_map[3] = PCM_CHANNEL_LS; |
| 614 | info->channel_map[4] = PCM_CHANNEL_RS; |
| 615 | info->channel_map[5] = PCM_CHANNEL_FLC; |
| 616 | info->channel_map[6] = PCM_CHANNEL_FRC; |
| 617 | break; |
| 618 | case 0x1f: |
| 619 | info->channel_map[0] = PCM_CHANNEL_FL; |
| 620 | info->channel_map[1] = PCM_CHANNEL_FR; |
| 621 | info->channel_map[2] = PCM_CHANNEL_LFE; |
| 622 | info->channel_map[3] = PCM_CHANNEL_FC; |
| 623 | info->channel_map[4] = PCM_CHANNEL_LS; |
| 624 | info->channel_map[5] = PCM_CHANNEL_RS; |
| 625 | info->channel_map[6] = PCM_CHANNEL_FLC; |
| 626 | info->channel_map[7] = PCM_CHANNEL_FRC; |
| 627 | break; |
| 628 | default: |
| 629 | break; |
| 630 | } |
| 631 | ALOGD("%s channel map updated to [%d %d %d %d %d %d %d %d ]", __func__ |
| 632 | , info->channel_map[0], info->channel_map[1], info->channel_map[2] |
| 633 | , info->channel_map[3], info->channel_map[4], info->channel_map[5] |
| 634 | , info->channel_map[6], info->channel_map[7]); |
| 635 | } |
| 636 | |
| 637 | static void dump_edid_data(edid_audio_info *info) |
| 638 | { |
| 639 | |
| 640 | int i; |
| 641 | for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) { |
| 642 | ALOGV("%s:FormatId:%d rate:%d bps:%d channels:%d", __func__, |
| 643 | info->audio_blocks_array[i].format_id, |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 644 | info->audio_blocks_array[i].sampling_freq_bitmask, |
| 645 | info->audio_blocks_array[i].bits_per_sample_bitmask, |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 646 | info->audio_blocks_array[i].channels); |
| 647 | } |
| 648 | ALOGV("%s:no of audio blocks:%d", __func__, info->audio_blocks); |
| 649 | ALOGV("%s:speaker allocation:[%x %x %x]", __func__, |
| 650 | info->speaker_allocation[0], info->speaker_allocation[1], |
| 651 | info->speaker_allocation[2]); |
| 652 | ALOGV("%s:channel map:[%x %x %x %x %x %x %x %x]", __func__, |
| 653 | info->channel_map[0], info->channel_map[1], |
| 654 | info->channel_map[2], info->channel_map[3], |
| 655 | info->channel_map[4], info->channel_map[5], |
| 656 | info->channel_map[6], info->channel_map[7]); |
| 657 | ALOGV("%s:channel allocation:%d", __func__, info->channel_allocation); |
| 658 | ALOGV("%s:[%d %d %d %d %d %d %d %d ]", __func__, |
| 659 | info->channel_map[0], info->channel_map[1], |
| 660 | info->channel_map[2], info->channel_map[3], |
| 661 | info->channel_map[4], info->channel_map[5], |
| 662 | info->channel_map[6], info->channel_map[7]); |
| 663 | } |
| 664 | |
| 665 | bool edid_get_sink_caps(edid_audio_info* info, char *edid_data) |
| 666 | { |
| 667 | unsigned char channels[MAX_EDID_BLOCKS]; |
| 668 | unsigned char formats[MAX_EDID_BLOCKS]; |
| 669 | unsigned char frequency[MAX_EDID_BLOCKS]; |
| 670 | unsigned char bitrate[MAX_EDID_BLOCKS]; |
| 671 | int i = 0; |
| 672 | int length, count_desc; |
| 673 | |
| 674 | if (!info || !edid_data) { |
| 675 | ALOGE("No valid EDID"); |
| 676 | return false; |
| 677 | } |
| 678 | |
| 679 | length = (int) *edid_data++; |
| 680 | ALOGV("Total length is %d",length); |
| 681 | |
| 682 | count_desc = length/MIN_AUDIO_DESC_LENGTH; |
| 683 | |
| 684 | if (!count_desc) { |
| 685 | ALOGE("insufficient descriptors"); |
| 686 | return false; |
| 687 | } |
| 688 | |
| 689 | memset(info, 0, sizeof(edid_audio_info)); |
| 690 | |
| 691 | info->audio_blocks = count_desc-1; |
| 692 | if (info->audio_blocks > MAX_EDID_BLOCKS) { |
| 693 | info->audio_blocks = MAX_EDID_BLOCKS; |
| 694 | } |
| 695 | |
| 696 | ALOGV("Total # of audio descriptors %d",count_desc); |
| 697 | |
| 698 | for (i=0; i<info->audio_blocks; i++) { |
| 699 | // last block for speaker allocation; |
| 700 | channels [i] = (*edid_data & 0x7) + 1; |
| 701 | formats [i] = (*edid_data++) >> 3; |
| 702 | frequency[i] = *edid_data++; |
| 703 | bitrate [i] = *edid_data++; |
| 704 | } |
| 705 | info->speaker_allocation[0] = *edid_data++; |
| 706 | info->speaker_allocation[1] = *edid_data++; |
| 707 | info->speaker_allocation[2] = *edid_data++; |
| 708 | |
| 709 | update_channel_map(info); |
| 710 | update_channel_allocation(info); |
| 711 | update_channel_map_lpass(info); |
| 712 | |
| 713 | for (i=0; i<info->audio_blocks; i++) { |
| 714 | ALOGV("AUDIO DESC BLOCK # %d\n",i); |
| 715 | |
| 716 | info->audio_blocks_array[i].channels = channels[i]; |
Ashish Jain | 957440f | 2015-08-28 10:47:13 +0530 | [diff] [blame] | 717 | ALOGD("info->audio_blocks_array[i].channels %d\n", |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 718 | info->audio_blocks_array[i].channels); |
| 719 | |
| 720 | ALOGV("Format Byte %d\n", formats[i]); |
| 721 | 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] | 722 | ALOGD("info->audio_blocks_array[i].format_id %s", |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 723 | edid_format_to_str(formats[i])); |
| 724 | |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 725 | ALOGV("Frequency Bitmask %d\n", frequency[i]); |
| 726 | info->audio_blocks_array[i].sampling_freq_bitmask = frequency[i]; |
| 727 | ALOGV("info->audio_blocks_array[i].sampling_freq_bitmask %d", |
| 728 | info->audio_blocks_array[i].sampling_freq_bitmask); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 729 | |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 730 | ALOGV("BitsPerSample Bitmask %d\n", bitrate[i]); |
| 731 | info->audio_blocks_array[i].bits_per_sample_bitmask = |
| 732 | get_edid_bps_byte(bitrate[i],formats[i]); |
| 733 | ALOGV("info->audio_blocks_array[i].bits_per_sample_bitmask %d", |
| 734 | info->audio_blocks_array[i].bits_per_sample_bitmask); |
Pradnya Chaphekar | 4403bd7 | 2014-09-09 09:50:01 -0700 | [diff] [blame] | 735 | } |
| 736 | dump_speaker_allocation(info); |
| 737 | dump_edid_data(info); |
| 738 | return true; |
| 739 | } |
Mingming Yin | ddd610b | 2016-01-20 17:09:32 -0800 | [diff] [blame] | 740 | |
| 741 | bool edid_is_supported_sr(edid_audio_info* info, int sr) |
| 742 | { |
| 743 | int i = 0; |
| 744 | if (info != NULL && sr != 0) { |
| 745 | for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 746 | if (is_supported_sr(info->audio_blocks_array[i].sampling_freq_bitmask , sr)) { |
Mingming Yin | ddd610b | 2016-01-20 17:09:32 -0800 | [diff] [blame] | 747 | ALOGV("%s: returns true for sample rate [%d]", |
| 748 | __func__, sr); |
| 749 | return true; |
| 750 | } |
| 751 | } |
| 752 | } |
| 753 | ALOGV("%s: returns false for sample rate [%d]", |
| 754 | __func__, sr); |
| 755 | return false; |
| 756 | } |
| 757 | |
| 758 | bool edid_is_supported_bps(edid_audio_info* info, int bps) |
| 759 | { |
| 760 | int i = 0; |
| 761 | |
| 762 | if (bps == 16) { |
| 763 | //16 bit bps is always supported |
| 764 | //some oem may not update 16bit support in their edid info |
| 765 | return true; |
| 766 | } |
| 767 | |
| 768 | if (info != NULL && bps != 0) { |
| 769 | for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) { |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 770 | if (is_supported_bps(info->audio_blocks_array[i].bits_per_sample_bitmask, bps)) { |
Mingming Yin | ddd610b | 2016-01-20 17:09:32 -0800 | [diff] [blame] | 771 | ALOGV("%s: returns true for bit width [%d]", |
| 772 | __func__, bps); |
| 773 | return true; |
| 774 | } |
| 775 | } |
| 776 | } |
| 777 | ALOGV("%s: returns false for bit width [%d]", |
| 778 | __func__, bps); |
| 779 | return false; |
| 780 | } |
Garmond Leung | 2f78a67 | 2016-11-07 16:27:40 -0800 | [diff] [blame] | 781 | |
| 782 | int edid_get_highest_supported_sr(edid_audio_info* info) |
| 783 | { |
| 784 | int sr = 0; |
| 785 | int highest_sr = 0; |
| 786 | int i; |
| 787 | |
| 788 | if (info != NULL) { |
| 789 | for (i = 0; i < info->audio_blocks && i < MAX_EDID_BLOCKS; i++) { |
| 790 | sr = get_highest_edid_sf(info->audio_blocks_array[i].sampling_freq_bitmask); |
| 791 | if (sr > highest_sr) |
| 792 | highest_sr = sr; |
| 793 | } |
| 794 | } |
| 795 | else |
| 796 | ALOGE("%s: info is NULL", __func__); |
| 797 | |
| 798 | ALOGV("%s: returns [%d] for highest supported sr", |
| 799 | __func__, highest_sr); |
| 800 | return highest_sr; |
| 801 | } |