1 /* 2 * Copyright 2018, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef STAGEFRIGHT_C2_PLATFORM_STORE_PLUGIN_LOADER_H_ 18 19 #define STAGEFRIGHT_C2_PLATFORM_STORE_PLUGIN_LOADER_H_ 20 21 #include <memory> 22 23 #include <utils/Mutex.h> 24 25 #include <C2.h> 26 #include <C2Buffer.h> 27 28 /** 29 * Extern C interface for creating block pool from platform store extension. 30 * 31 * \param alloctorId the ID of the backing allocator type. 32 * \parem blockPoolId the ID of created block pool. 33 * 34 * \return pointer of created C2BlockPool, nullptr on error. 35 */ 36 typedef ::C2BlockPool* (*CreateBlockPoolFunc)(::C2Allocator::id_t, ::C2BlockPool::local_id_t); 37 38 /** 39 * Extern C interface for creating allocator from platform store extension. 40 * 41 * \param alloctorId the ID of the allocator to create. 42 * \param status the returned status from creating allocator. 43 * 44 * \return pointer of created C2Allocator, nullptr on error. 45 */ 46 typedef ::C2Allocator* (*CreateAllocatorFunc)(::C2Allocator::id_t, ::c2_status_t*); 47 48 class C2PlatformStorePluginLoader { 49 public: 50 static const std::unique_ptr<C2PlatformStorePluginLoader>& GetInstance(); 51 ~C2PlatformStorePluginLoader(); 52 53 /** 54 * Creates block pool from platform store extension. 55 * 56 * \param alloctorId the ID of the backing allocator type. 57 * \param blockPoolId the ID of created block pool. 58 * \param pool shared pointer where the created block pool is stored. 59 * 60 * \retval C2_OK the block pool was created successfully. 61 * \retval C2_NOT_FOUND the extension symbol was not found. 62 * \retval C2_BAD_INDEX the input allocatorId is not defined in platform store extension. 63 */ 64 c2_status_t createBlockPool( 65 ::C2Allocator::id_t allocatorId, 66 ::C2BlockPool::local_id_t blockPoolId, 67 std::shared_ptr<C2BlockPool>* pool, 68 std::function<void(C2BlockPool *)> deleter = std::default_delete<C2BlockPool>()); 69 70 /** 71 * Creates allocator from platform store extension. 72 * 73 * Note that this allocator is not created as shared singleton as C2AllocatorStore does, because 74 * C interface only allows raw pointer transmission for extension. 75 * 76 * \param alloctorId the ID of the allocator to create. 77 * \param allocator shared pointer where the created allocator is stored. 78 * 79 * \retval C2_OK the allocator was created successfully. 80 * \retval C2_TIMED_OUT could not create the allocator within the time limit (unexpected) 81 * \retval C2_CORRUPTED some unknown error prevented the creation of the allocator (unexpected) 82 * \retval C2_NOT_FOUND the extension symbol was not found. 83 * \retval C2_BAD_INDEX the input allocatorId is not defined in platform store extension. 84 * \retval C2_NO_MEMORY not enough memory to create the allocator 85 */ 86 c2_status_t createAllocator( 87 ::C2Allocator::id_t allocatorId, 88 std::shared_ptr<C2Allocator>* const allocator, 89 std::function<void(C2Allocator *)> deleter = std::default_delete<C2Allocator>()); 90 91 private: 92 explicit C2PlatformStorePluginLoader(const char *libPath); 93 94 static android::Mutex sMutex; 95 static std::unique_ptr<C2PlatformStorePluginLoader> sInstance; 96 97 void *mLibHandle; 98 CreateBlockPoolFunc mCreateBlockPool; 99 CreateAllocatorFunc mCreateAllocator; 100 }; 101 102 #endif // STAGEFRIGHT_C2_PLATFORM_STORE_PLUGIN_LOADER_H_ 103