From cb420dbb7a2dbeb69ca1e5d2ada568c1e48f2183 Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Fri, 23 Feb 2024 17:52:17 +0800 Subject: [PATCH 1/3] Distributed_audio fix to support for independent compilation Signed-off-by: zhonglufu --- audiohandler/BUILD.gn | 9 +- audiohandler/include/daudio_handler.h | 1 - audiohandler/include/ihardware_handler.h | 51 ++ audiohandler/src/daudio_handler.cpp | 1 - common/dfx_utils/include/daudio_hidumper.h | 8 - common/dfx_utils/src/daudio_hidumper.cpp | 17 - .../inner_kits/native_cpp/audio_sink/BUILD.gn | 5 +- .../include/idistributed_hardware_sink.h | 55 ++ .../native_cpp/audio_source/BUILD.gn | 5 +- .../include/idistributed_hardware_source.h | 59 +++ services/audiomanager/servicesink/BUILD.gn | 1 - services/audiomanager/servicesource/BUILD.gn | 7 +- .../audiotransport/receiverengine/BUILD.gn | 6 +- services/audiotransport/senderengine/BUILD.gn | 6 +- services/hdfaudioclient/BUILD.gn | 4 +- .../hdfaudioclient/include/audio_adapter.h | 270 ++++++++++ .../hdfaudioclient/include/audio_attribute.h | 167 ++++++ .../hdfaudioclient/include/audio_capture.h | 98 ++++ .../hdfaudioclient/include/audio_control.h | 131 +++++ .../hdfaudioclient/include/audio_manager.h | 111 ++++ .../hdfaudioclient/include/audio_render.h | 181 +++++++ services/hdfaudioclient/include/audio_scene.h | 86 ++++ services/hdfaudioclient/include/audio_types.h | 487 ++++++++++++++++++ .../hdfaudioclient/include/audio_volume.h | 137 +++++ services/test_example/BUILD.gn | 2 - services/test_example/daudio_errcode.h | 43 ++ 26 files changed, 1883 insertions(+), 65 deletions(-) create mode 100644 audiohandler/include/ihardware_handler.h create mode 100644 interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h create mode 100644 interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h create mode 100644 services/hdfaudioclient/include/audio_adapter.h create mode 100644 services/hdfaudioclient/include/audio_attribute.h create mode 100644 services/hdfaudioclient/include/audio_capture.h create mode 100644 services/hdfaudioclient/include/audio_control.h create mode 100644 services/hdfaudioclient/include/audio_manager.h create mode 100644 services/hdfaudioclient/include/audio_render.h create mode 100644 services/hdfaudioclient/include/audio_scene.h create mode 100644 services/hdfaudioclient/include/audio_types.h create mode 100644 services/hdfaudioclient/include/audio_volume.h create mode 100644 services/test_example/daudio_errcode.h diff --git a/audiohandler/BUILD.gn b/audiohandler/BUILD.gn index ef27e252..cfc10ac4 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 4b79ea82..75123436 100644 --- a/audiohandler/include/daudio_handler.h +++ b/audiohandler/include/daudio_handler.h @@ -22,7 +22,6 @@ #include "single_instance.h" #include "audio_param.h" #include "audio_capturer.h" -#include "audio_info.h" namespace OHOS { namespace DistributedHardware { diff --git a/audiohandler/include/ihardware_handler.h b/audiohandler/include/ihardware_handler.h new file mode 100644 index 00000000..5ff5c405 --- /dev/null +++ b/audiohandler/include/ihardware_handler.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_IHARDWARE_HANDLER_H +#define OHOS_DISTRIBUTED_HARDWARE_IHARDWARE_HANDLER_H + +#include +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +const std::string COMPONENT_LOADER_GET_HARDWARE_HANDLER = "GetHardwareHandler"; +struct DHItem { + std::string dhId; + std::string attrs; + std::string subtype; +}; + +class PluginListener { +public: + virtual void PluginHardware(const std::string &dhId, const std::string &attrs, const std::string &subtype) = 0; + virtual void UnPluginHardware(const std::string &dhId) = 0; +}; + +class IHardwareHandler { +public: + virtual int32_t Initialize() = 0; + virtual std::vector Query() = 0; + virtual std::map QueryExtraInfo() = 0; + virtual bool IsSupportPlugin() = 0; + virtual void RegisterPluginListener(std::shared_ptr listener) = 0; + virtual void UnRegisterPluginListener() = 0; +}; +extern "C" __attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/audiohandler/src/daudio_handler.cpp b/audiohandler/src/daudio_handler.cpp index 36275a2e..c6551f37 100644 --- a/audiohandler/src/daudio_handler.cpp +++ b/audiohandler/src/daudio_handler.cpp @@ -22,7 +22,6 @@ #include "nlohmann/json.hpp" #include "string_ex.h" -#include "histreamer_query_tool.h" #include "daudio_constants.h" #include "daudio_errorcode.h" #include "daudio_log.h" diff --git a/common/dfx_utils/include/daudio_hidumper.h b/common/dfx_utils/include/daudio_hidumper.h index aa1d6da9..667e33db 100644 --- a/common/dfx_utils/include/daudio_hidumper.h +++ b/common/dfx_utils/include/daudio_hidumper.h @@ -20,11 +20,6 @@ #include #include "sys/stat.h" -#include "audio_capturer.h" -#include "audio_info.h" - -#include "audio_adapter.h" -#include "audio_manager.h" #include "daudio_handler.h" #include "single_instance.h" @@ -60,10 +55,7 @@ private: int32_t StopDumpData(std::string &result); private: - AudioManager *audioManager_ = nullptr; - AudioAdapterDescriptor *adapterdesc_ = nullptr; bool dumpAudioDataFlag_ = false; - int32_t g_deviceNum = 0; const std::string DEFAULT_SPK_DHID = "1"; const std::string DEFAULT_MIC_DHID = "134217729"; }; diff --git a/common/dfx_utils/src/daudio_hidumper.cpp b/common/dfx_utils/src/daudio_hidumper.cpp index d33ddbe8..44376fb9 100644 --- a/common/dfx_utils/src/daudio_hidumper.cpp +++ b/common/dfx_utils/src/daudio_hidumper.cpp @@ -128,23 +128,6 @@ int32_t DaudioHidumper::GetSourceDevId(std::string &result) int32_t DaudioHidumper::GetSinkInfo(std::string &result) { DHLOGI("Get sink info dump."); - audioManager_ = GetAudioManagerFuncs(); - if (audioManager_ == nullptr) { - return ERR_DH_AUDIO_NULLPTR; - } - int32_t ret = audioManager_->GetAllAdapters(audioManager_, &adapterdesc_, &g_deviceNum); - if (ret != DH_SUCCESS) { - DHLOGE("Get all adapters failed."); - return ERR_DH_AUDIO_NULLPTR; - } - for (int32_t index = 0; index < g_deviceNum; index++) { - AudioAdapterDescriptor &desc = adapterdesc_[index]; - result.append("sinkDevId: ").append(GetAnonyString(desc.adapterName)).append(" portId: "); - for (uint32_t i = 0; i < desc.portNum; i++) { - result.append(std::to_string(desc.ports[i].portId)).append(" "); - } - } - return DH_SUCCESS; } diff --git a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn index 2a10e58d..3b4c678b 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", diff --git a/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h b/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h new file mode 100644 index 00000000..db9dc6c6 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SINK_H +#define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SINK_H + +#include + +namespace OHOS { +namespace DistributedHardware { +const std::string COMPONENT_LOADER_GET_SINK_HANDLER = "GetSinkHardwareHandler"; +enum class ResourceEventType : int32_t { + EVENT_TYPE_QUERY_RESOURCE = 0, + EVENT_TYPE_PULL_UP_PAGE = 1, + EVENT_TYPE_CLOSE_PAGE = 2 +}; + +class SubscribeCallback { +public: + virtual int32_t OnSubscribeCallback(const std::string &dhId, int32_t status, const std::string &data) = 0; +}; + +class PrivacyResourcesListener { +public: + virtual int32_t OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) = 0; +}; + +class IDistributedHardwareSink { +public: + virtual int32_t InitSink(const std::string ¶ms) = 0; + virtual int32_t ReleaseSink() = 0; + virtual int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶ms) = 0; + virtual int32_t UnsubscribeLocalHardware(const std::string &dhId) = 0; + virtual int32_t RegisterPrivacyResources(std::shared_ptr listener) = 0; + virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; + virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; + virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; +}; +extern "C" __attribute__((visibility("default"))) IDistributedHardwareSink* GetSinkHardwareHandler(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn index feacb89b..9fcf62d7 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", diff --git a/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h b/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h new file mode 100644 index 00000000..78e2ed4d --- /dev/null +++ b/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H +#define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H + +#include +#include + +namespace OHOS { +namespace DistributedHardware { +const std::string COMPONENT_LOADER_GET_SOURCE_HANDLER = "GetSourceHardwareHandler"; +class RegisterCallback { +public: + virtual int32_t OnRegisterResult(const std::string &uuid, const std::string &dhId, int32_t status, + const std::string &data) = 0; +}; + +class UnregisterCallback { +public: + virtual int32_t OnUnregisterResult(const std::string &uuid, const std::string &dhId, int32_t status, + const std::string &data) = 0; +}; + +struct EnableParam { + std::string sourceVersion; + std::string sourceAttrs; + std::string sinkVersion; + std::string sinkAttrs; + std::string subtype; +}; + +class IDistributedHardwareSource { +public: + virtual int32_t InitSource(const std::string ¶ms) = 0; + virtual int32_t ReleaseSource() = 0; + virtual int32_t RegisterDistributedHardware(const std::string &uuid, const std::string &dhId, + const EnableParam ¶m, std::shared_ptr callback) = 0; + virtual int32_t UnregisterDistributedHardware(const std::string &uuid, const std::string &dhId, + std::shared_ptr callback) = 0; + virtual int32_t ConfigDistributedHardware(const std::string &uuid, const std::string &dhId, const std::string &key, + const std::string &value) = 0; +}; +extern "C" __attribute__((visibility("default"))) IDistributedHardwareSource* GetSourceHardwareHandler(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/services/audiomanager/servicesink/BUILD.gn b/services/audiomanager/servicesink/BUILD.gn index 02241542..842a8575 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -29,7 +29,6 @@ ohos_shared_library("distributed_audio_sink") { include_dirs = [ "//third_party/json/include", "//third_party/cJSON", - "${fwk_common_path}/utils/include", ] include_dirs += [ diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index c7d2fb51..572667c0 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -29,11 +29,6 @@ ohos_shared_library("distributed_audio_source") { include_dirs = [ "//third_party/json/include", "//third_party/cJSON", - "${driver_audio_path}/include", - "${fwk_common_path}/utils/include", - "${mediastandardfwk_path}/audiocapturer/include", - "${mediastandardfwk_path}/audiocommon/include", - "${mediastandardfwk_path}/audiomanager/include", ] include_dirs += [ @@ -49,7 +44,6 @@ ohos_shared_library("distributed_audio_source") { "${common_path}/dfx_utils/include", "${common_path}/include", "${distributedaudio_path}/audiohandler/include", - "${hdf_service_path}/hdi_service/common/include", "${innerkits_path}/native_cpp/audio_sink/include", "${innerkits_path}/native_cpp/audio_source/include", "${interfaces_path}/inner_kits/native_cpp/audio_sink/include", @@ -92,6 +86,7 @@ ohos_shared_library("distributed_audio_source") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", + "audio_framework:audio_capturer", "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", diff --git a/services/audiotransport/receiverengine/BUILD.gn b/services/audiotransport/receiverengine/BUILD.gn index 98cc9aa9..df5377c3 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 6e18f37a..fd720530 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/hdfaudioclient/BUILD.gn b/services/hdfaudioclient/BUILD.gn index f702e01b..a29eb55d 100644 --- a/services/hdfaudioclient/BUILD.gn +++ b/services/hdfaudioclient/BUILD.gn @@ -12,7 +12,6 @@ # limitations under the License. import("//build/ohos.gni") -import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") import("../../distributedaudio.gni") ohos_shared_library("daudio_client") { @@ -29,7 +28,6 @@ ohos_shared_library("daudio_client") { include_dirs = [ "./include", "${common_path}/include", - "${driver_audio_path}/include", ] sources = [ @@ -41,7 +39,7 @@ ohos_shared_library("daudio_client") { "./src/distributed_audio_client.cpp", ] - public_deps = [ "${services_path}/common:distributed_audio_utils" ] + deps = [ "${services_path}/common:distributed_audio_utils" ] external_deps = [ "c_utils:utils", diff --git a/services/hdfaudioclient/include/audio_adapter.h b/services/hdfaudioclient/include/audio_adapter.h new file mode 100644 index 00000000..5872080a --- /dev/null +++ b/services/hdfaudioclient/include/audio_adapter.h @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_adapter.h + * + * @brief Declares APIs for operations related to the audio adapter. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_ADAPTER_H +#define AUDIO_ADAPTER_H + +#include "audio_types.h" +#include "audio_render.h" +#include "audio_capture.h" + +/** + * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, + * and obtaining the port capability set. + * + * @see AudioRender + * @see AudioCapture + * @since 1.0 + * @version 1.0 + */ +struct AudioAdapter { + /** + * @brief Initializes all ports of an audio adapter. + * + * Call this function before calling other driver functions to check whether the initialization is complete. + * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again + * until the port initialization is complete. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @return Returns 0 if the initialization is successful; returns a negative value otherwise. + */ + int32_t (*InitAllPorts)(struct AudioAdapter *adapter); + + /** + * @brief Creates an AudioRender object. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter to start. + * @param attrs Indicates the pointer to the audio sampling attributes to open. + * @param render Indicates the double pointer to the AudioRender object. + * @return Returns 0 if the AudioRender object is created successfully; + * returns a negative value otherwise. + * @see GetPortCapability + * @see DestroyRender + */ + int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, + const struct AudioSampleAttributes *attrs, struct AudioRender **render); + + /** + * @brief Destroys an AudioRender object. + * + * @attention Do not destroy the object during audio rendering. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param render Indicates the pointer to the AudioRender object to operate. + * @return Returns 0 if the AudioRender object is destroyed; returns a negative value otherwise. + * @see CreateRender + */ + int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render); + + /** + * @brief Creates an AudioCapture object. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter to start. + * @param attrs Indicates the pointer to the audio sampling attributes to open. + * @param capture Indicates the double pointer to the AudioCapture object. + * @return Returns 0 if the AudioCapture object is created successfully; + * returns a negative value otherwise. + * @see GetPortCapability + * @see DestroyCapture + */ + int32_t (*CreateCapture)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, + const struct AudioSampleAttributes *attrs, struct AudioCapture **capture); + + /** + * @brief Destroys an AudioCapture object. + * + * @attention Do not destroy the object during audio capturing. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param capture Indicates the pointer to the AudioCapture object to operate. + * @return Returns 0 if the AudioCapture object is destroyed; returns a negative value otherwise. + * @see CreateCapture + */ + int32_t (*DestroyCapture)(struct AudioAdapter *adapter, struct AudioCapture *capture); + + /** + * @brief Obtains the capability set of the port driver for the audio adapter. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param capability Indicates the pointer to the capability set to obtain. + * @return Returns 0 if the capability set is successfully obtained; returns a negative value otherwise. + */ + int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, + struct AudioPortCapability *capability); + + /** + * @brief Sets the passthrough data transmission mode of the audio port driver. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param mode Indicates the passthrough transmission mode to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetPassthroughMode + */ + int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, + enum AudioPortPassthroughMode mode); + + /** + * @brief Obtains the passthrough data transmission mode of the audio port driver. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param port Indicates the pointer to the port. + * @param mode Indicates the pointer to the passthrough transmission mode to obtain. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetPassthroughMode + */ + int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, + enum AudioPortPassthroughMode *mode); + + /** + * @brief Update audio route on several source and sink ports. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param route Indicates route information. + * @param routeHandle Indicates route handle. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetPassthroughMode + */ + int32_t (*UpdateAudioRoute)(struct AudioAdapter *adapter, const struct AudioRoute *route, int32_t *routeHandle); + + /** + * @brief Release an audio route. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param routeHandle Indicates route handle. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetPassthroughMode + */ + int32_t (*ReleaseAudioRoute)(struct AudioAdapter *adapter, int32_t routeHandle); + + /** + * @brief Sets the mute operation for the audio. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param mute Specifies whether to mute the audio. Value true means to mute the audio, + * and false means the opposite. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetMute + */ + int32_t (*SetMicMute)(struct AudioAdapter *adapter, bool mute); + + /** + * @brief Obtains the mute operation set for the audio. + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that + * the audio is muted, and false means the opposite. + * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. + * @see SetMute + */ + int32_t (*GetMicMute)(struct AudioAdapter *adapter, bool *mute); + + /** + * @brief Sets the audio volume for voice call. + * + * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, + * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). + * + * @param adapter Indicates the pointer to the audio adapter to operate. + * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetVolume + */ + int32_t (*SetVoiceVolume)(struct AudioAdapter *adapter, float volume); + + /** + * @brief Sets extra audio parameters. + * + * @param adapter Indicates the audio adapter. + * @param key Indicates what kind of parameter type will be set. + * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. + * @param value Indicates the value of the specified condition. + * + * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). + * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: + * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" + * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4; + * VOLUME_GROUP_ID indicates which volume group will be set; + * AUDIO_VOLUME_TYPE indicates which volume type will be set; + * + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*SetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, + const char *condition, const char *value); + + /** + * @brief Get extra audio parameters. + * + * @param adapter Indicates the audio adapter. + * @param key Indicates what kind of parameter type will be get. + * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. + * @param value Indicates the value of the specified condition. + * @param lenth Indicates the length of the value pointer. + * + * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). + * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: + * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" + * EVENT_TYPE indicates sub volume event type: GetVolume = 1; GetMinVolume = 2; GetMaxVolume = 3; IsStreamMute = 4; + * VOLUME_GROUP_ID indicates which volume group want get; + * AUDIO_VOLUME_TYPE indicates which volume type want get; + * + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, + const char *condition, char *value, int32_t lenth); + + /** + * @brief Register extra audio parameters observer. + * + * @param adapter Indicates the audio adapter. + * @param callback Indicates param observer. + * @param cookie Indicates the pointer to the callback parameters; + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*RegExtraParamObserver)(struct AudioAdapter *adapter, ParamCallback callback, void* cookie); + /** + * @brief Get the device status of an adapter. + * + * @param adapter Indicates the audio adapter. + * @param status Indicates the status of device . + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetDeviceStatus)(struct AudioAdapter *adapter, struct AudioDeviceStatus *status); +}; +#endif /* AUDIO_ADAPTER_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_attribute.h b/services/hdfaudioclient/include/audio_attribute.h new file mode 100644 index 00000000..b5beed14 --- /dev/null +++ b/services/hdfaudioclient/include/audio_attribute.h @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_attribute.h + * + * @brief Declares APIs for audio attributes. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_ATTRIBUTE_H +#define AUDIO_ATTRIBUTE_H + +#include "audio_types.h" + +/** + * @brief Provides attribute-related APIs for audio rendering or capturing, including functions to + * obtain frame information and set audio sampling attributes. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioAttribute { + /** + * @brief Obtains the audio frame size, that is, the length (in bytes) of a frame. + * + * @param handle Indicates the audio handle. + * @param size Indicates the pointer to the audio frame size (in bytes). + * @return Returns 0 if the audio frame size is obtained; returns a negative value otherwise. + */ + int32_t (*GetFrameSize)(AudioHandle handle, uint64_t *size); + + /** + * @brief Obtains the number of audio frames in the audio buffer. + * + * @param handle Indicates the audio handle. + * @param count Indicates the pointer to the number of audio frames in the audio buffer. + * @return Returns 0 if the number of audio frames is obtained; returns a negative value otherwise. + */ + int32_t (*GetFrameCount)(AudioHandle handle, uint64_t *count); + + /** + * @brief Sets audio sampling attributes. + * + * @param handle Indicates the audio handle. + * @param attrs Indicates the pointer to the audio sampling attributes to set, such as the sampling rate, + * sampling precision, and channel. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetSampleAttributes + */ + int32_t (*SetSampleAttributes)(AudioHandle handle, const struct AudioSampleAttributes *attrs); + + /** + * @brief Obtains audio sampling attributes. + * + * @param handle Indicates the audio handle. + * @param attrs Indicates the pointer to the audio sampling attributes, such as the sampling rate, + * sampling precision, and channel. + * @return Returns 0 if audio sampling attributes are obtained; returns a negative value otherwise. + * @see SetSampleAttributes + */ + int32_t (*GetSampleAttributes)(AudioHandle handle, struct AudioSampleAttributes *attrs); + + /** + * @brief Obtains the data channel ID of the audio. + * + * @param handle Indicates the audio handle. + * @param channelId Indicates the pointer to the data channel ID. + * @return Returns 0 if the data channel ID is obtained; returns a negative value otherwise. + */ + int32_t (*GetCurrentChannelId)(AudioHandle handle, uint32_t *channelId); + + /** + * @brief Sets extra audio parameters. + * + * @param handle Indicates the audio handle. + * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. + * The format is key=value. Separate multiple key-value pairs by semicolons (;). + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*SetExtraParams)(AudioHandle handle, const char *keyValueList); + + /** + * @brief Obtains extra audio parameters. + * + * @param handle Indicates the audio handle. + * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. + * The format is key=value. Separate multiple key-value pairs by semicolons (;). + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetExtraParams)(AudioHandle handle, char *keyValueList, int32_t listLenth); + + /** + * @brief Requests a mmap buffer. + * + * @param handle Indicates the audio handle. + * @param reqSize Indicates the size of the request mmap buffer. + * @param desc Indicates the pointer to the mmap buffer descriptor. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*ReqMmapBuffer)(AudioHandle handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc); + + /** + * @brief Obtains the read/write position of the current mmap buffer. + * + * @param handle Indicates the audio handle. + * @param frames Indicates the pointer to the frame where the read/write starts. + * @param time Indicates the pointer to the timestamp associated with the frame where the read/write starts. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetMmapPosition)(AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time); + + /** + * @brief Add the audio effect which the effectid indicated. + * + * @param handle Indicates the audio handle. + * @param effectid Indicates the audio effect instance identifier which is going to be added. + * @return Returns 0 if the audio effect were added succesffully; returns a negative value otherwise. + */ + int32_t (*AddAudioEffect)(AudioHandle handle, uint64_t effectid); + + /** + * @brief Remove the audio effect which the effectid indicated. + * + * @param handle Indicates the audio handle. + * @param effectid Indicates the audio effect which is going to be removed. + * @return Returns 0 if the audio effect were removed succesffully; returns a negative value otherwise. + */ + int32_t (*RemoveAudioEffect)(AudioHandle handle, uint64_t effectid); + + /** + * @brief Get the buffer size of render or capturer + * + * @param handle Indicates the audio handle. + * @param bufferSize Indicates the buffer size (in bytes) queried from the vendor + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*GetFrameBufferSize)(AudioHandle handle, uint64_t *bufferSize); +}; + +#endif /* AUDIO_ATTRIBUTE_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_capture.h b/services/hdfaudioclient/include/audio_capture.h new file mode 100644 index 00000000..52347aab --- /dev/null +++ b/services/hdfaudioclient/include/audio_capture.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_capture.h + * + * @brief Declares APIs for audio capturing. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_CAPTURE_H +#define AUDIO_CAPTURE_H + +#include "audio_types.h" +#include "audio_control.h" +#include "audio_attribute.h" +#include "audio_scene.h" +#include "audio_volume.h" + +/** + * @brief Provides capabilities for audio capturing, including controlling the capturing, setting audio attributes, + * scenes, and volume, and capturing audio frames. + * + * @see AudioControl + * @see AudioAttribute + * @see AudioScene + * @see AudioVolume + * @since 1.0 + * @version 1.0 + */ +struct AudioCapture { + /** + * @brief Defines the audio control. For details, see {@link AudioControl}. + */ + struct AudioControl control; + /** + * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. + */ + struct AudioAttribute attr; + /** + * @brief Defines the audio scene. For details, see {@link AudioScene}. + */ + struct AudioScene scene; + /** + * @brief Defines audio volume. For details, see {@link AudioVolume}. + */ + struct AudioVolume volume; + + /** + * @brief Reads a frame of input data (uplink data) from the audio driver for capturing. + * + * @param capture Indicates the pointer to the AudioCapture object to operate. + * @param frame Indicates the pointer to the input data to read. + * @param requestBytes Indicates the size of the input data, in bytes. + * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to read. + * @return Returns 0 if the input data is read successfully; returns a negative value otherwise. + */ + int32_t (*CaptureFrame)(struct AudioCapture *capture, void *frame, uint64_t requestBytes, uint64_t *replyBytes); + + /** + * @brief Obtains the last number of input audio frames. + * + * @param capture Indicates the pointer to the AudioCapture object to operate. + * @param frames Indicates the pointer to the last number of input audio frames. + * @param time Indicates the pointer to the timestamp associated with the frame. + * @return Returns 0 if the last number is obtained; returns a negative value otherwise. + * @see CaptureFrame + */ + int32_t (*GetCapturePosition)(struct AudioCapture *capture, uint64_t *frames, struct AudioTimeStamp *time); +}; + +#endif /* AUDIO_CAPTURE_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_control.h b/services/hdfaudioclient/include/audio_control.h new file mode 100644 index 00000000..a20f7875 --- /dev/null +++ b/services/hdfaudioclient/include/audio_control.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_control.h + * + * @brief Declares APIs for audio control. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_CONTROL_H +#define AUDIO_CONTROL_H + +#include "audio_types.h" + +/** + * @brief Provides control-related APIs for audio rendering or capturing, including functions to + * start, stop, pause, and resume audio rendering or capturing, and flush data in the audio buffer. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioControl { + /** + * @brief Starts audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully started; + * returns a negative value otherwise. + * @see Stop + */ + int32_t (*Start)(AudioHandle handle); + + /** + * @brief Stops audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully stopped; + * returns a negative value otherwise. + * @see Start + */ + int32_t (*Stop)(AudioHandle handle); + + /** + * @brief Pauses audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully paused; + * returns a negative value otherwise. + * @see Resume + */ + int32_t (*Pause)(AudioHandle handle); + + /** + * @brief Resumes audio rendering or capturing. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the rendering or capturing is successfully resumed; + * returns a negative value otherwise. + * @see Pause + */ + int32_t (*Resume)(AudioHandle handle); + + /** + * @brief Flushes data in the audio buffer. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the flush is successful; returns a negative value otherwise. + */ + int32_t (*Flush)(AudioHandle handle); + + /** + * @brief Sets or cancels the standby mode of the audio device. + * + * @param handle Indicates the audio handle. + * @return Returns 0 if the device is set to standby mode; returns a positive value if the standby mode is + * canceled; returns a negative value if the setting fails. + */ + int32_t (*TurnStandbyMode)(AudioHandle handle); + + /** + * @brief Dumps information about the audio device. + * + * @param handle Indicates the audio handle. + * @param range Indicates the range of the device information to dump, which can be brief or full information. + * @param fd Indicates the file to which the device information will be dumped. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ + int32_t (*AudioDevDump)(AudioHandle handle, int32_t range, int32_t fd); + + /** + * @brief Query whether the vendor support pause and resume. + * + * @param handle Indicates the audio handle. + * @param supportPause Indicates the state whether the vendor supports pausing. Value true means that + * the vendor supports, and false means the opposite. + * @param supportResume Indicates the state whether the vendor supports resuming. Value true means that + * the vendor supports, and false means the opposite. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see IsSupportsPauseAndResume + */ + int32_t (*IsSupportsPauseAndResume)(AudioHandle handle, bool *supportPause, bool *supportResume); +}; + +#endif /* AUDIO_CONTROL_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_manager.h b/services/hdfaudioclient/include/audio_manager.h new file mode 100644 index 00000000..f952dc3c --- /dev/null +++ b/services/hdfaudioclient/include/audio_manager.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_manager.h + * + * @brief Declares APIs for audio adapter management and loading. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_MANAGER_H +#define AUDIO_MANAGER_H + +#include "audio_types.h" +#include "audio_adapter.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Manages audio adapters through a specific adapter driver program loaded based on the given audio + * adapter descriptor. + * + * @see AudioAdapter + * @since 1.0 + * @version 1.0 + */ +struct AudioManager { + /** + * @brief Obtains the list of all adapters supported by an audio driver. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param descs Indicates the double pointer to the audio adapter list. + * @param size Indicates the pointer to the length of the list. + * @return Returns 0 if the list is obtained successfully; returns a negative value otherwise. + * @see LoadAdapter + */ + int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size); + + /** + * @brief Loads the driver for an audio adapter. + * + * For example, to load a USB driver, you may need to load a dynamic-link library (*.so) in specific implementation. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param desc Indicates the pointer to the descriptor of the audio adapter. + * @param adapter Indicates the double pointer to the audio adapter. + * @return Returns 0 if the driver is loaded successfully; returns a negative value otherwise. + * @see GetAllAdapters + * @see UnloadAdapter + */ + int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc, + struct AudioAdapter **adapter); + + /** + * @brief Unloads the driver of an audio adapter. + * + * @param manager Indicates the pointer to the audio adapter manager to operate. + * @param adapter Indicates the pointer to the audio adapter whose driver will be unloaded. + * @see LoadAdapter + */ + void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter); + + /** + * @brief Release the AudioManager Object. + * + * @param object Indicates the pointer to the audio adapter manager to operate. + * @return Returns true if the Object is released; returns false otherwise. + */ + bool (*ReleaseAudioManagerObject)(struct AudioManager *object); +}; + +/** + * @brief Obtains the operation function list of the {@link AudioManager} class. + * + * @return Returns the pointer to the AudioManager object if the list is obtained; returns NULL otherwise. + */ +struct AudioManager *GetAudioManagerFuncs(void); + +#ifdef __cplusplus +} +#endif + +#endif /* AUDIO_MANAGER_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_render.h b/services/hdfaudioclient/include/audio_render.h new file mode 100644 index 00000000..1627fe62 --- /dev/null +++ b/services/hdfaudioclient/include/audio_render.h @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_render.h + * + * @brief Declares APIs for audio rendering. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_RENDER_H +#define AUDIO_RENDER_H + +#include "audio_types.h" +#include "audio_control.h" +#include "audio_attribute.h" +#include "audio_scene.h" +#include "audio_volume.h" + +/** + * @brief Provides capabilities for audio rendering, including controlling the rendering, setting audio attributes, + * scenes, and volume, obtaining hardware latency, and rendering audio frames. + * + * @see AudioControl + * @see AudioAttribute + * @see AudioScene + * @see AudioVolume + * @since 1.0 + * @version 1.0 + */ +struct AudioRender { + /** + * @brief Defines the audio control. For details, see {@link AudioControl}. + */ + struct AudioControl control; + /** + * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. + */ + struct AudioAttribute attr; + /** + * @brief Defines the audio scene. For details, see {@link AudioScene}. + */ + struct AudioScene scene; + /** + * @brief Defines audio volume. For details, see {@link AudioVolume}. + */ + struct AudioVolume volume; + + /** + * @brief Obtains the estimated latency of the audio device driver. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param ms Indicates the pointer to the latency (in milliseconds) to be obtained. + * @return Returns 0 if the latency is obtained; returns a negative value otherwise. + */ + int32_t (*GetLatency)(struct AudioRender *render, uint32_t *ms); + + /** + * @brief Writes a frame of output data (downlink data) into the audio driver for rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param frame Indicates the pointer to the frame to write. + * @param requestBytes Indicates the size of the frame, in bytes. + * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to write. + * @return Returns 0 if the data is written successfully; returns a negative value otherwise. + */ + int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes); + + /** + * @brief Obtains the last number of output audio frames. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param frames Indicates the pointer to the last number of output audio frames. + * @param time Indicates the pointer to the timestamp associated with the frame. + * @return Returns 0 if the last number is obtained; returns a negative value otherwise. + * @see RenderFrame + */ + int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time); + + /** + * @brief Sets the audio rendering speed. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param speed Indicates the rendering speed to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetRenderSpeed + */ + int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed); + + /** + * @brief Obtains the current audio rendering speed. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param speed Indicates the pointer to the current rendering speed to obtain. + * @return Returns 0 if the speed is successfully obtained; returns a negative value otherwise. + * @see SetRenderSpeed + */ + int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed); + + /** + * @brief Sets the channel mode for audio rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param mode Indicates the channel mode to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetChannelMode + */ + int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode); + + /** + * @brief Obtains the current channel mode for audio rendering. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param mode Indicates the pointer to the channel mode to obtain. + * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. + * @see SetChannelMode + */ + int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode); + + /** + * @brief Registers an audio callback that will be invoked during playback when buffer data writing or + * buffer drain is complete. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param callback Indicates the callback to register. + * @param cookie Indicates the pointer to the callback parameters. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see RegCallback + */ + int32_t (*RegCallback)(struct AudioRender *render, RenderCallback callback, void* cookie); + + /** + * @brief Drains the buffer. + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param type Indicates the pointer to the execution type of this function. For details, + * see {@link AudioDrainNotifyType}. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see RegCallback + */ + int32_t (*DrainBuffer)(struct AudioRender *render, enum AudioDrainNotifyType *type); + + /** + * @brief query whether the vendor supports draining buffer + * + * @param render Indicates the pointer to the AudioRender object to operate. + * @param support indicates the state whether the vendor supports draining buffer. Value true means that + * the vendor supports, and false means the opposite. + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + * @see IsSupportsDrain + */ + int32_t (*IsSupportsDrain)(struct AudioRender *render, bool *support); +}; + +#endif /* AUDIO_RENDER_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_scene.h b/services/hdfaudioclient/include/audio_scene.h new file mode 100644 index 00000000..e6ef9f90 --- /dev/null +++ b/services/hdfaudioclient/include/audio_scene.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_scene.h + * + * @brief Declares APIs for audio scenes. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_SCENE_H +#define AUDIO_SCENE_H + +#include "audio_types.h" + +/** + * @brief Provides scene-related APIs for audio rendering or capturing, including functions to + * select an audio scene and check whether the configuration of an audio scene is supported. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioScene { + /** + * @brief Checks whether the configuration of an audio scene is supported. + * + * @param handle Indicates the audio handle. + * @param scene Indicates the pointer to the descriptor of the audio scene. + * @param supported Indicates the pointer to the variable specifying whether the configuration is supported. + * Value true means that the configuration is supported, and false means the opposite. + * @return Returns 0 if the result is obtained; returns a negative value otherwise. + * @see SelectScene + */ + int32_t (*CheckSceneCapability)(AudioHandle handle, const struct AudioSceneDescriptor *scene, bool *supported); + + /** + * @brief Selects an audio scene. + * + *
    + *
  • To select a specific audio scene, you need to specify both the application scenario and output device. + * For example, to select a scene using a smartphone speaker as the output device, set scene according + * to the scenarios where the speaker is used. For example:
  • + *
      + *
    • For media playback, set the value to media_speaker.
    • + *
    • For a voice call, set the value to voice_speaker.
    • + *
    + *
  • To select only the application scenario, such as media playback, movie, or gaming, you can set + * scene to media, movie, or game, respectively.
  • + *
  • To select only the output device, such as media receiver, speaker, or headset, you can set + * scene to receiver, speaker, or headset, respectively.
  • + *
