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 DISTRIBUTED_CAMERA_STREAM_H 17 #define DISTRIBUTED_CAMERA_STREAM_H 18 19 #include "surface.h" 20 #include "dimage_buffer.h" 21 #include "dbuffer_manager.h" 22 23 #include "v1_0/dcamera_types.h" 24 #include "v1_0/types.h" 25 26 namespace OHOS { 27 namespace DistributedHardware { 28 using namespace std; 29 using namespace OHOS::HDI::Camera::V1_0; 30 using namespace OHOS::HDI::DistributedCamera::V1_0; 31 class DCameraStream { 32 public: 33 DCameraStream() = default; 34 ~DCameraStream() = default; 35 DCameraStream(const DCameraStream &other) = delete; 36 DCameraStream(DCameraStream &&other) = delete; 37 DCameraStream &operator=(const DCameraStream &other) = delete; 38 DCameraStream &operator=(DCameraStream &&other) = delete; 39 40 public: 41 DCamRetCode InitDCameraStream(const StreamInfo &info); 42 DCamRetCode GetDCameraStreamInfo(shared_ptr<StreamInfo> &info); 43 DCamRetCode SetDCameraBufferQueue(const OHOS::sptr<BufferProducerSequenceable> &producer); 44 DCamRetCode ReleaseDCameraBufferQueue(); 45 DCamRetCode GetDCameraStreamAttribute(StreamAttribute &attribute); 46 DCamRetCode GetDCameraBuffer(DCameraBuffer &buffer); 47 DCamRetCode ReturnDCameraBuffer(const DCameraBuffer &buffer); 48 DCamRetCode FinishCommitStream(); 49 bool HasBufferQueue(); 50 void DoCapture(); 51 void CancelCaptureWait(); 52 53 private: 54 DCamRetCode InitDCameraBufferManager(); 55 DCamRetCode GetNextRequest(); 56 DCamRetCode CheckRequestParam(); 57 void SetSurfaceBuffer(OHOS::sptr<OHOS::SurfaceBuffer>& surfaceBuffer, const DCameraBuffer &buffer); 58 DCamRetCode CancelDCameraBuffer(); 59 DCamRetCode FlushDCameraBuffer(const DCameraBuffer &buffer); 60 uint64_t GetVideoTimeStamp(); 61 62 private: 63 int32_t index_ = -1; 64 int dcStreamId_; 65 shared_ptr<StreamInfo> dcStreamInfo_ = nullptr; 66 StreamAttribute dcStreamAttribute_; 67 shared_ptr<DBufferManager> dcStreamBufferMgr_ = nullptr; 68 OHOS::sptr<OHOS::Surface> dcStreamProducer_ = nullptr; 69 map<shared_ptr<DImageBuffer>, tuple<OHOS::sptr<OHOS::SurfaceBuffer>, int>> bufferConfigMap_; 70 condition_variable cv_; 71 int captureBufferCount_ = 0; 72 bool isBufferMgrInited_ = false; 73 bool isCancelBuffer_ = false; 74 bool isCancelCapture_ = false; 75 mutex requestMutex_; 76 mutex bufferQueueMutex_; 77 mutex lockSync_; 78 }; 79 } // namespace DistributedHardware 80 } // namespace OHOS 81 #endif // DISTRIBUTED_CAMERA_STREAM_H