From f82a0fd7b59f6a98ef86efe56b225db9a7274f67 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Mon, 30 Oct 2023 20:20:25 +0800 Subject: [PATCH] fix:add privacy info Signed-off-by: chen0088 --- .../constants/dcamera_ipc_interface_code.h | 3 + .../constants/distributed_camera_constants.h | 2 + .../native_cpp/camera_sink/BUILD.gn | 3 + .../include/callback/dcamera_sink_callback.h | 42 +++++++++ .../callback/dcamera_sink_callback_stub.h | 43 +++++++++ .../include/callback/idcamera_sink_callback.h | 37 ++++++++ .../include/dcamera_sink_handler.h | 10 +- .../include/distributed_camera_sink_proxy.h | 7 +- .../include/idistributed_camera_sink.h | 6 +- .../src/callback/dcamera_sink_callback.cpp | 51 ++++++++++ .../callback/dcamera_sink_callback_stub.cpp | 69 ++++++++++++++ .../camera_sink/src/dcamera_sink_handler.cpp | 50 +++++++++- .../src/distributed_camera_sink_proxy.cpp | 84 ++++++++++++++++- .../callback/idcamera_source_callback.h | 6 +- .../client/include/dcamera_client.h | 2 + .../client/include/icamera_operator.h | 2 + .../client/src/dcamera_client.cpp | 20 ++++ services/cameraservice/sinkservice/BUILD.gn | 2 + .../dcamera_sink_callback_proxy.h | 42 +++++++++ .../distributed_camera_sink_service.h | 7 +- .../distributed_camera_sink_stub.h | 5 +- .../dcamera_sink_controller.h | 8 +- .../distributedcameramgr/dcamera_sink_dev.h | 11 ++- .../dcamera_sink_callback_proxy.cpp | 53 +++++++++++ .../distributed_camera_sink_service.cpp | 93 ++++++++++++++++++- .../distributed_camera_sink_stub.cpp | 68 +++++++++++++- .../dcamera_sink_controller.cpp | 50 +++++++++- .../distributedcameramgr/dcamera_sink_dev.cpp | 40 +++++++- services/cameraservice/sourceservice/BUILD.gn | 2 + .../dcamera_source_controller.cpp | 4 + 30 files changed, 798 insertions(+), 24 deletions(-) create mode 100644 interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback.h create mode 100644 interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback_stub.h create mode 100644 interfaces/inner_kits/native_cpp/camera_sink/include/callback/idcamera_sink_callback.h create mode 100644 interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp create mode 100644 interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback_stub.cpp create mode 100644 services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_callback_proxy.h create mode 100644 services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_callback_proxy.cpp diff --git a/common/include/constants/dcamera_ipc_interface_code.h b/common/include/constants/dcamera_ipc_interface_code.h index 659049e7..d18d37dd 100644 --- a/common/include/constants/dcamera_ipc_interface_code.h +++ b/common/include/constants/dcamera_ipc_interface_code.h @@ -40,6 +40,9 @@ enum class IDCameraSinkInterfaceCode : uint32_t { GET_CAMERA_INFO = 6, OPEN_CHANNEL = 7, CLOSE_CHANNEL = 8, + PAUSE_DISTRIBUTED_HARDWARE = 9, + RESUME_DISTRIBUTED_HARDWARE = 10, + STOP_DISTRIBUTED_HARDWARE = 11, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/constants/distributed_camera_constants.h b/common/include/constants/distributed_camera_constants.h index d6ae70c9..e924d526 100644 --- a/common/include/constants/distributed_camera_constants.h +++ b/common/include/constants/distributed_camera_constants.h @@ -43,12 +43,14 @@ typedef enum { typedef enum { DCAMERA_MESSAGE = 0, DCAMERA_OPERATION = 1, + DCAMERA_SINK_STOP = 2, } DCameraEventType; typedef enum { DCAMERA_EVENT_CHANNEL_DISCONNECTED = 0, DCAMERA_EVENT_CHANNEL_CONNECTED = 1, DCAMERA_EVENT_CAMERA_SUCCESS = 2, + DCAMERA_EVENT_SINK_STOP = 3, DCAMERA_EVENT_CAMERA_ERROR = -1, DCAMERA_EVENT_OPEN_CHANNEL_ERROR = -2, diff --git a/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn index e39dec9c..8eee10db 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn @@ -29,11 +29,14 @@ ohos_shared_library("distributed_camera_sink_sdk") { include_dirs += [ "include", + "include/callback", "${common_path}/include/constants", "${common_path}/include/utils", ] sources = [ + "src/callback/dcamera_sink_callback_stub.cpp", + "src/callback/dcamera_sink_callback.cpp", "src/dcamera_sink_handler.cpp", "src/dcamera_sink_handler_ipc.cpp", "src/dcamera_sink_load_callback.cpp", diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback.h b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback.h new file mode 100644 index 00000000..83a07b38 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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_DCAMERA_SINK_CALLBACK_H +#define OHOS_DCAMERA_SINK_CALLBACK_H + +#include +#include + +#include "dcamera_sink_callback_stub.h" +#include "idistributed_hardware_sink.h" + +namespace OHOS { +namespace DistributedHardware { +class DCameraSinkCallback : public DCameraSinkCallbackStub { +public: + DCameraSinkCallback() = default; + ~DCameraSinkCallback() override; + + int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) override; + void PushPrivacyResCallback(const std::shared_ptr &listener); + +private: + std::mutex privacyResMutex_; + std::vector> privacyResCallback_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_SINK_CALLBACK_H diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback_stub.h b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback_stub.h new file mode 100644 index 00000000..576b624b --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback_stub.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 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_DCAMERA_SINK_CALLBACK_STUB_H +#define OHOS_DCAMERA_SINK_CALLBACK_STUB_H + +#include + +#include "iremote_stub.h" +#include "idcamera_sink_callback.h" +#include "refbase.h" +namespace OHOS { class MessageOption; } +namespace OHOS { class MessageParcel; } + +namespace OHOS { +namespace DistributedHardware { +class DCameraSinkCallbackStub : public IRemoteStub { +public: + DCameraSinkCallbackStub(); + virtual ~DCameraSinkCallbackStub(); + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + int32_t OnNotifyResourceInfoInner(MessageParcel &data, MessageParcel &reply); + + using DCameraFunc = int32_t (DCameraSinkCallbackStub::*)(MessageParcel &data, MessageParcel &reply); + std::map memberFuncMap_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_SINK_CALLBACK_STUB_H diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/callback/idcamera_sink_callback.h b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/idcamera_sink_callback.h new file mode 100644 index 00000000..4ac0b62f --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/idcamera_sink_callback.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 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_IDCAMERA_SINK_CALLBACK_H +#define OHOS_IDCAMERA_SINK_CALLBACK_H + +#include "iremote_broker.h" +#include "idistributed_hardware_sink.h" + +namespace OHOS { +namespace DistributedHardware { +class IDCameraSinkCallback : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.dcamerasinkcallback"); + enum { + NOTIFY_RESOURCEINFO = 0, + }; + + virtual ~IDCameraSinkCallback() {} + virtual int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_IDCAMERA_SINK_CALLBACK_H diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/dcamera_sink_handler.h b/interfaces/inner_kits/native_cpp/camera_sink/include/dcamera_sink_handler.h index 782c3cf2..083e2006 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/include/dcamera_sink_handler.h +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/dcamera_sink_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -21,6 +21,7 @@ #include #include "idistributed_hardware_sink.h" +#include "dcamera_sink_callback.h" #include "single_instance.h" namespace OHOS { @@ -32,12 +33,16 @@ public: int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override; int32_t UnsubscribeLocalHardware(const std::string& dhId) override; + int32_t RegisterPrivacyResources(std::shared_ptr listener) override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; private: typedef enum { DCAMERA_SA_STATE_STOP = 0, DCAMERA_SA_STATE_START = 1, } DCameraSAState; - DCameraSinkHandler() = default; + DCameraSinkHandler(); ~DCameraSinkHandler(); void FinishStartSA(const std::string ¶ms); void FinishStartSAFailed(const int32_t systemAbilityId); @@ -46,6 +51,7 @@ private: std::mutex producerMutex_; DCameraSAState state_ = DCAMERA_SA_STATE_STOP; friend class DCameraSinkLoadCallback; + sptr dCameraSinkCallback_ = nullptr; }; #ifdef __cplusplus diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h b/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h index 1f798e94..498a105f 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -32,7 +32,7 @@ public: } ~DistributedCameraSinkProxy() {} - int32_t InitSink(const std::string& params) override; + int32_t InitSink(const std::string& params, const sptr &sinkCallback) override; int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override; int32_t UnsubscribeLocalHardware(const std::string& dhId) override; @@ -41,6 +41,9 @@ public: int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) override; int32_t OpenChannel(const std::string& dhId, std::string& openInfo) override; int32_t CloseChannel(const std::string& dhId) override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; private: static inline BrokerDelegator delegator_; diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h b/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h index 8fd8b1a3..34ad3389 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h @@ -16,6 +16,7 @@ #ifndef OHOS_IDISTRIBUTED_CAMERA_SINK_H #define OHOS_IDISTRIBUTED_CAMERA_SINK_H +#include "idcamera_sink_callback.h" #include "iremote_broker.h" namespace OHOS { @@ -26,7 +27,7 @@ public: IDistributedCameraSink() = default; virtual ~IDistributedCameraSink() = default; - virtual int32_t InitSink(const std::string& params) = 0; + virtual int32_t InitSink(const std::string& params, const sptr &sinkCallback) = 0; virtual int32_t ReleaseSink() = 0; virtual int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) = 0; virtual int32_t UnsubscribeLocalHardware(const std::string& dhId) = 0; @@ -35,6 +36,9 @@ public: virtual int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) = 0; virtual int32_t OpenChannel(const std::string& dhId, std::string& openInfo) = 0; virtual int32_t CloseChannel(const std::string& dhId) = 0; + virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; + virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; + virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp new file mode 100644 index 00000000..127c270e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 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 "dcamera_sink_callback.h" + +#include "anonymous_string.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +DCameraSinkCallback::~DCameraSinkCallback() +{ + privacyResCallback_.clear(); +} + +int32_t DCameraSinkCallback::OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) +{ + DHLOGI("DCameraSinkCallback OnNotifyResourceInfo type: %d, subType: %s, networkId: %s, " + "isSensitive: %d, isSameAccout: %d", (uint32_t)type, subType.c_str(), + GetAnonyString(networkId).c_str(), isSensitive, isSameAccout); + int32_t ret = DCAMERA_OK; + std::lock_guard lock(privacyResMutex_); + auto iter = privacyResCallback_.begin(); + if (iter != privacyResCallback_.end()) { + ret = (*iter)->OnPrivaceResourceMessage(type, subType, networkId, isSensitive, isSameAccout); + } + return ret; +} + +void DCameraSinkCallback::PushPrivacyResCallback(const std::shared_ptr &listener) +{ + DHLOGI("push resource info callback."); + std::lock_guard lock(privacyResMutex_); + privacyResCallback_.push_back(listener); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback_stub.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback_stub.cpp new file mode 100644 index 00000000..e6526c0d --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback_stub.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 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 "dcamera_sink_callback_stub.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" +#include "ipc_object_stub.h" +#include "ipc_types.h" +#include "message_parcel.h" +namespace OHOS { class MessageOption; } + +namespace OHOS { +namespace DistributedHardware { +DCameraSinkCallbackStub::DCameraSinkCallbackStub() +{ + memberFuncMap_[NOTIFY_RESOURCEINFO] = &DCameraSinkCallbackStub::OnNotifyResourceInfoInner; +} + +DCameraSinkCallbackStub::~DCameraSinkCallbackStub() +{} + +int32_t DCameraSinkCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + DHLOGI("DCameraSinkCallbackStub OnRemoteRequest code: %d", code); + std::u16string desc = DCameraSinkCallbackStub::GetDescriptor(); + std::u16string remoteDesc = data.ReadInterfaceToken(); + if (desc != remoteDesc) { + DHLOGE("remoteDesc is invalid!"); + return ERR_INVALID_DATA; + } + auto itFunc = memberFuncMap_.find(code); + if (itFunc == memberFuncMap_.end()) { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + auto memberFunc = itFunc->second; + return (this->*memberFunc)(data, reply); +} + +int32_t DCameraSinkCallbackStub::OnNotifyResourceInfoInner(MessageParcel &data, MessageParcel &reply) +{ + DHLOGI("DCameraSinkCallbackStub OnNotifyResourceInfoInner"); + int32_t ret = DCAMERA_OK; + do { + ResourceEventType type = static_cast(data.ReadInt32()); + std::string subType = data.ReadString(); + std::string networkId = data.ReadString(); + bool isSensitive = data.ReadBool(); + bool isSameAccout = data.ReadBool(); + ret = OnNotifyResourceInfo(type, subType, networkId, isSensitive, isSameAccout); + } while (0); + reply.WriteInt32(ret); + return DCAMERA_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler.cpp index 2e1a622d..496147ea 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler.cpp +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler.cpp @@ -36,6 +36,14 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DCameraSinkHandler); +DCameraSinkHandler::DCameraSinkHandler() +{ + DHLOGI("DCameraSinkHandler ctor."); + if (!dCameraSinkCallback_) { + dCameraSinkCallback_ = new DCameraSinkCallback(); + } +} + DCameraSinkHandler::~DCameraSinkHandler() { DHLOGI("~DCameraSinkHandler"); @@ -86,7 +94,7 @@ void DCameraSinkHandler::FinishStartSA(const std::string& params) DHLOGE("get Service failed"); return; } - dCameraSinkSrv->InitSink(params); + dCameraSinkSrv->InitSink(params, dCameraSinkCallback_); std::unique_lock lock(producerMutex_); state_ = DCAMERA_SA_STATE_START; producerCon_.notify_one(); @@ -150,5 +158,45 @@ IDistributedHardwareSink *GetSinkHardwareHandler() DHLOGI("DCameraSinkHandler::GetSinkHardwareHandler"); return &DCameraSinkHandler::GetInstance(); } + +int32_t DCameraSinkHandler::RegisterPrivacyResources(std::shared_ptr listener) +{ + DHLOGI("RegisterPrivacyResources start."); + dCameraSinkCallback_->PushPrivacyResCallback(listener); + return DCAMERA_OK; +} + +int32_t DCameraSinkHandler::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("pause distributed hardware."); + sptr dCameraSinkSrv = DCameraSinkHandlerIpc::GetInstance().GetSinkLocalCamSrv(); + if (dCameraSinkSrv == nullptr) { + DHLOGE("get Service failed"); + return DCAMERA_BAD_VALUE; + } + return dCameraSinkSrv->PauseDistributedHardware(networkId); +} + +int32_t DCameraSinkHandler::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("resume distributed hardware."); + sptr dCameraSinkSrv = DCameraSinkHandlerIpc::GetInstance().GetSinkLocalCamSrv(); + if (dCameraSinkSrv == nullptr) { + DHLOGE("get Service failed"); + return DCAMERA_BAD_VALUE; + } + return dCameraSinkSrv->ResumeDistributedHardware(networkId); +} + +int32_t DCameraSinkHandler::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("stop distributed hardware."); + sptr dCameraSinkSrv = DCameraSinkHandlerIpc::GetInstance().GetSinkLocalCamSrv(); + if (dCameraSinkSrv == nullptr) { + DHLOGE("get Service failed"); + return DCAMERA_BAD_VALUE; + } + return dCameraSinkSrv->StopDistributedHardware(networkId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp index eaca8b0d..35a86f83 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace DistributedHardware { -int32_t DistributedCameraSinkProxy::InitSink(const std::string& params) +int32_t DistributedCameraSinkProxy::InitSink(const std::string& params, const sptr &sinkCallback) { DHLOGI("start"); if (params.empty() || params.size() > PARAM_MAX_SIZE) { @@ -48,6 +48,10 @@ int32_t DistributedCameraSinkProxy::InitSink(const std::string& params) DHLOGE("write params failed"); return DCAMERA_BAD_VALUE; } + if (!data.WriteRemoteObject(sinkCallback->AsObject())) { + DHLOGE("write sinkCallback failed"); + return DCAMERA_BAD_VALUE; + } remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::INIT_SINK), data, reply, option); int32_t result = reply.ReadInt32(); return result; @@ -282,5 +286,83 @@ int32_t DistributedCameraSinkProxy::CloseChannel(const std::string& dhId) int32_t result = reply.ReadInt32(); return result; } + +int32_t DistributedCameraSinkProxy::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("networkId: %s", GetAnonyString(networkId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("remote service is null"); + return DCAMERA_BAD_VALUE; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { + DHLOGE("write token failed"); + return DCAMERA_BAD_VALUE; + } + if (!data.WriteString(networkId)) { + DHLOGE("write params failed"); + return DCAMERA_BAD_VALUE; + } + remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t result = reply.ReadInt32(); + return result; +} + +int32_t DistributedCameraSinkProxy::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("networkId: %s", GetAnonyString(networkId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("remote service is null"); + return DCAMERA_BAD_VALUE; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { + DHLOGE("write token failed"); + return DCAMERA_BAD_VALUE; + } + if (!data.WriteString(networkId)) { + DHLOGE("write params failed"); + return DCAMERA_BAD_VALUE; + } + remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t result = reply.ReadInt32(); + return result; +} + +int32_t DistributedCameraSinkProxy::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("networkId: %s", GetAnonyString(networkId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("remote service is null"); + return DCAMERA_BAD_VALUE; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { + DHLOGE("write token failed"); + return DCAMERA_BAD_VALUE; + } + if (!data.WriteString(networkId)) { + DHLOGE("write params failed"); + return DCAMERA_BAD_VALUE; + } + remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::STOP_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t result = reply.ReadInt32(); + return result; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/camera_source/include/callback/idcamera_source_callback.h b/interfaces/inner_kits/native_cpp/camera_source/include/callback/idcamera_source_callback.h index 00325e84..02ffc914 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/include/callback/idcamera_source_callback.h +++ b/interfaces/inner_kits/native_cpp/camera_source/include/callback/idcamera_source_callback.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_IDCAMERA_SOURCE_CALLBACL_H -#define OHOS_IDCAMERA_SOURCE_CALLBACL_H +#ifndef OHOS_IDCAMERA_SOURCE_CALLBACK_H +#define OHOS_IDCAMERA_SOURCE_CALLBACK_H #include "iremote_broker.h" @@ -36,4 +36,4 @@ public: }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_IDCAMERA_SOURCE_CALLBACL_H +#endif // OHOS_IDCAMERA_SOURCE_CALLBACK_H diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index f49dd905..e52799fb 100644 --- a/services/cameraservice/cameraoperator/client/include/dcamera_client.h +++ b/services/cameraservice/cameraoperator/client/include/dcamera_client.h @@ -47,6 +47,8 @@ public: int32_t StopCapture() override; int32_t SetStateCallback(std::shared_ptr& callback) override; int32_t SetResultCallback(std::shared_ptr& callback) override; + int32_t PauseCapture() override; + int32_t ResumeCapture() override; private: int32_t ConfigCaptureSession(std::vector>& captureInfos); diff --git a/services/cameraservice/cameraoperator/client/include/icamera_operator.h b/services/cameraservice/cameraoperator/client/include/icamera_operator.h index e5d33b7b..6540a455 100644 --- a/services/cameraservice/cameraoperator/client/include/icamera_operator.h +++ b/services/cameraservice/cameraoperator/client/include/icamera_operator.h @@ -62,6 +62,8 @@ public: virtual int32_t StopCapture() = 0; virtual int32_t SetStateCallback(std::shared_ptr& callback) = 0; virtual int32_t SetResultCallback(std::shared_ptr& callback) = 0; + virtual int32_t PauseCapture() = 0; + virtual int32_t ResumeCapture() = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index 0dd1becd..38e7a961 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -645,5 +645,25 @@ void DCameraClient::SetPhotoCaptureLocation(const std::shared_ptrStop(); + if (ret != DCAMERA_OK) { + DHLOGE("PauseCapture captureSession stop failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } + return ret; +} + +int32_t DCameraClient::ResumeCapture() +{ + int32_t ret = captureSession_->Start(); + if (ret != DCAMERA_OK) { + DHLOGE("ResumeCapture captureSession Start failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } + return ret; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index 38ec8431..ba75ff40 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -53,6 +53,7 @@ ohos_shared_library("distributed_camera_sink") { "${common_path}/include/constants", "${common_path}/include/utils", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${innerkits_path}/native_cpp/camera_source/include", "${innerkits_path}/native_cpp/camera_source/include/callback", "${services_path}/cameraservice/base/include", @@ -80,6 +81,7 @@ ohos_shared_library("distributed_camera_sink") { "${services_path}/cameraservice/base/src/dcamera_info_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_open_info_cmd.cpp", + "src/distributedcamera/dcamera_sink_callback_proxy.cpp", "src/distributedcamera/dcamera_sink_hidumper.cpp", "src/distributedcamera/distributed_camera_sink_service.cpp", "src/distributedcamera/distributed_camera_sink_stub.cpp", diff --git a/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_callback_proxy.h b/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_callback_proxy.h new file mode 100644 index 00000000..abc7b7e9 --- /dev/null +++ b/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_callback_proxy.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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_DCAMERA_SINK_CALLBACK_PROXY_H +#define OHOS_DCAMERA_SINK_CALLBACK_PROXY_H +#include + +#include "iremote_proxy.h" +#include "iremote_broker.h" +#include "refbase.h" + +#include "idcamera_sink_callback.h" + +namespace OHOS { +namespace DistributedHardware { +class DCameraSinkCallbackProxy : public IRemoteProxy { +public: + explicit DCameraSinkCallbackProxy(const sptr &impl) : IRemoteProxy(impl) + {} + ~DCameraSinkCallbackProxy() + {} + + int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_SINK_CALLBACK_PROXY_H diff --git a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h index 67a0f5fb..601ef5be 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h @@ -34,7 +34,7 @@ public: DistributedCameraSinkService(int32_t saId, bool runOnCreate); ~DistributedCameraSinkService() override = default; - int32_t InitSink(const std::string& params) override; + int32_t InitSink(const std::string& params, const sptr &sinkCallback) override; int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override; int32_t UnsubscribeLocalHardware(const std::string& dhId) override; @@ -45,6 +45,9 @@ public: int32_t CloseChannel(const std::string& dhId) override; int Dump(int32_t fd, const std::vector& args) override; static void GetCamDumpInfo(CameraDumpInfo& camDump); + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; protected: void OnStart() override; @@ -52,6 +55,8 @@ protected: DISALLOW_COPY_AND_MOVE(DistributedCameraSinkService); private: + bool IsCurSinkDev(std::shared_ptr sinkDevice); + bool Init(); void GetCamIds(); bool registerToService_ = false; diff --git a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h index b2c2d1eb..0eeed77a 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -39,6 +39,9 @@ private: int32_t GetCameraInfoInner(MessageParcel &data, MessageParcel &reply); int32_t OpenChannelInner(MessageParcel &data, MessageParcel &reply); int32_t CloseChannelInner(MessageParcel &data, MessageParcel &reply); + int32_t PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); + int32_t ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); + int32_t StopDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); using DCameraFunc = int32_t (DistributedCameraSinkStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h index 870f53a2..07a348f7 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h @@ -28,6 +28,7 @@ #include #include "property_carrier.h" +#include "idcamera_sink_callback.h" namespace OHOS { namespace DistributedHardware { @@ -36,7 +37,8 @@ class DCameraSinkController : public ICameraController, public EventSender, public DistributedHardware::EventBusHandler, public std::enable_shared_from_this { public: - explicit DCameraSinkController(std::shared_ptr& accessControl); + explicit DCameraSinkController(std::shared_ptr& accessControl, + const sptr &sinkCallback); ~DCameraSinkController() override; int32_t StartCapture(std::vector>& captureInfos) override; @@ -49,6 +51,9 @@ public: int32_t CloseChannel() override; int32_t Init(std::vector& indexs) override; int32_t UnInit() override; + int32_t PauseDistributedHardware(const std::string &networkId); + int32_t ResumeDistributedHardware(const std::string &networkId); + int32_t StopDistributedHardware(const std::string &networkId); void OnEvent(DCameraFrameTriggerEvent& event) override; void OnEvent(DCameraPostAuthorizationEvent& event) override; @@ -78,6 +83,7 @@ private: std::shared_ptr operator_; std::shared_ptr accessControl_; std::shared_ptr output_; + sptr sinkCallback_; const std::string SESSION_FLAG = "control"; const std::string SRC_TYPE = "camera"; diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h index 79721f53..2c8dec07 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h @@ -20,14 +20,15 @@ #include #include -#include "icamera_controller.h" +#include "dcamera_sink_controller.h" #include "icamera_sink_access_control.h" +#include "idcamera_sink_callback.h" namespace OHOS { namespace DistributedHardware { class DCameraSinkDev { public: - explicit DCameraSinkDev(const std::string& dhId); + explicit DCameraSinkDev(const std::string& dhId, const sptr &sinkCallback); ~DCameraSinkDev(); int32_t Init(); @@ -40,12 +41,16 @@ public: int32_t OpenChannel(std::string& openInfo); int32_t CloseChannel(); std::string GetDhid(); + int32_t PauseDistributedHardware(const std::string &networkId); + int32_t ResumeDistributedHardware(const std::string &networkId); + int32_t StopDistributedHardware(const std::string &networkId); private: bool isInit_; std::string dhId_; - std::shared_ptr controller_; + std::shared_ptr controller_; std::shared_ptr accessControl_; + sptr sinkCallback_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_callback_proxy.cpp b/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_callback_proxy.cpp new file mode 100644 index 00000000..ac3ed1a3 --- /dev/null +++ b/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_callback_proxy.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 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 "dcamera_sink_callback_proxy.h" + +#include "parcel.h" + +#include "anonymous_string.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t DCameraSinkCallbackProxy::OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) +{ + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DCameraSinkCallbackProxy remote service null"); + return DCAMERA_BAD_VALUE; + } + MessageParcel req; + MessageParcel reply; + MessageOption option; + if (!req.WriteInterfaceToken(DCameraSinkCallbackProxy::GetDescriptor())) { + DHLOGE("write token failed"); + return DCAMERA_BAD_VALUE; + } + + int32_t resType = static_cast(type); + if (!req.WriteInt32(resType) || !req.WriteString(subType) || !req.WriteString(networkId) || + !req.WriteBool(isSensitive) || !req.WriteBool(isSameAccout)) { + DHLOGE("DCameraSinkCallbackProxy InitSink write params failed"); + return DCAMERA_BAD_VALUE; + } + remote->SendRequest(NOTIFY_RESOURCEINFO, req, reply, option); + int32_t result = reply.ReadInt32(); + return result; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp index 54aec91c..5010c572 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp @@ -15,6 +15,7 @@ #include "distributed_camera_sink_service.h" +#include "icamera_channel_listener.h" #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "ipc_types.h" @@ -81,7 +82,8 @@ void DistributedCameraSinkService::OnStop() DCameraSinkServiceIpc::GetInstance().UnInit(); } -int32_t DistributedCameraSinkService::InitSink(const std::string& params) +int32_t DistributedCameraSinkService::InitSink(const std::string& params, + const sptr &sinkCallback) { DHLOGI("start"); sinkVer_ = params; @@ -99,7 +101,7 @@ int32_t DistributedCameraSinkService::InitSink(const std::string& params) } g_camDump.camNumber = static_cast(cameras.size()); for (auto& dhId : cameras) { - std::shared_ptr sinkDevice = std::make_shared(dhId); + std::shared_ptr sinkDevice = std::make_shared(dhId, sinkCallback); ret = sinkDevice->Init(); if (ret != DCAMERA_OK) { DHLOGE("sink device init failed, ret: %d", ret); @@ -350,5 +352,92 @@ void DistributedCameraSinkService::GetCamDumpInfo(CameraDumpInfo& camDump) dcSinkService->GetCamIds(); camDump = g_camDump; } + +bool DistributedCameraSinkService::IsCurSinkDev(std::shared_ptr sinkDevice) +{ + std::string camInfoJson; + int32_t ret = sinkDevice->GetCameraInfo(camInfoJson); + if (ret != DCAMERA_OK) { + DHLOGE("GetCameraInfo failed, ret: %d", ret); + return false; + } + DCameraInfoCmd cmd; + ret = cmd.Unmarshal(camInfoJson); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraInfoCmd Unmarshal failed: %d", ret); + return false; + } + std::shared_ptr camInfo = cmd.value_; + if (camInfo->state_ == DCAMERA_CHANNEL_STATE_CONNECTED) { + return true; + } + return false; +} + +int32_t DistributedCameraSinkService::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("start."); + std::shared_ptr sinkDevice = nullptr; + { + std::lock_guard lock(mapMutex_); + for (auto iter = camerasMap_.begin(); iter != camerasMap_.end(); iter++) { + if (IsCurSinkDev(iter->second)) { + sinkDevice = iter->second; + } + } + } + + int32_t ret = sinkDevice->PauseDistributedHardware(networkId); + if (ret != DCAMERA_OK) { + DHLOGE("PauseDistributedHardware failed, ret: %d", ret); + return ret; + } + DHLOGI("PauseDistributedHardware success"); + return DCAMERA_OK; +} + +int32_t DistributedCameraSinkService::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("start."); + std::shared_ptr sinkDevice = nullptr; + { + std::lock_guard lock(mapMutex_); + for (auto iter = camerasMap_.begin(); iter != camerasMap_.end(); iter++) { + if (IsCurSinkDev(iter->second)) { + sinkDevice = iter->second; + } + } + } + + int32_t ret = sinkDevice->ResumeDistributedHardware(networkId); + if (ret != DCAMERA_OK) { + DHLOGE("ResumeDistributedHardware failed, ret: %d", ret); + return ret; + } + DHLOGI("ResumeDistributedHardware success"); + return DCAMERA_OK; +} + +int32_t DistributedCameraSinkService::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("start."); + std::shared_ptr sinkDevice = nullptr; + { + std::lock_guard lock(mapMutex_); + for (auto iter = camerasMap_.begin(); iter != camerasMap_.end(); iter++) { + if (IsCurSinkDev(iter->second)) { + sinkDevice = iter->second; + } + } + } + + int32_t ret = sinkDevice->StopDistributedHardware(networkId); + if (ret != DCAMERA_OK) { + DHLOGE("StopDistributedHardware failed, ret: %d", ret); + return ret; + } + DHLOGI("StopDistributedHardware success"); + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp index a0ec2d08..82c76868 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp @@ -17,6 +17,7 @@ #include "distributed_camera_sink_stub.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" +#include "dcamera_sink_callback_proxy.h" namespace OHOS { namespace DistributedHardware { @@ -40,6 +41,12 @@ DistributedCameraSinkStub::DistributedCameraSinkStub() &DistributedCameraSinkStub::OpenChannelInner; memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::CLOSE_CHANNEL)] = &DistributedCameraSinkStub::CloseChannelInner; + memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE)] = + &DistributedCameraSinkStub::PauseDistributedHardwareInner; + memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE)] = + &DistributedCameraSinkStub::ResumeDistributedHardwareInner; + memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::STOP_DISTRIBUTED_HARDWARE)] = + &DistributedCameraSinkStub::StopDistributedHardwareInner; } DistributedCameraSinkStub::~DistributedCameraSinkStub() @@ -75,7 +82,15 @@ int32_t DistributedCameraSinkStub::InitSinkInner(MessageParcel &data, MessagePar ret = DCAMERA_BAD_VALUE; break; } - ret = InitSink(params); + sptr remoteObject = data.ReadRemoteObject(); + if (remoteObject == nullptr) { + DHLOGE("Read ReadRemoteObject failed."); + ret = DCAMERA_BAD_VALUE; + break; + } + + sptr dCameraSinkCallbackProxy(new DCameraSinkCallbackProxy(remoteObject)); + ret = InitSink(params, dCameraSinkCallbackProxy); } while (0); reply.WriteInt32(ret); return DCAMERA_OK; @@ -214,5 +229,56 @@ int32_t DistributedCameraSinkStub::CloseChannelInner(MessageParcel &data, Messag reply.WriteInt32(ret); return DCAMERA_OK; } + +int32_t DistributedCameraSinkStub::PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) +{ + DHLOGD("enter"); + int32_t ret = DCAMERA_OK; + do { + std::string networkId = data.ReadString(); + if (networkId.empty() || networkId.size() > DID_MAX_SIZE) { + DHLOGE("params is invalid"); + ret = DCAMERA_BAD_VALUE; + break; + } + ret = PauseDistributedHardware(networkId); + } while (0); + reply.WriteInt32(ret); + return DCAMERA_OK; +} + +int32_t DistributedCameraSinkStub::ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) +{ + DHLOGD("enter"); + int32_t ret = DCAMERA_OK; + do { + std::string networkId = data.ReadString(); + if (networkId.empty() || networkId.size() > DID_MAX_SIZE) { + DHLOGE("params is invalid"); + ret = DCAMERA_BAD_VALUE; + break; + } + ret = ResumeDistributedHardware(networkId); + } while (0); + reply.WriteInt32(ret); + return DCAMERA_OK; +} + +int32_t DistributedCameraSinkStub::StopDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) +{ + DHLOGD("enter"); + int32_t ret = DCAMERA_OK; + do { + std::string networkId = data.ReadString(); + if (networkId.empty() || networkId.size() > DID_MAX_SIZE) { + DHLOGE("params is invalid"); + ret = DCAMERA_BAD_VALUE; + break; + } + ret = StopDistributedHardware(networkId); + } while (0); + reply.WriteInt32(ret); + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp index e31473f7..f69722fc 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp @@ -41,8 +41,10 @@ namespace OHOS { namespace DistributedHardware { -DCameraSinkController::DCameraSinkController(std::shared_ptr& accessControl) - : isInit_(false), sessionState_(DCAMERA_CHANNEL_STATE_DISCONNECTED), accessControl_(accessControl) +DCameraSinkController::DCameraSinkController(std::shared_ptr& accessControl, + const sptr &sinkCallback) + : isInit_(false), sessionState_(DCAMERA_CHANNEL_STATE_DISCONNECTED), accessControl_(accessControl), + sinkCallback_(sinkCallback) { } @@ -441,6 +443,11 @@ int32_t DCameraSinkController::StartCaptureInner(std::vectorOnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_PULL_UP_PAGE, subType, srcDevId_, + isSensitive, isSameAccout); DHLOGI("DCameraSinkController::StartCaptureInner %s success", GetAnonyString(dhId_).c_str()); return DCAMERA_OK; } @@ -496,5 +503,44 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr& d } return DCAMERA_BAD_VALUE; } + +int32_t DCameraSinkController::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("Pause distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + int32_t ret = operator_->PauseCapture(); + if (ret != DCAMERA_OK) { + DHLOGE("Pause distributed hardware failed, dhId: %s, ret: %d", GetAnonyString(dhId_).c_str(), ret); + } + return ret; +} + +int32_t DCameraSinkController::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("Resume distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + int32_t ret = operator_->ResumeCapture(); + if (ret != DCAMERA_OK) { + DHLOGE("Resume distributed hardware failed, dhId: %s, ret: %d", GetAnonyString(dhId_).c_str(), ret); + } + return ret; +} + +int32_t DCameraSinkController::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("Stop distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + + return DCameraNotifyInner(DCAMERA_SINK_STOP, DCAMERA_EVENT_SINK_STOP, std::string("sink stop dcamera business")); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp index 01eaa305..2d190a4c 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -26,7 +26,8 @@ namespace OHOS { namespace DistributedHardware { -DCameraSinkDev::DCameraSinkDev(const std::string& dhId) : dhId_(dhId) +DCameraSinkDev::DCameraSinkDev(const std::string& dhId, const sptr &sinkCallback) : + dhId_(dhId), sinkCallback_(sinkCallback) { DHLOGI("DCameraSinkDev Constructor dhId: %s", GetAnonyString(dhId_).c_str()); isInit_ = false; @@ -43,7 +44,7 @@ int32_t DCameraSinkDev::Init() { DHLOGI("Init dhId: %s", GetAnonyString(dhId_).c_str()); accessControl_ = std::make_shared(); - controller_ = std::make_shared(accessControl_); + controller_ = std::make_shared(accessControl_, sinkCallback_); DCameraIndex index("", dhId_); std::vector indexs; indexs.push_back(index); @@ -159,5 +160,38 @@ std::string DCameraSinkDev::GetDhid() { return GetAnonyString(dhId_); } + +int32_t DCameraSinkDev::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("Pause distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + + return controller_->PauseDistributedHardware(networkId); +} + +int32_t DCameraSinkDev::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("Pause distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + + return controller_->ResumeDistributedHardware(networkId); +} + +int32_t DCameraSinkDev::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("Pause distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + + return controller_->StopDistributedHardware(networkId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 6f0c82e5..61da8e3c 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -51,6 +51,7 @@ ohos_shared_library("distributed_camera_source") { "${common_path}/include/utils", "${innerkits_path}/native_cpp/camera_source/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${innerkits_path}/native_cpp/camera_source/include/callback", "${services_path}/cameraservice/base/include", "${services_path}/channel/include", @@ -105,6 +106,7 @@ ohos_shared_library("distributed_camera_source") { deps = [ "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", "${services_path}/channel:distributed_camera_channel", "${services_path}/data_process:distributed_camera_data_process", "//third_party/cJSON:cjson", diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp index 432d8d33..0cfdaa5f 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp @@ -180,6 +180,10 @@ int32_t DCameraSourceController::DCameraNotify(std::shared_ptr& ev DHBase dhBase; dhBase.deviceId_ = devId_; dhBase.dhId_ = dhId_; + if (events->eventType_ == DCAMERA_SINK_STOP && events->eventResult_ == DCAMERA_EVENT_SINK_STOP) { + events->eventType_ = DCAMERA_OPERATION; + events->eventResult_ = DCAMERA_EVENT_DEVICE_ERROR; + } DCameraHDFEvent hdiEvent; hdiEvent.type_ = events->eventType_; hdiEvent.result_ = events->eventResult_; -- Gitee