mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-21 05:45:23 -04:00
Description:low latency
Match-id-d71f0036ecf2ee584e4100319a50844ee715d81b
This commit is contained in:
@@ -32,6 +32,9 @@ namespace DistributedInput {
|
||||
constexpr int32_t ERR_DH_INPUT_HUB_GET_EVENT_FAIL = -60006;
|
||||
constexpr int32_t ERR_DH_INPUT_HUB_DEVICE_ENABLE_FAIL = -60007;
|
||||
constexpr int32_t ERR_DH_INPUT_HUB_IS_VIRTUAL_DEVICE = -60008;
|
||||
constexpr int32_t ERR_DH_INPUT_DLOPEN_FAIL = -60009;
|
||||
constexpr int32_t ERR_DH_INPUT_DLSYM_FAIL = -60010;
|
||||
constexpr int32_t ERR_DH_INPUT_LOW_LATENCY_LIB_NULL = -60011;
|
||||
// whilte list error code
|
||||
constexpr int32_t ERR_DH_INPUT_WHILTELIST_INIT_FAIL = -61001;
|
||||
constexpr int32_t ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL = -61002;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_low_latency_utils.h"
|
||||
#include "hisysevent_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -45,6 +46,7 @@ void SetSinkProcessExit()
|
||||
}
|
||||
DHLOGI("exit sa process success.");
|
||||
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_EXIT, "dinput sink sa exit success.");
|
||||
DInputLowLatencyUtils::GetInstance().DisableSinkLowLatency();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -59,6 +61,7 @@ void SetSourceProcessExit()
|
||||
}
|
||||
DHLOGI("exit sa process success.");
|
||||
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_EXIT, "dinput source sa exit success.");
|
||||
DInputLowLatencyUtils::GetInstance().DisableSourceLowLatency();
|
||||
exit(0);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -28,6 +28,7 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/transport",
|
||||
"${service_common}/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -48,6 +49,7 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_low_latency_utils.h"
|
||||
#include "hidumper.h"
|
||||
#include "session.h"
|
||||
#include "softbus_bus_center.h"
|
||||
@@ -255,6 +256,8 @@ int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
DInputLowLatencyUtils::GetInstance().EnableSinkLowLatency();
|
||||
|
||||
// return 1 is client
|
||||
int32_t sessionSide = GetSessionSide(sessionId);
|
||||
DHLOGI("session open succeed, sessionId %s, sessionSide %d", GetAnonyInt32(sessionId).c_str(), sessionSide);
|
||||
@@ -287,6 +290,8 @@ void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId)
|
||||
{
|
||||
DHLOGI("OnSessionClosed, sessionId:%s", GetAnonyInt32(sessionId).c_str());
|
||||
|
||||
DInputLowLatencyUtils::GetInstance().DisableSinkLowLatency();
|
||||
|
||||
char peerDevId[DEVICE_ID_SIZE_MAX] = "";
|
||||
int ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId));
|
||||
if (ret != DH_SUCCESS) {
|
||||
|
||||
@@ -39,6 +39,7 @@ ohos_unittest("distributed_input_sinktrans_test") {
|
||||
"//third_party/json/include",
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/transport/test/sinktransunittest/mock",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -67,6 +68,7 @@ ohos_unittest("distributed_input_sinktrans_test") {
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -47,6 +47,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"${services_source_path}/transport/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -106,6 +107,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -31,6 +31,7 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"${services_source_path}/inputinject/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -51,6 +52,7 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_hitrace.h"
|
||||
#include "dinput_low_latency_utils.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "distributed_input_inject.h"
|
||||
#include "hidumper.h"
|
||||
@@ -184,6 +185,7 @@ int32_t DistributedInputSourceTransport::OpenInputSoftbus(const std::string &rem
|
||||
|
||||
DHLOGI("OpenSession success, remoteDevId:%s, sessionId:%s",
|
||||
GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str());
|
||||
DInputLowLatencyUtils::GetInstance().EnableSourceLowLatency();
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId, SessionStatus::OPENED);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
@@ -205,6 +207,7 @@ void DistributedInputSourceTransport::CloseInputSoftbus(const std::string &remot
|
||||
sessionDevMap_.erase(remoteDevId);
|
||||
channelStatusMap_.erase(remoteDevId);
|
||||
DistributedInputInject::GetInstance().StopInjectThread();
|
||||
DInputLowLatencyUtils::GetInstance().DisableSourceLowLatency();
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId, SessionStatus::CLOSED);
|
||||
HiDumper::GetInstance().DeleteSessionInfo(remoteDevId);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ ohos_unittest("distributed_input_sourcetrans_test") {
|
||||
"//foundation/communication/dsoftbus/interfaces/kits/transport",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -70,6 +71,7 @@ ohos_unittest("distributed_input_sourcetrans_test") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -33,6 +33,7 @@ ohos_fuzztest("DistributedInputSinkTransportFuzzTest") {
|
||||
"${service_common}/include",
|
||||
"//third_party/json/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
@@ -53,6 +54,7 @@ ohos_fuzztest("DistributedInputSinkTransportFuzzTest") {
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -36,6 +36,7 @@ ohos_fuzztest("DistributedInputSourceTransportFuzzTest") {
|
||||
"${services_source_path}/transport/include",
|
||||
"//third_party/json/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
]
|
||||
|
||||
@@ -59,6 +60,7 @@ ohos_fuzztest("DistributedInputSourceTransportFuzzTest") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/transport:libdinput_source_trans",
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -16,6 +16,7 @@ import("//foundation/distributedhardware/distributed_input/distributedinput.gni"
|
||||
|
||||
ohos_shared_library("libdinput_utils") {
|
||||
include_dirs = [
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_common_path}/log/include",
|
||||
"${fwk_utils_path}/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
@@ -25,6 +26,7 @@ ohos_shared_library("libdinput_utils") {
|
||||
|
||||
sources = [
|
||||
"src/dinput_utils_tool.cpp",
|
||||
"src/dinput_low_latency_utils.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 DINPUT_LOW_LATENCY_UTILS_H
|
||||
#define DINPUT_LOW_LATENCY_UTILS_H
|
||||
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DInputLowLatencyUtils {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DInputLowLatencyUtils);
|
||||
public:
|
||||
void EnableSourceLowLatency();
|
||||
void DisableSourceLowLatency();
|
||||
void EnableSinkLowLatency();
|
||||
void DisableSinkLowLatency();
|
||||
private:
|
||||
DInputLowLatencyUtils() = default;
|
||||
~DInputLowLatencyUtils();
|
||||
int32_t LoadLibrary();
|
||||
void CloseLibrary();
|
||||
|
||||
private:
|
||||
void *handler_ { nullptr };
|
||||
std::mutex mutex_;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DINPUT_LOW_LATENCY_UTILS_H
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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 "dinput_low_latency_utils.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <dlfcn.h>
|
||||
#include <string>
|
||||
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DInputLowLatencyUtils);
|
||||
const std::string LIB_NAME = "libdinput_low_latency.z.so";
|
||||
const std::string FUNC_GET_ENABLE_SOURCE = "EnableSourceLowLatency";
|
||||
const std::string FUNC_GET_DISABLE_SOURCE = "DisableSourceLowLatency";
|
||||
const std::string FUNC_GET_ENABLE_SINK = "EnableSinkLowLatency";
|
||||
const std::string FUNC_GET_DISABLE_SINK = "DisableSinkLowLatency";
|
||||
|
||||
using GetLowLatencyFunc = void *(*)();
|
||||
|
||||
DInputLowLatencyUtils::~DInputLowLatencyUtils()
|
||||
{
|
||||
CloseLibrary();
|
||||
}
|
||||
|
||||
void DInputLowLatencyUtils::EnableSourceLowLatency()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (LoadLibrary() != DH_SUCCESS) {
|
||||
DHLOGE("load library failed");
|
||||
return;
|
||||
}
|
||||
auto enableSourceLowLatency = reinterpret_cast<GetLowLatencyFunc>(dlsym(handler_, FUNC_GET_ENABLE_SOURCE.c_str()));
|
||||
if (enableSourceLowLatency == nullptr) {
|
||||
DHLOGE("can not find %s, failed reason : %s", FUNC_GET_ENABLE_SOURCE.c_str(), dlerror());
|
||||
return;
|
||||
}
|
||||
|
||||
enableSourceLowLatency();
|
||||
}
|
||||
|
||||
void DInputLowLatencyUtils::DisableSourceLowLatency()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (LoadLibrary() != DH_SUCCESS) {
|
||||
DHLOGE("load library failed");
|
||||
return;
|
||||
}
|
||||
auto disableSourceLowLatency =
|
||||
reinterpret_cast<GetLowLatencyFunc>(dlsym(handler_, FUNC_GET_DISABLE_SOURCE.c_str()));
|
||||
if (disableSourceLowLatency == nullptr) {
|
||||
DHLOGE("can not find %s, failed reason : %s", FUNC_GET_DISABLE_SOURCE.c_str(), dlerror());
|
||||
return;
|
||||
}
|
||||
|
||||
disableSourceLowLatency();
|
||||
}
|
||||
|
||||
void DInputLowLatencyUtils::EnableSinkLowLatency()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (LoadLibrary() != DH_SUCCESS) {
|
||||
DHLOGE("load library failed");
|
||||
return;
|
||||
}
|
||||
auto enableSinkLowLatency = reinterpret_cast<GetLowLatencyFunc>(dlsym(handler_, FUNC_GET_ENABLE_SINK.c_str()));
|
||||
if (enableSinkLowLatency == nullptr) {
|
||||
DHLOGE("can not find %s, failed reason : %s", FUNC_GET_ENABLE_SINK.c_str(), dlerror());
|
||||
return;
|
||||
}
|
||||
|
||||
enableSinkLowLatency();
|
||||
}
|
||||
|
||||
void DInputLowLatencyUtils::DisableSinkLowLatency()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (LoadLibrary() != DH_SUCCESS) {
|
||||
DHLOGE("load library failed");
|
||||
return;
|
||||
}
|
||||
auto disableSinkLowLatency = reinterpret_cast<GetLowLatencyFunc>(dlsym(handler_, FUNC_GET_DISABLE_SINK.c_str()));
|
||||
if (disableSinkLowLatency == nullptr) {
|
||||
DHLOGE("can not find %s, failed reason : %s", FUNC_GET_DISABLE_SINK.c_str(), dlerror());
|
||||
return;
|
||||
}
|
||||
|
||||
disableSinkLowLatency();
|
||||
}
|
||||
|
||||
int32_t DInputLowLatencyUtils::LoadLibrary()
|
||||
{
|
||||
DHLOGI("start.");
|
||||
if (handler_ != nullptr) {
|
||||
DHLOGE("DInputLowLatencyUtils handler has loaded.");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
handler_ = dlopen(LIB_NAME.c_str(), RTLD_NOW | RTLD_NODELETE);
|
||||
if (handler_ == nullptr) {
|
||||
DHLOGE("open %s failed, fail reason : %s", LIB_NAME.c_str(), dlerror());
|
||||
return ERR_DH_INPUT_DLOPEN_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DInputLowLatencyUtils::CloseLibrary()
|
||||
{
|
||||
if (handler_ == nullptr) {
|
||||
DHLOGI("%s is already closed.", LIB_NAME.c_str());
|
||||
return;
|
||||
}
|
||||
dlclose(handler_);
|
||||
handler_ = nullptr;
|
||||
DHLOGI("%s is closed.", LIB_NAME.c_str());
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user