From dd82d30ef5d27d05f916814975772b74af374e6e Mon Sep 17 00:00:00 2001 From: byndyx Date: Mon, 22 Jan 2024 21:26:06 +0800 Subject: [PATCH 01/17] add UT Signed-off-by: byndyx --- common/include/daudio_log.h | 27 ++- common/test/unittest/BUILD.gn | 2 + .../test/unittest/src/daudio_utils_test.cpp | 20 ++ .../managersink/src/daudio_sink_dev.cpp | 183 +++++----------- .../managersink/src/daudio_sink_manager.cpp | 21 +- .../test/unittest/managersink/BUILD.gn | 1 + .../managersink/src/daudio_sink_dev_test.cpp | 198 +++++++++++++++++- .../src/daudio_sink_manager_test.cpp | 29 +++ .../audiotransport/receiverengine/BUILD.gn | 4 +- .../engineutils/include/engine_test_utils.h | 72 +++++++ .../src/av_sender_engine_adapter_test.cpp | 42 ++++ .../src/av_sender_engine_transport_test.cpp | 19 ++ 12 files changed, 468 insertions(+), 150 deletions(-) diff --git a/common/include/daudio_log.h b/common/include/daudio_log.h index 3d597a23..25f16cc1 100644 --- a/common/include/daudio_log.h +++ b/common/include/daudio_log.h @@ -39,7 +39,7 @@ 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) \ +#define CHECK_NULL_VOID(ptr) \ do { \ if ((ptr) == nullptr) { \ DHLOGE("Address pointer is null"); \ @@ -47,13 +47,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/test/unittest/BUILD.gn b/common/test/unittest/BUILD.gn index b6231b5d..ece35feb 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,6 +42,7 @@ ohos_unittest("DaudioUtilsTest") { deps = [ "${services_path}/common:distributed_audio_utils", + "//third_party/cJSON:cjson", "//third_party/googletest:gtest_main", ] diff --git a/common/test/unittest/src/daudio_utils_test.cpp b/common/test/unittest/src/daudio_utils_test.cpp index 88131841..0945e4a5 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" @@ -299,5 +300,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/services/audiomanager/managersink/src/daudio_sink_dev.cpp b/services/audiomanager/managersink/src/daudio_sink_dev.cpp index 5096b4bb..5a621858 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 c05403b3..5d172c50 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/test/unittest/managersink/BUILD.gn b/services/audiomanager/test/unittest/managersink/BUILD.gn index aa19c34c..641605c0 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 2a1bfd3e..2023f6ef 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. @@ -144,6 +156,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 +185,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 +239,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 +253,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,7 +298,7 @@ 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_); @@ -289,8 +326,8 @@ 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)); @@ -357,10 +394,19 @@ 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"; int32_t result = 0; + 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(AUDIO_START, devId, result); EXPECT_NE(DH_SUCCESS, sinkDev_->TaskRenderStateChange(args)); } @@ -412,5 +458,151 @@ 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_->isSpkInUse_.store(true); + sinkDev_->JudgeDeviceStatus(); + sinkDev_->isSpkInUse_.store(false); + sinkDev_->isMicInUse_.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); + auto eventParam = std::make_shared(audioEvent); + auto msg = AppExecFwk::InnerEvent::Get(static_cast(audioEvent.type), eventParam, 0); + 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 a1715fbc..b161adfa 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/audiotransport/receiverengine/BUILD.gn b/services/audiotransport/receiverengine/BUILD.gn index 6db639fb..e0b7772a 100644 --- a/services/audiotransport/receiverengine/BUILD.gn +++ b/services/audiotransport/receiverengine/BUILD.gn @@ -60,9 +60,7 @@ ohos_shared_library("distributed_audio_decode_transport") { "${services_path}/common/audiodata/src/audio_data.cpp", ] - deps = [ - "${services_path}/common:distributed_audio_utils", - ] + deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", 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 f4a3b631..781ef403 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 5c5d140e..54dd0494 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 486867b1..57b919a2 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 -- Gitee From 96b740ff7b180e69e9a3178eedaa2ade185d7e44 Mon Sep 17 00:00:00 2001 From: byndyx Date: Fri, 26 Jan 2024 11:09:55 +0800 Subject: [PATCH 02/17] modify bug Signed-off-by: byndyx --- services/hdfaudioclient/src/distributed_audio_client.cpp | 3 +++ services/hdfaudioclient/test/unittest/audio_manager_test.cpp | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/hdfaudioclient/src/distributed_audio_client.cpp b/services/hdfaudioclient/src/distributed_audio_client.cpp index 0bba46de..e4df6a37 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/audio_manager_test.cpp b/services/hdfaudioclient/test/unittest/audio_manager_test.cpp index 2cb3906c..4ce51c2f 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); -- Gitee From 2f4b52c86100c79fc0c975aca88eed9631de3ad0 Mon Sep 17 00:00:00 2001 From: byndyx Date: Tue, 30 Jan 2024 12:08:39 +0800 Subject: [PATCH 03/17] modify code Signed-off-by: byndyx --- audiohandler/src/daudio_handler.cpp | 10 ---------- .../test/unittest/include/daudio_handler_test.h | 2 +- audiohandler/test/unittest/src/daudio_handler_test.cpp | 2 +- 3 files changed, 2 insertions(+), 12 deletions(-) diff --git a/audiohandler/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index b12f08c7..36275a2e 100644 --- a/audiohandler/src/daudio_handler.cpp +++ b/audiohandler/src/daudio_handler.cpp @@ -99,16 +99,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); diff --git a/audiohandler/test/unittest/include/daudio_handler_test.h b/audiohandler/test/unittest/include/daudio_handler_test.h index fb2e0169..db960170 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 f9a7162f..04c547b3 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) {} -- Gitee From f8e3584e1b632f1dfa630be53f0ea0d2a803d923 Mon Sep 17 00:00:00 2001 From: w30042960 Date: Fri, 2 Feb 2024 17:42:22 +0800 Subject: [PATCH 04/17] delete syscap Signed-off-by: w30042960 --- bundle.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle.json b/bundle.json index 4d74f225..942a75ba 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" -- Gitee From 4055a5e208f1b831b62fc2ec61600dcd23f3b153 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Tue, 6 Feb 2024 11:21:46 +0800 Subject: [PATCH 05/17] add fuzz Signed-off-by: chen0088 --- .../native_cpp/test/fuzztest/BUILD.gn | 6 ++ .../BUILD.gn | 63 ++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...handlerpausedistributedhardware_fuzzer.cpp | 41 +++++++++++ ...nkhandlerpausedistributedhardware_fuzzer.h | 21 ++++++ .../BUILD.gn | 71 +++++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...handlerregisterprivacyresources_fuzzer.cpp | 41 +++++++++++ ...nkhandlerregisterprivacyresources_fuzzer.h | 21 ++++++ .../BUILD.gn | 63 ++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...andlerresumedistributedhardware_fuzzer.cpp | 41 +++++++++++ ...khandlerresumedistributedhardware_fuzzer.h | 21 ++++++ .../BUILD.gn | 63 ++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...khandlerstopdistributedhardware_fuzzer.cpp | 41 +++++++++++ ...inkhandlerstopdistributedhardware_fuzzer.h | 21 ++++++ .../BUILD.gn | 66 +++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...ipccallbackonnotifyresourceinfo_fuzzer.cpp | 55 ++++++++++++++ ...nkipccallbackonnotifyresourceinfo_fuzzer.h | 21 ++++++ .../BUILD.gn | 66 +++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ .../sinkipccallbackonremoterequest_fuzzer.cpp | 71 +++++++++++++++++++ .../sinkipccallbackonremoterequest_fuzzer.h | 21 ++++++ .../include/mock_component_resourceinfo.h | 43 +++++++++++ 32 files changed, 1103 insertions(+) create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/include/mock_component_resourceinfo.h diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 588e4a1a..50d01480 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 00000000..d56fa2b9 --- /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 00000000..6198079a --- /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 00000000..7133b2b9 --- /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 00000000..4506ec0d --- /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 00000000..62825e55 --- /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 00000000..7223f143 --- /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 00000000..6198079a --- /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 00000000..7133b2b9 --- /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 00000000..0da44199 --- /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 00000000..24bebe33 --- /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 00000000..399a6eba --- /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 00000000..6198079a --- /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 00000000..7133b2b9 --- /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 00000000..b5ff478a --- /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 00000000..aead1565 --- /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 00000000..34194f27 --- /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 00000000..6198079a --- /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 00000000..7133b2b9 --- /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 00000000..711d0432 --- /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 00000000..22d522a2 --- /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 00000000..2843357e --- /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 00000000..6198079a --- /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 00000000..7133b2b9 --- /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 00000000..b28186d7 --- /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 00000000..ee2f7003 --- /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 00000000..0002af03 --- /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 00000000..6198079a --- /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 00000000..7133b2b9 --- /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 00000000..99422366 --- /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 00000000..a00a5c2a --- /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 00000000..95fcd06c --- /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 -- Gitee From ba2ce60ac3e0d70b6242f228e38b96ba46ac4737 Mon Sep 17 00:00:00 2001 From: w30042960 Date: Wed, 7 Feb 2024 11:29:25 +0800 Subject: [PATCH 06/17] modify ut Signed-off-by: w30042960 --- .../audio_render_internal/audio_render_internal_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1a1665ff..1377ee4a 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); -- Gitee From 3c30dc4b8de4d023227c5308e657e32daabbd673 Mon Sep 17 00:00:00 2001 From: w30042960 Date: Wed, 7 Feb 2024 11:40:29 +0800 Subject: [PATCH 07/17] add UT Signed-off-by: w30042960 --- .../test/unittest/spkclient/src/dspeaker_client_test.cpp | 2 ++ .../test/unittest/sourcedevice/src/dmic_dev_test.cpp | 6 ++++++ 2 files changed, 8 insertions(+) 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 cfbd8d54..efd37f35 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/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp b/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp index bfe29a87..d68d6ea7 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)); -- Gitee From 7f8db13a5b1b3c5112fcd42a6bc318ff241922a7 Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Mon, 19 Feb 2024 15:00:13 +0800 Subject: [PATCH 08/17] Distributed_audio fix to support for independent compilation Signed-off-by: zhonglufu --- audiohandler/BUILD.gn | 5 - audiohandler/include/daudio_handler.h | 1 - audiohandler/include/ihardware_handler.h | 51 ++ audiohandler/src/daudio_handler.cpp | 1 - common/dfx_utils/include/daudio_hidumper.h | 8 - common/dfx_utils/src/daudio_hidumper.cpp | 17 - .../inner_kits/native_cpp/audio_sink/BUILD.gn | 1 - .../include/idistributed_hardware_sink.h | 55 ++ .../native_cpp/audio_source/BUILD.gn | 1 - .../include/idistributed_hardware_source.h | 59 +++ services/audiomanager/servicesink/BUILD.gn | 1 - services/audiomanager/servicesource/BUILD.gn | 7 +- .../audiotransport/receiverengine/BUILD.gn | 2 - services/audiotransport/senderengine/BUILD.gn | 2 - services/hdfaudioclient/BUILD.gn | 4 +- .../hdfaudioclient/include/audio_adapter.h | 270 ++++++++++ .../hdfaudioclient/include/audio_attribute.h | 167 ++++++ .../hdfaudioclient/include/audio_capture.h | 98 ++++ .../hdfaudioclient/include/audio_control.h | 131 +++++ .../hdfaudioclient/include/audio_manager.h | 111 ++++ .../hdfaudioclient/include/audio_render.h | 181 +++++++ services/hdfaudioclient/include/audio_scene.h | 86 ++++ services/hdfaudioclient/include/audio_types.h | 487 ++++++++++++++++++ .../hdfaudioclient/include/audio_volume.h | 137 +++++ services/test_example/BUILD.gn | 2 - services/test_example/daudio_errcode.h | 43 ++ 26 files changed, 1878 insertions(+), 50 deletions(-) create mode 100644 audiohandler/include/ihardware_handler.h create mode 100644 interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h create mode 100644 interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h create mode 100644 services/hdfaudioclient/include/audio_adapter.h create mode 100644 services/hdfaudioclient/include/audio_attribute.h create mode 100644 services/hdfaudioclient/include/audio_capture.h create mode 100644 services/hdfaudioclient/include/audio_control.h create mode 100644 services/hdfaudioclient/include/audio_manager.h create mode 100644 services/hdfaudioclient/include/audio_render.h create mode 100644 services/hdfaudioclient/include/audio_scene.h create mode 100644 services/hdfaudioclient/include/audio_types.h create mode 100644 services/hdfaudioclient/include/audio_volume.h create mode 100644 services/test_example/daudio_errcode.h diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index ef27e252..66a35b45 100644 --- a/audiohandler/BUILD.gn +++ b/audiohandler/BUILD.gn @@ -25,11 +25,6 @@ ohos_shared_library("distributed_audio_handler") { stack_protector_ret = true include_dirs = [ "//third_party/json/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include", - "${mediastandardfwk_path}/audiomanager/include", - "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiocapturer/include", ] include_dirs += [ diff --git a/audiohandler/include/daudio_handler.h b/audiohandler/include/daudio_handler.h index 4b79ea82..75123436 100644 --- a/audiohandler/include/daudio_handler.h +++ b/audiohandler/include/daudio_handler.h @@ -22,7 +22,6 @@ #include "single_instance.h" #include "audio_param.h" #include "audio_capturer.h" -#include "audio_info.h" namespace OHOS { namespace DistributedHardware { diff --git a/audiohandler/include/ihardware_handler.h b/audiohandler/include/ihardware_handler.h new file mode 100644 index 00000000..fa0f75e9 --- /dev/null +++ b/audiohandler/include/ihardware_handler.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021-2023 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_DISTRIBUTED_HARDWARE_IHARDWARE_HANDLER_H +#define OHOS_DISTRIBUTED_HARDWARE_IHARDWARE_HANDLER_H + +#include +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +const std::string COMPONENT_LOADER_GET_HARDWARE_HANDLER = "GetHardwareHandler"; +struct DHItem { + std::string dhId; + std::string attrs; + std::string subtype; +}; + +class PluginListener { +public: + virtual void PluginHardware(const std::string &dhId, const std::string &attrs, const std::string &subtype) = 0; + virtual void UnPluginHardware(const std::string &dhId) = 0; +}; + +class IHardwareHandler { +public: + virtual int32_t Initialize() = 0; + virtual std::vector Query() = 0; + virtual std::map QueryExtraInfo() = 0; + virtual bool IsSupportPlugin() = 0; + virtual void RegisterPluginListener(std::shared_ptr listener) = 0; + virtual void UnRegisterPluginListener() = 0; +}; +extern "C" __attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/audiohandler/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index 36275a2e..c6551f37 100644 --- a/audiohandler/src/daudio_handler.cpp +++ b/audiohandler/src/daudio_handler.cpp @@ -22,7 +22,6 @@ #include "nlohmann/json.hpp" #include "string_ex.h" -#include "histreamer_query_tool.h" #include "daudio_constants.h" #include "daudio_errorcode.h" #include "daudio_log.h" diff --git a/common/dfx_utils/include/daudio_hidumper.h b/common/dfx_utils/include/daudio_hidumper.h index aa1d6da9..667e33db 100644 --- a/common/dfx_utils/include/daudio_hidumper.h +++ b/common/dfx_utils/include/daudio_hidumper.h @@ -20,11 +20,6 @@ #include #include "sys/stat.h" -#include "audio_capturer.h" -#include "audio_info.h" - -#include "audio_adapter.h" -#include "audio_manager.h" #include "daudio_handler.h" #include "single_instance.h" @@ -60,10 +55,7 @@ private: int32_t StopDumpData(std::string &result); private: - AudioManager *audioManager_ = nullptr; - AudioAdapterDescriptor *adapterdesc_ = nullptr; bool dumpAudioDataFlag_ = false; - int32_t g_deviceNum = 0; const std::string DEFAULT_SPK_DHID = "1"; const std::string DEFAULT_MIC_DHID = "134217729"; }; diff --git a/common/dfx_utils/src/daudio_hidumper.cpp b/common/dfx_utils/src/daudio_hidumper.cpp index d33ddbe8..44376fb9 100644 --- a/common/dfx_utils/src/daudio_hidumper.cpp +++ b/common/dfx_utils/src/daudio_hidumper.cpp @@ -128,23 +128,6 @@ int32_t DaudioHidumper::GetSourceDevId(std::string &result) int32_t DaudioHidumper::GetSinkInfo(std::string &result) { DHLOGI("Get sink info dump."); - audioManager_ = GetAudioManagerFuncs(); - if (audioManager_ == nullptr) { - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = audioManager_->GetAllAdapters(audioManager_, &adapterdesc_, &g_deviceNum); - if (ret != DH_SUCCESS) { - DHLOGE("Get all adapters failed."); - return ERR_DH_AUDIO_NULLPTR; - } - for (int32_t index = 0; index < g_deviceNum; index++) { - AudioAdapterDescriptor &desc = adapterdesc_[index]; - result.append("sinkDevId: ").append(GetAnonyString(desc.adapterName)).append(" portId: "); - for (uint32_t i = 0; i < desc.portNum; i++) { - result.append(std::to_string(desc.ports[i].portId)).append(" "); - } - } - return DH_SUCCESS; } diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 2a10e58d..0d7ab1c9 100755 --- a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn @@ -27,7 +27,6 @@ ohos_shared_library("distributed_audio_sink_sdk") { } stack_protector_ret = true include_dirs = [ - "${fwk_common_path}/utils/include", "//third_party/json/include", ] diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h b/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h new file mode 100644 index 00000000..70515851 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2023 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_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SINK_H +#define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SINK_H + +#include + +namespace OHOS { +namespace DistributedHardware { +const std::string COMPONENT_LOADER_GET_SINK_HANDLER = "GetSinkHardwareHandler"; +enum class ResourceEventType : int32_t { + EVENT_TYPE_QUERY_RESOURCE = 0, + EVENT_TYPE_PULL_UP_PAGE = 1, + EVENT_TYPE_CLOSE_PAGE = 2 +}; + +class SubscribeCallback { +public: + virtual int32_t OnSubscribeCallback(const std::string &dhId, int32_t status, const std::string &data) = 0; +}; + +class PrivacyResourcesListener { +public: + virtual int32_t OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) = 0; +}; + +class IDistributedHardwareSink { +public: + virtual int32_t InitSink(const std::string ¶ms) = 0; + virtual int32_t ReleaseSink() = 0; + virtual int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶ms) = 0; + virtual int32_t UnsubscribeLocalHardware(const std::string &dhId) = 0; + virtual int32_t RegisterPrivacyResources(std::shared_ptr listener) = 0; + virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; + virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; + virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; +}; +extern "C" __attribute__((visibility("default"))) IDistributedHardwareSink* GetSinkHardwareHandler(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn index feacb89b..64bf5603 100755 --- a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn @@ -27,7 +27,6 @@ ohos_shared_library("distributed_audio_source_sdk") { } stack_protector_ret = true include_dirs = [ - "${fwk_common_path}/utils/include", "//third_party/json/include", ] diff --git a/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h b/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h new file mode 100644 index 00000000..3517bb3e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021-2023 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_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H +#define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H + +#include +#include + +namespace OHOS { +namespace DistributedHardware { +const std::string COMPONENT_LOADER_GET_SOURCE_HANDLER = "GetSourceHardwareHandler"; +class RegisterCallback { +public: + virtual int32_t OnRegisterResult(const std::string &uuid, const std::string &dhId, int32_t status, + const std::string &data) = 0; +}; + +class UnregisterCallback { +public: + virtual int32_t OnUnregisterResult(const std::string &uuid, const std::string &dhId, int32_t status, + const std::string &data) = 0; +}; + +struct EnableParam { + std::string sourceVersion; + std::string sourceAttrs; + std::string sinkVersion; + std::string sinkAttrs; + std::string subtype; +}; + +class IDistributedHardwareSource { +public: + virtual int32_t InitSource(const std::string ¶ms) = 0; + virtual int32_t ReleaseSource() = 0; + virtual int32_t RegisterDistributedHardware(const std::string &uuid, const std::string &dhId, + const EnableParam ¶m, std::shared_ptr callback) = 0; + virtual int32_t UnregisterDistributedHardware(const std::string &uuid, const std::string &dhId, + std::shared_ptr callback) = 0; + virtual int32_t ConfigDistributedHardware(const std::string &uuid, const std::string &dhId, const std::string &key, + const std::string &value) = 0; +}; +extern "C" __attribute__((visibility("default"))) IDistributedHardwareSource* GetSourceHardwareHandler(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 02241542..842a8575 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -29,7 +29,6 @@ ohos_shared_library("distributed_audio_sink") { include_dirs = [ "//third_party/json/include", "//third_party/cJSON", - "${fwk_common_path}/utils/include", ] include_dirs += [ diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index c7d2fb51..caf33f13 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -29,11 +29,6 @@ ohos_shared_library("distributed_audio_source") { include_dirs = [ "//third_party/json/include", "//third_party/cJSON", - "${driver_audio_path}/include", - "${fwk_common_path}/utils/include", - "${mediastandardfwk_path}/audiocapturer/include", - "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiomanager/include", ] include_dirs += [ @@ -49,7 +44,6 @@ ohos_shared_library("distributed_audio_source") { "${common_path}/dfx_utils/include", "${common_path}/include", "${distributedaudio_path}/audiohandler/include", - "${hdf_service_path}/hdi_service/common/include", "${innerkits_path}/native_cpp/audio_sink/include", "${innerkits_path}/native_cpp/audio_source/include", "${interfaces_path}/inner_kits/native_cpp/audio_sink/include", @@ -92,6 +86,7 @@ ohos_shared_library("distributed_audio_source") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "audio_framework:audio_capturer", "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", diff --git a/services/audiotransport/receiverengine/BUILD.gn b/services/audiotransport/receiverengine/BUILD.gn index 98cc9aa9..53065ab2 100644 --- a/services/audiotransport/receiverengine/BUILD.gn +++ b/services/audiotransport/receiverengine/BUILD.gn @@ -34,8 +34,6 @@ ohos_shared_library("distributed_audio_decode_transport") { } stack_protector_ret = true include_dirs = [ - "${mediastandard_path}/interfaces/innerkits/native/media/include", - "${mediastandardfwk_path}/audiocommon/include", "//third_party/json/include", ] diff --git a/services/audiotransport/senderengine/BUILD.gn b/services/audiotransport/senderengine/BUILD.gn index 6e18f37a..f5c714ba 100644 --- a/services/audiotransport/senderengine/BUILD.gn +++ b/services/audiotransport/senderengine/BUILD.gn @@ -34,8 +34,6 @@ ohos_shared_library("distributed_audio_encode_transport") { } stack_protector_ret = true include_dirs = [ - "${mediastandard_path}/interfaces/innerkits/native/media/include", - "${mediastandardfwk_path}/audiocommon/include", "//third_party/json/include", ] diff --git a/services/hdfaudioclient/BUILD.gn b/services/hdfaudioclient/BUILD.gn index f702e01b..a29eb55d 100644 --- a/services/hdfaudioclient/BUILD.gn +++ b/services/hdfaudioclient/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") import("../../distributedaudio.gni") ohos_shared_library("daudio_client") { @@ -29,7 +28,6 @@ ohos_shared_library("daudio_client") { include_dirs = [ "./include", "${common_path}/include", - "${driver_audio_path}/include", ] sources = [ @@ -41,7 +39,7 @@ ohos_shared_library("daudio_client") { "./src/distributed_audio_client.cpp", ] - public_deps = [ "${services_path}/common:distributed_audio_utils" ] + deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", diff --git a/services/hdfaudioclient/include/audio_adapter.h b/services/hdfaudioclient/include/audio_adapter.h new file mode 100644 index 00000000..e818ec26 --- /dev/null +++ b/services/hdfaudioclient/include/audio_adapter.h @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_adapter.h + * + * @brief Declares APIs for operations related to the audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_ADAPTER_H +#define AUDIO_ADAPTER_H + +#include "audio_types.h" +#include "audio_render.h" +#include "audio_capture.h" + +/** + * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, + * and obtaining the port capability set. + * + * @see AudioRender + * @see AudioCapture + * @since 1.0 + * @version 1.0 + */ +struct AudioAdapter { + /** + * @brief Initializes all ports of an audio adapter. + * + * Call this function before calling other driver functions to check whether the initialization is complete. + * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again + * until the port initialization is complete. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @return Returns 0 if the initialization is successful; returns a negative value otherwise. + */ + int32_t (*InitAllPorts)(struct AudioAdapter *adapter); + + /** + * @brief Creates an AudioRender object. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter to start. + * @param attrs Indicates the pointer to the audio sampling attributes to open. + * @param render Indicates the double pointer to the AudioRender object. + * @return Returns 0 if the AudioRender object is created successfully; + * returns a negative value otherwise. + * @see GetPortCapability + * @see DestroyRender + */ + int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, + const struct AudioSampleAttributes *attrs, struct AudioRender **render); + + /** + * @brief Destroys an AudioRender object. + * + * @attention Do not destroy the object during audio rendering. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param render Indicates the pointer to the AudioRender object to operate. + * @return Returns 0 if the AudioRender object is destroyed; returns a negative value otherwise. + * @see CreateRender + */ + int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render); + + /** + * @brief Creates an AudioCapture object. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter to start. + * @param attrs Indicates the pointer to the audio sampling attributes to open. + * @param capture Indicates the double pointer to the AudioCapture object. + * @return Returns 0 if the AudioCapture object is created successfully; + * returns a negative value otherwise. + * @see GetPortCapability + * @see DestroyCapture + */ + int32_t (*CreateCapture)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, + const struct AudioSampleAttributes *attrs, struct AudioCapture **capture); + + /** + * @brief Destroys an AudioCapture object. + * + * @attention Do not destroy the object during audio capturing. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param capture Indicates the pointer to the AudioCapture object to operate. + * @return Returns 0 if the AudioCapture object is destroyed; returns a negative value otherwise. + * @see CreateCapture + */ + int32_t (*DestroyCapture)(struct AudioAdapter *adapter, struct AudioCapture *capture); + + /** + * @brief Obtains the capability set of the port driver for the audio adapter. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param capability Indicates the pointer to the capability set to obtain. + * @return Returns 0 if the capability set is successfully obtained; returns a negative value otherwise. + */ + int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, + struct AudioPortCapability *capability); + + /** + * @brief Sets the passthrough data transmission mode of the audio port driver. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param mode Indicates the passthrough transmission mode to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetPassthroughMode + */ + int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, + enum AudioPortPassthroughMode mode); + + /** + * @brief Obtains the passthrough data transmission mode of the audio port driver. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param mode Indicates the pointer to the passthrough transmission mode to obtain. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetPassthroughMode + */ + int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, + enum AudioPortPassthroughMode *mode); + + /** + * @brief Update audio route on several source and sink ports. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param route Indicates route information. + * @param routeHandle Indicates route handle. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetPassthroughMode + */ + int32_t (*UpdateAudioRoute)(struct AudioAdapter *adapter, const struct AudioRoute *route, int32_t *routeHandle); + + /** + * @brief Release an audio route. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param routeHandle Indicates route handle. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetPassthroughMode + */ + int32_t (*ReleaseAudioRoute)(struct AudioAdapter *adapter, int32_t routeHandle); + + /** + * @brief Sets the mute operation for the audio. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param mute Specifies whether to mute the audio. Value true means to mute the audio, + * and false means the opposite. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetMute + */ + int32_t (*SetMicMute)(struct AudioAdapter *adapter, bool mute); + + /** + * @brief Obtains the mute operation set for the audio. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that + * the audio is muted, and false means the opposite. + * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. + * @see SetMute + */ + int32_t (*GetMicMute)(struct AudioAdapter *adapter, bool *mute); + + /** + * @brief Sets the audio volume for voice call. + * + * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, + * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetVolume + */ + int32_t (*SetVoiceVolume)(struct AudioAdapter *adapter, float volume); + + /** + * @brief Sets extra audio parameters. + * + * @param adapter Indicates the audio adapter. + * @param key Indicates what kind of parameter type will be set. + * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. + * @param value Indicates the value of the specified condition. + * + * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). + * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: + * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" + * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4; + * VOLUME_GROUP_ID indicates which volume group will be set; + * AUDIO_VOLUME_TYPE indicates which volume type will be set; + * + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*SetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, + const char *condition, const char *value); + + /** + * @brief Get extra audio parameters. + * + * @param adapter Indicates the audio adapter. + * @param key Indicates what kind of parameter type will be get. + * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. + * @param value Indicates the value of the specified condition. + * @param lenth Indicates the length of the value pointer. + * + * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). + * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: + * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" + * EVENT_TYPE indicates sub volume event type: GetVolume = 1; GetMinVolume = 2; GetMaxVolume = 3; IsStreamMute = 4; + * VOLUME_GROUP_ID indicates which volume group want get; + * AUDIO_VOLUME_TYPE indicates which volume type want get; + * + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, + const char *condition, char *value, int32_t lenth); + + /** + * @brief Register extra audio parameters observer. + * + * @param adapter Indicates the audio adapter. + * @param callback Indicates param observer. + * @param cookie Indicates the pointer to the callback parameters; + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*RegExtraParamObserver)(struct AudioAdapter *adapter, ParamCallback callback, void* cookie); + /** + * @brief Get the device status of an adapter. + * + * @param adapter Indicates the audio adapter. + * @param status Indicates the status of device . + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetDeviceStatus)(struct AudioAdapter *adapter, struct AudioDeviceStatus *status); +}; +#endif /* AUDIO_ADAPTER_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_attribute.h b/services/hdfaudioclient/include/audio_attribute.h new file mode 100644 index 00000000..bd93c7c9 --- /dev/null +++ b/services/hdfaudioclient/include/audio_attribute.h @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_attribute.h + * + * @brief Declares APIs for audio attributes. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_ATTRIBUTE_H +#define AUDIO_ATTRIBUTE_H + +#include "audio_types.h" + +/** + * @brief Provides attribute-related APIs for audio rendering or capturing, including functions to + * obtain frame information and set audio sampling attributes. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioAttribute { + /** + * @brief Obtains the audio frame size, that is, the length (in bytes) of a frame. + * + * @param handle Indicates the audio handle. + * @param size Indicates the pointer to the audio frame size (in bytes). + * @return Returns 0 if the audio frame size is obtained; returns a negative value otherwise. + */ + int32_t (*GetFrameSize)(AudioHandle handle, uint64_t *size); + + /** + * @brief Obtains the number of audio frames in the audio buffer. + * + * @param handle Indicates the audio handle. + * @param count Indicates the pointer to the number of audio frames in the audio buffer. + * @return Returns 0 if the number of audio frames is obtained; returns a negative value otherwise. + */ + int32_t (*GetFrameCount)(AudioHandle handle, uint64_t *count); + + /** + * @brief Sets audio sampling attributes. + * + * @param handle Indicates the audio handle. + * @param attrs Indicates the pointer to the audio sampling attributes to set, such as the sampling rate, + * sampling precision, and channel. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetSampleAttributes + */ + int32_t (*SetSampleAttributes)(AudioHandle handle, const struct AudioSampleAttributes *attrs); + + /** + * @brief Obtains audio sampling attributes. + * + * @param handle Indicates the audio handle. + * @param attrs Indicates the pointer to the audio sampling attributes, such as the sampling rate, + * sampling precision, and channel. + * @return Returns 0 if audio sampling attributes are obtained; returns a negative value otherwise. + * @see SetSampleAttributes + */ + int32_t (*GetSampleAttributes)(AudioHandle handle, struct AudioSampleAttributes *attrs); + + /** + * @brief Obtains the data channel ID of the audio. + * + * @param handle Indicates the audio handle. + * @param channelId Indicates the pointer to the data channel ID. + * @return Returns 0 if the data channel ID is obtained; returns a negative value otherwise. + */ + int32_t (*GetCurrentChannelId)(AudioHandle handle, uint32_t *channelId); + + /** + * @brief Sets extra audio parameters. + * + * @param handle Indicates the audio handle. + * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. + * The format is key=value. Separate multiple key-value pairs by semicolons (;). + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*SetExtraParams)(AudioHandle handle, const char *keyValueList); + + /** + * @brief Obtains extra audio parameters. + * + * @param handle Indicates the audio handle. + * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. + * The format is key=value. Separate multiple key-value pairs by semicolons (;). + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetExtraParams)(AudioHandle handle, char *keyValueList, int32_t listLenth); + + /** + * @brief Requests a mmap buffer. + * + * @param handle Indicates the audio handle. + * @param reqSize Indicates the size of the request mmap buffer. + * @param desc Indicates the pointer to the mmap buffer descriptor. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*ReqMmapBuffer)(AudioHandle handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc); + + /** + * @brief Obtains the read/write position of the current mmap buffer. + * + * @param handle Indicates the audio handle. + * @param frames Indicates the pointer to the frame where the read/write starts. + * @param time Indicates the pointer to the timestamp associated with the frame where the read/write starts. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetMmapPosition)(AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time); + + /** + * @brief Add the audio effect which the effectid indicated. + * + * @param handle Indicates the audio handle. + * @param effectid Indicates the audio effect instance identifier which is going to be added. + * @return Returns 0 if the audio effect were added succesffully; returns a negative value otherwise. + */ + int32_t (*AddAudioEffect)(AudioHandle handle, uint64_t effectid); + + /** + * @brief Remove the audio effect which the effectid indicated. + * + * @param handle Indicates the audio handle. + * @param effectid Indicates the audio effect which is going to be removed. + * @return Returns 0 if the audio effect were removed succesffully; returns a negative value otherwise. + */ + int32_t (*RemoveAudioEffect)(AudioHandle handle, uint64_t effectid); + + /** + * @brief Get the buffer size of render or capturer + * + * @param handle Indicates the audio handle. + * @param bufferSize Indicates the buffer size (in bytes) queried from the vendor + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetFrameBufferSize)(AudioHandle handle, uint64_t *bufferSize); +}; + +#endif /* AUDIO_ATTRIBUTE_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_capture.h b/services/hdfaudioclient/include/audio_capture.h new file mode 100644 index 00000000..a45e2471 --- /dev/null +++ b/services/hdfaudioclient/include/audio_capture.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_capture.h + * + * @brief Declares APIs for audio capturing. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_CAPTURE_H +#define AUDIO_CAPTURE_H + +#include "audio_types.h" +#include "audio_control.h" +#include "audio_attribute.h" +#include "audio_scene.h" +#include "audio_volume.h" + +/** + * @brief Provides capabilities for audio capturing, including controlling the capturing, setting audio attributes, + * scenes, and volume, and capturing audio frames. + * + * @see AudioControl + * @see AudioAttribute + * @see AudioScene + * @see AudioVolume + * @since 1.0 + * @version 1.0 + */ +struct AudioCapture { + /** + * @brief Defines the audio control. For details, see {@link AudioControl}. + */ + struct AudioControl control; + /** + * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. + */ + struct AudioAttribute attr; + /** + * @brief Defines the audio scene. For details, see {@link AudioScene}. + */ + struct AudioScene scene; + /** + * @brief Defines audio volume. For details, see {@link AudioVolume}. + */ + struct AudioVolume volume; + + /** + * @brief Reads a frame of input data (uplink data) from the audio driver for capturing. + * + * @param capture Indicates the pointer to the AudioCapture object to operate. + * @param frame Indicates the pointer to the input data to read. + * @param requestBytes Indicates the size of the input data, in bytes. + * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to read. + * @return Returns 0 if the input data is read successfully; returns a negative value otherwise. + */ + int32_t (*CaptureFrame)(struct AudioCapture *capture, void *frame, uint64_t requestBytes, uint64_t *replyBytes); + + /** + * @brief Obtains the last number of input audio frames. + * + * @param capture Indicates the pointer to the AudioCapture object to operate. + * @param frames Indicates the pointer to the last number of input audio frames. + * @param time Indicates the pointer to the timestamp associated with the frame. + * @return Returns 0 if the last number is obtained; returns a negative value otherwise. + * @see CaptureFrame + */ + int32_t (*GetCapturePosition)(struct AudioCapture *capture, uint64_t *frames, struct AudioTimeStamp *time); +}; + +#endif /* AUDIO_CAPTURE_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_control.h b/services/hdfaudioclient/include/audio_control.h new file mode 100644 index 00000000..536f8fe0 --- /dev/null +++ b/services/hdfaudioclient/include/audio_control.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_control.h + * + * @brief Declares APIs for audio control. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_CONTROL_H +#define AUDIO_CONTROL_H + +#include "audio_types.h" + +/** + * @brief Provides control-related APIs for audio rendering or capturing, including functions to + * start, stop, pause, and resume audio rendering or capturing, and flush data in the audio buffer. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioControl { + /** + * @brief Starts audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully started; + * returns a negative value otherwise. + * @see Stop + */ + int32_t (*Start)(AudioHandle handle); + + /** + * @brief Stops audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully stopped; + * returns a negative value otherwise. + * @see Start + */ + int32_t (*Stop)(AudioHandle handle); + + /** + * @brief Pauses audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully paused; + * returns a negative value otherwise. + * @see Resume + */ + int32_t (*Pause)(AudioHandle handle); + + /** + * @brief Resumes audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully resumed; + * returns a negative value otherwise. + * @see Pause + */ + int32_t (*Resume)(AudioHandle handle); + + /** + * @brief Flushes data in the audio buffer. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the flush is successful; returns a negative value otherwise. + */ + int32_t (*Flush)(AudioHandle handle); + + /** + * @brief Sets or cancels the standby mode of the audio device. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the device is set to standby mode; returns a positive value if the standby mode is + * canceled; returns a negative value if the setting fails. + */ + int32_t (*TurnStandbyMode)(AudioHandle handle); + + /** + * @brief Dumps information about the audio device. + * + * @param handle Indicates the audio handle. + * @param range Indicates the range of the device information to dump, which can be brief or full information. + * @param fd Indicates the file to which the device information will be dumped. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*AudioDevDump)(AudioHandle handle, int32_t range, int32_t fd); + + /** + * @brief Query whether the vendor support pause and resume. + * + * @param handle Indicates the audio handle. + * @param supportPause Indicates the state whether the vendor supports pausing. Value true means that + * the vendor supports, and false means the opposite. + * @param supportResume Indicates the state whether the vendor supports resuming. Value true means that + * the vendor supports, and false means the opposite. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see IsSupportsPauseAndResume + */ + int32_t (*IsSupportsPauseAndResume)(AudioHandle handle, bool *supportPause, bool *supportResume); +}; + +#endif /* AUDIO_CONTROL_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_manager.h b/services/hdfaudioclient/include/audio_manager.h new file mode 100644 index 00000000..fcaa4ddd --- /dev/null +++ b/services/hdfaudioclient/include/audio_manager.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_manager.h + * + * @brief Declares APIs for audio adapter management and loading. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_MANAGER_H +#define AUDIO_MANAGER_H + +#include "audio_types.h" +#include "audio_adapter.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Manages audio adapters through a specific adapter driver program loaded based on the given audio + * adapter descriptor. + * + * @see AudioAdapter + * @since 1.0 + * @version 1.0 + */ +struct AudioManager { + /** + * @brief Obtains the list of all adapters supported by an audio driver. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param descs Indicates the double pointer to the audio adapter list. + * @param size Indicates the pointer to the length of the list. + * @return Returns 0 if the list is obtained successfully; returns a negative value otherwise. + * @see LoadAdapter + */ + int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size); + + /** + * @brief Loads the driver for an audio adapter. + * + * For example, to load a USB driver, you may need to load a dynamic-link library (*.so) in specific implementation. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter. + * @param adapter Indicates the double pointer to the audio adapter. + * @return Returns 0 if the driver is loaded successfully; returns a negative value otherwise. + * @see GetAllAdapters + * @see UnloadAdapter + */ + int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc, + struct AudioAdapter **adapter); + + /** + * @brief Unloads the driver of an audio adapter. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param adapter Indicates the pointer to the audio adapter whose driver will be unloaded. + * @see LoadAdapter + */ + void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter); + + /** + * @brief Release the AudioManager Object. + * + * @param object Indicates the pointer to the audio adapter manager to operate. + * @return Returns true if the Object is released; returns false otherwise. + */ + bool (*ReleaseAudioManagerObject)(struct AudioManager *object); +}; + +/** + * @brief Obtains the operation function list of the {@link AudioManager} class. + * + * @return Returns the pointer to the AudioManager object if the list is obtained; returns NULL otherwise. + */ +struct AudioManager *GetAudioManagerFuncs(void); + +#ifdef __cplusplus +} +#endif + +#endif /* AUDIO_MANAGER_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_render.h b/services/hdfaudioclient/include/audio_render.h new file mode 100644 index 00000000..3803075a --- /dev/null +++ b/services/hdfaudioclient/include/audio_render.h @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_render.h + * + * @brief Declares APIs for audio rendering. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_RENDER_H +#define AUDIO_RENDER_H + +#include "audio_types.h" +#include "audio_control.h" +#include "audio_attribute.h" +#include "audio_scene.h" +#include "audio_volume.h" + +/** + * @brief Provides capabilities for audio rendering, including controlling the rendering, setting audio attributes, + * scenes, and volume, obtaining hardware latency, and rendering audio frames. + * + * @see AudioControl + * @see AudioAttribute + * @see AudioScene + * @see AudioVolume + * @since 1.0 + * @version 1.0 + */ +struct AudioRender { + /** + * @brief Defines the audio control. For details, see {@link AudioControl}. + */ + struct AudioControl control; + /** + * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. + */ + struct AudioAttribute attr; + /** + * @brief Defines the audio scene. For details, see {@link AudioScene}. + */ + struct AudioScene scene; + /** + * @brief Defines audio volume. For details, see {@link AudioVolume}. + */ + struct AudioVolume volume; + + /** + * @brief Obtains the estimated latency of the audio device driver. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param ms Indicates the pointer to the latency (in milliseconds) to be obtained. + * @return Returns 0 if the latency is obtained; returns a negative value otherwise. + */ + int32_t (*GetLatency)(struct AudioRender *render, uint32_t *ms); + + /** + * @brief Writes a frame of output data (downlink data) into the audio driver for rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param frame Indicates the pointer to the frame to write. + * @param requestBytes Indicates the size of the frame, in bytes. + * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to write. + * @return Returns 0 if the data is written successfully; returns a negative value otherwise. + */ + int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes); + + /** + * @brief Obtains the last number of output audio frames. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param frames Indicates the pointer to the last number of output audio frames. + * @param time Indicates the pointer to the timestamp associated with the frame. + * @return Returns 0 if the last number is obtained; returns a negative value otherwise. + * @see RenderFrame + */ + int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time); + + /** + * @brief Sets the audio rendering speed. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param speed Indicates the rendering speed to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetRenderSpeed + */ + int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed); + + /** + * @brief Obtains the current audio rendering speed. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param speed Indicates the pointer to the current rendering speed to obtain. + * @return Returns 0 if the speed is successfully obtained; returns a negative value otherwise. + * @see SetRenderSpeed + */ + int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed); + + /** + * @brief Sets the channel mode for audio rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param mode Indicates the channel mode to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetChannelMode + */ + int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode); + + /** + * @brief Obtains the current channel mode for audio rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param mode Indicates the pointer to the channel mode to obtain. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetChannelMode + */ + int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode); + + /** + * @brief Registers an audio callback that will be invoked during playback when buffer data writing or + * buffer drain is complete. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param callback Indicates the callback to register. + * @param cookie Indicates the pointer to the callback parameters. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see RegCallback + */ + int32_t (*RegCallback)(struct AudioRender *render, RenderCallback callback, void* cookie); + + /** + * @brief Drains the buffer. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param type Indicates the pointer to the execution type of this function. For details, + * see {@link AudioDrainNotifyType}. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see RegCallback + */ + int32_t (*DrainBuffer)(struct AudioRender *render, enum AudioDrainNotifyType *type); + + /** + * @brief query whether the vendor supports draining buffer + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param support indicates the state whether the vendor supports draining buffer. Value true means that + * the vendor supports, and false means the opposite. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see IsSupportsDrain + */ + int32_t (*IsSupportsDrain)(struct AudioRender *render, bool *support); +}; + +#endif /* AUDIO_RENDER_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_scene.h b/services/hdfaudioclient/include/audio_scene.h new file mode 100644 index 00000000..73d397f8 --- /dev/null +++ b/services/hdfaudioclient/include/audio_scene.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_scene.h + * + * @brief Declares APIs for audio scenes. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_SCENE_H +#define AUDIO_SCENE_H + +#include "audio_types.h" + +/** + * @brief Provides scene-related APIs for audio rendering or capturing, including functions to + * select an audio scene and check whether the configuration of an audio scene is supported. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioScene { + /** + * @brief Checks whether the configuration of an audio scene is supported. + * + * @param handle Indicates the audio handle. + * @param scene Indicates the pointer to the descriptor of the audio scene. + * @param supported Indicates the pointer to the variable specifying whether the configuration is supported. + * Value true means that the configuration is supported, and false means the opposite. + * @return Returns 0 if the result is obtained; returns a negative value otherwise. + * @see SelectScene + */ + int32_t (*CheckSceneCapability)(AudioHandle handle, const struct AudioSceneDescriptor *scene, bool *supported); + + /** + * @brief Selects an audio scene. + * + *
    + *
  • To select a specific audio scene, you need to specify both the application scenario and output device. + * For example, to select a scene using a smartphone speaker as the output device, set scene according + * to the scenarios where the speaker is used. For example:
  • + *
      + *
    • For media playback, set the value to media_speaker.
    • + *
    • For a voice call, set the value to voice_speaker.
    • + *
    + *
  • To select only the application scenario, such as media playback, movie, or gaming, you can set + * scene to media, movie, or game, respectively.
  • + *
  • To select only the output device, such as media receiver, speaker, or headset, you can set + * scene to receiver, speaker, or headset, respectively.
  • + *