+ * @param handle Indicates the audio handle. + * @param scene Indicates the pointer to the descriptor of the audio scene to select. + * @return Returns 0 if the scene is selected successfully; returns a negative value otherwise. + * @see CheckSceneCapability + */ + int32_t (*SelectScene)(AudioHandle handle, const struct AudioSceneDescriptor *scene); +}; + +#endif /* AUDIO_SCENE_H */ +/** @} */ diff --git a/services/hdfaudioclient/include/audio_types.h b/services/hdfaudioclient/include/audio_types.h new file mode 100644 index 00000000..76662f99 --- /dev/null +++ b/services/hdfaudioclient/include/audio_types.h @@ -0,0 +1,487 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_types.h + * + * @brief Defines custom data types used in API declarations for the audio module, including audio ports, + * adapter descriptors, device descriptors, scene descriptors, sampling attributes, and timestamp. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_TYPES_H +#define AUDIO_TYPES_H + +#include +#include + +/** + * @brief Defines the audio handle. + */ +typedef void *AudioHandle; + +/** + * @brief Enumerates the audio port type. + */ +enum AudioPortDirection { + PORT_OUT = 0x1u, /**< Output port */ + PORT_IN = 0x2u, /**< Input port */ + PORT_OUT_IN = 0x3u, /**< Input/output port, supporting both audio input and output */ +}; + +/** + * @brief Defines the audio port. + */ +struct AudioPort { + enum AudioPortDirection dir; /**< Audio port type. For details, see {@link AudioPortDirection} */ + uint32_t portId; /**< Audio port ID */ + const char *portName; /**< Audio port name */ +}; + +/** + * @brief Defines the audio adapter descriptor. + * + * An audio adapter is a set of port drivers for a sound card, including the output and input ports. + * One port corresponds to multiple pins, and each pin belongs to a physical component (such as a + * speaker or a wired headset). + */ +struct AudioAdapterDescriptor { + const char *adapterName; /**< Name of the audio adapter */ + uint32_t portNum; /**< Number of ports supported by an audio adapter */ + struct AudioPort *ports; /**< List of ports supported by an audio adapter */ +}; + +/** + * @brief Enumerates the pin of an audio adapter. + */ +enum AudioPortPin { + PIN_NONE = 0x0u, /**< Invalid pin */ + PIN_OUT_SPEAKER = 0x1u, /**< Speaker output pin */ + PIN_OUT_HEADSET = 0x2u, /**< Wired headset pin for output */ + PIN_OUT_LINEOUT = 0x4u, /**< Line-out pin */ + PIN_OUT_HDMI = 0x8u, /**< HDMI output pin */ + PIN_OUT_USB = 0x10u, /**< USB output pin */ + PIN_OUT_USB_EXT = 0x20u, /**< Extended USB output pin*/ + PIN_OUT_EARPIECE = 0x30u, /**< Earpiece output pin */ + PIN_OUT_BLUETOOTH_SCO = 0x40u, /**< Bluetooth SCO output pin */ + PIN_OUT_DAUDIO_DEFAULT = 0x80u, + PIN_OUT_HEADPHONE = 0x100u, /**< Wired headphone output pin*/ + PIN_OUT_USB_HEADSET = 0x200u, /**< ARM USB out pin */ + PIN_IN_MIC = 0x8000001u, /**< Microphone input pin */ + PIN_IN_HS_MIC = 0x8000002u, /**< Wired headset microphone pin for input */ + PIN_IN_LINEIN = 0x8000004u, /**< Line-in pin */ + PIN_IN_USB_EXT = 0x8000008u, /**< Extended USB input pin*/ + PIN_IN_BLUETOOTH_SCO_HEADSET = 0x8000010u, /**< Bluetooth SCO headset input pin */ + PIN_IN_USB_HEADSET = 0x8000040u, /**< ARM USB input pin */ +}; + +/** + * @brief Defines the audio device descriptor. + */ +struct AudioDeviceDescriptor { + uint32_t portId; /**< Audio port ID */ + enum AudioPortPin pins; /**< Pins of audio ports (input and output). For details, see {@link AudioPortPin}. */ + const char *desc; /**< Audio device name */ +}; + +/** + * @brief Enumerates the audio category. + */ +enum AudioCategory { + AUDIO_IN_MEDIA = 0, /**< Media */ + AUDIO_IN_COMMUNICATION, /**< Communications */ + AUDIO_IN_RINGTONE, /**< Ringtone */ + AUDIO_IN_CALL, /**< Call */ + AUDIO_MMAP_NOIRQ, /**< Mmap mode */ +}; + +/** + * @brief Defines the audio scene descriptor. + */ +struct AudioSceneDescriptor { + /** + * @brief Describes the audio scene. + */ + union SceneDesc { + uint32_t id; /**< Audio scene ID */ + const char *desc; /**< Name of the audio scene */ + } scene; /**< The scene object */ + struct AudioDeviceDescriptor desc; /**< Audio device descriptor */ +}; + +/** + * @brief Enumerates the audio format. + */ +enum AudioFormat { + AUDIO_FORMAT_TYPE_PCM_8_BIT = 0x1u, /**< 8-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_16_BIT = 0x2u, /**< 16-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_24_BIT = 0x3u, /**< 24-bit PCM */ + AUDIO_FORMAT_TYPE_PCM_32_BIT = 0x4u, /**< 32-bit PCM */ + AUDIO_FORMAT_TYPE_AAC_MAIN = 0x1000001u, /**< AAC main */ + AUDIO_FORMAT_TYPE_AAC_LC = 0x1000002u, /**< AAC LC */ + AUDIO_FORMAT_TYPE_AAC_LD = 0x1000003u, /**< AAC LD */ + AUDIO_FORMAT_TYPE_AAC_ELD = 0x1000004u, /**< AAC ELD */ + AUDIO_FORMAT_TYPE_AAC_HE_V1 = 0x1000005u, /**< AAC HE_V1 */ + AUDIO_FORMAT_TYPE_AAC_HE_V2 = 0x1000006u, /**< AAC HE_V2 */ + AUDIO_FORMAT_TYPE_G711A = 0x2000001u, /**< G711A */ + AUDIO_FORMAT_TYPE_G711U = 0x2000002u, /**< G711u */ + AUDIO_FORMAT_TYPE_G726 = 0x2000003u, /**< G726 */ +}; + +/** + * @brief Enumerates the audio channel mask. + * + * A mask describes an audio channel position. + */ +enum AudioChannelMask { + AUDIO_CHANNEL_MONO = 1u, /**< Mono channel */ + AUDIO_CHANNEL_FRONT_LEFT = 1u, /**< Front left channel */ + AUDIO_CHANNEL_FRONT_RIGHT = 2u, /**< Front right channel */ + AUDIO_CHANNEL_FRONT_CENTER = 4u, /**< Front right channel */ + AUDIO_CHANNEL_LOW_FREQUENCY = 8u, /**< 0x8 */ + AUDIO_CHANNEL_BACK_LEFT = 16u, /**< 0x10 */ + AUDIO_CHANNEL_BACK_RIGHT = 32u, /**< 0x20 */ + AUDIO_CHANNEL_BACK_CENTER = 256u, /**< 0x100 */ + AUDIO_CHANNEL_SIDE_LEFT = 512u, /**< 0x200 */ + AUDIO_CHANNEL_SIDE_RIGHT = 1024u, /**< 0x400 */ + AUDIO_CHANNEL_TOP_SIDE_LEFT = 262144u, /**< 0x40000 */ + AUDIO_CHANNEL_TOP_SIDE_RIGHT = 524288u, /**< 0x80000 */ + AUDIO_CHANNEL_STEREO = 3u, /**< FRONT_LEFT | FRONT_RIGHT */ + AUDIO_CHANNEL_2POINT1 = 11u, /**< STEREO | LOW_FREQUENCY */ + AUDIO_CHANNEL_QUAD = 51u, /**< STEREO | BACK_LEFT | BACK_RIGHT */ + AUDIO_CHANNEL_3POINT0POINT2 = 786439u, /**< STEREO | FRONT_CENTER | TOP_SIDE_LEFT | TOP_SIDE_RIGHT */ + AUDIO_CHANNEL_5POINT1 = 63u, /**< QUAD | FRONT_CENTER | LOW_FREQUENCY */ + AUDIO_CHANNEL_6POINT1 = 319u, /**< AUDIO_CHANNEL_5POINT1 | BACK_CENTER */ + AUDIO_CHANNEL_7POINT1 = 1599u, /**< AUDIO_CHANNEL_5POINT1 | SIDE_LEFT | SIDE_RIGHT */ +}; + +/** + * @brief Enumerates masks of audio sampling rates. + */ +enum AudioSampleRatesMask { + AUDIO_SAMPLE_RATE_MASK_8000 = 0x1u, /**< 8 kHz */ + AUDIO_SAMPLE_RATE_MASK_12000 = 0x2u, /**< 12 kHz */ + AUDIO_SAMPLE_RATE_MASK_11025 = 0x4u, /**< 11.025 kHz */ + AUDIO_SAMPLE_RATE_MASK_16000 = 0x8u, /**< 16 kHz */ + AUDIO_SAMPLE_RATE_MASK_22050 = 0x10u, /**< 22.050 kHz */ + AUDIO_SAMPLE_RATE_MASK_24000 = 0x20u, /**< 24 kHz */ + AUDIO_SAMPLE_RATE_MASK_32000 = 0x40u, /**< 32 kHz */ + AUDIO_SAMPLE_RATE_MASK_44100 = 0x80u, /**< 44.1 kHz */ + AUDIO_SAMPLE_RATE_MASK_48000 = 0x100u, /**< 48 kHz */ + AUDIO_SAMPLE_RATE_MASK_64000 = 0x200u, /**< 64 kHz */ + AUDIO_SAMPLE_RATE_MASK_96000 = 0x400u, /**< 96 kHz */ + AUDIO_SAMPLE_RATE_MASK_INVALID = 0xFFFFFFFFu, /**< Invalid sampling rate */ +}; +enum AudioInputType { + AUDIO_INPUT_DEFAULT_TYPE = 0, + AUDIO_INPUT_MIC_TYPE = 1 << 0, + AUDIO_INPUT_SPEECH_WAKEUP_TYPE = 1 << 1, + AUDIO_INPUT_VOICE_COMMUNICATION_TYPE = 1 << 2, + AUDIO_INPUT_VOICE_RECOGNITION_TYPE = 1 << 3, +}; +/** + * @brief Defines audio sampling attributes. + */ +struct AudioSampleAttributes { + enum AudioCategory type; /**< Audio type. For details, see {@link AudioCategory} */ + bool interleaved; /**< Interleaving flag of audio data */ + enum AudioFormat format; /**< Audio data format. For details, see {@link AudioFormat}. */ + uint32_t sampleRate; /**< Audio sampling rate */ + uint32_t channelCount; /**< Number of audio channels. For example, for the mono channel, the value is 1, + * and for the stereo channel, the value is 2. + */ + uint32_t period; /**< Audio sampling period */ + uint32_t frameSize; /**< Frame size of the audio data */ + bool isBigEndian; /**< Big endian flag of audio data */ + bool isSignedData; /**< Signed or unsigned flag of audio data */ + uint32_t startThreshold; /**< Audio render start threshold. */ + uint32_t stopThreshold; /**< Audio render stop threshold. */ + uint32_t silenceThreshold; /**< Audio capture buffer threshold. */ + int32_t streamId; /**< Audio Identifier of render or capture */ + int32_t sourceType; +}; + +/** + * @brief Defines the audio timestamp, which is a substitute for POSIX timespec. + */ +struct AudioTimeStamp { + int64_t tvSec; /**< Seconds */ + int64_t tvNSec; /**< Nanoseconds */ +}; + +/** + * @brief Enumerates the passthrough data transmission mode of an audio port. + */ +enum AudioPortPassthroughMode { + PORT_PASSTHROUGH_LPCM = 0x1, /**< Stereo PCM */ + PORT_PASSTHROUGH_RAW = 0x2, /**< HDMI passthrough */ + PORT_PASSTHROUGH_HBR2LBR = 0x4, /**< Blu-ray next-generation audio output with reduced specifications */ + PORT_PASSTHROUGH_AUTO = 0x8, /**< Mode automatically matched based on the HDMI EDID */ +}; + +/** + * @brief Defines the sub-port capability. + */ +struct AudioSubPortCapability { + uint32_t portId; /**< Sub-port ID */ + const char *desc; /**< Sub-port name */ + enum AudioPortPassthroughMode mask; /**< Passthrough mode of data transmission. For details, + * see {@link AudioPortPassthroughMode}. + */ +}; + +/** + * @brief Defines formats of raw audio samples. + */ +enum AudioSampleFormat { + /* 8 bits */ + AUDIO_SAMPLE_FORMAT_S8, /**< signed 8 bit sample */ + AUDIO_SAMPLE_FORMAT_S8P, /**< signed 8 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U8, /**< unsigned 8 bit sample */ + AUDIO_SAMPLE_FORMAT_U8P, /**< unsigned 8 bit planar sample */ + /* 16 bits */ + AUDIO_SAMPLE_FORMAT_S16, /**< signed 16 bit sample */ + AUDIO_SAMPLE_FORMAT_S16P, /**< signed 16 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U16, /**< unsigned 16 bit sample */ + AUDIO_SAMPLE_FORMAT_U16P, /**< unsigned 16 bit planar sample */ + /* 24 bits */ + AUDIO_SAMPLE_FORMAT_S24, /**< signed 24 bit sample */ + AUDIO_SAMPLE_FORMAT_S24P, /**< signed 24 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U24, /**< unsigned 24 bit sample */ + AUDIO_SAMPLE_FORMAT_U24P, /**< unsigned 24 bit planar sample */ + /* 32 bits */ + AUDIO_SAMPLE_FORMAT_S32, /**< signed 32 bit sample */ + AUDIO_SAMPLE_FORMAT_S32P, /**< signed 32 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U32, /**< unsigned 32 bit sample */ + AUDIO_SAMPLE_FORMAT_U32P, /**< unsigned 32 bit planar sample */ + /* 64 bits */ + AUDIO_SAMPLE_FORMAT_S64, /**< signed 64 bit sample */ + AUDIO_SAMPLE_FORMAT_S64P, /**< signed 64 bit planar sample */ + AUDIO_SAMPLE_FORMAT_U64, /**< unsigned 64 bit sample */ + AUDIO_SAMPLE_FORMAT_U64P, /**< unsigned 64 bit planar sample */ + /* float double */ + AUDIO_SAMPLE_FORMAT_F32, /**< float 32 bit sample */ + AUDIO_SAMPLE_FORMAT_F32P, /**< float 32 bit planar sample */ + AUDIO_SAMPLE_FORMAT_F64, /**< double 64 bit sample */ + AUDIO_SAMPLE_FORMAT_F64P, /**< double 64 bit planar sample */ +}; + +/** + * @brief Defines the audio port capability. + */ +struct AudioPortCapability { + uint32_t deviceType; /**< Device type (output or input) */ + uint32_t deviceId; /**< Device ID used for device binding */ + bool hardwareMode; /**< Whether to support device binding */ + uint32_t formatNum; /**< Number of the supported audio formats */ + enum AudioFormat *formats; /**< Supported audio formats. For details, see {@link AudioFormat}. */ + uint32_t sampleRateMasks; /**< Supported audio sampling rates (8 kHz, 16 kHz, 32 kHz, and 48 kHz) */ + enum AudioChannelMask channelMasks; /**< Audio channel layout mask of the device. For details, + * see {@link AudioChannelMask}. + */ + uint32_t channelCount; /**< Supported maximum number of audio channels */ + uint32_t subPortsNum; /**< Number of supported sub-ports (for output devices only) */ + struct AudioSubPortCapability *subPorts; /**< List of supported sub-ports */ + uint32_t supportSampleFormatNum; /**< Number of the supported audio sample format enum. */ + enum AudioSampleFormat *supportSampleFormats; /**< Supported audio sample formats. For details, + * see {@link AudioSampleFormat}. + */ +}; + +/** + * @brief Enumerates channel modes for audio rendering. + * + * @attention The following modes are set for rendering dual-channel audios. Others are not supported. + */ +enum AudioChannelMode { + AUDIO_CHANNEL_NORMAL = 0, /**< Normal mode. No processing is required. */ + AUDIO_CHANNEL_BOTH_LEFT, /**< Two left channels */ + AUDIO_CHANNEL_BOTH_RIGHT, /**< Two right channels */ + AUDIO_CHANNEL_EXCHANGE, /**< Data exchange between the left and right channels. The left channel takes the audio + * stream of the right channel, and the right channel takes that of the left channel. + */ + AUDIO_CHANNEL_MIX, /**< Mix of streams of the left and right channels */ + AUDIO_CHANNEL_LEFT_MUTE, /**< Left channel muted. The stream of the right channel is output. */ + AUDIO_CHANNEL_RIGHT_MUTE, /**< Right channel muted. The stream of the left channel is output. */ + AUDIO_CHANNEL_BOTH_MUTE, /**< Both left and right channels muted */ +}; + +/** + * @brief Enumerates the execution types of the DrainBuffer function. + */ +enum AudioDrainNotifyType { + AUDIO_DRAIN_NORMAL_MODE, /**< The DrainBuffer function returns after all data finishes playback. */ + AUDIO_DRAIN_EARLY_MODE, /**< The DrainBuffer function returns before all the data of the current track + * finishes playback to reserve time for a smooth track switch by the audio service. + */ +}; + +/** + * @brief Enumerates callback notification events. + */ +enum AudioCallbackType { + AUDIO_NONBLOCK_WRITE_COMPLETED, /**< The non-block write is complete. */ + AUDIO_DRAIN_COMPLETED, /**< The draining is complete. */ + AUDIO_FLUSH_COMPLETED, /**< The flush is complete. */ + AUDIO_RENDER_FULL, /**< The render buffer is full.*/ + AUDIO_ERROR_OCCUR, /**< An error occurs.*/ +}; + +/** + * @brief Describes a mmap buffer. + */ +struct AudioMmapBufferDescriptor { + void *memoryAddress; /**< Pointer to the mmap buffer */ + int32_t memoryFd; /**< File descriptor of the mmap buffer */ + int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/ + int32_t transferFrameSize; /**< Transfer size (unit: frame) */ + int32_t isShareable; /**< Whether the mmap buffer can be shared among processes */ + uint32_t offset; +}; + +/** + * @brief Describes AudioPortRole. + */ +enum AudioPortRole { + AUDIO_PORT_UNASSIGNED_ROLE = 0, /**< Unassigned port role */ + AUDIO_PORT_SOURCE_ROLE = 1, /**< Assigned source role */ + AUDIO_PORT_SINK_ROLE = 2, /**< Assigned sink role */ +}; + +/** + * @brief Describes AudioPortType. + */ +enum AudioPortType { + AUDIO_PORT_UNASSIGNED_TYPE = 0, /**< Unassigned port type */ + AUDIO_PORT_DEVICE_TYPE = 1, /**< Assigned device type */ + AUDIO_PORT_MIX_TYPE = 2, /**< Assigned mix type */ + AUDIO_PORT_SESSION_TYPE = 3, /**< Assigned session type */ +}; + +/** + * @brief Describes AudioDevExtInfo. + */ +struct AudioDevExtInfo { + int32_t moduleId; /**< Identifier of the module stream is attached to */ + enum AudioPortPin type; /**< Device type For details, see {@link AudioPortPin}. */ + const char *desc; /**< Address */ +}; + +/** + * @brief Describes AudioMixInfo. + */ +struct AudioMixExtInfo { + int32_t moduleId; /**< Identifier of the module stream is attached to */ + int32_t streamId; /**< Identifier of the capture or render passed by caller */ +}; + +/** + * @brief Describes AudioSessionType. + */ +enum AudioSessionType { + AUDIO_OUTPUT_STAGE_SESSION = 0, + AUDIO_OUTPUT_MIX_SESSION, + AUDIO_ALLOCATE_SESSION, + AUDIO_INVALID_SESSION, +}; + +/** + * @brief Describes AudioSessionExtInfo. + */ +struct AudioSessionExtInfo { + enum AudioSessionType sessionType; +}; + +/** + * @brief Describes AudioRouteNode. + */ +struct AudioRouteNode { + int32_t portId; /**< Audio port ID */ + enum AudioPortRole role; /**< Audio port as a sink or a source */ + enum AudioPortType type; /**< device, mix ... */ + union { + struct AudioDevExtInfo device; /* Specific Device Ext info */ + struct AudioMixExtInfo mix; /* Specific mix info */ + struct AudioSessionExtInfo session; /* session specific info */ + } ext; +}; + +/** + * @brief Describes AudioRoute. + */ +struct AudioRoute { + uint32_t sourcesNum; + const struct AudioRouteNode *sources; + uint32_t sinksNum; + const struct AudioRouteNode *sinks; +}; + +/** + * @brief Enumerates the restricted key type of the parameters + */ +enum AudioExtParamKey { + AUDIO_EXT_PARAM_KEY_NONE = 0, /**< Distributed audio extra param key none */ + AUDIO_EXT_PARAM_KEY_VOLUME = 1, /**< Distributed audio extra param key volume event */ + AUDIO_EXT_PARAM_KEY_FOCUS = 2, /**< Distributed audio extra param key focus event */ + AUDIO_EXT_PARAM_KEY_BUTTON = 3, /**< Distributed audio extra param key media button event */ + AUDIO_EXT_PARAM_KEY_EFFECT = 4, /**< Distributed audio extra param key audio effect event */ + AUDIO_EXT_PARAM_KEY_STATUS = 5, /**< Distributed audio extra param key device status event */ + AUDIO_EXT_PARAM_KEY_USB_DEVICE = 101, /**< Check USB device type ARM or HIFI */ + AUDIO_EXT_PARAM_KEY_LOWPOWER = 1000, /**< Low power event type */ +}; +/** + * @brief Describes status of audio deivce.@link enum AudioDeviceType + */ +struct AudioDeviceStatus { + uint32_t pnpStatus; +}; +/** + * @brief Called when an event defined in {@link AudioCallbackType} occurs. + * + * @param AudioCallbackType Indicates the occurred event that triggers this callback. + * @param reserved Indicates the pointer to a reserved field. + * @param cookie Indicates the pointer to the cookie for data transmission. + * @return Returns 0 if the callback is successfully executed; returns a negative value otherwise. + * @see RegCallback + */ +typedef int32_t (*RenderCallback)(enum AudioCallbackType, void *reserved, void *cookie); + +/** + * @brief Register audio extra param callback that will be invoked during audio param event. + * + * @param key Indicates param change event. + * @param condition Indicates the param condition. + * @param value Indicates the param value. + * @param reserved Indicates reserved param. + * @param cookie Indicates the pointer to the callback parameters; + * @return Returns 0 if the operation is successful; returns a negative value otherwise. + */ +typedef int32_t (*ParamCallback)(enum AudioExtParamKey key, const char *condition, const char *value, void *reserved, + void *cookie); + +#endif /* AUDIO_TYPES_H */ diff --git a/services/hdfaudioclient/include/audio_volume.h b/services/hdfaudioclient/include/audio_volume.h new file mode 100644 index 00000000..ad476f7c --- /dev/null +++ b/services/hdfaudioclient/include/audio_volume.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2020-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup Audio + * @{ + * + * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, + * accessing a driver adapter, and rendering and capturing audios. + * + * @since 1.0 + * @version 1.0 + */ + +/** + * @file audio_volume.h + * + * @brief Declares APIs for audio volume. + * + * @since 1.0 + * @version 1.0 + */ + +#ifndef AUDIO_VOLUME_H +#define AUDIO_VOLUME_H + +#include "audio_types.h" + +/** + * @brief Provides volume-related APIs for audio rendering or capturing, including functions to + * set the mute operation, volume, and gain. + * + * @since 1.0 + * @version 1.0 + */ +struct AudioVolume { + /** + * @brief Sets the mute operation for the audio. + * + * @param handle Indicates the audio handle. + * @param mute Specifies whether to mute the audio. Value true means to mute the audio, + * and false means the opposite. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetMute + */ + int32_t (*SetMute)(AudioHandle handle, bool mute); + + /** + * @brief Obtains the mute operation set for the audio. + * + * @param handle Indicates the audio handle. + * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that + * the audio is muted, and false means the opposite. + * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. + * @see SetMute + */ + int32_t (*GetMute)(AudioHandle handle, bool *mute); + + /** + * @brief Sets the audio volume. + * + * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, + * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). + * + * @param handle Indicates the audio handle. + * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetVolume + */ + int32_t (*SetVolume)(AudioHandle handle, float volume); + + /** + * @brief Obtains the audio volume. + * + * @param handle Indicates the audio handle. + * @param volume Indicates the pointer to the volume to obtain. The value ranges from 0.0 to 1.0. + * @return Returns 0 if the volume is obtained; returns a negative value otherwise. + * @see SetVolume + */ + int32_t (*GetVolume)(AudioHandle handle, float *volume); + + /** + * @brief Obtains the range of the audio gain. + * + * The audio gain can be expressed in one of the following two ways (depending on the chip platform), + * corresponding to two types of value ranges: + *
    + *
  • Actual audio gain values, for example, ranging from -50 to 6 dB
  • + *
  • Float numbers ranging from 0.0 to 1.0, where 0.0 means to mute the audio, + * and 1.0 means the maximum gain value, for example, 6 dB
  • + *
