blob: f30e0440d0a2dd98567cd3a6094a88571f16fe93 [file] [log] [blame]
Mingming Yin21854652016-04-13 11:54:02 -07001/*
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +05302* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
Mingming Yin21854652016-04-13 11:54:02 -07003*
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 Patakokila1caa1b72016-05-24 13:47:08 +053040#include <cutils/properties.h>
41
42#include "sound/compress_params.h"
Manish Dewangan37864bc2017-06-09 12:28:37 +053043
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053044#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 Dewangan37864bc2017-06-09 12:28:37 +053049/*
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 */
57static 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 Yin21854652016-04-13 11:54:02 -070071
Harsh Bansalc83207c2017-09-01 16:04:36 +053072#define DDP_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (10 * 1024)
73
Mingming Yin21854652016-04-13 11:54:02 -070074static const audio_format_t audio_passthru_formats[] = {
75 AUDIO_FORMAT_AC3,
76 AUDIO_FORMAT_E_AC3,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +053077 AUDIO_FORMAT_E_AC3_JOC,
Mingming Yin21854652016-04-13 11:54:02 -070078 AUDIO_FORMAT_DTS,
Ben Romberger1aaaf862017-04-06 17:49:46 -070079 AUDIO_FORMAT_DTS_HD,
Naresh Tanniru928f0862017-04-07 16:44:23 -070080 AUDIO_FORMAT_DOLBY_TRUEHD,
81 AUDIO_FORMAT_IEC61937
Mingming Yin21854652016-04-13 11:54:02 -070082};
83
84/*
85 * This atomic var is incremented/decremented by the offload stream to notify
86 * other pcm playback streams that a pass thru session is about to start or has
87 * finished. This hint can be used by the other streams to move to standby or
88 * start calling pcm_write respectively.
89 * This behavior is necessary as the DSP backend can only be configured to one
90 * of PCM or compressed.
91 */
92static volatile int32_t compress_passthru_active;
93
Manish Dewangan37864bc2017-06-09 12:28:37 +053094#ifdef DTSHD_PARSER_ENABLED
Manish Dewangan671a4202017-08-18 17:30:46 +053095int audio_extn_passthru_update_dts_stream_configuration(struct stream_out *out,
Manish Dewangan37864bc2017-06-09 12:28:37 +053096 const void *buffer, size_t bytes)
97{
98 struct audio_parser_codec_info codec_info;
99 struct dtshd_iec61937_info dtshd_tr_info;
100 int i;
101 int ret;
102 bool is_valid_transmission_rate = false;
103 bool is_valid_transmission_channels = false;
104
Manish Dewangan671a4202017-08-18 17:30:46 +0530105 if (!out) {
106 ALOGE("Invalid session");
107 return -EINVAL;
108 }
109
110 if ((out->format != AUDIO_FORMAT_DTS) &&
111 (out->format != AUDIO_FORMAT_DTS_HD)) {
112 ALOGE("Non DTS format %d", out->format);
113 return -EINVAL;
114 }
115
116 if (!buffer || bytes <= 0) {
117 ALOGD("Invalid buffer %p size %d skipping dts stream conf update",
118 buffer, bytes);
119 out->sample_rate = 48000;
120 out->compr_config.codec->sample_rate = out->sample_rate;
121 out->compr_config.codec->ch_in = 2;
122 out->channel_mask = audio_channel_out_mask_from_count(2);
123 return -EINVAL;
124 }
125
Manish Dewangan37864bc2017-06-09 12:28:37 +0530126 /* codec format is AUDIO_PARSER_CODEC_DTSHD for both DTS and DTSHD as
127 * DTSHD parser can support both DTS and DTSHD
128 */
129 memset(&codec_info, 0, sizeof(struct audio_parser_codec_info));
130 memset(&dtshd_tr_info, 0, sizeof(struct dtshd_iec61937_info));
131
132 init_audio_parser((unsigned char *)buffer, bytes, AUDIO_PARSER_CODEC_DTSHD);
133 codec_info.codec_type = AUDIO_PARSER_CODEC_DTSHD;
134 if (!(ret = get_iec61937_info(&codec_info))) {
135 dtshd_tr_info = codec_info.codec_config.dtshd_tr_info;
136 ALOGD("dts new sample rate %d and channels %d\n",
137 dtshd_tr_info.sample_rate,
138 dtshd_tr_info.num_channels);
139 for (i = 0; i < sizeof(dts_transmission_sample_rates); i++) {
140 if (dts_transmission_sample_rates[i] ==
141 dtshd_tr_info.sample_rate) {
142 out->sample_rate = dtshd_tr_info.sample_rate;
143 out->compr_config.codec->sample_rate = out->sample_rate;
144 is_valid_transmission_rate = true;
145 break;
146 }
147 }
148 /* DTS transmission channels should be 2 or 8*/
149 if ((dtshd_tr_info.num_channels == 2) ||
150 (dtshd_tr_info.num_channels == 8)) {
151 out->compr_config.codec->ch_in = dtshd_tr_info.num_channels;
152 out->channel_mask = audio_channel_out_mask_from_count
153 (dtshd_tr_info.num_channels);
154 is_valid_transmission_channels = true;
155 }
156 } else {
157 ALOGE("%s:: get_iec61937_info failed %d", __func__, ret);
158 }
159
160 if (!is_valid_transmission_rate) {
Harsh Bansal0ab6b182017-08-14 11:49:43 +0530161 ALOGE("%s:: Invalid dts transmission rate %d\n using default sample rate 48000",
Manish Dewangan37864bc2017-06-09 12:28:37 +0530162 dtshd_tr_info.sample_rate);
Harsh Bansal0ab6b182017-08-14 11:49:43 +0530163 out->sample_rate = 48000;
Manish Dewangan37864bc2017-06-09 12:28:37 +0530164 out->compr_config.codec->sample_rate = out->sample_rate;
165 }
166
167 if (!is_valid_transmission_channels) {
168 ALOGE("%s:: Invalid transmission channels %d using default transmission"
169 " channels as 2", __func__, dtshd_tr_info.num_channels);
170 out->compr_config.codec->ch_in = 2;
171 out->channel_mask = audio_channel_out_mask_from_count(2);
172 }
Manish Dewangan671a4202017-08-18 17:30:46 +0530173 return 0;
Manish Dewangan37864bc2017-06-09 12:28:37 +0530174}
175#else
Manish Dewangan671a4202017-08-18 17:30:46 +0530176int audio_extn_passthru_update_dts_stream_configuration(
Manish Dewangan37864bc2017-06-09 12:28:37 +0530177 struct stream_out *out __unused,
178 const void *buffer __unused,
179 size_t bytes __unused)
180{
Manish Dewangan671a4202017-08-18 17:30:46 +0530181 return -ENOSYS;
Manish Dewangan37864bc2017-06-09 12:28:37 +0530182}
183#endif
184
185int audio_extn_passthru_get_channel_count(struct stream_out *out)
186{
187 int channel_count = DEFAULT_HDMI_OUT_CHANNELS;
188
189 if (!out) {
190 ALOGE("%s:: Invalid param out %p", __func__, out);
191 return -EINVAL;
192 }
193
194 if (!audio_extn_passthru_is_supported_format(out->format)) {
195 ALOGE("%s:: not a passthrough format %d", __func__, out->format);
196 return -EINVAL;
197 }
198
199 switch(out->format) {
200 case AUDIO_FORMAT_DOLBY_TRUEHD:
201 channel_count = 8;
202 break;
203 case AUDIO_FORMAT_DTS:
204 case AUDIO_FORMAT_DTS_HD:
205#ifdef DTSHD_PARSER_ENABLED
206 /* taken channel count from parser*/
207 channel_count = audio_channel_count_from_out_mask(out->channel_mask);
208#endif
209 break;
Harsh Bansal14d47262018-01-31 13:32:37 +0530210 case AUDIO_FORMAT_IEC61937:
211 channel_count = audio_channel_count_from_out_mask(out->channel_mask);
Manish Dewangan37864bc2017-06-09 12:28:37 +0530212 default:
213 break;
214 }
215
216 ALOGE("%s: pass through channel count %d\n", __func__, channel_count);
217 return channel_count;
218}
219
Mingming Yin21854652016-04-13 11:54:02 -0700220bool audio_extn_passthru_is_supported_format(audio_format_t format)
221{
222 int32_t num_passthru_formats = sizeof(audio_passthru_formats) /
223 sizeof(audio_passthru_formats[0]);
224 int32_t i;
225
226 for (i = 0; i < num_passthru_formats; i++) {
227 if (format == audio_passthru_formats[i]) {
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530228 ALOGD("%s : pass through format is true", __func__);
Mingming Yin21854652016-04-13 11:54:02 -0700229 return true;
230 }
231 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530232 ALOGD("%s : pass through format is false", __func__);
Mingming Yin21854652016-04-13 11:54:02 -0700233 return false;
234}
235
236/*
237 * must be called with stream lock held
238 * This function decides based on some rules whether the data
239 * coming on stream out must be rendered or dropped.
240 */
241bool audio_extn_passthru_should_drop_data(struct stream_out * out)
242{
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530243 /*Drop data only
244 *stream is routed to HDMI and
245 *stream has PCM format or
246 *if a compress offload (DSP decode) session
247 */
248 if ((out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
249 (((out->format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) ||
250 ((out->compr_config.codec != NULL) && (out->compr_config.codec->compr_passthr == LEGACY_PCM)))) {
Mingming Yin21854652016-04-13 11:54:02 -0700251 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
252 ALOGI("drop data as pass thru is active");
253 return true;
254 }
255 }
256
257 return false;
258}
259
260/* called with adev lock held */
261void audio_extn_passthru_on_start(struct stream_out * out)
262{
263
264 uint64_t max_period_us = 0;
265 uint64_t temp;
266 struct audio_usecase * usecase;
267 struct listnode *node;
268 struct stream_out * o;
269 struct audio_device *adev = out->dev;
270
271 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
272 ALOGI("pass thru is already active");
273 return;
274 }
275
276 ALOGV("inc pass thru count to notify other streams");
277 android_atomic_inc(&compress_passthru_active);
278
Mingming Yin21854652016-04-13 11:54:02 -0700279 while (true) {
280 /* find max period time among active playback use cases */
281 list_for_each(node, &adev->usecase_list) {
282 usecase = node_to_item(node, struct audio_usecase, list);
283 if (usecase->type == PCM_PLAYBACK &&
284 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
285 o = usecase->stream.out;
286 temp = o->config.period_size * 1000000LL / o->sample_rate;
287 if (temp > max_period_us)
288 max_period_us = temp;
289 }
290 }
291
292 if (max_period_us) {
293 pthread_mutex_unlock(&adev->lock);
294 usleep(2*max_period_us);
295 max_period_us = 0;
296 pthread_mutex_lock(&adev->lock);
297 } else
298 break;
299 }
300}
301
302/* called with adev lock held */
303void audio_extn_passthru_on_stop(struct stream_out * out)
304{
Mingming Yin21854652016-04-13 11:54:02 -0700305 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
306 /*
307 * its possible the count is already zero if pause was called before
308 * stop output stream
309 */
310 android_atomic_dec(&compress_passthru_active);
311 }
312
313 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530314 ALOGD("%s: passthru on aux digital, start keep alive", __func__);
315 audio_extn_keep_alive_start(KEEP_ALIVE_OUT_HDMI);
Mingming Yin21854652016-04-13 11:54:02 -0700316 }
317}
318
319void audio_extn_passthru_on_pause(struct stream_out * out __unused)
320{
321 if (android_atomic_acquire_load(&compress_passthru_active) == 0)
322 return;
Mingming Yin21854652016-04-13 11:54:02 -0700323}
324
325int audio_extn_passthru_set_parameters(struct audio_device *adev __unused,
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530326 struct str_parms *parms)
Mingming Yin21854652016-04-13 11:54:02 -0700327{
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530328 char value[32];
329 int ret;
330 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, sizeof(value));
331 if (ret >= 0) {
332 int val = atoi(value);
333 if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
334 if (!audio_extn_passthru_is_active()) {
335 ALOGV("%s: start keep alive on aux digital", __func__);
336 audio_extn_keep_alive_start(KEEP_ALIVE_OUT_HDMI);
337 }
338 }
339 }
340
341 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value,
342 sizeof(value));
343 if (ret >= 0) {
344 int val = atoi(value);
345 if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
346 ALOGV("%s: stop keep_alive on aux digital on device", __func__);
347 audio_extn_keep_alive_stop(KEEP_ALIVE_OUT_HDMI);
348 }
349 }
Mingming Yin21854652016-04-13 11:54:02 -0700350 return 0;
351}
352
353bool audio_extn_passthru_is_active()
354{
355 return android_atomic_acquire_load(&compress_passthru_active) > 0;
356}
357
358bool audio_extn_passthru_is_enabled() { return true; }
359
360void audio_extn_passthru_init(struct audio_device *adev __unused)
361{
362}
363
364bool audio_extn_passthru_should_standby(struct stream_out * out __unused)
365{
366 return true;
367}
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530368
369bool audio_extn_passthru_is_convert_supported(struct audio_device *adev,
370 struct stream_out *out)
371{
372
373 bool convert = false;
374 switch (out->format) {
375 case AUDIO_FORMAT_E_AC3:
376 case AUDIO_FORMAT_E_AC3_JOC:
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530377 if (!platform_is_edid_supported_format(adev->platform,
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530378 out->format)) {
379 if (platform_is_edid_supported_format(adev->platform,
380 AUDIO_FORMAT_AC3)) {
381 ALOGD("%s:PASSTHROUGH_CONVERT supported", __func__);
382 convert = true;
383 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530384 }
385 break;
386 default:
387 ALOGD("%s: PASSTHROUGH_CONVERT not supported for format 0x%x",
388 __func__, out->format);
389 break;
390 }
391 ALOGD("%s: convert %d", __func__, convert);
392 return convert;
393}
394
395bool audio_extn_passthru_is_passt_supported(struct audio_device *adev,
396 struct stream_out *out)
397{
398 bool passt = false;
399 switch (out->format) {
400 case AUDIO_FORMAT_E_AC3:
Ben Romberger1aaaf862017-04-06 17:49:46 -0700401 case AUDIO_FORMAT_DTS_HD:
402 case AUDIO_FORMAT_DOLBY_TRUEHD:
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530403 if (platform_is_edid_supported_format(adev->platform, out->format)) {
404 ALOGV("%s:PASSTHROUGH supported for format %x",
405 __func__, out->format);
406 passt = true;
407 }
408 break;
409 case AUDIO_FORMAT_AC3:
410 if (platform_is_edid_supported_format(adev->platform, AUDIO_FORMAT_AC3)
411 || platform_is_edid_supported_format(adev->platform,
412 AUDIO_FORMAT_E_AC3)) {
413 ALOGV("%s:PASSTHROUGH supported for format %x",
414 __func__, out->format);
415 passt = true;
416 }
417 break;
418 case AUDIO_FORMAT_E_AC3_JOC:
419 /* Check for DDP capability in edid for JOC contents.*/
420 if (platform_is_edid_supported_format(adev->platform,
421 AUDIO_FORMAT_E_AC3)) {
422 ALOGV("%s:PASSTHROUGH supported for format %x",
423 __func__, out->format);
424 passt = true;
425 }
426 break;
427 case AUDIO_FORMAT_DTS:
428 if (platform_is_edid_supported_format(adev->platform, AUDIO_FORMAT_DTS)
429 || platform_is_edid_supported_format(adev->platform,
430 AUDIO_FORMAT_DTS_HD)) {
431 ALOGV("%s:PASSTHROUGH supported for format %x",
432 __func__, out->format);
433 passt = true;
434 }
435 break;
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530436 default:
437 ALOGV("%s:Passthrough not supported", __func__);
438 }
439 return passt;
440}
441
442void audio_extn_passthru_update_stream_configuration(
Manish Dewangan37864bc2017-06-09 12:28:37 +0530443 struct audio_device *adev, struct stream_out *out,
Garmond Leung317cbf12017-09-13 16:20:50 -0700444 const void *buffer __unused, size_t bytes __unused)
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530445{
Naresh Tanniruccd9f382018-01-17 16:02:19 +0530446 if(out->compr_config.codec != NULL) {
447 if (audio_extn_passthru_is_passt_supported(adev, out)) {
448 ALOGV("%s:PASSTHROUGH", __func__);
449 out->compr_config.codec->compr_passthr = PASSTHROUGH;
450 } else if (audio_extn_passthru_is_convert_supported(adev, out)) {
451 ALOGV("%s:PASSTHROUGH CONVERT", __func__);
452 out->compr_config.codec->compr_passthr = PASSTHROUGH_CONVERT;
453 } else if (out->format == AUDIO_FORMAT_IEC61937) {
454 ALOGV("%s:PASSTHROUGH IEC61937", __func__);
455 out->compr_config.codec->compr_passthr = PASSTHROUGH_IEC61937;
456 } else {
457 ALOGV("%s:NO PASSTHROUGH", __func__);
458 out->compr_config.codec->compr_passthr = LEGACY_PCM;
459 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530460 }
461}
462
463bool audio_extn_passthru_is_passthrough_stream(struct stream_out *out)
464{
465 //check passthrough system property
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700466 if (!property_get_bool("vendor.audio.offload.passthrough", false)) {
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530467 return false;
468 }
469
470 //check supported device, currently only on HDMI.
471 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
472 //passthrough flag
473 if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)
474 return true;
475 //direct flag, check supported formats.
476 if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT) {
477 if (audio_extn_passthru_is_supported_format(out->format)) {
478 if (platform_is_edid_supported_format(out->dev->platform,
479 out->format)) {
480 ALOGV("%s : return true",__func__);
481 return true;
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530482 } else if (audio_extn_utils_is_dolby_format(out->format) &&
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530483 platform_is_edid_supported_format(out->dev->platform,
484 AUDIO_FORMAT_AC3)){
485 //return true for EAC3/EAC3_JOC formats
486 //if sink supports only AC3
487 ALOGV("%s : return true",__func__);
488 return true;
489 }
490 }
491 }
492 }
493 ALOGV("%s : return false",__func__);
494 return false;
495}
496
Manish Dewangan672001f2017-08-16 13:44:07 +0530497bool audio_extn_passthru_is_direct_passthrough(struct stream_out *out)
498{
499 if (((out != NULL) && audio_extn_passthru_is_passthrough_stream(out)) &&
500 !audio_extn_passthru_is_convert_supported(out->dev, out))
501 return true;
502 else
503 return false;
504}
505
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530506int audio_extn_passthru_get_buffer_size(audio_offload_info_t* info)
507{
Manish Dewangan37864bc2017-06-09 12:28:37 +0530508 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
509 char value[PROPERTY_VALUE_MAX] = {0};
510
511 if (((info->format == AUDIO_FORMAT_DOLBY_TRUEHD) ||
512 (info->format == AUDIO_FORMAT_IEC61937)) &&
Satish Babu Patakokila37e7c482018-02-02 11:50:06 +0530513 property_get("vendor.audio.truehd.buffer.size.kb", value, "") &&
Manish Dewangan37864bc2017-06-09 12:28:37 +0530514 atoi(value)) {
515 fragment_size = atoi(value) * 1024;
516 goto done;
517 } else if ((info->format == AUDIO_FORMAT_DTS) ||
518 (info->format == AUDIO_FORMAT_DTS_HD)) {
519 fragment_size = MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
520 goto done;
Harsh Bansalc83207c2017-09-01 16:04:36 +0530521 } else if (info->format == AUDIO_FORMAT_E_AC3) {
522 fragment_size = DDP_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
Satish Babu Patakokila37e7c482018-02-02 11:50:06 +0530523 if(property_get("vendor.audio.ddp.buffer.size.kb", value, "") &&
Harsh Bansalc83207c2017-09-01 16:04:36 +0530524 atoi(value)) {
525 fragment_size = atoi(value) * 1024;
526 }
527 goto done;
Manish Dewangan37864bc2017-06-09 12:28:37 +0530528 }
Manish Dewangan37864bc2017-06-09 12:28:37 +0530529done:
530 return fragment_size;
531
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530532}
533
534int audio_extn_passthru_set_volume(struct stream_out *out, int mute)
535{
536 return platform_set_device_params(out, DEVICE_PARAM_MUTE_ID, mute);
537}
538
539int audio_extn_passthru_set_latency(struct stream_out *out, int latency)
540{
541 return platform_set_device_params(out, DEVICE_PARAM_LATENCY_ID, latency);
542}
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530543
544bool audio_extn_passthru_is_supported_backend_edid_cfg(struct audio_device *adev,
545 struct stream_out *out)
546{
547 struct audio_backend_cfg backend_cfg;
548 snd_device_t out_snd_device = SND_DEVICE_NONE;
549 int max_edid_channels = platform_edid_get_max_channels(out->dev->platform);
550
551 out_snd_device = platform_get_output_snd_device(adev->platform, out);
552
553 if (platform_get_codec_backend_cfg(adev, out_snd_device, &backend_cfg)) {
554 ALOGE("%s: ERROR: Unable to get current backend config!!!", __func__);
555 return false;
556 }
557
558 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d"
559 ", device (%s)", __func__, backend_cfg.bit_width,
560 backend_cfg.sample_rate, backend_cfg.channels, backend_cfg.format,
561 platform_get_snd_device_name(out_snd_device));
562
563 /* Check if the channels are supported */
Garmond Leung438932f2017-10-04 19:35:18 -0700564 if (max_edid_channels < (int)backend_cfg.channels) {
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530565
566 ALOGE("%s: ERROR: Unsupported channels in passthru mode!!!"
567 " max_edid_channels - %d backend_channels - %d",
568 __func__, max_edid_channels, backend_cfg.channels);
569 return false;
570 }
571
572 /* Check if the sample rate supported */
573 if (!platform_is_edid_supported_sample_rate(adev->platform,
574 backend_cfg.sample_rate)) {
575
576 ALOGE("%s: ERROR: Unsupported sample rate in passthru mode!!!"
577 " backend_samplerate - %d",
578 __func__, backend_cfg.sample_rate);
579 return false;
580 }
581
582 return true;
583}