1 /* 2 * Copyright (c) 2021 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 HOS_CAMERA_IMAGE_BUFFER_H 17 #define HOS_CAMERA_IMAGE_BUFFER_H 18 19 #include "ibuffer.h" 20 #include <mutex> 21 22 namespace OHOS::Camera { 23 class ImageBuffer : public IBuffer { 24 public: 25 ImageBuffer(); 26 explicit ImageBuffer(const int32_t source); 27 ImageBuffer(const int32_t source, 28 const uint32_t width, 29 const uint32_t height, 30 const uint64_t usage, 31 const uint32_t format); 32 33 virtual ~ImageBuffer(); 34 35 int32_t GetIndex() const override; 36 uint32_t GetWidth() const override; 37 uint32_t GetHeight() const override; 38 uint32_t GetStride() const override; 39 int32_t GetFormat() const override; 40 uint32_t GetSize() const override; 41 uint64_t GetUsage() const override; 42 void* GetVirAddress() const override; 43 uint64_t GetPhyAddress() const override; 44 int32_t GetFileDescriptor() const override; 45 int32_t GetSourceType() const override; 46 uint64_t GetTimestamp() const override; 47 uint64_t GetFrameNumber() const override; 48 int64_t GetPoolId() const override; 49 int32_t GetCaptureId() const override; 50 CameraBufferStatus GetBufferStatus() const override; 51 int32_t GetSequenceId() const override; 52 int32_t GetFenceId() const override; 53 EsFrameInfo GetEsFrameInfo() const override; 54 int32_t GetEncodeType() const override; 55 int32_t GetStreamId() const override; 56 57 void SetIndex(const int32_t index) override; 58 void SetWidth(const uint32_t width) override; 59 void SetHeight(const uint32_t height) override; 60 void SetStride(const uint32_t stride) override; 61 void SetFormat(const int32_t format) override; 62 void SetSize(const uint32_t size) override; 63 void SetUsage(const uint64_t usage) override; 64 void SetVirAddress(const void* addr) override; 65 void SetPhyAddress(const uint64_t addr) override; 66 void SetFileDescriptor(const int32_t fd) override; 67 void SetTimestamp(const uint64_t timestamp) override; 68 void SetFrameNumber(const uint64_t frameNumber) override; 69 void SetPoolId(const int64_t id) override; 70 void SetCaptureId(const int32_t id) override; 71 void SetBufferStatus(const CameraBufferStatus flag) override; 72 void SetSequenceId(const int32_t sequence) override; 73 void SetFenceId(const int32_t fence) override; 74 void SetEncodeType(const int32_t type) override; 75 void SetEsFrameSize(const int32_t frameSize) override; 76 void SetEsTimestamp(const int64_t timeStamp) override; 77 void SetEsKeyFrame(const int32_t isKey) override; 78 void SetEsFrameNum(const int32_t frameNum) override; 79 void SetStreamId(const int32_t streamId) override; 80 81 void Free() override; 82 bool operator==(const IBuffer& u) override; 83 84 private: 85 int32_t index_ = -1; 86 uint32_t width_ = 0; 87 uint32_t height_ = 0; 88 uint32_t stride_ = 0; 89 uint32_t format_ = CAMERA_FORMAT_INVALID; 90 uint32_t size_ = 0; 91 uint64_t usage_ = 0; 92 void* virAddr_ = nullptr; 93 uint64_t phyAddr_ = 0; 94 int32_t fd_ = -1; 95 int32_t sourceType_ = CAMERA_BUFFER_SOURCE_TYPE_NONE; 96 uint64_t frameNumber_ = 0; 97 uint64_t timeStamp_ = 0; 98 int64_t poolId_ = -1; 99 int32_t captureId_ = -1; 100 CameraBufferStatus status_ = CAMERA_BUFFER_STATUS_OK; 101 int32_t sequenceId_ = -1; 102 int32_t fenceId_ = -1; 103 int32_t encodeType_ = 0; 104 EsFrameInfo esInfo_ = {-1, -1, -1, -1, -1}; 105 int32_t streamId_ = -1; 106 std::mutex l_; 107 }; 108 } // namespace OHOS::Camera 109 #endif 110 111