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