• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class C2PlatformStorePluginLoader {
39 public:
40     static const std::unique_ptr<C2PlatformStorePluginLoader>& GetInstance();
41     ~C2PlatformStorePluginLoader();
42 
43     /**
44      * Creates block pool from platform store extension.
45      *
46      * \param alloctorId  the ID of the backing allocator type.
47      * \param blockPoolId the ID of created block pool.
48      * \param pool        shared pointer where the created block pool is stored.
49      *
50      * \retval C2_OK        the block pool was created successfully.
51      * \retval C2_NOT_FOUND the extension symbol was not found.
52      * \retval C2_BAD_INDEX the input allocatorId is not defined in platform store extension.
53      */
54     c2_status_t createBlockPool(::C2Allocator::id_t allocatorId,
55                                 ::C2BlockPool::local_id_t blockPoolId,
56                                 std::shared_ptr<C2BlockPool>* pool);
57 
58 private:
59     explicit C2PlatformStorePluginLoader(const char *libPath);
60 
61     static android::Mutex sMutex;
62     static std::unique_ptr<C2PlatformStorePluginLoader> sInstance;
63 
64     void *mLibHandle;
65     CreateBlockPoolFunc mCreateBlockPool;
66 };
67 
68 #endif  // STAGEFRIGHT_C2_PLATFORM_STORE_PLUGIN_LOADER_H_
69