+ * @param handle Indicates the audio handle. + * @param min Indicates the pointer to the minimum value of the range. + * @param max Indicates the pointer to the maximum value of the range. + * @return Returns 0 if the range is obtained; returns a negative value otherwise. + * @see GetGain + * @see SetGain + */ + int32_t (*GetGainThreshold)(AudioHandle handle, float *min, float *max); + + /** + * @brief Obtains the audio gain. + * + * @param handle Indicates the audio handle. + * @param gain Indicates the pointer to the audio gain. + * @return Returns 0 if the audio gain is obtained; returns a negative value otherwise. + * @see GetGainThreshold + * @see SetGain + */ + int32_t (*GetGain)(AudioHandle handle, float *gain); + + /** + * @brief Sets the audio gain. + * + * @param handle Indicates the audio handle. + * @param gain Indicates the audio gain to set. + * @return Returns 0 if the setting is successful; returns a negative value otherwise. + * @see GetGainThreshold + * @see GetGain + */ + int32_t (*SetGain)(AudioHandle handle, float gain); +}; + +#endif /* AUDIO_VOLUME_H */ +/** @} */ diff --git a/services/test_example/BUILD.gn b/services/test_example/BUILD.gn index d207d120..6238bddd 100644 --- a/services/test_example/BUILD.gn +++ b/services/test_example/BUILD.gn @@ -23,8 +23,6 @@ ohos_executable("audio_distributed_test") { include_dirs = [ "./include", - "${driver_audio_path}/include", - "${hdf_service_path}/hdi_service/common/include", "${services_path}/hdfaudioclient/include", ] diff --git a/services/test_example/daudio_errcode.h b/services/test_example/daudio_errcode.h new file mode 100644 index 00000000..b408d569 --- /dev/null +++ b/services/test_example/daudio_errcode.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DAUDIO_ERRCODE_H +#define OHOS_DAUDIO_ERRCODE_H + +namespace OHOS { +namespace DistributedHardware { +enum DAudioErrorCode { + DH_SUCCESS = 0, + // Distributed Audio HDF Error Code + ERR_DH_AUDIO_HDF_FAIL = -46001, + ERR_DH_AUDIO_HDF_NULLPTR = -46002, + ERR_DH_AUDIO_HDF_INVALID_PARAM = -46003, + ERR_DH_AUDIO_HDF_REPEAT_OPERATION = -46004, + ERR_DH_AUDIO_HDF_INVALID_OPERATION = -46005, + ERR_DH_AUDIO_HDF_SET_PARAM_FAIL = -46006, + ERR_DH_AUDIO_HDF_OPEN_DEVICE_FAIL = -46007, + ERR_DH_AUDIO_HDF_CLOSE_DEVICE_FAIL = -46008, + ERR_DH_AUDIO_COMMON_NOT_FOUND_KEY = -46009, + ERR_DH_AUDIO_HDF_WAIT_TIMEOUT = -46010, + + ERR_DH_AUDIO_HDF_INIT_ENGINE_FAILED = -46011, + ERR_DH_AUDIO_HDF_NOTIFY_SINK_FAILED = -46012, + ERR_DH_AUDIO_HDF_TRANS_SETUP_FAILED = -46013, + ERR_DH_AUDIO_HDF_TRANS_START_FAILED = -46014, + ERR_DH_AUDIO_HDF_RESULT_FAILED = -46015, +}; +} // Distributedaudio +} // OHOS +#endif -- Gitee From f709c79ef021bd1a58242a05c178e0b8328513a7 Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Sat, 24 Feb 2024 09:25:44 +0800 Subject: [PATCH 2/3] Distributed_audio fix to support for independent compilation Signed-off-by: zhonglufu --- services/audiomanager/servicesource/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/audiomanager/servicesource/BUILD.gn b/services/audiomanager/servicesource/BUILD.gn index 572667c0..caf33f13 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -86,7 +86,7 @@ ohos_shared_library("distributed_audio_source") { external_deps = [ "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", - "audio_framework:audio_capturer", + "audio_framework:audio_capturer", "c_utils:utils", "distributed_hardware_fwk:distributed_av_receiver", "distributed_hardware_fwk:distributed_av_sender", -- Gitee From e5637fe57ff5cc29a651f06963bbb8fd3e40fbcf Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Thu, 29 Feb 2024 16:53:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=86=E5=B8=83=E5=BC=8F=E9=9F=B3?= =?UTF-8?q?=E9=A2=91=E9=83=A8=E4=BB=B6=E5=8C=96=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhonglufu --- audiohandler/include/ihardware_handler.h | 51 -- bundle.json | 9 - common/dfx_utils/include/daudio_hidumper.h | 7 + common/dfx_utils/src/daudio_hidumper.cpp | 18 + common/dfx_utils/test/unittest/BUILD.gn | 2 +- common/include/single_instance.h | 44 -- .../inner_kits/native_cpp/audio_sink/BUILD.gn | 1 + .../include/idistributed_hardware_sink.h | 55 -- .../native_cpp/audio_source/BUILD.gn | 1 + .../include/idistributed_hardware_source.h | 59 --- .../native_cpp/test/unittest/BUILD.gn | 1 - services/audiomanager/servicesink/BUILD.gn | 1 + services/audiomanager/servicesource/BUILD.gn | 4 +- .../BUILD.gn | 1 + .../sourceservicedaudionotify_fuzzer/BUILD.gn | 1 + .../sourceserviceinitsource_fuzzer/BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../BUILD.gn | 1 + .../test/unittest/servicesource/BUILD.gn | 2 +- .../test/unittest/sourcedevice/BUILD.gn | 1 - .../test/unittest/sourcemanager/BUILD.gn | 1 - services/common/BUILD.gn | 1 + services/hdfaudioclient/BUILD.gn | 60 --- .../hdfaudioclient/include/audio_adapter.h | 270 ---------- .../hdfaudioclient/include/audio_attribute.h | 167 ------ .../hdfaudioclient/include/audio_capture.h | 98 ---- .../hdfaudioclient/include/audio_control.h | 131 ----- .../hdfaudioclient/include/audio_manager.h | 111 ---- .../hdfaudioclient/include/audio_render.h | 181 ------- services/hdfaudioclient/include/audio_scene.h | 86 ---- services/hdfaudioclient/include/audio_types.h | 487 ------------------ .../hdfaudioclient/include/audio_volume.h | 137 ----- .../include/daudio_adapter_internal.h | 54 -- .../include/daudio_attribute_internal.h | 244 --------- .../include/daudio_capture_internal.h | 41 -- .../include/daudio_control_internal.h | 134 ----- .../include/daudio_param_callback_internal.h | 33 -- .../include/daudio_render_callback_internal.h | 33 -- .../include/daudio_render_internal.h | 44 -- .../include/daudio_scene_internal.h | 88 ---- .../include/daudio_volume_internal.h | 132 ----- .../include/distributed_audio_client.h | 49 -- .../src/daudio_adapter_internal.cpp | 464 ----------------- .../src/daudio_capture_internal.cpp | 121 ----- .../src/daudio_param_callback_internal.cpp | 71 --- .../src/daudio_render_callback_internal.cpp | 67 --- .../src/daudio_render_internal.cpp | 200 ------- .../src/distributed_audio_client.cpp | 281 ---------- .../hdfaudioclient/test/unittest/BUILD.gn | 166 ------ .../audio_adapter_internal_test.cpp | 444 ---------------- .../audio_adapter_internal_test.h | 140 ----- .../audio_capture_internal_test.cpp | 78 --- .../test/unittest/audio_manager_test.cpp | 85 --- .../audio_render_internal_test.cpp | 200 ------- services/test_example/BUILD.gn | 5 +- .../test_example/distributedaudiotest.cpp | 159 +++--- services/test_example/distributedaudiotest.h | 7 +- 58 files changed, 119 insertions(+), 5213 deletions(-) delete mode 100644 audiohandler/include/ihardware_handler.h delete mode 100644 common/include/single_instance.h delete mode 100644 interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h delete mode 100644 interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h delete mode 100644 services/hdfaudioclient/BUILD.gn delete mode 100644 services/hdfaudioclient/include/audio_adapter.h delete mode 100644 services/hdfaudioclient/include/audio_attribute.h delete mode 100644 services/hdfaudioclient/include/audio_capture.h delete mode 100644 services/hdfaudioclient/include/audio_control.h delete mode 100644 services/hdfaudioclient/include/audio_manager.h delete mode 100644 services/hdfaudioclient/include/audio_render.h delete mode 100644 services/hdfaudioclient/include/audio_scene.h delete mode 100644 services/hdfaudioclient/include/audio_types.h delete mode 100644 services/hdfaudioclient/include/audio_volume.h delete mode 100644 services/hdfaudioclient/include/daudio_adapter_internal.h delete mode 100644 services/hdfaudioclient/include/daudio_attribute_internal.h delete mode 100644 services/hdfaudioclient/include/daudio_capture_internal.h delete mode 100644 services/hdfaudioclient/include/daudio_control_internal.h delete mode 100644 services/hdfaudioclient/include/daudio_param_callback_internal.h delete mode 100644 services/hdfaudioclient/include/daudio_render_callback_internal.h delete mode 100644 services/hdfaudioclient/include/daudio_render_internal.h delete mode 100644 services/hdfaudioclient/include/daudio_scene_internal.h delete mode 100644 services/hdfaudioclient/include/daudio_volume_internal.h delete mode 100644 services/hdfaudioclient/include/distributed_audio_client.h delete mode 100644 services/hdfaudioclient/src/daudio_adapter_internal.cpp delete mode 100644 services/hdfaudioclient/src/daudio_capture_internal.cpp delete mode 100644 services/hdfaudioclient/src/daudio_param_callback_internal.cpp delete mode 100644 services/hdfaudioclient/src/daudio_render_callback_internal.cpp delete mode 100644 services/hdfaudioclient/src/daudio_render_internal.cpp delete mode 100644 services/hdfaudioclient/src/distributed_audio_client.cpp delete mode 100644 services/hdfaudioclient/test/unittest/BUILD.gn delete mode 100644 services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.cpp delete mode 100644 services/hdfaudioclient/test/unittest/audio_adapter_internal/audio_adapter_internal_test.h delete mode 100644 services/hdfaudioclient/test/unittest/audio_capture_internal/audio_capture_internal_test.cpp delete mode 100644 services/hdfaudioclient/test/unittest/audio_manager_test.cpp delete mode 100644 services/hdfaudioclient/test/unittest/audio_render_internal/audio_render_internal_test.cpp diff --git a/audiohandler/include/ihardware_handler.h b/audiohandler/include/ihardware_handler.h deleted file mode 100644 index 5ff5c405..00000000 --- a/audiohandler/include/ihardware_handler.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_HARDWARE_IHARDWARE_HANDLER_H -#define OHOS_DISTRIBUTED_HARDWARE_IHARDWARE_HANDLER_H - -#include -#include -#include -#include - -namespace OHOS { -namespace DistributedHardware { -const std::string COMPONENT_LOADER_GET_HARDWARE_HANDLER = "GetHardwareHandler"; -struct DHItem { - std::string dhId; - std::string attrs; - std::string subtype; -}; - -class PluginListener { -public: - virtual void PluginHardware(const std::string &dhId, const std::string &attrs, const std::string &subtype) = 0; - virtual void UnPluginHardware(const std::string &dhId) = 0; -}; - -class IHardwareHandler { -public: - virtual int32_t Initialize() = 0; - virtual std::vector Query() = 0; - virtual std::map QueryExtraInfo() = 0; - virtual bool IsSupportPlugin() = 0; - virtual void RegisterPluginListener(std::shared_ptr listener) = 0; - virtual void UnRegisterPluginListener() = 0; -}; -extern "C" __attribute__((visibility("default"))) IHardwareHandler* GetHardwareHandler(); -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/bundle.json b/bundle.json index 942a75ba..c875ce9b 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 667e33db..b5e9bbeb 100644 --- a/common/dfx_utils/include/daudio_hidumper.h +++ b/common/dfx_utils/include/daudio_hidumper.h @@ -20,9 +20,14 @@ #include #include "sys/stat.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 { @@ -55,6 +60,8 @@ private: int32_t StopDumpData(std::string &result); private: + sptr audioManager_ = nullptr; + std::vector adapterdesc_; bool dumpAudioDataFlag_ = false; const std::string DEFAULT_SPK_DHID = "1"; const std::string DEFAULT_MIC_DHID = "134217729"; diff --git a/common/dfx_utils/src/daudio_hidumper.cpp b/common/dfx_utils/src/daudio_hidumper.cpp index 44376fb9..e5528fce 100644 --- a/common/dfx_utils/src/daudio_hidumper.cpp +++ b/common/dfx_utils/src/daudio_hidumper.cpp @@ -128,6 +128,24 @@ int32_t DaudioHidumper::GetSourceDevId(std::string &result) int32_t DaudioHidumper::GetSinkInfo(std::string &result) { DHLOGI("Get sink info dump."); + + audioManager_ = IAudioManager::Get("daudio_primary_service", false); + if (audioManager_ == nullptr) { + return ERR_DH_AUDIO_NULLPTR; + } + 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 < adapterdesc_.size(); index++) { + AudioAdapterDescriptor desc = adapterdesc_[index]; + result.append("sinkDevId: ").append(GetAnonyString(desc.adapterName)).append(" portId: "); + for (uint32_t i = 0; i < desc.ports.size(); i++) { + result.append(std::to_string(desc.ports[i].portId)).append(" "); + } + } + return DH_SUCCESS; } diff --git a/common/dfx_utils/test/unittest/BUILD.gn b/common/dfx_utils/test/unittest/BUILD.gn index 38013170..659fcaf0 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 c2b71724..00000000 --- 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 3b4c678b..332d3ead 100755 --- a/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_sink/BUILD.gn @@ -46,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_sink/include/idistributed_hardware_sink.h b/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h deleted file mode 100644 index db9dc6c6..00000000 --- a/interfaces/inner_kits/native_cpp/audio_sink/include/idistributed_hardware_sink.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SINK_H -#define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SINK_H - -#include - -namespace OHOS { -namespace DistributedHardware { -const std::string COMPONENT_LOADER_GET_SINK_HANDLER = "GetSinkHardwareHandler"; -enum class ResourceEventType : int32_t { - EVENT_TYPE_QUERY_RESOURCE = 0, - EVENT_TYPE_PULL_UP_PAGE = 1, - EVENT_TYPE_CLOSE_PAGE = 2 -}; - -class SubscribeCallback { -public: - virtual int32_t OnSubscribeCallback(const std::string &dhId, int32_t status, const std::string &data) = 0; -}; - -class PrivacyResourcesListener { -public: - virtual int32_t OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subType, - const std::string &networkId, bool &isSensitive, bool &isSameAccout) = 0; -}; - -class IDistributedHardwareSink { -public: - virtual int32_t InitSink(const std::string ¶ms) = 0; - virtual int32_t ReleaseSink() = 0; - virtual int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶ms) = 0; - virtual int32_t UnsubscribeLocalHardware(const std::string &dhId) = 0; - virtual int32_t RegisterPrivacyResources(std::shared_ptr listener) = 0; - virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; - virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; - virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; -}; -extern "C" __attribute__((visibility("default"))) IDistributedHardwareSink* GetSinkHardwareHandler(); -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn index 9fcf62d7..c90b556e 100755 --- a/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/audio_source/BUILD.gn @@ -46,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/audio_source/include/idistributed_hardware_source.h b/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h deleted file mode 100644 index 78e2ed4d..00000000 --- a/interfaces/inner_kits/native_cpp/audio_source/include/idistributed_hardware_source.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H -#define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H - -#include -#include - -namespace OHOS { -namespace DistributedHardware { -const std::string COMPONENT_LOADER_GET_SOURCE_HANDLER = "GetSourceHardwareHandler"; -class RegisterCallback { -public: - virtual int32_t OnRegisterResult(const std::string &uuid, const std::string &dhId, int32_t status, - const std::string &data) = 0; -}; - -class UnregisterCallback { -public: - virtual int32_t OnUnregisterResult(const std::string &uuid, const std::string &dhId, int32_t status, - const std::string &data) = 0; -}; - -struct EnableParam { - std::string sourceVersion; - std::string sourceAttrs; - std::string sinkVersion; - std::string sinkAttrs; - std::string subtype; -}; - -class IDistributedHardwareSource { -public: - virtual int32_t InitSource(const std::string ¶ms) = 0; - virtual int32_t ReleaseSource() = 0; - virtual int32_t RegisterDistributedHardware(const std::string &uuid, const std::string &dhId, - const EnableParam ¶m, std::shared_ptr callback) = 0; - virtual int32_t UnregisterDistributedHardware(const std::string &uuid, const std::string &dhId, - std::shared_ptr callback) = 0; - virtual int32_t ConfigDistributedHardware(const std::string &uuid, const std::string &dhId, const std::string &key, - const std::string &value) = 0; -}; -extern "C" __attribute__((visibility("default"))) IDistributedHardwareSource* GetSourceHardwareHandler(); -} // namespace DistributedHardware -} // namespace OHOS -#endif diff --git a/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/unittest/BUILD.gn index a6bc0c5b..c028a65b 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 842a8575..230ebf57 100755 --- a/services/audiomanager/servicesink/BUILD.gn +++ b/services/audiomanager/servicesink/BUILD.gn @@ -84,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 caf33f13..d4134445 100755 --- a/services/audiomanager/servicesource/BUILD.gn +++ b/services/audiomanager/servicesource/BUILD.gn @@ -52,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", ] @@ -79,7 +78,6 @@ 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", ] @@ -88,8 +86,10 @@ ohos_shared_library("distributed_audio_source") { "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 9df9fde0..0827fd6b 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 65270fd9..457d3d37 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 b5dd2fdf..edebbc4c 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 1601f4a8..ac9c7033 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 5804e350..0003d6dd 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 cb841a09..61ccfeb8 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 116278e4..21bf7659 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 24583124..6b76259d 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 4c051504..8f8294b2 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/common/BUILD.gn b/services/common/BUILD.gn index 3a02e57e..0a7ffdfd 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 a29eb55d..00000000 --- a/services/hdfaudioclient/BUILD.gn +++ /dev/null @@ -1,60 +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("../../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", - ] - - 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", - ] - - 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/audio_adapter.h b/services/hdfaudioclient/include/audio_adapter.h deleted file mode 100644 index 5872080a..00000000 --- a/services/hdfaudioclient/include/audio_adapter.h +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_adapter.h - * - * @brief Declares APIs for operations related to the audio adapter. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_ADAPTER_H -#define AUDIO_ADAPTER_H - -#include "audio_types.h" -#include "audio_render.h" -#include "audio_capture.h" - -/** - * @brief Provides audio adapter capabilities, including initializing ports, creating rendering and capturing tasks, - * and obtaining the port capability set. - * - * @see AudioRender - * @see AudioCapture - * @since 1.0 - * @version 1.0 - */ -struct AudioAdapter { - /** - * @brief Initializes all ports of an audio adapter. - * - * Call this function before calling other driver functions to check whether the initialization is complete. - * If the initialization is not complete, wait for a while (for example, 100 ms) and perform the check again - * until the port initialization is complete. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @return Returns 0 if the initialization is successful; returns a negative value otherwise. - */ - int32_t (*InitAllPorts)(struct AudioAdapter *adapter); - - /** - * @brief Creates an AudioRender object. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param desc Indicates the pointer to the descriptor of the audio adapter to start. - * @param attrs Indicates the pointer to the audio sampling attributes to open. - * @param render Indicates the double pointer to the AudioRender object. - * @return Returns 0 if the AudioRender object is created successfully; - * returns a negative value otherwise. - * @see GetPortCapability - * @see DestroyRender - */ - int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, - const struct AudioSampleAttributes *attrs, struct AudioRender **render); - - /** - * @brief Destroys an AudioRender object. - * - * @attention Do not destroy the object during audio rendering. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param render Indicates the pointer to the AudioRender object to operate. - * @return Returns 0 if the AudioRender object is destroyed; returns a negative value otherwise. - * @see CreateRender - */ - int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render); - - /** - * @brief Creates an AudioCapture object. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param desc Indicates the pointer to the descriptor of the audio adapter to start. - * @param attrs Indicates the pointer to the audio sampling attributes to open. - * @param capture Indicates the double pointer to the AudioCapture object. - * @return Returns 0 if the AudioCapture object is created successfully; - * returns a negative value otherwise. - * @see GetPortCapability - * @see DestroyCapture - */ - int32_t (*CreateCapture)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, - const struct AudioSampleAttributes *attrs, struct AudioCapture **capture); - - /** - * @brief Destroys an AudioCapture object. - * - * @attention Do not destroy the object during audio capturing. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param capture Indicates the pointer to the AudioCapture object to operate. - * @return Returns 0 if the AudioCapture object is destroyed; returns a negative value otherwise. - * @see CreateCapture - */ - int32_t (*DestroyCapture)(struct AudioAdapter *adapter, struct AudioCapture *capture); - - /** - * @brief Obtains the capability set of the port driver for the audio adapter. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param port Indicates the pointer to the port. - * @param capability Indicates the pointer to the capability set to obtain. - * @return Returns 0 if the capability set is successfully obtained; returns a negative value otherwise. - */ - int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, - struct AudioPortCapability *capability); - - /** - * @brief Sets the passthrough data transmission mode of the audio port driver. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param port Indicates the pointer to the port. - * @param mode Indicates the passthrough transmission mode to set. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetPassthroughMode - */ - int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, - enum AudioPortPassthroughMode mode); - - /** - * @brief Obtains the passthrough data transmission mode of the audio port driver. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param port Indicates the pointer to the port. - * @param mode Indicates the pointer to the passthrough transmission mode to obtain. - * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. - * @see SetPassthroughMode - */ - int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, - enum AudioPortPassthroughMode *mode); - - /** - * @brief Update audio route on several source and sink ports. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param route Indicates route information. - * @param routeHandle Indicates route handle. - * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. - * @see SetPassthroughMode - */ - int32_t (*UpdateAudioRoute)(struct AudioAdapter *adapter, const struct AudioRoute *route, int32_t *routeHandle); - - /** - * @brief Release an audio route. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param routeHandle Indicates route handle. - * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. - * @see SetPassthroughMode - */ - int32_t (*ReleaseAudioRoute)(struct AudioAdapter *adapter, int32_t routeHandle); - - /** - * @brief Sets the mute operation for the audio. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param mute Specifies whether to mute the audio. Value true means to mute the audio, - * and false means the opposite. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetMute - */ - int32_t (*SetMicMute)(struct AudioAdapter *adapter, bool mute); - - /** - * @brief Obtains the mute operation set for the audio. - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that - * the audio is muted, and false means the opposite. - * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. - * @see SetMute - */ - int32_t (*GetMicMute)(struct AudioAdapter *adapter, bool *mute); - - /** - * @brief Sets the audio volume for voice call. - * - * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, - * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). - * - * @param adapter Indicates the pointer to the audio adapter to operate. - * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetVolume - */ - int32_t (*SetVoiceVolume)(struct AudioAdapter *adapter, float volume); - - /** - * @brief Sets extra audio parameters. - * - * @param adapter Indicates the audio adapter. - * @param key Indicates what kind of parameter type will be set. - * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. - * @param value Indicates the value of the specified condition. - * - * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). - * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: - * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" - * EVENT_TYPE indicates sub volume event type: SetVolume = 1; SetMute = 4; - * VOLUME_GROUP_ID indicates which volume group will be set; - * AUDIO_VOLUME_TYPE indicates which volume type will be set; - * - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*SetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, - const char *condition, const char *value); - - /** - * @brief Get extra audio parameters. - * - * @param adapter Indicates the audio adapter. - * @param key Indicates what kind of parameter type will be get. - * @param condition Indicates the specific extend parameter condition of AudioExtParamKey. - * @param value Indicates the value of the specified condition. - * @param lenth Indicates the length of the value pointer. - * - * The format of condition is key=value. Separate multiple key-value pairs by semicolons (;). - * When key equals to AudioExtParamKey::AUDIO_EXT_PARAM_KEY_VOLUME, the format of condition must be like this: - * "EVENT_TYPE=xxx;VOLUME_GROUP_ID=xxx;AUDIO_VOLUME_TYPE=xxx;" - * EVENT_TYPE indicates sub volume event type: GetVolume = 1; GetMinVolume = 2; GetMaxVolume = 3; IsStreamMute = 4; - * VOLUME_GROUP_ID indicates which volume group want get; - * AUDIO_VOLUME_TYPE indicates which volume type want get; - * - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetExtraParams)(struct AudioAdapter *adapter, enum AudioExtParamKey key, - const char *condition, char *value, int32_t lenth); - - /** - * @brief Register extra audio parameters observer. - * - * @param adapter Indicates the audio adapter. - * @param callback Indicates param observer. - * @param cookie Indicates the pointer to the callback parameters; - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*RegExtraParamObserver)(struct AudioAdapter *adapter, ParamCallback callback, void* cookie); - /** - * @brief Get the device status of an adapter. - * - * @param adapter Indicates the audio adapter. - * @param status Indicates the status of device . - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetDeviceStatus)(struct AudioAdapter *adapter, struct AudioDeviceStatus *status); -}; -#endif /* AUDIO_ADAPTER_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_attribute.h b/services/hdfaudioclient/include/audio_attribute.h deleted file mode 100644 index b5beed14..00000000 --- a/services/hdfaudioclient/include/audio_attribute.h +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_attribute.h - * - * @brief Declares APIs for audio attributes. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_ATTRIBUTE_H -#define AUDIO_ATTRIBUTE_H - -#include "audio_types.h" - -/** - * @brief Provides attribute-related APIs for audio rendering or capturing, including functions to - * obtain frame information and set audio sampling attributes. - * - * @since 1.0 - * @version 1.0 - */ -struct AudioAttribute { - /** - * @brief Obtains the audio frame size, that is, the length (in bytes) of a frame. - * - * @param handle Indicates the audio handle. - * @param size Indicates the pointer to the audio frame size (in bytes). - * @return Returns 0 if the audio frame size is obtained; returns a negative value otherwise. - */ - int32_t (*GetFrameSize)(AudioHandle handle, uint64_t *size); - - /** - * @brief Obtains the number of audio frames in the audio buffer. - * - * @param handle Indicates the audio handle. - * @param count Indicates the pointer to the number of audio frames in the audio buffer. - * @return Returns 0 if the number of audio frames is obtained; returns a negative value otherwise. - */ - int32_t (*GetFrameCount)(AudioHandle handle, uint64_t *count); - - /** - * @brief Sets audio sampling attributes. - * - * @param handle Indicates the audio handle. - * @param attrs Indicates the pointer to the audio sampling attributes to set, such as the sampling rate, - * sampling precision, and channel. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetSampleAttributes - */ - int32_t (*SetSampleAttributes)(AudioHandle handle, const struct AudioSampleAttributes *attrs); - - /** - * @brief Obtains audio sampling attributes. - * - * @param handle Indicates the audio handle. - * @param attrs Indicates the pointer to the audio sampling attributes, such as the sampling rate, - * sampling precision, and channel. - * @return Returns 0 if audio sampling attributes are obtained; returns a negative value otherwise. - * @see SetSampleAttributes - */ - int32_t (*GetSampleAttributes)(AudioHandle handle, struct AudioSampleAttributes *attrs); - - /** - * @brief Obtains the data channel ID of the audio. - * - * @param handle Indicates the audio handle. - * @param channelId Indicates the pointer to the data channel ID. - * @return Returns 0 if the data channel ID is obtained; returns a negative value otherwise. - */ - int32_t (*GetCurrentChannelId)(AudioHandle handle, uint32_t *channelId); - - /** - * @brief Sets extra audio parameters. - * - * @param handle Indicates the audio handle. - * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. - * The format is key=value. Separate multiple key-value pairs by semicolons (;). - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*SetExtraParams)(AudioHandle handle, const char *keyValueList); - - /** - * @brief Obtains extra audio parameters. - * - * @param handle Indicates the audio handle. - * @param keyValueList Indicates the pointer to the key-value list of the extra audio parameters. - * The format is key=value. Separate multiple key-value pairs by semicolons (;). - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetExtraParams)(AudioHandle handle, char *keyValueList, int32_t listLenth); - - /** - * @brief Requests a mmap buffer. - * - * @param handle Indicates the audio handle. - * @param reqSize Indicates the size of the request mmap buffer. - * @param desc Indicates the pointer to the mmap buffer descriptor. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*ReqMmapBuffer)(AudioHandle handle, int32_t reqSize, struct AudioMmapBufferDescriptor *desc); - - /** - * @brief Obtains the read/write position of the current mmap buffer. - * - * @param handle Indicates the audio handle. - * @param frames Indicates the pointer to the frame where the read/write starts. - * @param time Indicates the pointer to the timestamp associated with the frame where the read/write starts. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetMmapPosition)(AudioHandle handle, uint64_t *frames, struct AudioTimeStamp *time); - - /** - * @brief Add the audio effect which the effectid indicated. - * - * @param handle Indicates the audio handle. - * @param effectid Indicates the audio effect instance identifier which is going to be added. - * @return Returns 0 if the audio effect were added succesffully; returns a negative value otherwise. - */ - int32_t (*AddAudioEffect)(AudioHandle handle, uint64_t effectid); - - /** - * @brief Remove the audio effect which the effectid indicated. - * - * @param handle Indicates the audio handle. - * @param effectid Indicates the audio effect which is going to be removed. - * @return Returns 0 if the audio effect were removed succesffully; returns a negative value otherwise. - */ - int32_t (*RemoveAudioEffect)(AudioHandle handle, uint64_t effectid); - - /** - * @brief Get the buffer size of render or capturer - * - * @param handle Indicates the audio handle. - * @param bufferSize Indicates the buffer size (in bytes) queried from the vendor - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*GetFrameBufferSize)(AudioHandle handle, uint64_t *bufferSize); -}; - -#endif /* AUDIO_ATTRIBUTE_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_capture.h b/services/hdfaudioclient/include/audio_capture.h deleted file mode 100644 index 52347aab..00000000 --- a/services/hdfaudioclient/include/audio_capture.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_capture.h - * - * @brief Declares APIs for audio capturing. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_CAPTURE_H -#define AUDIO_CAPTURE_H - -#include "audio_types.h" -#include "audio_control.h" -#include "audio_attribute.h" -#include "audio_scene.h" -#include "audio_volume.h" - -/** - * @brief Provides capabilities for audio capturing, including controlling the capturing, setting audio attributes, - * scenes, and volume, and capturing audio frames. - * - * @see AudioControl - * @see AudioAttribute - * @see AudioScene - * @see AudioVolume - * @since 1.0 - * @version 1.0 - */ -struct AudioCapture { - /** - * @brief Defines the audio control. For details, see {@link AudioControl}. - */ - struct AudioControl control; - /** - * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. - */ - struct AudioAttribute attr; - /** - * @brief Defines the audio scene. For details, see {@link AudioScene}. - */ - struct AudioScene scene; - /** - * @brief Defines audio volume. For details, see {@link AudioVolume}. - */ - struct AudioVolume volume; - - /** - * @brief Reads a frame of input data (uplink data) from the audio driver for capturing. - * - * @param capture Indicates the pointer to the AudioCapture object to operate. - * @param frame Indicates the pointer to the input data to read. - * @param requestBytes Indicates the size of the input data, in bytes. - * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to read. - * @return Returns 0 if the input data is read successfully; returns a negative value otherwise. - */ - int32_t (*CaptureFrame)(struct AudioCapture *capture, void *frame, uint64_t requestBytes, uint64_t *replyBytes); - - /** - * @brief Obtains the last number of input audio frames. - * - * @param capture Indicates the pointer to the AudioCapture object to operate. - * @param frames Indicates the pointer to the last number of input audio frames. - * @param time Indicates the pointer to the timestamp associated with the frame. - * @return Returns 0 if the last number is obtained; returns a negative value otherwise. - * @see CaptureFrame - */ - int32_t (*GetCapturePosition)(struct AudioCapture *capture, uint64_t *frames, struct AudioTimeStamp *time); -}; - -#endif /* AUDIO_CAPTURE_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_control.h b/services/hdfaudioclient/include/audio_control.h deleted file mode 100644 index a20f7875..00000000 --- a/services/hdfaudioclient/include/audio_control.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_control.h - * - * @brief Declares APIs for audio control. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_CONTROL_H -#define AUDIO_CONTROL_H - -#include "audio_types.h" - -/** - * @brief Provides control-related APIs for audio rendering or capturing, including functions to - * start, stop, pause, and resume audio rendering or capturing, and flush data in the audio buffer. - * - * @since 1.0 - * @version 1.0 - */ -struct AudioControl { - /** - * @brief Starts audio rendering or capturing. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the rendering or capturing is successfully started; - * returns a negative value otherwise. - * @see Stop - */ - int32_t (*Start)(AudioHandle handle); - - /** - * @brief Stops audio rendering or capturing. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the rendering or capturing is successfully stopped; - * returns a negative value otherwise. - * @see Start - */ - int32_t (*Stop)(AudioHandle handle); - - /** - * @brief Pauses audio rendering or capturing. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the rendering or capturing is successfully paused; - * returns a negative value otherwise. - * @see Resume - */ - int32_t (*Pause)(AudioHandle handle); - - /** - * @brief Resumes audio rendering or capturing. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the rendering or capturing is successfully resumed; - * returns a negative value otherwise. - * @see Pause - */ - int32_t (*Resume)(AudioHandle handle); - - /** - * @brief Flushes data in the audio buffer. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the flush is successful; returns a negative value otherwise. - */ - int32_t (*Flush)(AudioHandle handle); - - /** - * @brief Sets or cancels the standby mode of the audio device. - * - * @param handle Indicates the audio handle. - * @return Returns 0 if the device is set to standby mode; returns a positive value if the standby mode is - * canceled; returns a negative value if the setting fails. - */ - int32_t (*TurnStandbyMode)(AudioHandle handle); - - /** - * @brief Dumps information about the audio device. - * - * @param handle Indicates the audio handle. - * @param range Indicates the range of the device information to dump, which can be brief or full information. - * @param fd Indicates the file to which the device information will be dumped. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ - int32_t (*AudioDevDump)(AudioHandle handle, int32_t range, int32_t fd); - - /** - * @brief Query whether the vendor support pause and resume. - * - * @param handle Indicates the audio handle. - * @param supportPause Indicates the state whether the vendor supports pausing. Value true means that - * the vendor supports, and false means the opposite. - * @param supportResume Indicates the state whether the vendor supports resuming. Value true means that - * the vendor supports, and false means the opposite. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - * @see IsSupportsPauseAndResume - */ - int32_t (*IsSupportsPauseAndResume)(AudioHandle handle, bool *supportPause, bool *supportResume); -}; - -#endif /* AUDIO_CONTROL_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_manager.h b/services/hdfaudioclient/include/audio_manager.h deleted file mode 100644 index f952dc3c..00000000 --- a/services/hdfaudioclient/include/audio_manager.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_manager.h - * - * @brief Declares APIs for audio adapter management and loading. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_MANAGER_H -#define AUDIO_MANAGER_H - -#include "audio_types.h" -#include "audio_adapter.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Manages audio adapters through a specific adapter driver program loaded based on the given audio - * adapter descriptor. - * - * @see AudioAdapter - * @since 1.0 - * @version 1.0 - */ -struct AudioManager { - /** - * @brief Obtains the list of all adapters supported by an audio driver. - * - * @param manager Indicates the pointer to the audio adapter manager to operate. - * @param descs Indicates the double pointer to the audio adapter list. - * @param size Indicates the pointer to the length of the list. - * @return Returns 0 if the list is obtained successfully; returns a negative value otherwise. - * @see LoadAdapter - */ - int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size); - - /** - * @brief Loads the driver for an audio adapter. - * - * For example, to load a USB driver, you may need to load a dynamic-link library (*.so) in specific implementation. - * - * @param manager Indicates the pointer to the audio adapter manager to operate. - * @param desc Indicates the pointer to the descriptor of the audio adapter. - * @param adapter Indicates the double pointer to the audio adapter. - * @return Returns 0 if the driver is loaded successfully; returns a negative value otherwise. - * @see GetAllAdapters - * @see UnloadAdapter - */ - int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc, - struct AudioAdapter **adapter); - - /** - * @brief Unloads the driver of an audio adapter. - * - * @param manager Indicates the pointer to the audio adapter manager to operate. - * @param adapter Indicates the pointer to the audio adapter whose driver will be unloaded. - * @see LoadAdapter - */ - void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter); - - /** - * @brief Release the AudioManager Object. - * - * @param object Indicates the pointer to the audio adapter manager to operate. - * @return Returns true if the Object is released; returns false otherwise. - */ - bool (*ReleaseAudioManagerObject)(struct AudioManager *object); -}; - -/** - * @brief Obtains the operation function list of the {@link AudioManager} class. - * - * @return Returns the pointer to the AudioManager object if the list is obtained; returns NULL otherwise. - */ -struct AudioManager *GetAudioManagerFuncs(void); - -#ifdef __cplusplus -} -#endif - -#endif /* AUDIO_MANAGER_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_render.h b/services/hdfaudioclient/include/audio_render.h deleted file mode 100644 index 1627fe62..00000000 --- a/services/hdfaudioclient/include/audio_render.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_render.h - * - * @brief Declares APIs for audio rendering. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_RENDER_H -#define AUDIO_RENDER_H - -#include "audio_types.h" -#include "audio_control.h" -#include "audio_attribute.h" -#include "audio_scene.h" -#include "audio_volume.h" - -/** - * @brief Provides capabilities for audio rendering, including controlling the rendering, setting audio attributes, - * scenes, and volume, obtaining hardware latency, and rendering audio frames. - * - * @see AudioControl - * @see AudioAttribute - * @see AudioScene - * @see AudioVolume - * @since 1.0 - * @version 1.0 - */ -struct AudioRender { - /** - * @brief Defines the audio control. For details, see {@link AudioControl}. - */ - struct AudioControl control; - /** - * @brief Defines the audio attribute. For details, see {@link AudioAttribute}. - */ - struct AudioAttribute attr; - /** - * @brief Defines the audio scene. For details, see {@link AudioScene}. - */ - struct AudioScene scene; - /** - * @brief Defines audio volume. For details, see {@link AudioVolume}. - */ - struct AudioVolume volume; - - /** - * @brief Obtains the estimated latency of the audio device driver. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param ms Indicates the pointer to the latency (in milliseconds) to be obtained. - * @return Returns 0 if the latency is obtained; returns a negative value otherwise. - */ - int32_t (*GetLatency)(struct AudioRender *render, uint32_t *ms); - - /** - * @brief Writes a frame of output data (downlink data) into the audio driver for rendering. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param frame Indicates the pointer to the frame to write. - * @param requestBytes Indicates the size of the frame, in bytes. - * @param replyBytes Indicates the pointer to the actual length (in bytes) of the audio data to write. - * @return Returns 0 if the data is written successfully; returns a negative value otherwise. - */ - int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes); - - /** - * @brief Obtains the last number of output audio frames. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param frames Indicates the pointer to the last number of output audio frames. - * @param time Indicates the pointer to the timestamp associated with the frame. - * @return Returns 0 if the last number is obtained; returns a negative value otherwise. - * @see RenderFrame - */ - int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time); - - /** - * @brief Sets the audio rendering speed. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param speed Indicates the rendering speed to set. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetRenderSpeed - */ - int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed); - - /** - * @brief Obtains the current audio rendering speed. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param speed Indicates the pointer to the current rendering speed to obtain. - * @return Returns 0 if the speed is successfully obtained; returns a negative value otherwise. - * @see SetRenderSpeed - */ - int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed); - - /** - * @brief Sets the channel mode for audio rendering. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param mode Indicates the channel mode to set. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetChannelMode - */ - int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode); - - /** - * @brief Obtains the current channel mode for audio rendering. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param mode Indicates the pointer to the channel mode to obtain. - * @return Returns 0 if the mode is successfully obtained; returns a negative value otherwise. - * @see SetChannelMode - */ - int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode); - - /** - * @brief Registers an audio callback that will be invoked during playback when buffer data writing or - * buffer drain is complete. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param callback Indicates the callback to register. - * @param cookie Indicates the pointer to the callback parameters. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - * @see RegCallback - */ - int32_t (*RegCallback)(struct AudioRender *render, RenderCallback callback, void* cookie); - - /** - * @brief Drains the buffer. - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param type Indicates the pointer to the execution type of this function. For details, - * see {@link AudioDrainNotifyType}. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - * @see RegCallback - */ - int32_t (*DrainBuffer)(struct AudioRender *render, enum AudioDrainNotifyType *type); - - /** - * @brief query whether the vendor supports draining buffer - * - * @param render Indicates the pointer to the AudioRender object to operate. - * @param support indicates the state whether the vendor supports draining buffer. Value true means that - * the vendor supports, and false means the opposite. - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - * @see IsSupportsDrain - */ - int32_t (*IsSupportsDrain)(struct AudioRender *render, bool *support); -}; - -#endif /* AUDIO_RENDER_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_scene.h b/services/hdfaudioclient/include/audio_scene.h deleted file mode 100644 index e6ef9f90..00000000 --- a/services/hdfaudioclient/include/audio_scene.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_scene.h - * - * @brief Declares APIs for audio scenes. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_SCENE_H -#define AUDIO_SCENE_H - -#include "audio_types.h" - -/** - * @brief Provides scene-related APIs for audio rendering or capturing, including functions to - * select an audio scene and check whether the configuration of an audio scene is supported. - * - * @since 1.0 - * @version 1.0 - */ -struct AudioScene { - /** - * @brief Checks whether the configuration of an audio scene is supported. - * - * @param handle Indicates the audio handle. - * @param scene Indicates the pointer to the descriptor of the audio scene. - * @param supported Indicates the pointer to the variable specifying whether the configuration is supported. - * Value true means that the configuration is supported, and false means the opposite. - * @return Returns 0 if the result is obtained; returns a negative value otherwise. - * @see SelectScene - */ - int32_t (*CheckSceneCapability)(AudioHandle handle, const struct AudioSceneDescriptor *scene, bool *supported); - - /** - * @brief Selects an audio scene. - * - *
    - *
  • To select a specific audio scene, you need to specify both the application scenario and output device. - * For example, to select a scene using a smartphone speaker as the output device, set scene according - * to the scenarios where the speaker is used. For example:
  • - *
      - *
    • For media playback, set the value to media_speaker.
    • - *
    • For a voice call, set the value to voice_speaker.
    • - *
    - *
  • To select only the application scenario, such as media playback, movie, or gaming, you can set - * scene to media, movie, or game, respectively.
  • - *
  • To select only the output device, such as media receiver, speaker, or headset, you can set - * scene to receiver, speaker, or headset, respectively.
  • - *