+ * @param handle Indicates the audio handle. + * @param scene Indicates the pointer to the descriptor of the audio scene to select. + * @return Returns 0 if the scene is selected successfully; returns a negative value otherwise. + * @see CheckSceneCapability + */ + int32_t (*SelectScene)(AudioHandle handle, const struct AudioSceneDescriptor *scene); +}; + +#endif /* AUDIO_SCENE_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_types.h b/services/hdfaudioclient/include/audio_types.h new file mode 100644 index 00000000..7f3b84ca --- /dev/null +++ b/services/hdfaudioclient/include/audio_types.h @@ -0,0 +1,487 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_types.h + * + * @brief Defines custom data types used in API declarations for the audio module, including audio ports, + * adapter descriptors, device descriptors, scene descriptors, sampling attributes, and timestamp. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_TYPES_H +#define AUDIO_TYPES_H + +#include +#include + +/** + * @brief Defines the audio handle. + */ +typedef void *AudioHandle; + +/** + * @brief Enumerates the audio port type. + */ +enum AudioPortDirection { + PORT_OUT = 0x1u, /**< Output port */ + PORT_IN = 0x2u, /**< Input port */ + PORT_OUT_IN = 0x3u, /**< Input/output port, supporting both audio input and output */ +}; + +/** + * @brief Defines the audio port. + */ +struct AudioPort { + enum AudioPortDirection dir; /**< Audio port type. For details, see {@link AudioPortDirection} */ + uint32_t portId; /**< Audio port ID */ + const char *portName; /**< Audio port name */ +}; + +/** + * @brief Defines the audio adapter descriptor. + * + * An audio adapter is a set of port drivers for a sound card, including the output and input ports. + * One port corresponds to multiple pins, and each pin belongs to a physical component (such as a + * speaker or a wired headset). + */ +struct AudioAdapterDescriptor { + const char *adapterName; /**< Name of the audio adapter */ + uint32_t portNum; /**< Number of ports supported by an audio adapter */ + struct AudioPort *ports; /**< List of ports supported by an audio adapter */ +}; + +/** + * @brief Enumerates the pin of an audio adapter. + */ +enum AudioPortPin { + PIN_NONE = 0x0u, /**< Invalid pin */ + PIN_OUT_SPEAKER = 0x1u, /**< Speaker output pin */ + PIN_OUT_HEADSET = 0x2u, /**< Wired headset pin for output */ + PIN_OUT_LINEOUT = 0x4u, /**< Line-out pin */ + PIN_OUT_HDMI = 0x8u, /**< HDMI output pin */ + PIN_OUT_USB = 0x10u, /**< USB output pin */ + PIN_OUT_USB_EXT = 0x20u, /**< Extended USB output pin*/ + PIN_OUT_EARPIECE = 0x30u, /**< Earpiece output pin */ + PIN_OUT_BLUETOOTH_SCO = 0x40u, /**< Bluetooth SCO output pin */ + PIN_OUT_DAUDIO_DEFAULT = 0x80u, + PIN_OUT_HEADPHONE = 0x100u, /**< Wired headphone output pin*/ + PIN_OUT_USB_HEADSET = 0x200u, /**< ARM USB out pin */ + PIN_IN_MIC = 0x8000001u, /**< Microphone input pin */ + PIN_IN_HS_MIC = 0x8000002u, /**< Wired headset microphone pin for input */ + PIN_IN_LINEIN = 0x8000004u, /**< Line-in pin */ + PIN_IN_USB_EXT = 0x8000008u, /**< Extended USB input pin*/ + PIN_IN_BLUETOOTH_SCO_HEADSET = 0x8000010u, /**< Bluetooth SCO headset input pin */ + PIN_IN_USB_HEADSET = 0x8000040u, /**< ARM USB input pin */ +}; + +/** + * @brief Defines the audio device descriptor. + */ +struct AudioDeviceDescriptor { + uint32_t portId; /**< Audio port ID */ + enum AudioPortPin pins; /**< Pins of audio ports (input and output). For details, see {@link AudioPortPin}. */ + const char *desc; /**< Audio device name */ +}; + +/** + * @brief Enumerates the audio category. + */ +enum AudioCategory { + AUDIO_IN_MEDIA = 0, /**< Media */ + AUDIO_IN_COMMUNICATION, /**< Communications */ + AUDIO_IN_RINGTONE, /**< Ringtone */ + AUDIO_IN_CALL, /**< Call */ + AUDIO_MMAP_NOIRQ, /**< Mmap mode */ +}; + +/** + * @brief Defines the audio scene descriptor. + */ +struct AudioSceneDescriptor { + /** + * @brief Describes the audio scene. + */ + union SceneDesc { + uint32_t id; /**< Audio scene ID */ + const char *desc; /**< Name of the audio scene */ + } scene; /**< The scene object */ + struct AudioDeviceDescriptor desc; /**< Audio device descriptor */ +}; + +/** + * @brief Enumerates the audio format. + */ +enum AudioFormat { + AUDIO_FORMAT_TYPE_PCM_8_BIT = 0x1u, /**< 8-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_16_BIT = 0x2u, /**< 16-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_24_BIT = 0x3u, /**< 24-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_32_BIT = 0x4u, /**< 32-bit PCM */ + AUDIO_FORMAT_TYPE_AAC_MAIN = 0x1000001u, /**< AAC main */ + AUDIO_FORMAT_TYPE_AAC_LC = 0x1000002u, /**< AAC LC */ + AUDIO_FORMAT_TYPE_AAC_LD = 0x1000003u, /**< AAC LD */ + AUDIO_FORMAT_TYPE_AAC_ELD = 0x1000004u, /**< AAC ELD */ + AUDIO_FORMAT_TYPE_AAC_HE_V1 = 0x1000005u, /**< AAC HE_V1 */ + AUDIO_FORMAT_TYPE_AAC_HE_V2 = 0x1000006u, /**< AAC HE_V2 */ + AUDIO_FORMAT_TYPE_G711A = 0x2000001u, /**< G711A */ + AUDIO_FORMAT_TYPE_G711U = 0x2000002u, /**< G711u */ + AUDIO_FORMAT_TYPE_G726 = 0x2000003u, /**< G726 */ +}; + +/** + * @brief Enumerates the audio channel mask. + * + * A mask describes an audio channel position. + */ +enum AudioChannelMask { + AUDIO_CHANNEL_MONO = 1u, /**< Mono channel */ + AUDIO_CHANNEL_FRONT_LEFT = 1u, /**< Front left channel */ + AUDIO_CHANNEL_FRONT_RIGHT = 2u, /**< Front right channel */ + AUDIO_CHANNEL_FRONT_CENTER = 4u, /**< Front right channel */ + AUDIO_CHANNEL_LOW_FREQUENCY = 8u, /**< 0x8 */ + AUDIO_CHANNEL_BACK_LEFT = 16u, /**< 0x10 */ + AUDIO_CHANNEL_BACK_RIGHT = 32u, /**< 0x20 */ + AUDIO_CHANNEL_BACK_CENTER = 256u, /**< 0x100 */ + AUDIO_CHANNEL_SIDE_LEFT = 512u, /**< 0x200 */ + AUDIO_CHANNEL_SIDE_RIGHT = 1024u, /**< 0x400 */ + AUDIO_CHANNEL_TOP_SIDE_LEFT = 262144u, /**< 0x40000 */ + AUDIO_CHANNEL_TOP_SIDE_RIGHT = 524288u, /**< 0x80000 */ + AUDIO_CHANNEL_STEREO = 3u, /**< FRONT_LEFT | FRONT_RIGHT */ + AUDIO_CHANNEL_2POINT1 = 11u, /**< STEREO | LOW_FREQUENCY */ + AUDIO_CHANNEL_QUAD = 51u, /**< STEREO | BACK_LEFT | BACK_RIGHT */ + AUDIO_CHANNEL_3POINT0POINT2 = 786439u, /**< STEREO | FRONT_CENTER | TOP_SIDE_LEFT | TOP_SIDE_RIGHT */ + AUDIO_CHANNEL_5POINT1 = 63u, /**< QUAD | FRONT_CENTER | LOW_FREQUENCY */ + AUDIO_CHANNEL_6POINT1 = 319u, /**< AUDIO_CHANNEL_5POINT1 | BACK_CENTER */ + AUDIO_CHANNEL_7POINT1 = 1599u, /**< AUDIO_CHANNEL_5POINT1 | SIDE_LEFT | SIDE_RIGHT */ +}; + +/** + * @brief Enumerates masks of audio sampling rates. + */ +enum AudioSampleRatesMask { + AUDIO_SAMPLE_RATE_MASK_8000 = 0x1u, /**< 8 kHz */ + AUDIO_SAMPLE_RATE_MASK_12000 = 0x2u, /**< 12 kHz */ + AUDIO_SAMPLE_RATE_MASK_11025 = 0x4u, /**< 11.025 kHz */ + AUDIO_SAMPLE_RATE_MASK_16000 = 0x8u, /**< 16 kHz */ + AUDIO_SAMPLE_RATE_MASK_22050 = 0x10u, /**< 22.050 kHz */ + AUDIO_SAMPLE_RATE_MASK_24000 = 0x20u, /**< 24 kHz */ + AUDIO_SAMPLE_RATE_MASK_32000 = 0x40u, /**< 32 kHz */ + AUDIO_SAMPLE_RATE_MASK_44100 = 0x80u, /**< 44.1 kHz */ + AUDIO_SAMPLE_RATE_MASK_48000 = 0x100u, /**< 48 kHz */ + AUDIO_SAMPLE_RATE_MASK_64000 = 0x200u, /**< 64 kHz */ + AUDIO_SAMPLE_RATE_MASK_96000 = 0x400u, /**< 96 kHz */ + AUDIO_SAMPLE_RATE_MASK_INVALID = 0xFFFFFFFFu, /**< Invalid sampling rate */ +}; +enum AudioInputType { + AUDIO_INPUT_DEFAULT_TYPE = 0, + AUDIO_INPUT_MIC_TYPE = 1 << 0, + AUDIO_INPUT_SPEECH_WAKEUP_TYPE = 1 << 1, + AUDIO_INPUT_VOICE_COMMUNICATION_TYPE = 1 << 2, + AUDIO_INPUT_VOICE_RECOGNITION_TYPE = 1 << 3, +}; +/** + * @brief Defines audio sampling attributes. + */ +struct AudioSampleAttributes { + enum AudioCategory type; /**< Audio type. For details, see {@link AudioCategory} */ + bool interleaved; /**< Interleaving flag of audio data */ + enum AudioFormat format; /**< Audio data format. For details, see {@link AudioFormat}. */ + uint32_t sampleRate; /**< Audio sampling rate */ + uint32_t channelCount; /**< Number of audio channels. For example, for the mono channel, the value is 1, + * and for the stereo channel, the value is 2. + */ + uint32_t period; /**< Audio sampling period */ + uint32_t frameSize; /**< Frame size of the audio data */ + bool isBigEndian; /**< Big endian flag of audio data */ + bool isSignedData; /**< Signed or unsigned flag of audio data */ + uint32_t startThreshold; /**< Audio render start threshold. */ + uint32_t stopThreshold; /**< Audio render stop threshold. */ + uint32_t silenceThreshold; /**< Audio capture buffer threshold. */ + int32_t streamId; /**< Audio Identifier of render or capture */ + int32_t sourceType; +}; + +/** + * @brief Defines the audio timestamp, which is a substitute for POSIX timespec. + */ +struct AudioTimeStamp { + int64_t tvSec; /**< Seconds */ + int64_t tvNSec; /**< Nanoseconds */ +}; + +/** + * @brief Enumerates the passthrough data transmission mode of an audio port. + */ +enum AudioPortPassthroughMode { + PORT_PASSTHROUGH_LPCM = 0x1, /**< Stereo PCM */ + PORT_PASSTHROUGH_RAW = 0x2, /**< HDMI passthrough */ + PORT_PASSTHROUGH_HBR2LBR = 0x4, /**< Blu-ray next-generation audio output with reduced specifications */ + PORT_PASSTHROUGH_AUTO = 0x8, /**< Mode automatically matched based on the HDMI EDID */ +}; + +/** + * @brief Defines the sub-port capability. + */ +struct AudioSubPortCapability { + uint32_t portId; /**< Sub-port ID */ + const char *desc; /**< Sub-port name */ + enum AudioPortPassthroughMode mask; /**< Passthrough mode of data transmission. For details, + * see {@link AudioPortPassthroughMode}. + */ +}; + +/** + * @brief Defines formats of raw audio samples. + */ +enum AudioSampleFormat { + /* 8 bits */ + AUDIO_SAMPLE_FORMAT_S8, /**< signed 8 bit sample */ + AUDIO_SAMPLE_FORMAT_S8P, /**< signed 8 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U8, /**< unsigned 8 bit sample */ + AUDIO_SAMPLE_FORMAT_U8P, /**< unsigned 8 bit planar sample */ + /* 16 bits */ + AUDIO_SAMPLE_FORMAT_S16, /**< signed 16 bit sample */ + AUDIO_SAMPLE_FORMAT_S16P, /**< signed 16 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U16, /**< unsigned 16 bit sample */ + AUDIO_SAMPLE_FORMAT_U16P, /**< unsigned 16 bit planar sample */ + /* 24 bits */ + AUDIO_SAMPLE_FORMAT_S24, /**< signed 24 bit sample */ + AUDIO_SAMPLE_FORMAT_S24P, /**< signed 24 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U24, /**< unsigned 24 bit sample */ + AUDIO_SAMPLE_FORMAT_U24P, /**< unsigned 24 bit planar sample */ + /* 32 bits */ + AUDIO_SAMPLE_FORMAT_S32, /**< signed 32 bit sample */ + AUDIO_SAMPLE_FORMAT_S32P, /**< signed 32 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U32, /**< unsigned 32 bit sample */ + AUDIO_SAMPLE_FORMAT_U32P, /**< unsigned 32 bit planar sample */ + /* 64 bits */ + AUDIO_SAMPLE_FORMAT_S64, /**< signed 64 bit sample */ + AUDIO_SAMPLE_FORMAT_S64P, /**< signed 64 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U64, /**< unsigned 64 bit sample */ + AUDIO_SAMPLE_FORMAT_U64P, /**< unsigned 64 bit planar sample */ + /* float double */ + AUDIO_SAMPLE_FORMAT_F32, /**< float 32 bit sample */ + AUDIO_SAMPLE_FORMAT_F32P, /**< float 32 bit planar sample */ + AUDIO_SAMPLE_FORMAT_F64, /**< double 64 bit sample */ + AUDIO_SAMPLE_FORMAT_F64P, /**< double 64 bit planar sample */ +}; + +/** + * @brief Defines the audio port capability. + */ +struct AudioPortCapability { + uint32_t deviceType; /**< Device type (output or input) */ + uint32_t deviceId; /**< Device ID used for device binding */ + bool hardwareMode; /**< Whether to support device binding */ + uint32_t formatNum; /**< Number of the supported audio formats */ + enum AudioFormat *formats; /**< Supported audio formats. For details, see {@link AudioFormat}. */ + uint32_t sampleRateMasks; /**< Supported audio sampling rates (8 kHz, 16 kHz, 32 kHz, and 48 kHz) */ + enum AudioChannelMask channelMasks; /**< Audio channel layout mask of the device. For details, + * see {@link AudioChannelMask}. + */ + uint32_t channelCount; /**< Supported maximum number of audio channels */ + uint32_t subPortsNum; /**< Number of supported sub-ports (for output devices only) */ + struct AudioSubPortCapability *subPorts; /**< List of supported sub-ports */ + uint32_t supportSampleFormatNum; /**< Number of the supported audio sample format enum. */ + enum AudioSampleFormat *supportSampleFormats; /**< Supported audio sample formats. For details, + * see {@link AudioSampleFormat}. + */ +}; + +/** + * @brief Enumerates channel modes for audio rendering. + * + * @attention The following modes are set for rendering dual-channel audios. Others are not supported. + */ +enum AudioChannelMode { + AUDIO_CHANNEL_NORMAL = 0, /**< Normal mode. No processing is required. */ + AUDIO_CHANNEL_BOTH_LEFT, /**< Two left channels */ + AUDIO_CHANNEL_BOTH_RIGHT, /**< Two right channels */ + AUDIO_CHANNEL_EXCHANGE, /**< Data exchange between the left and right channels. The left channel takes the audio + * stream of the right channel, and the right channel takes that of the left channel. + */ + AUDIO_CHANNEL_MIX, /**< Mix of streams of the left and right channels */ + AUDIO_CHANNEL_LEFT_MUTE, /**< Left channel muted. The stream of the right channel is output. */ + AUDIO_CHANNEL_RIGHT_MUTE, /**< Right channel muted. The stream of the left channel is output. */ + AUDIO_CHANNEL_BOTH_MUTE, /**< Both left and right channels muted */ +}; + +/** + * @brief Enumerates the execution types of the DrainBuffer function. + */ +enum AudioDrainNotifyType { + AUDIO_DRAIN_NORMAL_MODE, /**< The DrainBuffer function returns after all data finishes playback. */ + AUDIO_DRAIN_EARLY_MODE, /**< The DrainBuffer function returns before all the data of the current track + * finishes playback to reserve time for a smooth track switch by the audio service. + */ +}; + +/** + * @brief Enumerates callback notification events. + */ +enum AudioCallbackType { + AUDIO_NONBLOCK_WRITE_COMPLETED, /**< The non-block write is complete. */ + AUDIO_DRAIN_COMPLETED, /**< The draining is complete. */ + AUDIO_FLUSH_COMPLETED, /**< The flush is complete. */ + AUDIO_RENDER_FULL, /**< The render buffer is full.*/ + AUDIO_ERROR_OCCUR, /**< An error occurs.*/ +}; + +/** + * @brief Describes a mmap buffer. + */ +struct AudioMmapBufferDescriptor { + void *memoryAddress; /**< Pointer to the mmap buffer */ + int32_t memoryFd; /**< File descriptor of the mmap buffer */ + int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/ + int32_t transferFrameSize; /**< Transfer size (unit: frame) */ + int32_t isShareable; /**< Whether the mmap buffer can be shared among processes */ + uint32_t offset; +}; + +/** + * @brief Describes AudioPortRole. + */ +enum AudioPortRole { + AUDIO_PORT_UNASSIGNED_ROLE = 0, /**< Unassigned port role */ + AUDIO_PORT_SOURCE_ROLE = 1, /**< Assigned source role */ + AUDIO_PORT_SINK_ROLE = 2, /**< Assigned sink role */ +}; + +/** + * @brief Describes AudioPortType. + */ +enum AudioPortType { + AUDIO_PORT_UNASSIGNED_TYPE = 0, /**< Unassigned port type */ + AUDIO_PORT_DEVICE_TYPE = 1, /**< Assigned device type */ + AUDIO_PORT_MIX_TYPE = 2, /**< Assigned mix type */ + AUDIO_PORT_SESSION_TYPE = 3, /**< Assigned session type */ +}; + +/** + * @brief Describes AudioDevExtInfo. + */ +struct AudioDevExtInfo { + int32_t moduleId; /**< Identifier of the module stream is attached to */ + enum AudioPortPin type; /**< Device type For details, see {@link AudioPortPin}. */ + const char *desc; /**< Address */ +}; + +/** + * @brief Describes AudioMixInfo. + */ +struct AudioMixExtInfo { + int32_t moduleId; /**< Identifier of the module stream is attached to */ + int32_t streamId; /**< Identifier of the capture or render passed by caller */ +}; + +/** + * @brief Describes AudioSessionType. + */ +enum AudioSessionType { + AUDIO_OUTPUT_STAGE_SESSION = 0, + AUDIO_OUTPUT_MIX_SESSION, + AUDIO_ALLOCATE_SESSION, + AUDIO_INVALID_SESSION, +}; + +/** + * @brief Describes AudioSessionExtInfo. + */ +struct AudioSessionExtInfo { + enum AudioSessionType sessionType; +}; + +/** + * @brief Describes AudioRouteNode. + */ +struct AudioRouteNode { + int32_t portId; /**< Audio port ID */ + enum AudioPortRole role; /**< Audio port as a sink or a source */ + enum AudioPortType type; /**< device, mix ... */ + union { + struct AudioDevExtInfo device; /* Specific Device Ext info */ + struct AudioMixExtInfo mix; /* Specific mix info */ + struct AudioSessionExtInfo session; /* session specific info */ + } ext; +}; + +/** + * @brief Describes AudioRoute. + */ +struct AudioRoute { + uint32_t sourcesNum; + const struct AudioRouteNode *sources; + uint32_t sinksNum; + const struct AudioRouteNode *sinks; +}; + +/** + * @brief Enumerates the restricted key type of the parameters + */ +enum AudioExtParamKey { + AUDIO_EXT_PARAM_KEY_NONE = 0, /**< Distributed audio extra param key none */ + AUDIO_EXT_PARAM_KEY_VOLUME = 1, /**< Distributed audio extra param key volume event */ + AUDIO_EXT_PARAM_KEY_FOCUS = 2, /**< Distributed audio extra param key focus event */ + AUDIO_EXT_PARAM_KEY_BUTTON = 3, /**< Distributed audio extra param key media button event */ + AUDIO_EXT_PARAM_KEY_EFFECT = 4, /**< Distributed audio extra param key audio effect event */ + AUDIO_EXT_PARAM_KEY_STATUS = 5, /**< Distributed audio extra param key device status event */ + AUDIO_EXT_PARAM_KEY_USB_DEVICE = 101, /**< Check USB device type ARM or HIFI */ + AUDIO_EXT_PARAM_KEY_LOWPOWER = 1000, /**< Low power event type */ +}; +/** + * @brief Describes status of audio deivce.@link enum AudioDeviceType + */ +struct AudioDeviceStatus { + uint32_t pnpStatus; +}; +/** + * @brief Called when an event defined in {@link AudioCallbackType} occurs. + * + * @param AudioCallbackType Indicates the occurred event that triggers this callback. + * @param reserved Indicates the pointer to a reserved field. + * @param cookie Indicates the pointer to the cookie for data transmission. + * @return Returns 0 if the callback is successfully executed; returns a negative value otherwise. + * @see RegCallback + */ +typedef int32_t (*RenderCallback)(enum AudioCallbackType, void *reserved, void *cookie); + +/** + * @brief Register audio extra param callback that will be invoked during audio param event. + * + * @param key Indicates param change event. + * @param condition Indicates the param condition. + * @param value Indicates the param value. + * @param reserved Indicates reserved param. + * @param cookie Indicates the pointer to the callback parameters; + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ +typedef int32_t (*ParamCallback)(enum AudioExtParamKey key, const char *condition, const char *value, void *reserved, + void *cookie); + +#endif /* AUDIO_TYPES_H */ diff --git a/services/hdfaudioclient/include/audio_volume.h b/services/hdfaudioclient/include/audio_volume.h new file mode 100644 index 00000000..c57ac6f9 --- /dev/null +++ b/services/hdfaudioclient/include/audio_volume.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2020-2021 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. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_volume.h + * + * @brief Declares APIs for audio volume. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_VOLUME_H +#define AUDIO_VOLUME_H + +#include "audio_types.h" + +/** + * @brief Provides volume-related APIs for audio rendering or capturing, including functions to + * set the mute operation, volume, and gain. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioVolume { + /** + * @brief Sets the mute operation for the audio. + * + * @param handle Indicates the audio handle. + * @param mute Specifies whether to mute the audio. Value true means to mute the audio, + * and false means the opposite. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetMute + */ + int32_t (*SetMute)(AudioHandle handle, bool mute); + + /** + * @brief Obtains the mute operation set for the audio. + * + * @param handle Indicates the audio handle. + * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that + * the audio is muted, and false means the opposite. + * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. + * @see SetMute + */ + int32_t (*GetMute)(AudioHandle handle, bool *mute); + + /** + * @brief Sets the audio volume. + * + * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, + * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). + * + * @param handle Indicates the audio handle. + * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetVolume + */ + int32_t (*SetVolume)(AudioHandle handle, float volume); + + /** + * @brief Obtains the audio volume. + * + * @param handle Indicates the audio handle. + * @param volume Indicates the pointer to the volume to obtain. The value ranges from 0.0 to 1.0. + * @return Returns 0 if the volume is obtained; returns a negative value otherwise. + * @see SetVolume + */ + int32_t (*GetVolume)(AudioHandle handle, float *volume); + + /** + * @brief Obtains the range of the audio gain. + * + * The audio gain can be expressed in one of the following two ways (depending on the chip platform), + * corresponding to two types of value ranges: + *
    + *
  • Actual audio gain values, for example, ranging from -50 to 6 dB
  • + *
  • Float numbers ranging from 0.0 to 1.0, where 0.0 means to mute the audio, + * and 1.0 means the maximum gain value, for example, 6 dB
  • + *
