• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_DCAMERA_SINK_CONTROLLER_H
17 #define OHOS_DCAMERA_SINK_CONTROLLER_H
18 
19 #include "event_bus.h"
20 #include "dcamera_frame_trigger_event.h"
21 #include "dcamera_post_authorization_event.h"
22 #include "icamera_controller.h"
23 
24 #include "icamera_channel.h"
25 #include "icamera_operator.h"
26 #include "icamera_sink_access_control.h"
27 #include "icamera_sink_output.h"
28 #include <mutex>
29 #include <atomic>
30 #include "device_manager.h"
31 #include "device_manager_callback.h"
32 #include "property_carrier.h"
33 #include "idcamera_sink_callback.h"
34 
35 namespace OHOS {
36 namespace DistributedHardware {
37 class DCameraSinkController : public ICameraController, public EventSender,
38     public DistributedHardware::EventBusHandler<DCameraFrameTriggerEvent>,
39     public DistributedHardware::EventBusHandler<DCameraPostAuthorizationEvent>,
40     public std::enable_shared_from_this<DCameraSinkController> {
41 public:
42     explicit DCameraSinkController(std::shared_ptr<ICameraSinkAccessControl>& accessControl,
43         const sptr<IDCameraSinkCallback> &sinkCallback);
44     ~DCameraSinkController() override;
45 
46     int32_t StartCapture(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos) override;
47     int32_t StopCapture() override;
48     int32_t ChannelNeg(std::shared_ptr<DCameraChannelInfo>& info) override;
49     int32_t DCameraNotify(std::shared_ptr<DCameraEvent>& events) override;
50     int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings) override;
51     int32_t GetCameraInfo(std::shared_ptr<DCameraInfo>& camInfo) override;
52     int32_t OpenChannel(std::shared_ptr<DCameraOpenInfo>& openInfo) override;
53     int32_t CloseChannel() override;
54     int32_t Init(std::vector<DCameraIndex>& indexs) override;
55     int32_t UnInit() override;
56     int32_t PauseDistributedHardware(const std::string &networkId) override;
57     int32_t ResumeDistributedHardware(const std::string &networkId) override;
58     int32_t StopDistributedHardware(const std::string &networkId) override;
59 
60     void OnEvent(DCameraFrameTriggerEvent& event) override;
61     void OnEvent(DCameraPostAuthorizationEvent& event) override;
62 
63     void OnStateChanged(std::shared_ptr<DCameraEvent>& event);
64     void OnMetadataResult(std::vector<std::shared_ptr<DCameraSettings>>& settings);
65 
66     void OnSessionState(int32_t state);
67     void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail);
68     void OnDataReceived(std::vector<std::shared_ptr<DataBuffer>>& buffers);
69 
70 private:
71     int32_t StartCaptureInner(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos);
72     int32_t DCameraNotifyInner(int32_t type, int32_t result, std::string content);
73     int32_t HandleReceivedData(std::shared_ptr<DataBuffer>& dataBuffer);
74     void PostAuthorization(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos);
75     bool CheckDeviceSecurityLevel(const std::string &srcDeviceId, const std::string &dstDeviceId);
76     int32_t GetDeviceSecurityLevel(const std::string &udid);
77     std::string GetUdidByNetworkId(const std::string &networkId);
78     int32_t PullUpPage();
79     bool CheckPermission();
80 
81     bool isInit_;
82     int32_t sessionState_;
83     std::mutex autoLock_;
84     std::mutex captureLock_;
85     std::mutex channelLock_;
86     std::string dhId_;
87     std::string srcDevId_;
88     std::shared_ptr<EventBus> eventBus_;
89     std::shared_ptr<ICameraChannel> channel_;
90     std::shared_ptr<ICameraOperator> operator_;
91     std::shared_ptr<ICameraSinkAccessControl> accessControl_;
92     std::shared_ptr<ICameraSinkOutput> output_;
93     sptr<IDCameraSinkCallback> sinkCallback_;
94     std::atomic<bool> isPageStatus_ = false;
95     std::shared_ptr<DmInitCallback> initCallback_;
96     bool isSensitive_;
97     bool isSameAccount_;
98 
99     const std::string SESSION_FLAG = "control";
100     const std::string SRC_TYPE = "camera";
101     const size_t DATABUFF_MAX_SIZE = 100 * 1024 * 1024;
102 };
103 
104 class DeviceInitCallback : public DmInitCallback {
105     void OnRemoteDied() override;
106 };
107 } // namespace DistributedHardware
108 } // namespace OHOS
109 #endif // OHOS_DCAMERA_SINK_CONTROLLER_H