From be738c2302c70ebb123a138072740c7e78429904 Mon Sep 17 00:00:00 2001 From: heyabinghyb Date: Thu, 16 May 2024 10:12:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=83=A8=E5=88=86=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heyabinghyb --- frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp | 2 +- frameworks/native/audioutils/src/audio_speed.cpp | 4 ++++ frameworks/native/audioutils/src/audio_utils.cpp | 7 +++---- .../hdiadapter/sink/primary/audio_renderer_sink.cpp | 2 +- .../native/pulseaudio/modules/abstract/module_loopback.c | 4 ++-- frameworks/native/pulseaudio/modules/hdi/hdi_sink.c | 2 +- .../server/src/service/manager/audio_adapter_manager.cpp | 4 ++-- .../server/src/service/manager/volume_data_maintainer.cpp | 2 +- services/audio_service/server/src/audio_effect_server.cpp | 8 ++++++++ 9 files changed, 23 insertions(+), 12 deletions(-) diff --git a/frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp b/frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp index 41a7c73cc7..45dcabac1e 100644 --- a/frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp +++ b/frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp @@ -496,7 +496,7 @@ napi_value NapiAudioCapturer::GetAudioTime(napi_env env, napi_callback_info info Timestamp timestamp; if (napiAudioCapturer->audioCapturer_->GetAudioTime(timestamp, Timestamp::Timestampbase::MONOTONIC)) { const uint64_t secToNanosecond = 1000000000; - context->time = timestamp.time.tv_nsec + timestamp.time.tv_sec * secToNanosecond; + context->time = static_cast(timestamp.time.tv_nsec) + static_cast(imestamp.time.tv_sec) * secToNanosecond; } else { context->SignError(NAPI_ERR_SYSTEM); } diff --git a/frameworks/native/audioutils/src/audio_speed.cpp b/frameworks/native/audioutils/src/audio_speed.cpp index 7c1c7e5b31..dfe8443599 100644 --- a/frameworks/native/audioutils/src/audio_speed.cpp +++ b/frameworks/native/audioutils/src/audio_speed.cpp @@ -136,9 +136,13 @@ int32_t AudioSpeed::ChangeSpeedFor24Bit(uint8_t *buffer, int32_t bufferSize, return ERR_MEMORY_ALLOC_FAILED; } float* bitTofloat = new(std::nothrow) float[bufferSize]; + if (!bitTofloat) + return ERROR; ConvertFrom24BitToFloat(bufferSize / formatSize_, buffer, bitTofloat); float* speedBuf = new(std::nothrow) float[MAX_BUFFER_SIZE]; + if (!speedBuf) + return ERROR; int32_t ret = ChangeSpeedForFloat(bitTofloat, bufferSize, speedBuf, outBufferSize); ConvertFromFloatTo24Bit(outBufferSize / formatSize_, speedBuf, outBuffer.get()); diff --git a/frameworks/native/audioutils/src/audio_utils.cpp b/frameworks/native/audioutils/src/audio_utils.cpp index d793227df7..0acc2c8095 100644 --- a/frameworks/native/audioutils/src/audio_utils.cpp +++ b/frameworks/native/audioutils/src/audio_utils.cpp @@ -587,8 +587,7 @@ void DumpFileUtil::OpenDumpFile(std::string para, std::string fileName, FILE **f if (para == DUMP_SERVER_PARA) { if (fileName == DUMP_BLUETOOTH_RENDER_SINK_FILENAME || fileName == DUMP_RENDER_SINK_FILENAME || - fileName == DUMP_CAPTURER_SOURCE_FILENAME || fileName == DUMP_OFFLOAD_RENDER_SINK_FILENAME || - fileName.find("effect") != std::string::npos) { // special name for audio effect + fileName == DUMP_CAPTURER_SOURCE_FILENAME || fileName == DUMP_OFFLOAD_RENDER_SINK_FILENAME) { *file = DumpFileUtil::OpenDumpFileInner(para, fileName, AUDIO_PULSE); return; } @@ -612,8 +611,8 @@ static void MemcpyToI32FromI24(uint8_t *src, int32_t *dst, size_t count) { for (size_t i = 0; i < count; i++) { uint8_t *tmp = src + 3 * i; // 3 is byte size of SAMPLE_S24LE; - *(dst + i) = static_cast(tmp[2] << (2 * sizeof(uint8_t))) | - static_cast(tmp[1] << sizeof(uint8_t)) | static_cast(tmp[0]); + *(dst + i) = static_cast(tmp[2] << (2 * sizeof(uint8_t))) | + static_cast(tmp[1] << sizeof(uuint8_t)) | static_cast(tmp[0]); } } diff --git a/frameworks/native/hdiadapter/sink/primary/audio_renderer_sink.cpp b/frameworks/native/hdiadapter/sink/primary/audio_renderer_sink.cpp index 443a5ffb9f..6ca630a340 100644 --- a/frameworks/native/hdiadapter/sink/primary/audio_renderer_sink.cpp +++ b/frameworks/native/hdiadapter/sink/primary/audio_renderer_sink.cpp @@ -320,7 +320,7 @@ bool AudioRendererSinkInner::AttributesCheck(AudioSampleAttributes &attrInfo) int32_t AudioRendererSinkInner::SetAudioAttrInfo(AudioSampleAttributes &attrInfo) { CHECK_AND_RETURN_RET_LOG(AttributesCheck(attrInfo), ERROR, "AttributesCheck failed"); - int32_t bufferSize = attrInfo.sampleRate * attrInfo.format * attrInfo.channelCount * + uint32_t bufferSize = attrInfo.sampleRate * attrInfo.format * attrInfo.channelCount * BUFFER_CALC_20MS / BUFFER_CALC_1000MS; audioAttrInfo_ = "rate="+to_string(attrInfo.sampleRate)+" format=" + ParseAudioFormatToStr(attrInfo.format) + " channels=" + to_string(attrInfo.channelCount) + " buffer_size="+to_string(bufferSize); diff --git a/frameworks/native/pulseaudio/modules/abstract/module_loopback.c b/frameworks/native/pulseaudio/modules/abstract/module_loopback.c index fad3a22d5d..d0b015c022 100644 --- a/frameworks/native/pulseaudio/modules/abstract/module_loopback.c +++ b/frameworks/native/pulseaudio/modules/abstract/module_loopback.c @@ -944,8 +944,8 @@ static int SinkInputProcessMsgCb(pa_msgobject *obj, int code, void *data, int64_ u->latency_snapshot.recv_counter = u->output_thread_info.recv_counter; u->latency_snapshot.loopback_memblockq_length = pa_memblockq_get_length(u->memblockq); /* Add content of render memblockq to sink latency */ - u->latency_snapshot.sink_latency = pa_sink_get_latency_within_thread(u->sink_input->sink, true) + - pa_bytes_to_usec(length, &u->sink_input->sink->sample_spec); + u->latency_snapshot.sink_latency = (int64_t)(pa_sink_get_latency_within_thread(u->sink_input->sink, true) + + pa_bytes_to_usec(length, &u->sink_input->sink->sample_spec)); u->latency_snapshot.sink_timestamp = pa_rtclock_now(); return 0; } diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c index 3702933c76..d443c17d79 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c @@ -2782,7 +2782,7 @@ static void ThreadFuncRendererTimerMultiChannel(void *userdata) pa_usec_t now = 0; - int64_t sleepForUsec = -1; + int sleepForUsec = -1; bool flag = ThreadFuncRendererTimerMultiChannelFlagJudge(u); if (flag) { diff --git a/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp b/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp index 8c8d3a7bd0..967673f232 100644 --- a/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp +++ b/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp @@ -334,7 +334,7 @@ int32_t AudioAdapterManager::SetVolumeDb(AudioStreamType streamType) CHECK_AND_RETURN_RET_LOG(audioServiceAdapter_, ERR_OPERATION_FAILED, "SetSystemVolumeLevel audio adapter null"); - AUDIO_INFO_LOG("streamType:%{public}d volumeDb:%{public}f volume:%{public}d", streamType, volumeDb, volumeLevel); + AUDIO_INFO_LOG("SetVolumeDb: streamType %{public}d, volumeDb %{public}f", streamType, volumeDb); if (streamType == STREAM_VOICE_CALL || streamType == STREAM_VOICE_COMMUNICATION) { return SetVolumeDbForVolumeTypeGroup(VOICE_CALL_VOLUME_TYPE_LIST, volumeDb); } else if (streamType == STREAM_MUSIC) { @@ -1517,7 +1517,7 @@ uint32_t AudioAdapterManager::GetPositionInVolumePoints(std::vector int32_t rightPos = volumePoints.size() - 1; while (leftPos <= rightPos) { int32_t midPos = leftPos + (rightPos - leftPos)/NUMBER_TWO; - int32_t c = volumePoints[midPos].index - idx; + uint32_t c = volumePoints[midPos].index - idx; if (c == 0) { leftPos = midPos; break; diff --git a/services/audio_policy/server/src/service/manager/volume_data_maintainer.cpp b/services/audio_policy/server/src/service/manager/volume_data_maintainer.cpp index 6f371b0af4..a1ab361abe 100644 --- a/services/audio_policy/server/src/service/manager/volume_data_maintainer.cpp +++ b/services/audio_policy/server/src/service/manager/volume_data_maintainer.cpp @@ -324,7 +324,7 @@ bool VolumeDataMaintainer::SetMuteAffectedToMuteStatusDataBase(int32_t affected) { // transfer mute_streams_affected to mutestatus for (auto &streamtype : VOLUME_MUTE_STREAM_TYPE) { - if (affected & (1 << streamtype)) { + if (static_cast(affected) & (1 << streamtype)) { for (auto &device : DEVICE_TYPE_LIST) { // save mute status to database SaveMuteStatusInternal(device, AUDIO_STREAMTYPE_MAP[streamtype], true); diff --git a/services/audio_service/server/src/audio_effect_server.cpp b/services/audio_service/server/src/audio_effect_server.cpp index 65be1fac7d..5f297e3625 100644 --- a/services/audio_service/server/src/audio_effect_server.cpp +++ b/services/audio_service/server/src/audio_effect_server.cpp @@ -56,6 +56,14 @@ static bool LoadLibrary(const std::string &relativePath, std::shared_ptr realpath lib %{public}s Fail", relativePath.c_str()); + return false; + } + free(realPathRes); + void* handle = dlopen(absolutePath.c_str(), 1); if (!handle) { AUDIO_ERR_LOG(" dlopen lib %{public}s Fail", relativePath.c_str()); -- Gitee From cb365196335db0c1e8990ad29ba94b52886b08b8 Mon Sep 17 00:00:00 2001 From: heyabinghyb Date: Thu, 16 May 2024 10:28:21 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=83=A8=E5=88=86=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heyabinghyb --- frameworks/native/audioutils/src/audio_utils.cpp | 5 +++-- .../server/src/service/manager/audio_adapter_manager.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frameworks/native/audioutils/src/audio_utils.cpp b/frameworks/native/audioutils/src/audio_utils.cpp index 0acc2c8095..faeb6925a7 100644 --- a/frameworks/native/audioutils/src/audio_utils.cpp +++ b/frameworks/native/audioutils/src/audio_utils.cpp @@ -587,7 +587,8 @@ void DumpFileUtil::OpenDumpFile(std::string para, std::string fileName, FILE **f if (para == DUMP_SERVER_PARA) { if (fileName == DUMP_BLUETOOTH_RENDER_SINK_FILENAME || fileName == DUMP_RENDER_SINK_FILENAME || - fileName == DUMP_CAPTURER_SOURCE_FILENAME || fileName == DUMP_OFFLOAD_RENDER_SINK_FILENAME) { + fileName == DUMP_CAPTURER_SOURCE_FILENAME || fileName == DUMP_OFFLOAD_RENDER_SINK_FILENAME || + fileName.find("effect") != std::string::npos) { // special name for audio effect *file = DumpFileUtil::OpenDumpFileInner(para, fileName, AUDIO_PULSE); return; } @@ -612,7 +613,7 @@ static void MemcpyToI32FromI24(uint8_t *src, int32_t *dst, size_t count) for (size_t i = 0; i < count; i++) { uint8_t *tmp = src + 3 * i; // 3 is byte size of SAMPLE_S24LE; *(dst + i) = static_cast(tmp[2] << (2 * sizeof(uint8_t))) | - static_cast(tmp[1] << sizeof(uuint8_t)) | static_cast(tmp[0]); + static_cast(tmp[1] << sizeof(uint8_t)) | static_cast(tmp[0]); } } diff --git a/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp b/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp index 967673f232..17ee0eaebd 100644 --- a/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp +++ b/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp @@ -334,7 +334,7 @@ int32_t AudioAdapterManager::SetVolumeDb(AudioStreamType streamType) CHECK_AND_RETURN_RET_LOG(audioServiceAdapter_, ERR_OPERATION_FAILED, "SetSystemVolumeLevel audio adapter null"); - AUDIO_INFO_LOG("SetVolumeDb: streamType %{public}d, volumeDb %{public}f", streamType, volumeDb); + AUDIO_INFO_LOG("streamType:%{public}d volumeDb:%{public}f volume:%{public}d", streamType, volumeDb, volumeLevel); if (streamType == STREAM_VOICE_CALL || streamType == STREAM_VOICE_COMMUNICATION) { return SetVolumeDbForVolumeTypeGroup(VOICE_CALL_VOLUME_TYPE_LIST, volumeDb); } else if (streamType == STREAM_MUSIC) { -- Gitee From 7b9a95eacca8d5fdb31d0b09bcdc24a5b1e853e8 Mon Sep 17 00:00:00 2001 From: heyabinghyb Date: Thu, 16 May 2024 16:12:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: heyabinghyb --- .../audiocapturer/napi_audio_capturer.cpp | 3 ++- .../native/audioutils/src/audio_speed.cpp | 22 +++++++++++++++---- .../native/audioutils/src/audio_utils.cpp | 4 ++-- .../native/pulseaudio/modules/hdi/hdi_sink.c | 2 +- .../service/manager/audio_adapter_manager.cpp | 2 +- .../server/src/audio_effect_server.cpp | 7 +++--- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp b/frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp index 45dcabac1e..55806c40e5 100644 --- a/frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp +++ b/frameworks/js/napi/audiocapturer/napi_audio_capturer.cpp @@ -496,7 +496,8 @@ napi_value NapiAudioCapturer::GetAudioTime(napi_env env, napi_callback_info info Timestamp timestamp; if (napiAudioCapturer->audioCapturer_->GetAudioTime(timestamp, Timestamp::Timestampbase::MONOTONIC)) { const uint64_t secToNanosecond = 1000000000; - context->time = static_cast(timestamp.time.tv_nsec) + static_cast(imestamp.time.tv_sec) * secToNanosecond; + context->time = static_cast(timestamp.time.tv_nsec) + + static_cast(timestamp.time.tv_sec) * secToNanosecond; } else { context->SignError(NAPI_ERR_SYSTEM); } diff --git a/frameworks/native/audioutils/src/audio_speed.cpp b/frameworks/native/audioutils/src/audio_speed.cpp index dfe8443599..df886b4daf 100644 --- a/frameworks/native/audioutils/src/audio_speed.cpp +++ b/frameworks/native/audioutils/src/audio_speed.cpp @@ -136,13 +136,18 @@ int32_t AudioSpeed::ChangeSpeedFor24Bit(uint8_t *buffer, int32_t bufferSize, return ERR_MEMORY_ALLOC_FAILED; } float* bitTofloat = new(std::nothrow) float[bufferSize]; - if (!bitTofloat) - return ERROR; + if (!bitTofloat) { + AUDIO_ERR_LOG("bitTofloat nullptr, No memory"); + return ERR_MEMORY_ALLOC_FAILED; + } ConvertFrom24BitToFloat(bufferSize / formatSize_, buffer, bitTofloat); float* speedBuf = new(std::nothrow) float[MAX_BUFFER_SIZE]; - if (!speedBuf) - return ERROR; + if (!speedBuf) { + AUDIO_ERR_LOG("speedBuf nullptr, No memory"); + delete [] bitTofloat; + return ERR_MEMORY_ALLOC_FAILED; + } int32_t ret = ChangeSpeedForFloat(bitTofloat, bufferSize, speedBuf, outBufferSize); ConvertFromFloatTo24Bit(outBufferSize / formatSize_, speedBuf, outBuffer.get()); @@ -161,9 +166,18 @@ int32_t AudioSpeed::ChangeSpeedFor32Bit(uint8_t *buffer, int32_t bufferSize, return ERR_MEMORY_ALLOC_FAILED; } float* bitTofloat = new(std::nothrow) float[bufferSize]; + if (!bitTofloat) { + AUDIO_ERR_LOG("bitTofloat nullptr, No memory"); + return ERR_MEMORY_ALLOC_FAILED; + } ConvertFrom32BitToFloat(bufferSize / formatSize_, reinterpret_cast(buffer), bitTofloat); float* speedBuf = new(std::nothrow) float[MAX_BUFFER_SIZE]; + if (!speedBuf) { + AUDIO_ERR_LOG("speedBuf nullptr, No memory"); + delete [] bitTofloat; + return ERR_MEMORY_ALLOC_FAILED; + } int32_t ret = ChangeSpeedForFloat(bitTofloat, bufferSize, speedBuf, outBufferSize); ConvertFromFloatTo32Bit(outBufferSize / formatSize_, speedBuf, reinterpret_cast(outBuffer.get())); diff --git a/frameworks/native/audioutils/src/audio_utils.cpp b/frameworks/native/audioutils/src/audio_utils.cpp index faeb6925a7..d793227df7 100644 --- a/frameworks/native/audioutils/src/audio_utils.cpp +++ b/frameworks/native/audioutils/src/audio_utils.cpp @@ -612,8 +612,8 @@ static void MemcpyToI32FromI24(uint8_t *src, int32_t *dst, size_t count) { for (size_t i = 0; i < count; i++) { uint8_t *tmp = src + 3 * i; // 3 is byte size of SAMPLE_S24LE; - *(dst + i) = static_cast(tmp[2] << (2 * sizeof(uint8_t))) | - static_cast(tmp[1] << sizeof(uint8_t)) | static_cast(tmp[0]); + *(dst + i) = static_cast(tmp[2] << (2 * sizeof(uint8_t))) | + static_cast(tmp[1] << sizeof(uint8_t)) | static_cast(tmp[0]); } } diff --git a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c index d443c17d79..3702933c76 100644 --- a/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c +++ b/frameworks/native/pulseaudio/modules/hdi/hdi_sink.c @@ -2782,7 +2782,7 @@ static void ThreadFuncRendererTimerMultiChannel(void *userdata) pa_usec_t now = 0; - int sleepForUsec = -1; + int64_t sleepForUsec = -1; bool flag = ThreadFuncRendererTimerMultiChannelFlagJudge(u); if (flag) { diff --git a/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp b/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp index 17ee0eaebd..8c8d3a7bd0 100644 --- a/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp +++ b/services/audio_policy/server/src/service/manager/audio_adapter_manager.cpp @@ -1517,7 +1517,7 @@ uint32_t AudioAdapterManager::GetPositionInVolumePoints(std::vector int32_t rightPos = volumePoints.size() - 1; while (leftPos <= rightPos) { int32_t midPos = leftPos + (rightPos - leftPos)/NUMBER_TWO; - uint32_t c = volumePoints[midPos].index - idx; + int32_t c = volumePoints[midPos].index - idx; if (c == 0) { leftPos = midPos; break; diff --git a/services/audio_service/server/src/audio_effect_server.cpp b/services/audio_service/server/src/audio_effect_server.cpp index 5f297e3625..bbdd4626ac 100644 --- a/services/audio_service/server/src/audio_effect_server.cpp +++ b/services/audio_service/server/src/audio_effect_server.cpp @@ -56,13 +56,12 @@ static bool LoadLibrary(const std::string &relativePath, std::shared_ptr PATH_MAX) || !resultpath) { AUDIO_ERR_LOG(" realpath lib %{public}s Fail", relativePath.c_str()); return false; } - free(realPathRes); void* handle = dlopen(absolutePath.c_str(), 1); if (!handle) { -- Gitee