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