• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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_CODEC2_PLATFORM_SUPPORT_H_
18 #define STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_
19 
20 #include <C2Component.h>
21 #include <C2ComponentFactory.h>
22 
23 #include <memory>
24 
25 namespace android {
26 
27 /**
28  * Returns the platform allocator store.
29  * \retval nullptr if the platform allocator store could not be obtained
30  */
31 std::shared_ptr<C2AllocatorStore> GetCodec2PlatformAllocatorStore();
32 
33 /**
34  * Platform allocator store IDs
35  */
36 class C2PlatformAllocatorStore : public C2AllocatorStore {
37 public:
38     enum : id_t {
39         /**
40          * ID of the ion backed platform allocator.
41          *
42          * C2Handle consists of:
43          *   fd  shared ion buffer handle
44          *   int size (lo 32 bits)
45          *   int size (hi 32 bits)
46          *   int magic '\xc2io\x00'
47          */
48         ION = PLATFORM_START,
49 
50         /*
51          * ID of the DMA-Buf Heap (ion replacement) backed platform allocator.
52          *
53          * C2Handle consists of:
54          *   fd  shared dmabuf buffer handle
55          *   int size (lo 32 bits)
56          *   int size (hi 32 bits)
57          *   int magic '\xc2io\x00'
58          */
59         DMABUFHEAP = ION,
60 
61         /**
62          * ID of the gralloc backed platform allocator.
63          *
64          * C2Handle layout is not public. Use C2AllocatorGralloc::UnwrapNativeCodec2GrallocHandle
65          * to get the underlying gralloc handle from a C2Handle, and WrapNativeCodec2GrallocHandle
66          * to create a C2Handle from a gralloc handle - for C2Allocator::priorAllocation.
67          */
68         GRALLOC,
69 
70         /**
71          * ID of the bufferqueue backed platform allocator.
72          *
73          * C2Handle layout is not public. Use C2AllocatorGralloc::UnwrapNativeCodec2GrallocHandle
74          * to get the underlying handle from a C2Handle, and WrapNativeCodec2GrallocHandle
75          * to create a C2Handle from a handle - for C2Allocator::priorAllocation.
76          */
77         BUFFERQUEUE,
78 
79         /**
80          * ID of the gralloc backed platform allocator for linear blob buffer.
81          *
82          * C2Handle layout is not public. Use C2AllocatorGralloc::UnwrapNativeCodec2GrallocHandle
83          * to get the underlying gralloc handle from a C2Handle, and WrapNativeCodec2GrallocHandle
84          * to create a C2Handle from a gralloc handle - for C2Allocator::priorAllocation.
85          */
86         BLOB,
87 
88         /**
89          * ID of indicating the end of platform allocator definition.
90          *
91          * \note always put this macro in the last place.
92          *
93          * Extended platform store plugin should use this macro as the start ID of its own allocator
94          * types.
95          */
96         PLATFORM_END,
97     };
98 };
99 
100 /**
101  * Retrieves a block pool for a component.
102  *
103  * \param id        the local ID of the block pool
104  * \param component the component using the block pool (must be non-null)
105  * \param pool      pointer to where the obtained block pool shall be stored on success. nullptr
106  *                  will be stored here on failure
107  *
108  * \retval C2_OK        the operation was successful
109  * \retval C2_BAD_VALUE the component is null
110  * \retval C2_NOT_FOUND if the block pool does not exist
111  * \retval C2_NO_MEMORY not enough memory to fetch the block pool (this return value is only
112  *                      possible for basic pools)
113  * \retval C2_TIMED_OUT the operation timed out (this return value is only possible for basic pools)
114  * \retval C2_REFUSED   no permission to complete any required allocation (this return value is only
115  *                      possible for basic pools)
116  * \retval C2_CORRUPTED some unknown, unrecoverable error occured during operation (unexpected,
117  *                      this return value is only possible for basic pools)
118  */
119 c2_status_t GetCodec2BlockPool(
120         C2BlockPool::local_id_t id, std::shared_ptr<const C2Component> component,
121         std::shared_ptr<C2BlockPool> *pool);
122 
123 /**
124  * Creates a block pool.
125  * \param allocatorId  the allocator ID which is used to allocate blocks
126  * \param component     the component using the block pool (must be non-null)
127  * \param pool          pointer to where the created block pool shall be store on success.
128  *                      nullptr will be stored here on failure
129  *
130  * \retval C2_OK        the operation was successful
131  * \retval C2_BAD_VALUE the component is null
132  * \retval C2_NOT_FOUND if the allocator does not exist
133  * \retval C2_NO_MEMORY not enough memory to create a block pool
134  */
135 c2_status_t CreateCodec2BlockPool(
136         C2PlatformAllocatorStore::id_t allocatorId,
137         std::shared_ptr<const C2Component> component,
138         std::shared_ptr<C2BlockPool> *pool);
139 
140 /**
141  * Creates a block pool.
142  * \param allocatorId  the allocator ID which is used to allocate blocks
143  * \param components    the components using the block pool
144  * \param pool          pointer to where the created block pool shall be store on success.
145  *                      nullptr will be stored here on failure
146  *
147  * \retval C2_OK        the operation was successful
148  * \retval C2_BAD_VALUE the component is null
149  * \retval C2_NOT_FOUND if the allocator does not exist
150  * \retval C2_NO_MEMORY not enough memory to create a block pool
151  */
152 c2_status_t CreateCodec2BlockPool(
153         C2PlatformAllocatorStore::id_t allocatorId,
154         const std::vector<std::shared_ptr<const C2Component>> &components,
155         std::shared_ptr<C2BlockPool> *pool);
156 
157 /**
158  * Returns the platform component store.
159  * \retval nullptr if the platform component store could not be obtained
160  */
161 std::shared_ptr<C2ComponentStore> GetCodec2PlatformComponentStore();
162 
163 /**
164  * Returns the platform component store.
165  * NOTE: For testing only
166  * \retval nullptr if the platform component store could not be obtained
167  */
168 std::shared_ptr<C2ComponentStore> GetTestComponentStore(
169         std::vector<std::tuple<C2String, C2ComponentFactory::CreateCodec2FactoryFunc,
170         C2ComponentFactory::DestroyCodec2FactoryFunc>>);
171 
172 /**
173  * Sets the preferred component store in this process for the sole purpose of accessing its
174  * interface. If this is not called, the default IComponentStore HAL (if exists) is the preferred
175  * store for this purpose. If the default IComponentStore HAL is not present, the platform
176  * component store is used.
177  */
178 void SetPreferredCodec2ComponentStore(std::shared_ptr<C2ComponentStore> store);
179 
180 /**
181  * Returns the pool mask.
182  * \retval the default pool mask should be adopted if it could not be obtained from property
183  *         "debug.stagefright.c2-poolmask"
184  */
185 int GetCodec2PoolMask();
186 
187 /**
188  * Returns the preferred linear buffer allocator id from param poolMask.
189  * C2PlatformAllocatorStore::ION should be chosen as fallback allocator if BLOB is not enabled from
190  * param poolMask.
191  */
192 C2PlatformAllocatorStore::id_t GetPreferredLinearAllocatorId(int poolMask);
193 
194 } // namespace android
195 
196 #endif // STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_
197