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 gralloc backed platform allocator. 52 * 53 * C2Handle layout is not public. Use C2AllocatorGralloc::UnwrapNativeCodec2GrallocHandle 54 * to get the underlying gralloc handle from a C2Handle, and WrapNativeCodec2GrallocHandle 55 * to create a C2Handle from a gralloc handle - for C2Allocator::priorAllocation. 56 */ 57 GRALLOC, 58 59 /** 60 * ID of the bufferqueue backed platform allocator. 61 * 62 * C2Handle layout is not public. Use C2AllocatorGralloc::UnwrapNativeCodec2GrallocHandle 63 * to get the underlying handle from a C2Handle, and WrapNativeCodec2GrallocHandle 64 * to create a C2Handle from a handle - for C2Allocator::priorAllocation. 65 */ 66 BUFFERQUEUE, 67 68 /** 69 * ID of the gralloc backed platform allocator for linear blob buffer. 70 * 71 * C2Handle layout is not public. Use C2AllocatorGralloc::UnwrapNativeCodec2GrallocHandle 72 * to get the underlying gralloc handle from a C2Handle, and WrapNativeCodec2GrallocHandle 73 * to create a C2Handle from a gralloc handle - for C2Allocator::priorAllocation. 74 */ 75 BLOB, 76 77 /** 78 * ID of indicating the end of platform allocator definition. 79 * 80 * \note always put this macro in the last place. 81 * 82 * Extended platform store plugin should use this macro as the start ID of its own allocator 83 * types. 84 */ 85 PLATFORM_END, 86 }; 87 }; 88 89 /** 90 * Retrieves a block pool for a component. 91 * 92 * \param id the local ID of the block pool 93 * \param component the component using the block pool (must be non-null) 94 * \param pool pointer to where the obtained block pool shall be stored on success. nullptr 95 * will be stored here on failure 96 * 97 * \retval C2_OK the operation was successful 98 * \retval C2_BAD_VALUE the component is null 99 * \retval C2_NOT_FOUND if the block pool does not exist 100 * \retval C2_NO_MEMORY not enough memory to fetch the block pool (this return value is only 101 * possible for basic pools) 102 * \retval C2_TIMED_OUT the operation timed out (this return value is only possible for basic pools) 103 * \retval C2_REFUSED no permission to complete any required allocation (this return value is only 104 * possible for basic pools) 105 * \retval C2_CORRUPTED some unknown, unrecoverable error occured during operation (unexpected, 106 * this return value is only possible for basic pools) 107 */ 108 c2_status_t GetCodec2BlockPool( 109 C2BlockPool::local_id_t id, std::shared_ptr<const C2Component> component, 110 std::shared_ptr<C2BlockPool> *pool); 111 112 /** 113 * Creates a block pool. 114 * \param allocatorId the allocator ID which is used to allocate blocks 115 * \param component the component using the block pool (must be non-null) 116 * \param pool pointer to where the created block pool shall be store on success. 117 * nullptr will be stored here on failure 118 * 119 * \retval C2_OK the operation was successful 120 * \retval C2_BAD_VALUE the component is null 121 * \retval C2_NOT_FOUND if the allocator does not exist 122 * \retval C2_NO_MEMORY not enough memory to create a block pool 123 */ 124 c2_status_t CreateCodec2BlockPool( 125 C2PlatformAllocatorStore::id_t allocatorId, 126 std::shared_ptr<const C2Component> component, 127 std::shared_ptr<C2BlockPool> *pool); 128 129 /** 130 * Returns the platform component store. 131 * \retval nullptr if the platform component store could not be obtained 132 */ 133 std::shared_ptr<C2ComponentStore> GetCodec2PlatformComponentStore(); 134 135 /** 136 * Sets the preferred component store in this process for the sole purpose of accessing its 137 * interface. If this is not called, the default IComponentStore HAL (if exists) is the preferred 138 * store for this purpose. If the default IComponentStore HAL is not present, the platform 139 * component store is used. 140 */ 141 void SetPreferredCodec2ComponentStore(std::shared_ptr<C2ComponentStore> store); 142 143 /** 144 * Returns the pool mask. 145 * \retval the default pool mask should be adopted if it could not be obtained from property 146 * "debug.stagefright.c2-poolmask" 147 */ 148 int GetCodec2PoolMask(); 149 150 /** 151 * Returns the preferred linear buffer allocator id from param poolMask. 152 * C2PlatformAllocatorStore::ION should be chosen as fallback allocator if BLOB is not enabled from 153 * param poolMask. 154 */ 155 C2PlatformAllocatorStore::id_t GetPreferredLinearAllocatorId(int poolMask); 156 157 } // namespace android 158 159 #endif // STAGEFRIGHT_CODEC2_PLATFORM_SUPPORT_H_ 160