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 GetCurWidth() const override; 38 uint32_t GetHeight() const override; 39 uint32_t GetCurHeight() const override; 40 uint32_t GetStride() const override; 41 int32_t GetFormat() const override; 42 int32_t GetCurFormat() const override; 43 uint32_t GetSize() const override; 44 void* GetSuffaceBufferAddr() const override; 45 uint32_t GetSuffaceBufferSize() const override; 46 uint64_t GetUsage() const override; 47 void* GetVirAddress() const override; 48 uint64_t GetPhyAddress() const override; 49 int32_t GetFileDescriptor() const override; 50 int32_t GetSourceType() const override; 51 uint64_t GetTimestamp() const override; 52 uint64_t GetFrameNumber() const override; 53 int64_t GetPoolId() const override; 54 int32_t GetCaptureId() const override; 55 CameraBufferStatus GetBufferStatus() const override; 56 int32_t GetSequenceId() const override; 57 int32_t GetFenceId() const override; 58 EsFrameInfo GetEsFrameInfo() const override; 59 int32_t GetEncodeType() const override; 60 int32_t GetStreamId() const override; 61 bool GetIsValidDataInSurfaceBuffer() const override; 62 63 void SetIndex(const int32_t index) override; 64 void SetWidth(const uint32_t width) override; 65 void SetCurWidth(const uint32_t width) override; 66 void SetHeight(const uint32_t height) override; 67 void SetCurHeight(const uint32_t height) override; 68 void SetStride(const uint32_t stride) override; 69 void SetFormat(const int32_t format) override; 70 void SetCurFormat(const int32_t format) override; 71 void SetSize(const uint32_t size) override; 72 void SetSuffaceBufferSize(const uint32_t size) override; 73 void SetSuffaceBufferAddr(const void* addr) override; 74 void SetUsage(const uint64_t usage) override; 75 void SetVirAddress(const void* addr) override; 76 void SetPhyAddress(const uint64_t addr) override; 77 void SetFileDescriptor(const int32_t fd) override; 78 void SetTimestamp(const uint64_t timestamp) override; 79 void SetFrameNumber(const uint64_t frameNumber) override; 80 void SetPoolId(const int64_t id) override; 81 void SetCaptureId(const int32_t id) override; 82 void SetBufferStatus(const CameraBufferStatus flag) override; 83 void SetSequenceId(const int32_t sequence) override; 84 void SetFenceId(const int32_t fence) override; 85 void SetEncodeType(const int32_t type) override; 86 void SetEsFrameSize(const int32_t frameSize) override; 87 void SetEsTimestamp(const int64_t timeStamp) override; 88 void SetEsKeyFrame(const int32_t isKey) override; 89 void SetEsFrameNum(const int32_t frameNum) override; 90 void SetStreamId(const int32_t streamId) override; 91 void SetIsValidDataInSurfaceBuffer(const bool isValid) override; 92 93 void Free() override; 94 bool operator==(const IBuffer& u) override; 95 96 private: 97 bool isDataValidInSurfaceBuffer_ = false; 98 int32_t index_ = -1; 99 uint32_t width_ = 0; 100 uint32_t curWidth_ = 0; 101 uint32_t height_ = 0; 102 uint32_t curHeight_ = 0; 103 uint32_t stride_ = 0; 104 uint32_t format_ = CAMERA_FORMAT_INVALID; 105 uint32_t curFormat_ = CAMERA_FORMAT_INVALID; 106 uint32_t size_ = 0; 107 uint32_t sbSize_ = 0; 108 uint64_t usage_ = 0; 109 void* virAddr_ = nullptr; 110 void* sbAddr_ = nullptr; 111 uint64_t phyAddr_ = 0; 112 int32_t fd_ = -1; 113 int32_t sourceType_ = CAMERA_BUFFER_SOURCE_TYPE_NONE; 114 uint64_t frameNumber_ = 0; 115 uint64_t timeStamp_ = 0; 116 int64_t poolId_ = -1; 117 int32_t captureId_ = -1; 118 CameraBufferStatus status_ = CAMERA_BUFFER_STATUS_OK; 119 int32_t sequenceId_ = -1; 120 int32_t fenceId_ = -1; 121 int32_t encodeType_ = 0; 122 EsFrameInfo esInfo_ = {-1, -1, -1, -1, -1}; 123 int32_t streamId_ = -1; 124 std::mutex l_; 125 }; 126 } // namespace OHOS::Camera 127 #endif 128 129