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_VENDOR_ALLOCATOR_LOADER_H 6 #define ANDROID_V4L2_CODEC2_PLUGIN_STORE_VENDOR_ALLOCATOR_LOADER_H 7 8 #include <memory> 9 #include <mutex> 10 11 #include <C2Buffer.h> 12 13 namespace android { 14 15 // This class is for loading the vendor-specific C2Allocator implementations. 16 // The vendor should implement the shared library "libv4l2_codec2_vendor_allocator.so" 17 // and expose the function "C2Allocator* CreateAllocator(C2Allocator::id_t allocatorId);". 18 class VendorAllocatorLoader { 19 public: 20 using CreateAllocatorFunc = ::C2Allocator* (*)(C2Allocator::id_t /* allocatorId */); 21 using CreateBlockPoolFunc = ::C2BlockPool* (*)(C2Allocator::id_t /* allocatorId */, 22 C2BlockPool::local_id_t /* poolId */); 23 24 static std::unique_ptr<VendorAllocatorLoader> Create(); 25 ~VendorAllocatorLoader(); 26 27 // Delegate to the vendor's shared library. |allocatorId| should be one of enum listed at 28 // V4L2AllocatorId.h. 29 C2Allocator* createAllocator(C2Allocator::id_t allocatorId); 30 31 C2BlockPool* createBlockPool(C2Allocator::id_t allocatorId, C2BlockPool::local_id_t poolId); 32 33 private: 34 VendorAllocatorLoader(void* libHandle, CreateAllocatorFunc createAllocatorFunc, 35 CreateBlockPoolFunc createBlockPoolFunc); 36 37 void* mLibHandle; 38 CreateAllocatorFunc mCreateAllocatorFunc; 39 CreateBlockPoolFunc mCreateBlockPoolFunc; 40 }; 41 42 } // namespace android 43 #endif // ANDROID_V4L2_CODEC2_PLUGIN_STORE_VENDOR_ALLOCATOR_LOADER_H 44