From 0106de2092eb8a663835f4653d77fdf5e39f9b6d Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 26 Oct 2023 08:29:56 +0000 Subject: [PATCH 1/3] update Signed-off-by: hellohyh001 Change-Id: If0d6105fb96f17c700ef99120e7bdfb0c2d9bbb5 --- .../common/include/i_miscdevice_service.h | 1 + .../common/include/miscdevice_service_proxy.h | 1 + .../include/sensors_ipc_interface_code.h | 1 + .../common/src/miscdevice_service_proxy.cpp | 26 +++++++ .../include/vibrator_service_client.h | 27 ++++++++ .../vibrator/src/vibrator_service_client.cpp | 68 +++++++++++++++++++ frameworks/native/vibrator/vibrator_agent.cpp | 22 ++++++ .../inner_api/vibrator/vibrator_agent.h | 26 +++++++ .../inner_api/vibrator/vibrator_agent_type.h | 60 ++++++++++++++++ 9 files changed, 232 insertions(+) diff --git a/frameworks/native/common/include/i_miscdevice_service.h b/frameworks/native/common/include/i_miscdevice_service.h index 0e15a84..1727735 100644 --- a/frameworks/native/common/include/i_miscdevice_service.h +++ b/frameworks/native/common/include/i_miscdevice_service.h @@ -47,6 +47,7 @@ public: virtual std::vector GetLightList() = 0; virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) = 0; virtual int32_t TurnOff(int32_t lightId) = 0; + virtual int32_t GetDelayTime(int32_t &delayTime); }; } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/common/include/miscdevice_service_proxy.h b/frameworks/native/common/include/miscdevice_service_proxy.h index 7d029e9..d909e18 100644 --- a/frameworks/native/common/include/miscdevice_service_proxy.h +++ b/frameworks/native/common/include/miscdevice_service_proxy.h @@ -39,6 +39,7 @@ public: virtual std::vector GetLightList() override; virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) override; virtual int32_t TurnOff(int32_t lightId) override; + virtual int32_t GetDelayTime(int32_t &delayTime); private: DISALLOW_COPY_AND_MOVE(MiscdeviceServiceProxy); diff --git a/frameworks/native/common/include/sensors_ipc_interface_code.h b/frameworks/native/common/include/sensors_ipc_interface_code.h index 4bb2d16..cac75c3 100644 --- a/frameworks/native/common/include/sensors_ipc_interface_code.h +++ b/frameworks/native/common/include/sensors_ipc_interface_code.h @@ -31,6 +31,7 @@ enum class MiscdeviceInterfaceCode { GET_LIGHT_LIST, TURN_ON, TURN_OFF, + GET_DELAY_TIME, }; } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/common/src/miscdevice_service_proxy.cpp b/frameworks/native/common/src/miscdevice_service_proxy.cpp index cd0a8a9..7e9a934 100644 --- a/frameworks/native/common/src/miscdevice_service_proxy.cpp +++ b/frameworks/native/common/src/miscdevice_service_proxy.cpp @@ -325,5 +325,31 @@ int32_t MiscdeviceServiceProxy::TurnOff(int32_t lightId) } return ret; } + + +int32_t MiscdeviceServiceProxy::GetDelayTime(int32_t &delayTime) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(MiscdeviceServiceProxy::GetDescriptor())) { + MISC_HILOGE("Write descriptor failed"); + return WRITE_MSG_ERR; + } + sptr remote = Remote(); + CHKPR(remote, ERROR); + MessageParcel reply; + MessageOption option; + int32_t ret = remote->SendRequest(static_cast(MiscdeviceInterfaceCode::GET_DELAY_TIME), + data, reply, option); + if (ret != NO_ERROR) { + HiSysEventWrite(HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_IPC_EXCEPTION", + HiSysEvent::EventType::FAULT, "PKG_NAME", "GetDelayTime", "ERROR_CODE", ret); + MISC_HILOGE("SendRequest failed, ret:%{public}d", ret); + } + if (!reply.ReadInt32(delayTime)) { + MISC_HILOGE("Parcel read failed"); + return ERROR; + } + return ret; +} } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/vibrator/include/vibrator_service_client.h b/frameworks/native/vibrator/include/vibrator_service_client.h index 687eb7b..14e3a51 100644 --- a/frameworks/native/vibrator/include/vibrator_service_client.h +++ b/frameworks/native/vibrator/include/vibrator_service_client.h @@ -25,6 +25,27 @@ namespace OHOS { namespace Sensors { + +struct VibratorDecodeHandle { + void *handle; + IVibratorDecoder *decoder; + IVibratorDecoder *(*create)(); + void (*destroy)(IVibratorDecoder *); + + VibratorDecodeHandle(): handle(nullptr), decoder(nullptr), + create(nullptr), destroy(nullptr) {} + Free() + { + if (handle != nullptr) { + dlclose(handle); + handle = nullptr; + } + decoder = nullptr; + create = nullptr; + destroy = nullptr; + } +}; + class VibratorServiceClient : public Singleton { public: ~VibratorServiceClient() override; @@ -37,12 +58,18 @@ public: int32_t StopVibrator(int32_t vibratorId); int32_t IsSupportEffect(const std::string &effect, bool &state); void ProcessDeathObserver(const wptr &object); + int32_t DecodeVibratorFile(const VibratorFileDescription &fileDescription, + VibratorPackage &package); + int32_t GetDelayTime(int32_t &delayTime); private: int32_t InitServiceClient(); + std::optional LoadDecoderLibrary(const std::string& path); sptr serviceDeathObserver_ = nullptr; sptr miscdeviceProxy_ = nullptr; std::mutex clientMutex_; + VibratorDecodeHandle decodeHandle_; + std::mutex decodeMutex_; }; } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/vibrator/src/vibrator_service_client.cpp b/frameworks/native/vibrator/src/vibrator_service_client.cpp index ea091b5..79669c5 100644 --- a/frameworks/native/vibrator/src/vibrator_service_client.cpp +++ b/frameworks/native/vibrator/src/vibrator_service_client.cpp @@ -33,6 +33,12 @@ namespace { constexpr HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "VibratorServiceClient" }; constexpr int32_t GET_SERVICE_MAX_COUNT = 30; constexpr uint32_t WAIT_MS = 200; +constexpr int32_t PATH_MAX_LENGTH = 64; +#ifdef __aarch64__ + static const std::string DECODER_LIBRARY_PATH = "/system/lib64/libxxx.z.so"; +#else + static const std::string DECODER_LIBRARY_PATH = "/system/lib/libxxx.z.so"; +#endif } // namespace VibratorServiceClient::~VibratorServiceClient() @@ -43,6 +49,8 @@ VibratorServiceClient::~VibratorServiceClient() remoteObject->RemoveDeathRecipient(serviceDeathObserver_); } } + std::lock_guard decodeLock(decodeMutex_); + decodeHandle_.Free(); } int32_t VibratorServiceClient::InitServiceClient() @@ -204,5 +212,65 @@ void VibratorServiceClient::ProcessDeathObserver(const wptr &obje return; } } + +int32_t VibratorServiceClient::LoadDecoderLibrary(const std::string& path) +{ + std::lock_guard decodeLock(decodeMutex_); + if (decodeHandle_.handle != nullptr) { + MISC_HILOGD("The library has already been loaded"); + return 0; + } + char libRealPath[PATH_MAX_LENGTH] = {} + if (realPath(path.c_str(), libRealPath) == nullptr) { + MISC_HILOGD("Get file real path fail"); + return -1; + } + decodeHandle_.handle = dlopen(libRealPath, RTLD_LAZY); + if (decodeHandle_.handle == nullptr) { + MISC_HILOGE("dlopen failed, reason:%{public}s", dlerror()); + return -1; + } + decodeHandle_.create = static_cast(dlsym(decodeHandle_.handle, "Create")); + if (decodeHandle_.create == nullptr) { + MISC_HILOGE("dlsym create failed: error: %{public}s", dlerror()); + decodeHandle_.Free(); + return -1; + } + decodeHandle_.destroy = static_cast(dlsym(decodeHandle_.handle, "Destroy")); + if (decodeHandle_.destroy == nullptr) { + MISC_HILOGE("dlsym destroy failed: error: %{public}s", dlerror()); + decodeHandle_.Free(); + return -1; + } + decodeHandle_.decoder = decodeHandle_.create(); + return 0; +} + +int32_t VibratorServiceClient::DecodeVibratorFile(const VibratorFileDescription &fileDescription, VibratorPackage &package) +{ + if (LoadDecoderLibrary(DECODER_LIBRARY_PATH) != 0 || decodeHandle_.decoder == nullptr) { + MISC_HILOGD("LoadDecoderLibrary fail"); + return -1; + } + return decoder->Parse(fileDescription, package); +} + +int32_t VibratorServiceClient::GetDelayTime(int32_t &delayTime) +{ + MISC_HILOGD("GetDelayTime begin, vibratorId:%{public}d", vibratorId); + int32_t ret = InitServiceClient(); + if (ret != ERR_OK) { + MISC_HILOGE("InitServiceClient failed, ret:%{public}d", ret); + return MISC_NATIVE_GET_SERVICE_ERR; + } + CHKPR(miscdeviceProxy_, ERROR); + StartTrace(HITRACE_TAG_SENSORS, "GetDelayTime"); + ret = miscdeviceProxy_->GetDelayTime(delayTime); + FinishTrace(HITRACE_TAG_SENSORS); + if (ret != ERR_OK) { + MISC_HILOGE("GetDelayTime failed, ret:%{public}d", ret); + } + return ret; +} } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/vibrator/vibrator_agent.cpp b/frameworks/native/vibrator/vibrator_agent.cpp index 054b78f..431551c 100644 --- a/frameworks/native/vibrator/vibrator_agent.cpp +++ b/frameworks/native/vibrator/vibrator_agent.cpp @@ -174,5 +174,27 @@ int32_t IsSupportEffect(const char *effectId, bool *state) } return SUCCESS; } + +int32_t DecodeVibratorFile(const VibratorFileDescription &fileDescription, VibratorPackage &package) +{ + auto &client = VibratorServiceClient::GetInstance(); + int32_t ret = client.DecodeVibratorFile(fileDescription, package); + if (ret != ERR_OK) { + MISC_HILOGE("DecodeVibratorFile failed, ret:%{public}d", ret); + return NormalizeErrCode(ret); + } + return SUCCESS; +} + +int32_t GetDelayTime(int32_t &delayTime) +{ + auto &client = VibratorServiceClient::GetInstance(); + int32_t ret = client.GetDelayTime(delayTime); + if (ret != ERR_OK) { + MISC_HILOGE("GetDelayTime failed, ret:%{public}d", ret); + return NormalizeErrCode(ret); + } + return SUCCESS; +} } // namespace Sensors } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/vibrator/vibrator_agent.h b/interfaces/inner_api/vibrator/vibrator_agent.h index 6f79ebd..0803a00 100644 --- a/interfaces/inner_api/vibrator/vibrator_agent.h +++ b/interfaces/inner_api/vibrator/vibrator_agent.h @@ -144,6 +144,32 @@ bool SetUsage(int32_t usage); * @since 10 */ int32_t IsSupportEffect(const char *effectId, bool *state); + +/** + * @brief 获取振动时延,从下发振动到启动振动的时间间隔,可用于音振协调场景。 + * @param delayTime:出参,返回振动时间延迟,从下发振动到启动振动的时间间隔,单位:毫秒. + * @return 返回0表示成功,否则表示失败。 + * @since 11 + */ +int32_t GetDelayTime(int32_t &delayTime); + +/** + * @brief 解码振动媒体文件,生成振动波形。 + * @param fileDescription: 振动效果描述文件,支持he、json文件格式,如{@link VibrationFileDescription}。 + * @param package: 出参,生成的振动序列包,如 {@link VibrationPackage}。 + * @return 返回0表示成功,否则表示失败。 + * @since 11 + */ +int32_t DecodeVibratorFile(const VibratorFileDescription &fileDescription, VibratorPackage &package); + +/** + * @brief 播放振动序列。 + * @param channelId: 播放振动的通道ID。 + * @param pattern: 振动序列,如{@link VibratorPattern}。 + * @return 返回0表示成功,否则表示失败。 + * @since 11 + */ +int32_t PlayPattern(int32_t channelId, const VibratorPattern &pattern); } // namespace Sensors } // namespace OHOS #ifdef __cplusplus diff --git a/interfaces/inner_api/vibrator/vibrator_agent_type.h b/interfaces/inner_api/vibrator/vibrator_agent_type.h index 8db23c2..c8c36d8 100644 --- a/interfaces/inner_api/vibrator/vibrator_agent_type.h +++ b/interfaces/inner_api/vibrator/vibrator_agent_type.h @@ -94,6 +94,66 @@ typedef enum VibratorUsage { USAGE_MAX = 9 } VibratorUsage; +/** + * @brief 振动事件类型,分为连续振动和瞬态 + * + * @since 11 + */ +typedef enum VibratorEventType { + EVENT_TYPE_UNKNOWN = -1, /**< 未知振动类型 */ + EVENT_TYPE_CONTINUOUS = 0, /**< 连续振动类型 */ + EVENT_TYPE_TRANSIENT = 1, /**< 瞬态振动类型 */ +} VibratorEventType; + +/** + * @brief 振动效果描述文件 + * + * @since 11 + */ +typedef struct VibratorFileDescription { + int32_t fd = -1; + int64_t offset = -1; + int64_t length = -1; +} VibratorFileDescription; + +/** + * @brief 描述振动波形结构。振动媒体文件可以解析为该类型。 + * + * @since 11 + */ +typedef struct VibratorPackage { + int32_t patternNum = 0; // pattern + VibratorPattern *patterns = nullptr; // 振动媒体文件包含一个或者多个VibratorPattern +} VibratorPackage; + +/** + * @brief 描述振动波形 + * + * @since 11 + */ +typedef struct VibratorPattern { + int32_t time = -1; + int32_t eventNum = 0; + VibratorEvent *events = nullptr; // 最多包含16个event +} VibratorPattern; + +typedef struct VibratorEvent { + VibratorEventType type = EVENT_TYPE_UNKNOWN; + int32_t time = -1; + int32_t duration = -1; + int32_t intensity = -1; + int32_t frequency = -1; + int32_t index = 0; // 0:both 1:left 2:right + int32_t pointNum = 0; + VibratorCurvePoint *points = nullptr; +} VibratorPattern; + +typedef struct VibratorCurvePoint { + int64_t time = -1; + int32_t intensity = -1; + int32_t frequency = -1; +} VibratorCurvePoint; + /** @} */ #ifdef __cplusplus }; -- Gitee From 75904d43e4fabd83dca602ad0415e93612ab7203 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Thu, 26 Oct 2023 12:58:21 +0000 Subject: [PATCH 2/3] update Signed-off-by: hellohyh001 Change-Id: I51394aec67c7c79f30ecb4338afa2de63923404e --- .../common/include/miscdevice_service_proxy.h | 2 +- frameworks/native/vibrator/BUILD.gn | 1 + .../include/vibrator_service_client.h | 10 +-- .../vibrator/src/vibrator_service_client.cpp | 16 ++--- frameworks/native/vibrator/vibrator_agent.cpp | 4 +- .../inner_api/vibrator/vibrator_agent.h | 2 +- .../inner_api/vibrator/vibrator_agent_type.h | 63 +++++++++---------- 7 files changed, 51 insertions(+), 47 deletions(-) diff --git a/frameworks/native/common/include/miscdevice_service_proxy.h b/frameworks/native/common/include/miscdevice_service_proxy.h index d909e18..c5aaf93 100644 --- a/frameworks/native/common/include/miscdevice_service_proxy.h +++ b/frameworks/native/common/include/miscdevice_service_proxy.h @@ -39,7 +39,7 @@ public: virtual std::vector GetLightList() override; virtual int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimationIPC &animation) override; virtual int32_t TurnOff(int32_t lightId) override; - virtual int32_t GetDelayTime(int32_t &delayTime); + virtual int32_t GetDelayTime(int32_t &delayTime) override; private: DISALLOW_COPY_AND_MOVE(MiscdeviceServiceProxy); diff --git a/frameworks/native/vibrator/BUILD.gn b/frameworks/native/vibrator/BUILD.gn index 298bf9a..300dd57 100644 --- a/frameworks/native/vibrator/BUILD.gn +++ b/frameworks/native/vibrator/BUILD.gn @@ -74,6 +74,7 @@ ohos_shared_library("libvibrator_native") { ] include_dirs = [ + "$SUBSYSTEM_DIR/interfaces/inner_api/vibrator", "include", "$SUBSYSTEM_DIR/frameworks/native/common/include", "$SUBSYSTEM_DIR/interfaces/inner_api/light", diff --git a/frameworks/native/vibrator/include/vibrator_service_client.h b/frameworks/native/vibrator/include/vibrator_service_client.h index 14e3a51..8f17592 100644 --- a/frameworks/native/vibrator/include/vibrator_service_client.h +++ b/frameworks/native/vibrator/include/vibrator_service_client.h @@ -16,12 +16,14 @@ #ifndef VIBRATOR_SERVICE_CLIENT_H #define VIBRATOR_SERVICE_CLIENT_H +#include #include #include "iremote_object.h" #include "singleton.h" #include "miscdevice_service_proxy.h" +#include "vibrator_agent_type.h" namespace OHOS { namespace Sensors { @@ -34,7 +36,8 @@ struct VibratorDecodeHandle { VibratorDecodeHandle(): handle(nullptr), decoder(nullptr), create(nullptr), destroy(nullptr) {} - Free() + + void Free() { if (handle != nullptr) { dlclose(handle); @@ -58,13 +61,12 @@ public: int32_t StopVibrator(int32_t vibratorId); int32_t IsSupportEffect(const std::string &effect, bool &state); void ProcessDeathObserver(const wptr &object); - int32_t DecodeVibratorFile(const VibratorFileDescription &fileDescription, - VibratorPackage &package); + int32_t PreProcess(const VibratorFileDescription &fd, VibratorPackage &package); int32_t GetDelayTime(int32_t &delayTime); private: int32_t InitServiceClient(); - std::optional LoadDecoderLibrary(const std::string& path); + int32_t LoadDecoderLibrary(const std::string& path); sptr serviceDeathObserver_ = nullptr; sptr miscdeviceProxy_ = nullptr; std::mutex clientMutex_; diff --git a/frameworks/native/vibrator/src/vibrator_service_client.cpp b/frameworks/native/vibrator/src/vibrator_service_client.cpp index 79669c5..81dfe18 100644 --- a/frameworks/native/vibrator/src/vibrator_service_client.cpp +++ b/frameworks/native/vibrator/src/vibrator_service_client.cpp @@ -220,8 +220,8 @@ int32_t VibratorServiceClient::LoadDecoderLibrary(const std::string& path) MISC_HILOGD("The library has already been loaded"); return 0; } - char libRealPath[PATH_MAX_LENGTH] = {} - if (realPath(path.c_str(), libRealPath) == nullptr) { + char libRealPath[PATH_MAX_LENGTH] = {}; + if (realpath(path.c_str(), libRealPath) == nullptr) { MISC_HILOGD("Get file real path fail"); return -1; } @@ -230,13 +230,15 @@ int32_t VibratorServiceClient::LoadDecoderLibrary(const std::string& path) MISC_HILOGE("dlopen failed, reason:%{public}s", dlerror()); return -1; } - decodeHandle_.create = static_cast(dlsym(decodeHandle_.handle, "Create")); + decodeHandle_.create = static_cast( + dlsym(decodeHandle_.handle, "Create")); if (decodeHandle_.create == nullptr) { MISC_HILOGE("dlsym create failed: error: %{public}s", dlerror()); decodeHandle_.Free(); return -1; } - decodeHandle_.destroy = static_cast(dlsym(decodeHandle_.handle, "Destroy")); + decodeHandle_.destroy = static_cast( + dlsym(decodeHandle_.handle,"Destroy")); if (decodeHandle_.destroy == nullptr) { MISC_HILOGE("dlsym destroy failed: error: %{public}s", dlerror()); decodeHandle_.Free(); @@ -246,18 +248,18 @@ int32_t VibratorServiceClient::LoadDecoderLibrary(const std::string& path) return 0; } -int32_t VibratorServiceClient::DecodeVibratorFile(const VibratorFileDescription &fileDescription, VibratorPackage &package) +int32_t VibratorServiceClient::PreProcess( + const VibratorFileDescription &fd, VibratorPackage &package) { if (LoadDecoderLibrary(DECODER_LIBRARY_PATH) != 0 || decodeHandle_.decoder == nullptr) { MISC_HILOGD("LoadDecoderLibrary fail"); return -1; } - return decoder->Parse(fileDescription, package); + return decodeHandle_.decoder->Parse(fd, package); } int32_t VibratorServiceClient::GetDelayTime(int32_t &delayTime) { - MISC_HILOGD("GetDelayTime begin, vibratorId:%{public}d", vibratorId); int32_t ret = InitServiceClient(); if (ret != ERR_OK) { MISC_HILOGE("InitServiceClient failed, ret:%{public}d", ret); diff --git a/frameworks/native/vibrator/vibrator_agent.cpp b/frameworks/native/vibrator/vibrator_agent.cpp index 431551c..120b307 100644 --- a/frameworks/native/vibrator/vibrator_agent.cpp +++ b/frameworks/native/vibrator/vibrator_agent.cpp @@ -175,10 +175,10 @@ int32_t IsSupportEffect(const char *effectId, bool *state) return SUCCESS; } -int32_t DecodeVibratorFile(const VibratorFileDescription &fileDescription, VibratorPackage &package) +int32_t PreProcess(const VibratorFileDescription &fd, VibratorPackage &package) { auto &client = VibratorServiceClient::GetInstance(); - int32_t ret = client.DecodeVibratorFile(fileDescription, package); + int32_t ret = client.PreProcess(fd, package); if (ret != ERR_OK) { MISC_HILOGE("DecodeVibratorFile failed, ret:%{public}d", ret); return NormalizeErrCode(ret); diff --git a/interfaces/inner_api/vibrator/vibrator_agent.h b/interfaces/inner_api/vibrator/vibrator_agent.h index 0803a00..acb2d80 100644 --- a/interfaces/inner_api/vibrator/vibrator_agent.h +++ b/interfaces/inner_api/vibrator/vibrator_agent.h @@ -160,7 +160,7 @@ int32_t GetDelayTime(int32_t &delayTime); * @return 返回0表示成功,否则表示失败。 * @since 11 */ -int32_t DecodeVibratorFile(const VibratorFileDescription &fileDescription, VibratorPackage &package); +int32_t PreProcess(const VibratorFileDescription &fd, VibratorPackage &package); /** * @brief 播放振动序列。 diff --git a/interfaces/inner_api/vibrator/vibrator_agent_type.h b/interfaces/inner_api/vibrator/vibrator_agent_type.h index c8c36d8..a247e8c 100644 --- a/interfaces/inner_api/vibrator/vibrator_agent_type.h +++ b/interfaces/inner_api/vibrator/vibrator_agent_type.h @@ -94,17 +94,6 @@ typedef enum VibratorUsage { USAGE_MAX = 9 } VibratorUsage; -/** - * @brief 振动事件类型,分为连续振动和瞬态 - * - * @since 11 - */ -typedef enum VibratorEventType { - EVENT_TYPE_UNKNOWN = -1, /**< 未知振动类型 */ - EVENT_TYPE_CONTINUOUS = 0, /**< 连续振动类型 */ - EVENT_TYPE_TRANSIENT = 1, /**< 瞬态振动类型 */ -} VibratorEventType; - /** * @brief 振动效果描述文件 * @@ -117,25 +106,21 @@ typedef struct VibratorFileDescription { } VibratorFileDescription; /** - * @brief 描述振动波形结构。振动媒体文件可以解析为该类型。 + * @brief 振动事件类型,分为连续振动和瞬态 * * @since 11 */ -typedef struct VibratorPackage { - int32_t patternNum = 0; // pattern - VibratorPattern *patterns = nullptr; // 振动媒体文件包含一个或者多个VibratorPattern -} VibratorPackage; +typedef enum VibratorEventType { + EVENT_TYPE_UNKNOWN = -1, /**< 未知振动类型 */ + EVENT_TYPE_CONTINUOUS = 0, /**< 连续振动类型 */ + EVENT_TYPE_TRANSIENT = 1, /**< 瞬态振动类型 */ +} VibratorEventType; -/** - * @brief 描述振动波形 - * - * @since 11 - */ -typedef struct VibratorPattern { - int32_t time = -1; - int32_t eventNum = 0; - VibratorEvent *events = nullptr; // 最多包含16个event -} VibratorPattern; +typedef struct VibratorCurvePoint { + int64_t time = -1; + int32_t intensity = -1; + int32_t frequency = -1; +} VibratorCurvePoint; typedef struct VibratorEvent { VibratorEventType type = EVENT_TYPE_UNKNOWN; @@ -146,14 +131,28 @@ typedef struct VibratorEvent { int32_t index = 0; // 0:both 1:left 2:right int32_t pointNum = 0; VibratorCurvePoint *points = nullptr; -} VibratorPattern; +} VibratorEvent; -typedef struct VibratorCurvePoint { - int64_t time = -1; - int32_t intensity = -1; - int32_t frequency = -1; -} VibratorCurvePoint; +/** + * @brief 描述振动波形 + * + * @since 11 + */ +typedef struct VibratorPattern { + int32_t time = -1; + int32_t eventNum = 0; + VibratorEvent *events = nullptr; // 最多包含16个event +} VibratorPattern; +/** + * @brief 描述振动波形结构。振动媒体文件可以解析为该类型。 + * + * @since 11 + */ +typedef struct VibratorPackage { + int32_t patternNum = 0; // pattern + VibratorPattern *patterns = nullptr; // 振动媒体文件包含一个或者多个VibratorPattern +} VibratorPackage; /** @} */ #ifdef __cplusplus }; -- Gitee From ff3d05ff645ad65d727a77ae14b574f22ccde463 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Fri, 3 Nov 2023 06:57:27 +0000 Subject: [PATCH 3/3] update Signed-off-by: hellohyh001 --- interfaces/inner_api/vibrator/vibrator_agent.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/interfaces/inner_api/vibrator/vibrator_agent.h b/interfaces/inner_api/vibrator/vibrator_agent.h index acb2d80..85f8857 100644 --- a/interfaces/inner_api/vibrator/vibrator_agent.h +++ b/interfaces/inner_api/vibrator/vibrator_agent.h @@ -162,6 +162,14 @@ int32_t GetDelayTime(int32_t &delayTime); */ int32_t PreProcess(const VibratorFileDescription &fd, VibratorPackage &package); +/** + * @brief 释放振动序列包内存。 + * @param package: 生成的振动序列包,如 {@link VibrationPackage}。 + * @return 返回0表示成功,否则表示失败。 + * @since 11 + */ +int32_t FreeVibratorPackage(VibratorPackage &package); + /** * @brief 播放振动序列。 * @param channelId: 播放振动的通道ID。 @@ -169,7 +177,7 @@ int32_t PreProcess(const VibratorFileDescription &fd, VibratorPackage &package); * @return 返回0表示成功,否则表示失败。 * @since 11 */ -int32_t PlayPattern(int32_t channelId, const VibratorPattern &pattern); +int32_t PlayPattern(const VibratorPattern &pattern); } // namespace Sensors } // namespace OHOS #ifdef __cplusplus -- Gitee