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_IMAGE_BUFFER_H 17 #define DISTRIBUTED_CAMERA_IMAGE_BUFFER_H 18 19 #include <mutex> 20 21 #include "constants.h" 22 #include "sync_fence.h" 23 #include "v1_0/dcamera_types.h" 24 25 namespace OHOS { 26 namespace DistributedHardware { 27 class DImageBuffer { 28 public: 29 DImageBuffer() = default; 30 virtual ~DImageBuffer(); 31 32 int32_t GetIndex() const; 33 uint32_t GetWidth() const; 34 uint32_t GetHeight() const; 35 uint32_t GetStride() const; 36 int32_t GetFormat() const; 37 uint32_t GetSize() const; 38 uint64_t GetUsage() const; 39 uint64_t GetPhyAddress() const; 40 int32_t GetFileDescriptor() const; 41 uint64_t GetTimestamp() const; 42 uint64_t GetFrameNumber() const; 43 int32_t GetCaptureId() const; 44 bool GetValidFlag() const; 45 OHOS::sptr<OHOS::SyncFence> GetSyncFence() const; 46 int32_t GetEncodeType() const; 47 BufferHandle* GetBufferHandle() const; 48 49 void SetIndex(const int32_t index); 50 void SetWidth(const uint32_t width); 51 void SetHeight(const uint32_t height); 52 void SetStride(const uint32_t stride); 53 void SetFormat(const int32_t format); 54 void SetSize(const uint32_t size); 55 void SetUsage(const uint64_t usage); 56 void SetPhyAddress(const uint64_t addr); 57 void SetFileDescriptor(const int32_t fd); 58 void SetTimestamp(const uint64_t timeStamp); 59 void SetFrameNumber(const uint64_t frameNumber); 60 void SetCaptureId(const int32_t id); 61 void SetValidFlag(const bool flag); 62 void SetSyncFence(const sptr<OHOS::SyncFence> &syncFence); 63 void SetEncodeType(const int32_t type); 64 void SetBufferHandle(const BufferHandle* bufHandle); 65 66 void Free(); 67 bool operator==(const DImageBuffer& u); 68 69 private: 70 int32_t index_ = -1; 71 uint32_t width_ = 0; 72 uint32_t height_ = 0; 73 uint32_t stride_ = 0; 74 uint32_t format_ = OHOS_CAMERA_FORMAT_INVALID; 75 uint32_t size_ = 0; 76 uint64_t usage_ = 0; 77 uint64_t phyAddr_ = 0; 78 int32_t fd_ = -1; 79 uint64_t frameNumber_ = 0; 80 uint64_t timeStamp_ = 0; 81 int32_t captureId_ = -1; 82 bool valid_ = true; 83 OHOS::sptr<OHOS::SyncFence> syncFence_ = nullptr; 84 int32_t encodeType_ = 0; 85 BufferHandle* bufHandle_ = nullptr; 86 87 std::mutex l_; 88 }; 89 } // namespace DistributedHardware 90 } // namespace OHOS 91 #endif // DISTRIBUTED_CAMERA_IMAGE_BUFFER_H 92