1 /* 2 * Copyright (c) 2021-2023 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_INPUT_H 17 #define OHOS_DCAMERA_SOURCE_INPUT_H 18 19 #include "icamera_channel.h" 20 #include "icamera_channel_listener.h" 21 #include "icamera_input.h" 22 #include "icamera_source_data_process.h" 23 24 #include "dcamera_source_dev.h" 25 #include "event_bus.h" 26 #include "event_sender.h" 27 28 namespace OHOS { 29 namespace DistributedHardware { 30 class DCameraSourceInput : public ICameraInput, public EventSender, 31 public std::enable_shared_from_this<DCameraSourceInput> { 32 public: 33 DCameraSourceInput(std::string devId, std::string dhId, std::shared_ptr<DCameraSourceDev>& camDev); 34 ~DCameraSourceInput() override; 35 36 int32_t ConfigStreams(std::vector<std::shared_ptr<DCStreamInfo>>& streamInfos) override; 37 int32_t ReleaseStreams(std::vector<int>& streamIds, bool& isAllRelease) override; 38 int32_t ReleaseAllStreams() override; 39 int32_t StartCapture(std::vector<std::shared_ptr<DCCaptureInfo>>& captureInfos) override; 40 int32_t StopCapture(std::vector<int>& streamIds, bool& isAllStop) override; 41 int32_t StopAllCapture() override; 42 int32_t OpenChannel(std::vector<DCameraIndex>& indexs) override; 43 int32_t CloseChannel() override; 44 int32_t Init() override; 45 int32_t UnInit() override; 46 int32_t UpdateSettings(std::vector<std::shared_ptr<DCameraSettings>>& settings) override; 47 48 void OnSessionState(DCStreamType streamType, int32_t state); 49 void OnSessionError(DCStreamType streamType, int32_t eventType, int32_t eventReason, std::string detail); 50 void OnDataReceived(DCStreamType streamType, std::vector<std::shared_ptr<DataBuffer>>& buffers); 51 52 private: 53 void FinshFrameAsyncTrace(DCStreamType streamType); 54 void PostChannelDisconnectedEvent(); 55 int32_t WaitforSessionResult(); 56 int32_t EstablishContinuousFrameSession(std::vector<DCameraIndex>& indexs); 57 int32_t EstablishSnapshotFrameSession(std::vector<DCameraIndex>& indexs); 58 59 private: 60 std::map<DCStreamType, std::shared_ptr<ICameraChannel>> channels_; 61 std::map<DCStreamType, std::shared_ptr<ICameraChannelListener>> listeners_; 62 std::map<DCStreamType, std::shared_ptr<ICameraSourceDataProcess>> dataProcess_; 63 std::map<DCStreamType, DCameraChannelState> channelState_; 64 std::string devId_; 65 std::string dhId_; 66 std::weak_ptr<DCameraSourceDev> camDev_; 67 68 bool isInit = false; 69 70 static constexpr uint8_t CHANNEL_REL_SECONDS = 5; 71 std::atomic<bool> isChannelConnected_ = false; 72 std::mutex channelMtx_; 73 std::condition_variable channelCond_; 74 }; 75 } // namespace DistributedHardware 76 } // namespace OHOS 77 #endif // OHOS_DCAMERA_SOURCE_INPUT_H 78