+ * @param handle Indicates the audio handle. + * @param min Indicates the pointer to the minimum value of the range. + * @param max Indicates the pointer to the maximum value of the range. + * @return Returns 0 if the range is obtained; returns a negative value otherwise. + * @see GetGain + * @see SetGain + */ + int32_t (*GetGainThreshold)(AudioHandle handle, float *min, float *max); + + /** + * @brief Obtains the audio gain. + * + * @param handle Indicates the audio handle. + * @param gain Indicates the pointer to the audio gain. + * @return Returns 0 if the audio gain is obtained; returns a negative value otherwise. + * @see GetGainThreshold + * @see SetGain + */ + int32_t (*GetGain)(AudioHandle handle, float *gain); + + /** + * @brief Sets the audio gain. + * + * @param handle Indicates the audio handle. + * @param gain Indicates the audio gain to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetGainThreshold + * @see GetGain + */ + int32_t (*SetGain)(AudioHandle handle, float gain); +}; + +#endif /* AUDIO_VOLUME_H */ +/** @} */ diff --git a/services/test_example/BUILD.gn b/services/test_example/BUILD.gn index d207d120..6238bddd 100644 --- a/services/test_example/BUILD.gn +++ b/services/test_example/BUILD.gn @@ -23,8 +23,6 @@ ohos_executable("audio_distributed_test") { include_dirs = [ "./include", - "${driver_audio_path}/include", - "${hdf_service_path}/hdi_service/common/include", "${services_path}/hdfaudioclient/include", ] diff --git a/services/test_example/daudio_errcode.h b/services/test_example/daudio_errcode.h new file mode 100644 index 00000000..b408d569 --- /dev/null +++ b/services/test_example/daudio_errcode.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022-2023 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_ERRCODE_H +#define OHOS_DAUDIO_ERRCODE_H + +namespace OHOS { +namespace DistributedHardware { +enum DAudioErrorCode { + DH_SUCCESS = 0, + // Distributed Audio HDF Error Code + ERR_DH_AUDIO_HDF_FAIL = -46001, + ERR_DH_AUDIO_HDF_NULLPTR = -46002, + ERR_DH_AUDIO_HDF_INVALID_PARAM = -46003, + ERR_DH_AUDIO_HDF_REPEAT_OPERATION = -46004, + ERR_DH_AUDIO_HDF_INVALID_OPERATION = -46005, + ERR_DH_AUDIO_HDF_SET_PARAM_FAIL = -46006, + ERR_DH_AUDIO_HDF_OPEN_DEVICE_FAIL = -46007, + ERR_DH_AUDIO_HDF_CLOSE_DEVICE_FAIL = -46008, + ERR_DH_AUDIO_COMMON_NOT_FOUND_KEY = -46009, + ERR_DH_AUDIO_HDF_WAIT_TIMEOUT = -46010, + + ERR_DH_AUDIO_HDF_INIT_ENGINE_FAILED = -46011, + ERR_DH_AUDIO_HDF_NOTIFY_SINK_FAILED = -46012, + ERR_DH_AUDIO_HDF_TRANS_SETUP_FAILED = -46013, + ERR_DH_AUDIO_HDF_TRANS_START_FAILED = -46014, + ERR_DH_AUDIO_HDF_RESULT_FAILED = -46015, +}; +} // Distributedaudio +} // OHOS +#endif -- Gitee From b2de9856b41948fc968b59bfd669ef7d4b37f017 Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Mon, 19 Feb 2024 15:35:33 +0800 Subject: [PATCH 09/17] Distributed_audio fix to support for independent compilation Signed-off-by: zhonglufu --- audiohandler/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index 66a35b45..cfc10ac4 100644 --- a/audiohandler/BUILD.gn +++ b/audiohandler/BUILD.gn @@ -23,9 +23,7 @@ ohos_shared_library("distributed_audio_handler") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "//third_party/json/include", - ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "include", -- Gitee From edffc44838771841446414a1f63ba25d675405f5 Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Mon, 19 Feb 2024 15:57:52 +0800 Subject: [PATCH 10/17] Distributed_audio fix to support for independent compilation Signed-off-by: zhonglufu --- interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn | 4 +--- interfaces/inner_kits/native_cpp/audio_source/BUILD.gn | 4 +--- services/audiotransport/receiverengine/BUILD.gn | 4 +--- services/audiotransport/senderengine/BUILD.gn | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 0d7ab1c9..3b4c678b 100755 --- a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn @@ -26,9 +26,7 @@ ohos_shared_library("distributed_audio_sink_sdk") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "//third_party/json/include", - ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "include", diff --git a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn index 64bf5603..9fcf62d7 100755 --- a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn @@ -26,9 +26,7 @@ ohos_shared_library("distributed_audio_source_sdk") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "//third_party/json/include", - ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "include", diff --git a/services/audiotransport/receiverengine/BUILD.gn b/services/audiotransport/receiverengine/BUILD.gn index 53065ab2..df5377c3 100644 --- a/services/audiotransport/receiverengine/BUILD.gn +++ b/services/audiotransport/receiverengine/BUILD.gn @@ -33,9 +33,7 @@ ohos_shared_library("distributed_audio_decode_transport") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "//third_party/json/include", - ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "include", diff --git a/services/audiotransport/senderengine/BUILD.gn b/services/audiotransport/senderengine/BUILD.gn index f5c714ba..fd720530 100644 --- a/services/audiotransport/senderengine/BUILD.gn +++ b/services/audiotransport/senderengine/BUILD.gn @@ -33,9 +33,7 @@ ohos_shared_library("distributed_audio_encode_transport") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "//third_party/json/include", - ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "include", -- Gitee From b24077eb237a15cbf2b7da2560506f0aa8921a60 Mon Sep 17 00:00:00 2001 From: byndyx Date: Wed, 7 Feb 2024 09:33:53 +0800 Subject: [PATCH 11/17] sa serial Signed-off-by: byndyx --- .../src/daudio_sink_ipc_callback_stub.cpp | 2 +- .../audio_source/src/daudio_ipc_callback_stub.cpp | 2 +- .../src/daudio_ipc_callback_test.cpp | 13 +++++++++++-- .../servicesink/src/daudio_sink_stub.cpp | 2 +- .../servicesource/src/daudio_source_stub.cpp | 2 +- .../src/daudio_source_service_test.cpp | 3 +++ 6 files changed, 18 insertions(+), 6 deletions(-) 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 a0f6258c..e794b043 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/src/daudio_ipc_callback_stub.cpp b/interfaces/inner_kits/native_cpp/audio_source/src/daudio_ipc_callback_stub.cpp index 68f950c2..35e183de 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/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp b/interfaces/inner_kits/native_cpp/test/unittest/audiosourcetest/src/daudio_ipc_callback_test.cpp index 27df7a7e..9d6d3dfe 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/audiomanager/servicesink/src/daudio_sink_stub.cpp b/services/audiomanager/servicesink/src/daudio_sink_stub.cpp index 6f4a4cb4..3b777504 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/src/daudio_source_stub.cpp b/services/audiomanager/servicesource/src/daudio_source_stub.cpp index 85b9083c..d00be43a 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/unittest/servicesource/src/daudio_source_service_test.cpp b/services/audiomanager/test/unittest/servicesource/src/daudio_source_service_test.cpp index 21ff2f13..92947a23 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 -- Gitee From 38004f778beaeb3cc5f6db9f50783f6922291ace Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Wed, 21 Feb 2024 14:01:46 +0800 Subject: [PATCH 12/17] Distributed_audio fix to support for independent compilation Signed-off-by: zhonglufu --- audiohandler/include/ihardware_handler.h | 2 +- .../native_cpp/audio_sink/include/idistributed_hardware_sink.h | 2 +- .../audio_source/include/idistributed_hardware_source.h | 2 +- services/hdfaudioclient/include/audio_adapter.h | 2 +- services/hdfaudioclient/include/audio_attribute.h | 2 +- services/hdfaudioclient/include/audio_capture.h | 2 +- services/hdfaudioclient/include/audio_control.h | 2 +- services/hdfaudioclient/include/audio_manager.h | 2 +- services/hdfaudioclient/include/audio_render.h | 2 +- services/hdfaudioclient/include/audio_scene.h | 2 +- services/hdfaudioclient/include/audio_types.h | 2 +- services/hdfaudioclient/include/audio_volume.h | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/audiohandler/include/ihardware_handler.h b/audiohandler/include/ihardware_handler.h index fa0f75e9..5ff5c405 100644 --- a/audiohandler/include/ihardware_handler.h +++ b/audiohandler/include/ihardware_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h b/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h index 70515851..db9dc6c6 100644 --- a/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h b/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h index 3517bb3e..78e2ed4d 100644 --- a/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h +++ b/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/services/hdfaudioclient/include/audio_adapter.h b/services/hdfaudioclient/include/audio_adapter.h index e818ec26..5872080a 100644 --- a/services/hdfaudioclient/include/audio_adapter.h +++ b/services/hdfaudioclient/include/audio_adapter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/services/hdfaudioclient/include/audio_attribute.h b/services/hdfaudioclient/include/audio_attribute.h index bd93c7c9..b5beed14 100644 --- a/services/hdfaudioclient/include/audio_attribute.h +++ b/services/hdfaudioclient/include/audio_attribute.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/services/hdfaudioclient/include/audio_capture.h b/services/hdfaudioclient/include/audio_capture.h index a45e2471..52347aab 100644 --- a/services/hdfaudioclient/include/audio_capture.h +++ b/services/hdfaudioclient/include/audio_capture.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/services/hdfaudioclient/include/audio_control.h b/services/hdfaudioclient/include/audio_control.h index 536f8fe0..a20f7875 100644 --- a/services/hdfaudioclient/include/audio_control.h +++ b/services/hdfaudioclient/include/audio_control.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/services/hdfaudioclient/include/audio_manager.h b/services/hdfaudioclient/include/audio_manager.h index fcaa4ddd..f952dc3c 100644 --- a/services/hdfaudioclient/include/audio_manager.h +++ b/services/hdfaudioclient/include/audio_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/services/hdfaudioclient/include/audio_render.h b/services/hdfaudioclient/include/audio_render.h index 3803075a..1627fe62 100644 --- a/services/hdfaudioclient/include/audio_render.h +++ b/services/hdfaudioclient/include/audio_render.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/services/hdfaudioclient/include/audio_scene.h b/services/hdfaudioclient/include/audio_scene.h index 73d397f8..e6ef9f90 100644 --- a/services/hdfaudioclient/include/audio_scene.h +++ b/services/hdfaudioclient/include/audio_scene.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/services/hdfaudioclient/include/audio_types.h b/services/hdfaudioclient/include/audio_types.h index 7f3b84ca..76662f99 100644 --- a/services/hdfaudioclient/include/audio_types.h +++ b/services/hdfaudioclient/include/audio_types.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 diff --git a/services/hdfaudioclient/include/audio_volume.h b/services/hdfaudioclient/include/audio_volume.h index c57ac6f9..ad476f7c 100644 --- a/services/hdfaudioclient/include/audio_volume.h +++ b/services/hdfaudioclient/include/audio_volume.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-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 -- Gitee From bd6c902ab4d38ef4b924994e34bd0739c2ee22ed Mon Sep 17 00:00:00 2001 From: byndyx Date: Thu, 22 Feb 2024 14:16:17 +0800 Subject: [PATCH 13/17] add UT Signed-off-by: byndyx --- .../managersink/src/daudio_sink_dev_test.cpp | 72 ++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) 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 2023f6ef..06ccd6c5 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 @@ -114,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)); } /** @@ -304,6 +306,8 @@ HWTEST_F(DAudioSinkDevTest, TaskSetVolume_002, 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_->TaskSetVolume(args)); + std::string args1 = "dhId=1"; + EXPECT_NE(DH_SUCCESS, sinkDev_->TaskSetVolume(args1)); } /** @@ -332,6 +336,8 @@ HWTEST_F(DAudioSinkDevTest, TaskSetMute_002, 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_->TaskSetMute(args)); + std::string args1 = "dhId=1"; + EXPECT_NE(DH_SUCCESS, sinkDev_->TaskSetMute(args1)); } /** @@ -399,14 +405,20 @@ HWTEST_F(DAudioSinkDevTest, TaskRenderStateChange_001, TestSize.Level1) 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)); } @@ -467,10 +479,12 @@ HWTEST_F(DAudioSinkDevTest, PauseDistributedHardware_001, TestSize.Level1) */ 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_->isMicInUse_.store(false); sinkDev_->JudgeDeviceStatus(); std::string args = "one"; EXPECT_NE(DH_SUCCESS, sinkDev_->ConvertString2Int(args)); @@ -600,8 +614,64 @@ HWTEST_F(DAudioSinkDevTest, SinkEventHandler_004, TestSize.Level1) 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 -- Gitee From 51287695682456a67a95e900f60a97ca88846341 Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Fri, 23 Feb 2024 09:00:18 +0000 Subject: [PATCH 14/17] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!2?= =?UTF-8?q?66=20:=20Distributed=5Faudio=20fix=20to=20support=20for=20indep?= =?UTF-8?q?endent=20complilation'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- audiohandler/BUILD.gn | 9 +- audiohandler/include/daudio_handler.h | 1 + audiohandler/include/ihardware_handler.h | 51 -- audiohandler/src/daudio_handler.cpp | 1 + common/dfx_utils/include/daudio_hidumper.h | 8 + common/dfx_utils/src/daudio_hidumper.cpp | 17 + .../inner_kits/native_cpp/audio_sink/BUILD.gn | 5 +- .../include/idistributed_hardware_sink.h | 55 -- .../native_cpp/audio_source/BUILD.gn | 5 +- .../include/idistributed_hardware_source.h | 59 --- services/audiomanager/servicesink/BUILD.gn | 1 + services/audiomanager/servicesource/BUILD.gn | 7 +- .../audiotransport/receiverengine/BUILD.gn | 6 +- services/audiotransport/senderengine/BUILD.gn | 6 +- services/hdfaudioclient/BUILD.gn | 4 +- .../hdfaudioclient/include/audio_adapter.h | 270 ---------- .../hdfaudioclient/include/audio_attribute.h | 167 ------ .../hdfaudioclient/include/audio_capture.h | 98 ---- .../hdfaudioclient/include/audio_control.h | 131 ----- .../hdfaudioclient/include/audio_manager.h | 111 ---- .../hdfaudioclient/include/audio_render.h | 181 ------- services/hdfaudioclient/include/audio_scene.h | 86 ---- services/hdfaudioclient/include/audio_types.h | 487 ------------------ .../hdfaudioclient/include/audio_volume.h | 137 ----- services/test_example/BUILD.gn | 2 + services/test_example/daudio_errcode.h | 43 -- 26 files changed, 65 insertions(+), 1883 deletions(-) delete mode 100644 audiohandler/include/ihardware_handler.h delete mode 100644 interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h delete mode 100644 interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h delete mode 100644 services/hdfaudioclient/include/audio_adapter.h delete mode 100644 services/hdfaudioclient/include/audio_attribute.h delete mode 100644 services/hdfaudioclient/include/audio_capture.h delete mode 100644 services/hdfaudioclient/include/audio_control.h delete mode 100644 services/hdfaudioclient/include/audio_manager.h delete mode 100644 services/hdfaudioclient/include/audio_render.h delete mode 100644 services/hdfaudioclient/include/audio_scene.h delete mode 100644 services/hdfaudioclient/include/audio_types.h delete mode 100644 services/hdfaudioclient/include/audio_volume.h delete mode 100644 services/test_example/daudio_errcode.h diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index cfc10ac4..ef27e252 100644 --- a/audiohandler/BUILD.gn +++ b/audiohandler/BUILD.gn @@ -23,7 +23,14 @@ ohos_shared_library("distributed_audio_handler") { ubsan = true } stack_protector_ret = true - include_dirs = [ "//third_party/json/include" ] + include_dirs = [ + "//third_party/json/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include", + "${mediastandardfwk_path}/audiomanager/include", + "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiocapturer/include", + ] include_dirs += [ "include", diff --git a/audiohandler/include/daudio_handler.h b/audiohandler/include/daudio_handler.h index 75123436..4b79ea82 100644 --- a/audiohandler/include/daudio_handler.h +++ b/audiohandler/include/daudio_handler.h @@ -22,6 +22,7 @@ #include "single_instance.h" #include "audio_param.h" #include "audio_capturer.h" +#include "audio_info.h" namespace OHOS { namespace DistributedHardware { diff --git a/audiohandler/include/ihardware_handler.h b/audiohandler/include/ihardware_handler.h deleted file mode 100644 index 5ff5c405..00000000 --- a/audiohandler/include/ihardware_handler.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021-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_DISTRIBUTED_HARDWARE_IHARDWARE_HANDLER_H -#define OHOS_DISTRIBUTED_HARDWARE_IHARDWARE_HANDLER_H - -#include -#include -#include -#include - -namespace OHOS { -namespace DistributedHardware { -const std::string COMPONENT_LOADER_GET_HARDWARE_HANDLER = "GetHardwareHandler"; -struct DHItem { - std::string dhId; - std::string attrs; - std::string subtype; -}; - -class PluginListener { -public: - virtual void PluginHardware(const std::string &dhId, const std::string &attrs, const std::string &subtype) = 0; - virtual void UnPluginHardware(const std::string &dhId) = 0; -}; - -class IHardwareHandler { -public: - virtual int32_t Initialize() = 0; - virtual std::vector Query() = 0; - virtual std::map QueryExtraInfo() = 0; - virtual bool IsSupportPlugin() = 0; - virtual void RegisterPluginListener(std::shared_ptr listener) = 0; - virtual void UnRegisterPluginListener() = 0; -}; -extern "C" __attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler(); -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/audiohandler/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index c6551f37..36275a2e 100644 --- a/audiohandler/src/daudio_handler.cpp +++ b/audiohandler/src/daudio_handler.cpp @@ -22,6 +22,7 @@ #include "nlohmann/json.hpp" #include "string_ex.h" +#include "histreamer_query_tool.h" #include "daudio_constants.h" #include "daudio_errorcode.h" #include "daudio_log.h" diff --git a/common/dfx_utils/include/daudio_hidumper.h b/common/dfx_utils/include/daudio_hidumper.h index 667e33db..aa1d6da9 100644 --- a/common/dfx_utils/include/daudio_hidumper.h +++ b/common/dfx_utils/include/daudio_hidumper.h @@ -20,6 +20,11 @@ #include #include "sys/stat.h" +#include "audio_capturer.h" +#include "audio_info.h" + +#include "audio_adapter.h" +#include "audio_manager.h" #include "daudio_handler.h" #include "single_instance.h" @@ -55,7 +60,10 @@ private: int32_t StopDumpData(std::string &result); private: + AudioManager *audioManager_ = nullptr; + AudioAdapterDescriptor *adapterdesc_ = nullptr; bool dumpAudioDataFlag_ = false; + int32_t g_deviceNum = 0; const std::string DEFAULT_SPK_DHID = "1"; const std::string DEFAULT_MIC_DHID = "134217729"; }; diff --git a/common/dfx_utils/src/daudio_hidumper.cpp b/common/dfx_utils/src/daudio_hidumper.cpp index 44376fb9..d33ddbe8 100644 --- a/common/dfx_utils/src/daudio_hidumper.cpp +++ b/common/dfx_utils/src/daudio_hidumper.cpp @@ -128,6 +128,23 @@ int32_t DaudioHidumper::GetSourceDevId(std::string &result) int32_t DaudioHidumper::GetSinkInfo(std::string &result) { DHLOGI("Get sink info dump."); + audioManager_ = GetAudioManagerFuncs(); + if (audioManager_ == nullptr) { + return ERR_DH_AUDIO_NULLPTR; + } + int32_t ret = audioManager_->GetAllAdapters(audioManager_, &adapterdesc_, &g_deviceNum); + if (ret != DH_SUCCESS) { + DHLOGE("Get all adapters failed."); + return ERR_DH_AUDIO_NULLPTR; + } + for (int32_t index = 0; index < g_deviceNum; index++) { + AudioAdapterDescriptor &desc = adapterdesc_[index]; + result.append("sinkDevId: ").append(GetAnonyString(desc.adapterName)).append(" portId: "); + for (uint32_t i = 0; i < desc.portNum; i++) { + result.append(std::to_string(desc.ports[i].portId)).append(" "); + } + } + return DH_SUCCESS; } diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 3b4c678b..2a10e58d 100755 --- a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn @@ -26,7 +26,10 @@ ohos_shared_library("distributed_audio_sink_sdk") { ubsan = true } stack_protector_ret = true - include_dirs = [ "//third_party/json/include" ] + include_dirs = [ + "${fwk_common_path}/utils/include", + "//third_party/json/include", + ] include_dirs += [ "include", diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h b/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h deleted file mode 100644 index db9dc6c6..00000000 --- a/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021-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_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SINK_H -#define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SINK_H - -#include - -namespace OHOS { -namespace DistributedHardware { -const std::string COMPONENT_LOADER_GET_SINK_HANDLER = "GetSinkHardwareHandler"; -enum class ResourceEventType : int32_t { - EVENT_TYPE_QUERY_RESOURCE = 0, - EVENT_TYPE_PULL_UP_PAGE = 1, - EVENT_TYPE_CLOSE_PAGE = 2 -}; - -class SubscribeCallback { -public: - virtual int32_t OnSubscribeCallback(const std::string &dhId, int32_t status, const std::string &data) = 0; -}; - -class PrivacyResourcesListener { -public: - virtual int32_t OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subType, - const std::string &networkId, bool &isSensitive, bool &isSameAccout) = 0; -}; - -class IDistributedHardwareSink { -public: - virtual int32_t InitSink(const std::string ¶ms) = 0; - virtual int32_t ReleaseSink() = 0; - virtual int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶ms) = 0; - virtual int32_t UnsubscribeLocalHardware(const std::string &dhId) = 0; - virtual int32_t RegisterPrivacyResources(std::shared_ptr listener) = 0; - virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; - virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; - virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; -}; -extern "C" __attribute__((visibility("default"))) IDistributedHardwareSink* GetSinkHardwareHandler(); -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn index 9fcf62d7..feacb89b 100755 --- a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn @@ -26,7 +26,10 @@ ohos_shared_library("distributed_audio_source_sdk") { ubsan = true } stack_protector_ret = true - include_dirs = [ "//third_party/json/include" ] + include_dirs = [ + "${fwk_common_path}/utils/include", + "//third_party/json/include", + ] include_dirs += [ "include", diff --git a/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h b/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h deleted file mode 100644 index 78e2ed4d..00000000 --- a/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2021-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_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H -#define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H - -#include -#include - -namespace OHOS { -namespace DistributedHardware { -const std::string COMPONENT_LOADER_GET_SOURCE_HANDLER = "GetSourceHardwareHandler"; -class RegisterCallback { -public: - virtual int32_t OnRegisterResult(const std::string &uuid, const std::string &dhId, int32_t status, - const std::string &data) = 0; -}; - -class UnregisterCallback { -public: - virtual int32_t OnUnregisterResult(const std::string &uuid, const std::string &dhId, int32_t status, - const std::string &data) = 0; -}; - -struct EnableParam { - std::string sourceVersion; - std::string sourceAttrs; - std::string sinkVersion; - std::string sinkAttrs; - std::string subtype; -}; - -class IDistributedHardwareSource { -public: - virtual int32_t InitSource(const std::string ¶ms) = 0; - virtual int32_t ReleaseSource() = 0; - virtual int32_t RegisterDistributedHardware(const std::string &uuid, const std::string &dhId, - const EnableParam ¶m, std::shared_ptr callback) = 0; - virtual int32_t UnregisterDistributedHardware(const std::string &uuid, const std::string &dhId, - std::shared_ptr callback) = 0; - virtual int32_t ConfigDistributedHardware(const std::string &uuid, const std::string &dhId, const std::string &key, - const std::string &value) = 0; -}; -extern "C" __attribute__((visibility("default"))) IDistributedHardwareSource* GetSourceHardwareHandler(); -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 842a8575..02241542 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -29,6 +29,7 @@ ohos_shared_library("distributed_audio_sink") { include_dirs = [ "//third_party/json/include", "//third_party/cJSON", + "${fwk_common_path}/utils/include", ] include_dirs += [ diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index caf33f13..c7d2fb51 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -29,6 +29,11 @@ ohos_shared_library("distributed_audio_source") { include_dirs = [ "//third_party/json/include", "//third_party/cJSON", + "${driver_audio_path}/include", + "${fwk_common_path}/utils/include", + "${mediastandardfwk_path}/audiocapturer/include", + "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiomanager/include", ] include_dirs += [ @@ -44,6 +49,7 @@ ohos_shared_library("distributed_audio_source") { "${common_path}/dfx_utils/include", "${common_path}/include", "${distributedaudio_path}/audiohandler/include", + "${hdf_service_path}/hdi_service/common/include", "${innerkits_path}/native_cpp/audio_sink/include", "${innerkits_path}/native_cpp/audio_source/include", "${interfaces_path}/inner_kits/native_cpp/audio_sink/include", @@ -86,7 +92,6 @@ ohos_shared_library("distributed_audio_source") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", - "audio_framework:audio_capturer", "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", diff --git a/services/audiotransport/receiverengine/BUILD.gn b/services/audiotransport/receiverengine/BUILD.gn index df5377c3..98cc9aa9 100644 --- a/services/audiotransport/receiverengine/BUILD.gn +++ b/services/audiotransport/receiverengine/BUILD.gn @@ -33,7 +33,11 @@ ohos_shared_library("distributed_audio_decode_transport") { ubsan = true } stack_protector_ret = true - include_dirs = [ "//third_party/json/include" ] + include_dirs = [ + "${mediastandard_path}/interfaces/innerkits/native/media/include", + "${mediastandardfwk_path}/audiocommon/include", + "//third_party/json/include", + ] include_dirs += [ "include", diff --git a/services/audiotransport/senderengine/BUILD.gn b/services/audiotransport/senderengine/BUILD.gn index fd720530..6e18f37a 100644 --- a/services/audiotransport/senderengine/BUILD.gn +++ b/services/audiotransport/senderengine/BUILD.gn @@ -33,7 +33,11 @@ ohos_shared_library("distributed_audio_encode_transport") { ubsan = true } stack_protector_ret = true - include_dirs = [ "//third_party/json/include" ] + include_dirs = [ + "${mediastandard_path}/interfaces/innerkits/native/media/include", + "${mediastandardfwk_path}/audiocommon/include", + "//third_party/json/include", + ] include_dirs += [ "include", diff --git a/services/hdfaudioclient/BUILD.gn b/services/hdfaudioclient/BUILD.gn index a29eb55d..f702e01b 100644 --- a/services/hdfaudioclient/BUILD.gn +++ b/services/hdfaudioclient/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/ohos.gni") +import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") import("../../distributedaudio.gni") ohos_shared_library("daudio_client") { @@ -28,6 +29,7 @@ ohos_shared_library("daudio_client") { include_dirs = [ "./include", "${common_path}/include", + "${driver_audio_path}/include", ] sources = [ @@ -39,7 +41,7 @@ ohos_shared_library("daudio_client") { "./src/distributed_audio_client.cpp", ] - deps = [ "${services_path}/common:distributed_audio_utils" ] + public_deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", diff --git a/services/hdfaudioclient/include/audio_adapter.h b/services/hdfaudioclient/include/audio_adapter.h deleted file mode 100644 index 5872080a..00000000 --- a/services/hdfaudioclient/include/audio_adapter.h +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_adapter.h - * - * @brief Declares APIs for operations related to the audio adapter. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_ADAPTER_H -#define AUDIO_ADAPTER_H - -#include "audio_types.h" -#include "audio_render.h" -#include "audio_capture.h" - -/** - * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, - * and obtaining the port capability set. - * - * @see AudioRender - * @see AudioCapture - * @since 1.0 - * @version 1.0 - */ -struct AudioAdapter { - /** - * @brief Initializes all ports of an audio adapter. - * - * Call this function before calling other driver functions to check whether the initialization is complete. - * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again - * until the port initialization is complete. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @return Returns 0 if the initialization is successful; returns a negative value otherwise. - */ - int32_t (*InitAllPorts)(struct AudioAdapter *adapter); - - /** - * @brief Creates an AudioRender object. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param desc Indicates the pointer to the descriptor of the audio adapter to start. - * @param attrs Indicates the pointer to the audio sampling attributes to open. - * @param render Indicates the double pointer to the AudioRender object. - * @return Returns 0 if the AudioRender object is created successfully; - * returns a negative value otherwise. - * @see GetPortCapability - * @see DestroyRender - */ - int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, - const struct AudioSampleAttributes *attrs, struct AudioRender **render); - - /** - * @brief Destroys an AudioRender object. - * - * @attention Do not destroy the object during audio rendering. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param render Indicates the pointer to the AudioRender object to operate. - * @return Returns 0 if the AudioRender object is destroyed; returns a negative value otherwise. - * @see CreateRender - */ - int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render); - - /** - * @brief Creates an AudioCapture object. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param desc Indicates the pointer to the descriptor of the audio adapter to start. - * @param attrs Indicates the pointer to the audio sampling attributes to open. - * @param capture Indicates the double pointer to the AudioCapture object. - * @return Returns 0 if the AudioCapture object is created successfully; - * returns a negative value otherwise. - * @see GetPortCapability - * @see DestroyCapture - */ - int32_t (*CreateCapture)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, - const struct AudioSampleAttributes *attrs, struct AudioCapture **capture); - - /** - * @brief Destroys an AudioCapture object. - * - * @attention Do not destroy the object during audio capturing. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param capture Indicates the pointer to the AudioCapture object to operate. - * @return Returns 0 if the AudioCapture object is destroyed; returns a negative value otherwise. - * @see CreateCapture - */ - int32_t (*DestroyCapture)(struct AudioAdapter *adapter, struct AudioCapture *capture); - - /** - * @brief Obtains the capability set of the port driver for the audio adapter. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param port Indicates the pointer to the port. - * @param capability Indicates the pointer to the capability set to obtain. - * @return Returns 0 if the capability set is successfully obtained; returns a negative value otherwise. - */ - int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, - struct AudioPortCapability *capability); - - /** - * @brief Sets the passthrough data transmission mode of the audio port driver. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param port Indicates the pointer to the port. - * @param mode Indicates the passthrough transmission mode to set. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetPassthroughMode - */ - int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, - enum AudioPortPassthroughMode mode); - - /** - * @brief Obtains the passthrough data transmission mode of the audio port driver. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param port Indicates the pointer to the port. - * @param mode Indicates the pointer to the passthrough transmission mode to obtain. - * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. - * @see SetPassthroughMode - */ - int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, - enum AudioPortPassthroughMode *mode); - - /** - * @brief Update audio route on several source and sink ports. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param route Indicates route information. - * @param routeHandle Indicates route handle. - * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. - * @see SetPassthroughMode - */ - int32_t (*UpdateAudioRoute)(struct AudioAdapter *adapter, const struct AudioRoute *route, int32_t *routeHandle); - - /** - * @brief Release an audio route. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param routeHandle Indicates route handle. - * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. - * @see SetPassthroughMode - */ - int32_t (*ReleaseAudioRoute)(struct AudioAdapter *adapter, int32_t routeHandle); - - /** - * @brief Sets the mute operation for the audio. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param mute Specifies whether to mute the audio. Value true means to mute the audio, - * and false means the opposite. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetMute - */ - int32_t (*SetMicMute)(struct AudioAdapter *adapter, bool mute); - - /** - * @brief Obtains the mute operation set for the audio. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that - * the audio is muted, and false means the opposite. - * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. - * @see SetMute - */ - int32_t (*GetMicMute)(struct AudioAdapter *adapter, bool *mute); - - /** - * @brief Sets the audio volume for voice call. - * - * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, - * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetVolume - */ - int32_t (*SetVoiceVolume)(struct AudioAdapter *adapter, float volume); - - /** - * @brief Sets extra audio parameters. - * - * @param adapter Indicates the audio adapter. - * @param key Indicates what kind of parameter type will be set. - * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. - * @param value Indicates the value of the specified condition. - * - * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). - * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: - * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" - * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4; - * VOLUME_GROUP_ID indicates which volume group will be set; - * AUDIO_VOLUME_TYPE indicates which volume type will be set; - * - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*SetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, - const char *condition, const char *value); - - /** - * @brief Get extra audio parameters. - * - * @param adapter Indicates the audio adapter. - * @param key Indicates what kind of parameter type will be get. - * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. - * @param value Indicates the value of the specified condition. - * @param lenth Indicates the length of the value pointer. - * - * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). - * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: - * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" - * EVENT_TYPE indicates sub volume event type: GetVolume = 1; GetMinVolume = 2; GetMaxVolume = 3; IsStreamMute = 4; - * VOLUME_GROUP_ID indicates which volume group want get; - * AUDIO_VOLUME_TYPE indicates which volume type want get; - * - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, - const char *condition, char *value, int32_t lenth); - - /** - * @brief Register extra audio parameters observer. - * - * @param adapter Indicates the audio adapter. - * @param callback Indicates param observer. - * @param cookie Indicates the pointer to the callback parameters; - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*RegExtraParamObserver)(struct AudioAdapter *adapter, ParamCallback callback, void* cookie); - /** - * @brief Get the device status of an adapter. - * - * @param adapter Indicates the audio adapter. - * @param status Indicates the status of device . - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetDeviceStatus)(struct AudioAdapter *adapter, struct AudioDeviceStatus *status); -}; -#endif /* AUDIO_ADAPTER_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_attribute.h b/services/hdfaudioclient/include/audio_attribute.h deleted file mode 100644 index b5beed14..00000000 --- a/services/hdfaudioclient/include/audio_attribute.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_attribute.h - * - * @brief Declares APIs for audio attributes. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_ATTRIBUTE_H -#define AUDIO_ATTRIBUTE_H - -#include "audio_types.h" - -/** - * @brief Provides attribute-related APIs for audio rendering or capturing, including functions to - * obtain frame information and set audio sampling attributes. - * - * @since 1.0 - * @version 1.0 - */ -struct AudioAttribute { - /** - * @brief Obtains the audio frame size, that is, the length (in bytes) of a frame. - * - * @param handle Indicates the audio handle. - * @param size Indicates the pointer to the audio frame size (in bytes). - * @return Returns 0 if the audio frame size is obtained; returns a negative value otherwise. - */ - int32_t (*GetFrameSize)(AudioHandle handle, uint64_t *size); - - /** - * @brief Obtains the number of audio frames in the audio buffer. - * - * @param handle Indicates the audio handle. - * @param count Indicates the pointer to the number of audio frames in the audio buffer. - * @return Returns 0 if the number of audio frames is obtained; returns a negative value otherwise. - */ - int32_t (*GetFrameCount)(AudioHandle handle, uint64_t *count); - - /** - * @brief Sets audio sampling attributes. - * - * @param handle Indicates the audio handle. - * @param attrs Indicates the pointer to the audio sampling attributes to set, such as the sampling rate, - * sampling precision, and channel. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetSampleAttributes - */ - int32_t (*SetSampleAttributes)(AudioHandle handle, const struct AudioSampleAttributes *attrs); - - /** - * @brief Obtains audio sampling attributes. - * - * @param handle Indicates the audio handle. - * @param attrs Indicates the pointer to the audio sampling attributes, such as the sampling rate, - * sampling precision, and channel. - * @return Returns 0 if audio sampling attributes are obtained; returns a negative value otherwise. - * @see SetSampleAttributes - */ - int32_t (*GetSampleAttributes)(AudioHandle handle, struct AudioSampleAttributes *attrs); - - /** - * @brief Obtains the data channel ID of the audio. - * - * @param handle Indicates the audio handle. - * @param channelId Indicates the pointer to the data channel ID. - * @return Returns 0 if the data channel ID is obtained; returns a negative value otherwise. - */ - int32_t (*GetCurrentChannelId)(AudioHandle handle, uint32_t *channelId); - - /** - * @brief Sets extra audio parameters. - * - * @param handle Indicates the audio handle. - * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. - * The format is key=value. Separate multiple key-value pairs by semicolons (;). - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*SetExtraParams)(AudioHandle handle, const char *keyValueList); - - /** - * @brief Obtains extra audio parameters. - * - * @param handle Indicates the audio handle. - * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. - * The format is key=value. Separate multiple key-value pairs by semicolons (;). - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetExtraParams)(AudioHandle handle, char *keyValueList, int32_t listLenth); - - /** - * @brief Requests a mmap buffer. - * - * @param handle Indicates the audio handle. - * @param reqSize Indicates the size of the request mmap buffer. - * @param desc Indicates the pointer to the mmap buffer descriptor. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*ReqMmapBuffer)(AudioHandle handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc); - - /** - * @brief Obtains the read/write position of the current mmap buffer. - * - * @param handle Indicates the audio handle. - * @param frames Indicates the pointer to the frame where the read/write starts. - * @param time Indicates the pointer to the timestamp associated with the frame where the read/write starts. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetMmapPosition)(AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time); - - /** - * @brief Add the audio effect which the effectid indicated. - * - * @param handle Indicates the audio handle. - * @param effectid Indicates the audio effect instance identifier which is going to be added. - * @return Returns 0 if the audio effect were added succesffully; returns a negative value otherwise. - */ - int32_t (*AddAudioEffect)(AudioHandle handle, uint64_t effectid); - - /** - * @brief Remove the audio effect which the effectid indicated. - * - * @param handle Indicates the audio handle. - * @param effectid Indicates the audio effect which is going to be removed. - * @return Returns 0 if the audio effect were removed succesffully; returns a negative value otherwise. - */ - int32_t (*RemoveAudioEffect)(AudioHandle handle, uint64_t effectid); - - /** - * @brief Get the buffer size of render or capturer - * - * @param handle Indicates the audio handle. - * @param bufferSize Indicates the buffer size (in bytes) queried from the vendor - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetFrameBufferSize)(AudioHandle handle, uint64_t *bufferSize); -}; - -#endif /* AUDIO_ATTRIBUTE_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_capture.h b/services/hdfaudioclient/include/audio_capture.h deleted file mode 100644 index 52347aab..00000000 --- a/services/hdfaudioclient/include/audio_capture.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_capture.h - * - * @brief Declares APIs for audio capturing. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_CAPTURE_H -#define AUDIO_CAPTURE_H - -#include "audio_types.h" -#include "audio_control.h" -#include "audio_attribute.h" -#include "audio_scene.h" -#include "audio_volume.h" - -/** - * @brief Provides capabilities for audio capturing, including controlling the capturing, setting audio attributes, - * scenes, and volume, and capturing audio frames. - * - * @see AudioControl - * @see AudioAttribute - * @see AudioScene - * @see AudioVolume - * @since 1.0 - * @version 1.0 - */ -struct AudioCapture { - /** - * @brief Defines the audio control. For details, see {@link AudioControl}. - */ - struct AudioControl control; - /** - * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. - */ - struct AudioAttribute attr; - /** - * @brief Defines the audio scene. For details, see {@link AudioScene}. - */ - struct AudioScene scene; - /** - * @brief Defines audio volume. For details, see {@link AudioVolume}. - */ - struct AudioVolume volume; - - /** - * @brief Reads a frame of input data (uplink data) from the audio driver for capturing. - * - * @param capture Indicates the pointer to the AudioCapture object to operate. - * @param frame Indicates the pointer to the input data to read. - * @param requestBytes Indicates the size of the input data, in bytes. - * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to read. - * @return Returns 0 if the input data is read successfully; returns a negative value otherwise. - */ - int32_t (*CaptureFrame)(struct AudioCapture *capture, void *frame, uint64_t requestBytes, uint64_t *replyBytes); - - /** - * @brief Obtains the last number of input audio frames. - * - * @param capture Indicates the pointer to the AudioCapture object to operate. - * @param frames Indicates the pointer to the last number of input audio frames. - * @param time Indicates the pointer to the timestamp associated with the frame. - * @return Returns 0 if the last number is obtained; returns a negative value otherwise. - * @see CaptureFrame - */ - int32_t (*GetCapturePosition)(struct AudioCapture *capture, uint64_t *frames, struct AudioTimeStamp *time); -}; - -#endif /* AUDIO_CAPTURE_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_control.h b/services/hdfaudioclient/include/audio_control.h deleted file mode 100644 index a20f7875..00000000 --- a/services/hdfaudioclient/include/audio_control.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_control.h - * - * @brief Declares APIs for audio control. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_CONTROL_H -#define AUDIO_CONTROL_H - -#include "audio_types.h" - -/** - * @brief Provides control-related APIs for audio rendering or capturing, including functions to - * start, stop, pause, and resume audio rendering or capturing, and flush data in the audio buffer. - * - * @since 1.0 - * @version 1.0 - */ -struct AudioControl { - /** - * @brief Starts audio rendering or capturing. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the rendering or capturing is successfully started; - * returns a negative value otherwise. - * @see Stop - */ - int32_t (*Start)(AudioHandle handle); - - /** - * @brief Stops audio rendering or capturing. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the rendering or capturing is successfully stopped; - * returns a negative value otherwise. - * @see Start - */ - int32_t (*Stop)(AudioHandle handle); - - /** - * @brief Pauses audio rendering or capturing. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the rendering or capturing is successfully paused; - * returns a negative value otherwise. - * @see Resume - */ - int32_t (*Pause)(AudioHandle handle); - - /** - * @brief Resumes audio rendering or capturing. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the rendering or capturing is successfully resumed; - * returns a negative value otherwise. - * @see Pause - */ - int32_t (*Resume)(AudioHandle handle); - - /** - * @brief Flushes data in the audio buffer. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the flush is successful; returns a negative value otherwise. - */ - int32_t (*Flush)(AudioHandle handle); - - /** - * @brief Sets or cancels the standby mode of the audio device. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the device is set to standby mode; returns a positive value if the standby mode is - * canceled; returns a negative value if the setting fails. - */ - int32_t (*TurnStandbyMode)(AudioHandle handle); - - /** - * @brief Dumps information about the audio device. - * - * @param handle Indicates the audio handle. - * @param range Indicates the range of the device information to dump, which can be brief or full information. - * @param fd Indicates the file to which the device information will be dumped. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*AudioDevDump)(AudioHandle handle, int32_t range, int32_t fd); - - /** - * @brief Query whether the vendor support pause and resume. - * - * @param handle Indicates the audio handle. - * @param supportPause Indicates the state whether the vendor supports pausing. Value true means that - * the vendor supports, and false means the opposite. - * @param supportResume Indicates the state whether the vendor supports resuming. Value true means that - * the vendor supports, and false means the opposite. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - * @see IsSupportsPauseAndResume - */ - int32_t (*IsSupportsPauseAndResume)(AudioHandle handle, bool *supportPause, bool *supportResume); -}; - -#endif /* AUDIO_CONTROL_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_manager.h b/services/hdfaudioclient/include/audio_manager.h deleted file mode 100644 index f952dc3c..00000000 --- a/services/hdfaudioclient/include/audio_manager.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_manager.h - * - * @brief Declares APIs for audio adapter management and loading. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_MANAGER_H -#define AUDIO_MANAGER_H - -#include "audio_types.h" -#include "audio_adapter.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Manages audio adapters through a specific adapter driver program loaded based on the given audio - * adapter descriptor. - * - * @see AudioAdapter - * @since 1.0 - * @version 1.0 - */ -struct AudioManager { - /** - * @brief Obtains the list of all adapters supported by an audio driver. - * - * @param manager Indicates the pointer to the audio adapter manager to operate. - * @param descs Indicates the double pointer to the audio adapter list. - * @param size Indicates the pointer to the length of the list. - * @return Returns 0 if the list is obtained successfully; returns a negative value otherwise. - * @see LoadAdapter - */ - int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size); - - /** - * @brief Loads the driver for an audio adapter. - * - * For example, to load a USB driver, you may need to load a dynamic-link library (*.so) in specific implementation. - * - * @param manager Indicates the pointer to the audio adapter manager to operate. - * @param desc Indicates the pointer to the descriptor of the audio adapter. - * @param adapter Indicates the double pointer to the audio adapter. - * @return Returns 0 if the driver is loaded successfully; returns a negative value otherwise. - * @see GetAllAdapters - * @see UnloadAdapter - */ - int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc, - struct AudioAdapter **adapter); - - /** - * @brief Unloads the driver of an audio adapter. - * - * @param manager Indicates the pointer to the audio adapter manager to operate. - * @param adapter Indicates the pointer to the audio adapter whose driver will be unloaded. - * @see LoadAdapter - */ - void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter); - - /** - * @brief Release the AudioManager Object. - * - * @param object Indicates the pointer to the audio adapter manager to operate. - * @return Returns true if the Object is released; returns false otherwise. - */ - bool (*ReleaseAudioManagerObject)(struct AudioManager *object); -}; - -/** - * @brief Obtains the operation function list of the {@link AudioManager} class. - * - * @return Returns the pointer to the AudioManager object if the list is obtained; returns NULL otherwise. - */ -struct AudioManager *GetAudioManagerFuncs(void); - -#ifdef __cplusplus -} -#endif - -#endif /* AUDIO_MANAGER_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_render.h b/services/hdfaudioclient/include/audio_render.h deleted file mode 100644 index 1627fe62..00000000 --- a/services/hdfaudioclient/include/audio_render.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_render.h - * - * @brief Declares APIs for audio rendering. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_RENDER_H -#define AUDIO_RENDER_H - -#include "audio_types.h" -#include "audio_control.h" -#include "audio_attribute.h" -#include "audio_scene.h" -#include "audio_volume.h" - -/** - * @brief Provides capabilities for audio rendering, including controlling the rendering, setting audio attributes, - * scenes, and volume, obtaining hardware latency, and rendering audio frames. - * - * @see AudioControl - * @see AudioAttribute - * @see AudioScene - * @see AudioVolume - * @since 1.0 - * @version 1.0 - */ -struct AudioRender { - /** - * @brief Defines the audio control. For details, see {@link AudioControl}. - */ - struct AudioControl control; - /** - * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. - */ - struct AudioAttribute attr; - /** - * @brief Defines the audio scene. For details, see {@link AudioScene}. - */ - struct AudioScene scene; - /** - * @brief Defines audio volume. For details, see {@link AudioVolume}. - */ - struct AudioVolume volume; - - /** - * @brief Obtains the estimated latency of the audio device driver. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param ms Indicates the pointer to the latency (in milliseconds) to be obtained. - * @return Returns 0 if the latency is obtained; returns a negative value otherwise. - */ - int32_t (*GetLatency)(struct AudioRender *render, uint32_t *ms); - - /** - * @brief Writes a frame of output data (downlink data) into the audio driver for rendering. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param frame Indicates the pointer to the frame to write. - * @param requestBytes Indicates the size of the frame, in bytes. - * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to write. - * @return Returns 0 if the data is written successfully; returns a negative value otherwise. - */ - int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes); - - /** - * @brief Obtains the last number of output audio frames. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param frames Indicates the pointer to the last number of output audio frames. - * @param time Indicates the pointer to the timestamp associated with the frame. - * @return Returns 0 if the last number is obtained; returns a negative value otherwise. - * @see RenderFrame - */ - int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time); - - /** - * @brief Sets the audio rendering speed. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param speed Indicates the rendering speed to set. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetRenderSpeed - */ - int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed); - - /** - * @brief Obtains the current audio rendering speed. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param speed Indicates the pointer to the current rendering speed to obtain. - * @return Returns 0 if the speed is successfully obtained; returns a negative value otherwise. - * @see SetRenderSpeed - */ - int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed); - - /** - * @brief Sets the channel mode for audio rendering. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param mode Indicates the channel mode to set. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetChannelMode - */ - int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode); - - /** - * @brief Obtains the current channel mode for audio rendering. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param mode Indicates the pointer to the channel mode to obtain. - * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. - * @see SetChannelMode - */ - int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode); - - /** - * @brief Registers an audio callback that will be invoked during playback when buffer data writing or - * buffer drain is complete. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param callback Indicates the callback to register. - * @param cookie Indicates the pointer to the callback parameters. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - * @see RegCallback - */ - int32_t (*RegCallback)(struct AudioRender *render, RenderCallback callback, void* cookie); - - /** - * @brief Drains the buffer. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param type Indicates the pointer to the execution type of this function. For details, - * see {@link AudioDrainNotifyType}. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - * @see RegCallback - */ - int32_t (*DrainBuffer)(struct AudioRender *render, enum AudioDrainNotifyType *type); - - /** - * @brief query whether the vendor supports draining buffer - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param support indicates the state whether the vendor supports draining buffer. Value true means that - * the vendor supports, and false means the opposite. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - * @see IsSupportsDrain - */ - int32_t (*IsSupportsDrain)(struct AudioRender *render, bool *support); -}; - -#endif /* AUDIO_RENDER_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_scene.h b/services/hdfaudioclient/include/audio_scene.h deleted file mode 100644 index e6ef9f90..00000000 --- a/services/hdfaudioclient/include/audio_scene.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_scene.h - * - * @brief Declares APIs for audio scenes. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_SCENE_H -#define AUDIO_SCENE_H - -#include "audio_types.h" - -/** - * @brief Provides scene-related APIs for audio rendering or capturing, including functions to - * select an audio scene and check whether the configuration of an audio scene is supported. - * - * @since 1.0 - * @version 1.0 - */ -struct AudioScene { - /** - * @brief Checks whether the configuration of an audio scene is supported. - * - * @param handle Indicates the audio handle. - * @param scene Indicates the pointer to the descriptor of the audio scene. - * @param supported Indicates the pointer to the variable specifying whether the configuration is supported. - * Value true means that the configuration is supported, and false means the opposite. - * @return Returns 0 if the result is obtained; returns a negative value otherwise. - * @see SelectScene - */ - int32_t (*CheckSceneCapability)(AudioHandle handle, const struct AudioSceneDescriptor *scene, bool *supported); - - /** - * @brief Selects an audio scene. - * - *
    - *
  • To select a specific audio scene, you need to specify both the application scenario and output device. - * For example, to select a scene using a smartphone speaker as the output device, set scene according - * to the scenarios where the speaker is used. For example:
  • - *
      - *
    • For media playback, set the value to media_speaker.
    • - *
    • For a voice call, set the value to voice_speaker.
    • - *
    - *
  • To select only the application scenario, such as media playback, movie, or gaming, you can set - * scene to media, movie, or game, respectively.
  • - *
  • To select only the output device, such as media receiver, speaker, or headset, you can set - * scene to receiver, speaker, or headset, respectively.
  • - *
- * @param handle Indicates the audio handle. - * @param scene Indicates the pointer to the descriptor of the audio scene to select. - * @return Returns 0 if the scene is selected successfully; returns a negative value otherwise. - * @see CheckSceneCapability - */ - int32_t (*SelectScene)(AudioHandle handle, const struct AudioSceneDescriptor *scene); -}; - -#endif /* AUDIO_SCENE_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_types.h b/services/hdfaudioclient/include/audio_types.h deleted file mode 100644 index 76662f99..00000000 --- a/services/hdfaudioclient/include/audio_types.h +++ /dev/null @@ -1,487 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_types.h - * - * @brief Defines custom data types used in API declarations for the audio module, including audio ports, - * adapter descriptors, device descriptors, scene descriptors, sampling attributes, and timestamp. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_TYPES_H -#define AUDIO_TYPES_H - -#include -#include - -/** - * @brief Defines the audio handle. - */ -typedef void *AudioHandle; - -/** - * @brief Enumerates the audio port type. - */ -enum AudioPortDirection { - PORT_OUT = 0x1u, /**< Output port */ - PORT_IN = 0x2u, /**< Input port */ - PORT_OUT_IN = 0x3u, /**< Input/output port, supporting both audio input and output */ -}; - -/** - * @brief Defines the audio port. - */ -struct AudioPort { - enum AudioPortDirection dir; /**< Audio port type. For details, see {@link AudioPortDirection} */ - uint32_t portId; /**< Audio port ID */ - const char *portName; /**< Audio port name */ -}; - -/** - * @brief Defines the audio adapter descriptor. - * - * An audio adapter is a set of port drivers for a sound card, including the output and input ports. - * One port corresponds to multiple pins, and each pin belongs to a physical component (such as a - * speaker or a wired headset). - */ -struct AudioAdapterDescriptor { - const char *adapterName; /**< Name of the audio adapter */ - uint32_t portNum; /**< Number of ports supported by an audio adapter */ - struct AudioPort *ports; /**< List of ports supported by an audio adapter */ -}; - -/** - * @brief Enumerates the pin of an audio adapter. - */ -enum AudioPortPin { - PIN_NONE = 0x0u, /**< Invalid pin */ - PIN_OUT_SPEAKER = 0x1u, /**< Speaker output pin */ - PIN_OUT_HEADSET = 0x2u, /**< Wired headset pin for output */ - PIN_OUT_LINEOUT = 0x4u, /**< Line-out pin */ - PIN_OUT_HDMI = 0x8u, /**< HDMI output pin */ - PIN_OUT_USB = 0x10u, /**< USB output pin */ - PIN_OUT_USB_EXT = 0x20u, /**< Extended USB output pin*/ - PIN_OUT_EARPIECE = 0x30u, /**< Earpiece output pin */ - PIN_OUT_BLUETOOTH_SCO = 0x40u, /**< Bluetooth SCO output pin */ - PIN_OUT_DAUDIO_DEFAULT = 0x80u, - PIN_OUT_HEADPHONE = 0x100u, /**< Wired headphone output pin*/ - PIN_OUT_USB_HEADSET = 0x200u, /**< ARM USB out pin */ - PIN_IN_MIC = 0x8000001u, /**< Microphone input pin */ - PIN_IN_HS_MIC = 0x8000002u, /**< Wired headset microphone pin for input */ - PIN_IN_LINEIN = 0x8000004u, /**< Line-in pin */ - PIN_IN_USB_EXT = 0x8000008u, /**< Extended USB input pin*/ - PIN_IN_BLUETOOTH_SCO_HEADSET = 0x8000010u, /**< Bluetooth SCO headset input pin */ - PIN_IN_USB_HEADSET = 0x8000040u, /**< ARM USB input pin */ -}; - -/** - * @brief Defines the audio device descriptor. - */ -struct AudioDeviceDescriptor { - uint32_t portId; /**< Audio port ID */ - enum AudioPortPin pins; /**< Pins of audio ports (input and output). For details, see {@link AudioPortPin}. */ - const char *desc; /**< Audio device name */ -}; - -/** - * @brief Enumerates the audio category. - */ -enum AudioCategory { - AUDIO_IN_MEDIA = 0, /**< Media */ - AUDIO_IN_COMMUNICATION, /**< Communications */ - AUDIO_IN_RINGTONE, /**< Ringtone */ - AUDIO_IN_CALL, /**< Call */ - AUDIO_MMAP_NOIRQ, /**< Mmap mode */ -}; - -/** - * @brief Defines the audio scene descriptor. - */ -struct AudioSceneDescriptor { - /** - * @brief Describes the audio scene. - */ - union SceneDesc { - uint32_t id; /**< Audio scene ID */ - const char *desc; /**< Name of the audio scene */ - } scene; /**< The scene object */ - struct AudioDeviceDescriptor desc; /**< Audio device descriptor */ -}; - -/** - * @brief Enumerates the audio format. - */ -enum AudioFormat { - AUDIO_FORMAT_TYPE_PCM_8_BIT = 0x1u, /**< 8-bit PCM */ - AUDIO_FORMAT_TYPE_PCM_16_BIT = 0x2u, /**< 16-bit PCM */ - AUDIO_FORMAT_TYPE_PCM_24_BIT = 0x3u, /**< 24-bit PCM */ - AUDIO_FORMAT_TYPE_PCM_32_BIT = 0x4u, /**< 32-bit PCM */ - AUDIO_FORMAT_TYPE_AAC_MAIN = 0x1000001u, /**< AAC main */ - AUDIO_FORMAT_TYPE_AAC_LC = 0x1000002u, /**< AAC LC */ - AUDIO_FORMAT_TYPE_AAC_LD = 0x1000003u, /**< AAC LD */ - AUDIO_FORMAT_TYPE_AAC_ELD = 0x1000004u, /**< AAC ELD */ - AUDIO_FORMAT_TYPE_AAC_HE_V1 = 0x1000005u, /**< AAC HE_V1 */ - AUDIO_FORMAT_TYPE_AAC_HE_V2 = 0x1000006u, /**< AAC HE_V2 */ - AUDIO_FORMAT_TYPE_G711A = 0x2000001u, /**< G711A */ - AUDIO_FORMAT_TYPE_G711U = 0x2000002u, /**< G711u */ - AUDIO_FORMAT_TYPE_G726 = 0x2000003u, /**< G726 */ -}; - -/** - * @brief Enumerates the audio channel mask. - * - * A mask describes an audio channel position. - */ -enum AudioChannelMask { - AUDIO_CHANNEL_MONO = 1u, /**< Mono channel */ - AUDIO_CHANNEL_FRONT_LEFT = 1u, /**< Front left channel */ - AUDIO_CHANNEL_FRONT_RIGHT = 2u, /**< Front right channel */ - AUDIO_CHANNEL_FRONT_CENTER = 4u, /**< Front right channel */ - AUDIO_CHANNEL_LOW_FREQUENCY = 8u, /**< 0x8 */ - AUDIO_CHANNEL_BACK_LEFT = 16u, /**< 0x10 */ - AUDIO_CHANNEL_BACK_RIGHT = 32u, /**< 0x20 */ - AUDIO_CHANNEL_BACK_CENTER = 256u, /**< 0x100 */ - AUDIO_CHANNEL_SIDE_LEFT = 512u, /**< 0x200 */ - AUDIO_CHANNEL_SIDE_RIGHT = 1024u, /**< 0x400 */ - AUDIO_CHANNEL_TOP_SIDE_LEFT = 262144u, /**< 0x40000 */ - AUDIO_CHANNEL_TOP_SIDE_RIGHT = 524288u, /**< 0x80000 */ - AUDIO_CHANNEL_STEREO = 3u, /**< FRONT_LEFT | FRONT_RIGHT */ - AUDIO_CHANNEL_2POINT1 = 11u, /**< STEREO | LOW_FREQUENCY */ - AUDIO_CHANNEL_QUAD = 51u, /**< STEREO | BACK_LEFT | BACK_RIGHT */ - AUDIO_CHANNEL_3POINT0POINT2 = 786439u, /**< STEREO | FRONT_CENTER | TOP_SIDE_LEFT | TOP_SIDE_RIGHT */ - AUDIO_CHANNEL_5POINT1 = 63u, /**< QUAD | FRONT_CENTER | LOW_FREQUENCY */ - AUDIO_CHANNEL_6POINT1 = 319u, /**< AUDIO_CHANNEL_5POINT1 | BACK_CENTER */ - AUDIO_CHANNEL_7POINT1 = 1599u, /**< AUDIO_CHANNEL_5POINT1 | SIDE_LEFT | SIDE_RIGHT */ -}; - -/** - * @brief Enumerates masks of audio sampling rates. - */ -enum AudioSampleRatesMask { - AUDIO_SAMPLE_RATE_MASK_8000 = 0x1u, /**< 8 kHz */ - AUDIO_SAMPLE_RATE_MASK_12000 = 0x2u, /**< 12 kHz */ - AUDIO_SAMPLE_RATE_MASK_11025 = 0x4u, /**< 11.025 kHz */ - AUDIO_SAMPLE_RATE_MASK_16000 = 0x8u, /**< 16 kHz */ - AUDIO_SAMPLE_RATE_MASK_22050 = 0x10u, /**< 22.050 kHz */ - AUDIO_SAMPLE_RATE_MASK_24000 = 0x20u, /**< 24 kHz */ - AUDIO_SAMPLE_RATE_MASK_32000 = 0x40u, /**< 32 kHz */ - AUDIO_SAMPLE_RATE_MASK_44100 = 0x80u, /**< 44.1 kHz */ - AUDIO_SAMPLE_RATE_MASK_48000 = 0x100u, /**< 48 kHz */ - AUDIO_SAMPLE_RATE_MASK_64000 = 0x200u, /**< 64 kHz */ - AUDIO_SAMPLE_RATE_MASK_96000 = 0x400u, /**< 96 kHz */ - AUDIO_SAMPLE_RATE_MASK_INVALID = 0xFFFFFFFFu, /**< Invalid sampling rate */ -}; -enum AudioInputType { - AUDIO_INPUT_DEFAULT_TYPE = 0, - AUDIO_INPUT_MIC_TYPE = 1 << 0, - AUDIO_INPUT_SPEECH_WAKEUP_TYPE = 1 << 1, - AUDIO_INPUT_VOICE_COMMUNICATION_TYPE = 1 << 2, - AUDIO_INPUT_VOICE_RECOGNITION_TYPE = 1 << 3, -}; -/** - * @brief Defines audio sampling attributes. - */ -struct AudioSampleAttributes { - enum AudioCategory type; /**< Audio type. For details, see {@link AudioCategory} */ - bool interleaved; /**< Interleaving flag of audio data */ - enum AudioFormat format; /**< Audio data format. For details, see {@link AudioFormat}. */ - uint32_t sampleRate; /**< Audio sampling rate */ - uint32_t channelCount; /**< Number of audio channels. For example, for the mono channel, the value is 1, - * and for the stereo channel, the value is 2. - */ - uint32_t period; /**< Audio sampling period */ - uint32_t frameSize; /**< Frame size of the audio data */ - bool isBigEndian; /**< Big endian flag of audio data */ - bool isSignedData; /**< Signed or unsigned flag of audio data */ - uint32_t startThreshold; /**< Audio render start threshold. */ - uint32_t stopThreshold; /**< Audio render stop threshold. */ - uint32_t silenceThreshold; /**< Audio capture buffer threshold. */ - int32_t streamId; /**< Audio Identifier of render or capture */ - int32_t sourceType; -}; - -/** - * @brief Defines the audio timestamp, which is a substitute for POSIX timespec. - */ -struct AudioTimeStamp { - int64_t tvSec; /**< Seconds */ - int64_t tvNSec; /**< Nanoseconds */ -}; - -/** - * @brief Enumerates the passthrough data transmission mode of an audio port. - */ -enum AudioPortPassthroughMode { - PORT_PASSTHROUGH_LPCM = 0x1, /**< Stereo PCM */ - PORT_PASSTHROUGH_RAW = 0x2, /**< HDMI passthrough */ - PORT_PASSTHROUGH_HBR2LBR = 0x4, /**< Blu-ray next-generation audio output with reduced specifications */ - PORT_PASSTHROUGH_AUTO = 0x8, /**< Mode automatically matched based on the HDMI EDID */ -}; - -/** - * @brief Defines the sub-port capability. - */ -struct AudioSubPortCapability { - uint32_t portId; /**< Sub-port ID */ - const char *desc; /**< Sub-port name */ - enum AudioPortPassthroughMode mask; /**< Passthrough mode of data transmission. For details, - * see {@link AudioPortPassthroughMode}. - */ -}; - -/** - * @brief Defines formats of raw audio samples. - */ -enum AudioSampleFormat { - /* 8 bits */ - AUDIO_SAMPLE_FORMAT_S8, /**< signed 8 bit sample */ - AUDIO_SAMPLE_FORMAT_S8P, /**< signed 8 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U8, /**< unsigned 8 bit sample */ - AUDIO_SAMPLE_FORMAT_U8P, /**< unsigned 8 bit planar sample */ - /* 16 bits */ - AUDIO_SAMPLE_FORMAT_S16, /**< signed 16 bit sample */ - AUDIO_SAMPLE_FORMAT_S16P, /**< signed 16 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U16, /**< unsigned 16 bit sample */ - AUDIO_SAMPLE_FORMAT_U16P, /**< unsigned 16 bit planar sample */ - /* 24 bits */ - AUDIO_SAMPLE_FORMAT_S24, /**< signed 24 bit sample */ - AUDIO_SAMPLE_FORMAT_S24P, /**< signed 24 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U24, /**< unsigned 24 bit sample */ - AUDIO_SAMPLE_FORMAT_U24P, /**< unsigned 24 bit planar sample */ - /* 32 bits */ - AUDIO_SAMPLE_FORMAT_S32, /**< signed 32 bit sample */ - AUDIO_SAMPLE_FORMAT_S32P, /**< signed 32 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U32, /**< unsigned 32 bit sample */ - AUDIO_SAMPLE_FORMAT_U32P, /**< unsigned 32 bit planar sample */ - /* 64 bits */ - AUDIO_SAMPLE_FORMAT_S64, /**< signed 64 bit sample */ - AUDIO_SAMPLE_FORMAT_S64P, /**< signed 64 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U64, /**< unsigned 64 bit sample */ - AUDIO_SAMPLE_FORMAT_U64P, /**< unsigned 64 bit planar sample */ - /* float double */ - AUDIO_SAMPLE_FORMAT_F32, /**< float 32 bit sample */ - AUDIO_SAMPLE_FORMAT_F32P, /**< float 32 bit planar sample */ - AUDIO_SAMPLE_FORMAT_F64, /**< double 64 bit sample */ - AUDIO_SAMPLE_FORMAT_F64P, /**< double 64 bit planar sample */ -}; - -/** - * @brief Defines the audio port capability. - */ -struct AudioPortCapability { - uint32_t deviceType; /**< Device type (output or input) */ - uint32_t deviceId; /**< Device ID used for device binding */ - bool hardwareMode; /**< Whether to support device binding */ - uint32_t formatNum; /**< Number of the supported audio formats */ - enum AudioFormat *formats; /**< Supported audio formats. For details, see {@link AudioFormat}. */ - uint32_t sampleRateMasks; /**< Supported audio sampling rates (8 kHz, 16 kHz, 32 kHz, and 48 kHz) */ - enum AudioChannelMask channelMasks; /**< Audio channel layout mask of the device. For details, - * see {@link AudioChannelMask}. - */ - uint32_t channelCount; /**< Supported maximum number of audio channels */ - uint32_t subPortsNum; /**< Number of supported sub-ports (for output devices only) */ - struct AudioSubPortCapability *subPorts; /**< List of supported sub-ports */ - uint32_t supportSampleFormatNum; /**< Number of the supported audio sample format enum. */ - enum AudioSampleFormat *supportSampleFormats; /**< Supported audio sample formats. For details, - * see {@link AudioSampleFormat}. - */ -}; - -/** - * @brief Enumerates channel modes for audio rendering. - * - * @attention The following modes are set for rendering dual-channel audios. Others are not supported. - */ -enum AudioChannelMode { - AUDIO_CHANNEL_NORMAL = 0, /**< Normal mode. No processing is required. */ - AUDIO_CHANNEL_BOTH_LEFT, /**< Two left channels */ - AUDIO_CHANNEL_BOTH_RIGHT, /**< Two right channels */ - AUDIO_CHANNEL_EXCHANGE, /**< Data exchange between the left and right channels. The left channel takes the audio - * stream of the right channel, and the right channel takes that of the left channel. - */ - AUDIO_CHANNEL_MIX, /**< Mix of streams of the left and right channels */ - AUDIO_CHANNEL_LEFT_MUTE, /**< Left channel muted. The stream of the right channel is output. */ - AUDIO_CHANNEL_RIGHT_MUTE, /**< Right channel muted. The stream of the left channel is output. */ - AUDIO_CHANNEL_BOTH_MUTE, /**< Both left and right channels muted */ -}; - -/** - * @brief Enumerates the execution types of the DrainBuffer function. - */ -enum AudioDrainNotifyType { - AUDIO_DRAIN_NORMAL_MODE, /**< The DrainBuffer function returns after all data finishes playback. */ - AUDIO_DRAIN_EARLY_MODE, /**< The DrainBuffer function returns before all the data of the current track - * finishes playback to reserve time for a smooth track switch by the audio service. - */ -}; - -/** - * @brief Enumerates callback notification events. - */ -enum AudioCallbackType { - AUDIO_NONBLOCK_WRITE_COMPLETED, /**< The non-block write is complete. */ - AUDIO_DRAIN_COMPLETED, /**< The draining is complete. */ - AUDIO_FLUSH_COMPLETED, /**< The flush is complete. */ - AUDIO_RENDER_FULL, /**< The render buffer is full.*/ - AUDIO_ERROR_OCCUR, /**< An error occurs.*/ -}; - -/** - * @brief Describes a mmap buffer. - */ -struct AudioMmapBufferDescriptor { - void *memoryAddress; /**< Pointer to the mmap buffer */ - int32_t memoryFd; /**< File descriptor of the mmap buffer */ - int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/ - int32_t transferFrameSize; /**< Transfer size (unit: frame) */ - int32_t isShareable; /**< Whether the mmap buffer can be shared among processes */ - uint32_t offset; -}; - -/** - * @brief Describes AudioPortRole. - */ -enum AudioPortRole { - AUDIO_PORT_UNASSIGNED_ROLE = 0, /**< Unassigned port role */ - AUDIO_PORT_SOURCE_ROLE = 1, /**< Assigned source role */ - AUDIO_PORT_SINK_ROLE = 2, /**< Assigned sink role */ -}; - -/** - * @brief Describes AudioPortType. - */ -enum AudioPortType { - AUDIO_PORT_UNASSIGNED_TYPE = 0, /**< Unassigned port type */ - AUDIO_PORT_DEVICE_TYPE = 1, /**< Assigned device type */ - AUDIO_PORT_MIX_TYPE = 2, /**< Assigned mix type */ - AUDIO_PORT_SESSION_TYPE = 3, /**< Assigned session type */ -}; - -/** - * @brief Describes AudioDevExtInfo. - */ -struct AudioDevExtInfo { - int32_t moduleId; /**< Identifier of the module stream is attached to */ - enum AudioPortPin type; /**< Device type For details, see {@link AudioPortPin}. */ - const char *desc; /**< Address */ -}; - -/** - * @brief Describes AudioMixInfo. - */ -struct AudioMixExtInfo { - int32_t moduleId; /**< Identifier of the module stream is attached to */ - int32_t streamId; /**< Identifier of the capture or render passed by caller */ -}; - -/** - * @brief Describes AudioSessionType. - */ -enum AudioSessionType { - AUDIO_OUTPUT_STAGE_SESSION = 0, - AUDIO_OUTPUT_MIX_SESSION, - AUDIO_ALLOCATE_SESSION, - AUDIO_INVALID_SESSION, -}; - -/** - * @brief Describes AudioSessionExtInfo. - */ -struct AudioSessionExtInfo { - enum AudioSessionType sessionType; -}; - -/** - * @brief Describes AudioRouteNode. - */ -struct AudioRouteNode { - int32_t portId; /**< Audio port ID */ - enum AudioPortRole role; /**< Audio port as a sink or a source */ - enum AudioPortType type; /**< device, mix ... */ - union { - struct AudioDevExtInfo device; /* Specific Device Ext info */ - struct AudioMixExtInfo mix; /* Specific mix info */ - struct AudioSessionExtInfo session; /* session specific info */ - } ext; -}; - -/** - * @brief Describes AudioRoute. - */ -struct AudioRoute { - uint32_t sourcesNum; - const struct AudioRouteNode *sources; - uint32_t sinksNum; - const struct AudioRouteNode *sinks; -}; - -/** - * @brief Enumerates the restricted key type of the parameters - */ -enum AudioExtParamKey { - AUDIO_EXT_PARAM_KEY_NONE = 0, /**< Distributed audio extra param key none */ - AUDIO_EXT_PARAM_KEY_VOLUME = 1, /**< Distributed audio extra param key volume event */ - AUDIO_EXT_PARAM_KEY_FOCUS = 2, /**< Distributed audio extra param key focus event */ - AUDIO_EXT_PARAM_KEY_BUTTON = 3, /**< Distributed audio extra param key media button event */ - AUDIO_EXT_PARAM_KEY_EFFECT = 4, /**< Distributed audio extra param key audio effect event */ - AUDIO_EXT_PARAM_KEY_STATUS = 5, /**< Distributed audio extra param key device status event */ - AUDIO_EXT_PARAM_KEY_USB_DEVICE = 101, /**< Check USB device type ARM or HIFI */ - AUDIO_EXT_PARAM_KEY_LOWPOWER = 1000, /**< Low power event type */ -}; -/** - * @brief Describes status of audio deivce.@link enum AudioDeviceType - */ -struct AudioDeviceStatus { - uint32_t pnpStatus; -}; -/** - * @brief Called when an event defined in {@link AudioCallbackType} occurs. - * - * @param AudioCallbackType Indicates the occurred event that triggers this callback. - * @param reserved Indicates the pointer to a reserved field. - * @param cookie Indicates the pointer to the cookie for data transmission. - * @return Returns 0 if the callback is successfully executed; returns a negative value otherwise. - * @see RegCallback - */ -typedef int32_t (*RenderCallback)(enum AudioCallbackType, void *reserved, void *cookie); - -/** - * @brief Register audio extra param callback that will be invoked during audio param event. - * - * @param key Indicates param change event. - * @param condition Indicates the param condition. - * @param value Indicates the param value. - * @param reserved Indicates reserved param. - * @param cookie Indicates the pointer to the callback parameters; - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ -typedef int32_t (*ParamCallback)(enum AudioExtParamKey key, const char *condition, const char *value, void *reserved, - void *cookie); - -#endif /* AUDIO_TYPES_H */ diff --git a/services/hdfaudioclient/include/audio_volume.h b/services/hdfaudioclient/include/audio_volume.h deleted file mode 100644 index ad476f7c..00000000 --- a/services/hdfaudioclient/include/audio_volume.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2020-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. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_volume.h - * - * @brief Declares APIs for audio volume. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_VOLUME_H -#define AUDIO_VOLUME_H - -#include "audio_types.h" - -/** - * @brief Provides volume-related APIs for audio rendering or capturing, including functions to - * set the mute operation, volume, and gain. - * - * @since 1.0 - * @version 1.0 - */ -struct AudioVolume { - /** - * @brief Sets the mute operation for the audio. - * - * @param handle Indicates the audio handle. - * @param mute Specifies whether to mute the audio. Value true means to mute the audio, - * and false means the opposite. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetMute - */ - int32_t (*SetMute)(AudioHandle handle, bool mute); - - /** - * @brief Obtains the mute operation set for the audio. - * - * @param handle Indicates the audio handle. - * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that - * the audio is muted, and false means the opposite. - * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. - * @see SetMute - */ - int32_t (*GetMute)(AudioHandle handle, bool *mute); - - /** - * @brief Sets the audio volume. - * - * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, - * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). - * - * @param handle Indicates the audio handle. - * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetVolume - */ - int32_t (*SetVolume)(AudioHandle handle, float volume); - - /** - * @brief Obtains the audio volume. - * - * @param handle Indicates the audio handle. - * @param volume Indicates the pointer to the volume to obtain. The value ranges from 0.0 to 1.0. - * @return Returns 0 if the volume is obtained; returns a negative value otherwise. - * @see SetVolume - */ - int32_t (*GetVolume)(AudioHandle handle, float *volume); - - /** - * @brief Obtains the range of the audio gain. - * - * The audio gain can be expressed in one of the following two ways (depending on the chip platform), - * corresponding to two types of value ranges: - *
    - *
  • Actual audio gain values, for example, ranging from -50 to 6 dB
  • - *
  • Float numbers ranging from 0.0 to 1.0, where 0.0 means to mute the audio, - * and 1.0 means the maximum gain value, for example, 6 dB
  • - *
