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_BUFFER_POOL_H 17 #define HOS_CAMERA_BUFFER_POOL_H 18 19 #include "buffer_allocator_factory.h" 20 #include "ibuffer.h" 21 #include "ibuffer_pool.h" 22 #include <condition_variable> 23 #include <list> 24 #include <memory> 25 #include <mutex> 26 #include <utility> 27 28 namespace OHOS::Camera { 29 class BufferPool : public IBufferPool { 30 public: 31 BufferPool(); 32 virtual ~BufferPool(); 33 34 RetCode Init(const uint32_t width, 35 const uint32_t height, 36 const uint64_t usage, 37 const uint32_t bufferFormat, 38 const uint32_t count, 39 const int32_t bufferSourceType) override; 40 RetCode AddBuffer(std::shared_ptr<IBuffer>& buffer) override; 41 std::shared_ptr<IBuffer> AcquireBuffer(int timeout) override; 42 RetCode ReturnBuffer(std::shared_ptr<IBuffer>& buffer) override; 43 void EnableTracking(const int32_t id) override; 44 void SetId(const int64_t id) override; 45 void NotifyStop() override; 46 void NotifyStart() override; 47 void ClearBuffers() override; 48 uint32_t GetIdleBufferCount() override; 49 50 private: 51 RetCode PrepareBuffer(); 52 RetCode DestroyBuffer(); 53 54 private: 55 std::mutex lock_; 56 std::condition_variable cv_; 57 std::atomic_bool stop_ = false; 58 int64_t poolId_ = -1; 59 int32_t trackingId_ = -1; 60 uint32_t bufferCount_ = 0; 61 uint32_t bufferWidth_ = 0; 62 uint32_t bufferHeight_ = 0; 63 uint64_t bufferUsage_ = 0; 64 uint32_t bufferFormat_ = CAMERA_FORMAT_INVALID; 65 int32_t bufferSourceType_ = CAMERA_BUFFER_SOURCE_TYPE_NONE; 66 std::shared_ptr<IBufferAllocator> bufferAllocator_ = nullptr; 67 std::list<std::shared_ptr<IBuffer>> idleList_ = {}; 68 std::list<std::shared_ptr<IBuffer>> busyList_ = {}; 69 }; 70 } // namespace OHOS::Camera 71 #endif 72