audio: Fix Dolby TrueHD passthrough issue [1/1]
PD#SWPL-195287
Problem:
There is audio gap when passthrough the Dolby TrueHD
data
Solution:
1. Reduce the size of each write to prevent encoder buffer overflow.
2. Close eARC device after closing stream.
Verify:
yocto-t5w
Change-Id: I99aee926375c546ddf498cd5b30d13122d26a435
Signed-off-by: yayun.shi <yayun.shi@amlogic.com>
diff --git a/audio_hal/audio_hw.c b/audio_hal/audio_hw.c
index c93b33a..cd43da8 100644
--- a/audio_hal/audio_hw.c
+++ b/audio_hal/audio_hw.c
@@ -7639,7 +7639,7 @@
set_ms12_mch_enable(&(adev->ms12), false);
}
}
-
+ get_sink_format(adev);
AM_LOGI("exit!!");
}
diff --git a/audio_hal/audio_hw_ms12_v2.c b/audio_hal/audio_hw_ms12_v2.c
index 3b01406..9d73f95 100644
--- a/audio_hal/audio_hw_ms12_v2.c
+++ b/audio_hal/audio_hw_ms12_v2.c
@@ -2335,11 +2335,18 @@
int nbytes_consumed = 0;
const unsigned char *pbuf = (unsigned char *)abuffer->buffer;
memset(ms12->mat_enc_out_buffer, 0, ms12->matenc_maxoutbufsize);
+ int write_size = 0;
while (offset < abuffer->size) {
+ /*if the size is too big, mat encoder will meet error*/
+ if ((abuffer->size - offset) >= 4096) {
+ write_size = 4096;
+ } else {
+ write_size = (abuffer->size - offset);
+ }
ret = dolby_ms12_mat_encoder_process
(ms12->mat_enc_handle
, (const unsigned char *)(pbuf + offset)
- , (abuffer->size - offset)
+ , write_size//(abuffer->size - offset)
, (const unsigned char *)ms12->mat_enc_out_buffer
, &ms12->mat_enc_out_bytes
, ms12->matenc_maxoutbufsize
@@ -2351,6 +2358,8 @@
}
if (ret) {
+ AM_LOGE("mat_encoder_process error %d bytes %"PRId32" offset %d nbytes_consumed %d mat_enc_out_bytes %d",
+ ret, abuffer->size, offset, nbytes_consumed, ms12->mat_enc_out_bytes);
/* try to re-init the mat encoder */
if (ms12->mat_enc_handle) {
dolby_ms12_mat_encoder_cleanup(ms12->mat_enc_handle);