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_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 "icamera_channel.h" 26 #include "iremote_object.h" 27 28 #include "v1_1/id_camera_provider.h" 29 30 namespace OHOS { 31 namespace DistributedHardware { 32 class DCameraSourceController : public ICameraController, 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, int32_t sceneMode) 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 int32_t PauseDistributedHardware(const std::string &networkId) override; 49 int32_t ResumeDistributedHardware(const std::string &networkId) override; 50 int32_t StopDistributedHardware(const std::string &networkId) override; 51 52 void OnSessionState(int32_t state); 53 void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail); 54 void OnDataReceived(std::vector<std::shared_ptr<DataBuffer>>& buffers); 55 56 private: 57 void HandleMetaDataResult(std::string& jsonStr); 58 void PostChannelDisconnectedEvent(); 59 int32_t PublishEnableLatencyMsg(const std::string& devId); 60 class DCameraHdiRecipient : public IRemoteObject::DeathRecipient { 61 public: 62 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 63 }; 64 sptr<DCameraHdiRecipient> cameraHdiRecipient_; 65 66 private: 67 std::string devId_; 68 std::string dhId_; 69 std::shared_ptr<ICameraChannel> channel_; 70 std::shared_ptr<ICameraChannelListener> listener_; 71 std::vector<DCameraIndex> indexs_; 72 std::shared_ptr<DCameraSourceStateMachine> stateMachine_; 73 std::weak_ptr<DCameraSourceDev> camDev_; 74 int32_t channelState_; 75 sptr<IDCameraProvider> camHdiProvider_; 76 sptr<IRemoteObject> remote_; 77 78 bool isInit; 79 const std::string SESSION_FLAG = "control"; 80 81 static constexpr uint8_t CHANNEL_REL_SECONDS = 5; 82 std::atomic<bool> isChannelConnected_ = false; 83 std::mutex channelMtx_; 84 std::condition_variable channelCond_; 85 }; 86 } // namespace DistributedHardware 87 } // namespace OHOS 88 #endif // OHOS_DCAMERA_SOURCE_CONTROLLER_H 89