• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_SOURCE_CONTROLLER_H
17 #define OHOS_DCAMERA_SOURCE_CONTROLLER_H
18 
19 #include "icamera_controller.h"
20 
21 #include "dcamera_index.h"
22 #include "icamera_channel_listener.h"
23 #include "dcamera_source_dev.h"
24 #include "dcamera_source_state_machine.h"
25 #include "icamera_channel.h"
26 #include "iremote_object.h"
27 #include "device_manager.h"
28 #include "camera_service_proxy.h"
29 
30 #include "v1_1/id_camera_provider.h"
31 
32 namespace OHOS {
33 namespace DistributedHardware {
34 class DCameraSourceController : public ICameraController,
35     public std::enable_shared_from_this<DCameraSourceController> {
36 public:
37     DCameraSourceController(std::string devId, std::string dhId,
38         std::shared_ptr<DCameraSourceStateMachine>& stateMachine, std::shared_ptr<DCameraSourceDev>& camDev);
39     ~DCameraSourceController() override;
40     int32_t StartCapture(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos, int32_t sceneMode) override;
41     int32_t StopCapture() override;
42     int32_t ChannelNeg(std::shared_ptr<DCameraChannelInfo>& info) override;
43     int32_t DCameraNotify(std::shared_ptr<DCameraEvent>& events) override;
44     int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings) override;
45     int32_t GetCameraInfo(std::shared_ptr<DCameraInfo>& camInfo) override;
46     int32_t OpenChannel(std::shared_ptr<DCameraOpenInfo>& openInfo) override;
47     int32_t CloseChannel() override;
48     int32_t Init(std::vector<DCameraIndex>& indexs) override;
49     int32_t UnInit() override;
50     int32_t PauseDistributedHardware(const std::string &networkId) override;
51     int32_t ResumeDistributedHardware(const std::string &networkId) override;
52     int32_t StopDistributedHardware(const std::string &networkId) override;
53     void SetTokenId(uint64_t token) override;
54 
55     void OnSessionState(int32_t state, std::string networkId);
56     void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail);
57     void OnDataReceived(std::vector<std::shared_ptr<DataBuffer>>& buffers);
58 
59 private:
60     void HandleMetaDataResult(std::string& jsonStr);
61     void PostChannelDisconnectedEvent();
62     int32_t PublishEnableLatencyMsg(const std::string& devId);
63     void HandleReceivedData(std::shared_ptr<DataBuffer> &dataBuffer);
64     bool CheckAclRight();
65     bool GetOsAccountInfo();
66     int32_t CheckOsType(const std::string &networkId, bool &isInvalid);
67     int32_t ParseValueFromCjson(std::string args, std::string key);
68     int32_t AddCameraServiceDeathRecipient();
69     class DCameraHdiRecipient : public IRemoteObject::DeathRecipient {
70     public:
71         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
72     };
73     sptr<DCameraHdiRecipient> cameraHdiRecipient_;
74     class CameraServiceRecipient : public IRemoteObject::DeathRecipient {
75     public:
76         CameraServiceRecipient(std::shared_ptr<DCameraSourceController> sourceContrlPtr);
77         ~CameraServiceRecipient() override = default;
78         void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
79 
80     private:
81         std::weak_ptr<DCameraSourceController> sourceContrlPtr_;
82     };
83     sptr<CameraServiceRecipient> cameraServiceRecipient_;
84 
85 private:
86     std::string devId_;
87     std::string dhId_;
88     std::shared_ptr<ICameraChannel> channel_;
89     std::shared_ptr<ICameraChannelListener> listener_;
90     std::vector<DCameraIndex> indexs_;
91     std::shared_ptr<DCameraSourceStateMachine> stateMachine_;
92     std::weak_ptr<DCameraSourceDev> camDev_;
93     int32_t channelState_;
94     sptr<IDCameraProvider> camHdiProvider_;
95     sptr<IRemoteObject> remote_;
96     sptr<CameraStandard::ICameraService> cameraServiceProxy_;
97     std::shared_ptr<DCameraSourceController> controller_;
98 
99     bool isInit;
100     const std::string SESSION_FLAG = "control";
101 
102     static constexpr uint8_t CHANNEL_REL_SECONDS = 5;
103     const size_t DATABUFF_MAX_SIZE = 100 * 1024 * 1024;
104     std::atomic<bool> isChannelConnected_ = false;
105     std::mutex channelMtx_;
106     std::condition_variable channelCond_;
107     std::string accountId_ = "";
108     int32_t userId_ = -1;
109     std::string srcDevId_ = "";
110     uint64_t tokenId_ = 0;
111 };
112 
113 class DeviceInitCallback : public DmInitCallback {
114     void OnRemoteDied() override;
115 };
116 } // namespace DistributedHardware
117 } // namespace OHOS
118 #endif // OHOS_DCAMERA_SOURCE_CONTROLLER_H
119