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