diff --git a/services/audio_engine/BUILD.gn b/services/audio_engine/BUILD.gn index d22bf8086100242ef5e7535f6e6b7d90327b1a03..ccdca23a49cfdd280c31de96b66ab6748f8fcb59 100644 --- a/services/audio_engine/BUILD.gn +++ b/services/audio_engine/BUILD.gn @@ -172,7 +172,6 @@ ohos_shared_library("audio_engine_node") { "node/src/hpae_plugin_node.cpp", "node/src/hpae_process_cluster.cpp", "node/src/hpae_render_effect_node.cpp", - "node/src/hpae_resample_node.cpp", "node/src/hpae_sink_input_node.cpp", "node/src/hpae_sink_output_node.cpp", "node/src/hpae_source_input_cluster.cpp", diff --git a/services/audio_engine/manager/include/hpae_inner_capturer_manager.h b/services/audio_engine/manager/include/hpae_inner_capturer_manager.h index e5a6022c1f756128879915ffd9fdc5f74d77b1b4..9ddce8635e7e1fddecf4693899857d7babed04d9 100644 --- a/services/audio_engine/manager/include/hpae_inner_capturer_manager.h +++ b/services/audio_engine/manager/include/hpae_inner_capturer_manager.h @@ -24,7 +24,6 @@ #include "i_renderer_stream.h" #include "hpae_signal_process_thread.h" #include "hpae_sink_input_node.h" -#include "hpae_resample_node.h" #include "hpae_inner_cap_sink_node.h" #include "hpae_source_output_node.h" #include "hpae_source_process_cluster.h" diff --git a/services/audio_engine/node/include/hpae_resample_node.h b/services/audio_engine/node/include/hpae_resample_node.h deleted file mode 100644 index 1b51f619cd01eed87622f3e44d3f20f4e4a310b7..0000000000000000000000000000000000000000 --- a/services/audio_engine/node/include/hpae_resample_node.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ -#ifndef HPAE_RESAMPLE_NODE_H -#define HPAE_RESAMPLE_NODE_H -#include "audio_proresampler.h" -#include "hpae_plugin_node.h" -#ifdef ENABLE_HOOK_PCM -#include "hpae_pcm_dumper.h" -#endif -namespace OHOS { -namespace AudioStandard { -namespace HPAE { - -enum class ResamplerType { - PRORESAMPLER -}; - -class HpaeResampleNode : public HpaePluginNode { -public: - HpaeResampleNode(HpaeNodeInfo& nodeInfo, HpaeNodeInfo& preNodeInfo, ResamplerType type); - HpaeResampleNode(HpaeNodeInfo& nodeInfo, HpaeNodeInfo& preNodeInfo); - ~HpaeResampleNode() = default; - virtual bool Reset() override; - void ConnectWithInfo(const std::shared_ptr> &preNode, HpaeNodeInfo &nodeInfo) override; - void DisConnectWithInfo(const std::shared_ptr> &preNode, - HpaeNodeInfo &nodeInfo) override; -protected: - HpaePcmBuffer* SignalProcess(const std::vector& inputs) override; -private: - void ResampleProcess(float *srcData, uint32_t inputFrameLen, float *dstData, uint32_t outputFrameLen); - PcmBufferInfo pcmBufferInfo_; - HpaePcmBuffer resampleOutput_; - HpaeNodeInfo preNodeInfo_; - std::vector tempOutput_; -#ifdef ENABLE_HOOK_PCM - std::unique_ptr inputPcmDumper_ = nullptr; - std::unique_ptr outputPcmDumper_ = nullptr; -#endif - std::unique_ptr resampler_ = nullptr; -}; -} // namespace HPAE -} // namespace AudioStandard -} // namespace OHOS -#endif \ No newline at end of file diff --git a/services/audio_engine/node/src/hpae_resample_node.cpp b/services/audio_engine/node/src/hpae_resample_node.cpp deleted file mode 100644 index 4036a79cb987dad5f6055513c7a12743d33446d9..0000000000000000000000000000000000000000 --- a/services/audio_engine/node/src/hpae_resample_node.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef LOG_TAG -#define LOG_TAG "HpaeResampleNode" -#endif - -#include -#include -#include -#include "hpae_resample_node.h" -#include "hpae_pcm_buffer.h" -#include "audio_utils.h" -#include "audio_effect_log.h" - -namespace OHOS { -namespace AudioStandard { -namespace HPAE { -constexpr int REASAMPLE_QUAILTY = 5; -static inline uint32_t Min(const uint32_t a, const uint32_t b) {return a > b ? b : a;} -HpaeResampleNode::HpaeResampleNode(HpaeNodeInfo &preNodeInfo, HpaeNodeInfo &nodeInfo, ResamplerType type) - : HpaeNode(nodeInfo), HpaePluginNode(nodeInfo), - pcmBufferInfo_(nodeInfo.channels, nodeInfo.frameLen, nodeInfo.samplingRate), - resampleOutput_(pcmBufferInfo_), preNodeInfo_(preNodeInfo), tempOutput_(preNodeInfo.channels * nodeInfo.frameLen) -{ - if (type == ResamplerType::PRORESAMPLER) { - resampler_ = std::make_unique(preNodeInfo_.samplingRate, nodeInfo.samplingRate, - preNodeInfo_.channels, REASAMPLE_QUAILTY); - } -#ifdef ENABLE_HOOK_PCM - inputPcmDumper_ = std::make_unique("HpaeResampleNodeInput1_id_" + - std::to_string(GetSessionId()) + "_ch_" + std::to_string(preNodeInfo_.channels) + - "_rate_" + std::to_string(preNodeInfo_.samplingRate) + "_scene_" + - std::to_string(HpaeNode::GetSceneType()) + "_" + GetTime() + ".pcm"); - outputPcmDumper_ = std::make_unique("HpaeResampleNodeOutput1_id_" + - std::to_string(GetSessionId()) + "_ch_" + std::to_string(GetChannelCount()) + - "_rate_" + std::to_string(GetSampleRate()) + "_scene_" + - std::to_string(HpaeNode::GetSceneType())+ "_" + GetTime() + ".pcm"); -#endif -} - -HpaeResampleNode::HpaeResampleNode(HpaeNodeInfo &preNodeInfo, HpaeNodeInfo &nodeInfo) - : HpaeNode(nodeInfo), HpaePluginNode(nodeInfo), - pcmBufferInfo_(nodeInfo.channels, nodeInfo.frameLen, nodeInfo.samplingRate), - resampleOutput_(pcmBufferInfo_), preNodeInfo_(preNodeInfo), tempOutput_(preNodeInfo.channels * nodeInfo.frameLen) -{ // use ProResampler as default - resampler_ = std::make_unique(preNodeInfo_.samplingRate, nodeInfo.samplingRate, - preNodeInfo_.channels, REASAMPLE_QUAILTY); - -#ifdef ENABLE_HOOK_PCM - inputPcmDumper_ = std::make_unique("HpaeResampleNodeInput1_id_" + - std::to_string(HpaeNode::GetSessionId()) + "_ch_" + std::to_string(preNodeInfo_.channels) + "_rate_" + - std::to_string(preNodeInfo_.samplingRate) + "_scene_" + std::to_string(HpaeNode::GetSceneType())+".pcm"); - - outputPcmDumper_ = std::make_unique("HpaeResampleNodeOutput1_id_" + - std::to_string(HpaeNode::GetSessionId()) + "_ch_" + std::to_string(HpaeNode::GetChannelCount()) + - "_rate_" + std::to_string(HpaeNode::GetSampleRate()) + - "_scene_"+ std::to_string(HpaeNode::GetSceneType())+".pcm"); -#endif - AUDIO_INFO_LOG("input rate %{public}u, output rate %{public}u", preNodeInfo_.samplingRate, nodeInfo.samplingRate); - AUDIO_INFO_LOG("input SessionId %{public}u, output streamType %{public}u", HpaeNode::GetSessionId(), - nodeInfo.streamType); - AUDIO_INFO_LOG("input ch %{public}u, output ch %{public}u", preNodeInfo_.channels, HpaeNode::GetChannelCount()); -} - -bool HpaeResampleNode::Reset() -{ - if (resampler_ == nullptr) { - AUDIO_WARNING_LOG("resampler_ is nullptr, SessionId:%{public}d", GetSessionId()); - return false; - } - resampler_->Reset(); - return true; -} - -HpaePcmBuffer *HpaeResampleNode::SignalProcess(const std::vector &inputs) -{ - Trace trace("[" + std::to_string(GetSessionId()) + "]HpaeResampleNode::SignalProcess"); - if (inputs.empty()) { - AUDIO_WARNING_LOG("inputs size is empty, SessionId:%{public}d", GetSessionId()); - return nullptr; - } - if (inputs.size() != 1) { - AUDIO_WARNING_LOG("error inputs size is not eqaul to 1, SessionId:%{public}d", GetSessionId()); - } - if (resampler_ == nullptr) { - return &silenceData_; - } - resampleOutput_.Reset(); - uint32_t inputFrameLen = preNodeInfo_.frameLen; - uint32_t outputFrameLen = GetFrameLen(); - float *srcData = (*(inputs[0])).GetPcmDataBuffer(); - float *dstData = tempOutput_.data(); - if (preNodeInfo_.channels == GetChannelCount()) { - dstData = resampleOutput_.GetPcmDataBuffer(); - } -#ifdef ENABLE_HOOK_PCM - if (inputPcmDumper_ != nullptr) { - inputPcmDumper_->CheckAndReopenHandle(); - inputPcmDumper_->Dump((int8_t *)(srcData), (inputFrameLen * sizeof(float) * preNodeInfo_.channels)); - } -#endif - ResampleProcess(srcData, inputFrameLen, dstData, outputFrameLen); - return &resampleOutput_; -} - -void HpaeResampleNode::ResampleProcess(float *srcData, uint32_t inputFrameLen, float *dstData, uint32_t outputFrameLen) -{ - resampler_->Process(srcData, inputFrameLen, dstData, outputFrameLen); - - if (preNodeInfo_.channels == GetChannelCount()) { -#ifdef ENABLE_HOOK_PCM - if (outputPcmDumper_ != nullptr) { - outputPcmDumper_->CheckAndReopenHandle(); - outputPcmDumper_->Dump( - (int8_t *)(resampleOutput_.GetPcmDataBuffer()), GetFrameLen() * sizeof(float) * GetChannelCount()); - } -#endif - return; - } - - float *targetData = resampleOutput_.GetPcmDataBuffer(); - uint32_t targetChannels = GetChannelCount(); - for (uint32_t i = 0; i < outputFrameLen; ++i) { - for (uint32_t ch = 0; ch < targetChannels; ++ch) { - uint32_t leftChIndex = Min(ch, (preNodeInfo_.channels - 1)); - targetData[i * targetChannels + ch] = - dstData[i * preNodeInfo_.channels + leftChIndex]; - } - } - -#ifdef ENABLE_HOOK_PCM - if (outputPcmDumper_ != nullptr) { - outputPcmDumper_->CheckAndReopenHandle(); - outputPcmDumper_->Dump( - (int8_t *)(resampleOutput_.GetPcmDataBuffer()), GetFrameLen() * sizeof(float) * GetChannelCount()); - } -#endif -} - -void HpaeResampleNode::ConnectWithInfo(const std::shared_ptr> &preNode, - HpaeNodeInfo &nodeInfo) -{ - inputStream_.Connect(preNode->GetSharedInstance(), preNode->GetOutputPort(nodeInfo)); - resampleOutput_.SetSourceBufferType(preNode->GetOutputPortBufferType(nodeInfo)); -} - -void HpaeResampleNode::DisConnectWithInfo(const std::shared_ptr> &preNode, - HpaeNodeInfo &nodeInfo) -{ - inputStream_.DisConnect(preNode->GetOutputPort(nodeInfo, true)); -} - -} // namespace HPAE -} // namespace AudioStandard -} // namespace OHOS \ No newline at end of file diff --git a/services/audio_engine/plugin/resample/include/audio_proresampler.h b/services/audio_engine/plugin/resample/include/audio_proresampler.h index 8b25ea53f4574c23e8f7ded9a1cc548e744964cf..ed16864bcee7a655e6cfb42dee94b45d197c6bdf 100644 --- a/services/audio_engine/plugin/resample/include/audio_proresampler.h +++ b/services/audio_engine/plugin/resample/include/audio_proresampler.h @@ -56,8 +56,8 @@ private: uint32_t outRate_; uint32_t channels_; uint32_t quality_; - uint32_t expectedOutFrameLen_; - uint32_t expectedInFrameLen_; + uint32_t expectedOutFrameLen_ = 0; + uint32_t expectedInFrameLen_ = 0; SingleStagePolyphaseResamplerState* state_ = nullptr; }; } // HPAE diff --git a/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp b/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp index bc4a4bb09d54795a5dad14f8504e337e94c6db32..7145fc53b5801ca73e44319426de18dd44a9f39d 100644 --- a/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp +++ b/services/audio_engine/plugin/resample/proresampler/audio_proresampler.cpp @@ -30,6 +30,11 @@ constexpr uint32_t FRAME_LEN_20MS = 20; constexpr uint32_t MS_PER_SECOND = 1000; constexpr uint32_t ADD_SIZE = 100; static constexpr uint32_t CUSTOM_SAMPLE_RATE_MULTIPLES = 50; +constexpr uint32_t MAX_CHANNELS = 16; +constexpr uint32_t MAX_SAMPLE_RATE = SAMPLE_RATE_384000; +constexpr uint32_t MIN_SAMPLE_RATE = SAMPLE_RATE_8000; +constexpr uint32_t MAX_FRAME_SIZE = SAMPLE_RATE_384000 * 10; // max frame size, max sample rate, 10s duration +constexpr uint32_t MAX_QUALITY = 10; // for now ProResampler accept input 20ms for other sample rates, 40ms input for 11025hz // 100ms input for 10Hz resolution rates that are not multiples of 50, eg. 8010, 8020, 8030, 8040... // however 8050, 8100, 8150... are for 20ms @@ -38,6 +43,19 @@ ProResampler::ProResampler(uint32_t inRate, uint32_t outRate, uint32_t channels, : inRate_(inRate), outRate_(outRate), channels_(channels), quality_(quality), expectedOutFrameLen_(outRate_ * FRAME_LEN_20MS / MS_PER_SECOND) { + CHECK_AND_RETURN_LOG(inRate == outRate, + "input and output rate of ProResampler should be different! Same Rate: %{public}d", inRate); + + CHECK_AND_RETURN_LOG((inRate_ >= MIN_SAMPLE_RATE) && (inRate_ <= MAX_SAMPLE_RATE) && + (outRate_ >= MIN_SAMPLE_RATE) && (outRate_ <= MAX_SAMPLE_RATE), + "resampler input and output sample rate should be within [8000, 384000]. " + "inRate_ %{public}d, outRate_ %{public}d is not valid", inRate_, outRate_); + + CHECK_AND_RETURN_LOG((channels_ > 0) && (channels_ <= MAX_CHANNELS), "invalid channel number: %{public}d, " + "channel number should within [1, 10]", channels_); + + CHECK_AND_RETURN_LOG((quality >= 0) && (quality <= MAX_QUALITY), "invalid quality level: %{public}d", quality); + if (inRate_ == SAMPLE_RATE_11025) { // for 11025, process input 40ms per time and output 20ms per time buf11025_.reserve(expectedOutFrameLen_ * channels_ * BUFFER_EXPAND_SIZE_2 + ADD_SIZE); AUDIO_INFO_LOG("input 11025hz, output resample rate %{public}d, buf11025_ size %{public}d", @@ -64,8 +82,10 @@ ProResampler::ProResampler(uint32_t inRate, uint32_t outRate, uint32_t channels, int32_t ProResampler::Process(const float *inBuffer, uint32_t inFrameSize, float *outBuffer, uint32_t outFrameSize) { - CHECK_AND_RETURN_RET_LOG(state_ != nullptr, RESAMPLER_ERR_ALLOC_FAILED, - "resampler is %{public}s", ErrCodeToString(RESAMPLER_ERR_ALLOC_FAILED).c_str()); + CHECK_AND_RETURN_RET_LOG(state_ != nullptr, RESAMPLER_ERR_ALLOC_FAILED, "resampler state is invalid"); + CHECK_AND_RETURN_RET_LOG((0 <= inFrameSize) && (inFrameSize <= MAX_FRAME_SIZE) && + (0 <= outFrameSize) && (outFrameSize <= MAX_FRAME_SIZE), RESAMPLER_ERR_ALLOC_FAILED, "inFrameSize %{public}d" + "or outFrameSize %{public}d out of valid range", inFrameSize, outFrameSize); if (inRate_ == SAMPLE_RATE_11025) { return Process11025SampleRate(inBuffer, inFrameSize, outBuffer, outFrameSize); } else if (inRate_ % CUSTOM_SAMPLE_RATE_MULTIPLES != 0) { @@ -195,6 +215,11 @@ int32_t ProResampler::Process10HzSampleRate(const float *inBuffer, uint32_t inFr int32_t ProResampler::UpdateRates(uint32_t inRate, uint32_t outRate) { + CHECK_AND_RETURN_RET_LOG((inRate >= MIN_SAMPLE_RATE) && (inRate <= MAX_SAMPLE_RATE) && + (outRate >= MIN_SAMPLE_RATE) && (outRate <= MAX_SAMPLE_RATE), RESAMPLER_ERR_INVALID_ARG, + "resampler input and output sample rate should be within [8000, 384000]. " + "inRate_ %{public}d, outRate_ %{public}d is not valid", inRate, outRate); + CHECK_AND_RETURN_RET_LOG(state_ != nullptr, RESAMPLER_ERR_ALLOC_FAILED, "resampler is null"); inRate_ = inRate; outRate_ = outRate; expectedOutFrameLen_ = outRate_ * FRAME_LEN_20MS / MS_PER_SECOND; @@ -204,7 +229,6 @@ int32_t ProResampler::UpdateRates(uint32_t inRate, uint32_t outRate) } else if (inRate_ % CUSTOM_SAMPLE_RATE_MULTIPLES != 0) { expectedInFrameLen_ = inRate_ * FRAME_LEN_20MS * BUFFER_EXPAND_SIZE_5 / MS_PER_SECOND; } - CHECK_AND_RETURN_RET_LOG(state_ != nullptr, RESAMPLER_ERR_ALLOC_FAILED, "resampler is null"); int32_t ret = SingleStagePolyphaseResamplerSetRate(state_, inRate_, outRate_); CHECK_AND_RETURN_RET_LOG(ret == RESAMPLER_ERR_SUCCESS, ret, "error code %{public}s", ErrCodeToString(ret).c_str()); @@ -213,9 +237,14 @@ int32_t ProResampler::UpdateRates(uint32_t inRate, uint32_t outRate) int32_t ProResampler::UpdateChannels(uint32_t channels) { - uint32_t oldChannels = channels_; + CHECK_AND_RETURN_RET_LOG((channels > 0) && (channels <= MAX_CHANNELS), RESAMPLER_ERR_ALLOC_FAILED, + "invalid channel number: %{public}d, channel number should within [1, 10]", channels); + CHECK_AND_RETURN_RET_LOG(state_ != nullptr, RESAMPLER_ERR_ALLOC_FAILED, "resampler is null"); + + AUDIO_INFO_LOG("update work channel success old channel: %{public}d, new channel: %{public}d", + channels_, channels); + channels_ = channels; - CHECK_AND_RETURN_RET_LOG(state_ != nullptr, RESAMPLER_ERR_ALLOC_FAILED, "ProResampler: resampler is null"); SingleStagePolyphaseResamplerFree(state_); int32_t errRet = RESAMPLER_ERR_SUCCESS; @@ -223,8 +252,6 @@ int32_t ProResampler::UpdateChannels(uint32_t channels) CHECK_AND_RETURN_RET_LOG(state_ && (errRet == RESAMPLER_ERR_SUCCESS), errRet, "error code %{public}s", ErrCodeToString(errRet).c_str()); - AUDIO_INFO_LOG("success old channels: %{public}d, new channels: %{public}d", oldChannels, channels_); - return SingleStagePolyphaseResamplerSkipHalfTaps(state_); } diff --git a/services/audio_engine/test/unittest/BUILD.gn b/services/audio_engine/test/unittest/BUILD.gn index 6cec754c06aebfc1468eb3a5c10cdf1747fa8e57..761e69096b0c87e089efc1587390c14107c759f2 100644 --- a/services/audio_engine/test/unittest/BUILD.gn +++ b/services/audio_engine/test/unittest/BUILD.gn @@ -544,28 +544,6 @@ ohos_unittest("hpae_process_cluster_test") { resource_config_file = "./resource/ohos_test.xml" } -ohos_unittest("hpae_resample_node_test") { - module_out_path = module_output_path - sources = [ - "common/test_case_common.cpp", - "node/hpae_resample_node_test.cpp", - ] - - configs = [ ":audio_engine_private_config" ] - - deps = [ - "../../:audio_engine_manager", - "../../:audio_engine_node", - "../../:audio_engine_utils", - "../../../audio_service:audio_common", - "../../../../frameworks/native/audioeffect:audio_effect", - ] - - external_deps = engine_test_external_deps - - resource_config_file = "./resource/ohos_test.xml" -} - ohos_unittest("hpae_sink_input_node_test") { module_out_path = module_output_path sources = [ diff --git a/services/audio_engine/test/unittest/node/hpae_resample_node_test.cpp b/services/audio_engine/test/unittest/node/hpae_resample_node_test.cpp deleted file mode 100644 index 333aa7b5107b847636ae6a03969aa7dab2ef5512..0000000000000000000000000000000000000000 --- a/services/audio_engine/test/unittest/node/hpae_resample_node_test.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ -#include -#include -#include -#include -#include "hpae_sink_input_node.h" -#include "hpae_resample_node.h" -#include "hpae_sink_output_node.h" -#include "hpae_source_input_node.h" -#include -#include -#include -#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; - -static constexpr uint32_t TEST_ID = 1243; -static constexpr uint32_t TEST_ID2 = 1246; -static constexpr uint32_t TEST_FRAMELEN1 = 960; -static constexpr uint32_t TEST_FRAMELEN2 = 640; -namespace { -class HpaeResampleNodeTest : public testing::Test { -public: - void SetUp(); - void TearDown(); -}; - -void HpaeResampleNodeTest::SetUp() -{} - -void HpaeResampleNodeTest::TearDown() -{} - -HWTEST_F(HpaeResampleNodeTest, constructHpaeResampleNode, TestSize.Level0) -{ - HpaeNodeInfo nodeInfo; - nodeInfo.nodeId = TEST_ID; - nodeInfo.frameLen = TEST_FRAMELEN1; - nodeInfo.samplingRate = SAMPLE_RATE_48000; - nodeInfo.channels = STEREO; - nodeInfo.format = SAMPLE_F32LE; - HpaeNodeInfo dstNodeInfo; - dstNodeInfo.nodeId = TEST_ID2; - dstNodeInfo.frameLen = TEST_FRAMELEN1; - dstNodeInfo.samplingRate = SAMPLE_RATE_44100; - dstNodeInfo.channels = CHANNEL_4; - dstNodeInfo.format = SAMPLE_F32LE; - std::shared_ptr hpaeResampleNode = std::make_shared(nodeInfo, dstNodeInfo); - EXPECT_EQ(hpaeResampleNode->GetSampleRate(), dstNodeInfo.samplingRate); - EXPECT_EQ(hpaeResampleNode->GetFrameLen(), dstNodeInfo.frameLen); - EXPECT_EQ(hpaeResampleNode->GetChannelCount(), dstNodeInfo.channels); - EXPECT_EQ(hpaeResampleNode->GetBitWidth(), dstNodeInfo.format); - HpaeNodeInfo &retNi = hpaeResampleNode->GetNodeInfo(); - EXPECT_EQ(retNi.samplingRate, dstNodeInfo.samplingRate); - EXPECT_EQ(retNi.frameLen, dstNodeInfo.frameLen); - EXPECT_EQ(retNi.channels, dstNodeInfo.channels); - EXPECT_EQ(retNi.format, dstNodeInfo.format); -} - -HWTEST_F(HpaeResampleNodeTest, testReset, TestSize.Level0) -{ - HpaeNodeInfo nodeInfo; - nodeInfo.nodeId = TEST_ID; - nodeInfo.frameLen = TEST_FRAMELEN1; - nodeInfo.samplingRate = SAMPLE_RATE_48000; - nodeInfo.channels = STEREO; - nodeInfo.format = SAMPLE_F32LE; - HpaeNodeInfo dstNodeInfo; - dstNodeInfo.nodeId = TEST_ID2; - dstNodeInfo.frameLen = TEST_FRAMELEN1; - dstNodeInfo.samplingRate = SAMPLE_RATE_44100; - dstNodeInfo.channels = CHANNEL_4; - dstNodeInfo.format = SAMPLE_F32LE; - std::shared_ptr hpaeResampleNode = - std::make_shared(nodeInfo, dstNodeInfo, ResamplerType::PRORESAMPLER); - std::shared_ptr hpaeResampleNode2 = - std::make_shared(nodeInfo, dstNodeInfo, (ResamplerType)0xff); - EXPECT_EQ(hpaeResampleNode->GetSampleRate(), dstNodeInfo.samplingRate); - EXPECT_EQ(hpaeResampleNode->GetFrameLen(), dstNodeInfo.frameLen); - EXPECT_EQ(hpaeResampleNode->GetChannelCount(), dstNodeInfo.channels); - EXPECT_EQ(hpaeResampleNode->GetBitWidth(), dstNodeInfo.format); - HpaeNodeInfo &retNi = hpaeResampleNode->GetNodeInfo(); - EXPECT_EQ(retNi.samplingRate, dstNodeInfo.samplingRate); - EXPECT_EQ(retNi.frameLen, dstNodeInfo.frameLen); - EXPECT_EQ(retNi.channels, dstNodeInfo.channels); - EXPECT_EQ(retNi.format, dstNodeInfo.format); - EXPECT_EQ(hpaeResampleNode->Reset(), true); - EXPECT_EQ(hpaeResampleNode2->Reset(), false); -} - -HWTEST_F(HpaeResampleNodeTest, testSignalProcess_001, TestSize.Level0) -{ - HpaeNodeInfo nodeInfo; - nodeInfo.nodeId = TEST_ID; - nodeInfo.frameLen = TEST_FRAMELEN1; - nodeInfo.samplingRate = SAMPLE_RATE_48000; - nodeInfo.channels = STEREO; - nodeInfo.format = SAMPLE_F32LE; - HpaeNodeInfo dstNodeInfo; - dstNodeInfo.nodeId = TEST_ID2; - dstNodeInfo.frameLen = TEST_FRAMELEN1; - dstNodeInfo.samplingRate = SAMPLE_RATE_44100; - dstNodeInfo.channels = MONO; - dstNodeInfo.format = SAMPLE_F32LE; - std::shared_ptr hpaeResampleNode = std::make_shared(nodeInfo, dstNodeInfo); - - std::vector inputs; - EXPECT_EQ(hpaeResampleNode->SignalProcess(inputs), nullptr); - PcmBufferInfo pcmBufferInfo(MONO, TEST_FRAMELEN1, SAMPLE_RATE_44100); - HpaePcmBuffer hpaePcmBuffer(pcmBufferInfo); - inputs.emplace_back(&hpaePcmBuffer); - EXPECT_NE(hpaeResampleNode->SignalProcess(inputs), nullptr); - inputs.emplace_back(&hpaePcmBuffer); - EXPECT_NE(hpaeResampleNode->SignalProcess(inputs), nullptr); -} - -HWTEST_F(HpaeResampleNodeTest, testSignalProcess_002, TestSize.Level0) -{ - HpaeNodeInfo nodeInfo; - nodeInfo.nodeId = TEST_ID; - nodeInfo.frameLen = TEST_FRAMELEN1; - nodeInfo.samplingRate = SAMPLE_RATE_48000; - nodeInfo.channels = MONO; - nodeInfo.format = SAMPLE_F32LE; - HpaeNodeInfo dstNodeInfo; - dstNodeInfo.nodeId = TEST_ID2; - dstNodeInfo.frameLen = TEST_FRAMELEN1; - dstNodeInfo.samplingRate = SAMPLE_RATE_44100; - dstNodeInfo.channels = MONO; - dstNodeInfo.format = SAMPLE_F32LE; - std::shared_ptr hpaeResampleNode = - std::make_shared(nodeInfo, dstNodeInfo, (ResamplerType)0xff); - - std::vector inputs; - PcmBufferInfo pcmBufferInfo(MONO, TEST_FRAMELEN1, SAMPLE_RATE_44100); - HpaePcmBuffer hpaePcmBuffer(pcmBufferInfo); - inputs.emplace_back(&hpaePcmBuffer); - EXPECT_NE(hpaeResampleNode->SignalProcess(inputs), nullptr); - - std::shared_ptr hpaeResampleNode2 = - std::make_shared(nodeInfo, dstNodeInfo); - EXPECT_NE(hpaeResampleNode2->SignalProcess(inputs), nullptr); -} - -HWTEST_F(HpaeResampleNodeTest, testConnectWithInfo, TestSize.Level0) -{ - HpaeNodeInfo srcNodeInfo; - srcNodeInfo.nodeId = TEST_ID; - srcNodeInfo.frameLen = TEST_FRAMELEN1; - srcNodeInfo.samplingRate = SAMPLE_RATE_48000; - srcNodeInfo.channels = STEREO; - srcNodeInfo.format = SAMPLE_S32LE; - std::shared_ptr hpaeInputNode = std::make_shared(srcNodeInfo); - HpaeNodeInfo dstNodeInfo; - dstNodeInfo.nodeId = TEST_ID; - dstNodeInfo.frameLen = TEST_FRAMELEN2; - dstNodeInfo.samplingRate = SAMPLE_RATE_32000; - dstNodeInfo.channels = CHANNEL_4; - dstNodeInfo.format = SAMPLE_F32LE; - std::shared_ptr hpaeResampleNode = std::make_shared(srcNodeInfo, dstNodeInfo); - EXPECT_EQ(hpaeResampleNode->GetSampleRate(), dstNodeInfo.samplingRate); - EXPECT_EQ(hpaeResampleNode->GetFrameLen(), dstNodeInfo.frameLen); - EXPECT_EQ(hpaeResampleNode->GetChannelCount(), dstNodeInfo.channels); - EXPECT_EQ(hpaeResampleNode->GetBitWidth(), dstNodeInfo.format); - - hpaeResampleNode->ConnectWithInfo(hpaeInputNode, srcNodeInfo); - hpaeResampleNode->DisConnectWithInfo(hpaeInputNode, srcNodeInfo); -} -} // namespace diff --git a/test/BUILD.gn b/test/BUILD.gn index 8c1d68c43f9fd229afea6b73d0d7dfbbe7d98cc5..ad551516dfa51b98d719befc8d284a051695e6a1 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -96,7 +96,6 @@ group("audio_unit_test") { "../services/audio_engine/test/unittest:hpae_remote_sink_output_node_test", "../services/audio_engine/test/unittest:hpae_render_effect_node_test", "../services/audio_engine/test/unittest:hpae_render_manager_test", - "../services/audio_engine/test/unittest:hpae_resample_node_test", "../services/audio_engine/test/unittest:hpae_signal_process_thread_test", "../services/audio_engine/test/unittest:hpae_sink_input_node_test", "../services/audio_engine/test/unittest:hpae_sink_output_node_test", @@ -298,7 +297,7 @@ group("audio_fuzz_test") { "fuzztest/captureclockmanager_fuzzer:fuzztest", "fuzztest/capturerinserver_fuzzer:fuzztest", "fuzztest/capturermanager_fuzzer:fuzztest", - "fuzztest/channelconverter_fuzzer:fuzztest", + "fuzztest/hpaechannelconverter_fuzzer:fuzztest", "fuzztest/coreserviceproviderstub_fuzzer:fuzztest", "fuzztest/deviceinitcallback_fuzzer:fuzztest", "fuzztest/devicestatuslistener_fuzzer:fuzztest", @@ -307,7 +306,6 @@ group("audio_fuzz_test") { "fuzztest/formatconverter_fuzzer:fuzztest", "fuzztest/futextool_fuzzer:fuzztest", "fuzztest/hapeaudioformatconverternode_fuzzer:fuzztest", - "fuzztest/hpaedownmixer_fuzzer:fuzztest", "fuzztest/hpaecaptureeffectnode_fuzzer:fuzztest", "fuzztest/hpaecapturermanager_fuzzer:fuzztest", "fuzztest/hpaecapturerstreamimpl_fuzzer:fuzztest", @@ -328,11 +326,10 @@ group("audio_fuzz_test") { "fuzztest/hpaepcmprocess_fuzzer:fuzztest", "fuzztest/hpaepolicymanager_fuzzer:fuzztest", "fuzztest/hpaeprocesscluster_fuzzer:fuzztest", - "fuzztest/hpaeproresamplerprocess_fuzzer:fuzztest", + "fuzztest/hpaeproresampler_fuzzer:fuzztest", "fuzztest/hpaeremoteoutputcluster_fuzzer:fuzztest", "fuzztest/hpaerenderermanager_fuzzer:fuzztest", "fuzztest/hpaerenderermanageradd_fuzzer:fuzztest", - "fuzztest/hpaeresamplenode_fuzzer:fuzztest", "fuzztest/hpaesinkinputnode_fuzzer:fuzztest", "fuzztest/hpaesinkoutputnode_fuzzer:fuzztest", "fuzztest/hpaesoftlink_fuzzer:fuzztest", diff --git a/test/fuzztest/channelconverter_fuzzer/BUILD.gn b/test/fuzztest/channelconverter_fuzzer/BUILD.gn deleted file mode 100644 index 0456d34232e36181d16966d78f2fc8d59744ca54..0000000000000000000000000000000000000000 --- a/test/fuzztest/channelconverter_fuzzer/BUILD.gn +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# 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. - -import("//build/config/features.gni") -import("//build/test.gni") - -ohos_fuzztest("ChannelConverterFuzzTest") { - module_out_path = "audio_framework/audio_framework_route" - fuzz_config_file = "../channelconverter_fuzzer" - - include_dirs = [ - "../../../services/audio_engine/plugin/channel_converter/include", - "../../../interfaces/inner_api/native/audiocommon/include", - ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - cflags_cc = cflags - cflags_cc += [ "-fno-access-control" ] - - sources = [ "channel_converter_fuzzer.cpp" ] - - deps = [ - "../../../services/audio_engine:audio_engine_plugins", - ] - - external_deps = [ - "hilog:libhilog", - "os_account:os_account_innerkits", - ] -} - -group("fuzztest") { - testonly = true - deps = [ ":ChannelConverterFuzzTest" ] -} diff --git a/test/fuzztest/channelconverter_fuzzer/channel_converter_fuzzer.cpp b/test/fuzztest/channelconverter_fuzzer/channel_converter_fuzzer.cpp deleted file mode 100644 index e2542e2e73ebe60e9e63bfc8a65b0a0c7f77317e..0000000000000000000000000000000000000000 --- a/test/fuzztest/channelconverter_fuzzer/channel_converter_fuzzer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ - -#include -#include "channel_converter.h" -#include "audio_stream_info.h" -#include "audio_log.h" -#include "../fuzz_utils.h" - -namespace OHOS { -namespace AudioStandard { -using namespace OHOS::AudioStandard::HPAE; -using namespace std; -using namespace HPAE; - -FuzzUtils &g_fuzzUtils = FuzzUtils::GetInstance(); -const size_t THRESHOLD = 10; - -void SetParamFuzzTest() -{ - std::shared_ptr channelConverter = std::make_shared(); - CHECK_AND_RETURN(channelConverter != nullptr); - AudioChannelInfo inChannelInfo = { - .channelLayout = g_fuzzUtils.GetData(), - .numChannels = g_fuzzUtils.GetData(), - }; - AudioChannelInfo outChannelInfo = { - .channelLayout = g_fuzzUtils.GetData(), - .numChannels = g_fuzzUtils.GetData(), - }; - AudioSampleFormat format = g_fuzzUtils.GetData(); - bool mixLfe = g_fuzzUtils.GetData(); - - channelConverter->SetParam(inChannelInfo, outChannelInfo, format, mixLfe); -} - -void SetInChannelInfoFuzzTest() -{ - std::shared_ptr channelConverter = std::make_shared(); - CHECK_AND_RETURN(channelConverter != nullptr); - AudioChannelInfo inChannelInfo = { - .channelLayout = g_fuzzUtils.GetData(), - .numChannels = g_fuzzUtils.GetData(), - }; - channelConverter->SetInChannelInfo(inChannelInfo); -} - -void SetOutChannelInfoFuzzTest() -{ - std::shared_ptr channelConverter = std::make_shared(); - CHECK_AND_RETURN(channelConverter != nullptr); - AudioChannelInfo outChannelInfo = { - .channelLayout = g_fuzzUtils.GetData(), - .numChannels = g_fuzzUtils.GetData(), - }; - channelConverter->SetOutChannelInfo(outChannelInfo); -} - -void SetParamsecondFuzzTest() -{ - std::shared_ptr channelConverter = std::make_shared(); - CHECK_AND_RETURN(channelConverter != nullptr); - AudioChannelInfo inChannelInfo; - AudioChannelInfo outChannelInfo; - inChannelInfo.numChannels = g_fuzzUtils.GetData(); - outChannelInfo.numChannels = g_fuzzUtils.GetData(); - AudioSampleFormat workFormat = g_fuzzUtils.GetData(); - bool mixLfe = g_fuzzUtils.GetData(); - channelConverter->SetParam(inChannelInfo, outChannelInfo, workFormat, mixLfe); -} - -vector g_testFuncs = { - SetParamFuzzTest, - SetInChannelInfoFuzzTest, - SetOutChannelInfoFuzzTest, - SetParamsecondFuzzTest, -}; - -} // namespace AudioStandard -} // namesapce OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - if (size < OHOS::AudioStandard::THRESHOLD) { - return 0; - } - - OHOS::AudioStandard::g_fuzzUtils.fuzzTest(data, size, OHOS::AudioStandard::g_testFuncs); - return 0; -} diff --git a/test/fuzztest/hpaeproresamplerprocess_fuzzer/BUILD.gn b/test/fuzztest/hpaechannelconverter_fuzzer/BUILD.gn similarity index 89% rename from test/fuzztest/hpaeproresamplerprocess_fuzzer/BUILD.gn rename to test/fuzztest/hpaechannelconverter_fuzzer/BUILD.gn index 8bec994792d99211cca0388e6e78fe2872d99dae..c77cbaa3844a380f64abe477c6c266b7f1b2ab05 100644 --- a/test/fuzztest/hpaeproresamplerprocess_fuzzer/BUILD.gn +++ b/test/fuzztest/hpaechannelconverter_fuzzer/BUILD.gn @@ -18,9 +18,9 @@ import("../../../appgallery.gni") import("../../../bluetooth_part.gni") import("../../../config.gni") -ohos_fuzztest("HpaeProresamplerProcessFuzzTest") { +ohos_fuzztest("HpaeChannelConverterFuzzTest") { module_out_path = "audio_framework/audio_framework_engine" - fuzz_config_file = "../hpaeproresamplerprocess_fuzzer" + fuzz_config_file = "../hpaechannelconverter_fuzzer" include_dirs = [ "../../../services/audio_engine/node/include", @@ -37,7 +37,7 @@ ohos_fuzztest("HpaeProresamplerProcessFuzzTest") { ] sources = [ - "hpae_proresampler_process_fuzzer.cpp", + "hpae_channel_converter_fuzzer.cpp", ] cflags_cc = [ "-std=c++20" ] @@ -66,5 +66,5 @@ ohos_fuzztest("HpaeProresamplerProcessFuzzTest") { group("fuzztest") { testonly = true - deps = [ ":HpaeProresamplerProcessFuzzTest" ] -} + deps = [ ":HpaeChannelConverterFuzzTest" ] +} \ No newline at end of file diff --git a/test/fuzztest/channelconverter_fuzzer/corpus/init b/test/fuzztest/hpaechannelconverter_fuzzer/corpus/init similarity index 100% rename from test/fuzztest/channelconverter_fuzzer/corpus/init rename to test/fuzztest/hpaechannelconverter_fuzzer/corpus/init diff --git a/test/fuzztest/hpaedownmixer_fuzzer/hpae_down_mixer_fuzzer.cpp b/test/fuzztest/hpaechannelconverter_fuzzer/hpae_channel_converter_fuzzer.cpp similarity index 70% rename from test/fuzztest/hpaedownmixer_fuzzer/hpae_down_mixer_fuzzer.cpp rename to test/fuzztest/hpaechannelconverter_fuzzer/hpae_channel_converter_fuzzer.cpp index 94ac54364f466437f3a22a549972d52ccee76242..30f440c0df72866975162c5a1ca4d48d99257ad5 100644 --- a/test/fuzztest/hpaedownmixer_fuzzer/hpae_down_mixer_fuzzer.cpp +++ b/test/fuzztest/hpaechannelconverter_fuzzer/hpae_channel_converter_fuzzer.cpp @@ -24,7 +24,7 @@ #include "volume_ramp.h" #include #include -#include "down_mixer.h" +#include "channel_converter.h" #include "audio_engine_log.h" namespace OHOS { @@ -41,6 +41,7 @@ const char* DEFAULT_TEST_DEVICE_NETWORKID = "LocalDevice"; constexpr size_t THRESHOLD = 10; // need full audio channel layouts to cover all cases during setting up downmix table -- first part +// 16 channels constexpr static AudioChannelLayout FIRST_PART_CH_LAYOUTS = static_cast ( FRONT_LEFT | FRONT_RIGHT | FRONT_CENTER | LOW_FREQUENCY | BACK_LEFT | BACK_RIGHT | @@ -50,6 +51,7 @@ constexpr static AudioChannelLayout FIRST_PART_CH_LAYOUTS = static_cast ( TOP_CENTER | TOP_BACK_LEFT | TOP_BACK_CENTER | TOP_BACK_RIGHT | STEREO_LEFT | STEREO_RIGHT | @@ -119,8 +121,9 @@ const static std::map DOWNMIX_CHANNEL_COUNT_MA }; constexpr uint32_t TEST_FORMAT_SIZE = 4; -constexpr uint32_t TEST_FRAME_LEN = 100; -constexpr uint32_t TEST_BUFFER_LEN = 10; +constexpr AudioSampleFormat TEST_FORMAT = SAMPLE_F32LE; +constexpr uint32_t TEST_ERR_FRAME_LEN = 100; +constexpr uint32_t TEST_FRAME_LEN = 10; constexpr bool MIX_FLE = true; static uint32_t BitCounts(uint64_t bits) @@ -160,42 +163,40 @@ uint32_t GetArrLength(T& arr) void SetParamFuzzTest() { - // invalid input Param - DownMixer downMixer; + // real FuzzTest random input AudioChannelInfo inChannelInfo; AudioChannelInfo outChannelInfo; - inChannelInfo.numChannels = MAX_CHANNELS + 1; - inChannelInfo.channelLayout = CH_LAYOUT_UNKNOWN; - outChannelInfo.numChannels = MAX_CHANNELS + 1; - outChannelInfo.channelLayout = CH_LAYOUT_UNKNOWN; - downMixer.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT_SIZE, MIX_FLE); + ChannelConverter channelConverter; + inChannelInfo.channelLayout = static_cast(GetData()); + inChannelInfo.numChannels = BitCounts(inChannelInfo.channelLayout); + outChannelInfo.channelLayout = static_cast(GetData()); + outChannelInfo.numChannels = BitCounts(outChannelInfo.channelLayout); + channelConverter.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT, MIX_FLE); - // valid param, predefined downmix rules + // valid param, predefined downmix rules, only for ensuring coverage rate for (AudioChannelLayout outLayout: OUTPUT_CH_LAYOUT_SET) { outChannelInfo.numChannels = BitCounts(outLayout); outChannelInfo.channelLayout = outLayout; for (AudioChannelLayout inLayout: FULL_CH_LAYOUT_SET) { inChannelInfo.channelLayout = inLayout; inChannelInfo.numChannels = MAX_CHANNELS; - downMixer.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT_SIZE, MIX_FLE); + channelConverter.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT, MIX_FLE); } } - // valid param, general downmix table rule + // valid param, general downmix table rule, only ensuring coverage rate for (AudioChannelLayout outLayout: GENERAL_OUTPUT_CH_LAYOUT_SET) { outChannelInfo.numChannels = BitCounts(outLayout); outChannelInfo.channelLayout = outLayout; for (AudioChannelLayout inLayout: FULL_CH_LAYOUT_SET) { inChannelInfo.channelLayout = inLayout; inChannelInfo.numChannels = MAX_CHANNELS; - downMixer.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT_SIZE, MIX_FLE); + channelConverter.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT, MIX_FLE); } } -} -void SetDefaultChannelLayoutFuzzTest() -{ DownMixer downMixer; + // make sure more coverage: SetDefaultChannelLayout for (auto pair : DOWNMIX_CHANNEL_COUNT_MAP) { downMixer.SetDefaultChannelLayout(pair.first); } @@ -203,8 +204,9 @@ void SetDefaultChannelLayoutFuzzTest() downMixer.CheckIsHOA(CH_LAYOUT_UNKNOWN); } -void ProcesFuzzTest1() +void DownMixProcesFuzzTest() { + // test downmix case AudioChannelInfo inChannelInfo; AudioChannelInfo outChannelInfo; inChannelInfo.channelLayout = CH_LAYOUT_5POINT1; @@ -212,72 +214,71 @@ void ProcesFuzzTest1() outChannelInfo.channelLayout = CH_LAYOUT_STEREO; outChannelInfo.numChannels = STEREO; - // test uninitialized - DownMixer downMixer; - std::vector in(TEST_BUFFER_LEN * CHANNEL_6, 0.0f); - std::vector out(TEST_BUFFER_LEN * STEREO, 0.0f); + // test downmix uninitialized for line coverage + ChannelConverter channelConverter; + std::vector in(TEST_FRAME_LEN * CHANNEL_6, 0.0f); + std::vector out(TEST_FRAME_LEN * STEREO, 0.0f); uint32_t testInBufferSize = in.size() * TEST_FORMAT_SIZE; uint32_t testOutBufferSize = out.size() * TEST_FORMAT_SIZE; - downMixer.Process(TEST_BUFFER_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); + channelConverter.Process(TEST_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); - // test input and output buffer length smaller than expected - downMixer.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT_SIZE, MIX_FLE); - downMixer.Process(TEST_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); + // test input and output buffer length smaller than expected for line coverage + channelConverter.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT, MIX_FLE); + channelConverter.Process(TEST_ERR_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); // test process usual channel layout - downMixer.Process(TEST_BUFFER_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); + for (uint32_t i = 0; i < in.size(); i++) { + in[i] = GetData(); + } + channelConverter.Process(TEST_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); // test process HOA inChannelInfo.channelLayout = CH_LAYOUT_HOA_ORDER2_ACN_SN3D; inChannelInfo.numChannels = CHANNEL_9; - in.resize(CHANNEL_9 * TEST_BUFFER_LEN, 0.0f); + in.resize(CHANNEL_9 * TEST_FRAME_LEN, 0.0f); testInBufferSize = in.size() * TEST_FORMAT_SIZE; - downMixer.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT_SIZE, MIX_FLE); - downMixer.Process(TEST_BUFFER_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); + for (uint32_t i = 0; i < in.size(); i++) { + in[i] = GetData(); + } + channelConverter.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT, MIX_FLE); + channelConverter.Process(TEST_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); } -void ProcesFuzzTest2() +void UpMixProcesFuzzTest() { + // test upmix case AudioChannelInfo inChannelInfo; AudioChannelInfo outChannelInfo; - inChannelInfo.channelLayout = CH_LAYOUT_5POINT1; - inChannelInfo.numChannels = CHANNEL_6; - outChannelInfo.channelLayout = CH_LAYOUT_STEREO; - outChannelInfo.numChannels = STEREO; + inChannelInfo.channelLayout = CH_LAYOUT_STEREO; + inChannelInfo.numChannels = STEREO; + outChannelInfo.channelLayout = CH_LAYOUT_9POINT1POINT6; + outChannelInfo.numChannels = CHANNEL_16; - // test uninitialized - DownMixer downMixer; - std::vector in(TEST_BUFFER_LEN * CHANNEL_6, 0.0f); - std::vector out(TEST_BUFFER_LEN * STEREO, 0.0f); - for (size_t i = 0; i < TEST_BUFFER_LEN * CHANNEL_6; i++) { - in[i] = GetData(); - } + // test upmix uninitialized for line coverage + ChannelConverter channelConverter; + std::vector in(TEST_FRAME_LEN * STEREO, 0.0f); + std::vector out(TEST_FRAME_LEN * CHANNEL_16, 0.0f); uint32_t testInBufferSize = in.size() * TEST_FORMAT_SIZE; uint32_t testOutBufferSize = out.size() * TEST_FORMAT_SIZE; - downMixer.Process(TEST_BUFFER_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); + channelConverter.Process(TEST_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); + + channelConverter.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT, MIX_FLE); - // test input and output buffer length smaller than expected - downMixer.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT_SIZE, MIX_FLE); - downMixer.Process(TEST_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); + // test data with input samller than expected + channelConverter.Process(TEST_ERR_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); // test process usual channel layout - downMixer.Process(TEST_BUFFER_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); - - // test process HOA - inChannelInfo.channelLayout = CH_LAYOUT_HOA_ORDER2_ACN_SN3D; - inChannelInfo.numChannels = CHANNEL_9; - in.resize(CHANNEL_9 * TEST_BUFFER_LEN, 0.0f); - testInBufferSize = in.size() * TEST_FORMAT_SIZE; - downMixer.SetParam(inChannelInfo, outChannelInfo, TEST_FORMAT_SIZE, MIX_FLE); - downMixer.Process(TEST_BUFFER_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); + for (uint32_t i = 0; i < in.size(); i++) { + in[i] = GetData(); + } + channelConverter.Process(TEST_FRAME_LEN, in.data(), testInBufferSize, out.data(), testOutBufferSize); } typedef void (*TestFuncs)(); TestFuncs g_testFuncs[] = { SetParamFuzzTest, - SetDefaultChannelLayoutFuzzTest, - ProcesFuzzTest1, - ProcesFuzzTest2, + DownMixProcesFuzzTest, + UpMixProcesFuzzTest, }; bool FuzzTest(const uint8_t* rawData, size_t size) diff --git a/test/fuzztest/channelconverter_fuzzer/project.xml b/test/fuzztest/hpaechannelconverter_fuzzer/project.xml similarity index 100% rename from test/fuzztest/channelconverter_fuzzer/project.xml rename to test/fuzztest/hpaechannelconverter_fuzzer/project.xml diff --git a/test/fuzztest/hpaedownmixer_fuzzer/corpus/init b/test/fuzztest/hpaedownmixer_fuzzer/corpus/init deleted file mode 100644 index 8f37f09254457133cae0f828d0a5faee7dcbd779..0000000000000000000000000000000000000000 --- a/test/fuzztest/hpaedownmixer_fuzzer/corpus/init +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# 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. -FUZZ \ No newline at end of file diff --git a/test/fuzztest/hpaedownmixer_fuzzer/project.xml b/test/fuzztest/hpaedownmixer_fuzzer/project.xml deleted file mode 100644 index 66e1dcac475475fb101b6f8670ec699e6e9696aa..0000000000000000000000000000000000000000 --- a/test/fuzztest/hpaedownmixer_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/hpaedownmixer_fuzzer/BUILD.gn b/test/fuzztest/hpaeproresampler_fuzzer/BUILD.gn similarity index 91% rename from test/fuzztest/hpaedownmixer_fuzzer/BUILD.gn rename to test/fuzztest/hpaeproresampler_fuzzer/BUILD.gn index 819dc62aa65df5ed2e31cea55f3bec044b46c208..4271dcfa494ee05a06cb76064f35504403769f30 100644 --- a/test/fuzztest/hpaedownmixer_fuzzer/BUILD.gn +++ b/test/fuzztest/hpaeproresampler_fuzzer/BUILD.gn @@ -18,9 +18,9 @@ import("../../../appgallery.gni") import("../../../bluetooth_part.gni") import("../../../config.gni") -ohos_fuzztest("HpaeDownMixerFuzzTest") { +ohos_fuzztest("HpaeProresamplerFuzzTest") { module_out_path = "audio_framework/audio_framework_engine" - fuzz_config_file = "../hpaedownmixer_fuzzer" + fuzz_config_file = "../hpaeproresampler_fuzzer" include_dirs = [ "../../../services/audio_engine/node/include", @@ -37,7 +37,7 @@ ohos_fuzztest("HpaeDownMixerFuzzTest") { ] sources = [ - "hpae_down_mixer_fuzzer.cpp", + "hpae_proresampler_fuzzer.cpp", ] cflags_cc = [ "-std=c++20" ] @@ -66,5 +66,5 @@ ohos_fuzztest("HpaeDownMixerFuzzTest") { group("fuzztest") { testonly = true - deps = [ ":HpaeDownMixerFuzzTest" ] + deps = [ ":HpaeProresamplerFuzzTest" ] } \ No newline at end of file diff --git a/test/fuzztest/hpaeproresamplerprocess_fuzzer/corpus/init b/test/fuzztest/hpaeproresampler_fuzzer/corpus/init similarity index 100% rename from test/fuzztest/hpaeproresamplerprocess_fuzzer/corpus/init rename to test/fuzztest/hpaeproresampler_fuzzer/corpus/init diff --git a/test/fuzztest/hpaeresamplenode_fuzzer/hpaeresamplenode_fuzzer.cpp b/test/fuzztest/hpaeproresampler_fuzzer/hpae_proresampler_fuzzer.cpp similarity index 40% rename from test/fuzztest/hpaeresamplenode_fuzzer/hpaeresamplenode_fuzzer.cpp rename to test/fuzztest/hpaeproresampler_fuzzer/hpae_proresampler_fuzzer.cpp index e1bfec920c06a409a375ed505f80c5ab616ac4fa..cfb9b09def745189e92a60d6e78ed2f4da95d17d 100644 --- a/test/fuzztest/hpaeresamplenode_fuzzer/hpaeresamplenode_fuzzer.cpp +++ b/test/fuzztest/hpaeproresampler_fuzzer/hpae_proresampler_fuzzer.cpp @@ -16,33 +16,31 @@ #include #include #include -#include -#include -#include -#include -#include "hpae_resample_node.h" -#include "hpae_source_input_node.h" +#include +#include "audio_utils.h" +#include +#include +#include "audio_proresampler_process.h" #include "audio_engine_log.h" -#include "audio_info.h" -#include -#include -#include -using namespace std; -using namespace OHOS::AudioStandard::HPAE; - - +#include "audio_proresampler.h" +#include "audio_stream_info.h" namespace OHOS { namespace AudioStandard { - -static const uint8_t *RAW_DATA = nullptr; +using namespace std; +using namespace HPAE; +static const uint8_t* RAW_DATA = nullptr; static size_t g_dataSize = 0; static size_t g_pos; const size_t THRESHOLD = 10; -const uint32_t TEST_ID = 1243; -const uint32_t TEST_ID2 = 1246; -const uint32_t TEST_FRAMELEN1 = 960; -const uint32_t TEST_FRAMELEN2 = 640; - +const static std::vector TEST_CHANNELS = {MONO, STEREO, CHANNEL_6}; + +constexpr uint32_t QUALITY_ONE = 1; +constexpr uint32_t FRAME_LEN_100MS = 100; +constexpr uint32_t FRAME_LEN_40MS = 40; +constexpr uint32_t FRAME_LEN_20MS = 20; +constexpr uint32_t MS_PER_SECOND = 1000; +constexpr uint32_t PROCESS_LOOP_COUNT = 10; +constexpr uint32_t CUSTOME_RATE_MULTIPLE = 50; template T GetData() { @@ -69,82 +67,81 @@ uint32_t GetArrLength(T& arr) return sizeof(arr) / sizeof(arr[0]); } -static void GetTestNodeInfo(HpaeNodeInfo &nodeInfo) +// test initialize resampler, update resampler +void ResampleBaseTest() { - nodeInfo.nodeId = TEST_ID; - nodeInfo.frameLen = TEST_FRAMELEN1; - nodeInfo.samplingRate = SAMPLE_RATE_48000; - nodeInfo.channels = STEREO; - nodeInfo.format = SAMPLE_F32LE; + uint32_t inRate = GetData(); + uint32_t outRate = GetData(); + uint32_t quality = GetData(); + uint32_t channels = GetData(); + + ProResampler resampler(inRate, outRate, channels, quality); + + inRate = GetData(); + outRate = GetData(); + resampler.UpdateRates(inRate, outRate); + + channels = GetData(); + resampler.UpdateChannels(channels); } -static void GetTestDtsNodeInfo(HpaeNodeInfo &nodeInfo) +void ResampleProcessTest() { - nodeInfo.nodeId = TEST_ID2; - nodeInfo.frameLen = TEST_FRAMELEN2; - nodeInfo.samplingRate = SAMPLE_RATE_44100; - nodeInfo.channels = CHANNEL_4; - nodeInfo.format = SAMPLE_F32LE; -} + uint32_t inRate = GetData(); + uint32_t outRate = GetData(); -void HpaeResampleNodeResetFuzzTest() -{ - HpaeNodeInfo nodeInfo; - HpaeNodeInfo dstNodeInfo; - GetTestNodeInfo(nodeInfo); - GetTestDtsNodeInfo(dstNodeInfo); - auto hpaeResampleNode = std::make_shared(nodeInfo, dstNodeInfo, ResamplerType::PRORESAMPLER); - hpaeResampleNode->GetSampleRate(); - hpaeResampleNode->GetFrameLen(); - hpaeResampleNode->GetChannelCount(); - hpaeResampleNode->GetBitWidth(); - hpaeResampleNode->Reset(); -} + CHECK_AND_RETURN_LOG(inRate != 0, "divisor cannot be 0"); -void HpaeResampleNodeSignalProcessFuzzTest01() -{ - HpaeNodeInfo nodeInfo; - HpaeNodeInfo dstNodeInfo; - GetTestNodeInfo(nodeInfo); - GetTestDtsNodeInfo(dstNodeInfo); - auto hpaeResampleNode = std::make_shared(nodeInfo, dstNodeInfo); - std::vector inputs; - hpaeResampleNode->SignalProcess(inputs); -} - -void HpaeResampleNodeSignalProcessFuzzTest02() -{ - HpaeNodeInfo nodeInfo; - HpaeNodeInfo dstNodeInfo; - GetTestNodeInfo(nodeInfo); - GetTestDtsNodeInfo(dstNodeInfo); - auto hpaeResampleNode = std::make_shared(nodeInfo, dstNodeInfo); - std::vector inputs; - PcmBufferInfo pcmBufferInfo(STEREO, TEST_FRAMELEN1, SAMPLE_RATE_48000); - HpaePcmBuffer hpaePcmBuffer(pcmBufferInfo); - inputs.emplace_back(&hpaePcmBuffer); - hpaeResampleNode->SignalProcess(inputs); + uint32_t inFrameLen = 0; + if (inRate % CUSTOME_RATE_MULTIPLE == 0) { + inFrameLen = FRAME_LEN_20MS * inRate / MS_PER_SECOND; + } else if (inRate == SAMPLE_RATE_11025) { + inFrameLen = FRAME_LEN_40MS * inRate / MS_PER_SECOND; + } else { + inFrameLen = FRAME_LEN_100MS * inRate / MS_PER_SECOND; + } + uint32_t outFrameLen = inFrameLen / inRate * outRate; + + for (uint32_t channels: TEST_CHANNELS) { + ProResampler resampler(inRate, outRate, channels, QUALITY_ONE); + vector in(inFrameLen, 0.0f); + vector out(outFrameLen, 0.0f); + for (uint32_t i = 0; i < inFrameLen; i++) { + in[i] = GetData(); + } + for (uint32_t i = 0; i < PROCESS_LOOP_COUNT; i++) { + resampler.Process(in.data(), inFrameLen, out.data(), outFrameLen); + } + } } -void HpaeResampleNodeConnectAndDisconnectWithInfoFuzzTest() +// special testcase for ensuring 11025 coverage +void ResampleProcessTest11025() { - HpaeNodeInfo srcNodeInfo; - HpaeNodeInfo dstNodeInfo; - GetTestNodeInfo(srcNodeInfo); - GetTestDtsNodeInfo(dstNodeInfo); - auto hpaeResampleNode = std::make_shared(srcNodeInfo, dstNodeInfo); - auto hpaeInputNode = std::make_shared(srcNodeInfo); - hpaeResampleNode->ConnectWithInfo(hpaeInputNode, srcNodeInfo); - hpaeResampleNode->DisConnectWithInfo(hpaeInputNode, srcNodeInfo); + uint32_t inRate = SAMPLE_RATE_11025; + uint32_t outRate = GetData(); + + uint32_t inFrameLen = FRAME_LEN_40MS * inRate / MS_PER_SECOND; + uint32_t outFrameLen = inFrameLen / inRate * outRate; + + for (uint32_t channels: TEST_CHANNELS) { + ProResampler resampler(inRate, outRate, channels, QUALITY_ONE); + vector in(inFrameLen, 0.0f); + vector out(outFrameLen, 0.0f); + for (uint32_t i = 0; i < inFrameLen; i++) { + in[i] = GetData(); + } + for (uint32_t i = 0; i < PROCESS_LOOP_COUNT; i++) { + resampler.Process(in.data(), inFrameLen, out.data(), outFrameLen); + } + } } -typedef void (*TestFuncs[4])(); - -TestFuncs g_testFuncs = { - HpaeResampleNodeResetFuzzTest, - HpaeResampleNodeSignalProcessFuzzTest01, - HpaeResampleNodeSignalProcessFuzzTest02, - HpaeResampleNodeConnectAndDisconnectWithInfoFuzzTest, +typedef void (*TestFuncs)(); +TestFuncs g_testFuncs[] = { + ResampleBaseTest, + ResampleProcessTest, + ResampleProcessTest11025, }; bool FuzzTest(const uint8_t* rawData, size_t size) @@ -168,7 +165,6 @@ bool FuzzTest(const uint8_t* rawData, size_t size) return true; } - } // namespace AudioStandard } // namesapce OHOS diff --git a/test/fuzztest/hpaeproresamplerprocess_fuzzer/project.xml b/test/fuzztest/hpaeproresampler_fuzzer/project.xml similarity index 100% rename from test/fuzztest/hpaeproresamplerprocess_fuzzer/project.xml rename to test/fuzztest/hpaeproresampler_fuzzer/project.xml diff --git a/test/fuzztest/hpaeproresamplerprocess_fuzzer/hpae_proresampler_process_fuzzer.cpp b/test/fuzztest/hpaeproresamplerprocess_fuzzer/hpae_proresampler_process_fuzzer.cpp deleted file mode 100644 index 96a6f5ecb59f4191a24f9083135536d7b6d56bdd..0000000000000000000000000000000000000000 --- a/test/fuzztest/hpaeproresamplerprocess_fuzzer/hpae_proresampler_process_fuzzer.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * 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. - */ - -#include -#include -#include -#include -#include "audio_utils.h" -#include -#include -#include "audio_proresampler_process.h" -#include "audio_engine_log.h" -#include "audio_proresampler.h" -#include "audio_stream_info.h" -namespace OHOS { -namespace AudioStandard { -using namespace std; -using namespace HPAE; -static const uint8_t* RAW_DATA = nullptr; -static size_t g_dataSize = 0; -static size_t g_pos; -const size_t THRESHOLD = 10; -const size_t NUM_TWO = 2; -const size_t NUM_SEVEN = 7; -const static std::vector TEST_CHANNELS = {MONO, STEREO, CHANNEL_6}; - -const static std::map TEST_SAMPLE_RATE_COMBINATION = { // {input, output} combination - {SAMPLE_RATE_24000, SAMPLE_RATE_48000}, - {SAMPLE_RATE_16000, SAMPLE_RATE_48000}, - {SAMPLE_RATE_44100, SAMPLE_RATE_192000}, - {SAMPLE_RATE_48000, SAMPLE_RATE_24000}, - {SAMPLE_RATE_48000, SAMPLE_RATE_16000}, - {SAMPLE_RATE_192000, SAMPLE_RATE_44100}, -}; - -constexpr uint32_t INVALID_QUALITY = -1; -constexpr uint32_t QUALITY_ONE = 1; -constexpr uint32_t FRAME_LEN_20MS = 20; -constexpr uint32_t FRAME_LEN_40MS = 40; -constexpr uint32_t MS_PER_SECOND = 1000; -template -T GetData() -{ - T object {}; - size_t objectSize = sizeof(object); - if (RAW_DATA == nullptr || objectSize > g_dataSize - g_pos) { - return object; - } - errno_t ret = memcpy_s(&object, objectSize, RAW_DATA + g_pos, objectSize); - if (ret != EOK) { - return {}; - } - g_pos += objectSize; - return object; -} - -template -uint32_t GetArrLength(T& arr) -{ - if (arr == nullptr) { - AUDIO_INFO_LOG("%{public}s: The array length is equal to 0", __func__); - return 0; - } - return sizeof(arr) / sizeof(arr[0]); -} - -void SingleStagePolyphaseResamplerSetRate1() -{ - SingleStagePolyphaseResamplerState state; - uint32_t decimateFactor = 0; - uint32_t interpolateFactor = 0; - SingleStagePolyphaseResamplerSetRate(&state, decimateFactor, interpolateFactor); -} - -void SingleStagePolyphaseResamplerSetRate2() -{ - SingleStagePolyphaseResamplerState state; - uint32_t decimateFactor = 0; - uint32_t interpolateFactor = 2; - SingleStagePolyphaseResamplerSetRate(&state, decimateFactor, interpolateFactor); -} - -void SingleStagePolyphaseResamplerSetRate3() -{ - SingleStagePolyphaseResamplerState state; - uint32_t decimateFactor = 2; - uint32_t interpolateFactor = 0; - SingleStagePolyphaseResamplerSetRate(&state, decimateFactor, interpolateFactor); -} - -void SingleStagePolyphaseResamplerSetRate4() -{ - SingleStagePolyphaseResamplerState state; - uint32_t decimateFactor = GetData(); - uint32_t interpolateFactor = GetData(); - SingleStagePolyphaseResamplerSetRate(&state, decimateFactor, interpolateFactor); -} - -void InitTest() -{ - // test invalid input - int32_t err = RESAMPLER_ERR_SUCCESS; - SingleStagePolyphaseResamplerInit(STEREO, SAMPLE_RATE_24000, SAMPLE_RATE_48000, INVALID_QUALITY, &err); - - // test valid input - SingleStagePolyphaseResamplerInit(STEREO, SAMPLE_RATE_24000, SAMPLE_RATE_48000, QUALITY_ONE, &err); - - // test 11025 input - ProResampler resampler1(SAMPLE_RATE_11025, SAMPLE_RATE_48000, STEREO, QUALITY_ONE); - - // test other input - ProResampler resampler2(SAMPLE_RATE_48000, SAMPLE_RATE_44100, STEREO, QUALITY_ONE); -} - -void ProcessTest() -{ - for (uint32_t channels: TEST_CHANNELS) { - for (auto pair: TEST_SAMPLE_RATE_COMBINATION) { - uint32_t inRate = pair.first; - uint32_t outRate = pair.second; - uint32_t inFrameLen = inRate * FRAME_LEN_20MS / MS_PER_SECOND; - uint32_t outFrameLen = outRate * FRAME_LEN_20MS / MS_PER_SECOND; - ProResampler resampler(inRate, outRate, channels, QUALITY_ONE); - std::vector in(inFrameLen * channels); - std::vector out(outFrameLen * channels); - resampler.Process(in.data(), inFrameLen, out.data(), outFrameLen); - } - } - - ProResampler resampler(SAMPLE_RATE_11025, SAMPLE_RATE_48000, STEREO, QUALITY_ONE); - uint32_t inFrameLen = SAMPLE_RATE_11025 * FRAME_LEN_40MS / MS_PER_SECOND; - uint32_t outFrameLen = SAMPLE_RATE_48000 * FRAME_LEN_20MS / MS_PER_SECOND; - std::vector in(inFrameLen * STEREO); - std::vector out(outFrameLen * STEREO); - resampler.Process(in.data(), inFrameLen, out.data(), outFrameLen); - - inFrameLen = 0; - resampler.Process(in.data(), inFrameLen, out.data(), outFrameLen); - resampler.Process(in.data(), inFrameLen, out.data(), outFrameLen); -} - -void UpdateRatesTest1() -{ - ProResampler resampler(SAMPLE_RATE_48000, SAMPLE_RATE_96000, STEREO, QUALITY_ONE); - resampler.UpdateRates(SAMPLE_RATE_11025, SAMPLE_RATE_48000); -} - -void UpdateRatesTest2() -{ - ProResampler resampler(SAMPLE_RATE_48000, SAMPLE_RATE_96000, STEREO, QUALITY_ONE); - resampler.UpdateRates(NUM_TWO, SAMPLE_RATE_48000); -} - -void UpdateChannel() -{ - ProResampler resampler(SAMPLE_RATE_48000, SAMPLE_RATE_96000, STEREO, QUALITY_ONE); - - resampler.UpdateChannels(CHANNEL_6); -} - -void ErrCodeToString() -{ - ProResampler resampler(SAMPLE_RATE_48000, SAMPLE_RATE_96000, STEREO, QUALITY_ONE); - resampler.ErrCodeToString(RESAMPLER_ERR_SUCCESS); - resampler.ErrCodeToString(RESAMPLER_ERR_ALLOC_FAILED); - resampler.ErrCodeToString(RESAMPLER_ERR_OVERFLOW); - resampler.ErrCodeToString(NUM_SEVEN); - resampler.ErrCodeToString(RESAMPLER_ERR_INVALID_ARG); - resampler.ErrCodeToString(GetData()); -} - -typedef void (*TestFuncs)(); -TestFuncs g_testFuncs[] = { - SingleStagePolyphaseResamplerSetRate1, - SingleStagePolyphaseResamplerSetRate2, - SingleStagePolyphaseResamplerSetRate3, - SingleStagePolyphaseResamplerSetRate4, - InitTest, - ProcessTest, - UpdateRatesTest1, - UpdateRatesTest2, - UpdateChannel, - ErrCodeToString, -}; - -bool FuzzTest(const uint8_t* rawData, size_t size) -{ - if (rawData == nullptr) { - return false; - } - - // initialize data - RAW_DATA = rawData; - g_dataSize = size; - g_pos = 0; - - uint32_t code = GetData(); - uint32_t len = GetArrLength(g_testFuncs); - if (len > 0) { - g_testFuncs[code % len](); - } else { - AUDIO_INFO_LOG("%{public}s: The len length is equal to 0", __func__); - } - - return true; -} -} // namespace AudioStandard -} // namesapce OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - if (size < OHOS::AudioStandard::THRESHOLD) { - return 0; - } - - OHOS::AudioStandard::FuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/hpaeresamplenode_fuzzer/BUILD.gn b/test/fuzztest/hpaeresamplenode_fuzzer/BUILD.gn deleted file mode 100644 index 3b3a4d04a9d85064542c8170b7de19ba487fea84..0000000000000000000000000000000000000000 --- a/test/fuzztest/hpaeresamplenode_fuzzer/BUILD.gn +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# 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. - -import("//build/config/features.gni") -import("//build/test.gni") -import("../../../accessibility.gni") -import("../../../config.gni") - -ohos_fuzztest("HpaeResampleNodeFuzzTest") { - module_out_path = "audio_framework/audio_framework_engine" - fuzz_config_file = "../hpaeresamplenode_fuzzer" - - include_dirs = [ - "../../../services/audio_policy/server/include/service", - "../../../services/audio_policy/server/include", - "../../../frameworks/native/audioutils/include", - "../../../services/audio_service/common/include/limiter/", - "../../../services/audio_engine/manager/include", - "../../../services/audio_engine/node/include", - "../../../services/audio_service/server/include", - "../../../interfaces/inner_api/native/audiocommon/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-fno-access-control", - "-DENABLE_HIDUMP_DFX", - "-DENABLE_HOOK_PCM", - ] - - configs = [ - "../../../services/audio_policy:audio_policy_public_config", - "../../../services/audio_engine:audio_engine_node_config", - ] - - sources = [ "hpaeresamplenode_fuzzer.cpp" ] - - deps = [ - "../../../frameworks/native/audioutils:audio_utils", - "../../../frameworks/native/bluetoothclient:audio_bluetooth_client", - "../../../services/audio_policy:audio_policy_service_static", - "../../../services/audio_service:audio_common", - "../../../frameworks/native/audioclock:audio_clock", - "../../../services/audio_engine:audio_engine_manager", - "../../../services/audio_engine:audio_engine_node", - "../../../services/audio_engine:audio_engine_utils", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:extension_manager", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken_shared", - "access_token:libprivacy_sdk", - "access_token:libtokenid_sdk", - "access_token:libtokensetproc_shared", - "background_task_mgr:bgtaskmgr_innerkits", - "bounds_checking_function:libsec_shared", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "data_share:datashare_common", - "data_share:datashare_consumer", - "eventhandler:libeventhandler", - "hdf_core:libhdf_ipc_adapter", - "hdf_core:libhdi", - "hdf_core:libpub_utils", - "hicollie:libhicollie", - "hilog:libhilog", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", - "init:libbegetutil", - "ipc:ipc_single", - "kv_store:distributeddata_inner", - "media_foundation:media_monitor_client", - "media_foundation:media_monitor_common", - "os_account:os_account_innerkits", - "power_manager:powermgr_client", - "relational_store:native_appdatafwk", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "bluetooth:btframework" - ] - if (sonic_enable == true) { - external_deps += [ "pulseaudio:sonic" ] - } - if (accessibility_enable == true) { - external_deps += [ - "accessibility:accessibility_common", - "accessibility:accessibilityconfig", - ] - } - - defines = [] - if (use_libfuzzer || use_clang_coverage) { - defines += [ "TEST_COVERAGE" ] - } - if (audio_framework_feature_dtmf_tone) { - defines += [ "FEATURE_DTMF_TONE" ] - } - if (audio_framework_feature_input) { - defines += [ "FEATURE_MULTIMODALINPUT_INPUT" ] - } -} - -group("fuzztest") { - testonly = true - deps = [ ":HpaeResampleNodeFuzzTest" ] -} diff --git a/test/fuzztest/hpaeresamplenode_fuzzer/project.xml b/test/fuzztest/hpaeresamplenode_fuzzer/project.xml deleted file mode 100644 index 0aef325cd0f79cb8cfb98a9313436e3633dad54c..0000000000000000000000000000000000000000 --- a/test/fuzztest/hpaeresamplenode_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - -