diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index ef27e2523666235435c2a070b125e08232b085fa..cfc10ac40f97386f99fe33679ff9d2e44ca0af4e 100644 --- a/audiohandler/BUILD.gn +++ b/audiohandler/BUILD.gn @@ -23,14 +23,7 @@ ohos_shared_library("distributed_audio_handler") { ubsan = true } 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 = [ "//third_party/json/include" ] include_dirs += [ "include", diff --git a/audiohandler/include/daudio_handler.h b/audiohandler/include/daudio_handler.h index 4b79ea821c5cd754d1c5e3be46fc3cbaa3059bbd..75123436ca58414393e90960656cd982b9c8b1ee 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/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index 36275a2e71c899a15091291d5a601a33138613d8..c6551f37e62aa599cdd1011b3e1d72842e327b5a 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/bundle.json b/bundle.json index 942a75ba5576df7a8f944f4f8118c4c5c715c191..c875ce9b779e8f7df2fd4e4144865d813596e3e1 100755 --- a/bundle.json +++ b/bundle.json @@ -64,7 +64,6 @@ "//foundation/distributedhardware/distributed_audio/interfaces/inner_kits/native_cpp/audio_source:distributed_audio_source_sdk", "//foundation/distributedhardware/distributed_audio/services/common:distributed_audio_utils", - "//foundation/distributedhardware/distributed_audio/services/hdfaudioclient:daudio_client", "//foundation/distributedhardware/distributed_audio/services/audiomanager/servicesource:distributed_audio_source", "//foundation/distributedhardware/distributed_audio/services/audiomanager/servicesink:distributed_audio_sink", @@ -125,14 +124,6 @@ "audioparam/audio_param.h" ] } - }, - { - "type": "so", - "name": "//foundation/distributedhardware/distributed_audio/services/hdfaudioclient:daudio_client", - "header": { - "header_base": "//foundation/distributedhardware/distributed_audio/services/hdfaudioclient", - "header_files": [] - } } ], "test": [ diff --git a/common/dfx_utils/include/daudio_hidumper.h b/common/dfx_utils/include/daudio_hidumper.h index aa1d6da9c99787b3ab35517c8fee2658cc28a045..b5e9bbebdacccf74f747713009ba72b483cc2c37 100644 --- a/common/dfx_utils/include/daudio_hidumper.h +++ b/common/dfx_utils/include/daudio_hidumper.h @@ -20,14 +20,14 @@ #include #include "sys/stat.h" -#include "audio_capturer.h" -#include "audio_info.h" - -#include "audio_adapter.h" -#include "audio_manager.h" +#include +#include #include "daudio_handler.h" #include "single_instance.h" +using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioManager; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioAdapterDescriptor; + namespace OHOS { namespace DistributedHardware { enum class HidumpFlag { @@ -60,10 +60,9 @@ private: int32_t StopDumpData(std::string &result); private: - AudioManager *audioManager_ = nullptr; - AudioAdapterDescriptor *adapterdesc_ = nullptr; + sptr audioManager_ = nullptr; + std::vector adapterdesc_; 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 d33ddbe83a415369a47cbb438c083c9a63375f61..e5528fce0f18151c5ef69fa85fe30d0e96cadd2f 100644 --- a/common/dfx_utils/src/daudio_hidumper.cpp +++ b/common/dfx_utils/src/daudio_hidumper.cpp @@ -128,19 +128,20 @@ int32_t DaudioHidumper::GetSourceDevId(std::string &result) int32_t DaudioHidumper::GetSinkInfo(std::string &result) { DHLOGI("Get sink info dump."); - audioManager_ = GetAudioManagerFuncs(); + + audioManager_ = IAudioManager::Get("daudio_primary_service", false); if (audioManager_ == nullptr) { return ERR_DH_AUDIO_NULLPTR; } - int32_t ret = audioManager_->GetAllAdapters(audioManager_, &adapterdesc_, &g_deviceNum); + int32_t ret = audioManager_->GetAllAdapters(adapterdesc_); 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]; + for (int32_t index = 0; index < adapterdesc_.size(); index++) { + AudioAdapterDescriptor desc = adapterdesc_[index]; result.append("sinkDevId: ").append(GetAnonyString(desc.adapterName)).append(" portId: "); - for (uint32_t i = 0; i < desc.portNum; i++) { + for (uint32_t i = 0; i < desc.ports.size(); i++) { result.append(std::to_string(desc.ports[i].portId)).append(" "); } } diff --git a/common/dfx_utils/test/unittest/BUILD.gn b/common/dfx_utils/test/unittest/BUILD.gn index 38013170a1c44604b68b59bae7ef214a32f3ce31..659fcaf0080f9fa3377d53533da7bbc630daf6b3 100644 --- a/common/dfx_utils/test/unittest/BUILD.gn +++ b/common/dfx_utils/test/unittest/BUILD.gn @@ -35,7 +35,6 @@ config("module_private_config") { "${common_path}/dfx_utils/include", "${distributedaudio_path}/audiohandler/include", "${driver_audio_path}/include", - "${services_path}/hdfaudioclient/include", "${hdf_service_path}/hdi_service/common/include", "${interfaces_path}/inner_kits/native_cpp/audio_sink/include", "${interfaces_path}/inner_kits/native_cpp/audio_source/include", @@ -73,6 +72,7 @@ ohos_unittest("DAudioDfxTest") { external_deps = [ "audio_framework:audio_capturer", "c_utils:utils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "dsoftbus:softbus_client", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/common/include/single_instance.h b/common/include/single_instance.h deleted file mode 100644 index c2b7172471a6cf92c1f36f11a27297c54867e5a2..0000000000000000000000000000000000000000 --- a/common/include/single_instance.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022 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_SINGLE_INSTANCE_H -#define OHOS_DAUDIO_SINGLE_INSTANCE_H - -namespace OHOS { -namespace DistributedHardware { -#define DECLARE_SINGLE_INSTANCE_BASE(className) \ -public: \ - static className& GetInstance(); \ -private: \ - className(const className&) = delete; \ - className& operator= (const className&) = delete; \ - className(className&&) = delete; \ - className& operator= (className&&) = delete; \ - -#define DECLARE_SINGLE_INSTANCE(className) \ - DECLARE_SINGLE_INSTANCE_BASE(className) \ -private: \ - className() = default; \ - ~className() = default; \ - -#define IMPLEMENT_SINGLE_INSTANCE(className) \ -className& className::GetInstance() \ -{ \ - static auto instance = new className(); \ - return *instance; \ -} -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_DAUDIO_SINGLE_INSTANCE_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 2a10e58d1ae4e1f6bf0d7017735f94574844d2fc..332d3eadb416bc8290a04593ba15ee3cd3603205 100755 --- a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn @@ -26,10 +26,7 @@ ohos_shared_library("distributed_audio_sink_sdk") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "${fwk_common_path}/utils/include", - "//third_party/json/include", - ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "include", @@ -49,6 +46,7 @@ ohos_shared_library("distributed_audio_sink_sdk") { external_deps = [ "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", "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 feacb89b654b5be163c7e8551eab5a4f6e40ed3f..c90b556ea7572049f3bfbbd5a6a5e0c70195c8ab 100755 --- a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn @@ -26,10 +26,7 @@ ohos_shared_library("distributed_audio_source_sdk") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "${fwk_common_path}/utils/include", - "//third_party/json/include", - ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "include", @@ -49,6 +46,7 @@ ohos_shared_library("distributed_audio_source_sdk") { external_deps = [ "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", diff --git a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn index a6bc0c5bdb33c63e0a2be847cf2f57879da9f19e..c028a65b5d5d499f326846484ccccb6af0d2a4e0 100644 --- a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn @@ -28,6 +28,5 @@ group("unittest") { "${services_path}/audiomanager/test/unittest:daudio_manager_test", "${services_path}/audioprocessor/test/unittest:daudio_processor_test", "${services_path}/audiotransport/test/unittest:daudio_transport_test", - "${services_path}/hdfaudioclient/test/unittest:audio_adapter_hdi_test", ] } diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 022415421ae243117915c6bf1e8ce8ab071406d0..230ebf57641b70a4901eaf27803d8afbf2e25625 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 += [ @@ -85,6 +84,7 @@ ohos_shared_library("distributed_audio_sink") { "c_utils:utils", "device_manager:devicemanagersdk", "device_security_level:dslm_sdk", + "distributed_hardware_fwk:distributedhardwareutils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", "distributed_hardware_fwk:libdhfwk_sdk", diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index c7d2fb51808b275b60be263faf559266bba891fd..d41344459f3ba1441a802f85229b2208cae926b8 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", @@ -58,7 +52,6 @@ ohos_shared_library("distributed_audio_source") { "${services_path}/common/audiodata/include", "${services_path}/common/audioeventcallback", "${services_path}/common/audioparam", - "${services_path}/hdfaudioclient/include", "${services_path}/audiomanager/common/include", ] @@ -85,16 +78,18 @@ ohos_shared_library("distributed_audio_source") { "${audio_transport_path}/senderengine:distributed_audio_encode_transport", "${distributedaudio_path}/audiohandler:distributed_audio_handler", "${services_path}/common:distributed_audio_utils", - "${services_path}/hdfaudioclient:daudio_client", "//third_party/cJSON:cjson", ] external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "audio_framework:audio_capturer", "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "drivers_interface_distributed_audio:libdaudioext_proxy_1.0", "dsoftbus:softbus_client", "eventhandler:libeventhandler", diff --git a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn index 9df9fde072903a68730da83293666ad2319b5ede..0827fd6b891a7340b2722678a3439312c92444f4 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer/BUILD.gn @@ -61,6 +61,7 @@ ohos_fuzztest("SourceServiceConfigDistributedHardwareFuzzTest") { external_deps = [ "c_utils:utils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn index 65270fd9b550e979e4eafa4e589c0fd39aebbbda..457d3d37e58c72f473093b5b8c4ba7cdbc81ff52 100644 --- a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/BUILD.gn @@ -62,6 +62,7 @@ ohos_fuzztest("SourceServiceDAudioNotifyFuzzTest") { external_deps = [ "c_utils:utils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn index b5dd2fdff71492ea8d1696b4fe8303c3ed60c6ef..edebbc4cc88c65eba4efc6dfd5fde2218c86b136 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer/BUILD.gn @@ -64,6 +64,7 @@ ohos_fuzztest("SourceServiceInitSourceFuzzTest") { external_deps = [ "c_utils:utils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn index 1601f4a8347d342897f887fef3bb7d3b7257f348..ac9c703317cba7672e9d7412cb9f63c5d1a8df16 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer/BUILD.gn @@ -61,6 +61,7 @@ ohos_fuzztest("SourceServiceRegisterDistributedHardwareFuzzTest") { external_deps = [ "c_utils:utils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn index 5804e350ad36f21d44b55eac7e58ae0cae39c3de..0003d6dd0e3b0a2afacca96abedefbe5c53afa04 100644 --- a/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer/BUILD.gn @@ -62,6 +62,7 @@ ohos_fuzztest("SourceServiceReleaseSourceFuzzTest") { external_deps = [ "c_utils:utils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn index cb841a09b96f131d5aab31ad36864e4a518b139c..61ccfeb8b881d85ce5d81fb5e890e3c79a89dc05 100644 --- a/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn +++ b/services/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer/BUILD.gn @@ -61,6 +61,7 @@ ohos_fuzztest("SourceServiceUnregisterDistributedHardwareFuzzTest") { external_deps = [ "c_utils:utils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr:samgr_proxy", diff --git a/services/audiomanager/test/unittest/servicesource/BUILD.gn b/services/audiomanager/test/unittest/servicesource/BUILD.gn index 116278e4c498db86d045d158cc49f78b6803ff31..21bf76592ec8205f79d313479fc632c985a35bce 100644 --- a/services/audiomanager/test/unittest/servicesource/BUILD.gn +++ b/services/audiomanager/test/unittest/servicesource/BUILD.gn @@ -57,7 +57,6 @@ config("module_private_config") { "${services_path}/common/audiodata/include", "${services_path}/common/audioeventcallback", "${services_path}/common/audioparam", - "${services_path}/hdfaudioclient/include", ] } @@ -80,6 +79,7 @@ ohos_unittest("DaudioSourceServiceTest") { "audio_framework:audio_client", "audio_framework:audio_renderer", "c_utils:utils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "dsoftbus:softbus_client", "hisysevent:libhisysevent", "hitrace:hitrace_meter", diff --git a/services/audiomanager/test/unittest/sourcedevice/BUILD.gn b/services/audiomanager/test/unittest/sourcedevice/BUILD.gn index 24583124fe2c8bec64f02aa27dc904751e7e104d..6b76259dca6289b104e16e78b7d80a6d8e0aa669 100644 --- a/services/audiomanager/test/unittest/sourcedevice/BUILD.gn +++ b/services/audiomanager/test/unittest/sourcedevice/BUILD.gn @@ -49,7 +49,6 @@ config("module_private_config") { "${services_path}/common/audioparam", "${services_path}/common/audiodata/include", "${services_path}/common/audioeventcallback", - "${services_path}/hdfaudioclient/include", ] } diff --git a/services/audiomanager/test/unittest/sourcemanager/BUILD.gn b/services/audiomanager/test/unittest/sourcemanager/BUILD.gn index 4c05150475011ab23d9c5d5d57b576a11f1ac007..8f8294b2167fbea66186c6921fb060076d87b36e 100644 --- a/services/audiomanager/test/unittest/sourcemanager/BUILD.gn +++ b/services/audiomanager/test/unittest/sourcemanager/BUILD.gn @@ -53,7 +53,6 @@ config("module_private_config") { "${services_path}/common/audioeventcallback", "${services_path}/common/audioparam", "${services_path}/common/taskProcessor/include", - "${services_path}/hdfaudioclient/include", ] } diff --git a/services/audiotransport/receiverengine/BUILD.gn b/services/audiotransport/receiverengine/BUILD.gn index 98cc9aa94dd1e0df3664cbd828f39bd501ffeb63..df5377c3423602d874cc3022ddf74dd8a464ab2f 100644 --- a/services/audiotransport/receiverengine/BUILD.gn +++ b/services/audiotransport/receiverengine/BUILD.gn @@ -33,11 +33,7 @@ ohos_shared_library("distributed_audio_decode_transport") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "${mediastandard_path}/interfaces/innerkits/native/media/include", - "${mediastandardfwk_path}/audiocommon/include", - "//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 6e18f37a28a06c8cb9f215d511eb193de20edae8..fd72053088401a1ee6b5aa8e5edb75b0b1416a5f 100644 --- a/services/audiotransport/senderengine/BUILD.gn +++ b/services/audiotransport/senderengine/BUILD.gn @@ -33,11 +33,7 @@ ohos_shared_library("distributed_audio_encode_transport") { ubsan = true } stack_protector_ret = true - include_dirs = [ - "${mediastandard_path}/interfaces/innerkits/native/media/include", - "${mediastandardfwk_path}/audiocommon/include", - "//third_party/json/include", - ] + include_dirs = [ "//third_party/json/include" ] include_dirs += [ "include", diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 3a02e57e3e1baebf53d3cbef2b7d407c22079890..0a7ffdfd98d348e58b38e23dd4f69704ba4092d1 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -62,6 +62,7 @@ ohos_shared_library("distributed_audio_utils") { deps = [ "//third_party/cJSON:cjson" ] external_deps = [ "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", "dsoftbus:softbus_client", "hilog:libhilog", "hisysevent:libhisysevent", diff --git a/services/hdfaudioclient/BUILD.gn b/services/hdfaudioclient/BUILD.gn deleted file mode 100644 index f702e01b242c62037056c323f94322152dab75ee..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/BUILD.gn +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") -import("../../distributedaudio.gni") - -ohos_shared_library("daudio_client") { - branch_protector_ret = "pac_ret" - sanitize = { - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - integer_overflow = true - ubsan = true - } - stack_protector_ret = true - include_dirs = [ - "./include", - "${common_path}/include", - "${driver_audio_path}/include", - ] - - sources = [ - "./src/daudio_adapter_internal.cpp", - "./src/daudio_capture_internal.cpp", - "./src/daudio_param_callback_internal.cpp", - "./src/daudio_render_callback_internal.cpp", - "./src/daudio_render_internal.cpp", - "./src/distributed_audio_client.cpp", - ] - - public_deps = [ "${services_path}/common:distributed_audio_utils" ] - - external_deps = [ - "c_utils:utils", - "drivers_interface_distributed_audio:libdaudio_proxy_1.0", - "hdf_core:libhdf_utils", - "hilog:libhilog", - "ipc:ipc_single", - ] - - defines = [ - "HI_LOG_ENABLE", - "LOG_DOMAIN=0xD004130", - ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_audio" -} diff --git a/services/hdfaudioclient/include/daudio_adapter_internal.h b/services/hdfaudioclient/include/daudio_adapter_internal.h deleted file mode 100644 index 78d0ebdf5bb893b315290e66efd1ffe41ac949b8..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_adapter_internal.h +++ /dev/null @@ -1,54 +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 DAUDIO_ADAPTER_INTERNAL_H -#define DAUDIO_ADAPTER_INTERNAL_H - -#include -#include -#include - -#include "audio_adapter.h" -#include "audio_types.h" -#include - -#include "daudio_capture_internal.h" -#include "daudio_render_internal.h" -#include "daudio_param_callback_internal.h" - -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioAdapter; - -constexpr int DESCRIPTOR_LENGTH = 32; -struct AudioAdapterContext { - AudioAdapterContext(); - ~AudioAdapterContext(); - - struct AudioAdapter instance_; - sptr proxy_ = nullptr; - std::string adapterName_; - std::mutex mtx_; - - std::unique_ptr callbackInternal_ = nullptr; - ParamCallback callback_ = nullptr; - - std::vector>> captures_; - std::vector>> renders_; - std::map> caps_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // DAUDIO_ADAPTER_INTERNAL_H diff --git a/services/hdfaudioclient/include/daudio_attribute_internal.h b/services/hdfaudioclient/include/daudio_attribute_internal.h deleted file mode 100644 index 17532a381aaf9b4d5c8d4ea0d827d64fce9b8a93..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_attribute_internal.h +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) 2022 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 HDI_DAUDIO_ATTRIBUTE_INTERNAL_H -#define HDI_DAUDIO_ATTRIBUTE_INTERNAL_H - -#include -#include -#include - -#include "audio_types.h" -#include - -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioAttributeInternal" - -namespace OHOS { -namespace DistributedHardware { -using namespace OHOS::HDI::DistributedAudio::Audio::V1_0; - -template -class AudioAttributeInternal final { -public: - static int32_t GetFrameSize(AudioHandle handle, uint64_t *size); - static int32_t GetFrameCount(AudioHandle handle, uint64_t *count); - static int32_t SetSampleAttributes(AudioHandle handle, const struct ::AudioSampleAttributes *attrs); - static int32_t GetSampleAttributes(AudioHandle handle, struct ::AudioSampleAttributes *attrs); - static int32_t GetCurrentChannelId(AudioHandle handle, uint32_t *channelId); - static int32_t SetExtraParams(AudioHandle handle, const char *keyValueList); - static int32_t GetExtraParams(AudioHandle handle, char *keyValueList, int32_t listLenth); - static int32_t ReqMmapBuffer(AudioHandle handle, int32_t reqSize, struct ::AudioMmapBufferDescriptor *desc); - static int32_t GetMmapPosition(AudioHandle handle, uint64_t *frames, struct ::AudioTimeStamp *time); -}; - -template -int32_t AudioAttributeInternal::GetFrameSize(AudioHandle handle, uint64_t *size) -{ - if (handle == nullptr || size == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->GetFrameSize(*size); -} - -template -int32_t AudioAttributeInternal::GetFrameCount(AudioHandle handle, uint64_t *count) -{ - if (handle == nullptr || count == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->GetFrameCount(*count); -} - -template -int32_t AudioAttributeInternal::SetSampleAttributes(AudioHandle handle, - const struct ::AudioSampleAttributes *attrs) -{ - if (handle == nullptr || attrs == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - AudioSampleAttributes attrsHal = { - .format = static_cast(attrs->format), - .sampleRate = attrs->sampleRate, - .channelCount = attrs->channelCount, - }; - DHLOGD("AttrsHal.format = %u", attrsHal.format); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->SetSampleAttributes(attrsHal); -} - -template -int32_t AudioAttributeInternal::GetSampleAttributes(AudioHandle handle, struct ::AudioSampleAttributes *attrs) -{ - if (handle == nullptr || attrs == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - DHLOGD("Get sample attributes."); - T *context = reinterpret_cast(handle); - if (context == nullptr || context->proxy_ == nullptr) { - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - AudioSampleAttributes attrsHal; - int32_t ret = context->proxy_->GetSampleAttributes(attrsHal); - if (ret != DH_SUCCESS) { - return ret; - } - - attrs->type = static_cast<::AudioCategory>(attrsHal.type); - attrs->interleaved = static_cast(attrsHal.interleaved); - attrs->format = static_cast<::AudioFormat>(attrsHal.format); - attrs->sampleRate = attrsHal.sampleRate; - attrs->channelCount = attrsHal.channelCount; - attrs->streamId = static_cast(attrsHal.streamId); - return DH_SUCCESS; -} - -template -int32_t AudioAttributeInternal::GetCurrentChannelId(AudioHandle handle, uint32_t *channelId) -{ - if (handle == nullptr || channelId == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->GetCurrentChannelId(*channelId); -} - -template -int32_t AudioAttributeInternal::SetExtraParams(AudioHandle handle, const char *keyValueList) -{ - if (handle == nullptr || keyValueList == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - std::string keyValueListHal(keyValueList); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->SetExtraParams(keyValueListHal); -} - -template -int32_t AudioAttributeInternal::GetExtraParams(AudioHandle handle, char *keyValueList, int32_t listLenth) -{ - if (handle == nullptr || keyValueList == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - if (listLenth <= 0) { - DHLOGE("The parameter is invalid."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - if (context == nullptr || context->proxy_ == nullptr) { - DHLOGE("The context is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - std::string keyValueListHal(keyValueList); - int32_t ret = context->proxy_->GetExtraParams(keyValueListHal); - if (ret != DH_SUCCESS) { - return ret; - } - if (listLenth - 1 < (int)keyValueListHal.length()) { - keyValueListHal = keyValueListHal.substr(0, listLenth - 1); - } - if (strcpy_s(keyValueList, listLenth, keyValueListHal.c_str()) != EOK) { - DHLOGE("Strcpy_s keyValueList failed."); - return ERR_DH_AUDIO_HDI_CALL_FAILED; - } - return DH_SUCCESS; -} - -template -int32_t AudioAttributeInternal::ReqMmapBuffer(AudioHandle handle, int32_t reqSize, - struct ::AudioMmapBufferDescriptor *desc) -{ - if (handle == nullptr || desc == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - if (context == nullptr || context->proxy_ == nullptr) { - DHLOGE("The context is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - AudioMmapBufferDescriptor descHal; - int32_t ret = context->proxy_->ReqMmapBuffer(reqSize, descHal); - if (ret != DH_SUCCESS) { - DHLOGE("Failed to request the mmap buffer."); - return ret; - } - - desc->memoryFd = descHal.memoryFd; - desc->totalBufferFrames = descHal.totalBufferFrames; - desc->transferFrameSize = descHal.transferFrameSize; - desc->isShareable = descHal.isShareable; - return DH_SUCCESS; -} - -template -int32_t AudioAttributeInternal::GetMmapPosition(AudioHandle handle, uint64_t *frames, - struct ::AudioTimeStamp *time) -{ - if (handle == nullptr || frames == nullptr || time == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - DHLOGD("Get mmap position."); - - T *context = reinterpret_cast(handle); - if (context == nullptr || context->proxy_ == nullptr) { - DHLOGE("The context is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - AudioTimeStamp timeHal; - int32_t ret = context->proxy_->GetMmapPosition(*frames, timeHal); - if (ret != DH_SUCCESS) { - DHLOGE("Failed to get the mmap position."); - return ret; - } - - time->tvSec = static_cast(timeHal.tvSec); - time->tvNSec = static_cast(timeHal.tvNSec); - return DH_SUCCESS; -} -} // DistributedHardware -} // OHOS -#endif // HDI_DAUDIO_ATTRIBUTE_INTERNAL_H diff --git a/services/hdfaudioclient/include/daudio_capture_internal.h b/services/hdfaudioclient/include/daudio_capture_internal.h deleted file mode 100644 index 16a0e51cc7272c5aa1d1ec0ac897a657f9ea05c6..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_capture_internal.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 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 DAUDIO_CAPTURE_INTERNAL_H -#define DAUDIO_CAPTURE_INTERNAL_H - -#include - -#include "audio_capture.h" -#include -#include - -#include "daudio_render_callback_internal.h" - -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor; -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCapture; -struct AudioCaptureContext { - AudioCaptureContext(); - ~AudioCaptureContext(); - - struct AudioCapture instance_; - struct AudioDeviceDescriptor descHal_; - sptr proxy_ = nullptr; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // DAUDIO_CAPTURE_INTERNAL_H diff --git a/services/hdfaudioclient/include/daudio_control_internal.h b/services/hdfaudioclient/include/daudio_control_internal.h deleted file mode 100644 index eab91c9dedfb7e8877a275f66ad7a3eb9cedf3e4..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_control_internal.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2022 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 HDI_DAUDIO_CONTROL_INTERNAL_H -#define HDI_DAUDIO_CONTROL_INTERNAL_H - -#include - -#include "audio_types.h" - -#include "daudio_errorcode.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioControlInternal" - -namespace OHOS { -namespace DistributedHardware { -template -class AudioControlInternal final { -public: - static int32_t Start(AudioHandle handle); - static int32_t Stop(AudioHandle handle); - static int32_t Pause(AudioHandle handle); - static int32_t Resume(AudioHandle handle); - static int32_t Flush(AudioHandle handle); - static int32_t TurnStandbyMode(AudioHandle handle); - static int32_t AudioDevDump(AudioHandle handle, int32_t range, int32_t fd); -}; - -template -int32_t AudioControlInternal::Start(AudioHandle handle) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->Start(); -} - -template -int32_t AudioControlInternal::Stop(AudioHandle handle) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->Stop(); -} - -template -int32_t AudioControlInternal::Pause(AudioHandle handle) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->Pause(); -} - -template -int32_t AudioControlInternal::Resume(AudioHandle handle) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->Resume(); -} - -template -int32_t AudioControlInternal::Flush(AudioHandle handle) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->Flush(); -} - -template -int32_t AudioControlInternal::TurnStandbyMode(AudioHandle handle) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->TurnStandbyMode(); -} - -template -int32_t AudioControlInternal::AudioDevDump(AudioHandle handle, int32_t range, int32_t fd) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->AudioDevDump(range, fd); -} -} // DistributedHardware -} // OHOS -#endif // HDI_DAUDIO_CONTROL_INTERNAL_H \ No newline at end of file diff --git a/services/hdfaudioclient/include/daudio_param_callback_internal.h b/services/hdfaudioclient/include/daudio_param_callback_internal.h deleted file mode 100644 index a5134370fb4ce34723717b0d0f9e0801f7994b79..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_param_callback_internal.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022 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 DAUDIO_PARAM_CALLBACK_INTERNAL_H -#define DAUDIO_PARAM_CALLBACK_INTERNAL_H - -#include "audio_types.h" -#include - -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback; -struct AudioParamCallbackContext { - AudioParamCallbackContext(::ParamCallback callback, void *cookie); - ~AudioParamCallbackContext() = default; - - sptr callbackStub_ = nullptr; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // DAUDIO_PARAM_CALLBACK_INTERNAL_H diff --git a/services/hdfaudioclient/include/daudio_render_callback_internal.h b/services/hdfaudioclient/include/daudio_render_callback_internal.h deleted file mode 100644 index a9ca74077bb7b678ef246cab54753a44acba2dff..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_render_callback_internal.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022 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 DAUDIO_RENDER_CALLBACK_INTERNAL_H -#define DAUDIO_RENDER_CALLBACK_INTERNAL_H - -#include "audio_types.h" -#include - -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback; -struct AudioRenderCallbackContext { - AudioRenderCallbackContext(::RenderCallback callback, void *cookie); - ~AudioRenderCallbackContext() = default; - - sptr callbackStub_ = nullptr; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // DAUDIO_RENDER_CALLBACK_INTERNAL_H diff --git a/services/hdfaudioclient/include/daudio_render_internal.h b/services/hdfaudioclient/include/daudio_render_internal.h deleted file mode 100644 index b6889f19a284d6a2b39c9938b78834df2c2eb821..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_render_internal.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022 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 DAUDIO_RENDER_INTERNAL_H -#define DAUDIO_RENDER_INTERNAL_H - -#include - -#include "audio_render.h" -#include - -#include "daudio_render_callback_internal.h" - -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor; -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioRender; - -struct AudioRenderContext { - AudioRenderContext(); - ~AudioRenderContext(); - - struct AudioRender instance_; - sptr proxy_ = nullptr; - struct AudioDeviceDescriptor descHal_; - std::mutex mtx_; - std::unique_ptr callbackInternal_ = nullptr; - ::RenderCallback callback_ = nullptr; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // DAUDIO_RENDER_INTERNAL_H diff --git a/services/hdfaudioclient/include/daudio_scene_internal.h b/services/hdfaudioclient/include/daudio_scene_internal.h deleted file mode 100644 index f4f08746bf1c672f4be0bf6e2c5e6194aa3e6261..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_scene_internal.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2022 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 DAUDIO_SCRENE_INTERNAL_H -#define DAUDIO_SCRENE_INTERNAL_H - -#include "audio_types.h" - -#include "daudio_errorcode.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioSceneInternal" - -namespace OHOS { -namespace DistributedHardware { -using namespace OHOS::HDI::DistributedAudio::Audio::V1_0; - -template -class AudioSceneInternal final { -public: - static int32_t CheckSceneCapability(AudioHandle handle, const struct ::AudioSceneDescriptor *scene, - bool *supported); - static int32_t SelectScene(AudioHandle handle, const struct ::AudioSceneDescriptor *scene); -}; - -template -int32_t AudioSceneInternal::SelectScene(AudioHandle handle, const struct ::AudioSceneDescriptor *scene) -{ - if (handle == nullptr || scene == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - AudioSceneDescriptor sceneHAL = { - .scene.id = scene->scene.id, - .desc.portId = scene->desc.portId, - .desc.pins = static_cast(scene->desc.pins), - }; - if (scene->desc.desc == nullptr) { - sceneHAL.desc.desc = ""; - } else { - sceneHAL.desc.desc = scene->desc.desc; - } - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->SelectScene(sceneHAL); -} - -template -int32_t AudioSceneInternal::CheckSceneCapability(AudioHandle handle, const struct ::AudioSceneDescriptor *scene, - bool *supported) -{ - if (handle == nullptr || scene == nullptr || supported == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - AudioSceneDescriptor sceneHAL = { - .scene.id = scene->scene.id, - .desc.portId = scene->desc.portId, - .desc.pins = static_cast(scene->desc.pins), - }; - - if (scene->desc.desc == nullptr) { - sceneHAL.desc.desc = ""; - } else { - sceneHAL.desc.desc = scene->desc.desc; - } - - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->CheckSceneCapability(sceneHAL, *supported); -} -} // namespace DistributedHardware -} // namespace OHOS -#endif // DAUDIO_SCRENE_INTERNAL_H diff --git a/services/hdfaudioclient/include/daudio_volume_internal.h b/services/hdfaudioclient/include/daudio_volume_internal.h deleted file mode 100644 index b48f4a427ce300cd944a7c946d1302842bf3aa08..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/include/daudio_volume_internal.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2022 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 HDI_DAUDIO_VOLUME_INTERNAL_H -#define HDI_DAUDIO_VOLUME_INTERNAL_H - -#include "audio_types.h" - -#include "daudio_errorcode.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioVolumeInternal" - -namespace OHOS { -namespace DistributedHardware { -template -class AudioVolumeInternal final { -public: - static int32_t SetMute(AudioHandle handle, bool mute); - static int32_t GetMute(AudioHandle handle, bool *mute); - static int32_t SetVolume(AudioHandle handle, float volume); - static int32_t GetVolume(AudioHandle handle, float *volume); - static int32_t GetGainThreshold(AudioHandle handle, float *min, float *max); - static int32_t SetGain(AudioHandle handle, float gain); - static int32_t GetGain(AudioHandle handle, float *gain); -}; - -template -int32_t AudioVolumeInternal::SetMute(AudioHandle handle, bool mute) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->SetMute(mute); -} - -template -int32_t AudioVolumeInternal::GetMute(AudioHandle handle, bool *mute) -{ - if (handle == nullptr || mute == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->GetMute(*mute); -} - -template -int32_t AudioVolumeInternal::SetVolume(AudioHandle handle, float volume) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->SetVolume(volume); -} - -template -int32_t AudioVolumeInternal::GetVolume(AudioHandle handle, float *volume) -{ - if (handle == nullptr || volume == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->GetVolume(*volume); -} - -template -int32_t AudioVolumeInternal::GetGainThreshold(AudioHandle handle, float *min, float *max) -{ - if (handle == nullptr || min == nullptr || max == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->GetGainThreshold(*min, *max); -} - -template -int32_t AudioVolumeInternal::SetGain(AudioHandle handle, float gain) -{ - if (handle == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->SetGain(gain); -} - -template -int32_t AudioVolumeInternal::GetGain(AudioHandle handle, float *gain) -{ - if (handle == nullptr || gain == nullptr) { - DHLOGE("The parameter is empty."); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - - T *context = reinterpret_cast(handle); - return (context == nullptr || context->proxy_ == nullptr) ? - ERR_DH_AUDIO_HDI_INVALID_PARAM : context->proxy_->GetGain(*gain); -} -} // DistributedHardware -} // OHOS -#endif // HDI_DAUDIO_VOLUME_INTERNAL_H diff --git a/services/hdfaudioclient/src/daudio_adapter_internal.cpp b/services/hdfaudioclient/src/daudio_adapter_internal.cpp deleted file mode 100644 index b6128c28084e09ca129fdfd97b4fd41d495f68ee..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/src/daudio_adapter_internal.cpp +++ /dev/null @@ -1,464 +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. - */ - -#include "daudio_adapter_internal.h" - -#include -#include - -#include -#include -#include - -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "DAudioAdapterInternal" - -namespace OHOS { -namespace DistributedHardware { -using namespace OHOS::HDI::DistributedAudio::Audio::V1_0; - -static int32_t InitAllPortsInternal(struct AudioAdapter *adapter) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->InitAllPorts(); -} - -static void SetAudioSampleAttributesHAL(const struct ::AudioSampleAttributes *attrs, - AudioSampleAttributes &attrsHal) -{ - attrsHal.type = static_cast(attrs->type); - attrsHal.interleaved = attrs->interleaved; - attrsHal.format = static_cast(attrs->format); - attrsHal.sampleRate = attrs->sampleRate; - attrsHal.channelCount = attrs->channelCount; - attrsHal.period = attrs->period; - attrsHal.frameSize = attrs->frameSize; - attrsHal.isBigEndian = attrs->isBigEndian; - attrsHal.isSignedData = attrs->isSignedData; - attrsHal.startThreshold = attrs->startThreshold; - attrsHal.stopThreshold = attrs->stopThreshold; - attrsHal.silenceThreshold = attrs->silenceThreshold; - attrsHal.streamId = attrs->streamId; -} - -static int32_t CreateRenderInternal(struct AudioAdapter *adapter, const struct ::AudioDeviceDescriptor *desc, - const struct ::AudioSampleAttributes *attrs, struct AudioRender **render) -{ - DHLOGI("Create distributed audio render."); - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(desc, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(attrs, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - AudioDeviceDescriptor descHal = { - .portId = desc->portId, - .pins = static_cast(desc->pins), - }; - descHal.desc = desc->desc == nullptr ? "" : desc->desc; - - AudioSampleAttributes attrsHal; - SetAudioSampleAttributesHAL(attrs, attrsHal); - sptr renderProxy = nullptr; - uint32_t renderId; - int32_t ret = context->proxy_->CreateRender(descHal, attrsHal, renderProxy, renderId); - if (ret != DH_SUCCESS) { - *render = nullptr; - return ret; - } - auto renderContext = std::make_unique(); - *render = &renderContext->instance_; - renderContext->proxy_ = renderProxy; - renderContext->descHal_ = descHal; - DHLOGI("The render ID: %u.", renderId); - { - std::lock_guard lock(context->mtx_); - context->renders_.push_back(std::make_pair(renderId, std::move(renderContext))); - } - return DH_SUCCESS; -} - -static int32_t DestroyRenderInternal(struct AudioAdapter *adapter, struct AudioRender *render) -{ - DHLOGI("Destroy distributed audio render."); - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *adapterContext = reinterpret_cast(adapter); - AudioRenderContext *renderContext = reinterpret_cast(render); - CHECK_NULL_RETURN(adapterContext->proxy_, ERR_DH_AUDIO_NULLPTR); - - std::lock_guard lock(adapterContext->mtx_); - for (auto it = adapterContext->renders_.begin(); it != adapterContext->renders_.end(); ++it) { - if ((it->second).get() == renderContext) { - int32_t ret = adapterContext->proxy_->DestroyRender(it->first); - if (ret != DH_SUCCESS) { - return ret; - } - adapterContext->renders_.erase(it); - break; - } - } - return DH_SUCCESS; -} - -static int32_t CreateCaptureInternal(struct AudioAdapter *adapter, const struct ::AudioDeviceDescriptor *desc, - const struct ::AudioSampleAttributes *attrs, struct AudioCapture **capture) -{ - DHLOGI("Create distributed audio capture."); - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(desc, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(attrs, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(capture, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - - AudioDeviceDescriptor descHal = { - .portId = desc->portId, - .pins = static_cast(desc->pins), - }; - descHal.desc = desc->desc == nullptr ? "" : desc->desc; - AudioSampleAttributes attrsHal; - SetAudioSampleAttributesHAL(attrs, attrsHal); - sptr captureProxy = nullptr; - uint32_t captureId; - int32_t ret = context->proxy_->CreateCapture(descHal, attrsHal, captureProxy, captureId); - if (ret != DH_SUCCESS) { - *capture = nullptr; - return ret; - } - - auto captureContext = std::make_unique(); - *capture = &captureContext->instance_; - captureContext->proxy_ = captureProxy; - captureContext->descHal_ = descHal; - DHLOGI("The capture ID: %u.", captureId); - { - std::lock_guard lock(context->mtx_); - context->captures_.push_back(std::make_pair(captureId, std::move(captureContext))); - } - return DH_SUCCESS; -} - -static int32_t DestroyCaptureInternal(struct AudioAdapter *adapter, struct AudioCapture *capture) -{ - DHLOGI("Destroy distributed audio capture."); - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(capture, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *adapterContext = reinterpret_cast(adapter); - AudioCaptureContext *captureContext = reinterpret_cast(capture); - CHECK_NULL_RETURN(adapterContext->proxy_, ERR_DH_AUDIO_NULLPTR); - - std::lock_guard lock(adapterContext->mtx_); - for (auto it = adapterContext->captures_.begin(); it != adapterContext->captures_.end(); ++it) { - if ((it->second).get() == captureContext) { - int32_t ret = adapterContext->proxy_->DestroyCapture(it->first); - if (ret != DH_SUCCESS) { - return ret; - } - adapterContext->captures_.erase(it); - break; - } - } - return DH_SUCCESS; -} - -static int32_t GetPassthroughModeInternal(struct AudioAdapter *adapter, const struct ::AudioPort *port, - enum ::AudioPortPassthroughMode *mode) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(port, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(mode, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - - AudioPort portHal = { - .dir = static_cast(port->dir), - .portId = port->portId, - .portName= port->portName, - }; - return context->proxy_->GetPassthroughMode(portHal, *(reinterpret_cast(mode))); -} - -static int32_t InitAudioPortCapability(std::unique_ptr<::AudioPortCapability> &capInternal, - AudioPortCapability &capabilityHal) -{ - DHLOGI("Init audio port capability internal, formatNum: %zu.", 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); - return ERR_DH_AUDIO_HDI_INVALID_PARAM; - } - ::AudioFormat *audioFormats = (::AudioFormat *)malloc(capabilityHal.formatNum * sizeof(::AudioFormat)); - CHECK_NULL_RETURN(audioFormats, ERR_DH_AUDIO_HDI_CALL_FAILED); - - capInternal->deviceType = capabilityHal.deviceType; - capInternal->deviceId = capabilityHal.deviceId; - capInternal->hardwareMode = static_cast(capabilityHal.hardwareMode); - capInternal->formatNum = capabilityHal.formatNum; - capInternal->formats = audioFormats; - for (auto format : capabilityHal.formats) { - *audioFormats = static_cast<::AudioFormat>(format); - audioFormats++; - } - capInternal->sampleRateMasks = capabilityHal.sampleRateMasks; - capInternal->channelMasks = static_cast<::AudioChannelMask>(capabilityHal.channelMasks); - capInternal->channelCount = capabilityHal.channelCount; - capInternal->subPortsNum = 0; - capInternal->subPorts = nullptr; - return DH_SUCCESS; -} - -static int32_t GetPortCapabilityInternal(struct AudioAdapter *adapter, const struct ::AudioPort *port, - struct ::AudioPortCapability *capability) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(port, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(port->portName, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(capability, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - - { - std::lock_guard lock(context->mtx_); - auto iter = context->caps_.find(port->portId); - if (iter != context->caps_.end()) { - *capability = *(iter->second); - return DH_SUCCESS; - } - } - AudioPort portHal = { - .dir = static_cast(port->dir), - .portId = port->portId, - .portName = port->portName, - }; - - AudioPortCapability capabilityHal; - int32_t ret = context->proxy_->GetPortCapability(portHal, capabilityHal); - if (ret != DH_SUCCESS) { - return ret; - } - - auto capInternal = std::make_unique<::AudioPortCapability>(); - ret = InitAudioPortCapability(capInternal, capabilityHal); - if (ret != DH_SUCCESS) { - return ret; - } - *capability = *capInternal; - { - std::lock_guard lock(context->mtx_); - context->caps_[port->portId] = std::move(capInternal); - } - return DH_SUCCESS; -} - -static int32_t ReleaseAudioRouteInternal(struct AudioAdapter *adapter, int32_t routeHandle) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->ReleaseAudioRoute(routeHandle); -} - -static int32_t SetPassthroughModeInternal(struct AudioAdapter *adapter, const struct ::AudioPort *port, - enum ::AudioPortPassthroughMode mode) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(port, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - - AudioPort portHal = { - .dir = static_cast(port->dir), - .portId = port->portId, - .portName = port->portName, - }; - AudioPortPassthroughMode modeHal = static_cast(static_cast(mode)); - return context->proxy_->SetPassthroughMode(portHal, modeHal); -} - -static void ConvertAudioRouteNodeToHAL(const ::AudioRouteNode &node, AudioRouteNode &halNode) -{ - halNode.portId = node.portId; - halNode.role = static_cast(node.role); - halNode.type = static_cast(node.type); - DHLOGD("Convert audio route node To HAL, portId: %d role: %d type: %d.", halNode.portId, halNode.role, - halNode.type); - - switch (node.type) { - case AUDIO_PORT_UNASSIGNED_TYPE: - break; - case AUDIO_PORT_DEVICE_TYPE: { - size_t descLength = DESCRIPTOR_LENGTH; - halNode.ext.device.moduleId = node.ext.device.moduleId; - halNode.ext.device.type = static_cast(node.ext.device.type); - if (node.ext.device.desc != nullptr) { - size_t length = strlen(node.ext.device.desc); - length = length < descLength ? length : descLength; - halNode.ext.device.desc = std::string(node.ext.device.desc, node.ext.device.desc + length); - } - break; - } - case AUDIO_PORT_MIX_TYPE: { - halNode.ext.mix.moduleId = node.ext.mix.moduleId; - halNode.ext.mix.streamId = node.ext.mix.streamId; - - DHLOGD("Convert audio route node To HAL, [Mix] moduleId: %d streamId: %d.", - halNode.ext.mix.moduleId, halNode.ext.mix.streamId); - break; - } - case AUDIO_PORT_SESSION_TYPE: { - halNode.ext.session.sessionType = static_cast(node.ext.session.sessionType); - DHLOGD("Convert audio route node To HAL, [Session] sessionType: %d.", halNode.ext.session.sessionType); - break; - } - default : - DHLOGD("Unknown node Type"); - } -} -static int32_t UpdateAudioRouteInternal(struct AudioAdapter *adapter, const struct ::AudioRoute *route, - int32_t *routeHandle) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(route, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(routeHandle, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioRoute audioRoute; - for (uint32_t i = 0; i < route->sourcesNum; ++i) { - AudioRouteNode halNode = {0}; - ConvertAudioRouteNodeToHAL(route->sources[i], halNode); - audioRoute.sources.push_back(halNode); - } - - for (uint32_t i = 0; i < route->sinksNum; ++i) { - AudioRouteNode halNode = {0}; - ConvertAudioRouteNodeToHAL(route->sinks[i], halNode); - audioRoute.sinks.push_back(halNode); - } - - int32_t handle = -1; - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - int32_t ret = context->proxy_->UpdateAudioRoute(audioRoute, handle); - *routeHandle = handle; - return ret; -} - -static int32_t SetExtraParamsInternal(struct AudioAdapter *adapter, enum ::AudioExtParamKey key, - const char *condition, const char *value) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(condition, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(value, ERR_DH_AUDIO_HDI_INVALID_PARAM); - - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->SetExtraParams(static_cast(key), - std::string(condition), std::string(value)); -} - -static int32_t GetExtraParamsInternal(struct AudioAdapter *adapter, enum ::AudioExtParamKey key, - const char *condition, char *value, int32_t length) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(condition, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(value, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - - std::string valueHal; - int32_t ret = - context->proxy_->GetExtraParams(static_cast(key), - std::string(condition), valueHal); - if (ret != DH_SUCCESS) { - return ret; - } - ret = strcpy_s(value, length, valueHal.c_str()); - if (ret != EOK) { - DHLOGE("Strcpy_s failed!, ret: %d", ret); - return ERR_DH_AUDIO_HDI_CALL_FAILED; - } - return DH_SUCCESS; -} - -static int32_t RegExtraParamObserverInternal(struct AudioAdapter *adapter, ParamCallback callback, void* cookie) -{ - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(callback, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioAdapterContext *context = reinterpret_cast(adapter); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - - std::lock_guard lock(context->mtx_); - if (context->callbackInternal_ == nullptr || callback != context->callback_) { - context->callbackInternal_ = std::make_unique(callback, cookie); - } else { - return DH_SUCCESS; - } - - if (context->callbackInternal_->callbackStub_ == nullptr) { - context->callbackInternal_ = nullptr; - return ERR_DH_AUDIO_HDI_CALL_FAILED; - } - - int32_t ret = context->proxy_->RegExtraParamObserver(context->callbackInternal_->callbackStub_, 0); - if (ret == DH_SUCCESS) { - context->callback_ = callback; - } else { - context->callbackInternal_ = nullptr; - } - - return ret; -} - -AudioAdapterContext::AudioAdapterContext() -{ - instance_.InitAllPorts = InitAllPortsInternal; - instance_.CreateRender = CreateRenderInternal; - instance_.DestroyRender = DestroyRenderInternal; - instance_.CreateCapture = CreateCaptureInternal; - instance_.DestroyCapture = DestroyCaptureInternal; - instance_.GetPassthroughMode = GetPassthroughModeInternal; - instance_.GetPortCapability = GetPortCapabilityInternal; - instance_.ReleaseAudioRoute = ReleaseAudioRouteInternal; - instance_.SetPassthroughMode = SetPassthroughModeInternal; - instance_.UpdateAudioRoute = UpdateAudioRouteInternal; - instance_.SetExtraParams = SetExtraParamsInternal; - instance_.GetExtraParams = GetExtraParamsInternal; - instance_.RegExtraParamObserver = RegExtraParamObserverInternal; - - instance_.SetVoiceVolume = nullptr; - instance_.GetMicMute = nullptr; - instance_.SetMicMute = nullptr; - instance_.GetDeviceStatus = nullptr; -} - -AudioAdapterContext::~AudioAdapterContext() -{ - captures_.clear(); - renders_.clear(); - for (auto &cap : caps_) { - if (cap.second->formats != nullptr) { - free(cap.second->formats); - } - } - caps_.clear(); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/hdfaudioclient/src/daudio_capture_internal.cpp b/services/hdfaudioclient/src/daudio_capture_internal.cpp deleted file mode 100644 index 8091c438f6f4192a4bc571d43314dd3086587b11..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/src/daudio_capture_internal.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2022 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 "daudio_capture_internal.h" - -#include - -#include "daudio_attribute_internal.h" -#include "daudio_control_internal.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "daudio_scene_internal.h" -#include "daudio_volume_internal.h" - -#define HDF_LOG_TAG HDF_AUDIO -#undef DH_LOG_TAG -#define DH_LOG_TAG "DAudioCaptureInternal" - -namespace OHOS { -namespace DistributedHardware { -using namespace OHOS::HDI::DistributedAudio::Audio::V1_0; - -static int32_t GetCapturePositionInternal(struct AudioCapture *capture, uint64_t *frames, - struct ::AudioTimeStamp *time) -{ - CHECK_NULL_RETURN(capture, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(frames, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(time, ERR_DH_AUDIO_HDI_INVALID_PARAM); - - AudioCaptureContext *context = reinterpret_cast(capture); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - AudioTimeStamp timeHal; - int32_t ret = context->proxy_->GetCapturePosition(*frames, timeHal); - if (ret != DH_SUCCESS) { - DHLOGE("Failed to getr the capture position."); - return ret; - } - time->tvSec = static_cast(timeHal.tvSec); - time->tvNSec = static_cast(timeHal.tvNSec); - return DH_SUCCESS; -} - -static int32_t CaptureFrameInternal(struct AudioCapture *capture, void *frame, uint64_t requestBytes, - uint64_t *replyBytes) -{ - CHECK_NULL_RETURN(capture, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(frame, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(replyBytes, ERR_DH_AUDIO_HDI_INVALID_PARAM); - - AudioCaptureContext *context = reinterpret_cast(capture); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - int8_t *uframe = reinterpret_cast(frame); - std::vector frameHal; - int32_t ret = context->proxy_->CaptureFrame(frameHal, *replyBytes); - if (ret != DH_SUCCESS) { - DHLOGE("Failed to capture frames."); - return ret; - } - - ret = memcpy_s(uframe, requestBytes, frameHal.data(), requestBytes); - if (ret != EOK) { - DHLOGE("Copy capture frame failed, error code %d.", ret); - return ERR_DH_AUDIO_HDI_CALL_FAILED; - } - *replyBytes = requestBytes; - return DH_SUCCESS; -} - -AudioCaptureContext::AudioCaptureContext() -{ - instance_.GetCapturePosition = GetCapturePositionInternal; - instance_.CaptureFrame = CaptureFrameInternal; - - instance_.control.Start = AudioControlInternal::Start; - instance_.control.Stop = AudioControlInternal::Stop; - instance_.control.Pause = AudioControlInternal::Pause; - instance_.control.Resume = AudioControlInternal::Resume; - instance_.control.Flush = AudioControlInternal::Flush; - instance_.control.TurnStandbyMode = AudioControlInternal::TurnStandbyMode; - instance_.control.AudioDevDump = AudioControlInternal::AudioDevDump; - - instance_.attr.GetFrameSize = AudioAttributeInternal::GetFrameSize; - instance_.attr.GetFrameCount = AudioAttributeInternal::GetFrameCount; - instance_.attr.SetSampleAttributes = AudioAttributeInternal::SetSampleAttributes; - instance_.attr.GetSampleAttributes = AudioAttributeInternal::GetSampleAttributes; - instance_.attr.GetCurrentChannelId = AudioAttributeInternal::GetCurrentChannelId; - instance_.attr.SetExtraParams = AudioAttributeInternal::SetExtraParams; - instance_.attr.GetExtraParams = AudioAttributeInternal::GetExtraParams; - instance_.attr.ReqMmapBuffer = AudioAttributeInternal::ReqMmapBuffer; - instance_.attr.GetMmapPosition = AudioAttributeInternal::GetMmapPosition; - - instance_.scene.SelectScene = AudioSceneInternal::SelectScene; - instance_.scene.CheckSceneCapability = AudioSceneInternal::CheckSceneCapability; - - instance_.volume.SetMute = AudioVolumeInternal::SetMute; - instance_.volume.GetMute = AudioVolumeInternal::GetMute; - instance_.volume.SetVolume = AudioVolumeInternal::SetVolume; - instance_.volume.GetVolume = AudioVolumeInternal::GetVolume; - instance_.volume.GetGainThreshold = AudioVolumeInternal::GetGainThreshold; - instance_.volume.SetGain = AudioVolumeInternal::SetGain; - instance_.volume.GetGain = AudioVolumeInternal::GetGain; - - descHal_.portId = 0; - descHal_.pins = PIN_NONE; -} - -AudioCaptureContext::~AudioCaptureContext() {} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/hdfaudioclient/src/daudio_param_callback_internal.cpp b/services/hdfaudioclient/src/daudio_param_callback_internal.cpp deleted file mode 100644 index 18cea822211a32da66eec4d56508ae8a01a209d1..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/src/daudio_param_callback_internal.cpp +++ /dev/null @@ -1,71 +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. - */ - -#include "daudio_param_callback_internal.h" - -#include - -#include -#include - -#include "daudio_errorcode.h" - -#define HDF_LOG_TAG HDF_AUDIO -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioCallbackType; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey; - -class AudioParamCallbackImpl final : public IAudioCallback { -public: - AudioParamCallbackImpl(::ParamCallback callback, void *cookie) : callback_(callback), cookie_(cookie) {} - ~AudioParamCallbackImpl() override {} - - int32_t RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie) override; - int32_t ParamCallback(AudioExtParamKey key, const std::string& condition, const std::string& value, - int8_t &reserved, int8_t cookie) override; -private: - ::ParamCallback callback_ = nullptr; - void *cookie_ = nullptr; -}; - -AudioParamCallbackContext::AudioParamCallbackContext(::ParamCallback callback, void *cookie) -{ - callbackStub_ = new AudioParamCallbackImpl(callback, cookie); -} - -int32_t AudioParamCallbackImpl::RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie) -{ - (void) type; - (void) reserved; - (void) cookie; - return DH_SUCCESS; -} - -int32_t AudioParamCallbackImpl::ParamCallback(AudioExtParamKey key, const std::string& condition, - const std::string& value, int8_t &reserved, int8_t cookie) -{ - (void) cookie; - if (callback_ != nullptr) { - callback_(static_cast<::AudioExtParamKey>(key), condition.c_str(), - value.c_str(), static_cast(&reserved), cookie_); - return DH_SUCCESS; - } else { - return ERR_DH_AUDIO_HDI_CALL_FAILED; - } -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/hdfaudioclient/src/daudio_render_callback_internal.cpp b/services/hdfaudioclient/src/daudio_render_callback_internal.cpp deleted file mode 100644 index 9facc92be22d4a79f90d7bc52c92b7e993121fbd..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/src/daudio_render_callback_internal.cpp +++ /dev/null @@ -1,67 +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. - */ - -#include "daudio_render_callback_internal.h" - -#include - -#include "daudio_errorcode.h" - -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioCallbackType; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey; - -class AudioRenderCallbackImpl final : public IAudioCallback { -public: - AudioRenderCallbackImpl(::RenderCallback callback, void *cookie) : callback_(callback), cookie_(cookie) {} - ~AudioRenderCallbackImpl() override {} - - int32_t RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie) override; - int32_t ParamCallback(AudioExtParamKey key, const std::string& condition, const std::string& value, - int8_t &reserved, int8_t cookie) override; - -private: - ::RenderCallback callback_ = nullptr; - void *cookie_ = nullptr; -}; - -AudioRenderCallbackContext::AudioRenderCallbackContext(::RenderCallback callback, void *cookie) -{ - callbackStub_ = new AudioRenderCallbackImpl(callback, cookie); -} - -int32_t AudioRenderCallbackImpl::RenderCallback(AudioCallbackType type, int8_t &reserved, int8_t &cookie) -{ - (void) reserved; - (void) cookie; - if (callback_ != nullptr) { - callback_(static_cast<::AudioCallbackType>(type), static_cast(&reserved), cookie_); - return DH_SUCCESS; - } else { - return ERR_DH_AUDIO_HDI_CALL_FAILED; - } -} - -int32_t AudioRenderCallbackImpl::ParamCallback(AudioExtParamKey key, const std::string& condition, - const std::string& value, int8_t &reserved, int8_t cookie) -{ - (void) reserved; - (void) cookie; - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/hdfaudioclient/src/daudio_render_internal.cpp b/services/hdfaudioclient/src/daudio_render_internal.cpp deleted file mode 100644 index f1839a0b53f5fe9e4cb907e1bdfe21c63cf6197d..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/src/daudio_render_internal.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2022 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 "daudio_render_internal.h" - -#include - -#include "daudio_attribute_internal.h" -#include "daudio_control_internal.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "daudio_scene_internal.h" -#include "daudio_volume_internal.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "DAudioRenderInternal" - -namespace OHOS { -namespace DistributedHardware { -using namespace OHOS::HDI::DistributedAudio::Audio::V1_0; - -static int32_t GetLatencyInternal(struct AudioRender *render, uint32_t *ms) -{ - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(ms, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->GetLatency(*ms); -} - -static int32_t RenderFrameInternal(struct AudioRender *render, const void *frame, uint64_t requestBytes, - uint64_t *replyBytes) -{ - DHLOGI("Render frame."); - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(frame, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(replyBytes, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - - const uint8_t *uframe = reinterpret_cast(frame); - std::vector frameHal(requestBytes); - int32_t ret = memcpy_s(frameHal.data(), requestBytes, uframe, requestBytes); - if (ret != EOK) { - DHLOGE("Copy render frame failed, error code %d.", ret); - return ERR_DH_AUDIO_HDI_CALL_FAILED; - } - return context->proxy_->RenderFrame(frameHal, *replyBytes); -} - -static int32_t GetRenderPositionInternal(struct AudioRender *render, uint64_t *frames, - struct ::AudioTimeStamp *time) -{ - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(frames, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(time, ERR_DH_AUDIO_HDI_INVALID_PARAM); - - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - AudioTimeStamp timeHal; - int32_t ret = context->proxy_->GetRenderPosition(*frames, timeHal); - if (ret != DH_SUCCESS) { - return ret; - } - time->tvSec = static_cast(timeHal.tvSec); - time->tvNSec = static_cast(timeHal.tvNSec); - return DH_SUCCESS; -} - -static int32_t SetRenderSpeedInternal(struct AudioRender *render, float speed) -{ - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->SetRenderSpeed(speed); -} - -static int32_t GetRenderSpeedInternal(struct AudioRender *render, float *speed) -{ - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(speed, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->GetRenderSpeed(*speed); -} - -static int32_t SetChannelModeInternal(struct AudioRender *render, enum ::AudioChannelMode mode) -{ - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->SetChannelMode(static_cast(mode)); -} - -static int32_t GetChannelModeInternal(struct AudioRender *render, enum ::AudioChannelMode *mode) -{ - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(mode, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->GetChannelMode(*(reinterpret_cast(mode))); -} - -static int32_t RegCallbackInternal(struct AudioRender *render, ::RenderCallback callback, void *cookie) -{ - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(callback, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(cookie, ERR_DH_AUDIO_HDI_INVALID_PARAM); - - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - std::lock_guard lock(context->mtx_); - if (context->callbackInternal_ == nullptr || callback != context->callback_) { - context->callbackInternal_ = std::make_unique(callback, cookie); - } else { - return DH_SUCCESS; - } - - if (context->callbackInternal_->callbackStub_ == nullptr) { - context->callbackInternal_ = nullptr; - return ERR_DH_AUDIO_HDI_CALL_FAILED; - } - int32_t ret = context->proxy_->RegCallback(context->callbackInternal_->callbackStub_, 0); - if (ret == DH_SUCCESS) { - context->callback_ = callback; - } else { - context->callbackInternal_ = nullptr; - } - return ret; -} - -static int32_t DrainBufferInternal(struct AudioRender *render, enum ::AudioDrainNotifyType *type) -{ - CHECK_NULL_RETURN(render, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(type, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioRenderContext *context = reinterpret_cast(render); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - return context->proxy_->DrainBuffer(*(reinterpret_cast(type))); -} - -AudioRenderContext::AudioRenderContext() -{ - instance_.GetLatency = GetLatencyInternal; - instance_.RenderFrame = RenderFrameInternal; - instance_.GetRenderPosition = GetRenderPositionInternal; - instance_.SetRenderSpeed = SetRenderSpeedInternal; - instance_.GetRenderSpeed = GetRenderSpeedInternal; - instance_.SetChannelMode = SetChannelModeInternal; - instance_.GetChannelMode = GetChannelModeInternal; - instance_.RegCallback = RegCallbackInternal; - instance_.DrainBuffer = DrainBufferInternal; - instance_.IsSupportsDrain = nullptr; - - instance_.control.Start = AudioControlInternal::Start; - instance_.control.Stop = AudioControlInternal::Stop; - instance_.control.Pause = AudioControlInternal::Pause; - instance_.control.Resume = AudioControlInternal::Resume; - instance_.control.Flush = AudioControlInternal::Flush; - instance_.control.TurnStandbyMode = AudioControlInternal::TurnStandbyMode; - instance_.control.AudioDevDump = AudioControlInternal::AudioDevDump; - - instance_.attr.GetFrameSize = AudioAttributeInternal::GetFrameSize; - instance_.attr.GetFrameCount = AudioAttributeInternal::GetFrameCount; - instance_.attr.SetSampleAttributes = AudioAttributeInternal::SetSampleAttributes; - instance_.attr.GetSampleAttributes = AudioAttributeInternal::GetSampleAttributes; - instance_.attr.GetCurrentChannelId = AudioAttributeInternal::GetCurrentChannelId; - instance_.attr.SetExtraParams = AudioAttributeInternal::SetExtraParams; - instance_.attr.GetExtraParams = AudioAttributeInternal::GetExtraParams; - instance_.attr.ReqMmapBuffer = AudioAttributeInternal::ReqMmapBuffer; - instance_.attr.GetMmapPosition = AudioAttributeInternal::GetMmapPosition; - - instance_.scene.SelectScene = AudioSceneInternal::SelectScene; - instance_.scene.CheckSceneCapability = AudioSceneInternal::CheckSceneCapability; - - instance_.volume.SetMute = AudioVolumeInternal::SetMute; - instance_.volume.GetMute = AudioVolumeInternal::GetMute; - instance_.volume.SetVolume = AudioVolumeInternal::SetVolume; - instance_.volume.GetVolume = AudioVolumeInternal::GetVolume; - instance_.volume.GetGainThreshold = AudioVolumeInternal::GetGainThreshold; - instance_.volume.SetGain = AudioVolumeInternal::SetGain; - instance_.volume.GetGain = AudioVolumeInternal::GetGain; - - descHal_.portId = 0; - descHal_.pins = PIN_NONE; -} - -AudioRenderContext::~AudioRenderContext() {} -} // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file diff --git a/services/hdfaudioclient/src/distributed_audio_client.cpp b/services/hdfaudioclient/src/distributed_audio_client.cpp deleted file mode 100644 index e4df6a370d9cdcc0406876125881db00d62791c8..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/src/distributed_audio_client.cpp +++ /dev/null @@ -1,281 +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. - */ - -#include "distributed_audio_client.h" - -#include - -#include - -#include "audio_types.h" -#include "daudio_constants.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "DAudioAudioClient" - -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioAdapter; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioAdapterDescriptor; - -static int32_t InitDescriptorPort(const AudioAdapterDescriptor &desc, ::AudioAdapterDescriptor &descInternal) -{ - DHLOGI("Init audio adapter descriptor port."); - ::AudioPort *audioPorts = (::AudioPort *)malloc(desc.ports.size() * sizeof(AudioPort)); - CHECK_NULL_RETURN(audioPorts, ERR_DH_AUDIO_NULLPTR); - descInternal.ports = audioPorts; - - bool isSuccess = true; - uint32_t cpyPortNum = 0; - constexpr uint32_t maxPortNameLen = 1000; - for (auto port : desc.ports) { - if (port.portName.length() >= maxPortNameLen) { - DHLOGE("Audio port name length is too long."); - continue; - } - char* portName = reinterpret_cast(calloc(port.portName.length() + STR_TERM_LEN, sizeof(char))); - if (portName == nullptr) { - DHLOGE("Calloc failed."); - isSuccess = false; - break; - } - if (strcpy_s(portName, port.portName.length() + STR_TERM_LEN, port.portName.c_str()) != EOK) { - DHLOGD("Strcpy_s port name failed."); - free(portName); - continue; - } - audioPorts->dir = static_cast<::AudioPortDirection>(port.dir); - audioPorts->portId = port.portId; - audioPorts->portName = portName; - audioPorts++; - cpyPortNum++; - } - if (isSuccess) { - return DH_SUCCESS; - } - - for (uint32_t i = 0; i < cpyPortNum; i++) { - if (descInternal.ports[i].portName != nullptr) { - free(const_cast(descInternal.ports[i].portName)); - } - } - free(descInternal.ports); - descInternal.ports = nullptr; - return ERR_DH_AUDIO_HDI_CALL_FAILED; -} - -static int32_t InitAudioAdapterDescriptor(AudioManagerContext *context, - std::vector &descriptors) -{ - DHLOGI("Init audio adapters descriptor, size is: %zu.", descriptors.size()); - constexpr uint32_t maxAdapterNameLen = 1000; - constexpr uint32_t maxPortNum = 100; - constexpr uint32_t minPortNum = 1; - for (auto desc : descriptors) { - if (desc.ports.size() < minPortNum || desc.ports.size() > maxPortNum) { - DHLOGE("The descriptor ports size: %zu.", desc.ports.size()); - continue; - } - if (desc.adapterName.length() >= maxAdapterNameLen) { - DHLOGE("Audio adapter name length is too long."); - continue; - } - char* adapterName = reinterpret_cast(calloc(desc.adapterName.length() + STR_TERM_LEN, sizeof(char))); - CHECK_NULL_RETURN(adapterName, ERR_DH_AUDIO_NULLPTR); - if (strcpy_s(adapterName, desc.adapterName.length() + STR_TERM_LEN, desc.adapterName.c_str()) != EOK) { - DHLOGD("Strcpy_s adapter name failed."); - free(adapterName); - continue; - } - - ::AudioAdapterDescriptor descInternal = { - .adapterName = adapterName, - .portNum = desc.ports.size(), - }; - int32_t ret = InitDescriptorPort(desc, descInternal); - if (ret != DH_SUCCESS) { - DHLOGE("Init audio adapter descriptor port fail."); - free(adapterName); - descInternal.adapterName = nullptr; - return ret; - } - context->descriptors_.push_back(descInternal); - } - return DH_SUCCESS; -} - -static int32_t GetAllAdaptersInternal(struct AudioManager *manager, struct ::AudioAdapterDescriptor **descs, - int32_t *size) -{ - DHLOGI("Get all adapters."); - CHECK_NULL_RETURN(manager, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(descs, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(size, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioManagerContext *context = reinterpret_cast(manager); - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - - std::lock_guard lock(context->mtx_); - std::vector descriptors; - int32_t ret = context->proxy_->GetAllAdapters(descriptors); - if (ret != DH_SUCCESS) { - *descs = nullptr; - *size = 0; - DHLOGE("Failed to get all adapters."); - return ret; - } - context->ClearDescriptors(); - ret = InitAudioAdapterDescriptor(context, descriptors); - if (ret != DH_SUCCESS) { - return ret; - } - *descs = context->descriptors_.data(); - *size = context->descriptors_.size(); - return DH_SUCCESS; -} - -static int32_t LoadAdapterInternal(struct AudioManager *manager, const struct ::AudioAdapterDescriptor *desc, - struct AudioAdapter **adapter) -{ - DHLOGI("Load adapter."); - CHECK_NULL_RETURN(manager, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(desc, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(desc->adapterName, ERR_DH_AUDIO_HDI_INVALID_PARAM); - CHECK_NULL_RETURN(adapter, ERR_DH_AUDIO_HDI_INVALID_PARAM); - AudioManagerContext *context = reinterpret_cast(manager); - std::string adpName = desc->adapterName; - { - std::lock_guard lock(context->mtx_); - if (context->adapters_.find(adpName) != context->adapters_.end()) { - DHLOGD("Adapter already has been load."); - *adapter = &(context->adapters_[adpName]->instance_); - return DH_SUCCESS; - } - } - - AudioAdapterDescriptor descriptor = { - .adapterName = desc->adapterName, - }; - sptr adapterProxy = nullptr; - CHECK_NULL_RETURN(context->proxy_, ERR_DH_AUDIO_NULLPTR); - int32_t ret = context->proxy_->LoadAdapter(descriptor, adapterProxy); - if (ret != DH_SUCCESS) { - DHLOGE("Failed to load the adapter."); - *adapter = nullptr; - return ret; - } - - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = adapterProxy; - *adapter = &adapterContext->instance_; - adapterContext->adapterName_ = descriptor.adapterName; - { - std::lock_guard lock(context->mtx_); - context->adapters_.insert(std::make_pair(adpName, std::move(adapterContext))); - } - return DH_SUCCESS; -} - -static void UnloadAdapterInternal(struct AudioManager *manager, struct AudioAdapter *adapter) -{ - DHLOGI("Unload adapter."); - CHECK_NULL_VOID(manager); - CHECK_NULL_VOID(adapter); - AudioManagerContext *context = reinterpret_cast(manager); - AudioAdapterContext *adapterContext = reinterpret_cast(adapter); - CHECK_NULL_VOID(context->proxy_); - - std::lock_guard lock(context->mtx_); - for (auto it = context->adapters_.begin(); it != context->adapters_.end(); it++) { - if ((it->second).get() == adapterContext) { - int32_t ret = context->proxy_->UnloadAdapter(adapterContext->adapterName_); - if (ret != DH_SUCCESS) { - DHLOGE("Failed to unload adapter."); - return; - } - context->adapters_.erase(it); - break; - } - } - DHLOGI("Unload adapter success."); -} - -void AudioManagerContext::ClearDescriptors() -{ - DHLOGI("Clear descriptors enter."); - for (auto &desc : descriptors_) { - if (desc.adapterName != nullptr) { - free(const_cast(desc.adapterName)); - } - for (uint32_t i = 0; i < desc.portNum; i++) { - if (desc.ports[i].portName != nullptr) { - free(const_cast(desc.ports[i].portName)); - } - } - free(desc.ports); - } - descriptors_.clear(); - DHLOGI("Clear descriptors end."); -} - -AudioManagerContext::AudioManagerContext() -{ - instance_.GetAllAdapters = GetAllAdaptersInternal; - instance_.LoadAdapter = LoadAdapterInternal; - instance_.UnloadAdapter = UnloadAdapterInternal; - - instance_.ReleaseAudioManagerObject = nullptr; -} - -AudioManagerContext::~AudioManagerContext() -{ - adapters_.clear(); - ClearDescriptors(); -} - -AudioManagerContext g_AudioManagerContext; - -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; - return true; -} -} // DistributedHardware -} // OHOS - -#ifdef __cplusplus -extern "C" { -#endif - -struct AudioManager *GetAudioManagerFuncs(void) -{ - if (OHOS::DistributedHardware::AudioManagerInit()) { - return &OHOS::DistributedHardware::g_AudioManagerContext.instance_; - } else { - return nullptr; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/services/hdfaudioclient/test/unittest/BUILD.gn b/services/hdfaudioclient/test/unittest/BUILD.gn deleted file mode 100644 index 056518e580ddb0d42e4aeef0c15d123f071be681..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/test/unittest/BUILD.gn +++ /dev/null @@ -1,166 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/test.gni") -import("../../../../distributedaudio.gni") - -module_output_path = "distributed_audio/hdfaudioclient" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "${common_path}/include", - "${driver_audio_path}/include", - "${services_path}/hdfaudioclient/include", - "audio_adapter_internal/", - ] -} - -ohos_unittest("AudioAdapterHdiTest") { - module_out_path = module_output_path - - configs = [ ":module_private_config" ] - - sources = [ "audio_manager_test.cpp" ] - - deps = [ - "${services_path}/hdfaudioclient:daudio_client", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "drivers_interface_distributed_audio:libdaudio_proxy_1.0", - "ipc:ipc_core", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"unittest\"", - "LOG_DOMAIN=0xD004130", - ] - - cflags = [ - "-Wall", - "-Wextra", - "-Werror", - "-fsigned-char", - "-fno-common", - "-fno-strict-aliasing", - ] -} - -ohos_unittest("AudioRenderInternalTest") { - module_out_path = module_output_path - - configs = [ ":module_private_config" ] - - sources = [ "audio_render_internal/audio_render_internal_test.cpp" ] - - deps = [ - "${services_path}/hdfaudioclient:daudio_client", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - external_deps = [ "drivers_interface_distributed_audio:libdaudio_proxy_1.0" ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"unittest\"", - "LOG_DOMAIN=0xD004130", - ] - - cflags = [ - "-Wall", - "-Wextra", - "-Werror", - "-fsigned-char", - "-fno-common", - "-fno-strict-aliasing", - ] -} - -ohos_unittest("AudioCaptureInternalTest") { - module_out_path = module_output_path - - configs = [ ":module_private_config" ] - - sources = [ "audio_capture_internal/audio_capture_internal_test.cpp" ] - - deps = [ - "${services_path}/hdfaudioclient:daudio_client", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - external_deps = [ "drivers_interface_distributed_audio:libdaudio_proxy_1.0" ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"unittest\"", - "LOG_DOMAIN=0xD004130", - ] - - cflags = [ - "-Wall", - "-Wextra", - "-Werror", - "-fsigned-char", - "-fno-common", - "-fno-strict-aliasing", - ] -} - -ohos_unittest("AudioAdapterInternalTest") { - module_out_path = module_output_path - - configs = [ ":module_private_config" ] - - sources = [ "audio_adapter_internal/audio_adapter_internal_test.cpp" ] - - deps = [ - "${services_path}/hdfaudioclient:daudio_client", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "c_utils:utils", - "drivers_interface_distributed_audio:libdaudio_proxy_1.0", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"unittest\"", - "LOG_DOMAIN=0xD004130", - ] - - cflags = [ - "-Wall", - "-Wextra", - "-Werror", - "-fsigned-char", - "-fno-common", - "-fno-strict-aliasing", - ] -} - -group("audio_adapter_hdi_test") { - testonly = true - deps = [ - ":AudioAdapterHdiTest", - ":AudioAdapterInternalTest", - ":AudioCaptureInternalTest", - ":AudioRenderInternalTest", - ] -} diff --git a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.cpp b/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.cpp deleted file mode 100644 index 2455a5acd08e51596da05e426159477c45df7ca9..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.cpp +++ /dev/null @@ -1,444 +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. - */ - -#include -#include -#include - -#include "daudio_adapter_internal.h" -#include "audio_adapter_internal_test.h" -#include "audio_adapter.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#include "audio_types.h" -#include -#include -#include -#include - - -#define HDF_LOG_TAG HDF_AUDIO_UT - -using namespace std; -using namespace testing::ext; -namespace OHOS { -namespace DistributedHardware { -class AudioAdapterTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); -}; - -void AudioAdapterTest::SetUpTestCase() -{ -} - -void AudioAdapterTest::TearDownTestCase() -{ -} - -/** -* @tc.name: InitAllPortsInternal -* @tc.desc: Verify the abnormal branch of the InitAllPortsInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, InitAllPortsInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - int32_t ret = adapterContext.instance_.InitAllPorts(adapter); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: InitAllPortsInternal -* @tc.desc: Verify the abnormal branch of the InitAllPortsInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, InitAllPortsInternal_002, TestSize.Level1) -{ - auto adapterContext = std::make_unique(); - int32_t ret = adapterContext->instance_.InitAllPorts(&adapterContext->instance_); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); -} - -/** -* @tc.name: CreateRenderInternal -* @tc.desc: Verify the abnormal branch of the CreateRenderInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, CreateRenderInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - const struct ::AudioDeviceDescriptor *desc = nullptr; - const struct ::AudioSampleAttributes *attrs = nullptr; - struct AudioRender **render = nullptr; - int32_t ret = adapterContext.instance_.CreateRender(adapter, desc, attrs, render); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: DestroyRenderInternal -* @tc.desc: Verify the abnormal branch of the DestroyRenderInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, DestroyRenderInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - struct AudioRender *render = nullptr; - int32_t ret = adapterContext.instance_.DestroyRender(adapter, render); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: DestroyRenderInternal -* @tc.desc: Verify the abnormal branch of the DestroyRenderInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, DestroyRenderInternal_002, TestSize.Level1) -{ - struct AudioRender *render = new AudioRender; - auto adapterContext1 = std::make_unique(); - int32_t ret = adapterContext1->instance_.DestroyRender(&adapterContext1->instance_, render); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - adapterContext->adapterName_ = "adapterName"; - EXPECT_EQ(DH_SUCCESS, adapterContext->instance_.DestroyRender(&adapterContext->instance_, render)); - delete render; -} - -/** -* @tc.name: CreateCaptureInternal -* @tc.desc: Verify the abnormal branch of the CreateCaptureInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, CreateCaptureInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - const struct ::AudioDeviceDescriptor *desc = nullptr; - const struct ::AudioSampleAttributes *attrs = nullptr; - struct AudioCapture **capture = nullptr; - int32_t ret = adapterContext.instance_.CreateCapture(adapter, desc, attrs, capture); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: DestroyCaptureInternal -* @tc.desc: Verify the abnormal branch of the DestroyCaptureInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, DestroyCaptureInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - struct AudioCapture *capture = nullptr; - int32_t ret = adapterContext.instance_.DestroyCapture(adapter, capture); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: DestroyCaptureInternal -* @tc.desc: Verify the abnormal branch of the DestroyCaptureInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, DestroyCaptureInternal_002, TestSize.Level1) -{ - struct AudioCapture *capture = new AudioCapture; - auto adapterContext1 = std::make_unique(); - int32_t ret = adapterContext1->instance_.DestroyCapture(&adapterContext1->instance_, capture); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - adapterContext->adapterName_ = "adapterName"; - EXPECT_EQ(DH_SUCCESS, adapterContext->instance_.DestroyCapture(&adapterContext->instance_, capture)); - delete capture; -} - -/** -* @tc.name: GetPassthroughModeInternal -* @tc.desc: Verify the abnormal branch of the GetPassthroughModeInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, GetPassthroughModeInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - const struct ::AudioPort *port = nullptr; - enum ::AudioPortPassthroughMode *mode = nullptr; - int32_t ret = adapterContext.instance_.GetPassthroughMode(adapter, port, mode); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: GetPassthroughModeInternal -* @tc.desc: Verify the abnormal branch of the GetPassthroughModeInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, GetPassthroughModeInternal_002, TestSize.Level1) -{ - struct ::AudioPort *port = new ::AudioPort; - enum ::AudioPortPassthroughMode *mode = new ::AudioPortPassthroughMode; - auto adapterContext1 = std::make_unique(); - int32_t ret = adapterContext1->instance_.GetPassthroughMode(&adapterContext1->instance_, port, mode); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - port->dir = AudioPortDirection::PORT_OUT; - port->portId = 1; - port->portName = "name"; - adapterContext->adapterName_ = "adapterName"; - EXPECT_EQ(DH_SUCCESS, adapterContext->instance_.GetPassthroughMode(&adapterContext->instance_, port, mode)); - delete port; - delete mode; -} - -/** -* @tc.name: ReleaseAudioRouteInternal -* @tc.desc: Verify the abnormal branch of the ReleaseAudioRouteInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, ReleaseAudioRouteInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - int32_t routeHandle = 0; - int32_t ret = adapterContext.instance_.ReleaseAudioRoute(adapter, routeHandle); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: ReleaseAudioRouteInternal -* @tc.desc: Verify the abnormal branch of the ReleaseAudioRouteInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, ReleaseAudioRouteInternal_002, TestSize.Level1) -{ - int32_t routeHandle = 0; - auto adapterContext1 = std::make_unique(); - int32_t ret = adapterContext1->instance_.ReleaseAudioRoute(&adapterContext1->instance_, routeHandle); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - adapterContext->adapterName_ = "adapterName"; - EXPECT_EQ(DH_SUCCESS, adapterContext->instance_.ReleaseAudioRoute(&adapterContext->instance_, routeHandle)); -} - -/** -* @tc.name: SetPassthroughModeInternal -* @tc.desc: Verify the abnormal branch of the SetPassthroughModeInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, SetPassthroughModeInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - const struct ::AudioPort *port = nullptr; - int32_t ret = adapterContext.instance_.SetPassthroughMode(adapter, port, PORT_PASSTHROUGH_LPCM); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: SetPassthroughModeInternal -* @tc.desc: Verify the abnormal branch of the SetPassthroughModeInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, SetPassthroughModeInternal_002, TestSize.Level1) -{ - struct ::AudioPort *port = new ::AudioPort; - auto adapterContext1 = std::make_unique(); - int32_t ret = adapterContext1->instance_.SetPassthroughMode(&adapterContext1->instance_, port, - PORT_PASSTHROUGH_LPCM); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - port->dir = AudioPortDirection::PORT_OUT; - port->portId = 1; - port->portName = "name"; - adapterContext->adapterName_ = "adapterName"; - EXPECT_EQ(DH_SUCCESS, adapterContext->instance_.SetPassthroughMode(&adapterContext->instance_, - port, PORT_PASSTHROUGH_LPCM)); - delete port; -} - -/** -* @tc.name: UpdateAudioRouteInternal -* @tc.desc: Verify the abnormal branch of the UpdateAudioRouteInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, UpdateAudioRouteInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext1; - struct AudioAdapter *adapter = nullptr; - const struct ::AudioRoute *route = nullptr; - int32_t *routeHandle = nullptr; - int32_t ret = adapterContext1.instance_.UpdateAudioRoute(adapter, route, routeHandle); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - adapterContext->adapterName_ = "adapterName"; - struct ::AudioRoute *route1 = new ::AudioRoute; - route1->sourcesNum = 0; - route1->sinksNum = 0; - int32_t a = 1; - int32_t *routeHandle1 = &a; - EXPECT_EQ(DH_SUCCESS, adapterContext->instance_.UpdateAudioRoute(&adapterContext->instance_, route1, routeHandle1)); - delete route1; -} - -/** -* @tc.name: UpdateAudioRouteInternal -* @tc.desc: Verify the abnormal branch of the UpdateAudioRouteInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, UpdateAudioRouteInternal_002, TestSize.Level1) -{ - auto adapterContext = std::make_unique(); - struct ::AudioRoute *route = new struct ::AudioRoute; - route->sourcesNum = 0; - route->sinksNum = 0; - int32_t *routeHandle = new int32_t(0); - int32_t ret = adapterContext->instance_.UpdateAudioRoute(&adapterContext->instance_, route, routeHandle); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); - delete route; - delete routeHandle; -} - -/** -* @tc.name: SetExtraParamsInternal -* @tc.desc: Verify the abnormal branch of the SetExtraParamsInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, SetExtraParamsInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - const char *condition = nullptr; - const char *value = nullptr; - int32_t ret = adapterContext.instance_.SetExtraParams(adapter, AUDIO_EXT_PARAM_KEY_NONE, condition, value); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: SetExtraParamsInternal -* @tc.desc: Verify the abnormal branch of the SetExtraParamsInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, SetExtraParamsInternal_002, TestSize.Level1) -{ - std::string t_condition = "condition"; - std::string t_value = "value"; - const char *condition = t_condition.c_str(); - const char *value = t_value.c_str(); - auto adapterContext1 = std::make_unique(); - int32_t ret = adapterContext1->instance_.SetExtraParams(&adapterContext1->instance_, - AUDIO_EXT_PARAM_KEY_NONE, condition, value); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - adapterContext->adapterName_ = "adapterName"; - EXPECT_EQ(DH_SUCCESS, adapterContext->instance_.SetExtraParams(&adapterContext->instance_, - AUDIO_EXT_PARAM_KEY_NONE, condition, value)); -} - -/** -* @tc.name: GetExtraParamsInternal -* @tc.desc: Verify the abnormal branch of the GetExtraParamsInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, GetExtraParamsInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext; - struct AudioAdapter *adapter = nullptr; - const char *condition = nullptr; - char *value = nullptr; - int32_t length = 0; - int32_t ret = adapterContext.instance_.GetExtraParams(adapter, AUDIO_EXT_PARAM_KEY_NONE, condition, value, length); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: GetExtraParamsInternal -* @tc.desc: Verify the abnormal branch of the GetExtraParamsInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, GetExtraParamsInternal_002, TestSize.Level1) -{ - std::string t_condition = "condition"; - std::string t_value = "value"; - const char *condition = t_condition.c_str(); - char *value = new char; - int32_t length = 0; - auto adapterContext1 = std::make_unique(); - int32_t ret = adapterContext1->instance_.GetExtraParams(&adapterContext1->instance_, - AUDIO_EXT_PARAM_KEY_NONE, condition, value, length); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - adapterContext->adapterName_ = "adapterName"; - length = 1; - EXPECT_EQ(DH_SUCCESS, adapterContext->instance_.GetExtraParams(&adapterContext->instance_, - AUDIO_EXT_PARAM_KEY_NONE, condition, value, length)); - delete value; -} - -/** -* @tc.name: RegExtraParamObserverInternal -* @tc.desc: Verify the abnormal branch of the RegExtraParamObserverInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioAdapterTest, RegExtraParamObserverInternal_001, TestSize.Level1) -{ - struct AudioAdapterContext adapterContext1; - struct AudioAdapter *adapter = nullptr; - ParamCallback callback = nullptr; - void* cookie = nullptr; - int32_t ret = adapterContext1.instance_.RegExtraParamObserver(adapter, callback, cookie); - auto adapterContext = std::make_unique(); - adapterContext->proxy_ = new MockIAudioAdapter(); - adapterContext->adapterName_ = "adapterName"; - ParamCallback callback1; - cookie = &callback1; - adapterContext->instance_.RegExtraParamObserver(&adapterContext->instance_, - callback1, cookie); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h b/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h deleted file mode 100644 index e083a165d129a771d137b96453b529fe1d93ba6c..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h +++ /dev/null @@ -1,140 +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 DAUDIO_ADAPTER_INTERNAL_TEST_H -#define DAUDIO_ADAPTER_INTERNAL_TEST_H - -#include - -#include "daudio_adapter_internal.h" -#include "audio_adapter.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#include "audio_types.h" -#include -#include -#include -#include -namespace OHOS { -namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioAdapter; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes; -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioRender; -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCapture; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortCapability; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortPassthroughMode; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceStatus; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRoute; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey; -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback; -using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioAdapterDescriptor; -class MockIAudioAdapter : public IAudioAdapter { -public: - MockIAudioAdapter() {} - ~MockIAudioAdapter() {} - - int32_t InitAllPorts() override - { - return DH_SUCCESS; - } - - int32_t CreateRender(const AudioDeviceDescriptor& desc, const AudioSampleAttributes& attrs, - sptr& render, uint32_t &renderId) override - { - return DH_SUCCESS; - } - - int32_t DestroyRender(uint32_t renderId) override - { - return DH_SUCCESS; - } - - int32_t CreateCapture(const AudioDeviceDescriptor& desc, const AudioSampleAttributes& attrs, - sptr& capture, uint32_t &captureId) override - { - return DH_SUCCESS; - } - - int32_t DestroyCapture(uint32_t captureId) override - { - return DH_SUCCESS; - } - - int32_t GetPortCapability(const AudioPort& port, AudioPortCapability& capability) override - { - return DH_SUCCESS; - } - - int32_t SetPassthroughMode(const AudioPort& port, AudioPortPassthroughMode mode) override - { - return DH_SUCCESS; - } - - int32_t GetPassthroughMode(const AudioPort& port, AudioPortPassthroughMode& mode) override - { - return DH_SUCCESS; - } - - int32_t GetDeviceStatus(AudioDeviceStatus& status) override - { - return DH_SUCCESS; - } - - int32_t UpdateAudioRoute(const AudioRoute& route, int32_t& routeHandle) override - { - return DH_SUCCESS; - } - - int32_t ReleaseAudioRoute(int32_t routeHandle) override - { - return DH_SUCCESS; - } - - int32_t SetMicMute(bool mute) override - { - return DH_SUCCESS; - } - - int32_t GetMicMute(bool& mute) override - { - return DH_SUCCESS; - } - - int32_t SetVoiceVolume(float volume) override - { - return DH_SUCCESS; - } - - int32_t SetExtraParams(AudioExtParamKey key, const std::string& condition, const std::string& value) override - { - return DH_SUCCESS; - } - - int32_t GetExtraParams(AudioExtParamKey key, const std::string& condition, std::string& value) override - { - return DH_SUCCESS; - } - - int32_t RegExtraParamObserver(const sptr& audioCallback, int8_t cookie) override - { - return DH_SUCCESS; - } -}; -} // DistributedHardware -} // OHOS -#endif \ No newline at end of file diff --git a/services/hdfaudioclient/test/unittest/audio_capture_internal/audio_capture_internal_test.cpp b/services/hdfaudioclient/test/unittest/audio_capture_internal/audio_capture_internal_test.cpp deleted file mode 100644 index 636ebbc2b0bb2ae2453ccdbd5e92d16bda16aa07..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/test/unittest/audio_capture_internal/audio_capture_internal_test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "daudio_capture_internal.h" -#include "audio_capture.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#define HDF_LOG_TAG HDF_AUDIO_UT - -using namespace std; -using namespace testing::ext; -namespace OHOS { -namespace DistributedHardware { -class AudioCaptureTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); -}; - -void AudioCaptureTest::SetUpTestCase() -{ -} - -void AudioCaptureTest::TearDownTestCase() -{ -} - -/** -* @tc.name: GetCapturePositionInternal -* @tc.desc: Verify the abnormal branch of the GetCapturePositionInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioCaptureTest, GetCapturePositionInternal_001, TestSize.Level1) -{ - struct AudioCaptureContext captureContext; - struct AudioCapture *capture = nullptr; - uint64_t *frames = nullptr; - struct ::AudioTimeStamp *time = nullptr; - int32_t ret = captureContext.instance_.GetCapturePosition(capture, frames, time); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: CaptureFrameInternal -* @tc.desc: Verify the abnormal branch of the CaptureFrameInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioCaptureTest, CaptureFrameInternal_001, TestSize.Level1) -{ - struct AudioCaptureContext captureContext; - struct AudioCapture *capture = nullptr; - void *frame = nullptr; - uint64_t requestBytes = 0; - uint64_t *replyBytes = nullptr; - int32_t ret = captureContext.instance_.CaptureFrame(capture, frame, requestBytes, replyBytes); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/hdfaudioclient/test/unittest/audio_manager_test.cpp b/services/hdfaudioclient/test/unittest/audio_manager_test.cpp deleted file mode 100644 index 4ce51c2f3bd5f8d021082e832b0dfae634d2b55d..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/test/unittest/audio_manager_test.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "distributed_audio_client.h" -#include "audio_manager.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#define HDF_LOG_TAG HDF_AUDIO_UT - -using namespace std; -using namespace testing::ext; -namespace OHOS { -namespace DistributedHardware { -class AudioManagerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); -}; - -void AudioManagerTest::SetUpTestCase() -{ -} - -void AudioManagerTest::TearDownTestCase() -{ -} - -/** -* @tc.name: GetAllAdaptersAbnormal -* @tc.desc: Verify the abnormal branch of the GetAllAdapters, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -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); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); - ret = managerContext.instance_.GetAllAdapters(&managerContext.instance_, &descs, nullptr); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: LoadAdapterAbnormal -* @tc.desc: Verify the abnormal branch of the LoadAdapter, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioManagerTest, LoadAdapterAbnormal, TestSize.Level1) -{ - struct AudioManagerContext managerContext; - 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); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); - ret = managerContext.instance_.LoadAdapter(&managerContext.instance_, &desc, nullptr); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); - managerContext.instance_.UnloadAdapter(manager, adapter); -} -} // DistributedHardware -} // OHOS \ No newline at end of file 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 deleted file mode 100644 index 1377ee4a916d126c27bea44f0ec5430595596079..0000000000000000000000000000000000000000 --- a/services/hdfaudioclient/test/unittest/audio_render_internal/audio_render_internal_test.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "daudio_render_internal.h" -#include "audio_render.h" -#include "daudio_errorcode.h" -#include "daudio_log.h" - -#define HDF_LOG_TAG HDF_AUDIO_UT - -using namespace std; -using namespace testing::ext; -namespace OHOS { -namespace DistributedHardware { -class AudioRenderTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); -}; - -void AudioRenderTest::SetUpTestCase() -{ -} - -void AudioRenderTest::TearDownTestCase() -{ -} - -/** -* @tc.name: GetLatencyInternal -* @tc.desc: Verify the abnormal branch of the GetLatencyInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, GetLatencyInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - uint32_t *ms = nullptr; - int32_t ret = renderContext.instance_.GetLatency(render, ms); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: RenderFrameInternal -* @tc.desc: Verify the abnormal branch of the RenderFrameInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, RenderFrameInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - const void *frame = nullptr; - uint64_t requestBytes = 0; - uint64_t *replyBytes = nullptr; - int32_t ret = renderContext.instance_.RenderFrame(render, frame, requestBytes, replyBytes); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: GetRenderPositionInternal -* @tc.desc: Verify the abnormal branch of the GetRenderPositionInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, GetRenderPositionInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - uint64_t *frames = nullptr; - struct ::AudioTimeStamp *time = nullptr; - int32_t ret = renderContext.instance_.GetRenderPosition(render, frames, time); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: SetRenderSpeedInternal -* @tc.desc: Verify the abnormal branch of the SetRenderSpeedInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, SetRenderSpeedInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - float speed = 0.0; - int32_t ret = renderContext.instance_.SetRenderSpeed(render, speed); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: GetRenderSpeedInternal -* @tc.desc: Verify the abnormal branch of the GetRenderSpeedInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, GetRenderSpeedInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - float *speed = nullptr; - int32_t ret = renderContext.instance_.GetRenderSpeed(render, speed); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: GetRenderSpeedInternal -* @tc.desc: Verify the abnormal branch of the GetRenderSpeedInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, GetRenderSpeedInternal_002, TestSize.Level1) -{ - struct AudioRender *render = new AudioRender; - float *speed = new float; - AudioRenderContext *context = reinterpret_cast(render); - int32_t ret = context->instance_.GetRenderSpeed(render, speed); - delete render; - delete speed; - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, ret); -} - -/** -* @tc.name: SetChannelModeInternal -* @tc.desc: Verify the abnormal branch of the SetChannelModeInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, SetChannelModeInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - int32_t ret = renderContext.instance_.SetChannelMode(render, AUDIO_CHANNEL_NORMAL); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: GetChannelModeInternal -* @tc.desc: Verify the abnormal branch of the GetChannelModeInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, GetChannelModeInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - enum ::AudioChannelMode *mode = nullptr; - int32_t ret = renderContext.instance_.GetChannelMode(render, mode); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: RegCallbackInternal -* @tc.desc: Verify the abnormal branch of the RegCallbackInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, RegCallbackInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - ::RenderCallback callback = nullptr; - void *cookie = nullptr; - int32_t ret = renderContext.instance_.RegCallback(render, callback, cookie); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} - -/** -* @tc.name: DrainBufferInternal -* @tc.desc: Verify the abnormal branch of the DrainBufferInternal, when param is null. -* @tc.type: FUNC -* @tc.require: AR000H0E6H -*/ -HWTEST_F(AudioRenderTest, DrainBufferInternal_001, TestSize.Level1) -{ - struct AudioRenderContext renderContext; - struct AudioRender *render = nullptr; - enum ::AudioDrainNotifyType *type = nullptr; - int32_t ret = renderContext.instance_.DrainBuffer(render, type); - EXPECT_EQ(ERR_DH_AUDIO_HDI_INVALID_PARAM, ret); -} -} // DistributedHardware -} // OHOS \ No newline at end of file diff --git a/services/test_example/BUILD.gn b/services/test_example/BUILD.gn index d207d1207b9f43287254cac70212083773df630d..840cdcd085f7369539cddbdd2411058312f2f937 100644 --- a/services/test_example/BUILD.gn +++ b/services/test_example/BUILD.gn @@ -23,17 +23,16 @@ ohos_executable("audio_distributed_test") { include_dirs = [ "./include", - "${driver_audio_path}/include", - "${hdf_service_path}/hdi_service/common/include", - "${services_path}/hdfaudioclient/include", ] sources = [ "distributedaudiotest.cpp" ] - deps = [ "${services_path}/hdfaudioclient:daudio_client" ] + deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", "hdf_core:libhdf_utils", "hilog:libhilog", ] diff --git a/services/hdfaudioclient/include/distributed_audio_client.h b/services/test_example/daudio_errcode.h similarity index 40% rename from services/hdfaudioclient/include/distributed_audio_client.h rename to services/test_example/daudio_errcode.h index 1cef07986f39c30a673dd1b3ebe492b42c1bacbf..b408d5698a2d3f11714dbbd41da4308ff327a447 100644 --- a/services/hdfaudioclient/include/distributed_audio_client.h +++ b/services/test_example/daudio_errcode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -13,37 +13,31 @@ * limitations under the License. */ -#ifndef HDI_DISTRIBUTED_AUDIO_CLIENT_H -#define HDI_DISTRIBUTED_AUDIO_CLIENT_H - -#include -#include -#include -#include -#include - -#include "audio_manager.h" -#include - -#include "daudio_adapter_internal.h" +#ifndef OHOS_DAUDIO_ERRCODE_H +#define OHOS_DAUDIO_ERRCODE_H namespace OHOS { namespace DistributedHardware { -using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioManager; - -struct AudioManagerContext { - AudioManagerContext(); - ~AudioManagerContext(); - void ClearDescriptors(); - - struct AudioManager instance_; - sptr proxy_ = nullptr; - - std::mutex mtx_; - - std::map> adapters_; - std::vector<::AudioAdapterDescriptor> descriptors_; +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, }; -} // DistributedHardware +} // Distributedaudio } // OHOS -#endif // HDI_DISTRIBUTED_AUDIO_CLIENT_H +#endif diff --git a/services/test_example/distributedaudiotest.cpp b/services/test_example/distributedaudiotest.cpp index 93ce79df5ac8faace0e9c9676566fbee108c4673..da67787eb5849474b6670c7dc6f7c67f1ef5fc5c 100644 --- a/services/test_example/distributedaudiotest.cpp +++ b/services/test_example/distributedaudiotest.cpp @@ -28,6 +28,27 @@ #include #include "unistd.h" #include "distributedaudiotest.h" +#include "daudio_log.h" + +using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioAdapter; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioAdapterDescriptor; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioFormat; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPort; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortDirection; +using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioManager; +using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioRender; +using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCapture; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSampleAttributes; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioDeviceDescriptor; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioCategory; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRouteNode; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioExtParamKey; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioRoute; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioSceneDescriptor; +using OHOS::HDI::DistributedAudio::Audio::V1_0::IAudioCallback; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortPin; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortType; +using OHOS::HDI::DistributedAudio::Audio::V1_0::AudioPortRole; namespace { using namespace OHOS::DistributedHardware; @@ -44,16 +65,12 @@ const int32_t CMD_STOP_MIC = 8; const int32_t CMD_SET_VOL = 11; const int32_t CMD_GET_VOL = 12; -const char DEV_TYPE_SPK = '1'; -const char DEV_TYPE_MIC = '2'; const char SPK_FILE_PATH[128] = "/data/test.wav"; const char MIC_FILE_PATH[128] = "/data/mic.pcm"; -constexpr int32_t TYPE_OFFSET = 12; constexpr int32_t AUDIO_SAMPLE_RATE = 48000; constexpr int32_t VOLUME_MIN = 0; constexpr int32_t VOLUME_MAX = 15; -constexpr int32_t VOLUME_BIT = 3; -constexpr int32_t RENDER_FRAME_SIZE = 4096; +constexpr int32_t RENDER_FRAME_SIZE = 3840; constexpr int32_t RENDER_INTER_LEAVED = 1; constexpr int32_t RENDER_STREAM_ID = 0; constexpr int32_t RENDER_CHANNEL_MASK = 2; @@ -62,18 +79,19 @@ constexpr int32_t CAPTURE_STREAM_ID = 2; constexpr int32_t CAPTURE_CHANNEL_MASK = 2; constexpr int64_t AUDIO_FRAME_TIME_INTERFAL_DEFAULT = 21333; -static AudioManager *g_manager = nullptr; -static AudioAdapter *g_adapter = nullptr; -static AudioRender *g_render = nullptr; -static AudioCapture *g_capture = nullptr; -static AudioAdapterDescriptor *g_devices = nullptr; +static OHOS::sptr g_manager = nullptr; +static OHOS::sptr g_adapter = nullptr; +static OHOS::sptr g_render = nullptr; +static OHOS::sptr g_capture = nullptr; +static std::vector g_devices; static std::string g_devId = ""; static constexpr const char* PLAY_THREAD = "playThread"; static constexpr const char* CAPTURE_THREAD = "captureThread"; -int32_t g_deviceNum = 0; +uint32_t renderId_ = 0; +uint32_t captureId_ = 0; int32_t g_frameNum = 0; int32_t g_frameIndex = 0; int32_t g_micFrameNum = 0; @@ -120,13 +138,13 @@ static void FindAudioDevice() std::cout << "Audio manager is null, Please Check network!" << std::endl; return; } - int32_t ret = g_manager->GetAllAdapters(g_manager, &g_devices, &g_deviceNum); + int32_t ret = g_manager->GetAllAdapters(g_devices); if (ret != DH_SUCCESS) { std::cout << "Get audio devices failed!" << std::endl; return; } - for (int32_t index = 0; index < g_deviceNum; index++) { - const AudioAdapterDescriptor &desc = g_devices[index]; + for (uint32_t index = 0; index < g_devices.size(); index++) { + const AudioAdapterDescriptor desc = g_devices[index]; if (index == 0) { g_devId = desc.adapterName; break; @@ -141,7 +159,7 @@ static int32_t InitTestDemo() std::cout << "**********************************************************************************" << std::endl; std::cout << std::endl; std::cout << "Init distributed audio hdf service." << std::endl; - g_manager = GetAudioManagerFuncs(); + g_manager = IAudioManager::Get("daudio_primary_service", false); if (g_manager == nullptr) { std::cout << "Distributed audio manager is null, Please Check network!" << std::endl; return ERR_DH_AUDIO_HDF_FAIL; @@ -156,49 +174,17 @@ static int32_t InitTestDemo() return DH_SUCCESS; } -static void HandleDevError(const char *condition, const char *value) -{ - if (condition[TYPE_OFFSET] == DEV_TYPE_SPK && g_spkStatus != DeviceStatus::DEVICE_IDLE) { - CloseSpk(); - } - - if (condition[TYPE_OFFSET] == DEV_TYPE_MIC && g_micStatus == DeviceStatus::DEVICE_IDLE) { - CloseMic(); - } - - std::cout << "Receive abnormal event, Demo quit." << std::endl; -} - -static int32_t ParamEventCallback(AudioExtParamKey key, const char *condition, const char *value, void *reserved, - void *cookie) -{ - std::string val(value); - std::string con(condition); - std::cout << std::endl; - std::cout << "**********************************************************************************" << std::endl; - std::cout << "Event recived: " << key << std::endl; - std::cout << "Condition: " << con << std::endl; - std::cout << "Value: " << val << std::endl; - std::cout << "**********************************************************************************" << std::endl; - std::cout << std::endl; - - if (key == AudioExtParamKey::AUDIO_EXT_PARAM_KEY_STATUS && con.rfind("ERR_EVENT", 0) == 0) { - HandleDevError(condition, value); - } - return DH_SUCCESS; -} - static int32_t LoadSpkDev(const std::string &devId) { - struct AudioAdapterDescriptor *dev = nullptr; - for (int32_t index = 0; index < g_deviceNum; index++) { - struct AudioAdapterDescriptor &desc = g_devices[index]; + struct AudioAdapterDescriptor dev; + for (uint32_t index = 0; index < g_devices.size(); index++) { + struct AudioAdapterDescriptor desc = g_devices[index]; if (desc.adapterName == devId) { - dev = &desc; + dev = desc; break; } } - if (dev == nullptr) { + if (dev.adapterName.data() == nullptr) { std::cout << "Input device id is wrong." << std::endl; FindAudioDevice(); return ERR_DH_AUDIO_HDF_FAIL; @@ -207,7 +193,7 @@ static int32_t LoadSpkDev(const std::string &devId) return ERR_DH_AUDIO_HDF_FAIL; } if (g_adapter == nullptr) { - int32_t ret = g_manager->LoadAdapter(g_manager, dev, &g_adapter); + int32_t ret = g_manager->LoadAdapter(dev, g_adapter); if (ret != DH_SUCCESS || g_adapter == nullptr) { std::cout << "Load audio device failed, ret: " << ret << std::endl; return ERR_DH_AUDIO_HDF_FAIL; @@ -226,24 +212,18 @@ static void OpenSpk(const std::string &devId) std::cout << "Load spk failed" << std::endl; return; } - ParamCallback callback = ParamEventCallback; - int32_t ret = g_adapter->RegExtraParamObserver(g_adapter, callback, nullptr); - if (ret != DH_SUCCESS) { - std::cout << "Register observer failed, ret: " << ret << std::endl; - return; - } struct AudioDeviceDescriptor renderDesc; renderDesc.pins = AudioPortPin::PIN_OUT_SPEAKER; - renderDesc.desc = nullptr; + renderDesc.desc = ""; AudioSampleAttributes g_rattrs = {}; - g_rattrs.type = AUDIO_IN_MEDIA; + g_rattrs.type = AudioCategory::AUDIO_IN_MEDIA; g_rattrs.interleaved = RENDER_INTER_LEAVED; g_rattrs.streamId = RENDER_STREAM_ID; g_rattrs.channelCount = RENDER_CHANNEL_MASK; g_rattrs.sampleRate = AUDIO_SAMPLE_RATE; g_rattrs.format = AudioFormat::AUDIO_FORMAT_TYPE_PCM_16_BIT; - ret = g_adapter->CreateRender(g_adapter, &renderDesc, &g_rattrs, &g_render); + int32_t ret = g_adapter->CreateRender(renderDesc, g_rattrs, g_render, renderId_); if (ret != DH_SUCCESS || g_render == nullptr) { std::cout << "Open SPK device failed, ret: " << ret << std::endl; return; @@ -274,13 +254,20 @@ static void Play() std::cout << "Play thread setname failed." << std::endl; } std::cout << "Playing thread started." << std::endl; - g_render->control.Start((AudioHandle)g_render); + g_render->Start(); g_spkStatus = DeviceStatus::DEVICE_START; uint64_t size = 0; while (g_spkStatus == DeviceStatus::DEVICE_START) { int64_t startTime = GetNowTimeUs(); - int32_t ret = g_render->RenderFrame(g_render, renderData[g_frameIndex], RENDER_FRAME_SIZE, &size); + + std::vector frameHal(RENDER_FRAME_SIZE); + int32_t ret = memcpy_s(frameHal.data(), RENDER_FRAME_SIZE, renderData[g_frameIndex], RENDER_FRAME_SIZE); + if (ret != EOK) { + DHLOGE("Copy render frame failed, error code %d.", ret); + return; + } + ret = g_render->RenderFrame(frameHal, size); if (ret != DH_SUCCESS) { std::cout<<"RenderFrame failed, index: "<< g_frameIndex << ", ret: " << ret << std::endl; } @@ -360,7 +347,7 @@ static void StopRender() if (g_playingThread.joinable()) { g_playingThread.join(); } - g_render->control.Stop((AudioHandle)g_render); + g_render->Stop(); } static void CloseSpk() @@ -374,13 +361,13 @@ static void CloseSpk() StopRender(); } - int32_t ret = g_adapter->DestroyRender(g_adapter, g_render); + int32_t ret = g_adapter->DestroyRender(renderId_); if (ret != DH_SUCCESS) { std::cout << "Close speaker failed" << std::endl; return; } if (g_micStatus == DeviceStatus::DEVICE_IDLE) { - g_manager->UnloadAdapter(g_manager, g_adapter); + g_manager->UnloadAdapter(g_devId); g_adapter = nullptr; } g_spkStatus = DeviceStatus::DEVICE_IDLE; @@ -397,15 +384,15 @@ static void CloseSpk() static int32_t LoadMicDev(const std::string &devId) { - struct AudioAdapterDescriptor *dev = nullptr; - for (int32_t index = 0; index < g_deviceNum; index++) { - struct AudioAdapterDescriptor &desc = g_devices[index]; + struct AudioAdapterDescriptor dev; + for (uint32_t index = 0; index < g_devices.size(); index++) { + struct AudioAdapterDescriptor desc = g_devices[index]; if (desc.adapterName == devId) { - dev = &desc; + dev = desc; break; } } - if (dev == nullptr) { + if (dev.adapterName.data() == nullptr) { std::cout << "Input device id is wrong." << std::endl; FindAudioDevice(); return ERR_DH_AUDIO_HDF_FAIL; @@ -414,7 +401,7 @@ static int32_t LoadMicDev(const std::string &devId) return ERR_DH_AUDIO_HDF_FAIL; } if (g_adapter == nullptr) { - int32_t ret = g_manager->LoadAdapter(g_manager, dev, &g_adapter); + int32_t ret = g_manager->LoadAdapter(dev, g_adapter); if (ret != DH_SUCCESS || g_adapter == nullptr) { std::cout << "Load audio device failed, ret: " << ret << std::endl; return ERR_DH_AUDIO_HDF_FAIL; @@ -436,15 +423,15 @@ static void OpenMic(const std::string &devId) AudioDeviceDescriptor captureDesc; captureDesc.pins = AudioPortPin::PIN_IN_MIC; - captureDesc.desc = nullptr; + captureDesc.desc = ""; AudioSampleAttributes captureAttr; - captureAttr.type = AUDIO_IN_MEDIA; + captureAttr.type = AudioCategory::AUDIO_IN_MEDIA; captureAttr.interleaved = CAPTURE_INTER_LEAVED; captureAttr.streamId = CAPTURE_STREAM_ID; captureAttr.channelCount = CAPTURE_CHANNEL_MASK; captureAttr.sampleRate = AUDIO_SAMPLE_RATE; captureAttr.format = AudioFormat::AUDIO_FORMAT_TYPE_PCM_16_BIT; - int32_t ret = g_adapter->CreateCapture(g_adapter, &captureDesc, &captureAttr, &g_capture); + int32_t ret = g_adapter->CreateCapture(captureDesc, captureAttr, g_capture, captureId_); if (ret != DH_SUCCESS || g_capture == nullptr) { std::cout << "Open MIC device failed." << std::endl; return; @@ -475,19 +462,19 @@ static void Capture() std::cout << "Capture thread setname failed." << std::endl; } std::cout << "Capturing thread started." << std::endl; - g_capture->control.Start((AudioHandle)g_capture); + g_capture->Start(); g_micStatus = DeviceStatus::DEVICE_START; uint64_t size = 0; while (g_micStatus == DeviceStatus::DEVICE_START) { - uint8_t *data[RENDER_FRAME_SIZE]; + std::vector data(RENDER_FRAME_SIZE); int64_t startTime = GetNowTimeUs(); - int32_t ret = g_capture->CaptureFrame(g_capture, data, RENDER_FRAME_SIZE, &size); + int32_t ret = g_capture->CaptureFrame(data, size); if (ret != DH_SUCCESS) { std::cout << "CaptureFrame failed, ret: " << ret << std::endl; return; } - size_t writeCnt = fwrite(data, 1, RENDER_FRAME_SIZE, g_micFile); + size_t writeCnt = fwrite(data.data(), 1, RENDER_FRAME_SIZE, g_micFile); if (static_cast(writeCnt) != RENDER_FRAME_SIZE) { std::cout << "fwrite data failed." << std::endl; } @@ -546,7 +533,7 @@ static void StopCapture() if (g_capingThread.joinable()) { g_capingThread.join(); } - g_capture->control.Stop((AudioHandle)g_capture); + g_capture->Stop(); } static void CloseMic() @@ -560,13 +547,13 @@ static void CloseMic() StopCapture(); } - int32_t ret = g_adapter->DestroyCapture(g_adapter, g_capture); + int32_t ret = g_adapter->DestroyCapture(captureId_); if (ret != DH_SUCCESS) { std::cout << "Close mic failed." << std::endl; return; } if (g_spkStatus == DeviceStatus::DEVICE_IDLE) { - g_manager->UnloadAdapter(g_manager, g_adapter); + g_manager->UnloadAdapter(g_devId); g_adapter = nullptr; } if (g_micFile != nullptr) { @@ -593,7 +580,7 @@ static void SetVolume() AudioExtParamKey key = AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME; std::string condition = "EVENT_TYPE=1;VOLUME_GROUP_ID=1;AUDIO_VOLUME_TYPE=1;"; std::string volStr = std::to_string(volInt); - int32_t ret = g_adapter->SetExtraParams(g_adapter, key, condition.c_str(), volStr.c_str()); + int32_t ret = g_adapter->SetExtraParams(key, condition, volStr); if (ret != DH_SUCCESS) { std::cout << "Set volume failed" << std::endl; } @@ -607,8 +594,8 @@ static void GetVolume() } AudioExtParamKey key = AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME; std::string condition = "EVENT_TYPE=1;VOLUME_GROUP_ID=1;AUDIO_VOLUME_TYPE=1;"; - char vol[VOLUME_BIT]; - int32_t ret = g_adapter->GetExtraParams(g_adapter, key, condition.c_str(), vol, VOLUME_BIT); + std::string vol; + int32_t ret = g_adapter->GetExtraParams(key, condition.c_str(), vol); if (ret != DH_SUCCESS) { std::cout << "Get Volume failed." << std::endl; return; diff --git a/services/test_example/distributedaudiotest.h b/services/test_example/distributedaudiotest.h index a4ec143fdde31ba12cab94ea5fbaf9b2205cbcaf..7ca9c44fb24af455e9c7eea15beb424acfa81502 100644 --- a/services/test_example/distributedaudiotest.h +++ b/services/test_example/distributedaudiotest.h @@ -24,9 +24,10 @@ #include #include -#include "audio_adapter.h" -#include "audio_manager.h" -#include "audio_types.h" +#include +#include +#include +#include #include "daudio_errcode.h" enum class DeviceStatus : uint32_t {