• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 
30 #include "property_carrier.h"
31 
32 namespace OHOS {
33 namespace DistributedHardware {
34 class DCameraSinkController : public ICameraController, public EventSender,
35     public DistributedHardware::EventBusHandler<DCameraFrameTriggerEvent>,
36     public DistributedHardware::EventBusHandler<DCameraPostAuthorizationEvent>,
37     public std::enable_shared_from_this<DCameraSinkController> {
38 public:
39     explicit DCameraSinkController(std::shared_ptr<ICameraSinkAccessControl>& accessControl);
40     ~DCameraSinkController() override;
41 
42     int32_t StartCapture(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos) override;
43     int32_t StopCapture() override;
44     int32_t ChannelNeg(std::shared_ptr<DCameraChannelInfo>& info) override;
45     int32_t DCameraNotify(std::shared_ptr<DCameraEvent>& events) override;
46     int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings) override;
47     int32_t GetCameraInfo(std::shared_ptr<DCameraInfo>& camInfo) override;
48     int32_t OpenChannel(std::shared_ptr<DCameraOpenInfo>& openInfo) override;
49     int32_t CloseChannel() override;
50     int32_t Init(std::vector<DCameraIndex>& indexs) override;
51     int32_t UnInit() override;
52 
53     void OnEvent(DCameraFrameTriggerEvent& event) override;
54     void OnEvent(DCameraPostAuthorizationEvent& event) override;
55 
56     void OnStateChanged(std::shared_ptr<DCameraEvent>& event);
57     void OnMetadataResult(std::vector<std::shared_ptr<DCameraSettings>>& settings);
58 
59     void OnSessionState(int32_t state);
60     void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail);
61     void OnDataReceived(std::vector<std::shared_ptr<DataBuffer>>& buffers);
62 
63 private:
64     int32_t StartCaptureInner(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos);
65     int32_t DCameraNotifyInner(int32_t type, int32_t result, std::string content);
66     int32_t HandleReceivedData(std::shared_ptr<DataBuffer>& dataBuffer);
67     void PostAuthorization(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos);
68 
69     bool isInit_;
70     int32_t sessionState_;
71     std::mutex autoLock_;
72     std::mutex captureLock_;
73     std::mutex channelLock_;
74     std::string dhId_;
75     std::string srcDevId_;
76     std::shared_ptr<EventBus> eventBus_;
77     std::shared_ptr<ICameraChannel> channel_;
78     std::shared_ptr<ICameraOperator> operator_;
79     std::shared_ptr<ICameraSinkAccessControl> accessControl_;
80     std::shared_ptr<ICameraSinkOutput> output_;
81 
82     const std::string SESSION_FLAG = "control";
83     const std::string SRC_TYPE = "camera";
84     const size_t DATABUFF_MAX_SIZE = 100 * 1024 * 1024;
85 };
86 } // namespace DistributedHardware
87 } // namespace OHOS
88 #endif // OHOS_DCAMERA_SINK_CONTROLLER_H