blob: a59717c061e207f0a5b10139353dbd7f612bc976 [file] [log] [blame]
Mingming Yin21854652016-04-13 11:54:02 -07001/*
Arun Mirpurie008ed22019-03-21 11:21:04 -07002* Copyright (c) 2014-2019, 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>
Weiyin Jiang2995f662019-04-17 14:25:12 +080034#include <cutils/properties.h>
Mingming Yin21854652016-04-13 11:54:02 -070035#include <cutils/str_parms.h>
Weiyin Jiang2995f662019-04-17 14:25:12 +080036#include <log/log.h>
Vinay Vermaaddfa4a2018-04-29 14:03:38 +053037#include <unistd.h>
Arun Mirpurie008ed22019-03-21 11:21:04 -070038#include <pthread.h>
Mingming Yin21854652016-04-13 11:54:02 -070039#include "audio_hw.h"
40#include "audio_extn.h"
41#include "platform_api.h"
42#include <platform.h>
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +053043
44#include "sound/compress_params.h"
Manish Dewangan37864bc2017-06-09 12:28:37 +053045
Revathi Uddaraju1eac8b02017-05-18 17:13:33 +053046#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 Dewangan37864bc2017-06-09 12:28:37 +053051/*
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 */
59static 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 Yin21854652016-04-13 11:54:02 -070073
Harsh Bansalc83207c2017-09-01 16:04:36 +053074#define DDP_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE (10 * 1024)
75
Mingming Yin21854652016-04-13 11:54:02 -070076static const audio_format_t audio_passthru_formats[] = {
77 AUDIO_FORMAT_AC3,
78 AUDIO_FORMAT_E_AC3,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +053079 AUDIO_FORMAT_E_AC3_JOC,
Mingming Yin21854652016-04-13 11:54:02 -070080 AUDIO_FORMAT_DTS,
Ben Romberger1aaaf862017-04-06 17:49:46 -070081 AUDIO_FORMAT_DTS_HD,
Naresh Tanniru928f0862017-04-07 16:44:23 -070082 AUDIO_FORMAT_DOLBY_TRUEHD,
83 AUDIO_FORMAT_IEC61937
Mingming Yin21854652016-04-13 11:54:02 -070084};
85
Arun Mirpurie008ed22019-03-21 11:21:04 -070086//external function depedency
87static fp_platform_is_edid_supported_format_t fp_platform_is_edid_supported_format;
88static fp_platform_set_device_params_t fp_platform_set_device_params;
89static fp_platform_edid_get_max_channels_t fp_platform_edid_get_max_channels;
90static fp_platform_get_output_snd_device_t fp_platform_get_output_snd_device;
91static fp_platform_get_codec_backend_cfg_t fp_platform_get_codec_backend_cfg;
92static fp_platform_get_snd_device_name_t fp_platform_get_snd_device_name;
93static fp_platform_is_edid_supported_sample_rate_t fp_platform_is_edid_supported_sample_rate;
94static fp_audio_extn_keep_alive_start_t fp_audio_extn_keep_alive_start;
95static fp_audio_extn_keep_alive_stop_t fp_audio_extn_keep_alive_stop;
96static fp_audio_extn_utils_is_dolby_format_t fp_audio_extn_utils_is_dolby_format;
97
Mingming Yin21854652016-04-13 11:54:02 -070098/*
99 * This atomic var is incremented/decremented by the offload stream to notify
100 * other pcm playback streams that a pass thru session is about to start or has
101 * finished. This hint can be used by the other streams to move to standby or
102 * start calling pcm_write respectively.
103 * This behavior is necessary as the DSP backend can only be configured to one
104 * of PCM or compressed.
105 */
106static volatile int32_t compress_passthru_active;
107
Arun Mirpurie008ed22019-03-21 11:21:04 -0700108int passthru_update_dts_stream_configuration(struct stream_out *out,
Manish Dewangan37864bc2017-06-09 12:28:37 +0530109 const void *buffer, size_t bytes)
110{
111 struct audio_parser_codec_info codec_info;
112 struct dtshd_iec61937_info dtshd_tr_info;
113 int i;
114 int ret;
115 bool is_valid_transmission_rate = false;
116 bool is_valid_transmission_channels = false;
117
Manish Dewangan671a4202017-08-18 17:30:46 +0530118 if (!out) {
119 ALOGE("Invalid session");
120 return -EINVAL;
121 }
122
123 if ((out->format != AUDIO_FORMAT_DTS) &&
124 (out->format != AUDIO_FORMAT_DTS_HD)) {
125 ALOGE("Non DTS format %d", out->format);
126 return -EINVAL;
127 }
128
129 if (!buffer || bytes <= 0) {
Arun Mirpurie008ed22019-03-21 11:21:04 -0700130 ALOGD("Invalid buffer %p size %lu skipping dts stream conf update",
131 buffer, (unsigned long)bytes);
Manish Dewangan671a4202017-08-18 17:30:46 +0530132 out->sample_rate = 48000;
133 out->compr_config.codec->sample_rate = out->sample_rate;
134 out->compr_config.codec->ch_in = 2;
135 out->channel_mask = audio_channel_out_mask_from_count(2);
136 return -EINVAL;
137 }
138
Manish Dewangan37864bc2017-06-09 12:28:37 +0530139 /* codec format is AUDIO_PARSER_CODEC_DTSHD for both DTS and DTSHD as
140 * DTSHD parser can support both DTS and DTSHD
141 */
142 memset(&codec_info, 0, sizeof(struct audio_parser_codec_info));
143 memset(&dtshd_tr_info, 0, sizeof(struct dtshd_iec61937_info));
144
145 init_audio_parser((unsigned char *)buffer, bytes, AUDIO_PARSER_CODEC_DTSHD);
146 codec_info.codec_type = AUDIO_PARSER_CODEC_DTSHD;
147 if (!(ret = get_iec61937_info(&codec_info))) {
148 dtshd_tr_info = codec_info.codec_config.dtshd_tr_info;
149 ALOGD("dts new sample rate %d and channels %d\n",
150 dtshd_tr_info.sample_rate,
151 dtshd_tr_info.num_channels);
Arun Mirpurie008ed22019-03-21 11:21:04 -0700152 for (i = 0; i < (sizeof(dts_transmission_sample_rates)/sizeof(int)); i++) {
Manish Dewangan37864bc2017-06-09 12:28:37 +0530153 if (dts_transmission_sample_rates[i] ==
154 dtshd_tr_info.sample_rate) {
155 out->sample_rate = dtshd_tr_info.sample_rate;
156 out->compr_config.codec->sample_rate = out->sample_rate;
157 is_valid_transmission_rate = true;
158 break;
159 }
160 }
161 /* DTS transmission channels should be 2 or 8*/
162 if ((dtshd_tr_info.num_channels == 2) ||
163 (dtshd_tr_info.num_channels == 8)) {
164 out->compr_config.codec->ch_in = dtshd_tr_info.num_channels;
165 out->channel_mask = audio_channel_out_mask_from_count
166 (dtshd_tr_info.num_channels);
167 is_valid_transmission_channels = true;
168 }
169 } else {
170 ALOGE("%s:: get_iec61937_info failed %d", __func__, ret);
171 }
172
173 if (!is_valid_transmission_rate) {
Harsh Bansal0ab6b182017-08-14 11:49:43 +0530174 ALOGE("%s:: Invalid dts transmission rate %d\n using default sample rate 48000",
Arun Mirpurie008ed22019-03-21 11:21:04 -0700175 __func__, dtshd_tr_info.sample_rate);
Harsh Bansal0ab6b182017-08-14 11:49:43 +0530176 out->sample_rate = 48000;
Manish Dewangan37864bc2017-06-09 12:28:37 +0530177 out->compr_config.codec->sample_rate = out->sample_rate;
178 }
179
180 if (!is_valid_transmission_channels) {
181 ALOGE("%s:: Invalid transmission channels %d using default transmission"
182 " channels as 2", __func__, dtshd_tr_info.num_channels);
183 out->compr_config.codec->ch_in = 2;
184 out->channel_mask = audio_channel_out_mask_from_count(2);
185 }
Manish Dewangan671a4202017-08-18 17:30:46 +0530186 return 0;
Manish Dewangan37864bc2017-06-09 12:28:37 +0530187}
Manish Dewangan37864bc2017-06-09 12:28:37 +0530188
Arun Mirpurie008ed22019-03-21 11:21:04 -0700189bool passthru_is_supported_format(audio_format_t format)
190{
191 int32_t num_passthru_formats = sizeof(audio_passthru_formats) /
192 sizeof(audio_passthru_formats[0]);
193 int32_t i;
194
195 for (i = 0; i < num_passthru_formats; i++) {
196 if (format == audio_passthru_formats[i]) {
197 ALOGD("%s : pass through format is true", __func__);
198 return true;
199 }
200 }
201 ALOGD("%s : pass through format is false", __func__);
202 return false;
203}
204
205int passthru_get_channel_count(struct stream_out *out)
Manish Dewangan37864bc2017-06-09 12:28:37 +0530206{
207 int channel_count = DEFAULT_HDMI_OUT_CHANNELS;
208
209 if (!out) {
210 ALOGE("%s:: Invalid param out %p", __func__, out);
211 return -EINVAL;
212 }
213
Arun Mirpurie008ed22019-03-21 11:21:04 -0700214 if (!passthru_is_supported_format(out->format)) {
Manish Dewangan37864bc2017-06-09 12:28:37 +0530215 ALOGE("%s:: not a passthrough format %d", __func__, out->format);
216 return -EINVAL;
217 }
218
219 switch(out->format) {
220 case AUDIO_FORMAT_DOLBY_TRUEHD:
221 channel_count = 8;
222 break;
223 case AUDIO_FORMAT_DTS:
224 case AUDIO_FORMAT_DTS_HD:
225#ifdef DTSHD_PARSER_ENABLED
226 /* taken channel count from parser*/
227 channel_count = audio_channel_count_from_out_mask(out->channel_mask);
228#endif
229 break;
Harsh Bansal14d47262018-01-31 13:32:37 +0530230 case AUDIO_FORMAT_IEC61937:
231 channel_count = audio_channel_count_from_out_mask(out->channel_mask);
Manish Dewangan37864bc2017-06-09 12:28:37 +0530232 default:
233 break;
234 }
235
236 ALOGE("%s: pass through channel count %d\n", __func__, channel_count);
237 return channel_count;
238}
239
Mingming Yin21854652016-04-13 11:54:02 -0700240/*
241 * must be called with stream lock held
242 * This function decides based on some rules whether the data
243 * coming on stream out must be rendered or dropped.
244 */
Arun Mirpurie008ed22019-03-21 11:21:04 -0700245bool passthru_should_drop_data(struct stream_out * out)
Mingming Yin21854652016-04-13 11:54:02 -0700246{
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530247 /*Drop data only
248 *stream is routed to HDMI and
249 *stream has PCM format or
250 *if a compress offload (DSP decode) session
251 */
252 if ((out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
253 (((out->format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) ||
254 ((out->compr_config.codec != NULL) && (out->compr_config.codec->compr_passthr == LEGACY_PCM)))) {
Mingming Yin21854652016-04-13 11:54:02 -0700255 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
256 ALOGI("drop data as pass thru is active");
257 return true;
258 }
259 }
260
261 return false;
262}
263
264/* called with adev lock held */
Arun Mirpurie008ed22019-03-21 11:21:04 -0700265void passthru_on_start(struct stream_out * out)
Mingming Yin21854652016-04-13 11:54:02 -0700266{
267
268 uint64_t max_period_us = 0;
269 uint64_t temp;
270 struct audio_usecase * usecase;
271 struct listnode *node;
272 struct stream_out * o;
273 struct audio_device *adev = out->dev;
274
275 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
276 ALOGI("pass thru is already active");
277 return;
278 }
279
280 ALOGV("inc pass thru count to notify other streams");
281 android_atomic_inc(&compress_passthru_active);
282
Mingming Yin21854652016-04-13 11:54:02 -0700283 while (true) {
284 /* find max period time among active playback use cases */
285 list_for_each(node, &adev->usecase_list) {
286 usecase = node_to_item(node, struct audio_usecase, list);
287 if (usecase->type == PCM_PLAYBACK &&
288 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
289 o = usecase->stream.out;
290 temp = o->config.period_size * 1000000LL / o->sample_rate;
291 if (temp > max_period_us)
292 max_period_us = temp;
293 }
294 }
295
296 if (max_period_us) {
297 pthread_mutex_unlock(&adev->lock);
298 usleep(2*max_period_us);
299 max_period_us = 0;
300 pthread_mutex_lock(&adev->lock);
301 } else
302 break;
303 }
304}
305
306/* called with adev lock held */
Arun Mirpurie008ed22019-03-21 11:21:04 -0700307void passthru_on_stop(struct stream_out * out)
Mingming Yin21854652016-04-13 11:54:02 -0700308{
Mingming Yin21854652016-04-13 11:54:02 -0700309 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
310 /*
311 * its possible the count is already zero if pause was called before
312 * stop output stream
313 */
314 android_atomic_dec(&compress_passthru_active);
315 }
316
317 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530318 ALOGD("%s: passthru on aux digital, start keep alive", __func__);
Arun Mirpurie008ed22019-03-21 11:21:04 -0700319 fp_audio_extn_keep_alive_start(KEEP_ALIVE_OUT_HDMI);
Mingming Yin21854652016-04-13 11:54:02 -0700320 }
321}
322
Arun Mirpurie008ed22019-03-21 11:21:04 -0700323void passthru_on_pause(struct stream_out * out __unused)
Mingming Yin21854652016-04-13 11:54:02 -0700324{
325 if (android_atomic_acquire_load(&compress_passthru_active) == 0)
326 return;
Mingming Yin21854652016-04-13 11:54:02 -0700327}
328
Arun Mirpurie008ed22019-03-21 11:21:04 -0700329bool passthru_is_active()
330{
331 return android_atomic_acquire_load(&compress_passthru_active) > 0;
332}
333
334int passthru_set_parameters(struct audio_device *adev __unused,
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530335 struct str_parms *parms)
Mingming Yin21854652016-04-13 11:54:02 -0700336{
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530337 char value[32];
338 int ret;
339 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_CONNECT, value, sizeof(value));
340 if (ret >= 0) {
341 int val = atoi(value);
342 if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
Arun Mirpurie008ed22019-03-21 11:21:04 -0700343 if (!passthru_is_active()) {
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530344 ALOGV("%s: start keep alive on aux digital", __func__);
Arun Mirpurie008ed22019-03-21 11:21:04 -0700345 fp_audio_extn_keep_alive_start(KEEP_ALIVE_OUT_HDMI);
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530346 }
347 }
348 }
349
350 ret = str_parms_get_str(parms, AUDIO_PARAMETER_DEVICE_DISCONNECT, value,
351 sizeof(value));
352 if (ret >= 0) {
353 int val = atoi(value);
354 if (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
355 ALOGV("%s: stop keep_alive on aux digital on device", __func__);
Arun Mirpurie008ed22019-03-21 11:21:04 -0700356 fp_audio_extn_keep_alive_stop(KEEP_ALIVE_OUT_HDMI);
Md Mansoor Ahmeddb1b4f92018-01-25 18:56:31 +0530357 }
358 }
Mingming Yin21854652016-04-13 11:54:02 -0700359 return 0;
360}
361
Arun Mirpurie008ed22019-03-21 11:21:04 -0700362bool passthru_is_enabled() { return true; }
363
364void passthru_init(passthru_init_config_t init_config)
Mingming Yin21854652016-04-13 11:54:02 -0700365{
Arun Mirpurie008ed22019-03-21 11:21:04 -0700366 fp_platform_is_edid_supported_format =
367 init_config.fp_platform_is_edid_supported_format;
368 fp_platform_set_device_params = init_config.fp_platform_set_device_params;
369 fp_platform_edid_get_max_channels =
370 init_config.fp_platform_edid_get_max_channels;
371 fp_platform_get_output_snd_device = init_config.fp_platform_get_output_snd_device;
372 fp_platform_get_codec_backend_cfg =
373 init_config.fp_platform_get_codec_backend_cfg;
374 fp_platform_get_snd_device_name = init_config.fp_platform_get_snd_device_name;
375 fp_platform_is_edid_supported_sample_rate =
376 init_config.fp_platform_is_edid_supported_sample_rate;
377 fp_audio_extn_keep_alive_start = init_config.fp_audio_extn_keep_alive_start;
378 fp_audio_extn_keep_alive_stop = init_config.fp_audio_extn_keep_alive_stop;
379 fp_audio_extn_utils_is_dolby_format = init_config.fp_audio_extn_utils_is_dolby_format;
Mingming Yin21854652016-04-13 11:54:02 -0700380}
381
Arun Mirpurie008ed22019-03-21 11:21:04 -0700382bool passthru_should_standby(struct stream_out * out __unused)
Mingming Yin21854652016-04-13 11:54:02 -0700383{
384 return true;
385}
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530386
Arun Mirpurie008ed22019-03-21 11:21:04 -0700387bool passthru_is_convert_supported(struct audio_device *adev,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530388 struct stream_out *out)
389{
390
391 bool convert = false;
392 switch (out->format) {
393 case AUDIO_FORMAT_E_AC3:
394 case AUDIO_FORMAT_E_AC3_JOC:
Arun Mirpurie008ed22019-03-21 11:21:04 -0700395 if (!fp_platform_is_edid_supported_format(adev->platform,
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530396 out->format)) {
Arun Mirpurie008ed22019-03-21 11:21:04 -0700397 if (fp_platform_is_edid_supported_format(adev->platform,
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530398 AUDIO_FORMAT_AC3)) {
399 ALOGD("%s:PASSTHROUGH_CONVERT supported", __func__);
400 convert = true;
401 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530402 }
403 break;
404 default:
405 ALOGD("%s: PASSTHROUGH_CONVERT not supported for format 0x%x",
406 __func__, out->format);
407 break;
408 }
409 ALOGD("%s: convert %d", __func__, convert);
410 return convert;
411}
412
Arun Mirpurie008ed22019-03-21 11:21:04 -0700413bool passthru_is_passt_supported(struct audio_device *adev,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530414 struct stream_out *out)
415{
416 bool passt = false;
417 switch (out->format) {
418 case AUDIO_FORMAT_E_AC3:
Ben Romberger1aaaf862017-04-06 17:49:46 -0700419 case AUDIO_FORMAT_DTS_HD:
420 case AUDIO_FORMAT_DOLBY_TRUEHD:
Arun Mirpurie008ed22019-03-21 11:21:04 -0700421 if (fp_platform_is_edid_supported_format(adev->platform, out->format)) {
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530422 ALOGV("%s:PASSTHROUGH supported for format %x",
423 __func__, out->format);
424 passt = true;
425 }
426 break;
427 case AUDIO_FORMAT_AC3:
Arun Mirpurie008ed22019-03-21 11:21:04 -0700428 if (fp_platform_is_edid_supported_format(adev->platform, AUDIO_FORMAT_AC3)
429 || fp_platform_is_edid_supported_format(adev->platform,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530430 AUDIO_FORMAT_E_AC3)) {
431 ALOGV("%s:PASSTHROUGH supported for format %x",
432 __func__, out->format);
433 passt = true;
434 }
435 break;
436 case AUDIO_FORMAT_E_AC3_JOC:
437 /* Check for DDP capability in edid for JOC contents.*/
Arun Mirpurie008ed22019-03-21 11:21:04 -0700438 if (fp_platform_is_edid_supported_format(adev->platform,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530439 AUDIO_FORMAT_E_AC3)) {
440 ALOGV("%s:PASSTHROUGH supported for format %x",
441 __func__, out->format);
442 passt = true;
443 }
444 break;
445 case AUDIO_FORMAT_DTS:
Arun Mirpurie008ed22019-03-21 11:21:04 -0700446 if (fp_platform_is_edid_supported_format(adev->platform, AUDIO_FORMAT_DTS)
447 || fp_platform_is_edid_supported_format(adev->platform,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530448 AUDIO_FORMAT_DTS_HD)) {
449 ALOGV("%s:PASSTHROUGH supported for format %x",
450 __func__, out->format);
451 passt = true;
452 }
453 break;
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530454 default:
455 ALOGV("%s:Passthrough not supported", __func__);
456 }
457 return passt;
458}
459
Arun Mirpurie008ed22019-03-21 11:21:04 -0700460void passthru_update_stream_configuration(
Manish Dewangan37864bc2017-06-09 12:28:37 +0530461 struct audio_device *adev, struct stream_out *out,
Garmond Leung317cbf12017-09-13 16:20:50 -0700462 const void *buffer __unused, size_t bytes __unused)
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530463{
Naresh Tanniruccd9f382018-01-17 16:02:19 +0530464 if(out->compr_config.codec != NULL) {
Arun Mirpurie008ed22019-03-21 11:21:04 -0700465 if (passthru_is_passt_supported(adev, out)) {
Naresh Tanniruccd9f382018-01-17 16:02:19 +0530466 ALOGV("%s:PASSTHROUGH", __func__);
467 out->compr_config.codec->compr_passthr = PASSTHROUGH;
Arun Mirpurie008ed22019-03-21 11:21:04 -0700468 } else if (passthru_is_convert_supported(adev, out)) {
Naresh Tanniruccd9f382018-01-17 16:02:19 +0530469 ALOGV("%s:PASSTHROUGH CONVERT", __func__);
470 out->compr_config.codec->compr_passthr = PASSTHROUGH_CONVERT;
471 } else if (out->format == AUDIO_FORMAT_IEC61937) {
472 ALOGV("%s:PASSTHROUGH IEC61937", __func__);
473 out->compr_config.codec->compr_passthr = PASSTHROUGH_IEC61937;
474 } else {
475 ALOGV("%s:NO PASSTHROUGH", __func__);
476 out->compr_config.codec->compr_passthr = LEGACY_PCM;
477 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530478 }
479}
480
Arun Mirpurie008ed22019-03-21 11:21:04 -0700481bool passthru_is_passthrough_stream(struct stream_out *out)
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530482{
483 //check passthrough system property
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700484 if (!property_get_bool("vendor.audio.offload.passthrough", false)) {
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530485 return false;
486 }
487
488 //check supported device, currently only on HDMI.
489 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
490 //passthrough flag
491 if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)
492 return true;
493 //direct flag, check supported formats.
494 if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT) {
Arun Mirpurie008ed22019-03-21 11:21:04 -0700495 if (passthru_is_supported_format(out->format)) {
496 if (fp_platform_is_edid_supported_format(out->dev->platform,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530497 out->format)) {
498 ALOGV("%s : return true",__func__);
499 return true;
Arun Mirpurie008ed22019-03-21 11:21:04 -0700500 } else if (fp_audio_extn_utils_is_dolby_format(out->format) &&
501 fp_platform_is_edid_supported_format(out->dev->platform,
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530502 AUDIO_FORMAT_AC3)){
503 //return true for EAC3/EAC3_JOC formats
504 //if sink supports only AC3
505 ALOGV("%s : return true",__func__);
506 return true;
507 }
508 }
509 }
510 }
511 ALOGV("%s : return false",__func__);
512 return false;
513}
514
Arun Mirpurie008ed22019-03-21 11:21:04 -0700515bool passthru_is_direct_passthrough(struct stream_out *out)
Manish Dewangan672001f2017-08-16 13:44:07 +0530516{
Arun Mirpurie008ed22019-03-21 11:21:04 -0700517 if (((out != NULL) && passthru_is_passthrough_stream(out)) &&
518 !passthru_is_convert_supported(out->dev, out))
Manish Dewangan672001f2017-08-16 13:44:07 +0530519 return true;
520 else
521 return false;
522}
523
Arun Mirpurie008ed22019-03-21 11:21:04 -0700524int passthru_get_buffer_size(audio_offload_info_t* info)
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530525{
Manish Dewangan37864bc2017-06-09 12:28:37 +0530526 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
527 char value[PROPERTY_VALUE_MAX] = {0};
528
529 if (((info->format == AUDIO_FORMAT_DOLBY_TRUEHD) ||
530 (info->format == AUDIO_FORMAT_IEC61937)) &&
Satish Babu Patakokila37e7c482018-02-02 11:50:06 +0530531 property_get("vendor.audio.truehd.buffer.size.kb", value, "") &&
Manish Dewangan37864bc2017-06-09 12:28:37 +0530532 atoi(value)) {
533 fragment_size = atoi(value) * 1024;
534 goto done;
535 } else if ((info->format == AUDIO_FORMAT_DTS) ||
536 (info->format == AUDIO_FORMAT_DTS_HD)) {
537 fragment_size = MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
538 goto done;
Harsh Bansalc83207c2017-09-01 16:04:36 +0530539 } else if (info->format == AUDIO_FORMAT_E_AC3) {
540 fragment_size = DDP_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
Satish Babu Patakokila37e7c482018-02-02 11:50:06 +0530541 if(property_get("vendor.audio.ddp.buffer.size.kb", value, "") &&
Harsh Bansalc83207c2017-09-01 16:04:36 +0530542 atoi(value)) {
543 fragment_size = atoi(value) * 1024;
544 }
545 goto done;
Manish Dewangan37864bc2017-06-09 12:28:37 +0530546 }
Manish Dewangan37864bc2017-06-09 12:28:37 +0530547done:
548 return fragment_size;
549
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530550}
551
Arun Mirpurie008ed22019-03-21 11:21:04 -0700552int passthru_set_volume(struct stream_out *out, int mute)
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530553{
Arun Mirpurie008ed22019-03-21 11:21:04 -0700554 return fp_platform_set_device_params(out, DEVICE_PARAM_MUTE_ID, mute);
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530555}
556
Arun Mirpurie008ed22019-03-21 11:21:04 -0700557int passthru_set_latency(struct stream_out *out, int latency)
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530558{
Arun Mirpurie008ed22019-03-21 11:21:04 -0700559 return fp_platform_set_device_params(out, DEVICE_PARAM_LATENCY_ID, latency);
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530560}
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530561
Arun Mirpurie008ed22019-03-21 11:21:04 -0700562bool passthru_is_supported_backend_edid_cfg(struct audio_device *adev,
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530563 struct stream_out *out)
564{
565 struct audio_backend_cfg backend_cfg;
mpang787a6aa2018-11-29 11:25:58 +0800566 backend_cfg.sample_rate = CODEC_BACKEND_DEFAULT_SAMPLE_RATE;
567 backend_cfg.channels = CODEC_BACKEND_DEFAULT_CHANNELS;
568 backend_cfg.bit_width = CODEC_BACKEND_DEFAULT_BIT_WIDTH;
569 backend_cfg.format = AUDIO_FORMAT_PCM_16_BIT;
570 backend_cfg.passthrough_enabled = false;
571
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530572 snd_device_t out_snd_device = SND_DEVICE_NONE;
Arun Mirpurie008ed22019-03-21 11:21:04 -0700573 int max_edid_channels = fp_platform_edid_get_max_channels(out->dev->platform);
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530574
Arun Mirpurie008ed22019-03-21 11:21:04 -0700575 out_snd_device = fp_platform_get_output_snd_device(adev->platform, out);
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530576
Arun Mirpurie008ed22019-03-21 11:21:04 -0700577 if (fp_platform_get_codec_backend_cfg(adev, out_snd_device, &backend_cfg)) {
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530578 ALOGE("%s: ERROR: Unable to get current backend config!!!", __func__);
579 return false;
580 }
581
582 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d"
583 ", device (%s)", __func__, backend_cfg.bit_width,
584 backend_cfg.sample_rate, backend_cfg.channels, backend_cfg.format,
Arun Mirpurie008ed22019-03-21 11:21:04 -0700585 fp_platform_get_snd_device_name(out_snd_device));
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530586
587 /* Check if the channels are supported */
Garmond Leung438932f2017-10-04 19:35:18 -0700588 if (max_edid_channels < (int)backend_cfg.channels) {
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530589
590 ALOGE("%s: ERROR: Unsupported channels in passthru mode!!!"
591 " max_edid_channels - %d backend_channels - %d",
592 __func__, max_edid_channels, backend_cfg.channels);
593 return false;
594 }
595
596 /* Check if the sample rate supported */
Arun Mirpurie008ed22019-03-21 11:21:04 -0700597 if (!fp_platform_is_edid_supported_sample_rate(adev->platform,
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530598 backend_cfg.sample_rate)) {
599
600 ALOGE("%s: ERROR: Unsupported sample rate in passthru mode!!!"
601 " backend_samplerate - %d",
602 __func__, backend_cfg.sample_rate);
603 return false;
604 }
605
606 return true;
607}