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