diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index ef27e2523666235435c2a070b125e08232b085fa..59fce37acf26219cfb78602003e1f23f94f12673 100644 --- a/audiohandler/BUILD.gn +++ b/audiohandler/BUILD.gn @@ -45,9 +45,10 @@ ohos_shared_library("distributed_audio_handler") { external_deps = [ "audio_framework:audio_capturer", "audio_framework:audio_client", + "audio_framework:audio_renderer", "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", - "player_framework:media_client", + "hilog:libhilog", ] defines = [ diff --git a/audiohandler/include/daudio_handler.h b/audiohandler/include/daudio_handler.h index 4b79ea821c5cd754d1c5e3be46fc3cbaa3059bbd..e93aab70dcbdc97b9479141be76e7301b8ce4439 100644 --- a/audiohandler/include/daudio_handler.h +++ b/audiohandler/include/daudio_handler.h @@ -23,17 +23,10 @@ #include "audio_param.h" #include "audio_capturer.h" #include "audio_info.h" +#include "audio_renderer.h" namespace OHOS { namespace DistributedHardware { -typedef struct { - std::vector sampleRates; - std::vector channels; - std::vector formats; - int32_t channelMaxVal; - int32_t channelMinVal; -} CoderInfo; - typedef struct { std::vector sampleRates; std::vector channels; @@ -55,16 +48,11 @@ public: private: DAudioHandler(); ~DAudioHandler(); - int32_t QueryCodecInfo(); int32_t QueryAudioInfo(); - void GetSupportAudioInfo(AudioInfo &audioInfos, CoderInfo &encoderInfos, CoderInfo &decoderInfos); private: - CoderInfo encoderInfos_; - CoderInfo decoderInfos_; - AudioInfo audioInfos_; - CoderInfo spkInfos_; - CoderInfo micInfos_; + AudioInfo spkInfos_; + AudioInfo micInfos_; std::shared_ptr listener_ = nullptr; }; diff --git a/audiohandler/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index b12f08c71d46cda55acb885322736d9800266fc5..3bf416bfaa8ee1dc474c702bab5576496237fef2 100644 --- a/audiohandler/src/daudio_handler.cpp +++ b/audiohandler/src/daudio_handler.cpp @@ -18,7 +18,6 @@ #include #include "audio_system_manager.h" -#include "avcodec_list.h" #include "nlohmann/json.hpp" #include "string_ex.h" @@ -39,14 +38,6 @@ IMPLEMENT_SINGLE_INSTANCE(DAudioHandler); DAudioHandler::DAudioHandler() { - encoderInfos_.channelMaxVal = 0; - encoderInfos_.channelMinVal = 0; - decoderInfos_.channelMaxVal = 0; - decoderInfos_.channelMinVal = 0; - spkInfos_.channelMaxVal = 0; - spkInfos_.channelMinVal = 0; - micInfos_.channelMaxVal = 0; - micInfos_.channelMinVal = 0; DHLOGD("Distributed audio handler constructed."); } @@ -58,14 +49,7 @@ DAudioHandler::~DAudioHandler() int32_t DAudioHandler::Initialize() { DHLOGI("Distributed audio handler initialize."); - int32_t ret = QueryCodecInfo(); - if (ret != DH_SUCCESS) { - DHLOGE("Failed to query the codec information."); - return ret; - } - ret = QueryAudioInfo(); - GetSupportAudioInfo(audioInfos_, encoderInfos_, decoderInfos_); - return ret; + return QueryAudioInfo(); } std::vector DAudioHandler::Query() @@ -99,16 +83,6 @@ std::vector DAudioHandler::Query() infoJson["INTERRUPT_GROUP_ID"] = dev->interruptGroupId_; infoJson["VOLUME_GROUP_ID"] = dev->volumeGroupId_; - std::string audioEncoders = - HiStreamerQueryTool::GetInstance().QueryHiStreamerPluginInfo(HISTREAM_PLUGIN_TYPE::AUDIO_ENCODER); - DHLOGI("DAudio QueryAudioEncoderAbility info: %s", audioEncoders.c_str()); - infoJson[KEY_HISTREAMER_AUDIO_ENCODER] = audioEncoders; - - std::string audioDecoders = - HiStreamerQueryTool::GetInstance().QueryHiStreamerPluginInfo(HISTREAM_PLUGIN_TYPE::AUDIO_DECODER); - DHLOGI("DAudio QueryAudioDecoderAbility info: %s", audioDecoders.c_str()); - infoJson[KEY_HISTREAMER_AUDIO_DECODER] = audioDecoders; - dhItem.dhId = std::to_string(dhId); dhItem.attrs = infoJson.dump(); dhItemVec.push_back(dhItem); @@ -134,102 +108,19 @@ std::vector DAudioHandler::ablityForDump() Query(); return ablityForDumpVec_; } -int32_t DAudioHandler::QueryCodecInfo() -{ - DHLOGD("Query codec information."); - auto avCodecList = Media::AVCodecListFactory::CreateAVCodecList(); - CHECK_NULL_RETURN(avCodecList, ERR_DH_AUDIO_NULLPTR); - - bool queryFlag = false; - for (auto codec : avCodecList->GetAudioEncoderCaps()) { - if (codec == nullptr || codec->GetCodecInfo() == nullptr || codec->GetCodecInfo()->GetName() != AVENC_AAC) { - continue; - } - encoderInfos_.sampleRates = codec->GetSupportedSampleRates(); - encoderInfos_.formats = codec->GetSupportedFormats(); - encoderInfos_.channelMaxVal = codec->GetSupportedChannel().maxVal; - encoderInfos_.channelMinVal = codec->GetSupportedChannel().minVal; - queryFlag = true; - } - - for (auto codec : avCodecList->GetAudioDecoderCaps()) { - if (codec == nullptr || codec->GetCodecInfo() == nullptr || codec->GetCodecInfo()->GetName() != AVENC_AAC) { - continue; - } - decoderInfos_.sampleRates = codec->GetSupportedSampleRates(); - decoderInfos_.formats = codec->GetSupportedFormats(); - decoderInfos_.channelMaxVal = codec->GetSupportedChannel().maxVal; - decoderInfos_.channelMinVal = codec->GetSupportedChannel().minVal; - queryFlag = true; - } - - if (!queryFlag) { - DHLOGE("Failed to query the codec information."); - return ERR_DH_AUDIO_FAILED; - } - return DH_SUCCESS; -} int32_t DAudioHandler::QueryAudioInfo() { DHLOGD("Start to query codec information."); - audioInfos_.sampleRates = OHOS::AudioStandard::AudioCapturer::GetSupportedSamplingRates(); - audioInfos_.formats = OHOS::AudioStandard::AudioCapturer::GetSupportedFormats(); - audioInfos_.channels = OHOS::AudioStandard::AudioCapturer::GetSupportedChannels(); + micInfos_.sampleRates = OHOS::AudioStandard::AudioCapturer::GetSupportedSamplingRates(); + micInfos_.formats = OHOS::AudioStandard::AudioCapturer::GetSupportedFormats(); + micInfos_.channels = OHOS::AudioStandard::AudioCapturer::GetSupportedChannels(); + spkInfos_.sampleRates = OHOS::AudioStandard::AudioRenderer::GetSupportedSamplingRates(); + spkInfos_.formats = OHOS::AudioStandard::AudioRenderer::GetSupportedFormats(); + spkInfos_.channels = OHOS::AudioStandard::AudioRenderer::GetSupportedChannels(); return DH_SUCCESS; } -void DAudioHandler::GetSupportAudioInfo(AudioInfo &audioInfos, CoderInfo &encoderInfos, - CoderInfo &decoderInfos) -{ - for (auto iter = audioInfos.sampleRates.begin(); iter != audioInfos.sampleRates.end(); iter++) { - if (std::find(encoderInfos.sampleRates.begin(), encoderInfos.sampleRates.end(), *iter) != - encoderInfos.sampleRates.end()) { - micInfos_.sampleRates.push_back(*iter); - } - if (std::find(decoderInfos.sampleRates.begin(), decoderInfos.sampleRates.end(), *iter) != - decoderInfos.sampleRates.end()) { - spkInfos_.sampleRates.push_back(*iter); - } - } - - for (auto iter = audioInfos.formats.begin(); iter != audioInfos.formats.end(); iter++) { - if (std::find(encoderInfos.formats.begin(), encoderInfos.formats.end(), *iter) != encoderInfos.formats.end()) { - micInfos_.formats.push_back(*iter); - } - if (std::find(decoderInfos.formats.begin(), decoderInfos.formats.end(), *iter) != decoderInfos.formats.end()) { - spkInfos_.formats.push_back(*iter); - } - } - - for (auto iter = audioInfos.channels.begin(); iter != audioInfos.channels.end(); iter++) { - if (*iter <= encoderInfos.channelMaxVal && *iter >= encoderInfos.channelMinVal) { - micInfos_.channels.push_back(*iter); - } - if (*iter <= decoderInfos.channelMaxVal && *iter >= decoderInfos.channelMinVal) { - spkInfos_.channels.push_back(*iter); - } - } - if (micInfos_.sampleRates.empty()) { - micInfos_.sampleRates.push_back(SAMPLE_RATE_DEFAULT); - } - if (spkInfos_.sampleRates.empty()) { - spkInfos_.sampleRates.push_back(SAMPLE_RATE_DEFAULT); - } - if (micInfos_.channels.empty()) { - micInfos_.channels.push_back(CHANNEL_COUNT_DEFAULT); - } - if (spkInfos_.channels.empty()) { - spkInfos_.channels.push_back(CHANNEL_COUNT_DEFAULT); - } - if (micInfos_.formats.empty()) { - micInfos_.formats.push_back(SAMPLE_FORMAT_DEFAULT); - } - if (spkInfos_.formats.empty()) { - spkInfos_.formats.push_back(SAMPLE_FORMAT_DEFAULT); - } -} - std::map DAudioHandler::QueryExtraInfo() { DHLOGD("Query extra information"); diff --git a/audiohandler/test/unittest/BUILD.gn b/audiohandler/test/unittest/BUILD.gn index c250a8da46b1540d7c6a355ff8dceec18d391563..0b355be7a09d585f44a66d1c776822a79c7ae167 100644 --- a/audiohandler/test/unittest/BUILD.gn +++ b/audiohandler/test/unittest/BUILD.gn @@ -50,7 +50,11 @@ ohos_unittest("AudioHandlerTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ "c_utils:utils" ] + external_deps = [ + "audio_framework:audio_renderer", + "c_utils:utils", + "hilog:libhilog", + ] } group("audio_handler_test") { diff --git a/audiohandler/test/unittest/include/daudio_handler_test.h b/audiohandler/test/unittest/include/daudio_handler_test.h index fb2e016988e6c2a9305d09696f36330441bd217d..db960170262f96ea7148a651c8a9b98730317914 100644 --- a/audiohandler/test/unittest/include/daudio_handler_test.h +++ b/audiohandler/test/unittest/include/daudio_handler_test.h @@ -30,7 +30,7 @@ class DAudioHandlerTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); - void SetUp(); + void SetUp(void); void TearDown(void); }; } // namespace DistributedHardware diff --git a/audiohandler/test/unittest/src/daudio_handler_test.cpp b/audiohandler/test/unittest/src/daudio_handler_test.cpp index f9a7162f81857e70d66aaa9cb85d0a0f41c5894b..53fa86d2b0e6a6a3c3cc5b0b436b831d4d27acbd 100644 --- a/audiohandler/test/unittest/src/daudio_handler_test.cpp +++ b/audiohandler/test/unittest/src/daudio_handler_test.cpp @@ -26,7 +26,7 @@ void DAudioHandlerTest::SetUpTestCase(void) {} void DAudioHandlerTest::TearDownTestCase(void) {} -void DAudioHandlerTest::SetUp() {} +void DAudioHandlerTest::SetUp(void) {} void DAudioHandlerTest::TearDown(void) {} @@ -42,18 +42,6 @@ HWTEST_F(DAudioHandlerTest, Initialize_001, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, actual); } -/** - * @tc.name: QueryCodecInfo_001 - * @tc.desc: Verify the QueryCodecInfo function. - * @tc.type: FUNC - * @tc.require: AR000H0E5F - */ -HWTEST_F(DAudioHandlerTest, QueryCodecInfo_001, TestSize.Level1) -{ - int32_t actual = DAudioHandler::GetInstance().QueryCodecInfo(); - EXPECT_EQ(DH_SUCCESS, actual); -} - /** * @tc.name: QueryAudioInfo_001 * @tc.desc: Verify the QueryAudioInfo function. diff --git a/bundle.json b/bundle.json index 4d74f225d5471605c9b9cd7bbd91ae4ac2d714ea..942a75ba5576df7a8f944f4f8118c4c5c715c191 100755 --- a/bundle.json +++ b/bundle.json @@ -14,9 +14,7 @@ "component": { "name": "distributed_audio", "subsystem": "distributedhardware", - "syscap": [ - "SystemCapability.DistributedHardware.DistributedAudio" - ], + "syscap": [], "features": [], "adapted_system_type": [ "standard" diff --git a/common/dfx_utils/src/daudio_hidumper.cpp b/common/dfx_utils/src/daudio_hidumper.cpp index d33ddbe83a415369a47cbb438c083c9a63375f61..e920cc79fa8ed8bbfed9cb68977e23ae5da30745 100644 --- a/common/dfx_utils/src/daudio_hidumper.cpp +++ b/common/dfx_utils/src/daudio_hidumper.cpp @@ -57,7 +57,7 @@ DaudioHidumper::~DaudioHidumper() bool DaudioHidumper::Dump(const std::vector &args, std::string &result) { - DHLOGI("Distributed audio hidumper dump args.size():%d.", args.size()); + DHLOGI("Distributed audio hidumper dump args.size():%lu.", args.size()); result.clear(); int32_t argsSize = static_cast(args.size()); for (int32_t i = 0; i < argsSize; i++) { diff --git a/common/dfx_utils/test/unittest/BUILD.gn b/common/dfx_utils/test/unittest/BUILD.gn index 38013170a1c44604b68b59bae7ef214a32f3ce31..358418166448fc1c258fd0504e9a7659ec427735 100644 --- a/common/dfx_utils/test/unittest/BUILD.gn +++ b/common/dfx_utils/test/unittest/BUILD.gn @@ -72,6 +72,7 @@ ohos_unittest("DAudioDfxTest") { external_deps = [ "audio_framework:audio_capturer", + "audio_framework:audio_renderer", "c_utils:utils", "dsoftbus:softbus_client", "hisysevent:libhisysevent", diff --git a/common/include/daudio_log.h b/common/include/daudio_log.h index 3d597a233fbfecff3e3ef978a93e6f0bfa66b7af..dd832b58663869173eb3b3a0c56455fa74863bf9 100644 --- a/common/include/daudio_log.h +++ b/common/include/daudio_log.h @@ -16,6 +16,11 @@ #ifndef OHOS_DAUDIO_LOG_H #define OHOS_DAUDIO_LOG_H +#include "hilog/log.h" + +#undef LOG_TAG +#define LOG_TAG "DAUDIO" + namespace OHOS { namespace DistributedHardware { typedef enum { @@ -27,6 +32,19 @@ typedef enum { void DHLog(DHLogLevel logLevel, const char *fmt, ...); +#ifdef HI_LOG_ENABLE +#define DHLOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, \ + "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) + +#define DHLOGI(fmt, ...) HILOG_INFO(LOG_CORE, \ + "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) + +#define DHLOGW(fmt, ...) HILOG_WARN(LOG_CORE, \ + "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) + +#define DHLOGE(fmt, ...) HILOG_ERROR(LOG_CORE, \ + "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) +#else #define DHLOGD(fmt, ...) DHLog(DH_LOG_DEBUG, \ (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) @@ -38,8 +56,8 @@ void DHLog(DHLogLevel logLevel, const char *fmt, ...); #define DHLOGE(fmt, ...) DHLog(DH_LOG_ERROR, \ (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) - -#define CHECK_NULL_VOID(ptr) \ +#endif +#define CHECK_NULL_VOID(ptr) \ do { \ if ((ptr) == nullptr) { \ DHLOGE("Address pointer is null"); \ @@ -47,13 +65,36 @@ void DHLog(DHLogLevel logLevel, const char *fmt, ...); } \ } while (0) -#define CHECK_NULL_RETURN(ptr, ret) \ +#define CHECK_NULL_RETURN(ptr, ret) \ do { \ if ((ptr) == nullptr) { \ DHLOGE("Address pointer is null"); \ return (ret); \ } \ } while (0) + +#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ + do { \ + if ((cond)) { \ + DHLOGE(fmt, ##__VA_ARGS__); \ + return (ret); \ + } \ + } while (0) + +#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ + do { \ + if ((cond)) { \ + DHLOGE(fmt, ##__VA_ARGS__); \ + return; \ + } \ + } while (0) + +#define CHECK_AND_LOG(cond, fmt, ...) \ + do { \ + if ((cond)) { \ + DHLOGE(fmt, ##__VA_ARGS__); \ + } \ + } while (0) } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DAUDIO_LOG_H diff --git a/common/src/daudio_latency_test.cpp b/common/src/daudio_latency_test.cpp index 1fd78732e18e31a0098131afddb5983e0d22149c..2dc3548007194b1480bf7e70f53e243a41e5184b 100644 --- a/common/src/daudio_latency_test.cpp +++ b/common/src/daudio_latency_test.cpp @@ -44,7 +44,7 @@ int32_t DAudioLatencyTest::AddPlayTime(const int64_t playBeepTime) DHLOGE("Catch play high frame, but not in %d ms.", TWO_BEEP_TIME_INTERVAL); return ERR_DH_AUDIO_FAILED; } - DHLOGI("Catch play high frame, playTime: %lld.", playBeepTime); + DHLOGI("Catch play high frame, playTime: %ld.", playBeepTime); playBeepTime_.push_back(playBeepTime); lastPlayTime_ = GetNowTimeUs(); return DH_SUCCESS; @@ -61,7 +61,7 @@ int32_t DAudioLatencyTest::AddRecordTime(const int64_t recordBeepTime) DHLOGE("Catch record high frame, but not in %d ms.", TWO_BEEP_TIME_INTERVAL); return ERR_DH_AUDIO_FAILED; } - DHLOGI("Catch record high frame, recordTime: %lld.", recordBeepTime); + DHLOGI("Catch record high frame, recordTime: %ld.", recordBeepTime); captureBeepTime_.push_back(recordBeepTime); lastRecordTime_ = GetNowTimeUs(); return DH_SUCCESS; @@ -98,14 +98,14 @@ int32_t DAudioLatencyTest::ComputeLatency() DHLOGD("Compute latency time."); int32_t playSize = static_cast(playBeepTime_.size()); if (playSize == 0 || playBeepTime_.size() != captureBeepTime_.size()) { - DHLOGE("Record num is not equal <%d, %d>", playSize, captureBeepTime_.size()); + DHLOGE("Record num is not equal <%d, %lu>", playSize, captureBeepTime_.size()); return -1; } DHLOGI("Record %d times frame high.", playSize); int32_t sum = 0; for (int32_t i = 0; i < playSize; i++) { - DHLOGI("Send: %lld, Received: %lld", playBeepTime_[i], captureBeepTime_[i]); - DHLOGI("Time is: %d ms.", (captureBeepTime_[i] - playBeepTime_[i]) / US_PER_MS); + DHLOGI("Send: %ld, Received: %ld", playBeepTime_[i], captureBeepTime_[i]); + DHLOGI("Time is: %ld ms.", (captureBeepTime_[i] - playBeepTime_[i]) / US_PER_MS); sum += captureBeepTime_[i] - playBeepTime_[i]; } DHLOGI("Audio latency in average is: %d us.", sum / playSize); diff --git a/common/src/daudio_log.cpp b/common/src/daudio_log.cpp index d0ad61fe7924fc6d6312cba0e33a481c227f6c73..d3b5cf166a41d2283a670039fdc8e51442a35c96 100644 --- a/common/src/daudio_log.cpp +++ b/common/src/daudio_log.cpp @@ -18,36 +18,12 @@ #include "daudio_constants.h" #include "securec.h" -#ifdef HI_LOG_ENABLE -#include "hilog/log.h" -#else #include -#endif namespace OHOS { namespace DistributedHardware { static void DHLogOut(DHLogLevel logLevel, const char *logBuf) { -#ifdef HI_LOG_ENABLE - LogLevel hiLogLevel = LOG_INFO; - switch (logLevel) { - case DH_LOG_DEBUG: - hiLogLevel = LOG_DEBUG; - break; - case DH_LOG_INFO: - hiLogLevel = LOG_INFO; - break; - case DH_LOG_WARN: - hiLogLevel = LOG_WARN; - break; - case DH_LOG_ERROR: - hiLogLevel = LOG_ERROR; - break; - default: - break; - } - (void)HiLogPrint(LOG_CORE, hiLogLevel, LOG_DOMAIN, DAUDIO_LOG_TITLE_TAG.c_str(), "%{public}s", logBuf); -#else switch (logLevel) { case DH_LOG_DEBUG: printf("[D]%s\n", logBuf); @@ -64,7 +40,6 @@ static void DHLogOut(DHLogLevel logLevel, const char *logBuf) default: break; } -#endif } void DHLog(DHLogLevel logLevel, const char *fmt, ...) diff --git a/common/src/daudio_util.cpp b/common/src/daudio_util.cpp index 78f50ed52b4a19894b415bacfe537906a5297912..414f5a116398413bb1dcad218623cf63617d7c71 100644 --- a/common/src/daudio_util.cpp +++ b/common/src/daudio_util.cpp @@ -368,7 +368,7 @@ int32_t AbsoluteSleep(int64_t nanoTime) { int32_t ret = -1; if (nanoTime <= 0) { - DHLOGE("AbsoluteSleep invalid sleep time : %d ns", nanoTime); + DHLOGE("AbsoluteSleep invalid sleep time : %ld ns", nanoTime); return ret; } struct timespec time; @@ -403,7 +403,7 @@ int64_t UpdateTimeOffset(const int64_t frameIndex, const int64_t framePeriodNs, bool CheckIsNum(const std::string &jsonString) { if (jsonString.empty() || jsonString.size() > MAX_KEY_DH_ID_LEN) { - DHLOGE("Json string size %d, is zero or too long.", jsonString.size()); + DHLOGE("Json string size %lu, is zero or too long.", jsonString.size()); return false; } for (char const &c : jsonString) { @@ -418,7 +418,7 @@ bool CheckIsNum(const std::string &jsonString) bool CheckDevIdIsLegal(const std::string &devId) { if (devId.empty() || devId.size() > DAUDIO_MAX_DEVICE_ID_LEN) { - DHLOGE("DevId size %d, is zero or too long.", devId.size()); + DHLOGE("DevId size %lu, is zero or too long.", devId.size()); return false; } for (char const &c : devId) { diff --git a/common/test/unittest/BUILD.gn b/common/test/unittest/BUILD.gn index 1d9dfbdcfd9b822612a0bf06c60893ec25793b73..c33e4504382ecc55923c2dcc16bd9099eb9fb78a 100644 --- a/common/test/unittest/BUILD.gn +++ b/common/test/unittest/BUILD.gn @@ -23,6 +23,7 @@ config("module_private_config") { include_dirs = [ "${fwk_common_path}/utils/include", + "//third_party/cJSON", "//third_party/json/include", ] @@ -41,10 +42,14 @@ ohos_unittest("DaudioUtilsTest") { deps = [ "${services_path}/common:distributed_audio_utils", + "//third_party/cJSON:cjson", "//third_party/googletest:gtest_main", ] - external_deps = [ "c_utils:utils" ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] defines = [ "HI_LOG_ENABLE", diff --git a/common/test/unittest/src/daudio_utils_test.cpp b/common/test/unittest/src/daudio_utils_test.cpp index 881318415547323032d607ab9a8270f5dae898db..88207a95e6be4020dace5c8c9afeb133be094407 100644 --- a/common/test/unittest/src/daudio_utils_test.cpp +++ b/common/test/unittest/src/daudio_utils_test.cpp @@ -17,6 +17,7 @@ #include +#include "cJSON.h" #include "securec.h" #include "daudio_constants.h" @@ -135,11 +136,12 @@ HWTEST_F(DAudioUtilsTest, DAudioLatencyTest_003, TestSize.Level1) */ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_001, TestSize.Level1) { + string args = "DHLog test"; DHLOGD("DAudio TDD test DHLOGD print."); - DHLOGI("DAudio TDD test DHLOGI print."); + DHLOGI("DAudio TDD test DHLOGI print %s.", args.c_str()); DHLOGW("DAudio TDD test DHLOGW print."); - DHLOGE("DAudio TDD test DHLOGE print."); - DHLog(DHLogLevel::DH_LOG_ERROR, ""); + DHLOGE("DAudio TDD test DHLOGE print %d.", 1); + DHLog(DHLogLevel::DH_LOG_ERROR, "DHLog test"); int64_t tvSec; int64_t tvNSec; GetCurrentTime(tvSec, tvNSec); @@ -299,5 +301,24 @@ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_007, TestSize.Level1) tempDevIdStr = "Test1"; EXPECT_EQ(true, CheckDevIdIsLegal(tempDevIdStr)); } + +/** + * @tc.name: DAudioLogTest_008 + * @tc.desc: Verify the GetEventNameByType function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(DAudioUtilsTest, DAudioUtilTest_008, TestSize.Level1) +{ + int32_t eventType = 200; + GetEventNameByType(eventType); + cJSON * jsonObj = nullptr; + std::initializer_list keys = { "one", "two" }; + CJsonParamCheck(jsonObj, keys); + jsonObj = cJSON_CreateObject(); + cJSON_AddStringToObject(jsonObj, "one", "one"); + cJSON_AddNumberToObject(jsonObj, "two", 2); + CJsonParamCheck(jsonObj, keys); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 2a10e58d1ae4e1f6bf0d7017735f94574844d2fc..c390d39c32724698cb44b3282ad772eec7f20ef4 100755 --- a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn @@ -49,6 +49,7 @@ ohos_shared_library("distributed_audio_sink_sdk") { external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", diff --git a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback_stub.cpp b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback_stub.cpp index a0f6258c4d77f03efee1a072129bf067dece6a64..e794b043fd15ce2506893a95c268adc151a6cafb 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback_stub.cpp +++ b/interfaces/inner_kits/native_cpp/audio_sink/src/daudio_sink_ipc_callback_stub.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace DistributedHardware { -DAudioSinkIpcCallbackStub::DAudioSinkIpcCallbackStub() +DAudioSinkIpcCallbackStub::DAudioSinkIpcCallbackStub() : IRemoteStub(true) { memberFuncMap_[NOTIFY_RESOURCEINFO] = &DAudioSinkIpcCallbackStub::OnNotifyResourceInfoInner; } diff --git a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn index feacb89b654b5be163c7e8551eab5a4f6e40ed3f..006ccb732df5a3d7d86aae396c873c9a390237e4 100755 --- a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn @@ -49,6 +49,7 @@ ohos_shared_library("distributed_audio_source_sdk") { external_deps = [ "c_utils:utils", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", diff --git a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp index 68f950c24112227dedde3902399cc3b9afa04c59..35e183de57c9125e1346bea2206e04d0b25611db 100644 --- a/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp +++ b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace DistributedHardware { -DAudioIpcCallbackStub::DAudioIpcCallbackStub() +DAudioIpcCallbackStub::DAudioIpcCallbackStub() : IRemoteStub(true) { memberFuncMap_[NOTIFY_REGRESULT] = &DAudioIpcCallbackStub::OnNotifyRegResultInner; memberFuncMap_[NOTIFY_UNREGRESULT] = &DAudioIpcCallbackStub::OnNotifyUnregResultInner; diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 588e4a1a5b9d90073755bd0fc599b52929649499..50d014801b7eb8b70f8c13992281888aa74d12fc 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -35,8 +35,14 @@ group("fuzztest") { "onremotesourcesvrdied_fuzzer:fuzztest", "sinkhandlerfinishstartsa_fuzzer:fuzztest", "sinkhandlerinitsink_fuzzer:fuzztest", + "sinkhandlerpausedistributedhardware_fuzzer:fuzztest", + "sinkhandlerregisterprivacyresources_fuzzer:fuzztest", + "sinkhandlerresumedistributedhardware_fuzzer:fuzztest", + "sinkhandlerstopdistributedhardware_fuzzer:fuzztest", "sinkhandlersubscribelocalhardware_fuzzer:fuzztest", "sinkhandlerunsubscribelocalhardware_fuzzer:fuzztest", + "sinkipccallbackonnotifyresourceinfo_fuzzer:fuzztest", + "sinkipccallbackonremoterequest_fuzzer:fuzztest", "sinkonloadsystemabilityfail_fuzzer:fuzztest", "sinkonloadsystemabilitysuccess_fuzzer:fuzztest", "sinkproxydaudionotify_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d56fa2b9bc1405b164711cc4d63e1ace9e0f01d4 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,63 @@ +# Copyright (c) 2024 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerPauseDistributedHardwareFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerpausedistributedhardware" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkhandlerpausedistributedhardware_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + ] + + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] + + external_deps = [ "c_utils:utils" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerPauseDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerPauseDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4506ec0d0ade89fadff6843be3bf80ed730b6855 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 "sinkhandlerpausedistributedhardware_fuzzer.h" + +#include "daudio_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerPauseDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string networkId(reinterpret_cast(data), size); + + DAudioSinkHandler::GetInstance().PauseDistributedHardware(networkId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerPauseDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..62825e5591ad69df6d92468674a4be141768f513 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 SINKHANDLERPAUSEDISTRIBUTEDHARDWARE_FUZZER_H +#define SINKHANDLERPAUSEDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerpausedistributedhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7223f1432c8af67ccc1e3f3fa45220fde5ea641e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# Copyright (c) 2024 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerRegisterPrivacyResourcesFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerregisterprivacyresources" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkhandlerregisterprivacyresources_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${innerkits_path}/native_cpp/test/include", + "${fwk_services_path}/distributedhardwarefwkservice/include", + "${fwk_services_path}/distributedhardwarefwkservice/include/componentmanager", + ] + + deps = [ + "${fwk_services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerRegisterPrivacyResourcesFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerRegisterPrivacyResourcesFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0da44199142712884acf468859302d6ca71249ac --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 "sinkhandlerregisterprivacyresources_fuzzer.h" + +#include "daudio_sink_handler.h" +#include "mock_component_resourceinfo.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerRegisterPrivacyResourcesFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + std::shared_ptr listener = std::make_shared(); + DAudioSinkHandler::GetInstance().RegisterPrivacyResources(listener); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerRegisterPrivacyResourcesFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..24bebe338b4c8230b846edaae48c1cc992819685 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 SINKHANDLERREGISTERPRIVACYRESOURCE_FUZZER_H +#define SINKHANDLERREGISTERPRIVACYRESOURCE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerregisterprivacyresources_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..399a6eba58b7ba349fe8efe9d1aea3eef0fbc2ac --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,63 @@ +# Copyright (c) 2024 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerResumeDistributedHardwareFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerresumedistributedhardware" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkhandlerresumedistributedhardware_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + ] + + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] + + external_deps = [ "c_utils:utils" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerResumeDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerResumeDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b5ff478ac696e88f961947d546acf5e8876e5da7 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 "sinkhandlerresumedistributedhardware_fuzzer.h" + +#include "daudio_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerResumeDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string networkId(reinterpret_cast(data), size); + + DAudioSinkHandler::GetInstance().ResumeDistributedHardware(networkId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerResumeDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..aead1565b2b8cf2437983bd8f86508463568af88 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 SINKHANDLERRESUMEDISTRIBUTEDHARDWARE_FUZZER_H +#define SINKHANDLERRESUMEDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerresumedistributedhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..34194f275601fe93f9b56073671bf1388feeb1d1 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,63 @@ +# Copyright (c) 2024 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerStopDistributedHardwareFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerstopdistributedhardware" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkhandlerstopdistributedhardware_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + ] + + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] + + external_deps = [ "c_utils:utils" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerStopDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerStopDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..711d0432f5dac398c7d8edcd363f24aab1b3e792 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 "sinkhandlerstopdistributedhardware_fuzzer.h" + +#include "daudio_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerStopDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string networkId(reinterpret_cast(data), size); + + DAudioSinkHandler::GetInstance().StopDistributedHardware(networkId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerStopDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..22d522a2a7cb6e17fcb498f29c866ec9e552b410 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 SINKHANDLERSTOPDISTRIBUTEDHARDWARE_FUZZER_H +#define SINKHANDLERSTOPDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerstopdistributedhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2843357e531c36330baa451d152177d948285c34 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2024 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkIpcCallbackOnNotifyResourceInfoFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkipccallbackonnotifyresourceinfo" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkipccallbackonnotifyresourceinfo_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + ] + + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkIpcCallbackOnNotifyResourceInfoFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkIpcCallbackOnNotifyResourceInfoFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b28186d775e654be5c151b3871b2aefb22b5a2e5 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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 "sinkipccallbackonnotifyresourceinfo_fuzzer.h" + +#include "daudio_sink_ipc_callback.h" + +namespace OHOS { +namespace DistributedHardware { +const uint32_t DC_RESOURCE_VALUE = 2; +const uint32_t DC_RESOURCE_SIZE = 3; +const ResourceEventType resourceEventType[DC_RESOURCE_SIZE] { + ResourceEventType::EVENT_TYPE_QUERY_RESOURCE, + ResourceEventType::EVENT_TYPE_PULL_UP_PAGE, + ResourceEventType::EVENT_TYPE_CLOSE_PAGE +}; + +void SinkIpcCallbackOnNotifyResourceInfoFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + ResourceEventType type = resourceEventType[data[0] % DC_RESOURCE_SIZE]; + std::string subtype(reinterpret_cast(data), size); + std::string networkId(reinterpret_cast(data), size); + bool isSensitive = data[0] % DC_RESOURCE_VALUE; + bool isSameAccout = data[0] % DC_RESOURCE_VALUE; + std::shared_ptr callback = std::make_shared(); + + callback->OnNotifyResourceInfo(type, subtype, networkId, isSensitive, isSameAccout); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkIpcCallbackOnNotifyResourceInfoFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ee2f7003fa0a8185d2c5542524e074188469e689 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 SINKIPCCALLBACKONNOTIFYRESOURCEINFO_FUZZER_H +#define SINKIPCCALLBACKONNOTIFYRESOURCEINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkipccallbackonnotifyresourceinfo_fuzzer" + +#endif diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0002af03318e0c1e13023d29ef64571cbc4c2b81 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2024 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkIpcCallbackOnRemoteRequestFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkipccallbackonremoterequest" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkipccallbackonremoterequest_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + ] + + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkIpcCallbackOnRemoteRequestFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkIpcCallbackOnRemoteRequestFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 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/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..994223664f69b6743c9ac4a27b03634816257609 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 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 "sinkipccallbackonremoterequest_fuzzer.h" + +#include +#include + +#include "daudio_sink_ipc_callback.h" +#include "daudio_sink_ipc_callback_stub.h" +#include "iremote_object.h" +#include "message_option.h" +#include "message_parcel.h" + +namespace OHOS { +namespace DistributedHardware { +const uint32_t DC_RESOURCE_VALUE = 2; +const uint32_t DC_RESOURCE_SIZE = 3; +const ResourceEventType resourceEventType[DC_RESOURCE_SIZE] { + ResourceEventType::EVENT_TYPE_QUERY_RESOURCE, + ResourceEventType::EVENT_TYPE_PULL_UP_PAGE, + ResourceEventType::EVENT_TYPE_CLOSE_PAGE +}; + +void SinkIpcCallbackOnRemoteRequestFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + uint32_t code = 0; + int32_t resType = static_cast(resourceEventType[data[0] % DC_RESOURCE_SIZE]); + std::string subtype(reinterpret_cast(data), size); + std::string networkId(reinterpret_cast(data), size); + bool isSensitive = data[0] % DC_RESOURCE_VALUE; + bool isSameAccout = data[0] % DC_RESOURCE_VALUE; + pdata.WriteInt32(resType); + pdata.WriteString(subtype); + pdata.WriteString(networkId); + pdata.ReadBool(isSensitive); + pdata.ReadBool(isSameAccout); + std::shared_ptr callback = std::make_shared(); + + callback->OnRemoteRequest(code, pdata, reply, option); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkIpcCallbackOnRemoteRequestFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a00a5c2aeb8144cc32b11f14f64fa78efd7a600f --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 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 SINKIPCCALLBACKONREMEOTREQUEST_FUZZER_H +#define SINKIPCCALLBACKONREMEOTREQUEST_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkipccallbackonremoterequest_fuzzer" + +#endif diff --git a/interfaces/inner_kits/native_cpp/test/include/mock_component_resourceinfo.h b/interfaces/inner_kits/native_cpp/test/include/mock_component_resourceinfo.h new file mode 100644 index 0000000000000000000000000000000000000000..95fcd06c229544f35404e39c4f95fe76c7b3b661 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/include/mock_component_resourceinfo.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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 OHOS_DAUDIO_MOCK_COMPONENT_RESOURCE_INFO_H +#define OHOS_DAUDIO_MOCK_COMPONENT_RESOURCE_INFO_H + +#include "daudio_errorcode.h" +#include "idistributed_hardware_sink.h" + +namespace OHOS { +namespace DistributedHardware { +class MockComponentResourceInfo : public std::enable_shared_from_this, + public PrivacyResourcesListener { +public: + MockComponentResourceInfo() + { + } + + virtual ~MockComponentResourceInfo() + { + } + + int32_t OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) override + { + return DH_SUCCESS; + } +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn index 7e1afd538129e703692fd111de6bfc056c21311d..fb2ed0d6cb182772c0086bc61a3f58e21d5536a0 100755 --- a/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("AudioSinkTest") { external_deps = [ "c_utils:utils", + "hilog:libhilog", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp index 27df7a7e8528ebeb9764d0ac44d184eeccb03bf0..9d6d3dfe874f68e08ce283cb1bd79885c8c6a0ab 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp +++ b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp @@ -82,14 +82,23 @@ HWTEST_F(DAudioIpcCallbackTest, OnNotifyRegResult_002, TestSize.Level1) HWTEST_F(DAudioIpcCallbackTest, OnNotifyRegResult_003, TestSize.Level1) { size_t DAUDIO_MAX_DEVICE_ID_LEN = 101; + size_t DAUDIO_LEGAL_DEVICE_ID_LEN = 10; std::string devId ; devId.resize(DAUDIO_MAX_DEVICE_ID_LEN); - const std::string dhId = "dhId"; - const std::string reqId = "reqId"; + std::string dhId = "dhId"; + std::string reqId = "reqId"; int32_t status = 0; const std::string data = "data"; int32_t ret = dAudioIpcCallback_->OnNotifyRegResult(devId, dhId, reqId, status, data); EXPECT_EQ(ERR_DH_AUDIO_SA_DEVID_ILLEGAL, ret); + devId.resize(DAUDIO_LEGAL_DEVICE_ID_LEN); + dhId.resize(DAUDIO_MAX_DEVICE_ID_LEN); + ret = dAudioIpcCallback_->OnNotifyRegResult(devId, dhId, reqId, status, data); + EXPECT_EQ(ERR_DH_AUDIO_SA_DEVID_ILLEGAL, ret); + dhId.resize(DAUDIO_LEGAL_DEVICE_ID_LEN); + reqId.resize(DAUDIO_MAX_DEVICE_ID_LEN); + ret = dAudioIpcCallback_->OnNotifyRegResult(devId, dhId, reqId, status, data); + EXPECT_EQ(ERR_DH_AUDIO_SA_DEVID_ILLEGAL, ret); } /** diff --git a/services/audioclient/micclient/src/dmic_client.cpp b/services/audioclient/micclient/src/dmic_client.cpp index 394a389b5cc9d7893d6dc8d9f08473239ca9bfe3..4d0976844b1f10c8b0956b61fb5d7a98d8db0853 100644 --- a/services/audioclient/micclient/src/dmic_client.cpp +++ b/services/audioclient/micclient/src/dmic_client.cpp @@ -153,7 +153,7 @@ int32_t DMicClient::TransSetUp() int32_t DMicClient::SetUp(const AudioParam ¶m) { - DHLOGI("Set up mic client, param: {sampleRate: %d, bitFormat: %d," + + DHLOGI("Set up mic client, param: {sampleRate: %d, bitFormat: %d," "channelMask: %d, sourceType: %d, capturerFlags: %d, frameSize: %d}.", param.comParam.sampleRate, param.comParam.bitFormat, param.comParam.channelMask, param.captureOpts.sourceType, param.captureOpts.capturerFlags, param.comParam.frameSize); @@ -252,7 +252,7 @@ void DMicClient::AudioFwkCaptureData() } int64_t endTime = GetNowTimeUs(); if (IsOutDurationRange(startTime, endTime, lastCaptureStartTime_)) { - DHLOGE("This time capture spend: %lld us, The interval of capture this time and the last time: %lld us", + DHLOGE("This time capture spend: %ld us, The interval of capture this time and the last time: %ld us", endTime - startTime, startTime - lastCaptureStartTime_); } lastCaptureStartTime_ = startTime; @@ -276,7 +276,7 @@ void DMicClient::AudioFwkCaptureData() } int64_t endTransTime = GetNowTimeUs(); if (IsOutDurationRange(startTransTime, endTransTime, lastTransStartTime_)) { - DHLOGE("This time send data spend: %lld us, The interval of send data this time and the last time: %lld us", + DHLOGE("This time send data spend: %ld us, The interval of send data this time and the last time: %ld us", endTransTime - startTransTime, startTransTime - lastTransStartTime_); } lastTransStartTime_ = startTransTime; @@ -312,7 +312,7 @@ void DMicClient::OnReadData(size_t length) std::shared_ptr audioData = std::make_shared(audioParam_.comParam.frameSize); if (audioData->Capacity() != bufDesc.bufLength) { - DHLOGE("Audio data length is not equal to buflength. datalength: %d, bufLength: %d", + DHLOGE("Audio data length is not equal to buflength. datalength: %lu, bufLength: %lu", audioData->Capacity(), bufDesc.bufLength); } if (memcpy_s(audioData->Data(), audioData->Capacity(), bufDesc.buffer, bufDesc.bufLength) != EOK) { diff --git a/services/audioclient/spkclient/src/dspeaker_client.cpp b/services/audioclient/spkclient/src/dspeaker_client.cpp index 5a800462adb957621948ce4f981f387f968a8778..d646abd3aa0c62d9f71894b8171d817baef09f1c 100644 --- a/services/audioclient/spkclient/src/dspeaker_client.cpp +++ b/services/audioclient/spkclient/src/dspeaker_client.cpp @@ -74,7 +74,7 @@ int32_t DSpeakerClient::InitReceiverEngine(IAVEngineProvider *providerPtr) int32_t DSpeakerClient::CreateAudioRenderer(const AudioParam ¶m) { - DHLOGD("Set up spk client: {sampleRate: %d, bitFormat: %d, channelMask: %d," + + DHLOGD("Set up spk client: {sampleRate: %d, bitFormat: %d, channelMask: %d," "frameSize: %d, contentType: %d, renderFlags: %d, streamUsage: %d}.", param.comParam.sampleRate, param.comParam.bitFormat, param.comParam.channelMask, param.comParam.frameSize, param.renderOpts.contentType, param.renderOpts.renderFlags, param.renderOpts.streamUsage); @@ -127,11 +127,11 @@ void DSpeakerClient::OnWriteData(size_t length) } else { audioData = dataQueue_.front(); dataQueue_.pop(); - DHLOGI("Pop spk data, dataQueue size: %d.", dataQueue_.size()); + DHLOGI("Pop spk data, dataQueue size: %lu.", dataQueue_.size()); } } if (audioData->Capacity() != bufDesc.bufLength) { - DHLOGE("Audio data length is not equal to buflength. datalength: %d, bufLength: %d", + DHLOGE("Audio data length is not equal to buflength. datalength: %lu, bufLength: %lu", audioData->Capacity(), bufDesc.bufLength); } if (memcpy_s(bufDesc.buffer, bufDesc.bufLength, audioData->Data(), audioData->Capacity()) != EOK) { @@ -283,7 +283,7 @@ void DSpeakerClient::PlayThreadRunning() } audioData = dataQueue_.front(); dataQueue_.pop(); - DHLOGD("Pop spk data, dataqueue size: %d.", dataQueue_.size()); + DHLOGD("Pop spk data, dataqueue size: %lu.", dataQueue_.size()); } #ifdef DUMP_DSPEAKERCLIENT_FILE if (DaudioSinkHidumper::GetInstance().QueryDumpDataFlag()) { @@ -294,7 +294,7 @@ void DSpeakerClient::PlayThreadRunning() while (writeOffSet < static_cast(audioData->Capacity())) { int32_t writeLen = audioRenderer_->Write(audioData->Data() + writeOffSet, static_cast(audioData->Capacity()) - writeOffSet); - DHLOGD("Write audio render, write len: %d, raw len: %d, offset: %d", writeLen, audioData->Capacity(), + DHLOGD("Write audio render, write len: %d, raw len: %zu, offset: %d", writeLen, audioData->Capacity(), writeOffSet); if (writeLen < 0) { break; @@ -303,7 +303,7 @@ void DSpeakerClient::PlayThreadRunning() } int64_t endTime = GetNowTimeUs(); if (IsOutDurationRange(startTime, endTime, lastPlayStartTime_)) { - DHLOGE("This time play spend: %lld us, The interval of play this time and the last time: %lld us", + DHLOGE("This time play spend: %ld us, The interval of play this time and the last time: %ld us", endTime - startTime, startTime - lastPlayStartTime_); } lastPlayStartTime_ = startTime; @@ -349,10 +349,10 @@ int32_t DSpeakerClient::OnDecodeTransDataDone(const std::shared_ptr & } dataQueue_.push(audioData); dataQueueCond_.notify_all(); - DHLOGI("Push new spk data, buf len: %d.", dataQueue_.size()); + DHLOGI("Push new spk data, buf len: %lu.", dataQueue_.size()); int64_t endTime = GetNowTimeUs(); if (IsOutDurationRange(startTime, endTime, lastReceiveStartTime_)) { - DHLOGE("This time receivce data spend: %lld us, Receivce data this time and the last time: %lld us", + DHLOGE("This time receivce data spend: %ld us, Receivce data this time and the last time: %ld us", endTime - startTime, startTime - lastReceiveStartTime_); } lastReceiveStartTime_ = startTime; diff --git a/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp b/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp index cfbd8d54c5a18482a4db16369ad001317de4c7dc..efd37f35f69977c32952162c167aa920e87ed9cc 100644 --- a/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp +++ b/services/audioclient/test/unittest/spkclient/src/dspeaker_client_test.cpp @@ -140,6 +140,8 @@ HWTEST_F(DSpeakerClientTest, StopRender001, TestSize.Level1) EXPECT_NE(DH_SUCCESS, speakerClient_->StopRender()); std::string args = "args"; AudioEvent event; + speakerClient_->isRenderReady_ = true; + speakerClient_->FlushJitterQueue(); speakerClient_->PlayStatusChange(args); speakerClient_->SetAudioParameters(event); speakerClient_->SetMute(event); diff --git a/services/audiohdiproxy/src/daudio_manager_callback.cpp b/services/audiohdiproxy/src/daudio_manager_callback.cpp index f87c4807ee9fd326f8a7f919e7b6a22588a179b3..592eb965ed280d02590220bb48bb26c9712fb2cd 100644 --- a/services/audiohdiproxy/src/daudio_manager_callback.cpp +++ b/services/audiohdiproxy/src/daudio_manager_callback.cpp @@ -69,7 +69,7 @@ int32_t DAudioManagerCallback::GetAudioParamHDF(const AudioParameter& param, Aud paramHDF.bitFormat = AudioSampleFormat::SAMPLE_S24LE; break; default: - DHLOGE("Format [%zu] does not support conversion.", param.format); + DHLOGE("Format [%u] does not support conversion.", param.format); return HDF_FAILURE; } switch (static_cast(param.streamUsage)) { @@ -86,7 +86,7 @@ int32_t DAudioManagerCallback::GetAudioParamHDF(const AudioParameter& param, Aud paramHDF.streamUsage = StreamUsage::STREAM_USAGE_MEDIA; break; default: - DHLOGE("Stream usage [%zu] does not support conversion.", param.streamUsage); + DHLOGE("Stream usage [%u] does not support conversion.", param.streamUsage); return HDF_FAILURE; } paramHDF.frameSize = param.frameSize; @@ -94,8 +94,8 @@ int32_t DAudioManagerCallback::GetAudioParamHDF(const AudioParameter& param, Aud paramHDF.ext = param.ext; paramHDF.renderFlags = static_cast(param.renderFlags); paramHDF.capturerFlags = static_cast(param.capturerFlags); - DHLOGI("HDF Param: sample rate %d, channel %d, bit format %d, stream usage %d, frame size %zu, " + - "period %zu, renderFlags %d, capturerFlags %d, ext {%s}.", paramHDF.sampleRate, paramHDF.channelMask, + DHLOGI("HDF Param: sample rate %d, channel %d, bit format %d, stream usage %d, frame size %u," + "period %u, renderFlags %d, capturerFlags %d, ext {%s}.", paramHDF.sampleRate, paramHDF.channelMask, paramHDF.bitFormat, paramHDF.streamUsage, paramHDF.frameSize, paramHDF.period, paramHDF.renderFlags, paramHDF.capturerFlags, paramHDF.ext.c_str()); return HDF_SUCCESS; diff --git a/services/audiomanager/managersink/src/daudio_sink_dev.cpp b/services/audiomanager/managersink/src/daudio_sink_dev.cpp index 5096b4bbccaabec041e03d6baf69d398c2cecc21..5a62185885ee6b9aeac7b8321b4705c1ff5f1d5f 100644 --- a/services/audiomanager/managersink/src/daudio_sink_dev.cpp +++ b/services/audiomanager/managersink/src/daudio_sink_dev.cpp @@ -127,10 +127,8 @@ int32_t DAudioSinkDev::TaskOpenDSpeaker(const std::string &args) return ERR_DH_AUDIO_FAILED; } int32_t dhId = ConvertString2Int(std::string(jParam[KEY_DH_ID])); - if (dhId == -1) { - DHLOGE("Parse dhId error."); - return ERR_DH_AUDIO_NULLPTR; - } + CHECK_AND_RETURN_RET_LOG(dhId == -1, ERR_DH_AUDIO_NULLPTR, + "%s", "Parse dhId error."); std::shared_ptr speakerClient = nullptr; { std::lock_guard devLck(spkClientMutex_); @@ -138,17 +136,12 @@ int32_t DAudioSinkDev::TaskOpenDSpeaker(const std::string &args) } AudioParam audioParam; int32_t ret = from_json(jParam[KEY_AUDIO_PARAM], audioParam); - if (ret != DH_SUCCESS) { - DHLOGE("Get audio param from json failed, error code %d.", ret); - return ret; - } - + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, + "Get audio param from json failed, error code %d.", ret); CHECK_NULL_RETURN(speakerClient, ERR_DH_AUDIO_NULLPTR); ret = speakerClient->SetUp(audioParam); - if (ret != DH_SUCCESS) { - DHLOGE("Setup speaker failed, ret: %d.", ret); - return ret; - } + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, + "Setup speaker failed, ret: %d.", ret); isSpkInUse_.store(true); return ret; } @@ -216,10 +209,8 @@ int32_t DAudioSinkDev::TaskStartRender(const std::string &args) CHECK_NULL_RETURN(speakerClient, ERR_DH_AUDIO_NULLPTR); int32_t ret = speakerClient->StartRender(); - if (ret != DH_SUCCESS) { - DHLOGE("Start render failed. ret: %d.", ret); - return ret; - } + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, + "Start render failed. ret: %d.", ret); DHLOGI("Start render success."); return DH_SUCCESS; } @@ -236,33 +227,24 @@ int32_t DAudioSinkDev::TaskOpenDMic(const std::string &args) } AudioParam audioParam; int32_t ret = from_json(jParam[KEY_AUDIO_PARAM], audioParam); - if (ret != DH_SUCCESS) { - DHLOGE("Get audio param from json failed, error code %d.", ret); - return ret; - } + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, + "Get audio param from json failed, error code %d.", ret); micDhId_ = std::string(jParam[KEY_DH_ID]); int32_t dhId = ConvertString2Int(std::string(jParam[KEY_DH_ID])); - if (dhId == -1) { - DHLOGE("Parse dhId error."); - return ERR_DH_AUDIO_NULLPTR; - } + CHECK_AND_RETURN_RET_LOG(dhId == -1, ERR_DH_AUDIO_NULLPTR, + "%s", "Parse dhId error."); std::shared_ptr micClient = nullptr; { std::lock_guard devLck(micClientMutex_); micClient = micClientMap_[dhId]; } CHECK_NULL_RETURN(micClient, ERR_DH_AUDIO_NULLPTR); - ret = micClient->SetUp(audioParam); - if (ret != DH_SUCCESS) { - DHLOGE("Set up mic failed, ret: %d.", ret); - return ERR_DH_AUDIO_FAILED; - } + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ERR_DH_AUDIO_FAILED, + "Set up mic failed, ret: %d.", ret); ret = micClient->StartCapture(); - if (ret != DH_SUCCESS) { - DHLOGE("Start capture failed, ret: %d.", ret); - return ERR_DH_AUDIO_FAILED; - } + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ERR_DH_AUDIO_FAILED, + "Start capture failed, ret: %d.", ret); PullUpPage(); isMicInUse_.store(true); return ret; @@ -281,13 +263,9 @@ int32_t DAudioSinkDev::TaskCloseDMic(const std::string &args) CHECK_NULL_RETURN(micClient, DH_SUCCESS); int32_t ret = micClient->StopCapture(); - if (ret != DH_SUCCESS) { - DHLOGE("Stop mic client failed, ret: %d.", ret); - } + CHECK_AND_LOG(ret != DH_SUCCESS, "Stop mic client failed, ret: %d.", ret); ret = micClient->Release(); - if (ret != DH_SUCCESS) { - DHLOGE("Release mic client failed, ret: %d.", ret); - } + CHECK_AND_LOG(ret != DH_SUCCESS, "Release mic client failed, ret: %d.", ret); micClientMap_.erase(dhId); if (isPageStatus_.load()) { bool isSensitive = false; @@ -335,10 +313,8 @@ int32_t DAudioSinkDev::TaskSetVolume(const std::string &args) AudioEvent event(AudioEventType::VOLUME_SET, args); int32_t ret = speakerClient->SetAudioParameters(event); - if (ret != DH_SUCCESS) { - DHLOGE("Volume set failed, ret: %d.", ret); - return ret; - } + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, + "Volume set failed, ret: %d.", ret); DHLOGD("Set audio volume success."); return DH_SUCCESS; } @@ -360,10 +336,8 @@ int32_t DAudioSinkDev::TaskSetMute(const std::string &args) AudioEvent event(AudioEventType::VOLUME_MUTE_SET, args); int32_t ret = speakerClient->SetMute(event); - if (ret != DH_SUCCESS) { - DHLOGE("Set mute failed, ret: %d.", ret); - return ret; - } + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ret, + "Set mute failed, ret: %d.", ret); DHLOGD("Set mute success."); return DH_SUCCESS; } @@ -426,10 +400,8 @@ int32_t DAudioSinkDev::SendAudioEventToRemote(const AudioEvent &event) int32_t ret = speakerClient->SendMessage(static_cast(event.type), event.content, devId_); - if (ret != DH_SUCCESS) { - DHLOGE("Task send message to remote failed."); - return ERR_DH_AUDIO_NULLPTR; - } + CHECK_AND_RETURN_RET_LOG(ret != DH_SUCCESS, ERR_DH_AUDIO_NULLPTR, + "%s", "Task send message to remote failed."); return DH_SUCCESS; } @@ -607,10 +579,7 @@ void DAudioSinkDev::SinkEventHandler::NotifyOpenSpeaker(const AppExecFwk::InnerE int32_t ret = sinkDevObj->TaskOpenDSpeaker(eventParam); sinkDevObj->NotifySourceDev(NOTIFY_OPEN_SPEAKER_RESULT, jParam[KEY_DH_ID], ret); DHLOGI("Open speaker device task end, notify source ret %d.", ret); - if (ret != DH_SUCCESS) { - DHLOGE("Open speaker failed."); - return; - } + CHECK_AND_RETURN_LOG(ret != DH_SUCCESS, "%s", "Open speaker failed."); } void DAudioSinkDev::SinkEventHandler::NotifyCloseSpeaker(const AppExecFwk::InnerEvent::Pointer &event) @@ -622,10 +591,8 @@ void DAudioSinkDev::SinkEventHandler::NotifyCloseSpeaker(const AppExecFwk::Inner } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - if (sinkDevObj->TaskCloseDSpeaker(eventParam) != DH_SUCCESS) { - DHLOGE("Open speaker failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskCloseDSpeaker(eventParam) != DH_SUCCESS, + "%s", "close speaker failed."); } void DAudioSinkDev::SinkEventHandler::NotifySpeakerOpened(const AppExecFwk::InnerEvent::Pointer &event) @@ -638,15 +605,10 @@ void DAudioSinkDev::SinkEventHandler::NotifySpeakerOpened(const AppExecFwk::Inne } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskStartRender(eventParam) != DH_SUCCESS) { - DHLOGE("Speaker client start failed."); - return; - } - if (sinkDevObj->TaskVolumeChange(eventParam) != DH_SUCCESS) { - DHLOGE("Notify pimary volume to source device failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskStartRender(eventParam) != DH_SUCCESS, + "%s", "Speaker client start failed."); + CHECK_AND_RETURN_LOG(sinkDevObj->TaskVolumeChange(eventParam) != DH_SUCCESS, + "%s", "Notify pimary volume to source device failed."); } void DAudioSinkDev::SinkEventHandler::NotifySpeakerClosed(const AppExecFwk::InnerEvent::Pointer &event) @@ -658,11 +620,8 @@ void DAudioSinkDev::SinkEventHandler::NotifySpeakerClosed(const AppExecFwk::Inne } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskCloseDSpeaker(eventParam) != DH_SUCCESS) { - DHLOGE("Close speaker failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskCloseDSpeaker(eventParam) != DH_SUCCESS, + "%s", "Close speaker failed."); } void DAudioSinkDev::SinkEventHandler::NotifyOpenMic(const AppExecFwk::InnerEvent::Pointer &event) @@ -683,10 +642,7 @@ void DAudioSinkDev::SinkEventHandler::NotifyOpenMic(const AppExecFwk::InnerEvent int32_t ret = sinkDevObj->TaskOpenDMic(eventParam); sinkDevObj->NotifySourceDev(NOTIFY_OPEN_MIC_RESULT, jParam[KEY_DH_ID], ret); DHLOGI("Open mic device task end, notify source ret %d.", ret); - if (ret != DH_SUCCESS) { - DHLOGE("Open mic failed."); - return; - } + CHECK_AND_RETURN_LOG(ret != DH_SUCCESS, "%s", "Open mic failed."); } void DAudioSinkDev::SinkEventHandler::NotifyCloseMic(const AppExecFwk::InnerEvent::Pointer &event) @@ -698,11 +654,8 @@ void DAudioSinkDev::SinkEventHandler::NotifyCloseMic(const AppExecFwk::InnerEven } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskCloseDMic(eventParam) != DH_SUCCESS) { - DHLOGE("Close mic failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskCloseDMic(eventParam) != DH_SUCCESS, + "%s", "Close mic failed."); } void DAudioSinkDev::SinkEventHandler::NotifyMicOpened(const AppExecFwk::InnerEvent::Pointer &event) @@ -720,11 +673,8 @@ void DAudioSinkDev::SinkEventHandler::NotifyMicClosed(const AppExecFwk::InnerEve } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskCloseDMic(eventParam) != DH_SUCCESS) { - DHLOGE("Close mic failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskCloseDMic(eventParam) != DH_SUCCESS, + "%s", "Close mic failed."); } void DAudioSinkDev::SinkEventHandler::NotifySetVolume(const AppExecFwk::InnerEvent::Pointer &event) @@ -736,11 +686,8 @@ void DAudioSinkDev::SinkEventHandler::NotifySetVolume(const AppExecFwk::InnerEve } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskSetVolume(eventParam) != DH_SUCCESS) { - DHLOGE("Set volume failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskSetVolume(eventParam) != DH_SUCCESS, + "%s", "Set volume failed."); } void DAudioSinkDev::SinkEventHandler::NotifyVolumeChange(const AppExecFwk::InnerEvent::Pointer &event) @@ -752,11 +699,8 @@ void DAudioSinkDev::SinkEventHandler::NotifyVolumeChange(const AppExecFwk::Inner } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskVolumeChange(eventParam) != DH_SUCCESS) { - DHLOGE("Notify volume change status to source device failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskVolumeChange(eventParam) != DH_SUCCESS, + "%s", "Notify volume change status to source device failed."); } void DAudioSinkDev::SinkEventHandler::NotifySetParam(const AppExecFwk::InnerEvent::Pointer &event) @@ -768,11 +712,8 @@ void DAudioSinkDev::SinkEventHandler::NotifySetParam(const AppExecFwk::InnerEven } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskSetParameter(eventParam) != DH_SUCCESS) { - DHLOGE("Set parameters failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskSetParameter(eventParam) != DH_SUCCESS, + "%s", "Set parameters failed."); } void DAudioSinkDev::SinkEventHandler::NotifySetMute(const AppExecFwk::InnerEvent::Pointer &event) @@ -784,11 +725,8 @@ void DAudioSinkDev::SinkEventHandler::NotifySetMute(const AppExecFwk::InnerEvent } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskSetMute(eventParam) != DH_SUCCESS) { - DHLOGE("Set mute failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskSetMute(eventParam) != DH_SUCCESS, + "%s", "Set mute failed."); } void DAudioSinkDev::SinkEventHandler::NotifyFocusChange(const AppExecFwk::InnerEvent::Pointer &event) @@ -800,11 +738,8 @@ void DAudioSinkDev::SinkEventHandler::NotifyFocusChange(const AppExecFwk::InnerE } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskFocusChange(eventParam) != DH_SUCCESS) { - DHLOGE("Handle focus change event failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskFocusChange(eventParam) != DH_SUCCESS, + "%s", "Handle focus change event failed."); } void DAudioSinkDev::SinkEventHandler::NotifyRenderStateChange(const AppExecFwk::InnerEvent::Pointer &event) @@ -816,11 +751,8 @@ void DAudioSinkDev::SinkEventHandler::NotifyRenderStateChange(const AppExecFwk:: } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskRenderStateChange(eventParam) != DH_SUCCESS) { - DHLOGE("Handle render state change failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskRenderStateChange(eventParam) != DH_SUCCESS, + "%s", "Handle render state change failed."); } void DAudioSinkDev::SinkEventHandler::NotifyPlayStatusChange(const AppExecFwk::InnerEvent::Pointer &event) @@ -832,11 +764,8 @@ void DAudioSinkDev::SinkEventHandler::NotifyPlayStatusChange(const AppExecFwk::I } auto sinkDevObj = sinkDev_.lock(); CHECK_NULL_VOID(sinkDevObj); - - if (sinkDevObj->TaskPlayStatusChange(eventParam) != DH_SUCCESS) { - DHLOGE("Handle play status change event failed."); - return; - } + CHECK_AND_RETURN_LOG(sinkDevObj->TaskPlayStatusChange(eventParam) != DH_SUCCESS, + "%s", "Handle play status change event failed."); } int32_t DAudioSinkDev::SinkEventHandler::GetEventParam(const AppExecFwk::InnerEvent::Pointer &event, @@ -861,9 +790,7 @@ int32_t DAudioSinkDev::PauseDistributedHardware(const std::string &networkId) CHECK_NULL_RETURN(micClient, ERR_DH_AUDIO_NULLPTR); int32_t ret = micClient->PauseCapture(); - if (ret != DH_SUCCESS) { - DHLOGE("Pause mic client failed, ret: %d.", ret); - } + CHECK_AND_LOG(ret != DH_SUCCESS, "Pause mic client failed, ret: %d.", ret); return ret; } @@ -879,9 +806,7 @@ int32_t DAudioSinkDev::ResumeDistributedHardware(const std::string &networkId) CHECK_NULL_RETURN(micClient, ERR_DH_AUDIO_NULLPTR); int32_t ret = micClient->ResumeCapture(); - if (ret != DH_SUCCESS) { - DHLOGE("Resume mic client failed, ret: %d.", ret); - } + CHECK_AND_LOG(ret != DH_SUCCESS, "Resume mic client failed, ret: %d.", ret); return ret; } diff --git a/services/audiomanager/managersink/src/daudio_sink_manager.cpp b/services/audiomanager/managersink/src/daudio_sink_manager.cpp index c05403b35a161fa158787940b5f1f260e44f8897..5d172c50f6cbad9df8041ee1c2bb847678530480 100644 --- a/services/audiomanager/managersink/src/daudio_sink_manager.cpp +++ b/services/audiomanager/managersink/src/daudio_sink_manager.cpp @@ -65,15 +65,10 @@ int32_t DAudioSinkManager::Init(const sptr &sinkCallback DHLOGI("Init audio sink manager."); initCallback_ = std::make_shared(); ipcSinkCallback_ = sinkCallback; - if (GetLocalDeviceNetworkId(localNetworkId_) != DH_SUCCESS) { - DHLOGE("Get local network id failed."); - return ERR_DH_AUDIO_FAILED; - } - - if (LoadAVReceiverEngineProvider() != DH_SUCCESS) { - DHLOGE("Load av receiver engine failed."); - return ERR_DH_AUDIO_FAILED; - } + CHECK_AND_RETURN_RET_LOG(GetLocalDeviceNetworkId(localNetworkId_) != DH_SUCCESS, + ERR_DH_AUDIO_FAILED, "%s", "Get local network id failed."); + CHECK_AND_RETURN_RET_LOG(LoadAVReceiverEngineProvider() != DH_SUCCESS, + ERR_DH_AUDIO_FAILED, "%s", "Load av receiver engine failed."); CHECK_NULL_RETURN(rcvProviderPtr_, ERR_DH_AUDIO_FAILED); providerListener_ = std::make_shared(); if (rcvProviderPtr_->RegisterProviderCallback(providerListener_) != DH_SUCCESS) { @@ -91,6 +86,8 @@ int32_t DAudioSinkManager::Init(const sptr &sinkCallback DHLOGE("Register av sender engine callback failed."); return ERR_DH_AUDIO_FAILED; } + CHECK_AND_RETURN_RET_LOG(sendProviderPtr_->RegisterProviderCallback(providerListener_) != DH_SUCCESS, + ERR_DH_AUDIO_FAILED, "%s", "Register av sender engine callback failed."); DHLOGI("Load av sender engine success."); return DH_SUCCESS; } @@ -238,10 +235,8 @@ void DAudioSinkManager::NotifyEvent(const std::string &devId, const int32_t even AudioEvent audioEvent(eventType, eventContent); std::lock_guard lock(devMapMutex_); DHLOGI("Notify event, devId: %s.", GetAnonyString(devId).c_str()); - if (audioDevMap_.find(devId) == audioDevMap_.end()) { - DHLOGE("Notify event error, dev not exist."); - return; - } + CHECK_AND_RETURN_LOG(audioDevMap_.find(devId) == audioDevMap_.end(), + "%s", "Notify event error, dev not exist."); CHECK_NULL_VOID(audioDevMap_[devId]); audioDevMap_[devId]->NotifyEvent(audioEvent); } diff --git a/services/audiomanager/managersource/src/dmic_dev.cpp b/services/audiomanager/managersource/src/dmic_dev.cpp index 537aafadf0ead552471a0039bbb58835490ad1b1..d31050386db1e92d4efff9ae6186e04dbcdef88b 100644 --- a/services/audiomanager/managersource/src/dmic_dev.cpp +++ b/services/audiomanager/managersource/src/dmic_dev.cpp @@ -56,7 +56,7 @@ void DMicDev::OnEngineTransMessage(const std::shared_ptr &messag void DMicDev::OnEngineTransDataAvailable(const std::shared_ptr &audioData) { - DHLOGI("On Engine Data available"); + DHLOGD("On Engine Data available"); OnDecodeTransDataDone(audioData); } @@ -305,7 +305,7 @@ int32_t DMicDev::ReadStreamData(const std::string &devId, const int32_t dhId, st #endif int64_t endTime = GetNowTimeUs(); if (IsOutDurationRange(startTime, endTime, lastReadStartTime_)) { - DHLOGE("This time read data spend: %lld us, The interval of read data this time and the last time: %lld us", + DHLOGE("This time read data spend: %ld us, The interval of read data this time and the last time: %ld us", endTime - startTime, startTime - lastReadStartTime_); } lastReadStartTime_ = startTime; @@ -369,7 +369,7 @@ void DMicDev::EnqueueThread() while (ashmem_ != nullptr && isEnqueueRunning_.load()) { int64_t timeOffset = UpdateTimeOffset(frameIndex_, LOW_LATENCY_INTERVAL_NS, startTime_); - DHLOGD("Write frameIndex: %lld, timeOffset: %lld.", frameIndex_, timeOffset); + DHLOGD("Write frameIndex: %ld, timeOffset: %ld.", frameIndex_, timeOffset); std::shared_ptr audioData = nullptr; { std::lock_guard lock(dataQueueMtx_); @@ -489,11 +489,11 @@ int32_t DMicDev::OnDecodeTransDataDone(const std::shared_ptr &audioDa dataQueSize_ = param_.captureOpts.capturerFlags == MMAP_MODE ? dataQueSize_ : DATA_QUEUE_EXT_SIZE; } while (dataQueue_.size() > dataQueSize_) { - DHLOGD("Data queue overflow. buf current size: %d", dataQueue_.size()); + DHLOGD("Data queue overflow. buf current size: %lu", dataQueue_.size()); dataQueue_.pop(); } dataQueue_.push(audioData); - DHLOGD("Push new mic data, buf len: %d", dataQueue_.size()); + DHLOGD("Push new mic data, buf len: %lu", dataQueue_.size()); return DH_SUCCESS; } } // DistributedHardware diff --git a/services/audiomanager/managersource/src/dspeaker_dev.cpp b/services/audiomanager/managersource/src/dspeaker_dev.cpp index 9a98296173145761ffdaa8aa2079aced5f58afdb..8d2484759e4fea77e104f45e8a1164eb61358319 100644 --- a/services/audiomanager/managersource/src/dspeaker_dev.cpp +++ b/services/audiomanager/managersource/src/dspeaker_dev.cpp @@ -292,7 +292,7 @@ int32_t DSpeakerDev::WriteStreamData(const std::string &devId, const int32_t dhI } int64_t endTime = GetNowTimeUs(); if (IsOutDurationRange(startTime, endTime, lastwriteStartTime_)) { - DHLOGE("This time write data spend: %lld us, The interval of write data this time and the last time: %lld us", + DHLOGE("This time write data spend: %ld us, The interval of write data this time and the last time: %ld us", endTime - startTime, startTime - lastwriteStartTime_); } lastwriteStartTime_ = startTime; @@ -353,7 +353,7 @@ void DSpeakerDev::EnqueueThread() while (ashmem_ != nullptr && isEnqueueRunning_.load()) { int64_t timeOffset = UpdateTimeOffset(frameIndex_, LOW_LATENCY_INTERVAL_NS, startTime_); - DHLOGD("Read frameIndex: %lld, timeOffset: %lld.", frameIndex_, timeOffset); + DHLOGD("Read frameIndex: %ld, timeOffset: %ld.", frameIndex_, timeOffset); auto readData = ashmem_->ReadFromAshmem(lengthPerTrans_, readIndex_); DHLOGI("Read from ashmem success! read index: %d, readLength: %d.", readIndex_, lengthPerTrans_); std::shared_ptr audioData = std::make_shared(lengthPerTrans_); diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 022415421ae243117915c6bf1e8ce8ab071406d0..17f992c28a088a825faf2806d45ed0ef043f5128 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -92,6 +92,7 @@ ohos_shared_library("distributed_audio_sink") { "eventhandler:libeventhandler", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdi", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", diff --git a/services/audiomanager/servicesink/src/daudio_sink_hidumper.cpp b/services/audiomanager/servicesink/src/daudio_sink_hidumper.cpp index 5060b5043763cfe4a04afd21a00a09ca4dabb256..0b03d39407a9522b4b5d7bb1da9837a33b5a784b 100644 --- a/services/audiomanager/servicesink/src/daudio_sink_hidumper.cpp +++ b/services/audiomanager/servicesink/src/daudio_sink_hidumper.cpp @@ -53,7 +53,7 @@ DaudioSinkHidumper::~DaudioSinkHidumper() bool DaudioSinkHidumper::Dump(const std::vector &args, std::string &result) { - DHLOGI("Distributed audio hidumper dump args.size():%d.", args.size()); + DHLOGI("Distributed audio hidumper dump args.size():%lu.", args.size()); result.clear(); int32_t argsSize = static_cast(args.size()); for (int32_t i = 0; i < argsSize; i++) { diff --git a/services/audiomanager/servicesink/src/daudio_sink_stub.cpp b/services/audiomanager/servicesink/src/daudio_sink_stub.cpp index 6f4a4cb470cd76d06c1889e505e49bf14316a576..3b777504661143ea5f6721203cefd3dab3d7e2d9 100644 --- a/services/audiomanager/servicesink/src/daudio_sink_stub.cpp +++ b/services/audiomanager/servicesink/src/daudio_sink_stub.cpp @@ -30,7 +30,7 @@ namespace OHOS { namespace DistributedHardware { -DAudioSinkStub::DAudioSinkStub() +DAudioSinkStub::DAudioSinkStub() : IRemoteStub(true) { DHLOGD("Distributed audio sink stub constructed."); memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::INIT_SINK)] = diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index c7d2fb51808b275b60be263faf559266bba891fd..b47b1df94293a84179644cb657359367c12ffca2 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -92,6 +92,7 @@ ohos_shared_library("distributed_audio_source") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "audio_framework:audio_renderer", "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", @@ -100,6 +101,7 @@ ohos_shared_library("distributed_audio_source") { "eventhandler:libeventhandler", "hdf_core:libhdi", "hicollie:libhicollie", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", diff --git a/services/audiomanager/servicesource/src/daudio_source_stub.cpp b/services/audiomanager/servicesource/src/daudio_source_stub.cpp index 85b9083ce885e1361e25f271c82102c79166fe73..d00be43ac442f0aeb68964d7fd4c35a2274821bc 100644 --- a/services/audiomanager/servicesource/src/daudio_source_stub.cpp +++ b/services/audiomanager/servicesource/src/daudio_source_stub.cpp @@ -30,7 +30,7 @@ namespace OHOS { namespace DistributedHardware { -DAudioSourceStub::DAudioSourceStub() +DAudioSourceStub::DAudioSourceStub() : IRemoteStub(true) { memberFuncMap_[static_cast(IDAudioSourceInterfaceCode::INIT_SOURCE)] = &DAudioSourceStub::InitSourceInner; diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn index 9df9fde072903a68730da83293666ad2319b5ede..7d0150932dc34fc7970c6dfe910d1a0c0c2ecdd6 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("SourceServiceConfigDistributedHardwareFuzzTest") { ] external_deps = [ + "audio_framework:audio_renderer", "c_utils:utils", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn index 65270fd9b550e979e4eafa4e589c0fd39aebbbda..41bbfc6a3e4b54321ce54a9262ffbbbde119db2b 100644 --- a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn @@ -61,6 +61,7 @@ ohos_fuzztest("SourceServiceDAudioNotifyFuzzTest") { ] external_deps = [ + "audio_framework:audio_renderer", "c_utils:utils", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn index b5dd2fdff71492ea8d1696b4fe8303c3ed60c6ef..a6b8aa132b5a97dd42968c71054409ca8dddedf5 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn @@ -63,6 +63,7 @@ ohos_fuzztest("SourceServiceInitSourceFuzzTest") { ] external_deps = [ + "audio_framework:audio_renderer", "c_utils:utils", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn index 1601f4a8347d342897f887fef3bb7d3b7257f348..c1cd645cb67029bba860b7e923298cffa51e8a9b 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("SourceServiceRegisterDistributedHardwareFuzzTest") { ] external_deps = [ + "audio_framework:audio_renderer", "c_utils:utils", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn index 5804e350ad36f21d44b55eac7e58ae0cae39c3de..c9288ccf744f7ba25473a8e73eeba3e290e0b216 100644 --- a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn @@ -61,6 +61,7 @@ ohos_fuzztest("SourceServiceReleaseSourceFuzzTest") { ] external_deps = [ + "audio_framework:audio_renderer", "c_utils:utils", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn index cb841a09b96f131d5aab31ad36864e4a518b139c..6828a2821c60a74fed7d836449e33240fe608647 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn @@ -60,6 +60,7 @@ ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { ] external_deps = [ + "audio_framework:audio_renderer", "c_utils:utils", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/audiomanager/test/unittest/managersink/BUILD.gn b/services/audiomanager/test/unittest/managersink/BUILD.gn index aa19c34c7731ef5623566c24635fca5d80191f46..641605c0c62d50c0be73fc629050768c8a254171 100644 --- a/services/audiomanager/test/unittest/managersink/BUILD.gn +++ b/services/audiomanager/test/unittest/managersink/BUILD.gn @@ -77,6 +77,7 @@ ohos_unittest("DaudioSinkDevTest") { "device_security_level:dslm_sdk", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", + "eventhandler:libeventhandler", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", "hdf_core:libhdi", diff --git a/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp b/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp index 2a1bfd3ea85cc37aadfba12799bc99c70448cff0..06ccd6c53871c03aa77b63b7500076a7098d1fc7 100644 --- a/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp +++ b/services/audiomanager/test/unittest/managersink/src/daudio_sink_dev_test.cpp @@ -92,6 +92,18 @@ HWTEST_F(DAudioSinkDevTest, TaskPlayStatusChange_001, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, sinkDev_->TaskPlayStatusChange("{\"dhId\":\"1\"}")); } +/** + * @tc.name: TaskDisableDevice_001 + * @tc.desc: Verify the TaskDisableDevice function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, TaskDisableDevice_001, TestSize.Level1) +{ + std::string spkName = "ohos.dhardware.daudio.dspeaker.ohos.dhardware.daudio.dmic"; + EXPECT_EQ(DH_SUCCESS, sinkDev_->TaskDisableDevice(spkName)); +} + /** * @tc.name: TaskOpenDSpeaker_001 * @tc.desc: Verify the TaskOpenDSpeaker function. @@ -102,6 +114,8 @@ HWTEST_F(DAudioSinkDevTest, TaskOpenDSpeaker_001, TestSize.Level1) { std::string args; EXPECT_NE(DH_SUCCESS, sinkDev_->TaskOpenDSpeaker(args)); + args.resize(DAUDIO_MAX_JSON_LEN + 1); + EXPECT_EQ(ERR_DH_AUDIO_SA_PARAM_INVALID, sinkDev_->TaskOpenDSpeaker(args)); } /** @@ -144,6 +158,20 @@ HWTEST_F(DAudioSinkDevTest, TaskCloseDSpeaker_002, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, sinkDev_->TaskCloseDSpeaker(args)); } +/** + * @tc.name: ParseDhidFromEvent_001 + * @tc.desc: Verify the ParseDhidFromEvent function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, ParseDhidFromEvent_001, TestSize.Level1) +{ + std::string args = "{\"devId\":\"1\"}"; + EXPECT_NE(DH_SUCCESS, sinkDev_->ParseDhidFromEvent(args)); + std::string dhIdArgs = "{\"dhId\": 1 }"; + EXPECT_NE(DH_SUCCESS, sinkDev_->ParseDhidFromEvent(dhIdArgs)); +} + /** * @tc.name: TaskStartRender_001 * @tc.desc: Verify the TaskStartRender function. @@ -159,6 +187,8 @@ HWTEST_F(DAudioSinkDevTest, TaskStartRender_001, TestSize.Level1) auto spkClient = std::make_shared(devId, dhId, sinkDev_); sinkDev_->spkClientMap_.insert(std::make_pair(DEFAULT_RENDER_ID, spkClient)); EXPECT_NE(DH_SUCCESS, sinkDev_->TaskStartRender(args)); + std::string devIdArgs = "{\"devId\":\"1\"}"; + EXPECT_EQ(ERR_DH_AUDIO_FAILED, sinkDev_->TaskStartRender(devIdArgs)); } /** @@ -211,6 +241,8 @@ HWTEST_F(DAudioSinkDevTest, TaskCloseDMic_002, TestSize.Level1) auto micClient = std::make_shared(devId, dhId, sinkDev_); sinkDev_->micClientMap_.insert(std::make_pair(DEFAULT_CAPTURE_ID, micClient)); EXPECT_EQ(DH_SUCCESS, sinkDev_->TaskCloseDMic(args)); + std::string dhIdArgs = "{\"dhId\":1}"; + EXPECT_EQ(ERR_DH_AUDIO_FAILED, sinkDev_->TaskCloseDMic(dhIdArgs)); } /** @@ -223,6 +255,13 @@ HWTEST_F(DAudioSinkDevTest, TaskSetParameter_001, TestSize.Level1) { std::string args; EXPECT_NE(DH_SUCCESS, sinkDev_->TaskSetParameter(args)); + int32_t dhId = 1; + std::string devId = "devId"; + args += "{\"dhId\":\"1\"}"; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->TaskSetParameter(args)); + auto spkClient = std::make_shared(devId, dhId, sinkDev_); + sinkDev_->spkClientMap_.insert(std::make_pair(DEFAULT_RENDER_ID, spkClient)); + EXPECT_NE(DH_SUCCESS, sinkDev_->TaskSetParameter(args)); } /** @@ -261,12 +300,14 @@ HWTEST_F(DAudioSinkDevTest, TaskSetVolume_001, TestSize.Level1) */ HWTEST_F(DAudioSinkDevTest, TaskSetVolume_002, TestSize.Level1) { - std::string args; + std::string args = "{\"dhId\":\"1\"}"; std::string devId; int32_t dhId = 1; auto spkClient = std::make_shared(devId, dhId, sinkDev_); sinkDev_->spkClientMap_.insert(std::make_pair(DEFAULT_RENDER_ID, spkClient)); EXPECT_NE(DH_SUCCESS, sinkDev_->TaskSetVolume(args)); + std::string args1 = "dhId=1"; + EXPECT_NE(DH_SUCCESS, sinkDev_->TaskSetVolume(args1)); } /** @@ -289,12 +330,14 @@ HWTEST_F(DAudioSinkDevTest, TaskSetMute_001, TestSize.Level1) */ HWTEST_F(DAudioSinkDevTest, TaskSetMute_002, TestSize.Level1) { - std::string args; - std::string devId; + std::string args = "{\"dhId\":\"1\", \"eventType\":\"setMute\"}"; + std::string devId = "devId"; int32_t dhId = 1; auto spkClient = std::make_shared(devId, dhId, sinkDev_); sinkDev_->spkClientMap_.insert(std::make_pair(DEFAULT_RENDER_ID, spkClient)); EXPECT_NE(DH_SUCCESS, sinkDev_->TaskSetMute(args)); + std::string args1 = "dhId=1"; + EXPECT_NE(DH_SUCCESS, sinkDev_->TaskSetMute(args1)); } /** @@ -357,10 +400,25 @@ HWTEST_F(DAudioSinkDevTest, TaskFocusChange_002, TestSize.Level1) */ HWTEST_F(DAudioSinkDevTest, TaskRenderStateChange_001, TestSize.Level1) { + int32_t dhIdSpk = 1; + int32_t dhIdMic = 1 << 27 | 1 << 0; std::string args = "{\"dhId\":\"123\"}"; std::string dhId = "123"; + std::string devId = "devId"; + std::string dhIdS = "1"; + std::string dhIdM = "134217729"; int32_t result = 0; sinkDev_->NotifySourceDev(AUDIO_START, dhId, result); + auto spkClient = std::make_shared(devId, dhIdSpk, sinkDev_); + sinkDev_->spkClientMap_.insert(std::make_pair(DEFAULT_RENDER_ID, spkClient)); + auto micClient = std::make_shared(devId, dhIdMic, sinkDev_); + sinkDev_->micClientMap_.insert(std::make_pair(DEFAULT_CAPTURE_ID, micClient)); + sinkDev_->NotifySourceDev(AUDIO_START, dhId, result); + sinkDev_->NotifySourceDev(NOTIFY_OPEN_CTRL_RESULT, dhId, result); + sinkDev_->NotifySourceDev(NOTIFY_CLOSE_CTRL_RESULT, dhId, result); + sinkDev_->NotifySourceDev(AUDIO_START, devId, result); + sinkDev_->NotifySourceDev(AUDIO_START, dhIdS, result); + sinkDev_->NotifySourceDev(AUDIO_START, dhIdM, result); EXPECT_NE(DH_SUCCESS, sinkDev_->TaskRenderStateChange(args)); } @@ -412,5 +470,209 @@ HWTEST_F(DAudioSinkDevTest, PauseDistributedHardware_001, TestSize.Level1) EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sinkDev_->ResumeDistributedHardware(networkId)); EXPECT_EQ(DH_SUCCESS, sinkDev_->StopDistributedHardware(networkId)); } + +/** + * @tc.name: JudgeDeviceStatus_001 + * @tc.desc: Verify the JudgeDeviceStatus function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, JudgeDeviceStatus_001, TestSize.Level1) +{ + sinkDev_->JudgeDeviceStatus(); + sinkDev_->isSpkInUse_.store(true); + sinkDev_->JudgeDeviceStatus(); + sinkDev_->isMicInUse_.store(true); + sinkDev_->JudgeDeviceStatus(); + sinkDev_->isSpkInUse_.store(false); + sinkDev_->JudgeDeviceStatus(); + std::string args = "one"; + EXPECT_NE(DH_SUCCESS, sinkDev_->ConvertString2Int(args)); +} + +/** + * @tc.name: SinkEventHandler_001 + * @tc.desc: Verify the SinkEventHandler function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, SinkEventHandler_001, TestSize.Level1) +{ + int32_t eventType = 2500; + std::string eventContent = "eventContent"; + AudioEvent audioEvent(eventType, eventContent); + auto eventParam = std::make_shared(audioEvent); + auto msgEvent = AppExecFwk::InnerEvent::Get(static_cast(audioEvent.type), eventParam, 0); + EXPECT_EQ(DH_SUCCESS, sinkDev_->AwakeAudioDev()); + sinkDev_->handler_->ProcessEvent(msgEvent); + eventType = CTRL_OPENED; + std::string content = "content"; + AudioEvent event(eventType, content); + auto Param = std::make_shared(event); + auto msg = AppExecFwk::InnerEvent::Get(static_cast(event.type), Param, 0); + sinkDev_->handler_->ProcessEvent(msg); + sinkDev_->handler_->NotifyCtrlOpened(msg); + std::string networkId = "networkId"; + std::string devId; + int32_t dhId = 134217729; + sinkDev_->micDhId_ = "134217729"; + auto micClient = std::make_shared(devId, dhId, sinkDev_); + sinkDev_->micClientMap_.insert(std::make_pair(DEFAULT_CAPTURE_ID, micClient)); + EXPECT_EQ(DH_SUCCESS, sinkDev_->PauseDistributedHardware(networkId)); +} + +/** + * @tc.name: SinkEventHandler_002 + * @tc.desc: Verify the SinkEventHandler function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, SinkEventHandler_002, TestSize.Level1) +{ + int32_t dhId = 1; + int32_t eventType = CTRL_CLOSED; + std::string eventContent = "{\"dhId\":\"1\"}"; + std::string devId = "devId"; + AudioEvent audioEvent(eventType, eventContent); + auto eventParam = std::make_shared(audioEvent); + auto msgEvent = AppExecFwk::InnerEvent::Get(static_cast(audioEvent.type), eventParam, 0); + EXPECT_EQ(DH_SUCCESS, sinkDev_->AwakeAudioDev()); + sinkDev_->spkClientMap_[dhId] = nullptr; + sinkDev_->micClientMap_[dhId] = nullptr; + sinkDev_->handler_->NotifyCtrlClosed(msgEvent); + auto micClient = std::make_shared(devId, dhId, sinkDev_); + sinkDev_->micClientMap_.insert(std::make_pair(DEFAULT_CAPTURE_ID, micClient)); + micClient->micTrans_ =nullptr; + sinkDev_->handler_->NotifyCtrlClosed(msgEvent); + std::string content = "content"; + AudioEvent event(eventType, content); + auto Param = std::make_shared(event); + auto msg = AppExecFwk::InnerEvent::Get(static_cast(event.type), Param, 0); + sinkDev_->handler_->NotifyCtrlClosed(msg); + std::string networkId = "networkId"; + dhId = 134217729; + sinkDev_->micDhId_ = "134217729"; + micClient = std::make_shared(devId, dhId, sinkDev_); + sinkDev_->micClientMap_.insert(std::make_pair(DEFAULT_CAPTURE_ID, micClient)); + EXPECT_EQ(DH_SUCCESS, sinkDev_->ResumeDistributedHardware(networkId)); +} + +/** + * @tc.name: SinkEventHandler_003 + * @tc.desc: Verify the SinkEventHandler function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, SinkEventHandler_003, TestSize.Level1) +{ + int32_t eventType = OPEN_SPEAKER; + std::string eventContent = "{\"dhId\":\"dhId\",\"audioParam\":\"audioParam\"}"; + std::string devId = "devId"; + std::string networkId = "networkId"; + AudioEvent audioEvent(eventType, devId); + auto eventParam = std::make_shared(audioEvent); + auto msgEvent = AppExecFwk::InnerEvent::Get(static_cast(audioEvent.type), eventParam, 0); + EXPECT_EQ(DH_SUCCESS, sinkDev_->AwakeAudioDev()); + sinkDev_->handler_->NotifyOpenSpeaker(msgEvent); + sinkDev_->handler_->NotifyOpenMic(msgEvent); + AudioEvent event(eventType, eventContent); + auto Param = std::make_shared(event); + auto msg = AppExecFwk::InnerEvent::Get(static_cast(event.type), Param, 0); + sinkDev_->handler_->NotifyOpenSpeaker(msg); + EXPECT_EQ(DH_SUCCESS, sinkDev_->StopDistributedHardware(networkId)); +} + +/** + * @tc.name: SinkEventHandler_004 + * @tc.desc: Verify the SinkEventHandler function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, SinkEventHandler_004, TestSize.Level1) +{ + int32_t eventType = OPEN_SPEAKER; + std::shared_ptr nullForFail = nullptr; + auto msgEvent = AppExecFwk::InnerEvent::Get(static_cast(eventType), nullForFail, 0); + EXPECT_EQ(DH_SUCCESS, sinkDev_->AwakeAudioDev()); + sinkDev_->handler_->NotifyCtrlOpened(msgEvent); + sinkDev_->handler_->NotifyCtrlClosed(msgEvent); + sinkDev_->handler_->NotifyOpenSpeaker(msgEvent); + sinkDev_->handler_->NotifyCloseSpeaker(msgEvent); + sinkDev_->handler_->NotifySpeakerOpened(msgEvent); + sinkDev_->handler_->NotifySpeakerClosed(msgEvent); + sinkDev_->handler_->NotifyOpenMic(msgEvent); + sinkDev_->handler_->NotifyCloseMic(msgEvent); + sinkDev_->handler_->NotifyMicOpened(msgEvent); + sinkDev_->handler_->NotifyMicClosed(msgEvent); + sinkDev_->handler_->NotifySetVolume(msgEvent); + sinkDev_->handler_->NotifyVolumeChange(msgEvent); + sinkDev_->handler_->NotifySetParam(msgEvent); + sinkDev_->handler_->NotifySetMute(msgEvent); + sinkDev_->handler_->NotifyFocusChange(msgEvent); + sinkDev_->handler_->NotifyRenderStateChange(msgEvent); + sinkDev_->handler_->NotifyPlayStatusChange(msgEvent); + std::string eventContent = "{\"dhId\":\"1\"}"; + std::string paramResult; + AudioEvent audioEvent(eventType, eventContent); + sinkDev_->NotifyEvent(audioEvent); + auto eventParam = std::make_shared(audioEvent); + auto msg = AppExecFwk::InnerEvent::Get(static_cast(audioEvent.type), eventParam, 0); + sinkDev_->handler_->NotifyCtrlOpened(msg); + sinkDev_->handler_->NotifyCtrlClosed(msg); + sinkDev_->handler_->NotifyOpenSpeaker(msg); + sinkDev_->handler_->NotifyCloseSpeaker(msg); + sinkDev_->handler_->NotifySpeakerOpened(msg); + sinkDev_->handler_->NotifySpeakerClosed(msg); + sinkDev_->handler_->NotifyOpenMic(msg); + sinkDev_->handler_->NotifyCloseMic(msg); + sinkDev_->handler_->NotifyMicOpened(msg); + sinkDev_->handler_->NotifyMicClosed(msg); + sinkDev_->handler_->NotifySetVolume(msg); + sinkDev_->handler_->NotifyVolumeChange(msg); + sinkDev_->handler_->NotifySetParam(msg); + sinkDev_->handler_->NotifySetMute(msg); + sinkDev_->handler_->NotifyFocusChange(msg); + sinkDev_->handler_->NotifyRenderStateChange(msg); + sinkDev_->handler_->NotifyPlayStatusChange(msg); + EXPECT_EQ(DH_SUCCESS, sinkDev_->handler_->GetEventParam(msg, paramResult)); +} + +/** + * @tc.name: NotifyCtrlClosed_001 + * @tc.desc: Verify the NotifyCtrlClosed function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkDevTest, NotifyCtrlClosed_001, TestSize.Level1) +{ + std::string eventContent1 = "ohos.dhardware.daudio.dspeaker"; + std::string eventContent2 = "ohos.dhardware.daudio.dmic"; + std::string eventContent3 = "ohos.dhardware.daudio.dspeaker.ohos.dhardware.daudio.dmic"; + int32_t eventType = DISABLE_DEVICE; + AudioEvent audioEvent(eventType, eventContent1); + sinkDev_->NotifyEvent(audioEvent); + audioEvent.content = eventContent2; + sinkDev_->NotifyEvent(audioEvent); + audioEvent.content = eventContent3; + sinkDev_->NotifyEvent(audioEvent); + std::string eventContent = "{\"devId\":\"1\"}"; + std::string paramResult; + audioEvent.type = OPEN_SPEAKER; + audioEvent.content = eventContent; + sinkDev_->NotifyEvent(audioEvent); + auto eventParam = std::make_shared(audioEvent); + auto msg = AppExecFwk::InnerEvent::Get(static_cast(audioEvent.type), eventParam, 0); + EXPECT_EQ(DH_SUCCESS, sinkDev_->AwakeAudioDev()); + sinkDev_->handler_->NotifyCtrlClosed(msg); + audioEvent.content = "{\"dhId\":\"134217729\"}"; + eventParam = std::make_shared(audioEvent); + msg = AppExecFwk::InnerEvent::Get(static_cast(audioEvent.type), eventParam, 0); + sinkDev_->handler_->NotifyCtrlClosed(msg); + int32_t dhIdMic = 1 << 27 | 1 << 0;; + std::string devId = "devId"; + auto micClient = std::make_shared(devId, dhIdMic, sinkDev_); + sinkDev_->micClientMap_.insert(std::make_pair(DEFAULT_CAPTURE_ID, micClient)); + EXPECT_EQ(DH_SUCCESS, sinkDev_->handler_->GetEventParam(msg, paramResult)); +} } // DistributedHardware } // OHOS diff --git a/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp b/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp index a1715fbcb9c82eb2ca3e4b165c2abea524c53e0d..b161adfa6f13449b5f8f61fe7aa103591992006e 100644 --- a/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp +++ b/services/audiomanager/test/unittest/managersink/src/daudio_sink_manager_test.cpp @@ -57,6 +57,35 @@ HWTEST_F(DAudioSinkManagerTest, Init_001, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, daudioSinkManager.UnInit()); } +/** + * @tc.name: OnSinkDevReleased_001 + * @tc.desc: Verify the OnSinkDevReleased function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkManagerTest, OnSinkDevReleased_001, TestSize.Level1) +{ + std::string devId = "1"; + daudioSinkManager.devClearThread_ = std::thread(&DAudioSinkManager::ClearAudioDev, &daudioSinkManager, devId); + daudioSinkManager.OnSinkDevReleased(devId); +} + +/** + * @tc.name: HandleDAudioNotify_001 + * @tc.desc: Verify the HandleDAudioNotify function. + * @tc.type: FUNC + * @tc.require: AR000H0E5F + */ +HWTEST_F(DAudioSinkManagerTest, HandleDAudioNotify_001, TestSize.Level1) +{ + std::string devId = "1"; + std::string dhId = "1"; + std::string content = "1"; + int32_t type = 1; + daudioSinkManager.audioDevMap_.emplace(devId, nullptr); + EXPECT_EQ(DH_SUCCESS, daudioSinkManager.HandleDAudioNotify(devId, dhId, type, content)); +} + /** * @tc.name: DAudioNotify_001 * @tc.desc: Verify the DAudioNotify function. diff --git a/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp b/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp index 21ff2f13f99fc2ca87956123466026a2d0e7b27b..92947a23e56846bf2d5bea817f1d168221c6c5e8 100644 --- a/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp +++ b/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp @@ -104,6 +104,9 @@ HWTEST_F(DAudioSourceServiceTest, Dump_001, TestSize.Level1) int32_t fd = 1; std::vector args; EXPECT_EQ(DH_SUCCESS, sourceSrv_->Dump(fd, args)); + std::u16string order = u"--sourceDevId"; + args.push_back(order); + EXPECT_EQ(ERR_DH_AUDIO_BAD_VALUE, sourceSrv_->Dump(fd, args)); } } // DistributedHardware } // OHOS diff --git a/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp b/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp index bfe29a877ba7387eab3cf941f1a9cfbc304f28c1..d68d6ea7cc7f40a60817940b3634dd98740a25f0 100644 --- a/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp +++ b/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp @@ -284,6 +284,12 @@ HWTEST_F(DMicDevTest, ReadStreamData_001, TestSize.Level1) std::shared_ptr readData = nullptr; mic_->dataQueue_.push(writeData); EXPECT_EQ(DH_SUCCESS, mic_->ReadStreamData(DEV_ID, DH_ID, readData)); + for (size_t i = 0; i < 11; ++i) { + auto data = std::make_shared(DEFAULT_AUDIO_DATA_SIZE); + mic_->dataQueue_.push(data); + } + mic_->isEnqueueRunning_ = true; + mic_->FillJitterQueue(); std::shared_ptr readData1 = nullptr; EXPECT_EQ(DH_SUCCESS, mic_->ReadStreamData(DEV_ID, DH_ID, readData1)); diff --git a/services/audiotransport/receiverengine/BUILD.gn b/services/audiotransport/receiverengine/BUILD.gn index 98cc9aa94dd1e0df3664cbd828f39bd501ffeb63..bd4467f85fd162771613248eb9897f0a4692662b 100644 --- a/services/audiotransport/receiverengine/BUILD.gn +++ b/services/audiotransport/receiverengine/BUILD.gn @@ -66,6 +66,7 @@ ohos_shared_library("distributed_audio_decode_transport") { "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "dsoftbus:softbus_client", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "player_framework:media_client", diff --git a/services/audiotransport/receiverengine/src/av_receiver_engine_transport.cpp b/services/audiotransport/receiverengine/src/av_receiver_engine_transport.cpp index a311d5f1edfc4ee7ad79c177c4a28da6366de7ff..5f0de401b63dc447ed54d752219a08ff8ed71361 100644 --- a/services/audiotransport/receiverengine/src/av_receiver_engine_transport.cpp +++ b/services/audiotransport/receiverengine/src/av_receiver_engine_transport.cpp @@ -126,7 +126,7 @@ void AVTransReceiverTransport::OnEngineMessage(const std::shared_ptr &buffer) { - DHLOGI("On data availabled."); + DHLOGD("On data availabled."); CHECK_NULL_VOID(buffer); auto bufferData = buffer->GetBufferData(0); std::shared_ptr audioData = std::make_shared(bufferData->GetSize()); diff --git a/services/audiotransport/senderengine/BUILD.gn b/services/audiotransport/senderengine/BUILD.gn index 6e18f37a28a06c8cb9f215d511eb193de20edae8..8b69ea14f3d698c79f0d6c949b33ca523772e670 100644 --- a/services/audiotransport/senderengine/BUILD.gn +++ b/services/audiotransport/senderengine/BUILD.gn @@ -66,6 +66,7 @@ ohos_shared_library("distributed_audio_encode_transport") { "c_utils:utils", "distributed_hardware_fwk:distributed_av_sender", "dsoftbus:softbus_client", + "hilog:libhilog", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "player_framework:media_client", diff --git a/services/audiotransport/test/unittest/receiverengine/engineutils/include/engine_test_utils.h b/services/audiotransport/test/unittest/receiverengine/engineutils/include/engine_test_utils.h index f4a3b6319e940039ba95ceccb6f1fa9e3246c3a5..781ef4034b54c382ad3cd0002b837666d4f0e548 100644 --- a/services/audiotransport/test/unittest/receiverengine/engineutils/include/engine_test_utils.h +++ b/services/audiotransport/test/unittest/receiverengine/engineutils/include/engine_test_utils.h @@ -198,6 +198,78 @@ public: return false; } }; + +class MockIAVSenderEngineForFail : public IAVSenderEngine { +public: + explicit MockIAVSenderEngineForFail() {} + ~MockIAVSenderEngineForFail() {} + + int32_t Initialize() override + { + return 0; + } + + int32_t Start() override + { + return 0; + } + + int32_t Stop() override + { + return 0; + } + + int32_t Release() override + { + return 1; + } + + int32_t PushData(const std::shared_ptr &buffer) override + { + return 0; + } + + int32_t SetParameter(AVTransTag tag, const std::string &value) override + { + (void) tag; + (void) value; + return 0; + } + + int32_t SendMessage(const std::shared_ptr &message) override + { + return 0; + } + + int32_t CreateControlChannel(const std::vector &dstDevIds, + const ChannelAttribute &attribution) override + { + (void) dstDevIds; + (void) attribution; + return 1; + } + + int32_t RegisterSenderCallback(const std::shared_ptr &callback) + { + (void) callback; + return 0; + } + + bool StartDumpMediaData() override + { + return false; + } + + bool StopDumpMediaData() override + { + return false; + } + + bool ReStartDumpMediaData() override + { + return false; + } +}; } // DistributedHardware } // OHOS #endif // OHOS_ENGINE_TEST_UTILS_H \ No newline at end of file diff --git a/services/audiotransport/test/unittest/senderengine/src/av_sender_engine_adapter_test.cpp b/services/audiotransport/test/unittest/senderengine/src/av_sender_engine_adapter_test.cpp index 5c5d140ef515fa722fa98afb627ec2cf69e9b9c9..54dd04947fb2643381d4b5cd6fc6abdd23383680 100644 --- a/services/audiotransport/test/unittest/senderengine/src/av_sender_engine_adapter_test.cpp +++ b/services/audiotransport/test/unittest/senderengine/src/av_sender_engine_adapter_test.cpp @@ -69,6 +69,18 @@ HWTEST_F(AVSenderEngineAdapterTest, Initialize_002, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, senderAdapter_->Release()); } +/** + * @tc.name: Release_001 + * @tc.desc: Verify the Release function. + * @tc.type: FUNC + * @tc.require: AR000HTAPM + */ +HWTEST_F(AVSenderEngineAdapterTest, Release_001, TestSize.Level1) +{ + senderAdapter_->senderEngine_ = std::make_shared(); + EXPECT_EQ(DH_SUCCESS, senderAdapter_->Release()); +} + /** * @tc.name: Start_001 * @tc.desc: Verify the Start and Stop function. @@ -149,6 +161,20 @@ HWTEST_F(AVSenderEngineAdapterTest, CreateControlChannel_002, TestSize.Level1) EXPECT_EQ(ERR_DH_AV_TRANS_CREATE_CHANNEL_FAILED, senderAdapter_->CreateControlChannel(peerDevId)); } +/** + * @tc.name: WaitForChannelCreated_001 + * @tc.desc: Verify the WaitForChannelCreated function. + * @tc.type: FUNC + * @tc.require: AR000HTAPM + */ +HWTEST_F(AVSenderEngineAdapterTest, WaitForChannelCreated_001, TestSize.Level1) +{ + senderAdapter_->chnCreateSuccess_ = true; + EXPECT_EQ(DH_SUCCESS, senderAdapter_->WaitForChannelCreated()); + senderAdapter_->chnCreateSuccess_ = false; + EXPECT_EQ(ERR_DH_AUDIO_SA_WAIT_TIMEOUT, senderAdapter_->WaitForChannelCreated()); +} + /** * @tc.name: SendMessageToRemote_001 * @tc.desc: Verify the SendMessageToRemote function. @@ -196,5 +222,21 @@ HWTEST_F(AVSenderEngineAdapterTest, OnSenderEvent_001, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, senderAdapter_->OnSenderEvent(event)); EXPECT_EQ(DH_SUCCESS, senderAdapter_->OnMessageReceived(message)); } + +/** + * @tc.name: OnSenderEvent_002 + * @tc.desc: Verify the OnSenderEvent function. + * @tc.type: FUNC + * @tc.require: AR000HTAPM + */ +HWTEST_F(AVSenderEngineAdapterTest, OnSenderEvent_002, TestSize.Level1) +{ + AVTransEvent event; + event.type = EventType::EVENT_ADD_STREAM; + EXPECT_EQ(DH_SUCCESS, senderAdapter_->OnSenderEvent(event)); + senderAdapter_->adapterCallback_ = std::make_shared(); + event.type = EventType::EVENT_START_SUCCESS; + EXPECT_EQ(DH_SUCCESS, senderAdapter_->OnSenderEvent(event)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/test/unittest/senderengine/src/av_sender_engine_transport_test.cpp b/services/audiotransport/test/unittest/senderengine/src/av_sender_engine_transport_test.cpp index 486867b1f35e750d573031d527f86ac37863e172..57b919a2f36f1f68fbfadc525515d9883f75b0c1 100644 --- a/services/audiotransport/test/unittest/senderengine/src/av_sender_engine_transport_test.cpp +++ b/services/audiotransport/test/unittest/senderengine/src/av_sender_engine_transport_test.cpp @@ -187,6 +187,25 @@ HWTEST_F(AVSenderEngineTransportTest, SetParameter_001, TestSize.Level1) EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, senderTrans_->SetParameter(audioParam)); senderTrans_->senderAdapter_ = std::make_shared(); EXPECT_EQ(DH_SUCCESS, senderTrans_->SetParameter(audioParam)); + message = std::make_shared(); + senderTrans_->OnEngineMessage(message); + senderTrans_->transCallback_ = nullptr; +} + +/** + * @tc.name: OnEngineMessage_001 + * @tc.desc: Verify the OnEngineMessage function. + * @tc.type: FUNC + * @tc.require: AR000HTAPM + */ +HWTEST_F(AVSenderEngineTransportTest, OnEngineMessage_001, TestSize.Level1) +{ + std::shared_ptr message = nullptr; + senderTrans_->OnEngineMessage(message); + message = std::make_shared(); + senderTrans_->OnEngineMessage(message); + senderTrans_->transCallback_ = nullptr; + senderTrans_->OnEngineMessage(message); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/hdfaudioclient/src/daudio_adapter_internal.cpp b/services/hdfaudioclient/src/daudio_adapter_internal.cpp index b6128c28084e09ca129fdfd97b4fd41d495f68ee..b78522e3c4e1ef5e6f86492dc6e9bafd9e1fbbc7 100644 --- a/services/hdfaudioclient/src/daudio_adapter_internal.cpp +++ b/services/hdfaudioclient/src/daudio_adapter_internal.cpp @@ -200,11 +200,11 @@ static int32_t GetPassthroughModeInternal(struct AudioAdapter *adapter, const st static int32_t InitAudioPortCapability(std::unique_ptr<::AudioPortCapability> &capInternal, AudioPortCapability &capabilityHal) { - DHLOGI("Init audio port capability internal, formatNum: %zu.", capabilityHal.formatNum); + DHLOGI("Init audio port capability internal, formatNum: %u.", capabilityHal.formatNum); constexpr uint32_t maxFormatNum = 100; constexpr uint32_t minFormatNum = 1; if (capabilityHal.formatNum < minFormatNum || capabilityHal.formatNum > maxFormatNum) { - DHLOGE("Init audio port capability, formatNum: %zu.", capabilityHal.formatNum); + DHLOGE("Init audio port capability, formatNum: %u.", capabilityHal.formatNum); return ERR_DH_AUDIO_HDI_INVALID_PARAM; } ::AudioFormat *audioFormats = (::AudioFormat *)malloc(capabilityHal.formatNum * sizeof(::AudioFormat)); diff --git a/services/hdfaudioclient/src/distributed_audio_client.cpp b/services/hdfaudioclient/src/distributed_audio_client.cpp index 0bba46de6042fd8cf350074fdd1f939cbbb6f6a6..e4df6a370d9cdcc0406876125881db00d62791c8 100644 --- a/services/hdfaudioclient/src/distributed_audio_client.cpp +++ b/services/hdfaudioclient/src/distributed_audio_client.cpp @@ -252,6 +252,9 @@ static bool AudioManagerInit() { std::lock_guard lock(g_AudioManagerContext.mtx_); + g_AudioManagerContext.adapters_.clear(); + g_AudioManagerContext.ClearDescriptors(); + sptr audioMgr = IAudioManager::Get("daudio_primary_service", false); CHECK_NULL_RETURN(audioMgr, false); g_AudioManagerContext.proxy_ = audioMgr; diff --git a/services/hdfaudioclient/test/unittest/BUILD.gn b/services/hdfaudioclient/test/unittest/BUILD.gn index 056518e580ddb0d42e4aeef0c15d123f071be681..08875bb4a4de930c6d00510539314b663f108630 100644 --- a/services/hdfaudioclient/test/unittest/BUILD.gn +++ b/services/hdfaudioclient/test/unittest/BUILD.gn @@ -42,6 +42,7 @@ ohos_unittest("AudioAdapterHdiTest") { external_deps = [ "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "hilog:libhilog", "ipc:ipc_core", ] @@ -73,7 +74,10 @@ ohos_unittest("AudioRenderInternalTest") { "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] - external_deps = [ "drivers_interface_distributed_audio:libdaudio_proxy_1.0" ] + external_deps = [ + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "hilog:libhilog", + ] defines = [ "HI_LOG_ENABLE", @@ -103,7 +107,10 @@ ohos_unittest("AudioCaptureInternalTest") { "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] - external_deps = [ "drivers_interface_distributed_audio:libdaudio_proxy_1.0" ] + external_deps = [ + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "hilog:libhilog", + ] defines = [ "HI_LOG_ENABLE", @@ -137,6 +144,7 @@ ohos_unittest("AudioAdapterInternalTest") { external_deps = [ "c_utils:utils", "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "hilog:libhilog", ] defines = [ diff --git a/services/hdfaudioclient/test/unittest/audio_manager_test.cpp b/services/hdfaudioclient/test/unittest/audio_manager_test.cpp index 2cb3906c2f416c17e5e6c6441a4675b727952dca..4ce51c2f3bd5f8d021082e832b0dfae634d2b55d 100644 --- a/services/hdfaudioclient/test/unittest/audio_manager_test.cpp +++ b/services/hdfaudioclient/test/unittest/audio_manager_test.cpp @@ -53,7 +53,6 @@ HWTEST_F(AudioManagerTest, GetAllAdaptersAbnormal, TestSize.Level1) struct AudioManagerContext managerContext; int32_t size = 0; AudioAdapterDescriptor *descs = nullptr; - int32_t ret = managerContext.instance_.GetAllAdapters(nullptr, &descs, &size); EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); ret = managerContext.instance_.GetAllAdapters(&managerContext.instance_, nullptr, &size); @@ -74,7 +73,6 @@ HWTEST_F(AudioManagerTest, LoadAdapterAbnormal, TestSize.Level1) AudioAdapterDescriptor desc = {}; AudioAdapter *adapter = nullptr; struct AudioManager *manager = nullptr; - int32_t ret = managerContext.instance_.LoadAdapter(nullptr, &desc, &adapter); EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); ret = managerContext.instance_.LoadAdapter(&managerContext.instance_, nullptr, &adapter); diff --git a/services/hdfaudioclient/test/unittest/audio_render_internal/audio_render_internal_test.cpp b/services/hdfaudioclient/test/unittest/audio_render_internal/audio_render_internal_test.cpp index 1a1665ff1b723ca50b5fb17638e4f1420c1a6e9b..1377ee4a916d126c27bea44f0ec5430595596079 100644 --- a/services/hdfaudioclient/test/unittest/audio_render_internal/audio_render_internal_test.cpp +++ b/services/hdfaudioclient/test/unittest/audio_render_internal/audio_render_internal_test.cpp @@ -128,10 +128,10 @@ HWTEST_F(AudioRenderTest, GetRenderSpeedInternal_001, TestSize.Level1) */ HWTEST_F(AudioRenderTest, GetRenderSpeedInternal_002, TestSize.Level1) { - struct AudioRenderContext renderContext; struct AudioRender *render = new AudioRender; float *speed = new float; - int32_t ret = renderContext.instance_.GetRenderSpeed(render, speed); + AudioRenderContext *context = reinterpret_cast(render); + int32_t ret = context->instance_.GetRenderSpeed(render, speed); delete render; delete speed; EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret);