mirror of
https://github.com/openharmony/distributed_screen.git
synced 2026-07-21 20:45:25 -04:00
+2
-1
@@ -52,7 +52,8 @@
|
||||
"//foundation/distributedhardware/distributedscreen/services/screentransport/screensourcetrans:distributed_screen_sourcetrans",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screenservice/sinkservice:distributed_screen_sink",
|
||||
"//foundation/distributedhardware/distributedscreen/services/screenservice/sourceservice:distributed_screen_source",
|
||||
"//foundation/distributedhardware/distributedscreen/sa_profile:dscreen_sa_profile"
|
||||
"//foundation/distributedhardware/distributedscreen/sa_profile:dscreen_sa_profile",
|
||||
"//foundation/distributedhardware/distributedscreen/sa_profile:dscreen.cfg"
|
||||
],
|
||||
"inner_kits":[
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ enum VideoFormat : uint8_t {
|
||||
};
|
||||
|
||||
/* Screen package name */
|
||||
const std::string PKG_NAME = "ohos.dhardware";
|
||||
const std::string PKG_NAME = "ohos.dhardware.dscreen";
|
||||
|
||||
/* Screen data session name */
|
||||
const std::string DATA_SESSION_NAME = "ohos.dhardware.dscreen.data";
|
||||
@@ -125,6 +125,7 @@ constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID = 4807;
|
||||
constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID = 4808;
|
||||
constexpr uint64_t SCREEN_ID_INVALID = -1ULL;
|
||||
constexpr uint64_t SCREEN_ID_DEFAULT = 0;
|
||||
constexpr int32_t SCREEN_LOADSA_TIMEOUT_MS = 10000;
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -53,6 +53,7 @@ enum DScreenErrorCode {
|
||||
ERR_DH_SCREEN_SA_REGISTER_SCREENLISTENER_FAIL = -500029,
|
||||
ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL = -500030,
|
||||
ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL = -500031,
|
||||
ERR_DH_SCREEN_SA_LOAD_TIMEOUT = -500032,
|
||||
// Transport component error code
|
||||
ERR_DH_SCREEN_TRANS_ERROR = -51000,
|
||||
ERR_DH_SCREEN_TRANS_TIMEOUT = -51001,
|
||||
|
||||
@@ -13,43 +13,46 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
import(
|
||||
"//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_sink_sdk") {
|
||||
include_dirs = [
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
include_dirs = [
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"${common_path}/include",
|
||||
]
|
||||
include_dirs += [
|
||||
"include",
|
||||
"include/callback",
|
||||
"${common_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/dscreen_sink_handler.cpp",
|
||||
"src/dscreen_sink_proxy.cpp",
|
||||
]
|
||||
sources = [
|
||||
"src/callback/dscreen_sink_load_callback.cpp",
|
||||
"src/dscreen_sink_handler.cpp",
|
||||
"src/dscreen_sink_proxy.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${common_path}:distributed_screen_utils",
|
||||
]
|
||||
deps = [
|
||||
"${common_path}:distributed_screen_utils",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensinksdk\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensinksdk\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_DSCREEN_SINK_LOAD_CALLBACK_H
|
||||
#define OHOS_DSCREEN_SINK_LOAD_CALLBACK_H
|
||||
|
||||
#include "system_ability_load_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSinkLoadCallback : public SystemAbilityLoadCallbackStub {
|
||||
public:
|
||||
explicit DScreenSinkLoadCallback(const std::string ¶ms);
|
||||
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
|
||||
const sptr<IRemoteObject> &remoteObject) override;
|
||||
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
|
||||
private:
|
||||
std::string params_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_DSCREEN_SINK_HANDLER_H
|
||||
#define OHOS_DSCREEN_SINK_HANDLER_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include "idistributed_hardware_sink.h"
|
||||
@@ -33,6 +34,7 @@ public:
|
||||
int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override;
|
||||
int32_t UnsubscribeLocalHardware(const std::string &dhId) override;
|
||||
void OnRemoteSinkSvrDied(const wptr<IRemoteObject> &remote);
|
||||
void FinishStartSA(const std::string ¶ms, const sptr<IRemoteObject> &remoteObject);
|
||||
private:
|
||||
class DScreenSinkSvrRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
@@ -42,7 +44,8 @@ private:
|
||||
DScreenSinkHandler();
|
||||
~DScreenSinkHandler();
|
||||
|
||||
std::mutex mutex_;
|
||||
std::mutex proxyMutex_;
|
||||
std::condition_variable proxyConVar_;
|
||||
sptr<IDScreenSink> dScreenSinkProxy_ = nullptr;
|
||||
sptr<DScreenSinkSvrRecipient> sinkSvrRecipient_ = nullptr;
|
||||
};
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 "dscreen_sink_load_callback.h"
|
||||
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_sink_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DScreenSinkLoadCallback::DScreenSinkLoadCallback(
|
||||
const std::string ¶ms) : params_(params) {}
|
||||
|
||||
void DScreenSinkLoadCallback::OnLoadSystemAbilitySuccess(
|
||||
int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject)
|
||||
{
|
||||
DHLOGI("load screen SA success, systemAbilityId:%d, remoteObject result:%s",
|
||||
systemAbilityId, (remoteObject != nullptr) ? "true" : "false");
|
||||
if (remoteObject == nullptr) {
|
||||
DHLOGE("remoteObject is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
DScreenSinkHandler::GetInstance().FinishStartSA(params_, remoteObject);
|
||||
}
|
||||
|
||||
void DScreenSinkLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
|
||||
{
|
||||
DHLOGE("load screen SA failed, systemAbilityId:%d", systemAbilityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_sink_load_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -29,7 +30,7 @@ IMPLEMENT_SINGLE_INSTANCE(DScreenSinkHandler);
|
||||
DScreenSinkHandler::DScreenSinkHandler()
|
||||
{
|
||||
DHLOGI("DScreenSinkHandler construct.");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (!sinkSvrRecipient_) {
|
||||
sinkSvrRecipient_ = new DScreenSinkSvrRecipient();
|
||||
}
|
||||
@@ -43,49 +44,65 @@ DScreenSinkHandler::~DScreenSinkHandler()
|
||||
int32_t DScreenSinkHandler::InitSink(const std::string ¶ms)
|
||||
{
|
||||
DHLOGD("InitSink");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (!dScreenSinkProxy_) {
|
||||
sptr<ISystemAbilityManager> samgr =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!samgr) {
|
||||
DHLOGE("Failed to get system ability mgr.");
|
||||
return ERR_DH_SCREEN_SA_GET_SAMGR_FAIL;
|
||||
}
|
||||
sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID);
|
||||
if (!remoteObject) {
|
||||
DHLOGE("Failed to get dscreen sink service.");
|
||||
return ERR_DH_SCREEN_SA_GET_SINKSERVICE_FAIL;
|
||||
}
|
||||
|
||||
remoteObject->AddDeathRecipient(sinkSvrRecipient_);
|
||||
dScreenSinkProxy_ = iface_cast<IDScreenSink>(remoteObject);
|
||||
if ((!dScreenSinkProxy_) || (!dScreenSinkProxy_->AsObject())) {
|
||||
DHLOGE("Failed to get dscreen sink proxy.");
|
||||
sptr<DScreenSinkLoadCallback> loadCallback = new DScreenSinkLoadCallback(params);
|
||||
int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, loadCallback);
|
||||
if (ret != ERR_OK) {
|
||||
DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d",
|
||||
DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, ret);
|
||||
return ERR_DH_SCREEN_SA_GET_SINKPROXY_FAIL;
|
||||
}
|
||||
}
|
||||
int32_t ret = dScreenSinkProxy_->InitSink(params);
|
||||
return ret;
|
||||
|
||||
std::unique_lock<std::mutex> lock(proxyMutex_);
|
||||
auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(SCREEN_LOADSA_TIMEOUT_MS),
|
||||
[this]() { return dScreenSinkProxy_ != nullptr; });
|
||||
if (!waitStatus) {
|
||||
DHLOGE("screen load sa timeout");
|
||||
return ERR_DH_SCREEN_SA_LOAD_TIMEOUT;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DScreenSinkHandler::FinishStartSA(const std::string ¶ms,
|
||||
const sptr<IRemoteObject> &remoteObject)
|
||||
{
|
||||
DHLOGD("FinishStartSA");
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
remoteObject->AddDeathRecipient(sinkSvrRecipient_);
|
||||
dScreenSinkProxy_ = iface_cast<IDScreenSink>(remoteObject);
|
||||
if ((!dScreenSinkProxy_) || (!dScreenSinkProxy_->AsObject())) {
|
||||
DHLOGE("Failed to get dscreen sink proxy.");
|
||||
return;
|
||||
}
|
||||
dScreenSinkProxy_->InitSink(params);
|
||||
proxyConVar_.notify_one();
|
||||
}
|
||||
|
||||
int32_t DScreenSinkHandler::ReleaseSink()
|
||||
{
|
||||
DHLOGD("ReleaseSink");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (!dScreenSinkProxy_) {
|
||||
DHLOGE("screen sink proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT;
|
||||
}
|
||||
|
||||
int32_t ret = dScreenSinkProxy_->ReleaseSink();
|
||||
dScreenSinkProxy_ = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkHandler::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m)
|
||||
{
|
||||
DHLOGD("SubscribeLocalHardware");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (!dScreenSinkProxy_) {
|
||||
DHLOGE("screen sink proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT;
|
||||
@@ -97,7 +114,7 @@ int32_t DScreenSinkHandler::SubscribeLocalHardware(const std::string &dhId, cons
|
||||
int32_t DScreenSinkHandler::UnsubscribeLocalHardware(const std::string &dhId)
|
||||
{
|
||||
DHLOGD("UnsubscribeLocalHardware");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (!dScreenSinkProxy_) {
|
||||
DHLOGE("screen sink proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT;
|
||||
@@ -120,7 +137,7 @@ void DScreenSinkHandler::OnRemoteSinkSvrDied(const wptr<IRemoteObject> &remote)
|
||||
DHLOGE("OnRemoteDied remote promoted failed");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (dScreenSinkProxy_ != nullptr) {
|
||||
dScreenSinkProxy_->AsObject()->RemoveDeathRecipient(sinkSvrRecipient_);
|
||||
dScreenSinkProxy_ = nullptr;
|
||||
|
||||
@@ -13,46 +13,48 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
import(
|
||||
"//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_source_sdk") {
|
||||
include_dirs = [
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
include_dirs = [
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"include",
|
||||
"include/callback",
|
||||
"${common_path}/include",
|
||||
]
|
||||
include_dirs += [
|
||||
"include",
|
||||
"include/callback",
|
||||
"${common_path}/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"src/dscreen_source_handler.cpp",
|
||||
"src/dscreen_source_proxy.cpp",
|
||||
"src/callback/dscreen_source_callback_stub.cpp",
|
||||
"src/callback/dscreen_source_callback.cpp",
|
||||
]
|
||||
sources = [
|
||||
"src/callback/dscreen_source_callback.cpp",
|
||||
"src/callback/dscreen_source_callback_stub.cpp",
|
||||
"src/callback/dscreen_source_load_callback.cpp",
|
||||
"src/dscreen_source_handler.cpp",
|
||||
"src/dscreen_source_proxy.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${common_path}:distributed_screen_utils",
|
||||
]
|
||||
deps = [
|
||||
"${common_path}:distributed_screen_utils",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensourcesdk\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensourcesdk\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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_DSCREEN_SOURCE_LOAD_CALLBACK_H
|
||||
#define OHOS_DSCREEN_SOURCE_LOAD_CALLBACK_H
|
||||
|
||||
#include "system_ability_load_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
class DScreenSourceLoadCallback : public SystemAbilityLoadCallbackStub {
|
||||
public:
|
||||
explicit DScreenSourceLoadCallback(const std::string ¶ms);
|
||||
void OnLoadSystemAbilitySuccess(int32_t systemAbilityId,
|
||||
const sptr<IRemoteObject> &remoteObject) override;
|
||||
void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
|
||||
private:
|
||||
std::string params_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_DSCREEN_SOURCE_HANDLER_H
|
||||
#define OHOS_DSCREEN_SOURCE_HANDLER_H
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include "dscreen_source_callback.h"
|
||||
@@ -37,6 +38,7 @@ public:
|
||||
int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId,
|
||||
const std::string &key, const std::string &value) override;
|
||||
void OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remote);
|
||||
void FinishStartSA(const std::string ¶ms, const sptr<IRemoteObject> &remoteObject);
|
||||
private:
|
||||
class DScreenSourceSvrRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
@@ -46,7 +48,8 @@ private:
|
||||
DScreenSourceHandler();
|
||||
~DScreenSourceHandler();
|
||||
|
||||
std::mutex mutex_;
|
||||
std::mutex proxyMutex_;
|
||||
std::condition_variable proxyConVar_;
|
||||
sptr<IDScreenSource> dScreenSourceProxy_ = nullptr;
|
||||
sptr<DScreenSourceCallback> dScreenSourceCallback_ = nullptr;
|
||||
sptr<DScreenSourceSvrRecipient> sourceSvrRecipient_ = nullptr;
|
||||
|
||||
+8
@@ -33,6 +33,14 @@ DScreenSourceCallbackStub::~DScreenSourceCallbackStub()
|
||||
int32_t DScreenSourceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
DHLOGI("OnRemoteRequest, code: %d", code);
|
||||
std::u16string desc = DScreenSourceCallbackStub::GetDescriptor();
|
||||
std::u16string remoteDesc = data.ReadInterfaceToken();
|
||||
if (desc != remoteDesc) {
|
||||
DHLOGE("DScreenSourceCallbackStub::OnRemoteRequest remoteDesc is invalid!");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
|
||||
std::map<int32_t, DScreenFunc>::iterator iter = memberFuncMap_.find(code);
|
||||
if (iter == memberFuncMap_.end()) {
|
||||
DHLOGE("invalid request code.");
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 "dscreen_source_load_callback.h"
|
||||
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_source_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
DScreenSourceLoadCallback::DScreenSourceLoadCallback(
|
||||
const std::string ¶ms) : params_(params) {}
|
||||
|
||||
void DScreenSourceLoadCallback::OnLoadSystemAbilitySuccess(
|
||||
int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject)
|
||||
{
|
||||
DHLOGI("load screen SA success, systemAbilityId:%d, remoteObject result:%s",
|
||||
systemAbilityId, (remoteObject != nullptr) ? "true" : "false");
|
||||
if (remoteObject == nullptr) {
|
||||
DHLOGE("remoteObject is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
DScreenSourceHandler::GetInstance().FinishStartSA(params_, remoteObject);
|
||||
}
|
||||
|
||||
void DScreenSourceLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId)
|
||||
{
|
||||
DHLOGE("load screen SA failed, systemAbilityId:%d", systemAbilityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "dscreen_constants.h"
|
||||
#include "dscreen_errcode.h"
|
||||
#include "dscreen_log.h"
|
||||
#include "dscreen_source_load_callback.h"
|
||||
#include "dscreen_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -30,7 +31,7 @@ IMPLEMENT_SINGLE_INSTANCE(DScreenSourceHandler);
|
||||
DScreenSourceHandler::DScreenSourceHandler()
|
||||
{
|
||||
DHLOGI("DScreenSourceHandler construct.");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (!sourceSvrRecipient_) {
|
||||
sourceSvrRecipient_ = new DScreenSourceSvrRecipient();
|
||||
}
|
||||
@@ -48,42 +49,58 @@ DScreenSourceHandler::~DScreenSourceHandler()
|
||||
int32_t DScreenSourceHandler::InitSource(const std::string ¶ms)
|
||||
{
|
||||
DHLOGD("InitSource");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
if (!dScreenSourceProxy_) {
|
||||
sptr<ISystemAbilityManager> samgr =
|
||||
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (!samgr) {
|
||||
DHLOGE("Failed to get system ability mgr.");
|
||||
return ERR_DH_SCREEN_SA_GET_SAMGR_FAIL;
|
||||
}
|
||||
sptr<IRemoteObject> remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID);
|
||||
if (!remoteObject) {
|
||||
DHLOGE("Failed to get dscreen source service.");
|
||||
return ERR_DH_SCREEN_SA_GET_SOURCESERVICE_FAIL;
|
||||
}
|
||||
|
||||
remoteObject->AddDeathRecipient(sourceSvrRecipient_);
|
||||
dScreenSourceProxy_ = iface_cast<IDScreenSource>(remoteObject);
|
||||
if ((!dScreenSourceProxy_) || (!dScreenSourceProxy_->AsObject())) {
|
||||
DHLOGE("Failed to get dscreen source proxy.");
|
||||
sptr<DScreenSourceLoadCallback> loadCallback = new DScreenSourceLoadCallback(params);
|
||||
int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, loadCallback);
|
||||
if (ret != ERR_OK) {
|
||||
DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d",
|
||||
DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, ret);
|
||||
return ERR_DH_SCREEN_SA_GET_SOURCEPROXY_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ret = dScreenSourceProxy_->InitSource(params, dScreenSourceCallback_);
|
||||
return ret;
|
||||
std::unique_lock<std::mutex> lock(proxyMutex_);
|
||||
auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(SCREEN_LOADSA_TIMEOUT_MS),
|
||||
[this]() { return (dScreenSourceProxy_ != nullptr); });
|
||||
if (!waitStatus) {
|
||||
DHLOGE("screen load sa timeout.");
|
||||
return ERR_DH_SCREEN_SA_LOAD_TIMEOUT;
|
||||
}
|
||||
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DScreenSourceHandler::FinishStartSA(const std::string ¶ms,
|
||||
const sptr<IRemoteObject> &remoteObject)
|
||||
{
|
||||
DHLOGD("FinishStartSA");
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
remoteObject->AddDeathRecipient(sourceSvrRecipient_);
|
||||
dScreenSourceProxy_ = iface_cast<IDScreenSource>(remoteObject);
|
||||
if ((!dScreenSourceProxy_) || (!dScreenSourceProxy_->AsObject())) {
|
||||
DHLOGE("Failed to get dscreen source proxy.");
|
||||
return;
|
||||
}
|
||||
dScreenSourceProxy_->InitSource(params, dScreenSourceCallback_);
|
||||
proxyConVar_.notify_one();
|
||||
}
|
||||
|
||||
int32_t DScreenSourceHandler::ReleaseSource()
|
||||
{
|
||||
DHLOGD("ReleaseSource");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (!dScreenSourceProxy_) {
|
||||
DHLOGE("screen source proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT;
|
||||
}
|
||||
int32_t ret = dScreenSourceProxy_->ReleaseSource();
|
||||
dScreenSourceProxy_ = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -92,7 +109,7 @@ int32_t DScreenSourceHandler::RegisterDistributedHardware(const std::string &dev
|
||||
{
|
||||
DHLOGD("RegisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (!dScreenSourceProxy_) {
|
||||
DHLOGE("screen source proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT;
|
||||
@@ -113,7 +130,7 @@ int32_t DScreenSourceHandler::UnregisterDistributedHardware(const std::string &d
|
||||
{
|
||||
DHLOGD("UnregisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(),
|
||||
GetAnonyString(dhId).c_str());
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (!dScreenSourceProxy_) {
|
||||
DHLOGE("screen source proxy not init.");
|
||||
return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT;
|
||||
@@ -150,7 +167,7 @@ void DScreenSourceHandler::OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remo
|
||||
DHLOGE("OnRemoteDied remote promoted failed");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::lock_guard<std::mutex> lock(proxyMutex_);
|
||||
if (dScreenSourceProxy_ != nullptr) {
|
||||
dScreenSourceProxy_->AsObject()->RemoveDeathRecipient(sourceSvrRecipient_);
|
||||
dScreenSourceProxy_ = nullptr;
|
||||
|
||||
+2
-2
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
-->
|
||||
<info>
|
||||
<process>dhardware</process>
|
||||
<process>dscreen</process>
|
||||
<systemability> <!-- Declare a sytem ability and its profile -->
|
||||
<name>4807</name> <!-- Declare the name of system ability -->
|
||||
<libpath>libdistributed_screen_source.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
|
||||
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
|
||||
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
|
||||
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
|
||||
<run-on-create>false</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
|
||||
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
|
||||
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
|
||||
</systemability>
|
||||
|
||||
+2
-2
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
-->
|
||||
<info>
|
||||
<process>dhardware</process>
|
||||
<process>dscreen</process>
|
||||
<systemability> <!-- Declare a sytem ability and its profile -->
|
||||
<name>4808</name> <!-- Declare the name of system ability -->
|
||||
<libpath>libdistributed_screen_sink.z.so</libpath> <!-- Declare the path of .so file which includes the system ability; Note: 1 .so file can have 1 to N system abilities. -->
|
||||
<!--<depend></depend> --> <!-- Declare the name of system abilities which the system ability depends on, using ";" as separator among names. If there are dependencies, it needs to check if all those dependencies are avliable in service manager before starting the system ability. -->
|
||||
<!--<depend-time-out></depend-time-out> --> <!-- Check all dependencies are avaliable before the timeout period ended. The MAX_DEPENDENCY_TIMEOUT is 60s. -->
|
||||
<run-on-create>true</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
|
||||
<run-on-create>false</run-on-create> <!-- "true" means the system ability would start imediately, "false" means the system ability would start on demand. -->
|
||||
<distributed>true</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not. -->
|
||||
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
|
||||
</systemability>
|
||||
|
||||
+9
-2
@@ -11,7 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos/sa_profile/sa_profile.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_sa_profile("dscreen_sa_profile") {
|
||||
sources = [
|
||||
@@ -20,4 +20,11 @@ ohos_sa_profile("dscreen_sa_profile") {
|
||||
]
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("dscreen.cfg") {
|
||||
relative_install_dir = "init"
|
||||
source = "dscreen.cfg"
|
||||
part_name = "distributed_screen"
|
||||
subsystem_name = "distributedhardware"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"services" : [{
|
||||
"name" : "dscreen",
|
||||
"path" : ["/system/bin/sa_main", "/system/profile/dscreen.xml"],
|
||||
"uid" : "system",
|
||||
"gid" : ["system"],
|
||||
"ondemand" : true
|
||||
}]
|
||||
}
|
||||
@@ -13,70 +13,71 @@
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos_var.gni")
|
||||
import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
import(
|
||||
"//foundation/distributedhardware/distributedscreen/distributedscreen.gni")
|
||||
|
||||
ohos_shared_library("distributed_screen_sink") {
|
||||
include_dirs = [
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//foundation/graphic/standard/interfaces/innerkits/surface",
|
||||
"${windowmanager_path}/interfaces/innerkits/dm",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
include_dirs = [
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"//foundation/graphic/standard/interfaces/innerkits/surface",
|
||||
"${windowmanager_path}/interfaces/innerkits/dm",
|
||||
"${fwk_common_path}/utils/include",
|
||||
]
|
||||
|
||||
include_dirs += [
|
||||
"./dscreenservice/include",
|
||||
"./screenregionmgr/include",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_sink/include",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_source/include",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_source/include/callback",
|
||||
"${common_path}/include",
|
||||
"${services_path}/common/utils/include",
|
||||
"${services_path}/common/databuffer/include",
|
||||
"${services_path}/common/screen_channel/include",
|
||||
"${services_path}/screentransport/screensinktrans/include",
|
||||
"${services_path}/screentransport/screensinkprocessor/include",
|
||||
"${services_path}/screentransport/screensinkprocessor/decoder/include",
|
||||
"${services_path}/screenclient/include/",
|
||||
]
|
||||
include_dirs += [
|
||||
"./dscreenservice/include",
|
||||
"./screenregionmgr/include",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_sink/include",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_source/include",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_source/include/callback",
|
||||
"${common_path}/include",
|
||||
"${services_path}/common/utils/include",
|
||||
"${services_path}/common/databuffer/include",
|
||||
"${services_path}/common/screen_channel/include",
|
||||
"${services_path}/screentransport/screensinktrans/include",
|
||||
"${services_path}/screentransport/screensinkprocessor/include",
|
||||
"${services_path}/screentransport/screensinkprocessor/decoder/include",
|
||||
"${services_path}/screenclient/include/",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${services_path}/common/utils/src/dscreen_maprelation.cpp",
|
||||
"${services_path}/common/utils/src/video_param.cpp",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp",
|
||||
"./dscreenservice/src/dscreen_sink_service.cpp",
|
||||
"./dscreenservice/src/dscreen_sink_stub.cpp",
|
||||
"./screenregionmgr/src/screenregion.cpp",
|
||||
"./screenregionmgr/src/screenregionmgr.cpp",
|
||||
]
|
||||
sources = [
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp",
|
||||
"${interfaces_path}/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp",
|
||||
"${services_path}/common/utils/src/dscreen_maprelation.cpp",
|
||||
"${services_path}/common/utils/src/video_param.cpp",
|
||||
"./dscreenservice/src/dscreen_sink_service.cpp",
|
||||
"./dscreenservice/src/dscreen_sink_stub.cpp",
|
||||
"./screenregionmgr/src/screenregion.cpp",
|
||||
"./screenregionmgr/src/screenregionmgr.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//utils/native/base:utils",
|
||||
"${common_path}:distributed_screen_utils",
|
||||
"${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans",
|
||||
"${services_path}/screenclient:distributed_screen_client",
|
||||
"//foundation/graphic/standard/frameworks/surface:surface",
|
||||
"${windowmanager_path}/dm:libdm",
|
||||
]
|
||||
deps = [
|
||||
"${common_path}:distributed_screen_utils",
|
||||
"${services_path}/screenclient:distributed_screen_client",
|
||||
"${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans",
|
||||
"${windowmanager_path}/dm:libdm",
|
||||
"//foundation/graphic/standard/frameworks/surface:surface",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensink\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"dscreensink\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
"multimedia_media_standard:media_client",
|
||||
]
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"multimedia_media_standard:media_client",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
subsystem_name = "distributedhardware"
|
||||
subsystem_name = "distributedhardware"
|
||||
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
part_name = "distributed_screen"
|
||||
}
|
||||
|
||||
@@ -76,7 +76,10 @@ int32_t DScreenSinkService::InitSink(const std::string ¶ms)
|
||||
int32_t DScreenSinkService::ReleaseSink()
|
||||
{
|
||||
DHLOGI("ReleaseSink");
|
||||
return ScreenRegionManager::GetInstance().ReleaseAllRegions();
|
||||
ScreenRegionManager::GetInstance().ReleaseAllRegions();
|
||||
DHLOGI("exit sink sa process");
|
||||
exit(0);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DScreenSinkService::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m)
|
||||
|
||||
@@ -93,6 +93,8 @@ int32_t DScreenSourceService::ReleaseSource()
|
||||
DHLOGE("UnInit DScreenManager failed. err: %d", ret);
|
||||
return ret;
|
||||
}
|
||||
DHLOGI("exit source sa process");
|
||||
exit(0);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,12 @@ int32_t SoftbusAdapter::RemoveSoftbusSessionServer(const std::string &pkgname, c
|
||||
return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION;
|
||||
}
|
||||
|
||||
int32_t ret = RemoveSessionServer(pkgname.c_str(), sessionName.c_str());
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("%s: RemoveSessionServer failed.", LOG_TAG);
|
||||
return ret;
|
||||
}
|
||||
|
||||
mapSessionSet_[sessionName].erase(peerDevId);
|
||||
if (mapSessionSet_[sessionName].empty()) {
|
||||
mapSessionSet_.erase(sessionName);
|
||||
|
||||
Reference in New Issue
Block a user