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_IBUFFER_POOL_H 17 #define HOS_CAMERA_IBUFFER_POOL_H 18 19 #include "ibuffer.h" 20 21 namespace OHOS::Camera { 22 class IBufferPool { 23 public: ~IBufferPool()24 virtual ~IBufferPool() {} 25 26 // init a buffer pool, bufferSourceType indicates where buffers come from. 27 virtual RetCode Init(const uint32_t width, 28 const uint32_t height, 29 const uint64_t usage, 30 const uint32_t bufferFormat, 31 const uint32_t count, 32 const int32_t bufferSourceType) = 0; 33 34 // add buffer to buffer pool, only for external source. 35 virtual RetCode AddBuffer(std::shared_ptr<IBuffer>& buffer) = 0; 36 37 /* request a idle buffer from pool. 38 * timeout < 0, wait until there is idle buffer in pool. 39 * timeout = 0, no wait, could return null. 40 * timeout > 0, wait for timeout seconds, if timeout return null. 41 */ 42 virtual std::shared_ptr<IBuffer> AcquireBuffer(int timeout) = 0; AcquireBuffer()43 std::shared_ptr<IBuffer> AcquireBuffer() 44 { 45 return AcquireBuffer(0); 46 } 47 48 // return a buffer to pool. 49 virtual RetCode ReturnBuffer(std::shared_ptr<IBuffer>& buffer) = 0; 50 51 // enable tracking buffers of pool 52 virtual void EnableTracking(const int32_t id) = 0; 53 virtual void SetId(const int64_t id) = 0; 54 virtual void NotifyStop() = 0; 55 virtual void NotifyStart() = 0; 56 virtual void ClearBuffers() = 0; 57 virtual uint32_t GetIdleBufferCount() = 0; 58 }; 59 } // namespace OHOS::Camera 60 61 #endif 62