• 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_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 "event_bus.h"
26 #include "icamera_channel.h"
27 
28 #include "v1_0/id_camera_provider.h"
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 class DCameraSourceController : public ICameraController, public EventSender,
33     public std::enable_shared_from_this<DCameraSourceController> {
34 public:
35     DCameraSourceController(std::string devId, std::string dhId,
36         std::shared_ptr<DCameraSourceStateMachine>& stateMachine, std::shared_ptr<DCameraSourceDev>& camDev);
37     ~DCameraSourceController() override;
38     int32_t StartCapture(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos) override;
39     int32_t StopCapture() override;
40     int32_t ChannelNeg(std::shared_ptr<DCameraChannelInfo>& info) override;
41     int32_t DCameraNotify(std::shared_ptr<DCameraEvent>& events) override;
42     int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings) override;
43     int32_t GetCameraInfo(std::shared_ptr<DCameraInfo>& camInfo) override;
44     int32_t OpenChannel(std::shared_ptr<DCameraOpenInfo>& openInfo) override;
45     int32_t CloseChannel() override;
46     int32_t Init(std::vector<DCameraIndex>& indexs) override;
47     int32_t UnInit() override;
48 
49     void OnSessionState(int32_t state);
50     void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail);
51     void OnDataReceived(std::vector<std::shared_ptr<DataBuffer>>& buffers);
52 
53 private:
54     void HandleMetaDataResult(std::string& jsonStr);
55     void PostChannelDisconnectedEvent();
56     int32_t WaitforSessionResult(const std::string& devId);
57 
58 private:
59     std::string devId_;
60     std::string dhId_;
61     std::shared_ptr<ICameraChannel> channel_;
62     std::shared_ptr<ICameraChannelListener> listener_;
63     std::vector<DCameraIndex> indexs_;
64     std::shared_ptr<DCameraSourceStateMachine> stateMachine_;
65     std::weak_ptr<DCameraSourceDev> camDev_;
66     int32_t channelState_;
67     sptr<IDCameraProvider> camHdiProvider_;
68 
69     bool isInit;
70     const std::string SESSION_FLAG = "control";
71 
72     static constexpr uint8_t CHANNEL_REL_SECONDS = 5;
73     std::atomic<bool> isChannelConnected_ = false;
74     std::mutex channelMtx_;
75     std::condition_variable channelCond_;
76 };
77 } // namespace DistributedHardware
78 } // namespace OHOS
79 #endif // OHOS_DCAMERA_SOURCE_CONTROLLER_H
80