mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-18 16:04:40 -04:00
Description:distributed input add low latency
Match-id-52a7420c5d4bc4c8bffb564f885b97692d9c1e59
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
#include "distributed_hardware_log.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_low_latency_utils.h"
|
||||
#include "dinput_low_latency.h"
|
||||
#include "hisysevent_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -46,7 +46,9 @@ void SetSinkProcessExit()
|
||||
}
|
||||
DHLOGI("exit sa process success.");
|
||||
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_EXIT, "dinput sink sa exit success.");
|
||||
DInputLowLatencyUtils::GetInstance().DisableSinkLowLatency();
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().DisableSinkLowLatency();
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -61,7 +63,9 @@ void SetSourceProcessExit()
|
||||
}
|
||||
DHLOGI("exit sa process success.");
|
||||
HisyseventUtil::GetInstance().SysEventWriteBehavior(DINPUT_EXIT, "dinput source sa exit success.");
|
||||
DInputLowLatencyUtils::GetInstance().DisableSourceLowLatency();
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().DisableSourceLowLatency();
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -33,8 +33,14 @@ frameworks_path = "${distributedinput_path}/frameworks"
|
||||
|
||||
service_common = "${distributedinput_path}/services/common"
|
||||
|
||||
low_latency_path = "${distributedinput_path}/low_latency"
|
||||
|
||||
fwk_common_path = "${distributedhardwarefwk_path}/common"
|
||||
|
||||
fwk_utils_path = "${distributedhardwarefwk_path}/utils"
|
||||
|
||||
distributedinput_ldflags = [ "-lpthread" ]
|
||||
|
||||
declare_args() {
|
||||
distributed_input_low_latency = false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
# 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("//foundation/distributedhardware/distributed_input/distributedinput.gni")
|
||||
|
||||
ohos_shared_library("libdinput_low_latency") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/log/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
"${fwk_utils_path}/include",
|
||||
"${frameworks_path}/include",
|
||||
"${distributedinput_path}/low_latency/include",
|
||||
"//foundation/resourceschedule/resource_schedule_service/ressched/interfaces/innerkits/ressched_client/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/dinput_low_latency.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"distributedinputlowlatency\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//utils/native/base:utils",
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"//foundation/resourceschedule/resource_schedule_service/ressched/interfaces/innerkits/ressched_client:ressched_client",
|
||||
"//third_party/jsoncpp:jsoncpp",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-DHILOG_ENABLE" ]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_input"
|
||||
|
||||
}
|
||||
+7
-17
@@ -13,36 +13,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef DINPUT_LOW_LATENCY_UTILS_H
|
||||
#define DINPUT_LOW_LATENCY_UTILS_H
|
||||
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#ifndef DINPUT_LOW_LATENCY_H
|
||||
#define DINPUT_LOW_LATENCY_H
|
||||
|
||||
#include "single_instance.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DInputLowLatencyUtils {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DInputLowLatencyUtils);
|
||||
class DInputLowLatency {
|
||||
DECLARE_SINGLE_INSTANCE_BASE(DInputLowLatency);
|
||||
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_;
|
||||
DInputLowLatency() = default;
|
||||
~DInputLowLatency() = default;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DINPUT_LOW_LATENCY_UTILS_H
|
||||
#endif // DINPUT_LOW_LATENCY_H
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.h"
|
||||
|
||||
#include "res_sched_client.h"
|
||||
#include "res_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
IMPLEMENT_SINGLE_INSTANCE(DInputLowLatency);
|
||||
|
||||
constexpr int32_t MODE_ENABLE = 0;
|
||||
constexpr int32_t MODE_DISABLE = 1;
|
||||
const std::string KEY = "identity";
|
||||
const std::string PKG_SOURCE = "ohos.DistributedHardware.DistributedInput.DistributedInputSourceTransport";
|
||||
const std::string PKG_SINK = "ohos.DistributedHardware.DistributedInput.DistributedInputSinkTransport";
|
||||
|
||||
void DInputLowLatency::EnableSourceLowLatency()
|
||||
{
|
||||
auto &rssClient = OHOS::ResourceSchedule::ResSchedClient::GetInstance();
|
||||
// to enable low latency mode: value = 0
|
||||
rssClient.ReportData(OHOS::ResourceSchedule::ResType::RES_TYPE_NETWORK_LATENCY_REQUEST, MODE_ENABLE,
|
||||
{{KEY, PKG_SOURCE}});
|
||||
}
|
||||
|
||||
void DInputLowLatency::DisableSourceLowLatency()
|
||||
{
|
||||
auto &rssClient = OHOS::ResourceSchedule::ResSchedClient::GetInstance();
|
||||
// to restore normal latency mode: value = 1
|
||||
rssClient.ReportData(OHOS::ResourceSchedule::ResType::RES_TYPE_NETWORK_LATENCY_REQUEST, MODE_DISABLE,
|
||||
{{KEY, PKG_SOURCE}});
|
||||
}
|
||||
|
||||
void DInputLowLatency::EnableSinkLowLatency()
|
||||
{
|
||||
auto &rssClient = OHOS::ResourceSchedule::ResSchedClient::GetInstance();
|
||||
// to enable low latency mode: value = 0
|
||||
rssClient.ReportData(OHOS::ResourceSchedule::ResType::RES_TYPE_NETWORK_LATENCY_REQUEST, MODE_ENABLE,
|
||||
{{KEY, PKG_SINK}});
|
||||
}
|
||||
|
||||
void DInputLowLatency::DisableSinkLowLatency()
|
||||
{
|
||||
auto &rssClient = OHOS::ResourceSchedule::ResSchedClient::GetInstance();
|
||||
// to restore normal latency mode: value = 1
|
||||
rssClient.ReportData(OHOS::ResourceSchedule::ResType::RES_TYPE_NETWORK_LATENCY_REQUEST, MODE_DISABLE,
|
||||
{{KEY, PKG_SINK}});
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -35,6 +35,7 @@ ohos_shared_library("libdinput_sink") {
|
||||
"//third_party/json/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -53,6 +54,12 @@ ohos_shared_library("libdinput_sink") {
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
if (distributed_input_low_latency) {
|
||||
defines += [
|
||||
"DINPUT_LOW_LATENCY",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//foundation/distributedhardware/distributed_input/interfaces/inner_kits:libdinput_sdk",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
@@ -62,6 +69,7 @@ ohos_shared_library("libdinput_sink") {
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/inputcollector:libdinput_collector",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -46,6 +46,7 @@ ohos_unittest("distributed_input_sinkmanager_test") {
|
||||
"${services_sink_path}/inputcollector/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -77,6 +78,12 @@ ohos_unittest("distributed_input_sinkmanager_test") {
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
if (distributed_input_low_latency) {
|
||||
defines += [
|
||||
"DINPUT_LOW_LATENCY",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//utils/native/base:utils",
|
||||
@@ -85,6 +92,7 @@ ohos_unittest("distributed_input_sinkmanager_test") {
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -29,6 +29,7 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"${service_common}/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -42,6 +43,12 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
if (distributed_input_low_latency) {
|
||||
defines += [
|
||||
"DINPUT_LOW_LATENCY",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
|
||||
@@ -50,6 +57,7 @@ ohos_shared_library("libdinput_sink_trans") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_low_latency_utils.h"
|
||||
#include "dinput_low_latency.h"
|
||||
#include "hidumper.h"
|
||||
#include "session.h"
|
||||
#include "softbus_bus_center.h"
|
||||
@@ -273,7 +273,9 @@ int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
DInputLowLatencyUtils::GetInstance().EnableSinkLowLatency();
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().EnableSinkLowLatency();
|
||||
#endif
|
||||
|
||||
// return 1 is client
|
||||
int32_t sessionSide = GetSessionSide(sessionId);
|
||||
@@ -307,7 +309,9 @@ void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId)
|
||||
{
|
||||
DHLOGI("OnSessionClosed, sessionId:%s", GetAnonyInt32(sessionId).c_str());
|
||||
|
||||
DInputLowLatencyUtils::GetInstance().DisableSinkLowLatency();
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().DisableSinkLowLatency();
|
||||
#endif
|
||||
|
||||
char peerDevId[DEVICE_ID_SIZE_MAX] = "";
|
||||
int ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId));
|
||||
|
||||
@@ -40,6 +40,7 @@ ohos_unittest("distributed_input_sinktrans_test") {
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/transport/test/sinktransunittest/mock",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -69,6 +70,7 @@ ohos_unittest("distributed_input_sinktrans_test") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -36,6 +36,7 @@ ohos_shared_library("libdinput_source") {
|
||||
"${utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -73,6 +74,12 @@ ohos_shared_library("libdinput_source") {
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
if (distributed_input_low_latency) {
|
||||
defines += [
|
||||
"DINPUT_LOW_LATENCY",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//foundation/distributedhardware/distributed_input/interfaces/inner_kits:libdinput_sdk",
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
@@ -82,6 +89,7 @@ ohos_shared_library("libdinput_source") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -48,6 +48,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"${dfx_utils_path}/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -100,6 +101,12 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
if (distributed_input_low_latency) {
|
||||
defines += [
|
||||
"DINPUT_LOW_LATENCY",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//utils/native/base:utils",
|
||||
@@ -108,6 +115,7 @@ ohos_unittest("distributed_input_sourcemanager_test") {
|
||||
"//foundation/distributedhardware/device_manager/interfaces/inner_kits/native_cpp:devicemanagersdk",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -32,6 +32,7 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -44,6 +45,12 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
if (distributed_input_low_latency) {
|
||||
defines += [
|
||||
"DINPUT_LOW_LATENCY",
|
||||
]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"//base/notification/eventhandler/frameworks/eventhandler:libeventhandler",
|
||||
"//utils/native/base:utils",
|
||||
@@ -53,6 +60,7 @@ ohos_shared_library("libdinput_source_trans") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_hitrace.h"
|
||||
#include "dinput_low_latency_utils.h"
|
||||
#include "dinput_low_latency.h"
|
||||
#include "dinput_softbus_define.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
#include "distributed_input_inject.h"
|
||||
@@ -188,7 +188,11 @@ 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();
|
||||
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().EnableSourceLowLatency();
|
||||
#endif
|
||||
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId, SessionStatus::OPENED);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
@@ -212,7 +216,11 @@ void DistributedInputSourceTransport::CloseInputSoftbus(const std::string &remot
|
||||
sessionDevMap_.erase(remoteDevId);
|
||||
channelStatusMap_.erase(remoteDevId);
|
||||
DistributedInputInject::GetInstance().StopInjectThread();
|
||||
DInputLowLatencyUtils::GetInstance().DisableSourceLowLatency();
|
||||
|
||||
#ifdef DINPUT_LOW_LATENCY
|
||||
DInputLowLatency::GetInstance().DisableSourceLowLatency();
|
||||
#endif
|
||||
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId, SessionStatus::CLOSED);
|
||||
HiDumper::GetInstance().DeleteSessionInfo(remoteDevId);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ ohos_unittest("distributed_input_sourcetrans_test") {
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
@@ -72,6 +73,7 @@ ohos_unittest("distributed_input_sourcetrans_test") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -34,6 +34,7 @@ ohos_fuzztest("DistributedInputSinkTransportFuzzTest") {
|
||||
"//third_party/json/include",
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
@@ -55,6 +56,7 @@ ohos_fuzztest("DistributedInputSinkTransportFuzzTest") {
|
||||
"//foundation/communication/dsoftbus/sdk:softbus_client",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -38,6 +38,7 @@ ohos_fuzztest("DistributedInputSourceTransportFuzzTest") {
|
||||
"${dfx_utils_path}/include",
|
||||
"${utils_path}/include",
|
||||
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter",
|
||||
"${low_latency_path}/include",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
@@ -61,6 +62,7 @@ ohos_fuzztest("DistributedInputSourceTransportFuzzTest") {
|
||||
"//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject",
|
||||
"${dfx_utils_path}:libdinput_dfx_utils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"${low_latency_path}:libdinput_low_latency",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -26,7 +26,6 @@ ohos_shared_library("libdinput_utils") {
|
||||
|
||||
sources = [
|
||||
"src/dinput_utils_tool.cpp",
|
||||
"src/dinput_low_latency_utils.cpp",
|
||||
]
|
||||
|
||||
defines = [
|
||||
|
||||
@@ -1,136 +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 "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);
|
||||
constexpr const char* LIB_NAME = "libdinput_low_latency.z.so";
|
||||
constexpr const char* FUNC_GET_ENABLE_SOURCE = "EnableSourceLowLatency";
|
||||
constexpr const char* FUNC_GET_DISABLE_SOURCE = "DisableSourceLowLatency";
|
||||
constexpr const char* FUNC_GET_ENABLE_SINK = "EnableSinkLowLatency";
|
||||
constexpr const char* 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));
|
||||
if (enableSourceLowLatency == nullptr) {
|
||||
DHLOGE("can not find %s, failed reason : %s", FUNC_GET_ENABLE_SOURCE, 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));
|
||||
if (disableSourceLowLatency == nullptr) {
|
||||
DHLOGE("can not find %s, failed reason : %s", FUNC_GET_DISABLE_SOURCE, 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));
|
||||
if (enableSinkLowLatency == nullptr) {
|
||||
DHLOGE("can not find %s, failed reason : %s", FUNC_GET_ENABLE_SINK, 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));
|
||||
if (disableSinkLowLatency == nullptr) {
|
||||
DHLOGE("can not find %s, failed reason : %s", FUNC_GET_DISABLE_SINK, dlerror());
|
||||
return;
|
||||
}
|
||||
|
||||
disableSinkLowLatency();
|
||||
}
|
||||
|
||||
int32_t DInputLowLatencyUtils::LoadLibrary()
|
||||
{
|
||||
DHLOGI("start.");
|
||||
if (handler_ != nullptr) {
|
||||
DHLOGE("DInputLowLatencyUtils handler has loaded.");
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
handler_ = dlopen(LIB_NAME, RTLD_NOW | RTLD_NODELETE);
|
||||
if (handler_ == nullptr) {
|
||||
DHLOGE("open %s failed, fail reason : %s", LIB_NAME, dlerror());
|
||||
return ERR_DH_INPUT_DLOPEN_FAIL;
|
||||
}
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DInputLowLatencyUtils::CloseLibrary()
|
||||
{
|
||||
if (handler_ == nullptr) {
|
||||
DHLOGI("%s is already closed.", LIB_NAME);
|
||||
return;
|
||||
}
|
||||
dlclose(handler_);
|
||||
handler_ = nullptr;
|
||||
DHLOGI("%s is closed.", LIB_NAME);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user