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 #include "dimage_buffer.h" 17 #include <buffer_handle_utils.h> 18 19 namespace OHOS { 20 namespace DistributedHardware { ~DImageBuffer()21DImageBuffer::~DImageBuffer() 22 { 23 Free(); 24 } 25 GetIndex() const26int32_t DImageBuffer::GetIndex() const 27 { 28 return index_; 29 } 30 GetWidth() const31uint32_t DImageBuffer::GetWidth() const 32 { 33 return width_; 34 } 35 GetHeight() const36uint32_t DImageBuffer::GetHeight() const 37 { 38 return height_; 39 } 40 GetStride() const41uint32_t DImageBuffer::GetStride() const 42 { 43 return stride_; 44 } 45 GetFormat() const46int32_t DImageBuffer::GetFormat() const 47 { 48 return format_; 49 } 50 GetSize() const51uint32_t DImageBuffer::GetSize() const 52 { 53 return size_; 54 } 55 GetUsage() const56uint64_t DImageBuffer::GetUsage() const 57 { 58 return usage_; 59 } 60 GetPhyAddress() const61uint64_t DImageBuffer::GetPhyAddress() const 62 { 63 return phyAddr_; 64 } 65 GetFileDescriptor() const66int32_t DImageBuffer::GetFileDescriptor() const 67 { 68 return fd_; 69 } 70 GetTimestamp() const71uint64_t DImageBuffer::GetTimestamp() const 72 { 73 return timeStamp_; 74 } 75 GetFrameNumber() const76uint64_t DImageBuffer::GetFrameNumber() const 77 { 78 return frameNumber_; 79 } 80 GetCaptureId() const81int32_t DImageBuffer::GetCaptureId() const 82 { 83 return captureId_; 84 } 85 GetValidFlag() const86bool DImageBuffer::GetValidFlag() const 87 { 88 return valid_; 89 } 90 GetSyncFence() const91OHOS::sptr<OHOS::SyncFence> DImageBuffer::GetSyncFence() const 92 { 93 return syncFence_; 94 } 95 GetEncodeType() const96int32_t DImageBuffer::GetEncodeType() const 97 { 98 return encodeType_; 99 } 100 GetBufferHandle() const101BufferHandle* DImageBuffer::GetBufferHandle() const 102 { 103 return bufHandle_; 104 } 105 SetIndex(const int32_t index)106void DImageBuffer::SetIndex(const int32_t index) 107 { 108 std::lock_guard<std::mutex> l(l_); 109 index_ = index; 110 return; 111 } 112 SetWidth(const uint32_t width)113void DImageBuffer::SetWidth(const uint32_t width) 114 { 115 std::lock_guard<std::mutex> l(l_); 116 width_ = width; 117 return; 118 } 119 SetHeight(const uint32_t height)120void DImageBuffer::SetHeight(const uint32_t height) 121 { 122 std::lock_guard<std::mutex> l(l_); 123 height_ = height; 124 return; 125 } 126 SetStride(const uint32_t stride)127void DImageBuffer::SetStride(const uint32_t stride) 128 { 129 std::lock_guard<std::mutex> l(l_); 130 stride_ = stride; 131 return; 132 } 133 SetFormat(const int32_t format)134void DImageBuffer::SetFormat(const int32_t format) 135 { 136 std::lock_guard<std::mutex> l(l_); 137 format_ = format; 138 return; 139 } 140 SetSize(const uint32_t size)141void DImageBuffer::SetSize(const uint32_t size) 142 { 143 std::lock_guard<std::mutex> l(l_); 144 size_ = size; 145 return; 146 } 147 SetUsage(const uint64_t usage)148void DImageBuffer::SetUsage(const uint64_t usage) 149 { 150 std::lock_guard<std::mutex> l(l_); 151 usage_ = usage; 152 return; 153 } 154 SetPhyAddress(const uint64_t addr)155void DImageBuffer::SetPhyAddress(const uint64_t addr) 156 { 157 std::lock_guard<std::mutex> l(l_); 158 phyAddr_ = addr; 159 return; 160 } 161 SetFileDescriptor(const int32_t fd)162void DImageBuffer::SetFileDescriptor(const int32_t fd) 163 { 164 std::lock_guard<std::mutex> l(l_); 165 fd_ = fd; 166 return; 167 } 168 SetTimestamp(const uint64_t timeStamp)169void DImageBuffer::SetTimestamp(const uint64_t timeStamp) 170 { 171 std::lock_guard<std::mutex> l(l_); 172 timeStamp_ = timeStamp; 173 return; 174 } 175 SetFrameNumber(const uint64_t frameNumber)176void DImageBuffer::SetFrameNumber(const uint64_t frameNumber) 177 { 178 std::lock_guard<std::mutex> l(l_); 179 frameNumber_ = frameNumber; 180 return; 181 } 182 SetCaptureId(const int32_t id)183void DImageBuffer::SetCaptureId(const int32_t id) 184 { 185 std::lock_guard<std::mutex> l(l_); 186 captureId_ = id; 187 return; 188 } 189 SetValidFlag(const bool flag)190void DImageBuffer::SetValidFlag(const bool flag) 191 { 192 std::lock_guard<std::mutex> l(l_); 193 valid_ = flag; 194 return; 195 } 196 SetSyncFence(const OHOS::sptr<OHOS::SyncFence> & syncFence)197void DImageBuffer::SetSyncFence(const OHOS::sptr<OHOS::SyncFence> &syncFence) 198 { 199 std::lock_guard<std::mutex> l(l_); 200 syncFence_ = syncFence; 201 return; 202 } 203 SetEncodeType(const int32_t type)204void DImageBuffer::SetEncodeType(const int32_t type) 205 { 206 std::lock_guard<std::mutex> l(l_); 207 encodeType_ = type; 208 return; 209 } 210 SetBufferHandle(const BufferHandle * bufHandle)211void DImageBuffer::SetBufferHandle(const BufferHandle* bufHandle) 212 { 213 std::lock_guard<std::mutex> l(l_); 214 bufHandle_ = const_cast<BufferHandle*>(bufHandle); 215 return; 216 } 217 Free()218void DImageBuffer::Free() 219 { 220 index_ = -1; 221 width_ = 0; 222 height_ = 0; 223 stride_ = 0; 224 format_ = OHOS_CAMERA_FORMAT_INVALID; 225 size_ = 0; 226 usage_ = 0; 227 bufHandle_ = nullptr; 228 phyAddr_ = 0; 229 fd_ = -1; 230 syncFence_ = nullptr; 231 232 return; 233 } 234 operator ==(const DImageBuffer & u)235bool DImageBuffer::operator==(const DImageBuffer& u) 236 { 237 if (u.GetPhyAddress() == 0 || phyAddr_ == 0) { 238 return u.GetIndex() == index_; 239 } 240 return u.GetPhyAddress() == phyAddr_; 241 } 242 } // namespace DistributedHardware 243 } // namespace OHOS 244