From 2ed3c063e0bb0a21a083526940dd63430b07e0f6 Mon Sep 17 00:00:00 2001 From: xxxx Date: Tue, 26 Jul 2022 16:50:07 +0800 Subject: [PATCH] Description:distributed input add low latency Match-id-52a7420c5d4bc4c8bffb564f885b97692d9c1e59 --- common/include/dinput_sa_process_state.cpp | 10 +- distributedinput.gni | 6 + low_latency/BUILD.gn | 64 +++++++++ .../include/dinput_low_latency.h | 24 +--- low_latency/src/dinput_low_latency.cpp | 65 +++++++++ services/sink/sinkmanager/BUILD.gn | 8 ++ .../test/sinkmanagerunittest/BUILD.gn | 8 ++ services/sink/transport/BUILD.gn | 8 ++ .../src/distributed_input_sink_transport.cpp | 10 +- .../transport/test/sinktransunittest/BUILD.gn | 2 + services/source/sourcemanager/BUILD.gn | 8 ++ .../test/sourcemanagerunittest/BUILD.gn | 8 ++ services/source/transport/BUILD.gn | 8 ++ .../distributed_input_source_transport.cpp | 14 +- .../test/sourcetransunittest/BUILD.gn | 2 + .../BUILD.gn | 2 + .../BUILD.gn | 2 + utils/BUILD.gn | 1 - utils/src/dinput_low_latency_utils.cpp | 136 ------------------ 19 files changed, 223 insertions(+), 163 deletions(-) create mode 100644 low_latency/BUILD.gn rename utils/include/dinput_low_latency_utils.h => low_latency/include/dinput_low_latency.h (70%) create mode 100644 low_latency/src/dinput_low_latency.cpp delete mode 100644 utils/src/dinput_low_latency_utils.cpp diff --git a/common/include/dinput_sa_process_state.cpp b/common/include/dinput_sa_process_state.cpp index 9ab7a71..3683d7f 100644 --- a/common/include/dinput_sa_process_state.cpp +++ b/common/include/dinput_sa_process_state.cpp @@ -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 diff --git a/distributedinput.gni b/distributedinput.gni index 2a6d432..61c3e68 100644 --- a/distributedinput.gni +++ b/distributedinput.gni @@ -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 +} diff --git a/low_latency/BUILD.gn b/low_latency/BUILD.gn new file mode 100644 index 0000000..a373a6b --- /dev/null +++ b/low_latency/BUILD.gn @@ -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" + +} diff --git a/utils/include/dinput_low_latency_utils.h b/low_latency/include/dinput_low_latency.h similarity index 70% rename from utils/include/dinput_low_latency_utils.h rename to low_latency/include/dinput_low_latency.h index 9e92248..2860995 100644 --- a/utils/include/dinput_low_latency_utils.h +++ b/low_latency/include/dinput_low_latency.h @@ -13,36 +13,26 @@ * limitations under the License. */ -#ifndef DINPUT_LOW_LATENCY_UTILS_H -#define DINPUT_LOW_LATENCY_UTILS_H - -#include -#include +#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 \ No newline at end of file +#endif // DINPUT_LOW_LATENCY_H diff --git a/low_latency/src/dinput_low_latency.cpp b/low_latency/src/dinput_low_latency.cpp new file mode 100644 index 0000000..71a5bdd --- /dev/null +++ b/low_latency/src/dinput_low_latency.cpp @@ -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 \ No newline at end of file diff --git a/services/sink/sinkmanager/BUILD.gn b/services/sink/sinkmanager/BUILD.gn index 464284b..d33bef4 100644 --- a/services/sink/sinkmanager/BUILD.gn +++ b/services/sink/sinkmanager/BUILD.gn @@ -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 = [ diff --git a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn index 6dd8625..5dd292c 100644 --- a/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn +++ b/services/sink/sinkmanager/test/sinkmanagerunittest/BUILD.gn @@ -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 = [ diff --git a/services/sink/transport/BUILD.gn b/services/sink/transport/BUILD.gn index fe57e71..f860c40 100644 --- a/services/sink/transport/BUILD.gn +++ b/services/sink/transport/BUILD.gn @@ -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 = [ diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index 25d4cce..42933f5 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -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)); diff --git a/services/sink/transport/test/sinktransunittest/BUILD.gn b/services/sink/transport/test/sinktransunittest/BUILD.gn index 9587628..ada8aae 100644 --- a/services/sink/transport/test/sinktransunittest/BUILD.gn +++ b/services/sink/transport/test/sinktransunittest/BUILD.gn @@ -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 = [ diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index d6cb9fe..ec74a94 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -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 = [ diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 4d37271..df845b9 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -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 = [ diff --git a/services/source/transport/BUILD.gn b/services/source/transport/BUILD.gn index 2cbc97c..d6045bc 100644 --- a/services/source/transport/BUILD.gn +++ b/services/source/transport/BUILD.gn @@ -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 = [ diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 40295ee..280a731 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -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); } diff --git a/services/source/transport/test/sourcetransunittest/BUILD.gn b/services/source/transport/test/sourcetransunittest/BUILD.gn index c677372..a899997 100644 --- a/services/source/transport/test/sourcetransunittest/BUILD.gn +++ b/services/source/transport/test/sourcetransunittest/BUILD.gn @@ -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 = [ diff --git a/test/fuzztest/distributedinputsinktransport_fuzzer/BUILD.gn b/test/fuzztest/distributedinputsinktransport_fuzzer/BUILD.gn index a8ed0f1..b48cce9 100644 --- a/test/fuzztest/distributedinputsinktransport_fuzzer/BUILD.gn +++ b/test/fuzztest/distributedinputsinktransport_fuzzer/BUILD.gn @@ -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 = [ diff --git a/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn b/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn index 00418e0..9678ee2 100644 --- a/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn +++ b/test/fuzztest/distributedinputsourcetransport_fuzzer/BUILD.gn @@ -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 = [ diff --git a/utils/BUILD.gn b/utils/BUILD.gn index a4ccf5f..5b274e3 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -26,7 +26,6 @@ ohos_shared_library("libdinput_utils") { sources = [ "src/dinput_utils_tool.cpp", - "src/dinput_low_latency_utils.cpp", ] defines = [ diff --git a/utils/src/dinput_low_latency_utils.cpp b/utils/src/dinput_low_latency_utils.cpp deleted file mode 100644 index 0f7b87c..0000000 --- a/utils/src/dinput_low_latency_utils.cpp +++ /dev/null @@ -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 -#include -#include - -#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 lock(mutex_); - if (LoadLibrary() != DH_SUCCESS) { - DHLOGE("load library failed"); - return; - } - auto enableSourceLowLatency = reinterpret_cast(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 lock(mutex_); - if (LoadLibrary() != DH_SUCCESS) { - DHLOGE("load library failed"); - return; - } - auto disableSourceLowLatency = - reinterpret_cast(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 lock(mutex_); - if (LoadLibrary() != DH_SUCCESS) { - DHLOGE("load library failed"); - return; - } - auto enableSinkLowLatency = reinterpret_cast(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 lock(mutex_); - if (LoadLibrary() != DH_SUCCESS) { - DHLOGE("load library failed"); - return; - } - auto disableSinkLowLatency = reinterpret_cast(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 \ No newline at end of file