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 STREAM_OPERATOR_STREAM_OPERATOR_VDI_IMPL_H 17 #define STREAM_OPERATOR_STREAM_OPERATOR_VDI_IMPL_H 18 19 #include <set> 20 #include "v1_0/icamera_device_vdi.h" 21 #include "v1_0/istream_operator_vdi.h" 22 #include "capture_message.h" 23 #include "istream.h" 24 #include "offline_stream_operator_vdi_impl.h" 25 #include "offline_stream.h" 26 #include "surface.h" 27 28 namespace OHOS::Camera { 29 using namespace OHOS::VDI::Camera::V1_0; 30 class StreamOperatorVdiImpl : public IStreamOperatorVdi { 31 public: 32 int32_t IsStreamsSupported(VdiOperationMode mode, const std::vector<uint8_t> &modeSetting, 33 const std::vector<VdiStreamInfo> &infos, VdiStreamSupportType &type) override; 34 int32_t CreateStreams(const std::vector<VdiStreamInfo> &streamInfos) override; 35 int32_t ReleaseStreams(const std::vector<int32_t> &streamIds) override; 36 int32_t CommitStreams(VdiOperationMode mode, const std::vector<uint8_t> &modeSetting) override; 37 int32_t GetStreamAttributes(std::vector<VdiStreamAttribute> &attributes) override; 38 int32_t AttachBufferQueue(int32_t streamId, const sptr<BufferProducerSequenceable> &bufferProducer); 39 int32_t DetachBufferQueue(int32_t streamId) override; 40 int32_t Capture(int32_t captureId, const VdiCaptureInfo &info, bool isStreaming) override; 41 int32_t CancelCapture(int32_t captureId) override; 42 int32_t ChangeToOfflineStream(const std::vector<int32_t> &streamIds, 43 const sptr<IStreamOperatorVdiCallback> &callbackObj, sptr<IOfflineStreamOperatorVdi> &offlineOperator) override; 44 45 public: 46 StreamOperatorVdiImpl() = default; 47 StreamOperatorVdiImpl(const OHOS::sptr<IStreamOperatorVdiCallback> &callback, 48 const std::weak_ptr<ICameraDeviceVdi> &device); 49 virtual ~StreamOperatorVdiImpl(); 50 StreamOperatorVdiImpl(const StreamOperatorVdiImpl &other) = delete; 51 StreamOperatorVdiImpl(StreamOperatorVdiImpl&& other) = delete; 52 StreamOperatorVdiImpl &operator=(const StreamOperatorVdiImpl &other) = delete; 53 StreamOperatorVdiImpl &operator=(StreamOperatorVdiImpl&& other) = delete; 54 55 RetCode Init(); 56 RetCode ReleaseStreams(); 57 58 private: 59 void FillCaptureErrorInfo(std::vector<VdiCaptureErrorInfo> &info, MessageGroup message); 60 void FillCaptureEndedInfo(std::vector<VdiCaptureEndedInfo> &info, MessageGroup message); 61 void HandleCallbackMessage(MessageGroup &message); 62 void OnCaptureStarted(int32_t captureId, const std::vector<int32_t> &streamIds); 63 void OnCaptureEnded(int32_t captureId, const std::vector<VdiCaptureEndedInfo> &infos); 64 void OnCaptureError(int32_t captureId, const std::vector<VdiCaptureErrorInfo> &infos); 65 void OnFrameShutter(int32_t captureId, const std::vector<int32_t> &streamIds, uint64_t timestamp); 66 bool CheckStreamInfo(const VdiStreamInfo streamInfo); 67 DynamicStreamSwitchMode CheckStreamsSupported(VdiOperationMode mode, 68 const std::shared_ptr<CameraMetadata> &modeSetting, 69 const std::vector<VdiStreamInfo> &infos); 70 void StreamInfoToStreamConfiguration(StreamConfiguration &scg, const VdiStreamInfo info); 71 void GetStreamSupportType(std::set<int32_t> inputIDSet, 72 DynamicStreamSwitchMode method, 73 VdiStreamSupportType &type); 74 private: 75 OHOS::sptr<IStreamOperatorVdiCallback> callback_ = nullptr; 76 std::weak_ptr<ICameraDeviceVdi> device_; 77 std::shared_ptr<IPipelineCore> pipelineCore_ = nullptr; 78 std::shared_ptr<IStreamPipelineCore> streamPipeline_ = nullptr; 79 std::shared_ptr<CaptureMessageOperator> messenger_ = nullptr; 80 81 std::mutex streamLock_ = {}; 82 std::unordered_map<int32_t, std::shared_ptr<IStream>> streamMap_ = {}; 83 84 std::mutex requestLock_ = {}; 85 std::unordered_map<int32_t, std::shared_ptr<CaptureRequest>> requestMap_ = {}; 86 OHOS::sptr<OfflineStreamOperatorVdiImpl> oflstor_ = nullptr; 87 std::function<void()> requestTimeoutCB_ = nullptr; 88 }; 89 } // end namespace OHOS::Camera 90 #endif // STREAM_OPERATOR_STREAM_OPERATOR_VDI_IMPL_H 91