blob: 1ee0008dd55aa87c466c55115e98580c973c14d6 [file] [log] [blame]
Mingming Yin21854652016-04-13 11:54:02 -07001/*
Ben Romberger1aaaf862017-04-06 17:49:46 -07002* Copyright (c) 2014-2017, 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;
210 default:
211 break;
212 }
213
214 ALOGE("%s: pass through channel count %d\n", __func__, channel_count);
215 return channel_count;
216}
217
Mingming Yin21854652016-04-13 11:54:02 -0700218bool audio_extn_passthru_is_supported_format(audio_format_t format)
219{
220 int32_t num_passthru_formats = sizeof(audio_passthru_formats) /
221 sizeof(audio_passthru_formats[0]);
222 int32_t i;
223
224 for (i = 0; i < num_passthru_formats; i++) {
225 if (format == audio_passthru_formats[i]) {
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530226 ALOGD("%s : pass through format is true", __func__);
Mingming Yin21854652016-04-13 11:54:02 -0700227 return true;
228 }
229 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530230 ALOGD("%s : pass through format is false", __func__);
Mingming Yin21854652016-04-13 11:54:02 -0700231 return false;
232}
233
234/*
235 * must be called with stream lock held
236 * This function decides based on some rules whether the data
237 * coming on stream out must be rendered or dropped.
238 */
239bool audio_extn_passthru_should_drop_data(struct stream_out * out)
240{
Ashish Jaind84fd6a2016-07-27 12:33:25 +0530241 /*Drop data only
242 *stream is routed to HDMI and
243 *stream has PCM format or
244 *if a compress offload (DSP decode) session
245 */
246 if ((out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) &&
247 (((out->format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) ||
248 ((out->compr_config.codec != NULL) && (out->compr_config.codec->compr_passthr == LEGACY_PCM)))) {
Mingming Yin21854652016-04-13 11:54:02 -0700249 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
250 ALOGI("drop data as pass thru is active");
251 return true;
252 }
253 }
254
255 return false;
256}
257
258/* called with adev lock held */
259void audio_extn_passthru_on_start(struct stream_out * out)
260{
261
262 uint64_t max_period_us = 0;
263 uint64_t temp;
264 struct audio_usecase * usecase;
265 struct listnode *node;
266 struct stream_out * o;
267 struct audio_device *adev = out->dev;
268
269 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
270 ALOGI("pass thru is already active");
271 return;
272 }
273
274 ALOGV("inc pass thru count to notify other streams");
275 android_atomic_inc(&compress_passthru_active);
276
Mingming Yin21854652016-04-13 11:54:02 -0700277 while (true) {
278 /* find max period time among active playback use cases */
279 list_for_each(node, &adev->usecase_list) {
280 usecase = node_to_item(node, struct audio_usecase, list);
281 if (usecase->type == PCM_PLAYBACK &&
282 usecase->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
283 o = usecase->stream.out;
284 temp = o->config.period_size * 1000000LL / o->sample_rate;
285 if (temp > max_period_us)
286 max_period_us = temp;
287 }
288 }
289
290 if (max_period_us) {
291 pthread_mutex_unlock(&adev->lock);
292 usleep(2*max_period_us);
293 max_period_us = 0;
294 pthread_mutex_lock(&adev->lock);
295 } else
296 break;
297 }
298}
299
300/* called with adev lock held */
301void audio_extn_passthru_on_stop(struct stream_out * out)
302{
Mingming Yin21854652016-04-13 11:54:02 -0700303 if (android_atomic_acquire_load(&compress_passthru_active) > 0) {
304 /*
305 * its possible the count is already zero if pause was called before
306 * stop output stream
307 */
308 android_atomic_dec(&compress_passthru_active);
309 }
310
311 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
312 ALOGI("passthru on aux digital, start keep alive");
313 audio_extn_keep_alive_start();
314 }
315}
316
317void audio_extn_passthru_on_pause(struct stream_out * out __unused)
318{
319 if (android_atomic_acquire_load(&compress_passthru_active) == 0)
320 return;
Mingming Yin21854652016-04-13 11:54:02 -0700321}
322
323int audio_extn_passthru_set_parameters(struct audio_device *adev __unused,
324 struct str_parms *parms __unused)
325{
326 return 0;
327}
328
329bool audio_extn_passthru_is_active()
330{
331 return android_atomic_acquire_load(&compress_passthru_active) > 0;
332}
333
334bool audio_extn_passthru_is_enabled() { return true; }
335
336void audio_extn_passthru_init(struct audio_device *adev __unused)
337{
338}
339
340bool audio_extn_passthru_should_standby(struct stream_out * out __unused)
341{
342 return true;
343}
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530344
345bool audio_extn_passthru_is_convert_supported(struct audio_device *adev,
346 struct stream_out *out)
347{
348
349 bool convert = false;
350 switch (out->format) {
351 case AUDIO_FORMAT_E_AC3:
352 case AUDIO_FORMAT_E_AC3_JOC:
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530353 if (!platform_is_edid_supported_format(adev->platform,
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530354 out->format)) {
355 if (platform_is_edid_supported_format(adev->platform,
356 AUDIO_FORMAT_AC3)) {
357 ALOGD("%s:PASSTHROUGH_CONVERT supported", __func__);
358 convert = true;
359 }
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530360 }
361 break;
362 default:
363 ALOGD("%s: PASSTHROUGH_CONVERT not supported for format 0x%x",
364 __func__, out->format);
365 break;
366 }
367 ALOGD("%s: convert %d", __func__, convert);
368 return convert;
369}
370
371bool audio_extn_passthru_is_passt_supported(struct audio_device *adev,
372 struct stream_out *out)
373{
374 bool passt = false;
375 switch (out->format) {
376 case AUDIO_FORMAT_E_AC3:
Ben Romberger1aaaf862017-04-06 17:49:46 -0700377 case AUDIO_FORMAT_DTS_HD:
378 case AUDIO_FORMAT_DOLBY_TRUEHD:
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530379 if (platform_is_edid_supported_format(adev->platform, out->format)) {
380 ALOGV("%s:PASSTHROUGH supported for format %x",
381 __func__, out->format);
382 passt = true;
383 }
384 break;
385 case AUDIO_FORMAT_AC3:
386 if (platform_is_edid_supported_format(adev->platform, AUDIO_FORMAT_AC3)
387 || platform_is_edid_supported_format(adev->platform,
388 AUDIO_FORMAT_E_AC3)) {
389 ALOGV("%s:PASSTHROUGH supported for format %x",
390 __func__, out->format);
391 passt = true;
392 }
393 break;
394 case AUDIO_FORMAT_E_AC3_JOC:
395 /* Check for DDP capability in edid for JOC contents.*/
396 if (platform_is_edid_supported_format(adev->platform,
397 AUDIO_FORMAT_E_AC3)) {
398 ALOGV("%s:PASSTHROUGH supported for format %x",
399 __func__, out->format);
400 passt = true;
401 }
402 break;
403 case AUDIO_FORMAT_DTS:
404 if (platform_is_edid_supported_format(adev->platform, AUDIO_FORMAT_DTS)
405 || platform_is_edid_supported_format(adev->platform,
406 AUDIO_FORMAT_DTS_HD)) {
407 ALOGV("%s:PASSTHROUGH supported for format %x",
408 __func__, out->format);
409 passt = true;
410 }
411 break;
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530412 default:
413 ALOGV("%s:Passthrough not supported", __func__);
414 }
415 return passt;
416}
417
418void audio_extn_passthru_update_stream_configuration(
Manish Dewangan37864bc2017-06-09 12:28:37 +0530419 struct audio_device *adev, struct stream_out *out,
Garmond Leung317cbf12017-09-13 16:20:50 -0700420 const void *buffer __unused, size_t bytes __unused)
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530421{
422 if (audio_extn_passthru_is_passt_supported(adev, out)) {
423 ALOGV("%s:PASSTHROUGH", __func__);
424 out->compr_config.codec->compr_passthr = PASSTHROUGH;
Naresh Tanniru928f0862017-04-07 16:44:23 -0700425 } else if (audio_extn_passthru_is_convert_supported(adev, out)) {
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530426 ALOGV("%s:PASSTHROUGH CONVERT", __func__);
427 out->compr_config.codec->compr_passthr = PASSTHROUGH_CONVERT;
Naresh Tanniru928f0862017-04-07 16:44:23 -0700428 } else if (out->format == AUDIO_FORMAT_IEC61937) {
429 ALOGV("%s:PASSTHROUGH IEC61937", __func__);
430 out->compr_config.codec->compr_passthr = PASSTHROUGH_IEC61937;
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530431 } else {
432 ALOGV("%s:NO PASSTHROUGH", __func__);
433 out->compr_config.codec->compr_passthr = LEGACY_PCM;
434 }
435}
436
437bool audio_extn_passthru_is_passthrough_stream(struct stream_out *out)
438{
439 //check passthrough system property
Aniket Kumar Lata8fc67e62017-05-02 12:33:46 -0700440 if (!property_get_bool("vendor.audio.offload.passthrough", false)) {
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530441 return false;
442 }
443
444 //check supported device, currently only on HDMI.
445 if (out->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL) {
446 //passthrough flag
447 if (out->flags & AUDIO_OUTPUT_FLAG_COMPRESS_PASSTHROUGH)
448 return true;
449 //direct flag, check supported formats.
450 if (out->flags & AUDIO_OUTPUT_FLAG_DIRECT) {
451 if (audio_extn_passthru_is_supported_format(out->format)) {
452 if (platform_is_edid_supported_format(out->dev->platform,
453 out->format)) {
454 ALOGV("%s : return true",__func__);
455 return true;
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530456 } else if (audio_extn_utils_is_dolby_format(out->format) &&
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530457 platform_is_edid_supported_format(out->dev->platform,
458 AUDIO_FORMAT_AC3)){
459 //return true for EAC3/EAC3_JOC formats
460 //if sink supports only AC3
461 ALOGV("%s : return true",__func__);
462 return true;
463 }
464 }
465 }
466 }
467 ALOGV("%s : return false",__func__);
468 return false;
469}
470
Manish Dewangan672001f2017-08-16 13:44:07 +0530471bool audio_extn_passthru_is_direct_passthrough(struct stream_out *out)
472{
473 if (((out != NULL) && audio_extn_passthru_is_passthrough_stream(out)) &&
474 !audio_extn_passthru_is_convert_supported(out->dev, out))
475 return true;
476 else
477 return false;
478}
479
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530480int audio_extn_passthru_get_buffer_size(audio_offload_info_t* info)
481{
Manish Dewangan37864bc2017-06-09 12:28:37 +0530482 uint32_t fragment_size = MIN_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
483 char value[PROPERTY_VALUE_MAX] = {0};
484
485 if (((info->format == AUDIO_FORMAT_DOLBY_TRUEHD) ||
486 (info->format == AUDIO_FORMAT_IEC61937)) &&
487 property_get("audio.truehd.buffer.size.kb", value, "") &&
488 atoi(value)) {
489 fragment_size = atoi(value) * 1024;
490 goto done;
491 } else if ((info->format == AUDIO_FORMAT_DTS) ||
492 (info->format == AUDIO_FORMAT_DTS_HD)) {
493 fragment_size = MAX_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
494 goto done;
Harsh Bansalc83207c2017-09-01 16:04:36 +0530495 } else if (info->format == AUDIO_FORMAT_E_AC3) {
496 fragment_size = DDP_COMPRESS_PASSTHROUGH_FRAGMENT_SIZE;
497 if(property_get("audio.ddp.buffer.size.kb", value, "") &&
498 atoi(value)) {
499 fragment_size = atoi(value) * 1024;
500 }
501 goto done;
Manish Dewangan37864bc2017-06-09 12:28:37 +0530502 }
Manish Dewangan37864bc2017-06-09 12:28:37 +0530503done:
504 return fragment_size;
505
Satish Babu Patakokila1caa1b72016-05-24 13:47:08 +0530506}
507
508int audio_extn_passthru_set_volume(struct stream_out *out, int mute)
509{
510 return platform_set_device_params(out, DEVICE_PARAM_MUTE_ID, mute);
511}
512
513int audio_extn_passthru_set_latency(struct stream_out *out, int latency)
514{
515 return platform_set_device_params(out, DEVICE_PARAM_LATENCY_ID, latency);
516}
Satish Babu Patakokila5933e972017-08-24 12:22:08 +0530517
518bool audio_extn_passthru_is_supported_backend_edid_cfg(struct audio_device *adev,
519 struct stream_out *out)
520{
521 struct audio_backend_cfg backend_cfg;
522 snd_device_t out_snd_device = SND_DEVICE_NONE;
523 int max_edid_channels = platform_edid_get_max_channels(out->dev->platform);
524
525 out_snd_device = platform_get_output_snd_device(adev->platform, out);
526
527 if (platform_get_codec_backend_cfg(adev, out_snd_device, &backend_cfg)) {
528 ALOGE("%s: ERROR: Unable to get current backend config!!!", __func__);
529 return false;
530 }
531
532 ALOGV("%s:becf: afe: bitwidth %d, samplerate %d channels %d format %d"
533 ", device (%s)", __func__, backend_cfg.bit_width,
534 backend_cfg.sample_rate, backend_cfg.channels, backend_cfg.format,
535 platform_get_snd_device_name(out_snd_device));
536
537 /* Check if the channels are supported */
538 if (max_edid_channels < backend_cfg.channels) {
539
540 ALOGE("%s: ERROR: Unsupported channels in passthru mode!!!"
541 " max_edid_channels - %d backend_channels - %d",
542 __func__, max_edid_channels, backend_cfg.channels);
543 return false;
544 }
545
546 /* Check if the sample rate supported */
547 if (!platform_is_edid_supported_sample_rate(adev->platform,
548 backend_cfg.sample_rate)) {
549
550 ALOGE("%s: ERROR: Unsupported sample rate in passthru mode!!!"
551 " backend_samplerate - %d",
552 __func__, backend_cfg.sample_rate);
553 return false;
554 }
555
556 return true;
557}