- * @param handle Indicates the audio handle. - * @param scene Indicates the pointer to the descriptor of the audio scene to select. - * @return Returns 0 if the scene is selected successfully; returns a negative value otherwise. - * @see CheckSceneCapability - */ - int32_t (*SelectScene)(AudioHandle handle, const struct AudioSceneDescriptor *scene); -}; - -#endif /* AUDIO_SCENE_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/audio_types.h b/services/hdfaudioclient/include/audio_types.h deleted file mode 100644 index 76662f99..00000000 --- a/services/hdfaudioclient/include/audio_types.h +++ /dev/null @@ -1,487 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_types.h - * - * @brief Defines custom data types used in API declarations for the audio module, including audio ports, - * adapter descriptors, device descriptors, scene descriptors, sampling attributes, and timestamp. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_TYPES_H -#define AUDIO_TYPES_H - -#include -#include - -/** - * @brief Defines the audio handle. - */ -typedef void *AudioHandle; - -/** - * @brief Enumerates the audio port type. - */ -enum AudioPortDirection { - PORT_OUT = 0x1u, /**< Output port */ - PORT_IN = 0x2u, /**< Input port */ - PORT_OUT_IN = 0x3u, /**< Input/output port, supporting both audio input and output */ -}; - -/** - * @brief Defines the audio port. - */ -struct AudioPort { - enum AudioPortDirection dir; /**< Audio port type. For details, see {@link AudioPortDirection} */ - uint32_t portId; /**< Audio port ID */ - const char *portName; /**< Audio port name */ -}; - -/** - * @brief Defines the audio adapter descriptor. - * - * An audio adapter is a set of port drivers for a sound card, including the output and input ports. - * One port corresponds to multiple pins, and each pin belongs to a physical component (such as a - * speaker or a wired headset). - */ -struct AudioAdapterDescriptor { - const char *adapterName; /**< Name of the audio adapter */ - uint32_t portNum; /**< Number of ports supported by an audio adapter */ - struct AudioPort *ports; /**< List of ports supported by an audio adapter */ -}; - -/** - * @brief Enumerates the pin of an audio adapter. - */ -enum AudioPortPin { - PIN_NONE = 0x0u, /**< Invalid pin */ - PIN_OUT_SPEAKER = 0x1u, /**< Speaker output pin */ - PIN_OUT_HEADSET = 0x2u, /**< Wired headset pin for output */ - PIN_OUT_LINEOUT = 0x4u, /**< Line-out pin */ - PIN_OUT_HDMI = 0x8u, /**< HDMI output pin */ - PIN_OUT_USB = 0x10u, /**< USB output pin */ - PIN_OUT_USB_EXT = 0x20u, /**< Extended USB output pin*/ - PIN_OUT_EARPIECE = 0x30u, /**< Earpiece output pin */ - PIN_OUT_BLUETOOTH_SCO = 0x40u, /**< Bluetooth SCO output pin */ - PIN_OUT_DAUDIO_DEFAULT = 0x80u, - PIN_OUT_HEADPHONE = 0x100u, /**< Wired headphone output pin*/ - PIN_OUT_USB_HEADSET = 0x200u, /**< ARM USB out pin */ - PIN_IN_MIC = 0x8000001u, /**< Microphone input pin */ - PIN_IN_HS_MIC = 0x8000002u, /**< Wired headset microphone pin for input */ - PIN_IN_LINEIN = 0x8000004u, /**< Line-in pin */ - PIN_IN_USB_EXT = 0x8000008u, /**< Extended USB input pin*/ - PIN_IN_BLUETOOTH_SCO_HEADSET = 0x8000010u, /**< Bluetooth SCO headset input pin */ - PIN_IN_USB_HEADSET = 0x8000040u, /**< ARM USB input pin */ -}; - -/** - * @brief Defines the audio device descriptor. - */ -struct AudioDeviceDescriptor { - uint32_t portId; /**< Audio port ID */ - enum AudioPortPin pins; /**< Pins of audio ports (input and output). For details, see {@link AudioPortPin}. */ - const char *desc; /**< Audio device name */ -}; - -/** - * @brief Enumerates the audio category. - */ -enum AudioCategory { - AUDIO_IN_MEDIA = 0, /**< Media */ - AUDIO_IN_COMMUNICATION, /**< Communications */ - AUDIO_IN_RINGTONE, /**< Ringtone */ - AUDIO_IN_CALL, /**< Call */ - AUDIO_MMAP_NOIRQ, /**< Mmap mode */ -}; - -/** - * @brief Defines the audio scene descriptor. - */ -struct AudioSceneDescriptor { - /** - * @brief Describes the audio scene. - */ - union SceneDesc { - uint32_t id; /**< Audio scene ID */ - const char *desc; /**< Name of the audio scene */ - } scene; /**< The scene object */ - struct AudioDeviceDescriptor desc; /**< Audio device descriptor */ -}; - -/** - * @brief Enumerates the audio format. - */ -enum AudioFormat { - AUDIO_FORMAT_TYPE_PCM_8_BIT = 0x1u, /**< 8-bit PCM */ - AUDIO_FORMAT_TYPE_PCM_16_BIT = 0x2u, /**< 16-bit PCM */ - AUDIO_FORMAT_TYPE_PCM_24_BIT = 0x3u, /**< 24-bit PCM */ - AUDIO_FORMAT_TYPE_PCM_32_BIT = 0x4u, /**< 32-bit PCM */ - AUDIO_FORMAT_TYPE_AAC_MAIN = 0x1000001u, /**< AAC main */ - AUDIO_FORMAT_TYPE_AAC_LC = 0x1000002u, /**< AAC LC */ - AUDIO_FORMAT_TYPE_AAC_LD = 0x1000003u, /**< AAC LD */ - AUDIO_FORMAT_TYPE_AAC_ELD = 0x1000004u, /**< AAC ELD */ - AUDIO_FORMAT_TYPE_AAC_HE_V1 = 0x1000005u, /**< AAC HE_V1 */ - AUDIO_FORMAT_TYPE_AAC_HE_V2 = 0x1000006u, /**< AAC HE_V2 */ - AUDIO_FORMAT_TYPE_G711A = 0x2000001u, /**< G711A */ - AUDIO_FORMAT_TYPE_G711U = 0x2000002u, /**< G711u */ - AUDIO_FORMAT_TYPE_G726 = 0x2000003u, /**< G726 */ -}; - -/** - * @brief Enumerates the audio channel mask. - * - * A mask describes an audio channel position. - */ -enum AudioChannelMask { - AUDIO_CHANNEL_MONO = 1u, /**< Mono channel */ - AUDIO_CHANNEL_FRONT_LEFT = 1u, /**< Front left channel */ - AUDIO_CHANNEL_FRONT_RIGHT = 2u, /**< Front right channel */ - AUDIO_CHANNEL_FRONT_CENTER = 4u, /**< Front right channel */ - AUDIO_CHANNEL_LOW_FREQUENCY = 8u, /**< 0x8 */ - AUDIO_CHANNEL_BACK_LEFT = 16u, /**< 0x10 */ - AUDIO_CHANNEL_BACK_RIGHT = 32u, /**< 0x20 */ - AUDIO_CHANNEL_BACK_CENTER = 256u, /**< 0x100 */ - AUDIO_CHANNEL_SIDE_LEFT = 512u, /**< 0x200 */ - AUDIO_CHANNEL_SIDE_RIGHT = 1024u, /**< 0x400 */ - AUDIO_CHANNEL_TOP_SIDE_LEFT = 262144u, /**< 0x40000 */ - AUDIO_CHANNEL_TOP_SIDE_RIGHT = 524288u, /**< 0x80000 */ - AUDIO_CHANNEL_STEREO = 3u, /**< FRONT_LEFT | FRONT_RIGHT */ - AUDIO_CHANNEL_2POINT1 = 11u, /**< STEREO | LOW_FREQUENCY */ - AUDIO_CHANNEL_QUAD = 51u, /**< STEREO | BACK_LEFT | BACK_RIGHT */ - AUDIO_CHANNEL_3POINT0POINT2 = 786439u, /**< STEREO | FRONT_CENTER | TOP_SIDE_LEFT | TOP_SIDE_RIGHT */ - AUDIO_CHANNEL_5POINT1 = 63u, /**< QUAD | FRONT_CENTER | LOW_FREQUENCY */ - AUDIO_CHANNEL_6POINT1 = 319u, /**< AUDIO_CHANNEL_5POINT1 | BACK_CENTER */ - AUDIO_CHANNEL_7POINT1 = 1599u, /**< AUDIO_CHANNEL_5POINT1 | SIDE_LEFT | SIDE_RIGHT */ -}; - -/** - * @brief Enumerates masks of audio sampling rates. - */ -enum AudioSampleRatesMask { - AUDIO_SAMPLE_RATE_MASK_8000 = 0x1u, /**< 8 kHz */ - AUDIO_SAMPLE_RATE_MASK_12000 = 0x2u, /**< 12 kHz */ - AUDIO_SAMPLE_RATE_MASK_11025 = 0x4u, /**< 11.025 kHz */ - AUDIO_SAMPLE_RATE_MASK_16000 = 0x8u, /**< 16 kHz */ - AUDIO_SAMPLE_RATE_MASK_22050 = 0x10u, /**< 22.050 kHz */ - AUDIO_SAMPLE_RATE_MASK_24000 = 0x20u, /**< 24 kHz */ - AUDIO_SAMPLE_RATE_MASK_32000 = 0x40u, /**< 32 kHz */ - AUDIO_SAMPLE_RATE_MASK_44100 = 0x80u, /**< 44.1 kHz */ - AUDIO_SAMPLE_RATE_MASK_48000 = 0x100u, /**< 48 kHz */ - AUDIO_SAMPLE_RATE_MASK_64000 = 0x200u, /**< 64 kHz */ - AUDIO_SAMPLE_RATE_MASK_96000 = 0x400u, /**< 96 kHz */ - AUDIO_SAMPLE_RATE_MASK_INVALID = 0xFFFFFFFFu, /**< Invalid sampling rate */ -}; -enum AudioInputType { - AUDIO_INPUT_DEFAULT_TYPE = 0, - AUDIO_INPUT_MIC_TYPE = 1 << 0, - AUDIO_INPUT_SPEECH_WAKEUP_TYPE = 1 << 1, - AUDIO_INPUT_VOICE_COMMUNICATION_TYPE = 1 << 2, - AUDIO_INPUT_VOICE_RECOGNITION_TYPE = 1 << 3, -}; -/** - * @brief Defines audio sampling attributes. - */ -struct AudioSampleAttributes { - enum AudioCategory type; /**< Audio type. For details, see {@link AudioCategory} */ - bool interleaved; /**< Interleaving flag of audio data */ - enum AudioFormat format; /**< Audio data format. For details, see {@link AudioFormat}. */ - uint32_t sampleRate; /**< Audio sampling rate */ - uint32_t channelCount; /**< Number of audio channels. For example, for the mono channel, the value is 1, - * and for the stereo channel, the value is 2. - */ - uint32_t period; /**< Audio sampling period */ - uint32_t frameSize; /**< Frame size of the audio data */ - bool isBigEndian; /**< Big endian flag of audio data */ - bool isSignedData; /**< Signed or unsigned flag of audio data */ - uint32_t startThreshold; /**< Audio render start threshold. */ - uint32_t stopThreshold; /**< Audio render stop threshold. */ - uint32_t silenceThreshold; /**< Audio capture buffer threshold. */ - int32_t streamId; /**< Audio Identifier of render or capture */ - int32_t sourceType; -}; - -/** - * @brief Defines the audio timestamp, which is a substitute for POSIX timespec. - */ -struct AudioTimeStamp { - int64_t tvSec; /**< Seconds */ - int64_t tvNSec; /**< Nanoseconds */ -}; - -/** - * @brief Enumerates the passthrough data transmission mode of an audio port. - */ -enum AudioPortPassthroughMode { - PORT_PASSTHROUGH_LPCM = 0x1, /**< Stereo PCM */ - PORT_PASSTHROUGH_RAW = 0x2, /**< HDMI passthrough */ - PORT_PASSTHROUGH_HBR2LBR = 0x4, /**< Blu-ray next-generation audio output with reduced specifications */ - PORT_PASSTHROUGH_AUTO = 0x8, /**< Mode automatically matched based on the HDMI EDID */ -}; - -/** - * @brief Defines the sub-port capability. - */ -struct AudioSubPortCapability { - uint32_t portId; /**< Sub-port ID */ - const char *desc; /**< Sub-port name */ - enum AudioPortPassthroughMode mask; /**< Passthrough mode of data transmission. For details, - * see {@link AudioPortPassthroughMode}. - */ -}; - -/** - * @brief Defines formats of raw audio samples. - */ -enum AudioSampleFormat { - /* 8 bits */ - AUDIO_SAMPLE_FORMAT_S8, /**< signed 8 bit sample */ - AUDIO_SAMPLE_FORMAT_S8P, /**< signed 8 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U8, /**< unsigned 8 bit sample */ - AUDIO_SAMPLE_FORMAT_U8P, /**< unsigned 8 bit planar sample */ - /* 16 bits */ - AUDIO_SAMPLE_FORMAT_S16, /**< signed 16 bit sample */ - AUDIO_SAMPLE_FORMAT_S16P, /**< signed 16 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U16, /**< unsigned 16 bit sample */ - AUDIO_SAMPLE_FORMAT_U16P, /**< unsigned 16 bit planar sample */ - /* 24 bits */ - AUDIO_SAMPLE_FORMAT_S24, /**< signed 24 bit sample */ - AUDIO_SAMPLE_FORMAT_S24P, /**< signed 24 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U24, /**< unsigned 24 bit sample */ - AUDIO_SAMPLE_FORMAT_U24P, /**< unsigned 24 bit planar sample */ - /* 32 bits */ - AUDIO_SAMPLE_FORMAT_S32, /**< signed 32 bit sample */ - AUDIO_SAMPLE_FORMAT_S32P, /**< signed 32 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U32, /**< unsigned 32 bit sample */ - AUDIO_SAMPLE_FORMAT_U32P, /**< unsigned 32 bit planar sample */ - /* 64 bits */ - AUDIO_SAMPLE_FORMAT_S64, /**< signed 64 bit sample */ - AUDIO_SAMPLE_FORMAT_S64P, /**< signed 64 bit planar sample */ - AUDIO_SAMPLE_FORMAT_U64, /**< unsigned 64 bit sample */ - AUDIO_SAMPLE_FORMAT_U64P, /**< unsigned 64 bit planar sample */ - /* float double */ - AUDIO_SAMPLE_FORMAT_F32, /**< float 32 bit sample */ - AUDIO_SAMPLE_FORMAT_F32P, /**< float 32 bit planar sample */ - AUDIO_SAMPLE_FORMAT_F64, /**< double 64 bit sample */ - AUDIO_SAMPLE_FORMAT_F64P, /**< double 64 bit planar sample */ -}; - -/** - * @brief Defines the audio port capability. - */ -struct AudioPortCapability { - uint32_t deviceType; /**< Device type (output or input) */ - uint32_t deviceId; /**< Device ID used for device binding */ - bool hardwareMode; /**< Whether to support device binding */ - uint32_t formatNum; /**< Number of the supported audio formats */ - enum AudioFormat *formats; /**< Supported audio formats. For details, see {@link AudioFormat}. */ - uint32_t sampleRateMasks; /**< Supported audio sampling rates (8 kHz, 16 kHz, 32 kHz, and 48 kHz) */ - enum AudioChannelMask channelMasks; /**< Audio channel layout mask of the device. For details, - * see {@link AudioChannelMask}. - */ - uint32_t channelCount; /**< Supported maximum number of audio channels */ - uint32_t subPortsNum; /**< Number of supported sub-ports (for output devices only) */ - struct AudioSubPortCapability *subPorts; /**< List of supported sub-ports */ - uint32_t supportSampleFormatNum; /**< Number of the supported audio sample format enum. */ - enum AudioSampleFormat *supportSampleFormats; /**< Supported audio sample formats. For details, - * see {@link AudioSampleFormat}. - */ -}; - -/** - * @brief Enumerates channel modes for audio rendering. - * - * @attention The following modes are set for rendering dual-channel audios. Others are not supported. - */ -enum AudioChannelMode { - AUDIO_CHANNEL_NORMAL = 0, /**< Normal mode. No processing is required. */ - AUDIO_CHANNEL_BOTH_LEFT, /**< Two left channels */ - AUDIO_CHANNEL_BOTH_RIGHT, /**< Two right channels */ - AUDIO_CHANNEL_EXCHANGE, /**< Data exchange between the left and right channels. The left channel takes the audio - * stream of the right channel, and the right channel takes that of the left channel. - */ - AUDIO_CHANNEL_MIX, /**< Mix of streams of the left and right channels */ - AUDIO_CHANNEL_LEFT_MUTE, /**< Left channel muted. The stream of the right channel is output. */ - AUDIO_CHANNEL_RIGHT_MUTE, /**< Right channel muted. The stream of the left channel is output. */ - AUDIO_CHANNEL_BOTH_MUTE, /**< Both left and right channels muted */ -}; - -/** - * @brief Enumerates the execution types of the DrainBuffer function. - */ -enum AudioDrainNotifyType { - AUDIO_DRAIN_NORMAL_MODE, /**< The DrainBuffer function returns after all data finishes playback. */ - AUDIO_DRAIN_EARLY_MODE, /**< The DrainBuffer function returns before all the data of the current track - * finishes playback to reserve time for a smooth track switch by the audio service. - */ -}; - -/** - * @brief Enumerates callback notification events. - */ -enum AudioCallbackType { - AUDIO_NONBLOCK_WRITE_COMPLETED, /**< The non-block write is complete. */ - AUDIO_DRAIN_COMPLETED, /**< The draining is complete. */ - AUDIO_FLUSH_COMPLETED, /**< The flush is complete. */ - AUDIO_RENDER_FULL, /**< The render buffer is full.*/ - AUDIO_ERROR_OCCUR, /**< An error occurs.*/ -}; - -/** - * @brief Describes a mmap buffer. - */ -struct AudioMmapBufferDescriptor { - void *memoryAddress; /**< Pointer to the mmap buffer */ - int32_t memoryFd; /**< File descriptor of the mmap buffer */ - int32_t totalBufferFrames; /**< Total size of the mmap buffer (unit: frame )*/ - int32_t transferFrameSize; /**< Transfer size (unit: frame) */ - int32_t isShareable; /**< Whether the mmap buffer can be shared among processes */ - uint32_t offset; -}; - -/** - * @brief Describes AudioPortRole. - */ -enum AudioPortRole { - AUDIO_PORT_UNASSIGNED_ROLE = 0, /**< Unassigned port role */ - AUDIO_PORT_SOURCE_ROLE = 1, /**< Assigned source role */ - AUDIO_PORT_SINK_ROLE = 2, /**< Assigned sink role */ -}; - -/** - * @brief Describes AudioPortType. - */ -enum AudioPortType { - AUDIO_PORT_UNASSIGNED_TYPE = 0, /**< Unassigned port type */ - AUDIO_PORT_DEVICE_TYPE = 1, /**< Assigned device type */ - AUDIO_PORT_MIX_TYPE = 2, /**< Assigned mix type */ - AUDIO_PORT_SESSION_TYPE = 3, /**< Assigned session type */ -}; - -/** - * @brief Describes AudioDevExtInfo. - */ -struct AudioDevExtInfo { - int32_t moduleId; /**< Identifier of the module stream is attached to */ - enum AudioPortPin type; /**< Device type For details, see {@link AudioPortPin}. */ - const char *desc; /**< Address */ -}; - -/** - * @brief Describes AudioMixInfo. - */ -struct AudioMixExtInfo { - int32_t moduleId; /**< Identifier of the module stream is attached to */ - int32_t streamId; /**< Identifier of the capture or render passed by caller */ -}; - -/** - * @brief Describes AudioSessionType. - */ -enum AudioSessionType { - AUDIO_OUTPUT_STAGE_SESSION = 0, - AUDIO_OUTPUT_MIX_SESSION, - AUDIO_ALLOCATE_SESSION, - AUDIO_INVALID_SESSION, -}; - -/** - * @brief Describes AudioSessionExtInfo. - */ -struct AudioSessionExtInfo { - enum AudioSessionType sessionType; -}; - -/** - * @brief Describes AudioRouteNode. - */ -struct AudioRouteNode { - int32_t portId; /**< Audio port ID */ - enum AudioPortRole role; /**< Audio port as a sink or a source */ - enum AudioPortType type; /**< device, mix ... */ - union { - struct AudioDevExtInfo device; /* Specific Device Ext info */ - struct AudioMixExtInfo mix; /* Specific mix info */ - struct AudioSessionExtInfo session; /* session specific info */ - } ext; -}; - -/** - * @brief Describes AudioRoute. - */ -struct AudioRoute { - uint32_t sourcesNum; - const struct AudioRouteNode *sources; - uint32_t sinksNum; - const struct AudioRouteNode *sinks; -}; - -/** - * @brief Enumerates the restricted key type of the parameters - */ -enum AudioExtParamKey { - AUDIO_EXT_PARAM_KEY_NONE = 0, /**< Distributed audio extra param key none */ - AUDIO_EXT_PARAM_KEY_VOLUME = 1, /**< Distributed audio extra param key volume event */ - AUDIO_EXT_PARAM_KEY_FOCUS = 2, /**< Distributed audio extra param key focus event */ - AUDIO_EXT_PARAM_KEY_BUTTON = 3, /**< Distributed audio extra param key media button event */ - AUDIO_EXT_PARAM_KEY_EFFECT = 4, /**< Distributed audio extra param key audio effect event */ - AUDIO_EXT_PARAM_KEY_STATUS = 5, /**< Distributed audio extra param key device status event */ - AUDIO_EXT_PARAM_KEY_USB_DEVICE = 101, /**< Check USB device type ARM or HIFI */ - AUDIO_EXT_PARAM_KEY_LOWPOWER = 1000, /**< Low power event type */ -}; -/** - * @brief Describes status of audio deivce.@link enum AudioDeviceType - */ -struct AudioDeviceStatus { - uint32_t pnpStatus; -}; -/** - * @brief Called when an event defined in {@link AudioCallbackType} occurs. - * - * @param AudioCallbackType Indicates the occurred event that triggers this callback. - * @param reserved Indicates the pointer to a reserved field. - * @param cookie Indicates the pointer to the cookie for data transmission. - * @return Returns 0 if the callback is successfully executed; returns a negative value otherwise. - * @see RegCallback - */ -typedef int32_t (*RenderCallback)(enum AudioCallbackType, void *reserved, void *cookie); - -/** - * @brief Register audio extra param callback that will be invoked during audio param event. - * - * @param key Indicates param change event. - * @param condition Indicates the param condition. - * @param value Indicates the param value. - * @param reserved Indicates reserved param. - * @param cookie Indicates the pointer to the callback parameters; - * @return Returns 0 if the operation is successful; returns a negative value otherwise. - */ -typedef int32_t (*ParamCallback)(enum AudioExtParamKey key, const char *condition, const char *value, void *reserved, - void *cookie); - -#endif /* AUDIO_TYPES_H */ diff --git a/services/hdfaudioclient/include/audio_volume.h b/services/hdfaudioclient/include/audio_volume.h deleted file mode 100644 index ad476f7c..00000000 --- a/services/hdfaudioclient/include/audio_volume.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2020-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @addtogroup Audio - * @{ - * - * @brief Defines audio-related APIs, including custom data types and functions for loading drivers, - * accessing a driver adapter, and rendering and capturing audios. - * - * @since 1.0 - * @version 1.0 - */ - -/** - * @file audio_volume.h - * - * @brief Declares APIs for audio volume. - * - * @since 1.0 - * @version 1.0 - */ - -#ifndef AUDIO_VOLUME_H -#define AUDIO_VOLUME_H - -#include "audio_types.h" - -/** - * @brief Provides volume-related APIs for audio rendering or capturing, including functions to - * set the mute operation, volume, and gain. - * - * @since 1.0 - * @version 1.0 - */ -struct AudioVolume { - /** - * @brief Sets the mute operation for the audio. - * - * @param handle Indicates the audio handle. - * @param mute Specifies whether to mute the audio. Value true means to mute the audio, - * and false means the opposite. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetMute - */ - int32_t (*SetMute)(AudioHandle handle, bool mute); - - /** - * @brief Obtains the mute operation set for the audio. - * - * @param handle Indicates the audio handle. - * @param mute Indicates the pointer to the mute operation set for the audio. Value true means that - * the audio is muted, and false means the opposite. - * @return Returns 0 if the mute operation is obtained; returns a negative value otherwise. - * @see SetMute - */ - int32_t (*GetMute)(AudioHandle handle, bool *mute); - - /** - * @brief Sets the audio volume. - * - * The volume ranges from 0.0 to 1.0. If the volume level in an audio service ranges from 0 to 15, - * 0.0 indicates that the audio is muted, and 1.0 indicates the maximum volume level (15). - * - * @param handle Indicates the audio handle. - * @param volume Indicates the volume to set. The value ranges from 0.0 to 1.0. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetVolume - */ - int32_t (*SetVolume)(AudioHandle handle, float volume); - - /** - * @brief Obtains the audio volume. - * - * @param handle Indicates the audio handle. - * @param volume Indicates the pointer to the volume to obtain. The value ranges from 0.0 to 1.0. - * @return Returns 0 if the volume is obtained; returns a negative value otherwise. - * @see SetVolume - */ - int32_t (*GetVolume)(AudioHandle handle, float *volume); - - /** - * @brief Obtains the range of the audio gain. - * - * The audio gain can be expressed in one of the following two ways (depending on the chip platform), - * corresponding to two types of value ranges: - *
    - *
  • Actual audio gain values, for example, ranging from -50 to 6 dB
  • - *
  • Float numbers ranging from 0.0 to 1.0, where 0.0 means to mute the audio, - * and 1.0 means the maximum gain value, for example, 6 dB
  • - *
