From 056eefa77763ea527afd65c71de8bb1074cd650a Mon Sep 17 00:00:00 2001 From: sgnanase Date: Tue, 20 Aug 2024 00:04:28 +0530 Subject: [PATCH] Update review comments #1 Compiles fine Signed-off-by: sgnanase --- primary/Android.mk | 1 - primary/audio_bt.h | 172 ------------------------------------------- primary/audio_dbg.h | 3 + primary/audio_hw.c | 173 +++++++++++++++++++++++++++++++++++++++++++- primary/audio_hw.h | 6 +- primary/config.c | 18 +---- primary/config.h | 17 +---- primary/utils.c | 18 +---- primary/utils.h | 17 +---- 9 files changed, 188 insertions(+), 237 deletions(-) delete mode 100644 primary/audio_bt.h diff --git a/primary/Android.mk b/primary/Android.mk index 0af6533..7436725 100755 --- a/primary/Android.mk +++ b/primary/Android.mk @@ -41,7 +41,6 @@ LOCAL_C_INCLUDES += \ $(call include-path-for, audio-effects) LOCAL_CFLAGS :=\ - -fno-common \ -fwrapv \ -D_FORTIFY_SOURCE=2 \ -fstack-protector-strong \ diff --git a/primary/audio_bt.h b/primary/audio_bt.h deleted file mode 100644 index 4e80351..0000000 --- a/primary/audio_bt.h +++ /dev/null @@ -1,172 +0,0 @@ - -/* VoIP pcm write in celadon devices goes to bt alsa card */ -int out_write_bt (struct stream_out *out, struct audio_device *adev, const void* buffer, - size_t bytes) -{ - int ret = 0; - size_t frames_in = round_to_16_mult(out->pcm_config->period_size); - size_t frames_out = round_to_16_mult(bt_out_config.period_size); - size_t buf_size_out = bt_out_config.channels * frames_out * SAMPLE_SIZE_IN_BYTES; - size_t buf_size_in = out->pcm_config->channels * frames_in * SAMPLE_SIZE_IN_BYTES; - size_t buf_size_remapped = bt_out_config.channels * frames_in * SAMPLE_SIZE_IN_BYTES; - int16_t *buf_out = (int16_t *) malloc (buf_size_out); - int16_t *buf_in = (int16_t *) malloc (buf_size_in); - int16_t *buf_remapped = (int16_t *) malloc (buf_size_remapped); - - if(adev->voip_out_resampler == NULL) { - int ret = create_resampler(out->pcm_config->rate /*src rate*/, bt_out_config.rate /*dst rate*/, bt_out_config.channels/*dst channels*/, - RESAMPLER_QUALITY_DEFAULT, NULL, &(adev->voip_out_resampler)); - ALOGD("%s : frames_in %zu frames_out %zu",__func__, frames_in, frames_out); - ALOGD("%s : to write bytes : %zu", __func__, bytes); - ALOGD("%s : size_in %zu size_out %zu size_remapped %zu", __func__, buf_size_in, buf_size_out, buf_size_remapped); - - if (ret != 0) { - adev->voip_out_resampler = NULL; - ALOGE("%s : Failure to create resampler %d", __func__, ret); - - free(buf_in); - free(buf_out); - free(buf_remapped); - } else { - ALOGD("%s : voip_out_resampler created rate : [%d -> %d]", __func__, out->pcm_config->rate, bt_out_config.rate); - } - } - - memset(buf_in, 0, buf_size_in); - memset(buf_remapped, 0, buf_size_remapped); - memset(buf_out, 0, buf_size_out); - - memcpy_s(buf_in,buf_size_in, buffer, buf_size_in); - -#ifdef DEBUG_PCM_DUMP - if(sco_call_write != NULL) { - fwrite(buf_in, 1, buf_size_in, sco_call_write); - } else { - ALOGD("%s : sco_call_write was NULL, no dump", __func__); - } -#endif - - adjust_channels(buf_in, out->pcm_config->channels, buf_remapped, bt_out_config.channels, - SAMPLE_SIZE_IN_BYTES, buf_size_in); - - //ALOGV("remapping : [%d -> %d]", out->pcm_config->channels, bt_out_config.channels); - -#ifdef DEBUG_PCM_DUMP - if(sco_call_write_remapped != NULL) { - fwrite(buf_remapped, 1, buf_size_remapped, sco_call_write_remapped); - } else { - ALOGD("%s : sco_call_write_remapped was NULL, no dump", __func__); - } -#endif - - if(adev->voip_out_resampler != NULL) { - adev->voip_out_resampler->resample_from_input(adev->voip_out_resampler, (int16_t *)buf_remapped, (size_t *)&frames_in, (int16_t *) buf_out, (size_t *)&frames_out); - //ALOGV("%s : upsampling [%d -> %d]",__func__, out->pcm_config->rate, bt_out_config.rate); - } - - ALOGV("%s : modified frames_in %zu frames_out %zu",__func__, frames_in, frames_out); - - buf_size_out = bt_out_config.channels * frames_out * SAMPLE_SIZE_IN_BYTES; - bytes = out->pcm_config->channels * frames_in * SAMPLE_SIZE_IN_BYTES; - -#ifdef DEBUG_PCM_DUMP - if(sco_call_write_bt != NULL) { - fwrite(buf_out, 1, buf_size_out, sco_call_write_bt); - } else { - ALOGD("%s : sco_call_write was NULL, no dump", __func__); - } -#endif - - ret = pcm_write(out->pcm, buf_out, buf_size_out); - - free(buf_in); - free(buf_out); - free(buf_remapped); - -return ret; -} - -/* VoIP pcm read from bt alsa card */ -int in_read_bt (struct stream_in *in, struct audio_device *adev, void* buffer, - size_t bytes) -{ - int ret = 0; - size_t frames_out = round_to_16_mult(in->pcm_config->period_size); - size_t frames_in = round_to_16_mult(bt_in_config.period_size); - size_t buf_size_out = in->pcm_config->channels * frames_out * SAMPLE_SIZE_IN_BYTES; - size_t buf_size_in = bt_in_config.channels * frames_in * SAMPLE_SIZE_IN_BYTES; - size_t buf_size_remapped = in->pcm_config->channels * frames_in * SAMPLE_SIZE_IN_BYTES; - int16_t *buf_out = (int16_t *) malloc (buf_size_out); - int16_t *buf_in = (int16_t *) malloc (buf_size_in); - int16_t *buf_remapped = (int16_t *) malloc (buf_size_remapped); - - if(adev->voip_in_resampler == NULL) { - int ret = create_resampler(bt_in_config.rate /*src rate*/, in->pcm_config->rate /*dst rate*/, in->pcm_config->channels/*dst channels*/, - RESAMPLER_QUALITY_DEFAULT, NULL, &(adev->voip_in_resampler)); - ALOGV("%s : bytes_requested : %zu", __func__, bytes); - ALOGV("%s : frames_in %zu frames_out %zu",__func__, frames_in, frames_out); - ALOGD("%s : size_in %zu size_out %zu size_remapped %zu", __func__, buf_size_in, buf_size_out, buf_size_remapped); - if (ret != 0) { - adev->voip_in_resampler = NULL; - ALOGE("%s : Failure to create resampler %d", __func__, ret); - - free(buf_in); - free(buf_out); - free(buf_remapped); - } else { - ALOGD("%s : voip_in_resampler created rate : [%d -> %d]", __func__, bt_in_config.rate, in->pcm_config->rate); - } - } - - memset(buf_in, 0, buf_size_in); - memset(buf_remapped, 0, buf_size_remapped); - memset(buf_out, 0, buf_size_out); - - ret = pcm_read(in->pcm, buf_in, buf_size_in); - -#ifdef DEBUG_PCM_DUMP - if(sco_call_read != NULL) { - fwrite(buf_in, 1, buf_size_in, sco_call_read); - } else { - ALOGD("%s : sco_call_read was NULL, no dump", __func__); - } -#endif - adjust_channels(buf_in, bt_in_config.channels, buf_remapped, in->pcm_config->channels, - SAMPLE_SIZE_IN_BYTES, buf_size_in); - - //ALOGV("%s : remapping : [%d -> %d]", __func__, bt_in_config.channels, in->pcm_config->channels); - -#ifdef DEBUG_PCM_DUMP - if(sco_call_read_remapped != NULL) { - fwrite(buf_remapped, 1, buf_size_remapped, sco_call_read_remapped); - } else { - ALOGD("%s : sco_call_read_remapped was NULL, no dump", __func__); - } -#endif - - if(adev->voip_in_resampler != NULL) { - adev->voip_in_resampler->resample_from_input(adev->voip_in_resampler, (int16_t *)buf_remapped, (size_t *)&frames_in, (int16_t *) buf_out, (size_t *)&frames_out); - //ALOGV("%s : upsampling [%d -> %d]",__func__, bt_in_config.rate, in->pcm_config->rate); - } - - ALOGV("%s : modified frames_in %zu frames_out %zu",__func__, frames_in, frames_out); - - buf_size_out = in->pcm_config->channels * frames_out * SAMPLE_SIZE_IN_BYTES; - bytes = buf_size_out; - -#ifdef DEBUG_PCM_DUMP - if(sco_call_read_bt != NULL) { - fwrite(buf_out, 1, buf_size_out, sco_call_read_bt); - } else { - ALOGD("%s : sco_call_read_bt was NULL, no dump", __func__); - } -#endif - - memcpy_s(buffer,buf_size_out, buf_out, buf_size_out); - - free(buf_in); - free(buf_out); - free(buf_remapped); - -return ret; -} diff --git a/primary/audio_dbg.h b/primary/audio_dbg.h index d35abb4..4f3ed14 100644 --- a/primary/audio_dbg.h +++ b/primary/audio_dbg.h @@ -1,3 +1,6 @@ +//Copyright (C) 2024 Intel Corporation +//SPDX-License-Identifier: Apache-2.0 + /*#define LOG_NDEBUG 0*/ //#define DEBUG_PCM_DUMP diff --git a/primary/audio_hw.c b/primary/audio_hw.c index e411c54..11ebe04 100755 --- a/primary/audio_hw.c +++ b/primary/audio_hw.c @@ -20,7 +20,6 @@ #include #include #include -#include static void select_devices(struct audio_device *adev) { @@ -1089,3 +1088,175 @@ struct audio_module HAL_MODULE_INFO_SYM = { .methods = &hal_module_methods, }, }; + +/* VoIP pcm write in celadon devices goes to bt alsa card */ +int out_write_bt (struct stream_out *out, struct audio_device *adev, const void* buffer, + size_t bytes) +{ + int ret = 0; + size_t frames_in = round_to_16_mult(out->pcm_config->period_size); + size_t frames_out = round_to_16_mult(bt_out_config.period_size); + size_t buf_size_out = bt_out_config.channels * frames_out * SAMPLE_SIZE_IN_BYTES; + size_t buf_size_in = out->pcm_config->channels * frames_in * SAMPLE_SIZE_IN_BYTES; + size_t buf_size_remapped = bt_out_config.channels * frames_in * SAMPLE_SIZE_IN_BYTES; + int16_t *buf_out = (int16_t *) malloc (buf_size_out); + int16_t *buf_in = (int16_t *) malloc (buf_size_in); + int16_t *buf_remapped = (int16_t *) malloc (buf_size_remapped); + + if(adev->voip_out_resampler == NULL) { + int ret = create_resampler(out->pcm_config->rate /*src rate*/, bt_out_config.rate /*dst rate*/, bt_out_config.channels/*dst channels*/, + RESAMPLER_QUALITY_DEFAULT, NULL, &(adev->voip_out_resampler)); + ALOGD("%s : frames_in %zu frames_out %zu",__func__, frames_in, frames_out); + ALOGD("%s : to write bytes : %zu", __func__, bytes); + ALOGD("%s : size_in %zu size_out %zu size_remapped %zu", __func__, buf_size_in, buf_size_out, buf_size_remapped); + + if (ret != 0) { + adev->voip_out_resampler = NULL; + ALOGE("%s : Failure to create resampler %d", __func__, ret); + + free(buf_in); + free(buf_out); + free(buf_remapped); + } else { + ALOGD("%s : voip_out_resampler created rate : [%d -> %d]", __func__, out->pcm_config->rate, bt_out_config.rate); + } + } + + memset(buf_in, 0, buf_size_in); + memset(buf_remapped, 0, buf_size_remapped); + memset(buf_out, 0, buf_size_out); + + memcpy_s(buf_in,buf_size_in, buffer, buf_size_in); + +#ifdef DEBUG_PCM_DUMP + if(sco_call_write != NULL) { + fwrite(buf_in, 1, buf_size_in, sco_call_write); + } else { + ALOGD("%s : sco_call_write was NULL, no dump", __func__); + } +#endif + + adjust_channels(buf_in, out->pcm_config->channels, buf_remapped, bt_out_config.channels, + SAMPLE_SIZE_IN_BYTES, buf_size_in); + + //ALOGV("remapping : [%d -> %d]", out->pcm_config->channels, bt_out_config.channels); + +#ifdef DEBUG_PCM_DUMP + if(sco_call_write_remapped != NULL) { + fwrite(buf_remapped, 1, buf_size_remapped, sco_call_write_remapped); + } else { + ALOGD("%s : sco_call_write_remapped was NULL, no dump", __func__); + } +#endif + + if(adev->voip_out_resampler != NULL) { + adev->voip_out_resampler->resample_from_input(adev->voip_out_resampler, (int16_t *)buf_remapped, (size_t *)&frames_in, (int16_t *) buf_out, (size_t *)&frames_out); + //ALOGV("%s : upsampling [%d -> %d]",__func__, out->pcm_config->rate, bt_out_config.rate); + } + + ALOGV("%s : modified frames_in %zu frames_out %zu",__func__, frames_in, frames_out); + + buf_size_out = bt_out_config.channels * frames_out * SAMPLE_SIZE_IN_BYTES; + bytes = out->pcm_config->channels * frames_in * SAMPLE_SIZE_IN_BYTES; + +#ifdef DEBUG_PCM_DUMP + if(sco_call_write_bt != NULL) { + fwrite(buf_out, 1, buf_size_out, sco_call_write_bt); + } else { + ALOGD("%s : sco_call_write was NULL, no dump", __func__); + } +#endif + + ret = pcm_write(out->pcm, buf_out, buf_size_out); + + free(buf_in); + free(buf_out); + free(buf_remapped); + +return ret; +} + +/* VoIP pcm read from bt alsa card */ +int in_read_bt (struct stream_in *in, struct audio_device *adev, void* buffer, + size_t bytes) +{ + int ret = 0; + size_t frames_out = round_to_16_mult(in->pcm_config->period_size); + size_t frames_in = round_to_16_mult(bt_in_config.period_size); + size_t buf_size_out = in->pcm_config->channels * frames_out * SAMPLE_SIZE_IN_BYTES; + size_t buf_size_in = bt_in_config.channels * frames_in * SAMPLE_SIZE_IN_BYTES; + size_t buf_size_remapped = in->pcm_config->channels * frames_in * SAMPLE_SIZE_IN_BYTES; + int16_t *buf_out = (int16_t *) malloc (buf_size_out); + int16_t *buf_in = (int16_t *) malloc (buf_size_in); + int16_t *buf_remapped = (int16_t *) malloc (buf_size_remapped); + + if(adev->voip_in_resampler == NULL) { + int ret = create_resampler(bt_in_config.rate /*src rate*/, in->pcm_config->rate /*dst rate*/, in->pcm_config->channels/*dst channels*/, + RESAMPLER_QUALITY_DEFAULT, NULL, &(adev->voip_in_resampler)); + ALOGV("%s : bytes_requested : %zu", __func__, bytes); + ALOGV("%s : frames_in %zu frames_out %zu",__func__, frames_in, frames_out); + ALOGD("%s : size_in %zu size_out %zu size_remapped %zu", __func__, buf_size_in, buf_size_out, buf_size_remapped); + if (ret != 0) { + adev->voip_in_resampler = NULL; + ALOGE("%s : Failure to create resampler %d", __func__, ret); + + free(buf_in); + free(buf_out); + free(buf_remapped); + } else { + ALOGD("%s : voip_in_resampler created rate : [%d -> %d]", __func__, bt_in_config.rate, in->pcm_config->rate); + } + } + + memset(buf_in, 0, buf_size_in); + memset(buf_remapped, 0, buf_size_remapped); + memset(buf_out, 0, buf_size_out); + + ret = pcm_read(in->pcm, buf_in, buf_size_in); + +#ifdef DEBUG_PCM_DUMP + if(sco_call_read != NULL) { + fwrite(buf_in, 1, buf_size_in, sco_call_read); + } else { + ALOGD("%s : sco_call_read was NULL, no dump", __func__); + } +#endif + adjust_channels(buf_in, bt_in_config.channels, buf_remapped, in->pcm_config->channels, + SAMPLE_SIZE_IN_BYTES, buf_size_in); + + //ALOGV("%s : remapping : [%d -> %d]", __func__, bt_in_config.channels, in->pcm_config->channels); + +#ifdef DEBUG_PCM_DUMP + if(sco_call_read_remapped != NULL) { + fwrite(buf_remapped, 1, buf_size_remapped, sco_call_read_remapped); + } else { + ALOGD("%s : sco_call_read_remapped was NULL, no dump", __func__); + } +#endif + + if(adev->voip_in_resampler != NULL) { + adev->voip_in_resampler->resample_from_input(adev->voip_in_resampler, (int16_t *)buf_remapped, (size_t *)&frames_in, (int16_t *) buf_out, (size_t *)&frames_out); + //ALOGV("%s : upsampling [%d -> %d]",__func__, bt_in_config.rate, in->pcm_config->rate); + } + + ALOGV("%s : modified frames_in %zu frames_out %zu",__func__, frames_in, frames_out); + + buf_size_out = in->pcm_config->channels * frames_out * SAMPLE_SIZE_IN_BYTES; + bytes = buf_size_out; + +#ifdef DEBUG_PCM_DUMP + if(sco_call_read_bt != NULL) { + fwrite(buf_out, 1, buf_size_out, sco_call_read_bt); + } else { + ALOGD("%s : sco_call_read_bt was NULL, no dump", __func__); + } +#endif + + memcpy_s(buffer,buf_size_out, buf_out, buf_size_out); + + free(buf_in); + free(buf_out); + free(buf_remapped); + +return ret; +} diff --git a/primary/audio_hw.h b/primary/audio_hw.h index 37e2316..af6d7b5 100644 --- a/primary/audio_hw.h +++ b/primary/audio_hw.h @@ -1,3 +1,6 @@ +//Copyright (C) 2024 Intel Corporation +//SPDX-License-Identifier: Apache-2.0 + // // All hash includes - Start // @@ -385,7 +388,8 @@ static int in_remove_audio_effect(const struct audio_stream *stream __unused, return 0; } -//int out_write_bt (struct stream_out *out, struct audio_device *adev, const void* buffer, size_t bytes); +int in_read_bt (struct stream_in *in, struct audio_device *adev, void* buffer, size_t bytes); +int out_write_bt (struct stream_out *out, struct audio_device *adev, const void* buffer, size_t bytes); // All Function declarations - End diff --git a/primary/config.c b/primary/config.c index a41f1c7..0b2fdf1 100644 --- a/primary/config.c +++ b/primary/config.c @@ -1,19 +1,5 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +//Copyright (C) 2024 Intel Corporation +//SPDX-License-Identifier: Apache-2.0 #define LOG_TAG "audio_hal_config" /*#define LOG_NDEBUG 0*/ diff --git a/primary/config.h b/primary/config.h index d98e3de..387a85c 100644 --- a/primary/config.h +++ b/primary/config.h @@ -1,18 +1,5 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +//Copyright (C) 2024 Intel Corporation +//SPDX-License-Identifier: Apache-2.0 #ifndef AUDIO_HAL_CONFIG_H #define AUDIO_HAL_CONFIG_H diff --git a/primary/utils.c b/primary/utils.c index 96e1ac3..6547856 100644 --- a/primary/utils.c +++ b/primary/utils.c @@ -1,19 +1,5 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +//Copyright (C) 2024 Intel Corporation +//SPDX-License-Identifier: Apache-2.0 #define LOG_TAG "audio_hal_utils" /*#define LOG_NDEBUG 0*/ diff --git a/primary/utils.h b/primary/utils.h index 56601a2..e7c174e 100644 --- a/primary/utils.h +++ b/primary/utils.h @@ -1,18 +1,5 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +//Copyright (C) 2024 Intel Corporation +//SPDX-License-Identifier: Apache-2.0 #ifndef AUDIO_HAL_UTILS_H #define AUDIO_HAL_UTILS_H