• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_DEV_H
17 #define OHOS_DCAMERA_SOURCE_DEV_H
18 
19 #include "dcamera_index.h"
20 #include "dcamera_source_event.h"
21 #include "dcamera_source_state_machine.h"
22 #include "event_bus.h"
23 #include "icamera_controller.h"
24 #include "icamera_state_listener.h"
25 #include "icamera_input.h"
26 
27 #include "v1_0/id_camera_provider_callback.h"
28 #include "v1_0/id_camera_provider.h"
29 
30 namespace OHOS {
31 namespace DistributedHardware {
32 class DCameraSourceDev : public EventSender, public DistributedHardware::EventBusHandler<DCameraSourceEvent>,
33     public std::enable_shared_from_this<DCameraSourceDev> {
34 public:
35     explicit DCameraSourceDev(std::string devId, std::string dhId, std::shared_ptr<ICameraStateListener>& stateLisener);
36     virtual ~DCameraSourceDev();
37 
38     int32_t InitDCameraSourceDev();
39     int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& reqId,
40         const std::string& ver, const std::string attrs);
41     int32_t UnRegisterDistributedHardware(const std::string devId, const std::string dhId, const std::string reqId);
42     int32_t DCameraNotify(std::string& eventStr);
43 
44     int32_t OpenSession(DCameraIndex& camIndex);
45     int32_t CloseSession(DCameraIndex& camIndex);
46     int32_t ConfigCameraStreams(const std::vector<std::shared_ptr<DCStreamInfo>>& streamInfos);
47     int32_t ReleaseCameraStreams(const std::vector<int>& streamIds);
48     int32_t StartCameraCapture(const std::vector<std::shared_ptr<DCCaptureInfo>>& captureInfos);
49     int32_t StopCameraCapture(const std::vector<int>& streamIds);
50     int32_t UpdateCameraSettings(const std::vector<std::shared_ptr<DCameraSettings>>& settings);
51 
52     void OnEvent(DCameraSourceEvent& event) override;
53     int32_t GetStateInfo();
54     std::string GetVersion();
55 
56 public:
57     virtual int32_t Register(std::shared_ptr<DCameraRegistParam>& param);
58     virtual int32_t UnRegister(std::shared_ptr<DCameraRegistParam>& param);
59     virtual int32_t OpenCamera();
60     virtual int32_t CloseCamera();
61     virtual int32_t ConfigStreams(std::vector<std::shared_ptr<DCStreamInfo>>& streamInfos);
62     virtual int32_t ReleaseStreams(std::vector<int>& streamIds, bool& isAllRelease);
63     virtual int32_t ReleaseAllStreams();
64     virtual int32_t StartCapture(std::vector<std::shared_ptr<DCCaptureInfo>>& captureInfos);
65     virtual int32_t StopCapture(std::vector<int>& streamIds, bool& isAllStop);
66     virtual int32_t StopAllCapture();
67     virtual int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings);
68     virtual int32_t CameraEventNotify(std::shared_ptr<DCameraEvent>& events);
69 
70 private:
71     using DCameraNotifyFunc = void (DCameraSourceDev::*)(DCAMERA_EVENT eventType, DCameraSourceEvent& event,
72         int32_t result);
73 
74     void NotifyResult(DCAMERA_EVENT eventType, DCameraSourceEvent& event, int32_t result);
75     void NotifyRegisterResult(DCAMERA_EVENT eventType, DCameraSourceEvent& event, int32_t result);
76     void NotifyHalResult(DCAMERA_EVENT eventType, DCameraSourceEvent& event, int32_t result);
77     void HitraceAndHisyseventImpl(std::vector<std::shared_ptr<DCCaptureInfo>>& captureInfos);
78 
79 private:
80     std::string devId_;
81     std::string dhId_;
82     std::string version_;
83     std::set<DCameraIndex> actualDevInfo_;
84     std::shared_ptr<ICameraStateListener> stateListener_;
85     std::shared_ptr<EventBus> eventBus_;
86     std::shared_ptr<DCameraSourceStateMachine> stateMachine_;
87     std::shared_ptr<ICameraController> controller_;
88     std::shared_ptr<ICameraInput> input_;
89     sptr<IDCameraProviderCallback> hdiCallback_;
90 
91     std::map<uint32_t, DCameraNotifyFunc> memberFuncMap_;
92     std::map<uint32_t, DCameraEventResult> eventResultMap_;
93 };
94 } // namespace DistributedHardware
95 } // namespace OHOS
96 #endif // OHOS_DCAMERA_SOURCE_DEV_H
97