- * @param handle Indicates the audio handle. - * @param min Indicates the pointer to the minimum value of the range. - * @param max Indicates the pointer to the maximum value of the range. - * @return Returns 0 if the range is obtained; returns a negative value otherwise. - * @see GetGain - * @see SetGain - */ - int32_t (*GetGainThreshold)(AudioHandle handle, float *min, float *max); - - /** - * @brief Obtains the audio gain. - * - * @param handle Indicates the audio handle. - * @param gain Indicates the pointer to the audio gain. - * @return Returns 0 if the audio gain is obtained; returns a negative value otherwise. - * @see GetGainThreshold - * @see SetGain - */ - int32_t (*GetGain)(AudioHandle handle, float *gain); - - /** - * @brief Sets the audio gain. - * - * @param handle Indicates the audio handle. - * @param gain Indicates the audio gain to set. - * @return Returns 0 if the setting is successful; returns a negative value otherwise. - * @see GetGainThreshold - * @see GetGain - */ - int32_t (*SetGain)(AudioHandle handle, float gain); -}; - -#endif /* AUDIO_VOLUME_H */ -/** @} */ diff --git a/services/hdfaudioclient/include/daudio_adapter_internal.h b/services/hdfaudioclient/include/daudio_adapter_internal.h deleted file mode 100644 index 78d0ebdf..00000000 --- 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 17532a38..00000000 --- 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 16a0e51c..00000000 --- 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 eab91c9d..00000000 --- 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 a5134370..00000000 --- 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 a9ca7407..00000000 --- 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 b6889f19..00000000 --- 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 f4f08746..00000000 --- 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 b48f4a42..00000000 --- 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/include/distributed_audio_client.h b/services/hdfaudioclient/include/distributed_audio_client.h deleted file mode 100644 index 1cef0798..00000000 --- a/services/hdfaudioclient/include/distributed_audio_client.h +++ /dev/null @@ -1,49 +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_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" - -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_; -}; -} // DistributedHardware -} // OHOS -#endif // HDI_DISTRIBUTED_AUDIO_CLIENT_H diff --git a/services/hdfaudioclient/src/daudio_adapter_internal.cpp b/services/hdfaudioclient/src/daudio_adapter_internal.cpp deleted file mode 100644 index b6128c28..00000000 --- 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 8091c438..00000000 --- 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 18cea822..00000000 --- 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 9facc92b..00000000 --- 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 f1839a0b..00000000 --- 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 e4df6a37..00000000 --- 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 056518e5..00000000 --- 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 2455a5ac..00000000 --- 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 e083a165..00000000 --- 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 636ebbc2..00000000 --- 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 4ce51c2f..00000000 --- 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 1377ee4a..00000000 --- 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 6238bddd..840cdcd0 100644 --- a/services/test_example/BUILD.gn +++ b/services/test_example/BUILD.gn @@ -23,15 +23,16 @@ ohos_executable("audio_distributed_test") { include_dirs = [ "./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/test_example/distributedaudiotest.cpp b/services/test_example/distributedaudiotest.cpp index 93ce79df..da67787e 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 a4ec143f..7ca9c44f 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 { -- Gitee