- * @param handle Indicates the audio handle. - * @param min Indicates the pointer to the minimum value of the range. - * @param max Indicates the pointer to the maximum value of the range. - * @return Returns 0 if the range is obtained; returns a negative value otherwise. - * @see GetGain - * @see SetGain - */ - int32_t (*GetGainThreshold)(AudioHandle handle, float *min, float *max); - - /** - * @brief Obtains the audio gain. - * - * @param handle Indicates the audio handle. - * @param gain Indicates the pointer to the audio gain. - * @return Returns 0 if the audio gain is obtained; returns a negative value otherwise. - * @see GetGainThreshold - * @see SetGain - */ - int32_t (*GetGain)(AudioHandle handle, float *gain); - - /** - * @brief Sets the audio gain. - * - * @param handle Indicates the audio handle. - * @param gain Indicates the audio gain to set. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetGainThreshold - * @see GetGain - */ - int32_t (*SetGain)(AudioHandle handle, float gain); -}; - -#endif /* AUDIO_VOLUME_H */ -/** @} */ diff --git a/services/test_example/BUILD.gn b/services/test_example/BUILD.gn index 6238bddd..d207d120 100644 --- a/services/test_example/BUILD.gn +++ b/services/test_example/BUILD.gn @@ -23,6 +23,8 @@ ohos_executable("audio_distributed_test") { include_dirs = [ "./include", + "${driver_audio_path}/include", + "${hdf_service_path}/hdi_service/common/include", "${services_path}/hdfaudioclient/include", ] diff --git a/services/test_example/daudio_errcode.h b/services/test_example/daudio_errcode.h deleted file mode 100644 index b408d569..00000000 --- a/services/test_example/daudio_errcode.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022-2023 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_ERRCODE_H -#define OHOS_DAUDIO_ERRCODE_H - -namespace OHOS { -namespace DistributedHardware { -enum DAudioErrorCode { - DH_SUCCESS = 0, - // Distributed Audio HDF Error Code - ERR_DH_AUDIO_HDF_FAIL = -46001, - ERR_DH_AUDIO_HDF_NULLPTR = -46002, - ERR_DH_AUDIO_HDF_INVALID_PARAM = -46003, - ERR_DH_AUDIO_HDF_REPEAT_OPERATION = -46004, - ERR_DH_AUDIO_HDF_INVALID_OPERATION = -46005, - ERR_DH_AUDIO_HDF_SET_PARAM_FAIL = -46006, - ERR_DH_AUDIO_HDF_OPEN_DEVICE_FAIL = -46007, - ERR_DH_AUDIO_HDF_CLOSE_DEVICE_FAIL = -46008, - ERR_DH_AUDIO_COMMON_NOT_FOUND_KEY = -46009, - ERR_DH_AUDIO_HDF_WAIT_TIMEOUT = -46010, - - ERR_DH_AUDIO_HDF_INIT_ENGINE_FAILED = -46011, - ERR_DH_AUDIO_HDF_NOTIFY_SINK_FAILED = -46012, - ERR_DH_AUDIO_HDF_TRANS_SETUP_FAILED = -46013, - ERR_DH_AUDIO_HDF_TRANS_START_FAILED = -46014, - ERR_DH_AUDIO_HDF_RESULT_FAILED = -46015, -}; -} // Distributedaudio -} // OHOS -#endif -- Gitee From 70108ff5f8cc99c11ce1ca9fb498c5b3b038bf89 Mon Sep 17 00:00:00 2001 From: byndyx Date: Mon, 26 Feb 2024 16:23:25 +0800 Subject: [PATCH 15/17] modify handler Signed-off-by: byndyx --- audiohandler/BUILD.gn | 2 +- audiohandler/include/daudio_handler.h | 17 +-- audiohandler/src/daudio_handler.cpp | 113 ++---------------- .../test/unittest/src/daudio_handler_test.cpp | 12 -- common/dfx_utils/test/unittest/BUILD.gn | 2 +- .../managersource/src/dmic_dev.cpp | 2 +- services/audiomanager/servicesource/BUILD.gn | 1 + .../BUILD.gn | 1 + .../sourceservicedaudionotify_fuzzer/BUILD.gn | 1 + .../sourceserviceinitsource_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../src/av_receiver_engine_transport.cpp | 2 +- 14 files changed, 20 insertions(+), 137 deletions(-) diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index ef27e252..833ed5b9 100644 --- a/audiohandler/BUILD.gn +++ b/audiohandler/BUILD.gn @@ -45,9 +45,9 @@ 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", ] defines = [ diff --git a/audiohandler/include/daudio_handler.h b/audiohandler/include/daudio_handler.h index 4b79ea82..dcb63aec 100644 --- a/audiohandler/include/daudio_handler.h +++ b/audiohandler/include/daudio_handler.h @@ -26,14 +26,6 @@ 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 +47,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 36275a2e..3bf416bf 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() @@ -124,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/src/daudio_handler_test.cpp b/audiohandler/test/unittest/src/daudio_handler_test.cpp index 04c547b3..53fa86d2 100644 --- a/audiohandler/test/unittest/src/daudio_handler_test.cpp +++ b/audiohandler/test/unittest/src/daudio_handler_test.cpp @@ -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/common/dfx_utils/test/unittest/BUILD.gn b/common/dfx_utils/test/unittest/BUILD.gn index 38013170..2c17792b 100644 --- a/common/dfx_utils/test/unittest/BUILD.gn +++ b/common/dfx_utils/test/unittest/BUILD.gn @@ -49,7 +49,6 @@ config("module_private_config") { "${fwk_common_path}/utils/include", "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiorenderer/include", "${mediastandardfwk_path}/audiomanager/include", ] } @@ -72,6 +71,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/services/audiomanager/managersource/src/dmic_dev.cpp b/services/audiomanager/managersource/src/dmic_dev.cpp index 537aafad..5c0eaa22 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); } diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index c7d2fb51..1d0ccaa5 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -34,6 +34,7 @@ ohos_shared_library("distributed_audio_source") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiocommon/include", "${mediastandardfwk_path}/audiomanager/include", + "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn index 9df9fde0..0fad8c76 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn @@ -38,6 +38,7 @@ ohos_fuzztest("SourceServiceConfigDistributedHardwareFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn index 65270fd9..3a13ac28 100644 --- a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn @@ -39,6 +39,7 @@ ohos_fuzztest("SourceServiceDAudioNotifyFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn index b5dd2fdf..30a06518 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn @@ -39,6 +39,7 @@ ohos_fuzztest("SourceServiceInitSourceFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn index 1601f4a8..e4053477 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn @@ -38,6 +38,7 @@ ohos_fuzztest("SourceServiceRegisterDistributedHardwareFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn index 5804e350..e00990fb 100644 --- a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn @@ -39,6 +39,7 @@ ohos_fuzztest("SourceServiceReleaseSourceFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn index cb841a09..f05d0ce3 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn @@ -38,6 +38,7 @@ ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ diff --git a/services/audiotransport/receiverengine/src/av_receiver_engine_transport.cpp b/services/audiotransport/receiverengine/src/av_receiver_engine_transport.cpp index a311d5f1..5f0de401 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()); -- Gitee From 3a4a6012067540963566cb4bdca13d8ff523f572 Mon Sep 17 00:00:00 2001 From: byndyx Date: Mon, 26 Feb 2024 20:03:17 +0800 Subject: [PATCH 16/17] modify handler 2 Signed-off-by: byndyx --- audiohandler/include/daudio_handler.h | 1 + audiohandler/test/unittest/BUILD.gn | 5 ++++- common/dfx_utils/test/unittest/BUILD.gn | 1 + services/audiomanager/servicesource/BUILD.gn | 2 +- .../sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn | 2 +- .../test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn | 2 +- .../test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn | 2 +- .../sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn | 2 +- .../test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn | 2 +- .../BUILD.gn | 2 +- 10 files changed, 13 insertions(+), 8 deletions(-) diff --git a/audiohandler/include/daudio_handler.h b/audiohandler/include/daudio_handler.h index dcb63aec..e93aab70 100644 --- a/audiohandler/include/daudio_handler.h +++ b/audiohandler/include/daudio_handler.h @@ -23,6 +23,7 @@ #include "audio_param.h" #include "audio_capturer.h" #include "audio_info.h" +#include "audio_renderer.h" namespace OHOS { namespace DistributedHardware { diff --git a/audiohandler/test/unittest/BUILD.gn b/audiohandler/test/unittest/BUILD.gn index c250a8da..2c791831 100644 --- a/audiohandler/test/unittest/BUILD.gn +++ b/audiohandler/test/unittest/BUILD.gn @@ -50,7 +50,10 @@ ohos_unittest("AudioHandlerTest") { "//third_party/googletest:gtest_main", ] - external_deps = [ "c_utils:utils" ] + external_deps = [ + "audio_framework:audio_renderer", + "c_utils:utils", + ] } group("audio_handler_test") { diff --git a/common/dfx_utils/test/unittest/BUILD.gn b/common/dfx_utils/test/unittest/BUILD.gn index 2c17792b..35841816 100644 --- a/common/dfx_utils/test/unittest/BUILD.gn +++ b/common/dfx_utils/test/unittest/BUILD.gn @@ -49,6 +49,7 @@ config("module_private_config") { "${fwk_common_path}/utils/include", "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiocommon/include", + "${mediastandardfwk_path}/audiorenderer/include", "${mediastandardfwk_path}/audiomanager/include", ] } diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index 1d0ccaa5..b9b88976 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -34,7 +34,6 @@ ohos_shared_library("distributed_audio_source") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiocommon/include", "${mediastandardfwk_path}/audiomanager/include", - "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ @@ -93,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", diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn index 0fad8c76..7d015093 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn @@ -38,7 +38,6 @@ ohos_fuzztest("SourceServiceConfigDistributedHardwareFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ @@ -61,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 3a13ac28..41bbfc6a 100644 --- a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn @@ -39,7 +39,6 @@ ohos_fuzztest("SourceServiceDAudioNotifyFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ @@ -62,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 30a06518..a6b8aa13 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn @@ -39,7 +39,6 @@ ohos_fuzztest("SourceServiceInitSourceFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ @@ -64,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 e4053477..c1cd645c 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn @@ -38,7 +38,6 @@ ohos_fuzztest("SourceServiceRegisterDistributedHardwareFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ @@ -61,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 e00990fb..c9288ccf 100644 --- a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn @@ -39,7 +39,6 @@ ohos_fuzztest("SourceServiceReleaseSourceFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ @@ -62,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 f05d0ce3..6828a282 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn @@ -38,7 +38,6 @@ ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { "${mediastandardfwk_path}/audiocapturer/include", "${mediastandardfwk_path}/audiomanager/include", "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiorenderer/include", ] include_dirs += [ @@ -61,6 +60,7 @@ ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { ] external_deps = [ + "audio_framework:audio_renderer", "c_utils:utils", "ipc:ipc_core", "safwk:system_ability_fwk", -- Gitee From c118502860209b8e785b87555eab9dd702a8037b Mon Sep 17 00:00:00 2001 From: byndyx Date: Mon, 26 Feb 2024 11:55:48 +0800 Subject: [PATCH 17/17] hilog Signed-off-by: byndyx --- audiohandler/BUILD.gn | 2 +- audiohandler/test/unittest/BUILD.gn | 6 ++++- common/dfx_utils/src/daudio_hidumper.cpp | 2 +- common/include/daudio_log.h | 20 ++++++++++++++- common/src/daudio_latency_test.cpp | 10 ++++---- common/src/daudio_log.cpp | 25 ------------------- common/src/daudio_util.cpp | 6 ++--- common/test/unittest/BUILD.gn | 5 +++- .../test/unittest/src/daudio_utils_test.cpp | 7 +++--- .../inner_kits/native_cpp/audio_sink/BUILD.gn | 1 + .../native_cpp/audio_source/BUILD.gn | 1 + .../test/unittest/audiosinktest/BUILD.gn | 1 + .../audioclient/micclient/src/dmic_client.cpp | 8 +++--- .../spkclient/src/dspeaker_client.cpp | 16 ++++++------ .../src/daudio_manager_callback.cpp | 8 +++--- .../managersource/src/dmic_dev.cpp | 8 +++--- .../managersource/src/dspeaker_dev.cpp | 4 +-- services/audiomanager/servicesink/BUILD.gn | 1 + .../servicesink/src/daudio_sink_hidumper.cpp | 2 +- services/audiomanager/servicesource/BUILD.gn | 1 + .../audiotransport/receiverengine/BUILD.gn | 1 + services/audiotransport/senderengine/BUILD.gn | 1 + .../src/daudio_adapter_internal.cpp | 4 +-- .../hdfaudioclient/test/unittest/BUILD.gn | 12 +++++++-- 24 files changed, 84 insertions(+), 68 deletions(-) diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index ef27e252..7e53bc6e 100644 --- a/audiohandler/BUILD.gn +++ b/audiohandler/BUILD.gn @@ -47,7 +47,7 @@ ohos_shared_library("distributed_audio_handler") { "audio_framework:audio_client", "c_utils:utils", "distributed_hardware_fwk:distributedhardwareutils", - "player_framework:media_client", + "hilog:libhilog", ] defines = [ diff --git a/audiohandler/test/unittest/BUILD.gn b/audiohandler/test/unittest/BUILD.gn index c250a8da..0b355be7 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/common/dfx_utils/src/daudio_hidumper.cpp b/common/dfx_utils/src/daudio_hidumper.cpp index d33ddbe8..e920cc79 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/include/daudio_log.h b/common/include/daudio_log.h index 25f16cc1..dd832b58 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,7 +56,7 @@ 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__) - +#endif #define CHECK_NULL_VOID(ptr) \ do { \ if ((ptr) == nullptr) { \ diff --git a/common/src/daudio_latency_test.cpp b/common/src/daudio_latency_test.cpp index 1fd78732..2dc35480 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 d0ad61fe..d3b5cf16 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 78f50ed5..414f5a11 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 a2f9398b..c33e4504 100644 --- a/common/test/unittest/BUILD.gn +++ b/common/test/unittest/BUILD.gn @@ -46,7 +46,10 @@ ohos_unittest("DaudioUtilsTest") { "//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 0945e4a5..88207a95 100644 --- a/common/test/unittest/src/daudio_utils_test.cpp +++ b/common/test/unittest/src/daudio_utils_test.cpp @@ -136,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); diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 2a10e58d..c390d39c 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_source/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn index feacb89b..006ccb73 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/test/unittest/audiosinktest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/audiosinktest/BUILD.gn index 7e1afd53..fb2ed0d6 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/services/audioclient/micclient/src/dmic_client.cpp b/services/audioclient/micclient/src/dmic_client.cpp index 394a389b..4d097684 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 5a800462..d646abd3 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/audiohdiproxy/src/daudio_manager_callback.cpp b/services/audiohdiproxy/src/daudio_manager_callback.cpp index f87c4807..592eb965 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/managersource/src/dmic_dev.cpp b/services/audiomanager/managersource/src/dmic_dev.cpp index 537aafad..bf41f62d 100644 --- a/services/audiomanager/managersource/src/dmic_dev.cpp +++ b/services/audiomanager/managersource/src/dmic_dev.cpp @@ -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 9a982961..8d248475 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 02241542..17f992c2 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 5060b504..0b03d394 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/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index c7d2fb51..ea371efc 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -100,6 +100,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/audiotransport/receiverengine/BUILD.gn b/services/audiotransport/receiverengine/BUILD.gn index 98cc9aa9..bd4467f8 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/senderengine/BUILD.gn b/services/audiotransport/senderengine/BUILD.gn index 6e18f37a..8b69ea14 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/hdfaudioclient/src/daudio_adapter_internal.cpp b/services/hdfaudioclient/src/daudio_adapter_internal.cpp index b6128c28..b78522e3 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/test/unittest/BUILD.gn b/services/hdfaudioclient/test/unittest/BUILD.gn index 056518e5..08875bb4 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 = [ -- Gitee