From 0c07301b51c987afc35e74e5112887bdf1b8005d Mon Sep 17 00:00:00 2001 From: kw Date: Fri, 5 Sep 2025 11:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=8E=E6=97=B6=E5=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=8F=8C=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kw --- .../native/audiocommon/include/audio_info.h | 2 + .../native/audiocommon/include/audio_log.h | 7 + .../server/include/audio_endpoint.h | 3 +- .../server/include/audio_endpoint_private.h | 10 +- .../server/include/audio_service.h | 14 +- .../server/include/i_renderer_stream.h | 3 + .../server/src/audio_endpoint.cpp | 69 ++++++--- .../server/src/audio_service.cpp | 133 ++++++++++++++---- .../src/audio_endpoint_unit_test.cpp | 40 ++++++ .../src/audio_server_unit_test.cpp | 4 +- .../test/unittest/audio_service_unit_test.cpp | 9 +- .../audio_service_fuzzer.cpp | 2 - 12 files changed, 233 insertions(+), 63 deletions(-) diff --git a/interfaces/inner_api/native/audiocommon/include/audio_info.h b/interfaces/inner_api/native/audiocommon/include/audio_info.h index eddf0afee9..a6d3811d8c 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_info.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_info.h @@ -78,6 +78,8 @@ constexpr uint64_t AUDIO_MS_PER_S = 1000; constexpr uint64_t MAX_CBBUF_IN_USEC = 100000; constexpr uint64_t MIN_CBBUF_IN_USEC = 20000; +constexpr int32_t FAST_DUAL_CAP_ID = 100000; + const float MIN_FLOAT_VOLUME = 0.0f; const float MAX_FLOAT_VOLUME = 1.0f; diff --git a/interfaces/inner_api/native/audiocommon/include/audio_log.h b/interfaces/inner_api/native/audiocommon/include/audio_log.h index 3e0ce2b824..38a0ce0acb 100644 --- a/interfaces/inner_api/native/audiocommon/include/audio_log.h +++ b/interfaces/inner_api/native/audiocommon/include/audio_log.h @@ -116,6 +116,13 @@ } \ } else void (0) +#define JUDGE_AND_WARNING_LOG(cond, fmt, ...) \ + if (1) { \ + if (cond) { \ + AUDIO_WARNING_LOG(fmt, ##__VA_ARGS__); \ + } \ + } else void (0) + #ifndef OHOS_DEBUG #define DECORATOR_PRERELEASE_HILOG(op, fmt, args...) \ do { \ diff --git a/services/audio_service/server/include/audio_endpoint.h b/services/audio_service/server/include/audio_endpoint.h index 76086a49a3..9ec75f6c52 100644 --- a/services/audio_service/server/include/audio_endpoint.h +++ b/services/audio_service/server/include/audio_endpoint.h @@ -82,7 +82,8 @@ public: virtual void Release() = 0; virtual bool ShouldInnerCap(int32_t innerCapId) = 0; - virtual int32_t EnableFastInnerCap(int32_t innerCapId) = 0; + virtual int32_t EnableFastInnerCap(int32_t innerCapId, + const std::optional &dualDeviceName = std::nullopt) = 0; virtual int32_t DisableFastInnerCap() = 0; virtual int32_t DisableFastInnerCap(int32_t innerCapId) = 0; diff --git a/services/audio_service/server/include/audio_endpoint_private.h b/services/audio_service/server/include/audio_endpoint_private.h index 2cac6d59ff..b933d7ae31 100644 --- a/services/audio_service/server/include/audio_endpoint_private.h +++ b/services/audio_service/server/include/audio_endpoint_private.h @@ -102,11 +102,12 @@ public: // for inner-cap bool ShouldInnerCap(int32_t innerCapId) override; - int32_t EnableFastInnerCap(int32_t innerCapId) override; + int32_t EnableFastInnerCap(int32_t innerCapId, + const std::optional &dualDeviceName = std::nullopt) override; int32_t DisableFastInnerCap() override; int32_t DisableFastInnerCap(int32_t innerCapId) override; - int32_t InitDupStream(int32_t innerCapId); + int32_t InitDupStream(int32_t innerCapId, const std::optional &dualDeviceName = std::nullopt); EndpointStatus GetStatus() override; @@ -225,6 +226,11 @@ private: bool NeedUseTempBuffer(const RingBufferWrapper &ringBuffer, size_t spanSizeInByte); void PrepareStreamDataBuffer(size_t i, size_t spanSizeInByte, RingBufferWrapper &ringBuffer, AudioStreamData &streamData); + int32_t WriteDupBufferInnerForWriteModeInner(const BufferDesc &bufferDesc, int32_t innerCapId); + int32_t WriteDupBufferInnerForCallbackModeInner(const BufferDesc &bufferDesc, int32_t innerCapId); + + static bool IsDupRenderCallbackMode(int32_t engineFlag, bool isDualStream); + static bool IsDualStream(const CaptureInfo &capInfo); private: static constexpr int64_t ONE_MILLISECOND_DURATION = 1000000; // 1ms static constexpr int64_t TWO_MILLISECOND_DURATION = 2000000; // 2ms diff --git a/services/audio_service/server/include/audio_service.h b/services/audio_service/server/include/audio_service.h index 92a6a1ab3e..d11ddc3a16 100644 --- a/services/audio_service/server/include/audio_service.h +++ b/services/audio_service/server/include/audio_service.h @@ -207,8 +207,15 @@ private: #ifdef SUPPORT_LOW_LATENCY sptr GetProcessInServerBySessionId(const uint32_t sessionId); int32_t GetPrivacyTypeForFastStream(const uint32_t sessionId, AudioPrivacyType &privacyType); + int32_t EnableDualStreamForFastStream(const uint32_t sessionId, const std::string &dupSinkName); + int32_t DisableDualStreamForFastStream(const uint32_t sessionId); + std::vector, std::shared_ptr>> GetLinkedPairInner( + const uint32_t sessionId); + void HandleProcessInserverDualStreamDisableInner(AudioEndpoint &endpoint); + void HandleProcessInserverDualStreamEnableInner(AudioEndpoint &endpoint, const std::string &dupSinkName); #endif - + int32_t EnableDualStreamForNormalStream(const uint32_t sessionId, const std::string &dupSinkName); + int32_t DisableDualStreamForNormalStream(const uint32_t sessionId); private: std::mutex foregroundSetMutex_; std::set foregroundSet_; @@ -237,7 +244,6 @@ private: // for inner-capturer bool isRegisterCapturerFilterListened_ = false; bool isDefaultAdapterEnable_ = false; - uint32_t workingDualToneId_ = 0; // invalid sessionId AudioPlaybackCaptureConfig workingConfig_; std::unordered_map workingConfigs_; @@ -249,8 +255,6 @@ private: std::map> allRendererMap_ = {}; std::map> allCapturerMap_ = {}; - std::vector> filteredDualToneRendererMap_ = {}; - std::mutex mutedSessionsMutex_; std::set mutedSessions_ = {}; int32_t currentRendererStreamCnt_ = 0; @@ -268,6 +272,8 @@ private: std::map muteStateMap_{}; std::mutex musicOrVoipSystemVolumeMutex_; float musicOrVoipSystemVolume_ = 0.0f; + + std::mutex dualStreamMutex_; }; } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/server/include/i_renderer_stream.h b/services/audio_service/server/include/i_renderer_stream.h index 7be568f339..0de78b947b 100644 --- a/services/audio_service/server/include/i_renderer_stream.h +++ b/services/audio_service/server/include/i_renderer_stream.h @@ -16,6 +16,8 @@ #ifndef I_RENDERER_STREAM_H #define I_RENDERER_STREAM_H +#include + #include "i_stream.h" #include "audio_stream_info.h" #include "i_hpae_soft_link.h" @@ -78,6 +80,7 @@ public: struct CaptureInfo { std::atomic isInnerCapEnabled = false; std::shared_ptr dupStream = nullptr; + std::optional dualDeviceName = std::nullopt; }; struct SoftLinkInfo { diff --git a/services/audio_service/server/src/audio_endpoint.cpp b/services/audio_service/server/src/audio_endpoint.cpp index 7425b93b76..0faa3d38ae 100644 --- a/services/audio_service/server/src/audio_endpoint.cpp +++ b/services/audio_service/server/src/audio_endpoint.cpp @@ -216,7 +216,7 @@ AudioProcessConfig AudioEndpointInner::GetInnerCapConfig() return processConfig; } -int32_t AudioEndpointInner::InitDupStream(int32_t innerCapId) +int32_t AudioEndpointInner::InitDupStream(int32_t innerCapId, const std::optional &dualDeviceName) { std::lock_guard lock(dupMutex_); bool hasEnabled = (fastCaptureInfos_.count(innerCapId) && fastCaptureInfos_[innerCapId].isInnerCapEnabled); @@ -225,7 +225,10 @@ int32_t AudioEndpointInner::InitDupStream(int32_t innerCapId) AudioProcessConfig processConfig = GetInnerCapConfig(); processConfig.innerCapId = innerCapId; auto &captureInfo = fastCaptureInfos_[innerCapId]; - int32_t ret = IStreamManager::GetDupPlaybackManager().CreateRender(processConfig, captureInfo.dupStream); + captureInfo.dualDeviceName = dualDeviceName; + IStreamManager &iStreamManager = dualDeviceName.has_value() ? + IStreamManager::GetDualPlaybackManager() : IStreamManager::GetDupPlaybackManager(); + int32_t ret = iStreamManager.CreateRender(processConfig, captureInfo.dupStream, dualDeviceName); CHECK_AND_RETURN_RET_LOG(ret == SUCCESS && captureInfo.dupStream != nullptr, ERR_OPERATION_FAILED, "Failed: %{public}d", ret); uint32_t dupStreamIndex = captureInfo.dupStream->GetStreamIndex(); @@ -256,9 +259,7 @@ int32_t AudioEndpointInner::InitDupStream(int32_t innerCapId) CHECK_AND_RETURN_RET_LOG(dupBufferSize_ < dstAudioBuffer_->GetDataSize(), ERR_OPERATION_FAILED, "Init buffer fail"); dupBuffer_ = std::make_unique(dupBufferSize_); ret = memset_s(reinterpret_cast(dupBuffer_.get()), dupBufferSize_, 0, dupBufferSize_); - if (ret != EOK) { - AUDIO_WARNING_LOG("memset buffer fail, ret %{public}d", ret); - } + JUDGE_AND_WARNING_LOG(ret != EOK, "memset buffer fail, ret %{public}d", ret); if (endpointStatus_ == RUNNING || (endpointStatus_ == IDEL && isDeviceRunningInIdel_)) { int32_t audioId = deviceInfo_.deviceId_; @@ -296,10 +297,10 @@ int32_t AudioEndpointInner::InitDupBuffer(AudioProcessConfig processConfig, int3 return SUCCESS; } -int32_t AudioEndpointInner::EnableFastInnerCap(int32_t innerCapId) +int32_t AudioEndpointInner::EnableFastInnerCap(int32_t innerCapId, const std::optional &dualDeviceName) { CHECK_AND_RETURN_RET_LOG(deviceInfo_.deviceRole_ == OUTPUT_DEVICE, ERR_INVALID_OPERATION, "Not output device!"); - int32_t ret = InitDupStream(innerCapId); + int32_t ret = InitDupStream(innerCapId, dualDeviceName); CHECK_AND_RETURN_RET_LOG(ret == SUCCESS, ERR_OPERATION_FAILED, "Init dup stream failed!"); return SUCCESS; } @@ -354,7 +355,9 @@ int32_t AudioEndpointInner::HandleDisableFastCap(CaptureInfo &captureInfo) AudioVolume::GetInstance()->RemoveStreamVolume(dupStreamIndex); } } - IStreamManager::GetDupPlaybackManager().ReleaseRender(captureInfo.dupStream->GetStreamIndex()); + IStreamManager &iStreamManager = captureInfo.dualDeviceName.has_value() ? + IStreamManager::GetDualPlaybackManager() : IStreamManager::GetDupPlaybackManager(); + iStreamManager.ReleaseRender(captureInfo.dupStream->GetStreamIndex()); captureInfo.dupStream = nullptr; return SUCCESS; } @@ -1244,13 +1247,9 @@ void AudioEndpointInner::MixToDupStream(const std::vector &srcD dstStream.bufferDesc = temp; FormatConverter::DataAccumulationFromVolume(tempList, dstStream); - int32_t ret; - if (GetEngineFlag() == 1) { - WriteDupBufferInner(temp, innerCapId); - } else { - ret = fastCaptureInfos_[innerCapId].dupStream->EnqueueBuffer(temp); - CHECK_AND_RETURN_LOG(ret == SUCCESS, "EnqueueBuffer failed:%{public}d", ret); - } + int32_t ret = WriteDupBufferInner(temp, innerCapId); + bool isCallbackMode = IsDupRenderCallbackMode(GetEngineFlag(), IsDualStream(fastCaptureInfos_[innerCapId])); + CHECK_AND_RETURN_LOG(isCallbackMode || ret >= 0, "EnqueueBuffer failed:%{public}d", ret); ret = memset_s(reinterpret_cast(dupBuffer_.get()), dupBufferSize_, 0, dupBufferSize_); if (ret != EOK) { @@ -1613,11 +1612,7 @@ void AudioEndpointInner::ProcessToDupStream(const std::vector & dstStreamData.bufferDesc = temp; HandleRendererDataParams(audioDataList[0], dstStreamData, false); - if (GetEngineFlag() == 1) { - WriteDupBufferInner(temp, innerCapId); - } else { - fastCaptureInfos_[innerCapId].dupStream->EnqueueBuffer(temp); - } + WriteDupBufferInner(temp, innerCapId); } } else { MixToDupStream(audioDataList, innerCapId); @@ -2311,7 +2306,7 @@ int32_t AudioEndpointInner::CreateDupBufferInner(int32_t innerCapId) return SUCCESS; } -int32_t AudioEndpointInner::WriteDupBufferInner(const BufferDesc &bufferDesc, int32_t innerCapId) +int32_t AudioEndpointInner::WriteDupBufferInnerForCallbackModeInner(const BufferDesc &bufferDesc, int32_t innerCapId) { size_t targetSize = bufferDesc.bufLength; @@ -2338,7 +2333,7 @@ int32_t AudioEndpointInner::WriteDupBufferInner(const BufferDesc &bufferDesc, in } DumpFileUtil::WriteDumpFile(dumpDupIn_, static_cast(bufferDesc.buffer), writeSize); } - return SUCCESS; + return writeSize; } void AudioEndpointInner::CheckAudioHapticsSync(uint64_t curWritePos) @@ -2355,5 +2350,35 @@ void AudioEndpointInner::CheckAudioHapticsSync(uint64_t curWritePos) audioHapticsSyncId_ = 0; } } + +bool AudioEndpointInner::IsDupRenderCallbackMode(int32_t engineFlag, bool isDualStream) +{ + if (engineFlag == 1 && !isDualStream) { + return true; + } + + return false; +} + +bool AudioEndpointInner::IsDualStream(const CaptureInfo &capInfo) +{ + if (capInfo.dualDeviceName.has_value()) { + return true; + } else { + return false; + } +} + +int32_t AudioEndpointInner::WriteDupBufferInnerForWriteModeInner(const BufferDesc &bufferDesc, int32_t innerCapId) +{ + return fastCaptureInfos_[innerCapId].dupStream->EnqueueBuffer(bufferDesc); +} + +int32_t AudioEndpointInner::WriteDupBufferInner(const BufferDesc &bufferDesc, int32_t innerCapId) +{ + bool isCallbackMode = IsDupRenderCallbackMode(GetEngineFlag(), IsDualStream(fastCaptureInfos_[innerCapId])); + return isCallbackMode ? WriteDupBufferInnerForCallbackModeInner(bufferDesc, innerCapId) : + WriteDupBufferInnerForWriteModeInner(bufferDesc, innerCapId); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/server/src/audio_service.cpp b/services/audio_service/server/src/audio_service.cpp index fbc7bf3e6d..89945c736c 100644 --- a/services/audio_service/server/src/audio_service.cpp +++ b/services/audio_service/server/src/audio_service.cpp @@ -112,6 +112,7 @@ int32_t AudioService::OnProcessRelease(IAudioProcessStream *process, bool isSwit RemoveIdFromMuteControlSet((*paired).first->GetSessionId()); } ret = UnlinkProcessToEndpoint((*paired).first, (*paired).second); + HandleProcessInserverDualStreamDisableInner(*(paired->second)); if ((*paired).second->GetStatus() == AudioEndpoint::EndpointStatus::UNLINKED) { needRelease = true; endpointName = (*paired).second->GetEndpointName(); @@ -890,38 +891,33 @@ int32_t AudioService::OnUpdateInnerCapList(int32_t innerCapId) } #endif -int32_t AudioService::EnableDualStream(const uint32_t sessionId, const std::string &dupSinkName) +int32_t AudioService::EnableDualStreamForNormalStream(const uint32_t sessionId, const std::string &dupSinkName) { - workingDualToneId_ = sessionId; AUDIO_INFO_LOG("sessionId is %{public}d", sessionId); - std::unique_lock lock(rendererMapMutex_); - for (auto it = allRendererMap_.begin(); it != allRendererMap_.end(); it++) { - std::shared_ptr renderer = it->second.lock(); - if (renderer == nullptr) { - AUDIO_WARNING_LOG("Renderer is already released!"); - continue; - } - if (ShouldBeDualTone(renderer->processConfig_, dupSinkName)) { - renderer->EnableDualTone(dupSinkName); - filteredDualToneRendererMap_.push_back(renderer); - } - } + std::lock_guard lock(rendererMapMutex_); + + CHECK_AND_RETURN_RET(allRendererMap_.count(sessionId) > 0, ERR_OPERATION_FAILED); + auto weakRenderer = allRendererMap_[sessionId]; + auto renderer = weakRenderer.lock(); + + CHECK_AND_RETURN_RET_LOG(renderer != nullptr, ERR_OPERATION_FAILED, "renderer is null"); + CHECK_AND_RETURN_RET(ShouldBeDualTone(renderer->processConfig_, dupSinkName), SUCCESS); + + renderer->EnableDualTone(dupSinkName); return SUCCESS; } -int32_t AudioService::DisableDualStream(const uint32_t sessionId) +int32_t AudioService::DisableDualStreamForNormalStream(const uint32_t sessionId) { AUDIO_INFO_LOG("disable dual tone, sessionId is %{public}d", sessionId); - std::unique_lock lock(rendererMapMutex_); - for (size_t i = 0; i < filteredDualToneRendererMap_.size(); i++) { - std::shared_ptr renderer = filteredDualToneRendererMap_[i].lock(); - if (renderer == nullptr) { - AUDIO_WARNING_LOG("Renderer is already released!"); - continue; - } - renderer->DisableDualTone(); - } - filteredDualToneRendererMap_.clear(); + std::lock_guard lock(rendererMapMutex_); + + CHECK_AND_RETURN_RET(allRendererMap_.count(sessionId) > 0, ERR_OPERATION_FAILED); + auto weakRenderer = allRendererMap_[sessionId]; + auto renderer = weakRenderer.lock(); + + CHECK_AND_RETURN_RET_LOG(renderer != nullptr, ERR_OPERATION_FAILED, "renderer is null"); + renderer->DisableDualTone(); return SUCCESS; } @@ -1993,5 +1989,92 @@ int32_t AudioService::GetPrivacyType(const uint32_t sessionId, AudioPrivacyType AUDIO_ERR_LOG("%{public}u not found", sessionId); return ERROR; } + +#ifdef SUPPORT_LOW_LATENCY +std::vector, std::shared_ptr>> AudioService::GetLinkedPairInner( + const uint32_t sessionId) +{ + std::vector, std::shared_ptr>> retVector; + for (const auto &[processInServer, endpoint] : linkedPairedList_) { + CHECK_AND_CONTINUE(processInServer != nullptr); + CHECK_AND_CONTINUE(endpoint != nullptr); + CHECK_AND_CONTINUE(processInServer->GetSessionId() == sessionId); + retVector.push_back({processInServer, endpoint}); + } + return retVector; +} + +void AudioService::HandleProcessInserverDualStreamDisableInner(AudioEndpoint &endpoint) +{ + bool enableDualStream = endpoint.ShouldInnerCap(FAST_DUAL_CAP_ID); + CHECK_AND_RETURN(!enableDualStream); + endpoint.DisableFastInnerCap(FAST_DUAL_CAP_ID); +} + +void AudioService::HandleProcessInserverDualStreamEnableInner(AudioEndpoint &endpoint, const std::string &dupSinkName) +{ + bool enableDualStream = endpoint.ShouldInnerCap(FAST_DUAL_CAP_ID); + CHECK_AND_RETURN(enableDualStream); + endpoint.EnableFastInnerCap(FAST_DUAL_CAP_ID, dupSinkName); +} + +int32_t AudioService::EnableDualStreamForFastStream(const uint32_t sessionId, const std::string &dupSinkName) +{ + std::lock_guard lock(processListMutex_); + auto linkedPairs = GetLinkedPairInner(sessionId); + CHECK_AND_RETURN_RET_LOG(!linkedPairs.empty(), ERR_OPERATION_FAILED, "%{public}u not found", sessionId); + + for (const auto &[processInServer, endpoint] : linkedPairs) { + processInServer->SetInnerCapState(true, FAST_DUAL_CAP_ID); + HandleProcessInserverDualStreamEnableInner(*endpoint, dupSinkName); + } + + return SUCCESS; +} + +int32_t AudioService::DisableDualStreamForFastStream(const uint32_t sessionId) +{ + std::lock_guard lock(processListMutex_); + auto linkedPairs = GetLinkedPairInner(sessionId); + CHECK_AND_RETURN_RET_LOG(!linkedPairs.empty(), ERR_OPERATION_FAILED, "%{public}u not found", sessionId); + + for (const auto &[processInServer, endpoint] : linkedPairs) { + processInServer->SetInnerCapState(false, FAST_DUAL_CAP_ID); + HandleProcessInserverDualStreamDisableInner(*endpoint); + } + + return SUCCESS; +} +#endif + +int32_t AudioService::EnableDualStream(const uint32_t sessionId, const std::string &dupSinkName) +{ + std::lock_guard lock(dualStreamMutex_); + int32_t ret = EnableDualStreamForNormalStream(sessionId, dupSinkName); + CHECK_AND_RETURN_RET(ret != SUCCESS, ret); + +#ifdef SUPPORT_LOW_LATENCY + ret = EnableDualStreamForFastStream(sessionId, dupSinkName); + CHECK_AND_RETURN_RET(ret != SUCCESS, ret); +#endif + + AUDIO_ERR_LOG("%{public}u failed", sessionId); + return ERR_OPERATION_FAILED; +} + +int32_t AudioService::DisableDualStream(const uint32_t sessionId) +{ + std::lock_guard lock(dualStreamMutex_); + int32_t ret = DisableDualStreamForNormalStream(sessionId); + CHECK_AND_RETURN_RET(ret != SUCCESS, ret); + +#ifdef SUPPORT_LOW_LATENCY + ret = DisableDualStreamForFastStream(sessionId); + CHECK_AND_RETURN_RET(ret != SUCCESS, ret); +#endif + + AUDIO_ERR_LOG("%{public}u failed", sessionId); + return ERR_OPERATION_FAILED; +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/test/unittest/audio_endpoint_unit_test/src/audio_endpoint_unit_test.cpp b/services/audio_service/test/unittest/audio_endpoint_unit_test/src/audio_endpoint_unit_test.cpp index 8fc631448a..bca0856341 100644 --- a/services/audio_service/test/unittest/audio_endpoint_unit_test/src/audio_endpoint_unit_test.cpp +++ b/services/audio_service/test/unittest/audio_endpoint_unit_test/src/audio_endpoint_unit_test.cpp @@ -1303,5 +1303,45 @@ HWTEST_F(AudioEndpointUnitTest, CheckPlaySignal_004, TestSize.Level1) audioEndpointInner->CheckPlaySignal(buffer, 10); EXPECT_EQ(1000, audioEndpointInner->detectedTime_); } + +/* + * @tc.name : Test IsDupRenderCallbackMode API + * @tc.type : FUNC + * @tc.number: IsDupRenderCallbackMode_001 + * @tc.desc : Test IsDupRenderCallbackMode interface + */ +HWTEST(AudioEndpointInnerUnitTest, IsDupRenderCallbackMode_001, TestSize.Level1) +{ + EXPECT_EQ(AudioEndpointInner::IsDupRenderCallbackMode(1, true), false); + EXPECT_EQ(AudioEndpointInner::IsDupRenderCallbackMode(1, false), true); + EXPECT_EQ(AudioEndpointInner::IsDupRenderCallbackMode(0, true), false); + EXPECT_EQ(AudioEndpointInner::IsDupRenderCallbackMode(0, false), false); +} + +/* + * @tc.name : Test IsDupRenderCallbackMode API + * @tc.type : FUNC + * @tc.number: IsDualStream_001 + * @tc.desc : Test IsDualStream interface + */ +HWTEST(AudioEndpointInnerUnitTest, IsDualStream_001, TestSize.Level1) +{ + CaptureInfo capInfo = { + .dualDeviceName = "Speaker" + }; + EXPECT_EQ(AudioEndpointInner::IsDualStream(capInfo), true); +} + +/* + * @tc.name : Test IsDupRenderCallbackMode API + * @tc.type : FUNC + * @tc.number: IsDualStream_002 + * @tc.desc : Test IsDualStream interface + */ +HWTEST(AudioEndpointInnerUnitTest, IsDualStream_002, TestSize.Level1) +{ + CaptureInfo capInfo; + EXPECT_EQ(AudioEndpointInner::IsDualStream(capInfo), false); +} } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_service/test/unittest/audio_server_unit_test/src/audio_server_unit_test.cpp b/services/audio_service/test/unittest/audio_server_unit_test/src/audio_server_unit_test.cpp index 6a02ba2a27..566f6e4e98 100644 --- a/services/audio_service/test/unittest/audio_server_unit_test/src/audio_server_unit_test.cpp +++ b/services/audio_service/test/unittest/audio_server_unit_test/src/audio_server_unit_test.cpp @@ -833,10 +833,10 @@ HWTEST_F(AudioServerUnitTest, AudioServerUpdateDualToneState_001, TestSize.Level EXPECT_NE(nullptr, audioServer); int32_t ret = audioServer->UpdateDualToneState(false, 123); - EXPECT_EQ(SUCCESS, ret); + EXPECT_NE(SUCCESS, ret); ret = audioServer->UpdateDualToneState(true, 123); - EXPECT_EQ(SUCCESS, ret); + EXPECT_NE(SUCCESS, ret); } #endif diff --git a/services/audio_service/test/unittest/audio_service_unit_test.cpp b/services/audio_service/test/unittest/audio_service_unit_test.cpp index 3fd85cfeb7..add2a5fc95 100644 --- a/services/audio_service/test/unittest/audio_service_unit_test.cpp +++ b/services/audio_service/test/unittest/audio_service_unit_test.cpp @@ -623,9 +623,9 @@ HWTEST(AudioServiceUnitTest, AudioServiceOnInitInnerCapList_001, TestSize.Level1 floatRet = AudioService::GetInstance()->GetMaxAmplitude(false); EXPECT_EQ(0, floatRet); int32_t ret = AudioService::GetInstance()->EnableDualStream(MAX_STREAMID - 1, "Speaker"); - EXPECT_EQ(SUCCESS, ret); + EXPECT_NE(SUCCESS, ret); ret = AudioService::GetInstance()->DisableDualStream(MAX_STREAMID - 1); - EXPECT_EQ(SUCCESS, ret); + EXPECT_NE(SUCCESS, ret); AudioService::GetInstance()->ResetAudioEndpoint(); ret = AudioService::GetInstance()->OnProcessRelease(audioProcess, false); EXPECT_EQ(SUCCESS, ret); @@ -1460,7 +1460,7 @@ HWTEST(AudioServiceUnitTest, EnableDualStream_001, TestSize.Level1) int32_t sessionId = 1; audioService->allRendererMap_.insert(std::make_pair(sessionId, renderer)); int32_t ret = audioService->EnableDualStream(sessionId, "Speaker"); - EXPECT_EQ(ret, SUCCESS); + EXPECT_NE(ret, SUCCESS); } /** * @tc.name : Test DisableDualToneList API @@ -1472,10 +1472,9 @@ HWTEST(AudioServiceUnitTest, DisableDualToneList_001, TestSize.Level1) { AudioService *audioService = AudioService::GetInstance(); std::shared_ptr renderer = nullptr; - audioService->filteredDualToneRendererMap_.push_back(renderer); int32_t sessionId = 1; int32_t ret = audioService->DisableDualStream(sessionId); - EXPECT_EQ(ret, SUCCESS); + EXPECT_NE(ret, SUCCESS); } /** * @tc.name : Test UpdateAudioSinkState API diff --git a/test/fuzztest/audioservice_fuzzer/audio_service_fuzzer.cpp b/test/fuzztest/audioservice_fuzzer/audio_service_fuzzer.cpp index 91efa12dd4..6eb259c634 100644 --- a/test/fuzztest/audioservice_fuzzer/audio_service_fuzzer.cpp +++ b/test/fuzztest/audioservice_fuzzer/audio_service_fuzzer.cpp @@ -716,8 +716,6 @@ void AudioServiceDisableDualToneListFuzzTest() renderer = std::make_shared(processConfig, streamListener); } - audioService->filteredDualToneRendererMap_.clear(); - audioService->filteredDualToneRendererMap_.push_back(renderer); int32_t sessionId = GetData(); audioService->DisableDualStream(sessionId); } -- Gitee