Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 1 | /* |
Md Mansoor Ahmed | db1b4f9 | 2018-01-25 18:56:31 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #define LOG_TAG "passthru" |
| 31 | /*#define LOG_NDEBUG 0*/ |
| 32 | #include <stdlib.h> |
| 33 | #include <cutils/atomic.h> |
| 34 | #include <cutils/str_parms.h> |
| 35 | #include <cutils/log.h> |
Vinay Verma | addfa4a | 2018-04-29 14:03:38 +0530 | [diff] [blame] | 36 | #include <unistd.h> |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 37 | #include "audio_hw.h" |
| 38 | #include "audio_extn.h" |
| 39 | #include "platform_api.h" |
| 40 | #include <platform.h> |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 41 | #include <cutils/properties.h> |
| 42 | |
| 43 | #include "sound/compress_params.h" |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 44 | |
Revathi Uddaraju | 1eac8b0 | 2017-05-18 17:13:33 +0530 | [diff] [blame] | 45 | #ifdef DYNAMIC_LOG_ENABLED |
| 46 | #include <log_xml_parser.h> |
| 47 | #define LOG_MASK HAL_MOD_FILE_PASSTH |
| 48 | #include <log_utils.h> |
| 49 | #endif |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 50 | /* |
| 51 | * Offload buffer size for compress passthrough |
| 52 | */ |
| 53 | |
| 54 | #ifdef DTSHD_PARSER_ENABLED |
| 55 | #include "audio_parsers.h" |
| 56 | |
| 57 | /* list of all supported DTS transmission sample rates */ |
| 58 | static const int dts_transmission_sample_rates[] = { |
| 59 | 44100, 48000, 88200, 96000, 176400, 192000 |
| 60 | }; |
| 61 | |
| 62 | /* |
| 63 | * for DTSHD stream one frame size can be upto 36kb and to extract iec61937 |
| 64 | * info for parsing usecase minimum one frame needs to be sent to dts parser |
| 65 | */ |
| 66 | #define MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (36 * 1024) |
| 67 | #else |
| 68 | #define MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (8 * 1024) |
| 69 | #endif |
| 70 | |
| 71 | #define MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (2 * 1024) |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 72 | |
Harsh Bansal | c83207c | 2017-09-01 16:04:36 +0530 | [diff] [blame] | 73 | #define DDP_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (10 * 1024) |
| 74 | |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 75 | static const audio_format_t audio_passthru_formats[] = { |
| 76 | AUDIO_FORMAT_AC3, |
| 77 | AUDIO_FORMAT_E_AC3, |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 78 | AUDIO_FORMAT_E_AC3_JOC, |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 79 | AUDIO_FORMAT_DTS, |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 80 | AUDIO_FORMAT_DTS_HD, |
Naresh Tanniru | 928f086 | 2017-04-07 16:44:23 -0700 | [diff] [blame] | 81 | AUDIO_FORMAT_DOLBY_TRUEHD, |
| 82 | AUDIO_FORMAT_IEC61937 |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | /* |
| 86 | * This atomic var is incremented/decremented by the offload stream to notify |
| 87 | * other pcm playback streams that a pass thru session is about to start or has |
| 88 | * finished. This hint can be used by the other streams to move to standby or |
| 89 | * start calling pcm_write respectively. |
| 90 | * This behavior is necessary as the DSP backend can only be configured to one |
| 91 | * of PCM or compressed. |
| 92 | */ |
| 93 | static volatile int32_t compress_passthru_active; |
| 94 | |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 95 | #ifdef DTSHD_PARSER_ENABLED |
Manish Dewangan | 671a420 | 2017-08-18 17:30:46 +0530 | [diff] [blame] | 96 | int audio_extn_passthru_update_dts_stream_configuration(struct stream_out *out, |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 97 | const void *buffer, size_t bytes) |
| 98 | { |
| 99 | struct audio_parser_codec_info codec_info; |
| 100 | struct dtshd_iec61937_info dtshd_tr_info; |
| 101 | int i; |
| 102 | int ret; |
| 103 | bool is_valid_transmission_rate = false; |
| 104 | bool is_valid_transmission_channels = false; |
| 105 | |
Manish Dewangan | 671a420 | 2017-08-18 17:30:46 +0530 | [diff] [blame] | 106 | if (!out) { |
| 107 | ALOGE("Invalid session"); |
| 108 | return -EINVAL; |
| 109 | } |
| 110 | |
| 111 | if ((out->format != AUDIO_FORMAT_DTS) && |
| 112 | (out->format != AUDIO_FORMAT_DTS_HD)) { |
| 113 | ALOGE("Non DTS format %d", out->format); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
| 117 | if (!buffer || bytes <= 0) { |
| 118 | ALOGD("Invalid buffer %p size %d skipping dts stream conf update", |
| 119 | buffer, bytes); |
| 120 | out->sample_rate = 48000; |
| 121 | out->compr_config.codec->sample_rate = out->sample_rate; |
| 122 | out->compr_config.codec->ch_in = 2; |
| 123 | out->channel_mask = audio_channel_out_mask_from_count(2); |
| 124 | return -EINVAL; |
| 125 | } |
| 126 | |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 127 | /* codec format is AUDIO_PARSER_CODEC_DTSHD for both DTS and DTSHD as |
| 128 | * DTSHD parser can support both DTS and DTSHD |
| 129 | */ |
| 130 | memset(&codec_info, 0, sizeof(struct audio_parser_codec_info)); |
| 131 | memset(&dtshd_tr_info, 0, sizeof(struct dtshd_iec61937_info)); |
| 132 | |
| 133 | init_audio_parser((unsigned char *)buffer, bytes, AUDIO_PARSER_CODEC_DTSHD); |
| 134 | codec_info.codec_type = AUDIO_PARSER_CODEC_DTSHD; |
| 135 | if (!(ret = get_iec61937_info(&codec_info))) { |
| 136 | dtshd_tr_info = codec_info.codec_config.dtshd_tr_info; |
| 137 | ALOGD("dts new sample rate %d and channels %d\n", |
| 138 | dtshd_tr_info.sample_rate, |
| 139 | dtshd_tr_info.num_channels); |
| 140 | for (i = 0; i < sizeof(dts_transmission_sample_rates); i++) { |
| 141 | if (dts_transmission_sample_rates[i] == |
| 142 | dtshd_tr_info.sample_rate) { |
| 143 | out->sample_rate = dtshd_tr_info.sample_rate; |
| 144 | out->compr_config.codec->sample_rate = out->sample_rate; |
| 145 | is_valid_transmission_rate = true; |
| 146 | break; |
| 147 | } |
| 148 | } |
| 149 | /* DTS transmission channels should be 2 or 8*/ |
| 150 | if ((dtshd_tr_info.num_channels == 2) || |
| 151 | (dtshd_tr_info.num_channels == 8)) { |
| 152 | out->compr_config.codec->ch_in = dtshd_tr_info.num_channels; |
| 153 | out->channel_mask = audio_channel_out_mask_from_count |
| 154 | (dtshd_tr_info.num_channels); |
| 155 | is_valid_transmission_channels = true; |
| 156 | } |
| 157 | } else { |
| 158 | ALOGE("%s:: get_iec61937_info failed %d", __func__, ret); |
| 159 | } |
| 160 | |
| 161 | if (!is_valid_transmission_rate) { |
Harsh Bansal | 0ab6b18 | 2017-08-14 11:49:43 +0530 | [diff] [blame] | 162 | ALOGE("%s:: Invalid dts transmission rate %d\n using default sample rate 48000", |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 163 | dtshd_tr_info.sample_rate); |
Harsh Bansal | 0ab6b18 | 2017-08-14 11:49:43 +0530 | [diff] [blame] | 164 | out->sample_rate = 48000; |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 165 | out->compr_config.codec->sample_rate = out->sample_rate; |
| 166 | } |
| 167 | |
| 168 | if (!is_valid_transmission_channels) { |
| 169 | ALOGE("%s:: Invalid transmission channels %d using default transmission" |
| 170 | " channels as 2", __func__, dtshd_tr_info.num_channels); |
| 171 | out->compr_config.codec->ch_in = 2; |
| 172 | out->channel_mask = audio_channel_out_mask_from_count(2); |
| 173 | } |
Manish Dewangan | 671a420 | 2017-08-18 17:30:46 +0530 | [diff] [blame] | 174 | return 0; |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 175 | } |
| 176 | #else |
Manish Dewangan | 671a420 | 2017-08-18 17:30:46 +0530 | [diff] [blame] | 177 | int audio_extn_passthru_update_dts_stream_configuration( |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 178 | struct stream_out *out __unused, |
| 179 | const void *buffer __unused, |
| 180 | size_t bytes __unused) |
| 181 | { |
Manish Dewangan | 671a420 | 2017-08-18 17:30:46 +0530 | [diff] [blame] | 182 | return -ENOSYS; |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 183 | } |
| 184 | #endif |
| 185 | |
| 186 | int audio_extn_passthru_get_channel_count(struct stream_out *out) |
| 187 | { |
| 188 | int channel_count = DEFAULT_HDMI_OUT_CHANNELS; |
| 189 | |
| 190 | if (!out) { |
| 191 | ALOGE("%s:: Invalid param out %p", __func__, out); |
| 192 | return -EINVAL; |
| 193 | } |
| 194 | |
| 195 | if (!audio_extn_passthru_is_supported_format(out->format)) { |
| 196 | ALOGE("%s:: not a passthrough format %d", __func__, out->format); |
| 197 | return -EINVAL; |
| 198 | } |
| 199 | |
| 200 | switch(out->format) { |
| 201 | case AUDIO_FORMAT_DOLBY_TRUEHD: |
| 202 | channel_count = 8; |
| 203 | break; |
| 204 | case AUDIO_FORMAT_DTS: |
| 205 | case AUDIO_FORMAT_DTS_HD: |
| 206 | #ifdef DTSHD_PARSER_ENABLED |
| 207 | /* taken channel count from parser*/ |
| 208 | channel_count = audio_channel_count_from_out_mask(out->channel_mask); |
| 209 | #endif |
| 210 | break; |
Harsh Bansal | 14d4726 | 2018-01-31 13:32:37 +0530 | [diff] [blame] | 211 | case AUDIO_FORMAT_IEC61937: |
| 212 | channel_count = audio_channel_count_from_out_mask(out->channel_mask); |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 213 | default: |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | ALOGE("%s: pass through channel count %d\n", __func__, channel_count); |
| 218 | return channel_count; |
| 219 | } |
| 220 | |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 221 | bool audio_extn_passthru_is_supported_format(audio_format_t format) |
| 222 | { |
| 223 | int32_t num_passthru_formats = sizeof(audio_passthru_formats) / |
| 224 | sizeof(audio_passthru_formats[0]); |
| 225 | int32_t i; |
| 226 | |
| 227 | for (i = 0; i < num_passthru_formats; i++) { |
| 228 | if (format == audio_passthru_formats[i]) { |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 229 | ALOGD("%s : pass through format is true", __func__); |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 230 | return true; |
| 231 | } |
| 232 | } |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 233 | ALOGD("%s : pass through format is false", __func__); |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 234 | return false; |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * must be called with stream lock held |
| 239 | * This function decides based on some rules whether the data |
| 240 | * coming on stream out must be rendered or dropped. |
| 241 | */ |
| 242 | bool audio_extn_passthru_should_drop_data(struct stream_out * out) |
| 243 | { |
Ashish Jain | d84fd6a | 2016-07-27 12:33:25 +0530 | [diff] [blame] | 244 | /*Drop data only |
| 245 | *stream is routed to HDMI and |
| 246 | *stream has PCM format or |
| 247 | *if a compress offload (DSP decode) session |
| 248 | */ |
| 249 | if ((out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) && |
| 250 | (((out->format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) || |
| 251 | ((out->compr_config.codec != NULL) && (out->compr_config.codec->compr_passthr == LEGACY_PCM)))) { |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 252 | if (android_atomic_acquire_load(&compress_passthru_active) > 0) { |
| 253 | ALOGI("drop data as pass thru is active"); |
| 254 | return true; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return false; |
| 259 | } |
| 260 | |
| 261 | /* called with adev lock held */ |
| 262 | void audio_extn_passthru_on_start(struct stream_out * out) |
| 263 | { |
| 264 | |
| 265 | uint64_t max_period_us = 0; |
| 266 | uint64_t temp; |
| 267 | struct audio_usecase * usecase; |
| 268 | struct listnode *node; |
| 269 | struct stream_out * o; |
| 270 | struct audio_device *adev = out->dev; |
| 271 | |
| 272 | if (android_atomic_acquire_load(&compress_passthru_active) > 0) { |
| 273 | ALOGI("pass thru is already active"); |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | ALOGV("inc pass thru count to notify other streams"); |
| 278 | android_atomic_inc(&compress_passthru_active); |
| 279 | |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 280 | while (true) { |
| 281 | /* find max period time among active playback use cases */ |
| 282 | list_for_each(node, &adev->usecase_list) { |
| 283 | usecase = node_to_item(node, struct audio_usecase, list); |
| 284 | if (usecase->type == PCM_PLAYBACK && |
| 285 | usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 286 | o = usecase->stream.out; |
| 287 | temp = o->config.period_size * 1000000LL / o->sample_rate; |
| 288 | if (temp > max_period_us) |
| 289 | max_period_us = temp; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | if (max_period_us) { |
| 294 | pthread_mutex_unlock(&adev->lock); |
| 295 | usleep(2*max_period_us); |
| 296 | max_period_us = 0; |
| 297 | pthread_mutex_lock(&adev->lock); |
| 298 | } else |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /* called with adev lock held */ |
| 304 | void audio_extn_passthru_on_stop(struct stream_out * out) |
| 305 | { |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 306 | if (android_atomic_acquire_load(&compress_passthru_active) > 0) { |
| 307 | /* |
| 308 | * its possible the count is already zero if pause was called before |
| 309 | * stop output stream |
| 310 | */ |
| 311 | android_atomic_dec(&compress_passthru_active); |
| 312 | } |
| 313 | |
| 314 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
Md Mansoor Ahmed | db1b4f9 | 2018-01-25 18:56:31 +0530 | [diff] [blame] | 315 | ALOGD("%s: passthru on aux digital, start keep alive", __func__); |
| 316 | audio_extn_keep_alive_start(KEEP_ALIVE_OUT_HDMI); |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | void audio_extn_passthru_on_pause(struct stream_out * out __unused) |
| 321 | { |
| 322 | if (android_atomic_acquire_load(&compress_passthru_active) == 0) |
| 323 | return; |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | int audio_extn_passthru_set_parameters(struct audio_device *adev __unused, |
Md Mansoor Ahmed | db1b4f9 | 2018-01-25 18:56:31 +0530 | [diff] [blame] | 327 | struct str_parms *parms) |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 328 | { |
Md Mansoor Ahmed | db1b4f9 | 2018-01-25 18:56:31 +0530 | [diff] [blame] | 329 | char value[32]; |
| 330 | int ret; |
| 331 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, sizeof(value)); |
| 332 | if (ret >= 0) { |
| 333 | int val = atoi(value); |
| 334 | if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 335 | if (!audio_extn_passthru_is_active()) { |
| 336 | ALOGV("%s: start keep alive on aux digital", __func__); |
| 337 | audio_extn_keep_alive_start(KEEP_ALIVE_OUT_HDMI); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value, |
| 343 | sizeof(value)); |
| 344 | if (ret >= 0) { |
| 345 | int val = atoi(value); |
| 346 | if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 347 | ALOGV("%s: stop keep_alive on aux digital on device", __func__); |
| 348 | audio_extn_keep_alive_stop(KEEP_ALIVE_OUT_HDMI); |
| 349 | } |
| 350 | } |
Mingming Yin | 2185465 | 2016-04-13 11:54:02 -0700 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | bool audio_extn_passthru_is_active() |
| 355 | { |
| 356 | return android_atomic_acquire_load(&compress_passthru_active) > 0; |
| 357 | } |
| 358 | |
| 359 | bool audio_extn_passthru_is_enabled() { return true; } |
| 360 | |
| 361 | void audio_extn_passthru_init(struct audio_device *adev __unused) |
| 362 | { |
| 363 | } |
| 364 | |
| 365 | bool audio_extn_passthru_should_standby(struct stream_out * out __unused) |
| 366 | { |
| 367 | return true; |
| 368 | } |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 369 | |
| 370 | bool audio_extn_passthru_is_convert_supported(struct audio_device *adev, |
| 371 | struct stream_out *out) |
| 372 | { |
| 373 | |
| 374 | bool convert = false; |
| 375 | switch (out->format) { |
| 376 | case AUDIO_FORMAT_E_AC3: |
| 377 | case AUDIO_FORMAT_E_AC3_JOC: |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 378 | if (!platform_is_edid_supported_format(adev->platform, |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 379 | out->format)) { |
| 380 | if (platform_is_edid_supported_format(adev->platform, |
| 381 | AUDIO_FORMAT_AC3)) { |
| 382 | ALOGD("%s:PASSTHROUGH_CONVERT supported", __func__); |
| 383 | convert = true; |
| 384 | } |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 385 | } |
| 386 | break; |
| 387 | default: |
| 388 | ALOGD("%s: PASSTHROUGH_CONVERT not supported for format 0x%x", |
| 389 | __func__, out->format); |
| 390 | break; |
| 391 | } |
| 392 | ALOGD("%s: convert %d", __func__, convert); |
| 393 | return convert; |
| 394 | } |
| 395 | |
| 396 | bool audio_extn_passthru_is_passt_supported(struct audio_device *adev, |
| 397 | struct stream_out *out) |
| 398 | { |
| 399 | bool passt = false; |
| 400 | switch (out->format) { |
| 401 | case AUDIO_FORMAT_E_AC3: |
Ben Romberger | 1aaaf86 | 2017-04-06 17:49:46 -0700 | [diff] [blame] | 402 | case AUDIO_FORMAT_DTS_HD: |
| 403 | case AUDIO_FORMAT_DOLBY_TRUEHD: |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 404 | if (platform_is_edid_supported_format(adev->platform, out->format)) { |
| 405 | ALOGV("%s:PASSTHROUGH supported for format %x", |
| 406 | __func__, out->format); |
| 407 | passt = true; |
| 408 | } |
| 409 | break; |
| 410 | case AUDIO_FORMAT_AC3: |
| 411 | if (platform_is_edid_supported_format(adev->platform, AUDIO_FORMAT_AC3) |
| 412 | || platform_is_edid_supported_format(adev->platform, |
| 413 | AUDIO_FORMAT_E_AC3)) { |
| 414 | ALOGV("%s:PASSTHROUGH supported for format %x", |
| 415 | __func__, out->format); |
| 416 | passt = true; |
| 417 | } |
| 418 | break; |
| 419 | case AUDIO_FORMAT_E_AC3_JOC: |
| 420 | /* Check for DDP capability in edid for JOC contents.*/ |
| 421 | if (platform_is_edid_supported_format(adev->platform, |
| 422 | AUDIO_FORMAT_E_AC3)) { |
| 423 | ALOGV("%s:PASSTHROUGH supported for format %x", |
| 424 | __func__, out->format); |
| 425 | passt = true; |
| 426 | } |
| 427 | break; |
| 428 | case AUDIO_FORMAT_DTS: |
| 429 | if (platform_is_edid_supported_format(adev->platform, AUDIO_FORMAT_DTS) |
| 430 | || platform_is_edid_supported_format(adev->platform, |
| 431 | AUDIO_FORMAT_DTS_HD)) { |
| 432 | ALOGV("%s:PASSTHROUGH supported for format %x", |
| 433 | __func__, out->format); |
| 434 | passt = true; |
| 435 | } |
| 436 | break; |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 437 | default: |
| 438 | ALOGV("%s:Passthrough not supported", __func__); |
| 439 | } |
| 440 | return passt; |
| 441 | } |
| 442 | |
| 443 | void audio_extn_passthru_update_stream_configuration( |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 444 | struct audio_device *adev, struct stream_out *out, |
Garmond Leung | 317cbf1 | 2017-09-13 16:20:50 -0700 | [diff] [blame] | 445 | const void *buffer __unused, size_t bytes __unused) |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 446 | { |
Naresh Tanniru | ccd9f38 | 2018-01-17 16:02:19 +0530 | [diff] [blame] | 447 | if(out->compr_config.codec != NULL) { |
| 448 | if (audio_extn_passthru_is_passt_supported(adev, out)) { |
| 449 | ALOGV("%s:PASSTHROUGH", __func__); |
| 450 | out->compr_config.codec->compr_passthr = PASSTHROUGH; |
| 451 | } else if (audio_extn_passthru_is_convert_supported(adev, out)) { |
| 452 | ALOGV("%s:PASSTHROUGH CONVERT", __func__); |
| 453 | out->compr_config.codec->compr_passthr = PASSTHROUGH_CONVERT; |
| 454 | } else if (out->format == AUDIO_FORMAT_IEC61937) { |
| 455 | ALOGV("%s:PASSTHROUGH IEC61937", __func__); |
| 456 | out->compr_config.codec->compr_passthr = PASSTHROUGH_IEC61937; |
| 457 | } else { |
| 458 | ALOGV("%s:NO PASSTHROUGH", __func__); |
| 459 | out->compr_config.codec->compr_passthr = LEGACY_PCM; |
| 460 | } |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
| 464 | bool audio_extn_passthru_is_passthrough_stream(struct stream_out *out) |
| 465 | { |
| 466 | //check passthrough system property |
Aniket Kumar Lata | 8fc67e6 | 2017-05-02 12:33:46 -0700 | [diff] [blame] | 467 | if (!property_get_bool("vendor.audio.offload.passthrough", false)) { |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 468 | return false; |
| 469 | } |
| 470 | |
| 471 | //check supported device, currently only on HDMI. |
| 472 | if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) { |
| 473 | //passthrough flag |
| 474 | if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH) |
| 475 | return true; |
| 476 | //direct flag, check supported formats. |
| 477 | if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT) { |
| 478 | if (audio_extn_passthru_is_supported_format(out->format)) { |
| 479 | if (platform_is_edid_supported_format(out->dev->platform, |
| 480 | out->format)) { |
| 481 | ALOGV("%s : return true",__func__); |
| 482 | return true; |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 483 | } else if (audio_extn_utils_is_dolby_format(out->format) && |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 484 | platform_is_edid_supported_format(out->dev->platform, |
| 485 | AUDIO_FORMAT_AC3)){ |
| 486 | //return true for EAC3/EAC3_JOC formats |
| 487 | //if sink supports only AC3 |
| 488 | ALOGV("%s : return true",__func__); |
| 489 | return true; |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | ALOGV("%s : return false",__func__); |
| 495 | return false; |
| 496 | } |
| 497 | |
Manish Dewangan | 672001f | 2017-08-16 13:44:07 +0530 | [diff] [blame] | 498 | bool audio_extn_passthru_is_direct_passthrough(struct stream_out *out) |
| 499 | { |
| 500 | if (((out != NULL) && audio_extn_passthru_is_passthrough_stream(out)) && |
| 501 | !audio_extn_passthru_is_convert_supported(out->dev, out)) |
| 502 | return true; |
| 503 | else |
| 504 | return false; |
| 505 | } |
| 506 | |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 507 | int audio_extn_passthru_get_buffer_size(audio_offload_info_t* info) |
| 508 | { |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 509 | uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE; |
| 510 | char value[PROPERTY_VALUE_MAX] = {0}; |
| 511 | |
| 512 | if (((info->format == AUDIO_FORMAT_DOLBY_TRUEHD) || |
| 513 | (info->format == AUDIO_FORMAT_IEC61937)) && |
Satish Babu Patakokila | 37e7c48 | 2018-02-02 11:50:06 +0530 | [diff] [blame] | 514 | property_get("vendor.audio.truehd.buffer.size.kb", value, "") && |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 515 | atoi(value)) { |
| 516 | fragment_size = atoi(value) * 1024; |
| 517 | goto done; |
| 518 | } else if ((info->format == AUDIO_FORMAT_DTS) || |
| 519 | (info->format == AUDIO_FORMAT_DTS_HD)) { |
| 520 | fragment_size = MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE; |
| 521 | goto done; |
Harsh Bansal | c83207c | 2017-09-01 16:04:36 +0530 | [diff] [blame] | 522 | } else if (info->format == AUDIO_FORMAT_E_AC3) { |
| 523 | fragment_size = DDP_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE; |
Satish Babu Patakokila | 37e7c48 | 2018-02-02 11:50:06 +0530 | [diff] [blame] | 524 | if(property_get("vendor.audio.ddp.buffer.size.kb", value, "") && |
Harsh Bansal | c83207c | 2017-09-01 16:04:36 +0530 | [diff] [blame] | 525 | atoi(value)) { |
| 526 | fragment_size = atoi(value) * 1024; |
| 527 | } |
| 528 | goto done; |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 529 | } |
Manish Dewangan | 37864bc | 2017-06-09 12:28:37 +0530 | [diff] [blame] | 530 | done: |
| 531 | return fragment_size; |
| 532 | |
Satish Babu Patakokila | 1caa1b7 | 2016-05-24 13:47:08 +0530 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | int audio_extn_passthru_set_volume(struct stream_out *out, int mute) |
| 536 | { |
| 537 | return platform_set_device_params(out, DEVICE_PARAM_MUTE_ID, mute); |
| 538 | } |
| 539 | |
| 540 | int audio_extn_passthru_set_latency(struct stream_out *out, int latency) |
| 541 | { |
| 542 | return platform_set_device_params(out, DEVICE_PARAM_LATENCY_ID, latency); |
| 543 | } |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 544 | |
| 545 | bool audio_extn_passthru_is_supported_backend_edid_cfg(struct audio_device *adev, |
| 546 | struct stream_out *out) |
| 547 | { |
| 548 | struct audio_backend_cfg backend_cfg; |
mpang | 787a6aa | 2018-11-29 11:25:58 +0800 | [diff] [blame] | 549 | backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE; |
| 550 | backend_cfg.channels = CODEC_BACKEND_DEFAULT_CHANNELS; |
| 551 | backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH; |
| 552 | backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 553 | backend_cfg.passthrough_enabled = false; |
| 554 | |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 555 | snd_device_t out_snd_device = SND_DEVICE_NONE; |
| 556 | int max_edid_channels = platform_edid_get_max_channels(out->dev->platform); |
| 557 | |
| 558 | out_snd_device = platform_get_output_snd_device(adev->platform, out); |
| 559 | |
| 560 | if (platform_get_codec_backend_cfg(adev, out_snd_device, &backend_cfg)) { |
| 561 | ALOGE("%s: ERROR: Unable to get current backend config!!!", __func__); |
| 562 | return false; |
| 563 | } |
| 564 | |
| 565 | ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d" |
| 566 | ", device (%s)", __func__, backend_cfg.bit_width, |
| 567 | backend_cfg.sample_rate, backend_cfg.channels, backend_cfg.format, |
| 568 | platform_get_snd_device_name(out_snd_device)); |
| 569 | |
| 570 | /* Check if the channels are supported */ |
Garmond Leung | 438932f | 2017-10-04 19:35:18 -0700 | [diff] [blame] | 571 | if (max_edid_channels < (int)backend_cfg.channels) { |
Satish Babu Patakokila | 5933e97 | 2017-08-24 12:22:08 +0530 | [diff] [blame] | 572 | |
| 573 | ALOGE("%s: ERROR: Unsupported channels in passthru mode!!!" |
| 574 | " max_edid_channels - %d backend_channels - %d", |
| 575 | __func__, max_edid_channels, backend_cfg.channels); |
| 576 | return false; |
| 577 | } |
| 578 | |
| 579 | /* Check if the sample rate supported */ |
| 580 | if (!platform_is_edid_supported_sample_rate(adev->platform, |
| 581 | backend_cfg.sample_rate)) { |
| 582 | |
| 583 | ALOGE("%s: ERROR: Unsupported sample rate in passthru mode!!!" |
| 584 | " backend_samplerate - %d", |
| 585 | __func__, backend_cfg.sample_rate); |
| 586 | return false; |
| 587 | } |
| 588 | |
| 589 | return true; |
| 590 | } |