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 namespace OHOS { 31 namespace DistributedHardware { 32 class DCameraSinkController : public ICameraController, public EventSender, 33 public DistributedHardware::EventBusHandler<DCameraFrameTriggerEvent>, 34 public DistributedHardware::EventBusHandler<DCameraPostAuthorizationEvent>, 35 public std::enable_shared_from_this<DCameraSinkController> { 36 public: 37 explicit DCameraSinkController(std::shared_ptr<ICameraSinkAccessControl>& accessControl); 38 ~DCameraSinkController(); 39 40 int32_t StartCapture(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos) 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 51 void OnEvent(DCameraFrameTriggerEvent& event) override; 52 void OnEvent(DCameraPostAuthorizationEvent& event) override; 53 54 void OnStateChanged(std::shared_ptr<DCameraEvent>& event); 55 void OnMetadataResult(std::vector<std::shared_ptr<DCameraSettings>>& settings); 56 57 void OnSessionState(int32_t state); 58 void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail); 59 void OnDataReceived(std::vector<std::shared_ptr<DataBuffer>>& buffers); 60 61 private: 62 int32_t StartCaptureInner(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); 63 int32_t DCameraNotifyInner(int32_t type, int32_t result, std::string content); 64 int32_t HandleReceivedData(std::shared_ptr<DataBuffer>& dataBuffer); 65 void PostAuthorization(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); 66 67 bool isInit_; 68 int32_t sessionState_; 69 std::mutex autoLock_; 70 std::mutex captureLock_; 71 std::mutex channelLock_; 72 std::string dhId_; 73 std::string srcDevId_; 74 std::shared_ptr<EventBus> eventBus_; 75 std::shared_ptr<ICameraChannel> channel_; 76 std::shared_ptr<ICameraOperator> operator_; 77 std::shared_ptr<ICameraSinkAccessControl> accessControl_; 78 std::shared_ptr<ICameraSinkOutput> output_; 79 80 const std::string SESSION_FLAG = "control"; 81 const std::string SRC_TYPE = "camera"; 82 const size_t DATABUFF_MAX_SIZE = 100 * 1024 * 1024; 83 }; 84 } // namespace DistributedHardware 85 } // namespace OHOS 86 #endif // OHOS_DCAMERA_SINK_CONTROLLER_H