Subhash Chandra Bose Naripeddy | 7690c56 | 2013-12-14 00:34:53 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. |
| 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright (C) 2010 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_dolby" |
| 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 "audio_extn.h" |
| 35 | #include "sound/compress_params.h" |
| 36 | |
| 37 | #ifdef DS1_DOLBY_DDP_ENABLED |
| 38 | |
| 39 | #define AUDIO_PARAMETER_DDP_DEV "ddp_device" |
| 40 | #define AUDIO_PARAMETER_DDP_CH_CAP "ddp_chancap" |
| 41 | #define AUDIO_PARAMETER_DDP_MAX_OUT_CHAN "ddp_maxoutchan" |
| 42 | #define AUDIO_PARAMETER_DDP_OUT_MODE "ddp_outmode" |
| 43 | #define AUDIO_PARAMETER_DDP_OUT_LFE_ON "ddp_outlfeon" |
| 44 | #define AUDIO_PARAMETER_DDP_COMP_MODE "ddp_compmode" |
| 45 | #define AUDIO_PARAMETER_DDP_STEREO_MODE "ddp_stereomode" |
| 46 | |
| 47 | #define PARAM_ID_MAX_OUTPUT_CHANNELS 0x00010DE2 |
| 48 | #define PARAM_ID_CTL_RUNNING_MODE 0x0 |
| 49 | #define PARAM_ID_CTL_ERROR_CONCEAL 0x00010DE3 |
| 50 | #define PARAM_ID_CTL_ERROR_MAX_RPTS 0x00010DE4 |
| 51 | #define PARAM_ID_CNV_ERROR_CONCEAL 0x00010DE5 |
| 52 | #define PARAM_ID_CTL_SUBSTREAM_SELECT 0x00010DE6 |
| 53 | #define PARAM_ID_CTL_INPUT_MODE 0x0 |
| 54 | #define PARAM_ID_OUT_CTL_OUTMODE 0x00010DE0 |
| 55 | #define PARAM_ID_OUT_CTL_OUTLFE_ON 0x00010DE1 |
| 56 | #define PARAM_ID_OUT_CTL_COMPMODE 0x00010D74 |
| 57 | #define PARAM_ID_OUT_CTL_STEREO_MODE 0x00010D76 |
| 58 | #define PARAM_ID_OUT_CTL_DUAL_MODE 0x00010D75 |
| 59 | #define PARAM_ID_OUT_CTL_DRCSCALE_HIGH 0x00010D7A |
| 60 | #define PARAM_ID_OUT_CTL_DRCSCALE_LOW 0x00010D79 |
| 61 | #define PARAM_ID_OUT_CTL_OUT_PCMSCALE 0x00010D78 |
| 62 | #define PARAM_ID_OUT_CTL_MDCT_BANDLIMIT 0x00010DE7 |
| 63 | #define PARAM_ID_OUT_CTL_DRC_SUPPRESS 0x00010DE8 |
| 64 | |
| 65 | /* DS1-DDP Endp Params */ |
| 66 | #define DDP_ENDP_NUM_PARAMS 17 |
| 67 | #define DDP_ENDP_NUM_DEVICES 22 |
| 68 | static int ddp_endp_params_id[DDP_ENDP_NUM_PARAMS] = { |
| 69 | PARAM_ID_MAX_OUTPUT_CHANNELS, PARAM_ID_CTL_RUNNING_MODE, |
| 70 | PARAM_ID_CTL_ERROR_CONCEAL, PARAM_ID_CTL_ERROR_MAX_RPTS, |
| 71 | PARAM_ID_CNV_ERROR_CONCEAL, PARAM_ID_CTL_SUBSTREAM_SELECT, |
| 72 | PARAM_ID_CTL_INPUT_MODE, PARAM_ID_OUT_CTL_OUTMODE, |
| 73 | PARAM_ID_OUT_CTL_OUTLFE_ON, PARAM_ID_OUT_CTL_COMPMODE, |
| 74 | PARAM_ID_OUT_CTL_STEREO_MODE, PARAM_ID_OUT_CTL_DUAL_MODE, |
| 75 | PARAM_ID_OUT_CTL_DRCSCALE_HIGH, PARAM_ID_OUT_CTL_DRCSCALE_LOW, |
| 76 | PARAM_ID_OUT_CTL_OUT_PCMSCALE, PARAM_ID_OUT_CTL_MDCT_BANDLIMIT, |
| 77 | PARAM_ID_OUT_CTL_DRC_SUPPRESS |
| 78 | }; |
| 79 | |
| 80 | static struct ddp_endp_params { |
| 81 | int device; |
| 82 | int dev_ch_cap; |
| 83 | int param_val[DDP_ENDP_NUM_PARAMS]; |
| 84 | bool is_param_valid[DDP_ENDP_NUM_PARAMS]; |
| 85 | } ddp_endp_params[DDP_ENDP_NUM_DEVICES] = { |
| 86 | {AUDIO_DEVICE_OUT_EARPIECE, 2, |
| 87 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 88 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 } }, |
| 89 | {AUDIO_DEVICE_OUT_SPEAKER, 2, |
| 90 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 91 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 92 | {AUDIO_DEVICE_OUT_WIRED_HEADSET, 2, |
| 93 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 94 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 95 | {AUDIO_DEVICE_OUT_WIRED_HEADPHONE, 2, |
| 96 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 97 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 98 | {AUDIO_DEVICE_OUT_BLUETOOTH_SCO, 2, |
| 99 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 100 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 101 | {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET, 2, |
| 102 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 103 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 104 | {AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT, 2, |
| 105 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 106 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 107 | {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, 2, |
| 108 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 109 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 110 | {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES, 2, |
| 111 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 112 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 113 | {AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER, 2, |
| 114 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 115 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 116 | {AUDIO_DEVICE_OUT_AUX_DIGITAL, 2, |
| 117 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0}, |
| 118 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 119 | {AUDIO_DEVICE_OUT_AUX_DIGITAL, 6, |
| 120 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0}, |
| 121 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 122 | {AUDIO_DEVICE_OUT_AUX_DIGITAL, 8, |
| 123 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 2, 0, 0, 0, 0, 0, 0, 0}, |
| 124 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 125 | {AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET, 2, |
| 126 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 127 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 128 | {AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET, 2, |
| 129 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 130 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 131 | {AUDIO_DEVICE_OUT_USB_ACCESSORY, 2, |
| 132 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 133 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 134 | {AUDIO_DEVICE_OUT_USB_DEVICE, 2, |
| 135 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 136 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 137 | {AUDIO_DEVICE_OUT_FM, 2, |
| 138 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 139 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 140 | {AUDIO_DEVICE_OUT_FM_TX, 2, |
| 141 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 142 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 143 | {AUDIO_DEVICE_OUT_ANC_HEADSET, 2, |
| 144 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 145 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 146 | {AUDIO_DEVICE_OUT_ANC_HEADPHONE, 2, |
| 147 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 148 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 149 | {AUDIO_DEVICE_OUT_PROXY, 2, |
| 150 | {8, 0, 0, 0, 0, 0, 0, 21, 1, 6, 0, 0, 0, 0, 0, 0, 0}, |
| 151 | {1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0} }, |
| 152 | }; |
| 153 | |
| 154 | int update_ddp_endp_table(int device, int dev_ch_cap, int param_id, |
| 155 | int param_val) |
| 156 | { |
| 157 | int idx = 0; |
| 158 | int param_idx = 0; |
| 159 | ALOGV("%s: dev 0x%x dev_ch_cap %d param_id 0x%x param_val %d", |
| 160 | __func__, device, dev_ch_cap , param_id, param_val); |
| 161 | |
| 162 | for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) { |
| 163 | if(ddp_endp_params[idx].device == device) { |
| 164 | if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) { |
| 165 | break; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if(idx>=DDP_ENDP_NUM_DEVICES) { |
| 171 | ALOGE("%s: device not available in DDP endp config table", __func__); |
| 172 | return -EINVAL; |
| 173 | } |
| 174 | |
| 175 | for(param_idx=0; param_idx<DDP_ENDP_NUM_PARAMS; param_idx++) { |
| 176 | if (ddp_endp_params_id[param_idx] == param_id) { |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if(param_idx>=DDP_ENDP_NUM_PARAMS) { |
| 182 | ALOGE("param not available in DDP endp config table"); |
| 183 | return -EINVAL; |
| 184 | } |
| 185 | |
| 186 | ALOGV("ddp_endp_params[%d].param_val[%d] = %d", idx, param_idx, param_val); |
| 187 | ddp_endp_params[idx].param_val[param_idx] = param_val; |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | void send_ddp_endp_params_stream(struct stream_out *out, |
| 192 | int device, int dev_ch_cap, |
| 193 | bool set_cache) |
| 194 | { |
| 195 | int idx, i; |
| 196 | int ddp_endp_params_data[2*DDP_ENDP_NUM_PARAMS + 1]; |
| 197 | int length = 0; |
| 198 | for(idx=0; idx<DDP_ENDP_NUM_DEVICES; idx++) { |
| 199 | if(ddp_endp_params[idx].device & device) { |
| 200 | if(ddp_endp_params[idx].dev_ch_cap == dev_ch_cap) { |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | if(idx>=DDP_ENDP_NUM_DEVICES) { |
| 206 | ALOGE("device not available in DDP endp config table"); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | length += 1; /* offset 0 is for num of parameter. increase offset by 1 */ |
| 211 | for (i=0; i<DDP_ENDP_NUM_PARAMS; i++) { |
| 212 | if(ddp_endp_params[idx].is_param_valid[i]) { |
| 213 | ddp_endp_params_data[length++] = ddp_endp_params_id[i]; |
| 214 | ddp_endp_params_data[length++] = ddp_endp_params[idx].param_val[i]; |
| 215 | } |
| 216 | } |
| 217 | ddp_endp_params_data[0] = (length-1)/2; |
| 218 | if(length) { |
| 219 | char mixer_ctl_name[128]; |
| 220 | struct audio_device *adev = out->dev; |
| 221 | struct mixer_ctl *ctl; |
| 222 | int pcm_device_id = platform_get_pcm_device_id(out->usecase, |
| 223 | PCM_PLAYBACK); |
| 224 | snprintf(mixer_ctl_name, sizeof(mixer_ctl_name), |
| 225 | "Audio Stream %d Dec Params", pcm_device_id); |
| 226 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 227 | if (!ctl) { |
| 228 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 229 | __func__, mixer_ctl_name); |
| 230 | return; |
| 231 | } |
| 232 | mixer_ctl_set_array(ctl, ddp_endp_params_data, length); |
| 233 | } |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | void send_ddp_endp_params(struct audio_device *adev, |
| 238 | int ddp_dev, int dev_ch_cap) |
| 239 | { |
| 240 | struct listnode *node; |
| 241 | struct audio_usecase *usecase; |
| 242 | |
| 243 | list_for_each(node, &adev->usecase_list) { |
| 244 | usecase = node_to_item(node, struct audio_usecase, list); |
| 245 | if ((usecase->type == PCM_PLAYBACK) && |
| 246 | (usecase->devices & ddp_dev) && |
| 247 | (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && |
| 248 | ((usecase->stream.out->format == AUDIO_FORMAT_AC3) || |
| 249 | (usecase->stream.out->format == AUDIO_FORMAT_EAC3))) { |
| 250 | send_ddp_endp_params_stream(usecase->stream.out, ddp_dev, |
| 251 | dev_ch_cap, false /* set cache */); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | void audio_extn_dolby_send_ddp_endp_params(struct audio_device *adev) |
| 257 | { |
| 258 | struct listnode *node; |
| 259 | struct audio_usecase *usecase; |
| 260 | list_for_each(node, &adev->usecase_list) { |
| 261 | usecase = node_to_item(node, struct audio_usecase, list); |
| 262 | if ((usecase->type == PCM_PLAYBACK) && |
| 263 | (usecase->devices & AUDIO_DEVICE_OUT_ALL) && |
| 264 | (usecase->stream.out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) && |
| 265 | ((usecase->stream.out->format == AUDIO_FORMAT_AC3) || |
| 266 | (usecase->stream.out->format == AUDIO_FORMAT_EAC3))) { |
| 267 | send_ddp_endp_params_stream(usecase->stream.out, usecase->devices, |
| 268 | usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ? |
| 269 | adev->cur_hdmi_channels : 2, false /* set cache */); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | void audio_extn_ddp_set_parameters(struct audio_device *adev, |
| 275 | struct str_parms *parms) |
| 276 | { |
| 277 | int ddp_dev, dev_ch_cap; |
| 278 | int val, ret; |
| 279 | char value[32]={0}; |
| 280 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_DEV, value, |
| 281 | sizeof(value)); |
| 282 | if (ret >= 0) { |
| 283 | ddp_dev = atoi(value); |
| 284 | if (!(AUDIO_DEVICE_OUT_ALL & ddp_dev)) |
| 285 | return; |
| 286 | } else |
| 287 | return; |
| 288 | |
| 289 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_CH_CAP, value, |
| 290 | sizeof(value)); |
| 291 | if (ret >= 0) { |
| 292 | dev_ch_cap = atoi(value); |
| 293 | if ((dev_ch_cap != 2) && (dev_ch_cap != 6) && (dev_ch_cap != 8)) |
| 294 | return; |
| 295 | } else |
| 296 | return; |
| 297 | |
| 298 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_MAX_OUT_CHAN, value, |
| 299 | sizeof(value)); |
| 300 | if (ret >= 0) { |
| 301 | val = atoi(value); |
| 302 | update_ddp_endp_table(ddp_dev, dev_ch_cap, |
| 303 | PARAM_ID_MAX_OUTPUT_CHANNELS, val); |
| 304 | } |
| 305 | |
| 306 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_MODE, value, |
| 307 | sizeof(value)); |
| 308 | if (ret >= 0) { |
| 309 | val = atoi(value); |
| 310 | update_ddp_endp_table(ddp_dev, dev_ch_cap, |
| 311 | PARAM_ID_OUT_CTL_OUTMODE, val); |
| 312 | } |
| 313 | |
| 314 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_OUT_LFE_ON, value, |
| 315 | sizeof(value)); |
| 316 | if (ret >= 0) { |
| 317 | val = atoi(value); |
| 318 | update_ddp_endp_table(ddp_dev, dev_ch_cap, |
| 319 | PARAM_ID_OUT_CTL_OUTLFE_ON, val); |
| 320 | } |
| 321 | |
| 322 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_COMP_MODE, value, |
| 323 | sizeof(value)); |
| 324 | if (ret >= 0) { |
| 325 | val = atoi(value); |
| 326 | update_ddp_endp_table(ddp_dev, dev_ch_cap, |
| 327 | PARAM_ID_OUT_CTL_COMPMODE, val); |
| 328 | } |
| 329 | |
| 330 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DDP_STEREO_MODE, value, |
| 331 | sizeof(value)); |
| 332 | if (ret >= 0) { |
| 333 | val = atoi(value); |
| 334 | update_ddp_endp_table(ddp_dev, dev_ch_cap, |
| 335 | PARAM_ID_OUT_CTL_STEREO_MODE, val); |
| 336 | } |
| 337 | |
| 338 | send_ddp_endp_params(adev, ddp_dev, dev_ch_cap); |
| 339 | } |
| 340 | |
| 341 | int audio_extn_dolby_get_snd_codec_id(struct audio_device *adev, |
| 342 | struct stream_out *out, |
| 343 | audio_format_t format) |
| 344 | { |
| 345 | int id = 0; |
| 346 | |
| 347 | switch (format) { |
| 348 | case AUDIO_FORMAT_AC3: |
| 349 | id = SND_AUDIOCODEC_AC3; |
| 350 | send_ddp_endp_params_stream(out, out->devices, |
| 351 | out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ? |
| 352 | adev->cur_hdmi_channels : 2, true /* set_cache */); |
| 353 | #ifndef DS1_DOLBY_DAP_ENABLED |
| 354 | audio_extn_dolby_set_dmid(adev); |
| 355 | #endif |
| 356 | break; |
| 357 | case AUDIO_FORMAT_EAC3: |
| 358 | id = SND_AUDIOCODEC_EAC3; |
| 359 | send_ddp_endp_params_stream(out, out->devices, |
| 360 | out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL ? |
| 361 | adev->cur_hdmi_channels : 2, true /* set_cache */); |
| 362 | #ifndef DS1_DOLBY_DAP_ENABLED |
| 363 | audio_extn_dolby_set_dmid(adev); |
| 364 | #endif |
| 365 | break; |
| 366 | default: |
| 367 | ALOGE("%s: Unsupported audio format :%x", __func__, format); |
| 368 | } |
| 369 | |
| 370 | return id; |
| 371 | } |
| 372 | |
| 373 | bool audio_extn_is_dolby_format(audio_format_t format) |
| 374 | { |
| 375 | if (format == AUDIO_FORMAT_AC3 || |
| 376 | format == AUDIO_FORMAT_EAC3) |
| 377 | return true; |
| 378 | else |
| 379 | return false; |
| 380 | } |
| 381 | |
| 382 | #endif /* DS1_DOLBY_DDP_ENABLED */ |
| 383 | |
| 384 | #ifdef DS1_DOLBY_DAP_ENABLED |
| 385 | void audio_extn_dolby_set_endpoint(struct audio_device *adev) |
| 386 | { |
| 387 | struct listnode *node; |
| 388 | struct audio_usecase *usecase; |
| 389 | struct mixer_ctl *ctl; |
| 390 | const char *mixer_ctl_name = "DS1 DAP Endpoint"; |
| 391 | int endpoint = 0, ret; |
| 392 | bool send = false; |
| 393 | |
| 394 | list_for_each(node, &adev->usecase_list) { |
| 395 | usecase = node_to_item(node, struct audio_usecase, list); |
| 396 | if ((usecase->type == PCM_PLAYBACK) && |
| 397 | (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) { |
| 398 | endpoint |= usecase->devices & AUDIO_DEVICE_OUT_ALL; |
| 399 | send = true; |
| 400 | } |
| 401 | } |
| 402 | if (!send) |
| 403 | return; |
| 404 | |
| 405 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 406 | if (!ctl) { |
| 407 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 408 | __func__, mixer_ctl_name); |
| 409 | return; |
| 410 | } |
| 411 | ret = mixer_ctl_set_value(ctl, 0, endpoint); |
| 412 | if (ret) |
| 413 | ALOGE("%s: Dolby set endpint cannot be set error:%d",__func__, ret); |
| 414 | |
| 415 | return; |
| 416 | } |
| 417 | #endif /* DS1_DOLBY_DAP_ENABLED */ |
| 418 | |
| 419 | |
| 420 | #if defined(DS1_DOLBY_DDP_ENABLED) || defined(DS1_DOLBY_DAP_ENABLED) |
| 421 | void audio_extn_dolby_set_dmid(struct audio_device *adev) |
| 422 | { |
| 423 | struct listnode *node; |
| 424 | struct audio_usecase *usecase; |
| 425 | struct mixer_ctl *ctl; |
| 426 | const char *mixer_ctl_name = "DS1 Security"; |
| 427 | char c_dmid[128] = {0}; |
| 428 | int i_dmid, ret; |
| 429 | bool send = false; |
| 430 | |
| 431 | list_for_each(node, &adev->usecase_list) { |
| 432 | usecase = node_to_item(node, struct audio_usecase, list); |
| 433 | if ((usecase->type == PCM_PLAYBACK) && |
| 434 | (usecase->id != USECASE_AUDIO_PLAYBACK_LOW_LATENCY)) |
| 435 | send = true; |
| 436 | } |
| 437 | if (!send) |
| 438 | return; |
| 439 | |
| 440 | property_get("dmid",c_dmid,"0"); |
| 441 | i_dmid = atoi(c_dmid); |
| 442 | |
| 443 | ctl = mixer_get_ctl_by_name(adev->mixer, mixer_ctl_name); |
| 444 | if (!ctl) { |
| 445 | ALOGE("%s: Could not get ctl for mixer cmd - %s", |
| 446 | __func__, mixer_ctl_name); |
| 447 | return; |
| 448 | } |
| 449 | ALOGV("%s Dolby device manufacturer id is:%d",__func__,i_dmid); |
| 450 | ret = mixer_ctl_set_value(ctl, 0, i_dmid); |
| 451 | if (ret) |
| 452 | ALOGE("%s: Dolby DMID cannot be set error:%d",__func__, ret); |
| 453 | |
| 454 | return; |
| 455 | } |
| 456 | #endif /* DS1_DOLBY_DDP_ENABLED || DS1_DOLBY_DAP_ENABLED */ |