From fd568c75416cc345071fa481539557f12369ad74 Mon Sep 17 00:00:00 2001 From: saga Date: Sat, 20 Apr 2024 17:14:55 +0800 Subject: [PATCH] add voip lowlatency Signed-off-by: saga --- common/include/daudio_constants.h | 1 - services/audiomanager/managersource/src/dmic_dev.cpp | 8 ++++---- services/audiomanager/managersource/src/dspeaker_dev.cpp | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/common/include/daudio_constants.h b/common/include/daudio_constants.h index 6034fc0b..1f9cf97d 100644 --- a/common/include/daudio_constants.h +++ b/common/include/daudio_constants.h @@ -66,7 +66,6 @@ constexpr uint32_t DAUDIO_MAX_RECV_DATA_LEN = 104857600; constexpr uint32_t DAUDIO_MAX_JSON_LEN = 1024; static constexpr int64_t AUDIO_OFFSET_FRAME_NUM = 10; -static constexpr int64_t LOW_LATENCY_INTERVAL_NS = 5000000; static constexpr int64_t LOW_LATENCY_CLIENT_INTERVAL_NS = 20000000; static constexpr int64_t MAX_TIME_INTERVAL_US = 23000; diff --git a/services/audiomanager/managersource/src/dmic_dev.cpp b/services/audiomanager/managersource/src/dmic_dev.cpp index ddf186d2..26ae3273 100644 --- a/services/audiomanager/managersource/src/dmic_dev.cpp +++ b/services/audiomanager/managersource/src/dmic_dev.cpp @@ -386,11 +386,11 @@ void DMicDev::EnqueueThread() { writeIndex_ = 0; writeNum_ = 0; - DHLOGD("Enqueue thread start, lengthPerWrite length: %{public}d.", lengthPerTrans_); + int64_t timeIntervalns = paramHDF_.period * AUDIO_NS_PER_SECOND / AUDIO_MS_PER_SECOND; + DHLOGD("Enqueue thread start, lengthPerWrite length: %{public}d, interval: %{public}d.", lengthPerTrans_, paramHDF_.period); FillJitterQueue(); while (ashmem_ != nullptr && isEnqueueRunning_.load()) { - int64_t timeOffset = UpdateTimeOffset(frameIndex_, LOW_LATENCY_INTERVAL_NS, - startTime_); + int64_t timeOffset = UpdateTimeOffset(frameIndex_, timeIntervalns, startTime_); DHLOGD("Write frameIndex: %{public}" PRId64", timeOffset: %{public}" PRId64, frameIndex_, timeOffset); std::shared_ptr audioData = nullptr; { @@ -422,7 +422,7 @@ void DMicDev::EnqueueThread() writeNum_ += static_cast(CalculateSampleNum(param_.comParam.sampleRate, timeInterval_)); GetCurrentTime(writeTvSec_, writeTvNSec_); frameIndex_++; - AbsoluteSleep(startTime_ + frameIndex_ * LOW_LATENCY_INTERVAL_NS - timeOffset); + AbsoluteSleep(startTime_ + frameIndex_ * timeIntervalns - timeOffset); } } diff --git a/services/audiomanager/managersource/src/dspeaker_dev.cpp b/services/audiomanager/managersource/src/dspeaker_dev.cpp index 4a810487..0b15d1b8 100644 --- a/services/audiomanager/managersource/src/dspeaker_dev.cpp +++ b/services/audiomanager/managersource/src/dspeaker_dev.cpp @@ -371,10 +371,10 @@ void DSpeakerDev::EnqueueThread() readIndex_ = 0; readNum_ = 0; frameIndex_ = 0; - DHLOGI("Enqueue thread start, lengthPerRead length: %{public}d.", lengthPerTrans_); + int64_t timeIntervalns = paramHDF_.period * AUDIO_NS_PER_SECOND / AUDIO_MS_PER_SECOND; + DHLOGI("Enqueue thread start, lengthPerRead length: %{public}d, interval: %{pubic}d.", lengthPerTrans_, paramHDF_.period); while (ashmem_ != nullptr && isEnqueueRunning_.load()) { - int64_t timeOffset = UpdateTimeOffset(frameIndex_, LOW_LATENCY_INTERVAL_NS, - startTime_); + int64_t timeOffset = UpdateTimeOffset(frameIndex_, timeIntervalns, startTime_); DHLOGD("Read frameIndex: %{public}" PRId64", timeOffset: %{public}" PRId64, frameIndex_, timeOffset); auto readData = ashmem_->ReadFromAshmem(lengthPerTrans_, readIndex_); DHLOGI("Read from ashmem success! read index: %{public}d, readLength: %{public}d.", @@ -403,7 +403,7 @@ void DSpeakerDev::EnqueueThread() readNum_ += static_cast(CalculateSampleNum(param_.comParam.sampleRate, timeInterval_)); GetCurrentTime(readTvSec_, readTvNSec_); frameIndex_++; - AbsoluteSleep(startTime_ + frameIndex_ * LOW_LATENCY_INTERVAL_NS - timeOffset); + AbsoluteSleep(startTime_ + frameIndex_ * timeIntervalns - timeOffset); } } -- Gitee