From 3c63523f90f1ed65c846d025b02025761e3424d2 Mon Sep 17 00:00:00 2001 From: owenCreeper Date: Thu, 4 Sep 2025 17:41:33 +0800 Subject: [PATCH 1/6] fix sink input node Signed-off-by: owenCreeper --- .../node/include/hpae_sink_input_node.h | 7 +- .../node/src/hpae_offload_sinkoutput_node.cpp | 2 +- .../node/src/hpae_sink_input_node.cpp | 83 +++++++++---------- 3 files changed, 45 insertions(+), 47 deletions(-) diff --git a/services/audio_engine/node/include/hpae_sink_input_node.h b/services/audio_engine/node/include/hpae_sink_input_node.h index 3c6f5eff28..8166e24c81 100644 --- a/services/audio_engine/node/include/hpae_sink_input_node.h +++ b/services/audio_engine/node/include/hpae_sink_input_node.h @@ -43,10 +43,9 @@ public: bool Drain(); int32_t SetState(HpaeSessionState renderState); HpaeSessionState GetState(); - uint64_t GetFramesWritten(); int32_t GetCurrentPosition(uint64_t &framePosition, std::vector ×tamp); - int32_t RewindHistoryBuffer(uint64_t rewindTime, uint64_t hdiFramePosition = 0); + void RewindHistoryBuffer(uint64_t rewindTime, uint64_t hdiFramePosition = 0); void SetAppUid(int32_t appUid); int32_t GetAppUid(); @@ -57,9 +56,10 @@ public: float GetLoudnessGain(); void SetSpeed(float speed); float GetSpeed(); + uint32_t GetLatency(); bool isConnected_ = false; private: - int32_t GetDataFromSharedBuffer(); + int32_t OnStreamInfoChange(bool needata = true); void CheckAndDestroyHistoryBuffer(); bool ReadToAudioBuffer(int32_t &ret); std::weak_ptr writeCallback_; @@ -70,7 +70,6 @@ private: HpaePcmBuffer emptyAudioBuffer_; OutputPort outputStream_; std::vector interleveData_; - uint64_t framesWritten_; uint64_t totalFrames_; bool isDrain_ = false; HpaeSessionState state_ = HPAE_SESSION_NEW; diff --git a/services/audio_engine/node/src/hpae_offload_sinkoutput_node.cpp b/services/audio_engine/node/src/hpae_offload_sinkoutput_node.cpp index 3ff7034730..c6e3eac6da 100644 --- a/services/audio_engine/node/src/hpae_offload_sinkoutput_node.cpp +++ b/services/audio_engine/node/src/hpae_offload_sinkoutput_node.cpp @@ -354,8 +354,8 @@ void HpaeOffloadSinkOutputNode::StopStream() AUDIO_DEBUG_LOG("OffloadRewindAndFlush rewind time in us %{public}" PRIu64, rewindTime); auto callback = GetNodeInfo().statusCallback.lock(); CHECK_AND_RETURN_LOG(callback != nullptr, "HpaeOffloadSinkOutputNode::StopStream callback is null"); - callback->OnRewindAndFlush(rewindTime, hdiRealPos_); OffloadReset(); + callback->OnRewindAndFlush(rewindTime, hdiRealPos_); } void HpaeOffloadSinkOutputNode::SetPolicyState(int32_t state) diff --git a/services/audio_engine/node/src/hpae_sink_input_node.cpp b/services/audio_engine/node/src/hpae_sink_input_node.cpp index 0a5e589881..d68e68e0c9 100644 --- a/services/audio_engine/node/src/hpae_sink_input_node.cpp +++ b/services/audio_engine/node/src/hpae_sink_input_node.cpp @@ -35,6 +35,8 @@ const std::string DEVICE_CLASS_REMOTE_OFFLOAD = "remote_offload"; static constexpr uint32_t CUSTOM_SAMPLE_RATE_MULTIPLES = 50; static constexpr uint32_t FRAME_LEN_100MS = 100; static constexpr uint32_t FRAME_LEN_20MS = 20; +constexpr int32_t STANDBY_THRESHOLD = 9; // 9 standby is about 40ms + HpaeSinkInputNode::HpaeSinkInputNode(HpaeNodeInfo &nodeInfo) : HpaeNode(nodeInfo), pcmBufferInfo_(nodeInfo.channels, nodeInfo.frameLen, nodeInfo.customSampleRate == 0 ? nodeInfo.samplingRate : @@ -42,7 +44,7 @@ HpaeSinkInputNode::HpaeSinkInputNode(HpaeNodeInfo &nodeInfo) emptyBufferInfo_(nodeInfo.channels, 0, nodeInfo.customSampleRate == 0 ? nodeInfo.samplingRate : nodeInfo.customSampleRate, (uint64_t)nodeInfo.channelLayout), inputAudioBuffer_(pcmBufferInfo_), emptyAudioBuffer_(emptyBufferInfo_), outputStream_(this), - interleveData_(nodeInfo.frameLen * nodeInfo.channels * GetSizeFromFormat(nodeInfo.format)), framesWritten_(0), + interleveData_(nodeInfo.frameLen * nodeInfo.channels * GetSizeFromFormat(nodeInfo.format)), totalFrames_(0) { AUDIO_INFO_LOG("sinkinput sessionId %{public}d, channelcount %{public}d, channelLayout %{public}" PRIu64 ", " @@ -99,31 +101,12 @@ void HpaeSinkInputNode::CheckAndDestroyHistoryBuffer() int32_t HpaeSinkInputNode::GetDataFromSharedBuffer() { - streamInfo_ = {.hdiFramePosition = hdiFramePosition_.exchange(0), - .framesWritten = framesWritten_, - .latency = streamInfo_.latency, - .inputData = interleveData_.data(), - .requestDataLen = interleveData_.size(), - .deviceClass = GetDeviceClass(), - .deviceNetId = GetDeviceNetId(), - .needData = !(historyBuffer_ && historyBuffer_->GetCurFrames()), - // offload enbale, underrun 9 times, request force write data; 9 times about 40ms - .forceData = offloadEnable_ ? (standbyCounter_ > 9 ? true : false) : true}; - GetCurrentPosition(streamInfo_.framePosition, streamInfo_.timestamp); - auto writeCallback = writeCallback_.lock(); - if (writeCallback != nullptr) { - return writeCallback->OnStreamData(streamInfo_); - } - AUDIO_ERR_LOG("sessionId: %{public}d, writeCallback is nullptr", GetSessionId()); - return ERROR; + return OnStreamInfoChange(true); } bool HpaeSinkInputNode::ReadToAudioBuffer(int32_t &ret) { auto nodeCallback = GetNodeStatusCallback().lock(); - if (nodeCallback) { - nodeCallback->OnRequestLatency(GetSessionId(), streamInfo_.latency); - } if ((GetDeviceClass() == DEVICE_CLASS_OFFLOAD || GetDeviceClass() == DEVICE_CLASS_REMOTE_OFFLOAD) && !offloadEnable_) { ret = ERR_OPERATION_FAILED; @@ -200,8 +183,7 @@ void HpaeSinkInputNode::DoProcess() AudioPerformanceMonitor::GetInstance().RecordSilenceState(GetSessionId(), false, pipeType, static_cast(appUid_)); } - totalFrames_ = totalFrames_ + GetFrameLen(); - framesWritten_ = totalFrames_; + totalFrames_ += GetFrameLen(); if (historyBuffer_) { historyBuffer_->StoreFrameData(inputAudioBuffer_); } @@ -281,29 +263,13 @@ int32_t HpaeSinkInputNode::GetAppUid() return appUid_; } -uint64_t HpaeSinkInputNode::GetFramesWritten() -{ - return framesWritten_; -} - -int32_t HpaeSinkInputNode::GetCurrentPosition(uint64_t &framePosition, std::vector ×tamp) -{ - framePosition = GetFramesWritten(); - if (historyBuffer_) { - framePosition = framePosition > historyBuffer_->GetCurFrames() * GetFrameLen() - ? framePosition - historyBuffer_->GetCurFrames() * GetFrameLen() - : 0; - } - ClockTime::GetAllTimeStamp(timestamp); - return SUCCESS; -} - -int32_t HpaeSinkInputNode::RewindHistoryBuffer(uint64_t rewindTime, uint64_t hdiFramePosition) +void HpaeSinkInputNode::RewindHistoryBuffer(uint64_t rewindTime, uint64_t hdiFramePosition) { CHECK_AND_RETURN_RET_LOG(historyBuffer_, ERROR, "historyBuffer_ is nullptr"); hdiFramePosition_.store(hdiFramePosition); AUDIO_INFO_LOG("HpaeSinkInputNode::rewind %{public}zu frames", ConvertUsToFrameCount(rewindTime, GetNodeInfo())); - return historyBuffer_->RewindBuffer(ConvertUsToFrameCount(rewindTime, GetNodeInfo())); + historyBuffer_->RewindBuffer(ConvertUsToFrameCount(rewindTime, GetNodeInfo())); + OnStreamInfoChange(false); } void HpaeSinkInputNode::SetOffloadEnabled(bool offloadEnable) @@ -336,6 +302,39 @@ float HpaeSinkInputNode::GetSpeed() { return speed_; } + +uint32_t HpaeSinkInputNode::GetLatency() +{ + return historyBuffer_ ? historyBuffer_->GetCurFrames() * GetFrameLen() : 0; +} + +int32_t HpaeSinkInputNode::OnStreamInfoChange(bool isPullData) +{ + auto nodeCallback = GetNodeStatusCallback().lock(); + CHECK_AND_RETURN_RET_LOG(nodeCallback, ERROR, "managerCallback is null, Id %{public}d fatal err", GetSessionId()); + auto writeCallback = writeCallback_.lock(); + CHECK_AND_RETURN_RET_LOG(writeCallback, ERROR, "writeCallback is null, Id: %{public}d fatal err", GetSessionId()); + bool needData = !(historyBuffer_ && historyBuffer_->GetCurFrames()) && isPullData; + // offload enbale, underrun 9 times, request force write data; 9 times about 40ms + bool forceData = offloadEnable_ ? (standbyCounter_ > STANDBY_THRESHOLD ? true : false) : true; + uint32_t latency = 0; + nodeCallback->OnRequestLatency(GetSessionId(), latency); + latency += GetLatency(); + streamInfo_ = { + .framePosition = totalFrames_, + .hdiFramePosition = hdiFramePosition_.exchange(0), + .framesWritten = totalFrames_, + .latency = latency, + .inputData = interleveData_.data(), + .requestDataLen = interleveData_.size(), + .deviceClass = GetDeviceClass(), + .deviceNetId = GetDeviceNetId(), + .needData = needData, + .forceData = forceData + }; + ClockTime::GetAllTimeStamp(streamInfo_.timestamp); + return writeCallback->OnStreamData(streamInfo_); +} } // namespace HPAE } // namespace AudioStandard } // namespace OHOS \ No newline at end of file -- Gitee From e3fc287e3572942e7325432e0862222d39bd5820 Mon Sep 17 00:00:00 2001 From: owen_creeper Date: Thu, 4 Sep 2025 19:51:02 +0800 Subject: [PATCH 2/6] add some ut Signed-off-by: owen_creeper --- .../test/unittest/common/hpae_mocks.h | 19 ++ .../node/hpae_sink_input_node_test.cpp | 241 +++++++++++++++++- 2 files changed, 252 insertions(+), 8 deletions(-) diff --git a/services/audio_engine/test/unittest/common/hpae_mocks.h b/services/audio_engine/test/unittest/common/hpae_mocks.h index 8a3a63dc29..2c07e464c2 100644 --- a/services/audio_engine/test/unittest/common/hpae_mocks.h +++ b/services/audio_engine/test/unittest/common/hpae_mocks.h @@ -112,6 +112,25 @@ public: MOCK_METHOD(void, DumpInfo, (std::string &dumpString), (override)); }; + +// Mock INodeCallback +class MockNodeCallback : public INodeCallback { +public: + MOCK_METHOD(void, OnNodeStatusUpdate, (uint32_t, IOperation), (override)); + MOCK_METHOD(void, OnFadeDone, (uint32_t, IOperation), (override)); + MOCK_METHOD(void, OnRequestLatency, (uint32_t, uint64_t &), (override)); + MOCK_METHOD(void, OnRewindAndFlush, (uint64_t, uint64_t), (override)); + MOCK_METHOD(void, OnNotifyQueue, (), (override)); + MOCK_METHOD(void, OnDisConnectProcessCluster, (HpaeProcessorType), (override)); + MOCK_METHOD(void, OnNotifyDfxNodeInfo, (bool, uint32_t, HpaeDfxNodeInfo &), (override)); + MOCK_METHOD(void, OnNotifyDfxNodeInfoChanged, (uint32_t, const HpaeDfxNodeInfo &), (override)); +}; + +// Mock IStreamCallback +class MockStreamCallback : public IStreamCallback { +public: + MOCK_METHOD(int32_t, OnStreamData, (AudioCallBackStreamInfo&), (override)); +}; } // namespace HPAE } // namespace AudioStandard } // namespace OHOS diff --git a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp index acbc8a0b81..3bc9c9eb6e 100644 --- a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp +++ b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ -#include #include #include +#include "hpae_mocks.h" #include "hpae_sink_input_node.h" #include "hpae_sink_output_node.h" #include "test_case_common.h" @@ -29,15 +29,34 @@ using namespace testing; class HpaeSinkInputNodeTest : public testing::Test { public: - void SetUp(); - void TearDown(); -}; + void SetUp() override + { + HpaeNodeInfo nodeInfo; + nodeInfo.frameLen = 960; + nodeInfo.samplingRate = SAMPLE_RATE_48000; + nodeInfo.channels = STEREO; + nodeInfo.format = SAMPLE_F32LE; + nodeInfo.deviceClass = "primary"; + nodeInfo.deviceNetId_ = "local"; + node_ = std::make_unique(nodeInfo); + mockNodeCallback_ = std::make_shared(); + mockStreamCallback_ = std::make_shared(); + + // Set up weak pointers for callbacks + node_->nodeCallback_ = mockNodeCallback_; + node_->writeCallback_ = mockStreamCallback_; + + } -void HpaeSinkInputNodeTest::SetUp() -{} + void TearDown() override + { + node_.reset(); + } -void HpaeSinkInputNodeTest::TearDown() -{} + std::unique_ptr node_; + std::shared_ptr mockNodeCallback_; + std::shared_ptr mockStreamCallback_; +}; namespace { constexpr int32_t NORMAL_FRAME_LEN = 960; @@ -46,6 +65,15 @@ constexpr int32_t NORMAL_ID = 1243; constexpr float LOUDNESS_GAIN = 1.0f; constexpr uint32_t SAMPLE_RATE_16010 = 16010; +static void AddFrameToBuffer(std::unique_ptr &buffer) +{ + PcmBufferInfo info = buffer->pcmBufferInfo_; + info.isMultiFrames = false; + info.frames = 1; + HpaePcmBuffer d{info}; + buffer.PushFrameData(d); +} + HWTEST_F(HpaeSinkInputNodeTest, constructHpaeSinkInputNode, TestSize.Level0) { HpaeNodeInfo nodeInfo; @@ -285,4 +313,201 @@ HWTEST_F(HpaeSinkInputNodeTest, testReadToAudioBuffer, TestSize.Level0) funcRet = sinkInputNode->ReadToAudioBuffer(ret); EXPECT_EQ(funcRet, true); } + +// Test case when nodeCallback is null +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NodeCallbackNull_ReturnsError) { + node_->nodeCallback_.reset(); + + int32_t result = node_->OnStreamInfoChange(true); + EXPECT_EQ(result, ERROR); +} + +// Test case when writeCallback is null +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_WriteCallbackNull_ReturnsError) { + node_->writeCallback_.reset(); + + int32_t result = node_->OnStreamInfoChange(true); + EXPECT_EQ(result, ERROR); +} + +// Test case when needData is true (historyBuffer is null and isPullData is true) +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NeedDataTrue) { + node->historyBuffer_ = nullptr; + + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + + // Verify that needData is true and forceData is true (offloadEnable_ is false by default) + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_TRUE(info.needData); + EXPECT_TRUE(info.forceData); + return SUCCESS; + }); + + int32_t result = node->OnStreamInfoChange(true); + EXPECT_EQ(result, SUCCESS); +} + +// Test case when needData is false (historyBuffer has data) +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NeedDataFalse) { + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)).WillOnce(Return(SUCCESS)); + + int32_t result = node_->OnStreamInfoChange(true); + EXPECT_EQ(result, SUCCESS); +} + +// Test case when needData is false (historyBuffer has data) +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NeedDataFalse) { + node_->historyBuffer_ = std::make_unique(2, 960, 48000, 3, 3); + node_->historyBuffer_.isMultiFrames = true; + AddFrameToBuffer(node_->historyBuffer_); + + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + + // Verify that needData is false and forceData is true (offloadEnable_ is false by default) + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_FALSE(info.needData); + EXPECT_TRUE(info.forceData); + return SUCCESS; + }); + + int32_t result = node->OnStreamInfoChange(true); + EXPECT_EQ(result, SUCCESS); +} + +// Test case when forceData is true (offloadEnable is false) +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataTrue_OffloadDisabled) { + node->historyBuffer_ = nullptr; + node->offloadEnable_ = false; + + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + + // Verify that needData is true and forceData is true + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_TRUE(info.needData); + EXPECT_TRUE(info.forceData); + return SUCCESS; + }); + + int32_t result = node->OnStreamInfoChange(true); + EXPECT_EQ(result, SUCCESS); +} + +// Test case when forceData is true (offloadEnable is true and standbyCounter exceeds threshold) +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataTrue_StandbyExceedThreshold) { + node->historyBuffer_ = nullptr; + node->offloadEnable_ = true; + node->standbyCounter_ = 10; // Exceeds STANDBY_THRESHOLD (9) + + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + + // Verify that needData is true and forceData is true + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_TRUE(info.needData); + EXPECT_TRUE(info.forceData); + return SUCCESS; + }); + + int32_t result = node->OnStreamInfoChange(true); + EXPECT_EQ(result, SUCCESS); +} + +// Test case when forceData is false (offloadEnable is true and standbyCounter is below threshold) +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataFalse_StandbyBelowThreshold) { + node->historyBuffer_ = nullptr; + node->offloadEnable_ = true; + node->standbyCounter_ = 5; // Below STANDBY_THRESHOLD (9) + + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + + // Verify that needData is true and forceData is false + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_TRUE(info.needData); + EXPECT_FALSE(info.forceData); + return SUCCESS; + }); + + int32_t result = node->OnStreamInfoChange(true); + EXPECT_EQ(result, SUCCESS); +} + +// Test case to verify parameters passed to OnStreamData are correct +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_StreamDataParametersCorrect) { + node_->historyBuffer_ = nullptr; + + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + + AudioCallBackStreamInfo expectedInfo; + expectedInfo.framePosition = node_->totalFrames_; + expectedInfo.hdiFramePosition = 0; // Because of hdiFramePosition_.exchange(0) + expectedInfo.framesWritten = node_->totalFrames_; + expectedInfo.latency = 15; // OnRequestLatency returns 5 + GetLatency returns 10 + expectedInfo.inputData = node_->interleveData_.data(); + expectedInfo.requestDataLen = node_->interleveData_.size(); + expectedInfo.deviceClass = DEVICE_CLASS_SPEAKER; + expectedInfo.deviceNetId = 0; + expectedInfo.needData = true; + expectedInfo.forceData = true; // Because offloadEnable_ is false by default + + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_EQ(info.framePosition, expectedInfo.framePosition); + EXPECT_EQ(info.hdiFramePosition, expectedInfo.hdiFramePosition); + EXPECT_EQ(info.framesWritten, expectedInfo.framesWritten); + EXPECT_EQ(info.latency, expectedInfo.latency); + EXPECT_EQ(info.inputData, expectedInfo.inputData); + EXPECT_EQ(info.requestDataLen, expectedInfo.requestDataLen); + EXPECT_EQ(info.deviceClass, expectedInfo.deviceClass); + EXPECT_EQ(info.deviceNetId, expectedInfo.deviceNetId); + EXPECT_EQ(info.needData, expectedInfo.needData); + EXPECT_EQ(info.forceData, expectedInfo.forceData); + return SUCCESS; + }); + + int32_t result = node_->OnStreamInfoChange(true); + EXPECT_EQ(result, SUCCESS); +} + +// Test case when isPullData is false and historyBuffer is null +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_IsPullDataFalse_HistoryBufferNull) { + node->historyBuffer_ = nullptr; + + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + + // Verify that needData is false (because isPullData is false) and forceData is true + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_FALSE(info.needData); + EXPECT_TRUE(info.forceData); // offloadEnable_ is false by default + return SUCCESS; + }); + + int32_t result = node->OnStreamInfoChange(false); + EXPECT_EQ(result, SUCCESS); +} + +// Test case when isPullData is false and historyBuffer has data +TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_IsPullDataFalse_HistoryBufferHasData) { + node_->historyBuffer_ = std::make_unique(2, 960, 48000, 3, 3); + node_->historyBuffer_.isMultiFrames = true; + AddFrameToBuffer(node_->historyBuffer_); + + EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + + // Verify that needData is false (because isPullData is false) and forceData is true + EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_FALSE(info.needData); + EXPECT_TRUE(info.forceData); // offloadEnable_ is false by default + return SUCCESS; + }); + + int32_t result = node->OnStreamInfoChange(false); + EXPECT_EQ(result, SUCCESS); +} } \ No newline at end of file -- Gitee From 238fc5af7fb853b3b977222a068829878ed89f1b Mon Sep 17 00:00:00 2001 From: owenCreeper Date: Thu, 4 Sep 2025 21:55:40 +0800 Subject: [PATCH 3/6] add some ut Signed-off-by: owenCreeper --- .../node/include/hpae_sink_input_node.h | 3 +- .../node/src/hpae_sink_input_node.cpp | 13 +- .../test/unittest/common/hpae_mocks.h | 6 + .../node/hpae_sink_input_node_test.cpp | 186 ++++++++---------- 4 files changed, 99 insertions(+), 109 deletions(-) diff --git a/services/audio_engine/node/include/hpae_sink_input_node.h b/services/audio_engine/node/include/hpae_sink_input_node.h index 8166e24c81..27eea3136d 100644 --- a/services/audio_engine/node/include/hpae_sink_input_node.h +++ b/services/audio_engine/node/include/hpae_sink_input_node.h @@ -56,9 +56,10 @@ public: float GetLoudnessGain(); void SetSpeed(float speed); float GetSpeed(); - uint32_t GetLatency(); + uint64_t GetLatency(); bool isConnected_ = false; private: + int32_t GetDataFromSharedBuffer(); int32_t OnStreamInfoChange(bool needata = true); void CheckAndDestroyHistoryBuffer(); bool ReadToAudioBuffer(int32_t &ret); diff --git a/services/audio_engine/node/src/hpae_sink_input_node.cpp b/services/audio_engine/node/src/hpae_sink_input_node.cpp index d68e68e0c9..67af1fe971 100644 --- a/services/audio_engine/node/src/hpae_sink_input_node.cpp +++ b/services/audio_engine/node/src/hpae_sink_input_node.cpp @@ -265,7 +265,7 @@ int32_t HpaeSinkInputNode::GetAppUid() void HpaeSinkInputNode::RewindHistoryBuffer(uint64_t rewindTime, uint64_t hdiFramePosition) { - CHECK_AND_RETURN_RET_LOG(historyBuffer_, ERROR, "historyBuffer_ is nullptr"); + CHECK_AND_RETURN_LOG(historyBuffer_, "historyBuffer_ is nullptr"); hdiFramePosition_.store(hdiFramePosition); AUDIO_INFO_LOG("HpaeSinkInputNode::rewind %{public}zu frames", ConvertUsToFrameCount(rewindTime, GetNodeInfo())); historyBuffer_->RewindBuffer(ConvertUsToFrameCount(rewindTime, GetNodeInfo())); @@ -303,22 +303,23 @@ float HpaeSinkInputNode::GetSpeed() return speed_; } -uint32_t HpaeSinkInputNode::GetLatency() +uint64_t HpaeSinkInputNode::GetLatency() { return historyBuffer_ ? historyBuffer_->GetCurFrames() * GetFrameLen() : 0; } int32_t HpaeSinkInputNode::OnStreamInfoChange(bool isPullData) { - auto nodeCallback = GetNodeStatusCallback().lock(); - CHECK_AND_RETURN_RET_LOG(nodeCallback, ERROR, "managerCallback is null, Id %{public}d fatal err", GetSessionId()); auto writeCallback = writeCallback_.lock(); CHECK_AND_RETURN_RET_LOG(writeCallback, ERROR, "writeCallback is null, Id: %{public}d fatal err", GetSessionId()); bool needData = !(historyBuffer_ && historyBuffer_->GetCurFrames()) && isPullData; // offload enbale, underrun 9 times, request force write data; 9 times about 40ms bool forceData = offloadEnable_ ? (standbyCounter_ > STANDBY_THRESHOLD ? true : false) : true; - uint32_t latency = 0; - nodeCallback->OnRequestLatency(GetSessionId(), latency); + uint64_t latency = 0; + auto nodeCallback = GetNodeStatusCallback().lock(); + if (nodeCallback) { + nodeCallback->OnRequestLatency(GetSessionId(), latency); + } latency += GetLatency(); streamInfo_ = { .framePosition = totalFrames_, diff --git a/services/audio_engine/test/unittest/common/hpae_mocks.h b/services/audio_engine/test/unittest/common/hpae_mocks.h index 2c07e464c2..0bb33af0c4 100644 --- a/services/audio_engine/test/unittest/common/hpae_mocks.h +++ b/services/audio_engine/test/unittest/common/hpae_mocks.h @@ -33,6 +33,8 @@ public: class MockAudioRenderSink : public IAudioRenderSink { public: + MockAudioRenderSink() = default; + virtual ~MockAudioRenderSink() = default; MOCK_METHOD(int32_t, Init, (const IAudioSinkAttr &attr), (override)); MOCK_METHOD(void, DeInit, (), (override)); MOCK_METHOD(bool, IsInited, (), (override)); @@ -116,6 +118,8 @@ public: // Mock INodeCallback class MockNodeCallback : public INodeCallback { public: + MockNodeCallback() = default; + virtual ~MockNodeCallback() = default; MOCK_METHOD(void, OnNodeStatusUpdate, (uint32_t, IOperation), (override)); MOCK_METHOD(void, OnFadeDone, (uint32_t, IOperation), (override)); MOCK_METHOD(void, OnRequestLatency, (uint32_t, uint64_t &), (override)); @@ -129,6 +133,8 @@ public: // Mock IStreamCallback class MockStreamCallback : public IStreamCallback { public: + MockStreamCallback() = default; + virtual ~MockStreamCallback() = default; MOCK_METHOD(int32_t, OnStreamData, (AudioCallBackStreamInfo&), (override)); }; } // namespace HPAE diff --git a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp index 3bc9c9eb6e..f486ae0a84 100644 --- a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp +++ b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp @@ -21,36 +21,57 @@ #include "test_case_common.h" #include "audio_errors.h" -using namespace OHOS; -using namespace AudioStandard; -using namespace HPAE; using namespace testing::ext; using namespace testing; +namespace OHOS { +namespace AudioStandard { +namespace HPAE { +constexpr int32_t NORMAL_FRAME_LEN = 960; +constexpr int32_t NORMAL_ID = 1243; +constexpr float LOUDNESS_GAIN = 1.0f; +constexpr uint32_t SAMPLE_RATE_16010 = 16010; + +static void AddFrameToBuffer(std::unique_ptr &buffer) +{ + PcmBufferInfo info = buffer->pcmBufferInfo_; + info.isMultiFrames = false; + info.frames = 1; + HpaePcmBuffer d{info}; + buffer->PushFrameData(d); +} + +static void PrepareNodeInfo(HpaeNodeInfo &nodeInfo) +{ + nodeInfo.frameLen = 960; + nodeInfo.samplingRate = SAMPLE_RATE_48000; + nodeInfo.channels = STEREO; + nodeInfo.format = SAMPLE_F32LE; + nodeInfo.deviceClass = "primary"; + nodeInfo.deviceNetId = "local"; + nodeInfo.historyFrameCount = 5; +} + class HpaeSinkInputNodeTest : public testing::Test { public: void SetUp() override { HpaeNodeInfo nodeInfo; - nodeInfo.frameLen = 960; - nodeInfo.samplingRate = SAMPLE_RATE_48000; - nodeInfo.channels = STEREO; - nodeInfo.format = SAMPLE_F32LE; - nodeInfo.deviceClass = "primary"; - nodeInfo.deviceNetId_ = "local"; + PrepareNodeInfo(nodeInfo); node_ = std::make_unique(nodeInfo); mockNodeCallback_ = std::make_shared(); mockStreamCallback_ = std::make_shared(); // Set up weak pointers for callbacks - node_->nodeCallback_ = mockNodeCallback_; + node_->nodeInfo_.statusCallback = mockNodeCallback_; node_->writeCallback_ = mockStreamCallback_; - } void TearDown() override { node_.reset(); + mockNodeCallback_.reset(); + mockStreamCallback_.reset(); } std::unique_ptr node_; @@ -58,22 +79,6 @@ public: std::shared_ptr mockStreamCallback_; }; -namespace { -constexpr int32_t NORMAL_FRAME_LEN = 960; -constexpr int32_t NORMAL_ID = 1243; - -constexpr float LOUDNESS_GAIN = 1.0f; -constexpr uint32_t SAMPLE_RATE_16010 = 16010; - -static void AddFrameToBuffer(std::unique_ptr &buffer) -{ - PcmBufferInfo info = buffer->pcmBufferInfo_; - info.isMultiFrames = false; - info.frames = 1; - HpaePcmBuffer d{info}; - buffer.PushFrameData(d); -} - HWTEST_F(HpaeSinkInputNodeTest, constructHpaeSinkInputNode, TestSize.Level0) { HpaeNodeInfo nodeInfo; @@ -315,15 +320,21 @@ HWTEST_F(HpaeSinkInputNodeTest, testReadToAudioBuffer, TestSize.Level0) } // Test case when nodeCallback is null -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NodeCallbackNull_ReturnsError) { - node_->nodeCallback_.reset(); +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NodeCallbackNull_LatencyZero, TestSize.Level0) { + node_->nodeInfo_.statusCallback.reset(); + + EXPECT_CALL(*mockStreamCallback_, OnStreamData(_)) + .WillOnce([&](AudioCallBackStreamInfo& info) { + EXPECT_EQ(info.latency, 0); // no latency + return SUCCESS; + }); int32_t result = node_->OnStreamInfoChange(true); - EXPECT_EQ(result, ERROR); + EXPECT_EQ(result, SUCCESS); } // Test case when writeCallback is null -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_WriteCallbackNull_ReturnsError) { +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_WriteCallbackNull_ReturnsError, TestSize.Level0) { node_->writeCallback_.reset(); int32_t result = node_->OnStreamInfoChange(true); @@ -331,130 +342,119 @@ TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_WriteCallbackNull_ReturnsError) } // Test case when needData is true (historyBuffer is null and isPullData is true) -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NeedDataTrue) { - node->historyBuffer_ = nullptr; +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NeedDataTrue, TestSize.Level0) { + node_->historyBuffer_ = nullptr; - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + EXPECT_CALL(*mockNodeCallback_, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); // Verify that needData is true and forceData is true (offloadEnable_ is false by default) - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + EXPECT_CALL(*mockStreamCallback_, OnStreamData(_)) .WillOnce([&](AudioCallBackStreamInfo& info) { EXPECT_TRUE(info.needData); EXPECT_TRUE(info.forceData); return SUCCESS; }); - int32_t result = node->OnStreamInfoChange(true); - EXPECT_EQ(result, SUCCESS); -} - -// Test case when needData is false (historyBuffer has data) -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NeedDataFalse) { - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)).WillOnce(Return(SUCCESS)); - int32_t result = node_->OnStreamInfoChange(true); EXPECT_EQ(result, SUCCESS); } // Test case when needData is false (historyBuffer has data) -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NeedDataFalse) { - node_->historyBuffer_ = std::make_unique(2, 960, 48000, 3, 3); - node_->historyBuffer_.isMultiFrames = true; +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_NeedDataFalse, TestSize.Level0) { AddFrameToBuffer(node_->historyBuffer_); - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + EXPECT_CALL(*mockNodeCallback_, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); // Verify that needData is false and forceData is true (offloadEnable_ is false by default) - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + EXPECT_CALL(*mockStreamCallback_, OnStreamData(_)) .WillOnce([&](AudioCallBackStreamInfo& info) { EXPECT_FALSE(info.needData); EXPECT_TRUE(info.forceData); return SUCCESS; }); - int32_t result = node->OnStreamInfoChange(true); + int32_t result = node_->OnStreamInfoChange(true); EXPECT_EQ(result, SUCCESS); } // Test case when forceData is true (offloadEnable is false) -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataTrue_OffloadDisabled) { - node->historyBuffer_ = nullptr; - node->offloadEnable_ = false; +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataTrue_OffloadDisabled, TestSize.Level0) { + node_->historyBuffer_ = nullptr; + node_->offloadEnable_ = false; - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + EXPECT_CALL(*mockNodeCallback_, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); // Verify that needData is true and forceData is true - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + EXPECT_CALL(*mockStreamCallback_, OnStreamData(_)) .WillOnce([&](AudioCallBackStreamInfo& info) { EXPECT_TRUE(info.needData); EXPECT_TRUE(info.forceData); return SUCCESS; }); - int32_t result = node->OnStreamInfoChange(true); + int32_t result = node_->OnStreamInfoChange(true); EXPECT_EQ(result, SUCCESS); } // Test case when forceData is true (offloadEnable is true and standbyCounter exceeds threshold) -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataTrue_StandbyExceedThreshold) { - node->historyBuffer_ = nullptr; - node->offloadEnable_ = true; - node->standbyCounter_ = 10; // Exceeds STANDBY_THRESHOLD (9) +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataTrue_StandbyExceedThreshold, TestSize.Level0) { + node_->historyBuffer_ = nullptr; + node_->offloadEnable_ = true; + node_->standbyCounter_ = 10; // Exceeds STANDBY_THRESHOLD (9) - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + EXPECT_CALL(*mockNodeCallback_, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); // Verify that needData is true and forceData is true - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + EXPECT_CALL(*mockStreamCallback_, OnStreamData(_)) .WillOnce([&](AudioCallBackStreamInfo& info) { EXPECT_TRUE(info.needData); EXPECT_TRUE(info.forceData); return SUCCESS; }); - int32_t result = node->OnStreamInfoChange(true); + int32_t result = node_->OnStreamInfoChange(true); EXPECT_EQ(result, SUCCESS); } // Test case when forceData is false (offloadEnable is true and standbyCounter is below threshold) -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataFalse_StandbyBelowThreshold) { - node->historyBuffer_ = nullptr; - node->offloadEnable_ = true; - node->standbyCounter_ = 5; // Below STANDBY_THRESHOLD (9) +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_ForceDataFalse_StandbyBelowThreshold, TestSize.Level0) { + node_->historyBuffer_ = nullptr; + node_->offloadEnable_ = true; + node_->standbyCounter_ = 5; // Below STANDBY_THRESHOLD (9) - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + EXPECT_CALL(*mockNodeCallback_, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); // Verify that needData is true and forceData is false - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + EXPECT_CALL(*mockStreamCallback_, OnStreamData(_)) .WillOnce([&](AudioCallBackStreamInfo& info) { EXPECT_TRUE(info.needData); EXPECT_FALSE(info.forceData); return SUCCESS; }); - int32_t result = node->OnStreamInfoChange(true); + int32_t result = node_->OnStreamInfoChange(true); EXPECT_EQ(result, SUCCESS); } // Test case to verify parameters passed to OnStreamData are correct -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_StreamDataParametersCorrect) { +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_StreamDataParametersCorrect, TestSize.Level0) { node_->historyBuffer_ = nullptr; - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + EXPECT_CALL(*mockNodeCallback_, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); AudioCallBackStreamInfo expectedInfo; expectedInfo.framePosition = node_->totalFrames_; expectedInfo.hdiFramePosition = 0; // Because of hdiFramePosition_.exchange(0) expectedInfo.framesWritten = node_->totalFrames_; - expectedInfo.latency = 15; // OnRequestLatency returns 5 + GetLatency returns 10 + expectedInfo.latency = 5; // OnRequestLatency returns 5 + GetLatency(0) returns 5 expectedInfo.inputData = node_->interleveData_.data(); expectedInfo.requestDataLen = node_->interleveData_.size(); - expectedInfo.deviceClass = DEVICE_CLASS_SPEAKER; - expectedInfo.deviceNetId = 0; + expectedInfo.deviceClass = "primary"; + expectedInfo.deviceNetId = "local"; expectedInfo.needData = true; expectedInfo.forceData = true; // Because offloadEnable_ is false by default - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + EXPECT_CALL(*mockStreamCallback_, OnStreamData(_)) .WillOnce([&](AudioCallBackStreamInfo& info) { EXPECT_EQ(info.framePosition, expectedInfo.framePosition); EXPECT_EQ(info.hdiFramePosition, expectedInfo.hdiFramePosition); @@ -474,40 +474,22 @@ TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_StreamDataParametersCorrect) { } // Test case when isPullData is false and historyBuffer is null -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_IsPullDataFalse_HistoryBufferNull) { - node->historyBuffer_ = nullptr; - - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); - - // Verify that needData is false (because isPullData is false) and forceData is true - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) - .WillOnce([&](AudioCallBackStreamInfo& info) { - EXPECT_FALSE(info.needData); - EXPECT_TRUE(info.forceData); // offloadEnable_ is false by default - return SUCCESS; - }); - - int32_t result = node->OnStreamInfoChange(false); - EXPECT_EQ(result, SUCCESS); -} - -// Test case when isPullData is false and historyBuffer has data -TEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_IsPullDataFalse_HistoryBufferHasData) { - node_->historyBuffer_ = std::make_unique(2, 960, 48000, 3, 3); - node_->historyBuffer_.isMultiFrames = true; - AddFrameToBuffer(node_->historyBuffer_); +HWTEST_F(HpaeSinkInputNodeTest, OnStreamInfoChange_IsPullDataFalse, TestSize.Level0) { + node_->historyBuffer_ = nullptr; - EXPECT_CALL(*mockNodeCallback, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); + EXPECT_CALL(*mockNodeCallback_, OnRequestLatency(_, _)).WillOnce(SetArgReferee<1>(5)); // Verify that needData is false (because isPullData is false) and forceData is true - EXPECT_CALL(*mockStreamCallback, OnStreamData(_)) + EXPECT_CALL(*mockStreamCallback_, OnStreamData(_)) .WillOnce([&](AudioCallBackStreamInfo& info) { EXPECT_FALSE(info.needData); EXPECT_TRUE(info.forceData); // offloadEnable_ is false by default return SUCCESS; }); - int32_t result = node->OnStreamInfoChange(false); + int32_t result = node_->OnStreamInfoChange(false); EXPECT_EQ(result, SUCCESS); } -} \ No newline at end of file +} // namespace HPAE +} // namespace AudioStandard +} // namespace OHOS \ No newline at end of file -- Gitee From d174450c2627f87abb0b5e7b10c7472b7d44c304 Mon Sep 17 00:00:00 2001 From: owenCreeper Date: Fri, 5 Sep 2025 10:09:26 +0800 Subject: [PATCH 4/6] fix codeecheck Signed-off-by: owenCreeper --- services/audio_engine/test/unittest/common/hpae_mocks.h | 1 + .../test/unittest/node/hpae_sink_input_node_test.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/services/audio_engine/test/unittest/common/hpae_mocks.h b/services/audio_engine/test/unittest/common/hpae_mocks.h index 0bb33af0c4..63771b5c6d 100644 --- a/services/audio_engine/test/unittest/common/hpae_mocks.h +++ b/services/audio_engine/test/unittest/common/hpae_mocks.h @@ -19,6 +19,7 @@ #include "gmock/gmock.h" #include "hpae_msg_channel.h" #include "sink/i_audio_render_sink.h" +#include "i_renderer_stream.h" namespace OHOS { namespace AudioStandard { diff --git a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp index f486ae0a84..efecca92b2 100644 --- a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp +++ b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp @@ -31,6 +31,7 @@ constexpr int32_t NORMAL_FRAME_LEN = 960; constexpr int32_t NORMAL_ID = 1243; constexpr float LOUDNESS_GAIN = 1.0f; constexpr uint32_t SAMPLE_RATE_16010 = 16010; +constexpr size_t DEFAULT_HISTROY_FRAME_COUNT = 5; static void AddFrameToBuffer(std::unique_ptr &buffer) { @@ -43,13 +44,13 @@ static void AddFrameToBuffer(std::unique_ptr &buffer) static void PrepareNodeInfo(HpaeNodeInfo &nodeInfo) { - nodeInfo.frameLen = 960; + nodeInfo.frameLen = NORMAL_FRAME_LEN; nodeInfo.samplingRate = SAMPLE_RATE_48000; nodeInfo.channels = STEREO; nodeInfo.format = SAMPLE_F32LE; nodeInfo.deviceClass = "primary"; nodeInfo.deviceNetId = "local"; - nodeInfo.historyFrameCount = 5; + nodeInfo.historyFrameCount = DEFAULT_HISTROY_FRAME_COUNT; } class HpaeSinkInputNodeTest : public testing::Test { -- Gitee From 5f11f6980d02bf5b0d328784cab3b2053580b34c Mon Sep 17 00:00:00 2001 From: owenCreeper Date: Fri, 5 Sep 2025 14:31:53 +0800 Subject: [PATCH 5/6] fix codecheck Signed-off-by: owenCreeper --- .../node/hpae_sink_input_node_test.cpp | 2 +- .../hpaesinkinputnode_fuzzer.cpp | 18 ------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp index efecca92b2..2799a310f5 100644 --- a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp +++ b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp @@ -31,7 +31,7 @@ constexpr int32_t NORMAL_FRAME_LEN = 960; constexpr int32_t NORMAL_ID = 1243; constexpr float LOUDNESS_GAIN = 1.0f; constexpr uint32_t SAMPLE_RATE_16010 = 16010; -constexpr size_t DEFAULT_HISTROY_FRAME_COUNT = 5; +constexpr size_t DEFAULT_HISTROY_FRAME_COUNT = 5; static void AddFrameToBuffer(std::unique_ptr &buffer) { diff --git a/test/fuzztest/hpaesinkinputnode_fuzzer/hpaesinkinputnode_fuzzer.cpp b/test/fuzztest/hpaesinkinputnode_fuzzer/hpaesinkinputnode_fuzzer.cpp index aaea849028..87423cd0b4 100644 --- a/test/fuzztest/hpaesinkinputnode_fuzzer/hpaesinkinputnode_fuzzer.cpp +++ b/test/fuzztest/hpaesinkinputnode_fuzzer/hpaesinkinputnode_fuzzer.cpp @@ -139,22 +139,6 @@ void GetStateFuzzTest() hpaeSinkInputNode->GetState(); } -void GetFramesWrittenFuzzTest() -{ - HpaeNodeInfo nodeInfo; - auto hpaeSinkInputNode = std::make_shared(nodeInfo); - hpaeSinkInputNode->GetFramesWritten(); -} - -void GetCurrentPositionFuzzTest() -{ - HpaeNodeInfo nodeInfo; - auto hpaeSinkInputNode = std::make_shared(nodeInfo); - uint64_t framePosition = GetData(); - std::vector timestamp; - hpaeSinkInputNode->GetCurrentPosition(framePosition, timestamp); -} - void RewindHistoryBufferFuzzTest() { HpaeNodeInfo nodeInfo; @@ -218,8 +202,6 @@ TestFuncs g_testFuncs = { DrainFuzzTest, SetStateFuzzTest, GetStateFuzzTest, - GetFramesWrittenFuzzTest, - GetCurrentPositionFuzzTest, RewindHistoryBufferFuzzTest, SetAppUidFuzzTest, GetAppUidFuzzTest, -- Gitee From 2abead655ec9847b478bea8c0cf28f2409c21c58 Mon Sep 17 00:00:00 2001 From: owenCreeper Date: Fri, 5 Sep 2025 15:24:26 +0800 Subject: [PATCH 6/6] fix codecheck Signed-off-by: owenCreeper --- .../test/unittest/node/hpae_sink_input_node_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp index 2799a310f5..ee742e40a5 100644 --- a/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp +++ b/services/audio_engine/test/unittest/node/hpae_sink_input_node_test.cpp @@ -35,6 +35,7 @@ constexpr size_t DEFAULT_HISTROY_FRAME_COUNT = 5; static void AddFrameToBuffer(std::unique_ptr &buffer) { + CHECK_AND_RETURN(buffer); PcmBufferInfo info = buffer->pcmBufferInfo_; info.isMultiFrames = false; info.frames = 1; -- Gitee