1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ANDROID_V4L2_CODEC2_PLUGIN_STORE_C2_VDA_POOLED_BLOCK_POOL_H 6 #define ANDROID_V4L2_CODEC2_PLUGIN_STORE_C2_VDA_POOLED_BLOCK_POOL_H 7 8 #include <memory> 9 #include <mutex> 10 #include <optional> 11 #include <set> 12 13 #include <C2Buffer.h> 14 #include <C2BufferPriv.h> 15 #include <C2PlatformSupport.h> 16 #include <android-base/thread_annotations.h> 17 18 namespace android { 19 20 class C2VdaPooledBlockPool : public C2PooledBlockPool { 21 public: 22 using C2PooledBlockPool::C2PooledBlockPool; 23 ~C2VdaPooledBlockPool() override = default; 24 25 // Extracts the buffer ID from BufferPoolData of the graphic block. 26 // |block| is the graphic block allocated by bufferpool block pool. 27 static std::optional<uint32_t> getBufferIdFromGraphicBlock(const C2Block2D& block); 28 29 // Allocate the specified number of buffers. 30 // |bufferCount| is the number of requested buffers. 31 c2_status_t requestNewBufferSet(int32_t bufferCount); 32 33 // Return C2_OK and store a buffer in |block| if a buffer is successfully fetched. 34 // Return C2_TIMED_OUT if the pool already allocated |mBufferCount| buffers but they are all in 35 // use. 36 // Return C2_NO_MEMORY if the pool fails to allocate a new buffer. 37 c2_status_t fetchGraphicBlock(uint32_t width, uint32_t height, uint32_t format, 38 C2MemoryUsage usage, 39 std::shared_ptr<C2GraphicBlock>* block /* nonnull */) override; 40 41 private: 42 // Function mutex to lock at the start of each API function call for protecting the 43 // synchronization of all member variables. 44 std::mutex mMutex; 45 46 // The ids of all allocated buffers. 47 std::set<uint32_t> mBufferIds GUARDED_BY(mMutex); 48 // The maximum count of allocated buffers. GUARDED_BY(mMutex)49 size_t mBufferCount GUARDED_BY(mMutex){0}; 50 }; 51 52 } // namespace android 53 #endif // ANDROID_V4L2_CODEC2_PLUGIN_STORE_C2_VDA_POOLED_BLOCK_POOL_H 54