1 /* 2 * Copyright (C) 2009 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 #include "OMXComponentBase.h" 18 19 #include <stdlib.h> 20 21 #include <media/stagefright/MediaDebug.h> 22 23 namespace android { 24 25 OMXComponentBase::OMXComponentBase( 26 const OMX_CALLBACKTYPE *callbacks, 27 OMX_PTR appData) 28 : mCallbacks(callbacks), 29 mAppData(appData), 30 mComponentHandle(NULL) { 31 } 32 33 OMXComponentBase::~OMXComponentBase() {} 34 35 void OMXComponentBase::setComponentHandle(OMX_COMPONENTTYPE *handle) { 36 CHECK_EQ(mComponentHandle, NULL); 37 mComponentHandle = handle; 38 } 39 40 void OMXComponentBase::postEvent( 41 OMX_EVENTTYPE event, OMX_U32 param1, OMX_U32 param2) { 42 (*mCallbacks->EventHandler)( 43 mComponentHandle, mAppData, event, param1, param2, NULL); 44 } 45 46 void OMXComponentBase::postFillBufferDone(OMX_BUFFERHEADERTYPE *bufHdr) { 47 (*mCallbacks->FillBufferDone)(mComponentHandle, mAppData, bufHdr); 48 } 49 50 void OMXComponentBase::postEmptyBufferDone(OMX_BUFFERHEADERTYPE *bufHdr) { 51 (*mCallbacks->EmptyBufferDone)(mComponentHandle, mAppData, bufHdr); 52 } 53 54 static OMXComponentBase *getBase(OMX_HANDLETYPE hComponent) { 55 return (OMXComponentBase *) 56 ((OMX_COMPONENTTYPE *)hComponent)->pComponentPrivate; 57 } 58 59 static OMX_ERRORTYPE SendCommandWrapper( 60 OMX_IN OMX_HANDLETYPE hComponent, 61 OMX_IN OMX_COMMANDTYPE Cmd, 62 OMX_IN OMX_U32 nParam1, 63 OMX_IN OMX_PTR pCmdData) { 64 return getBase(hComponent)->sendCommand(Cmd, nParam1, pCmdData); 65 } 66 67 static OMX_ERRORTYPE GetParameterWrapper( 68 OMX_IN OMX_HANDLETYPE hComponent, 69 OMX_IN OMX_INDEXTYPE nParamIndex, 70 OMX_INOUT OMX_PTR pComponentParameterStructure) { 71 return getBase(hComponent)->getParameter( 72 nParamIndex, pComponentParameterStructure); 73 } 74 75 static OMX_ERRORTYPE SetParameterWrapper( 76 OMX_IN OMX_HANDLETYPE hComponent, 77 OMX_IN OMX_INDEXTYPE nIndex, 78 OMX_IN OMX_PTR pComponentParameterStructure) { 79 return getBase(hComponent)->getParameter( 80 nIndex, pComponentParameterStructure); 81 } 82 83 static OMX_ERRORTYPE GetConfigWrapper( 84 OMX_IN OMX_HANDLETYPE hComponent, 85 OMX_IN OMX_INDEXTYPE nIndex, 86 OMX_INOUT OMX_PTR pComponentConfigStructure) { 87 return getBase(hComponent)->getConfig(nIndex, pComponentConfigStructure); 88 } 89 90 static OMX_ERRORTYPE SetConfigWrapper( 91 OMX_IN OMX_HANDLETYPE hComponent, 92 OMX_IN OMX_INDEXTYPE nIndex, 93 OMX_IN OMX_PTR pComponentConfigStructure) { 94 return getBase(hComponent)->setConfig(nIndex, pComponentConfigStructure); 95 } 96 97 static OMX_ERRORTYPE GetExtensionIndexWrapper( 98 OMX_IN OMX_HANDLETYPE hComponent, 99 OMX_IN OMX_STRING cParameterName, 100 OMX_OUT OMX_INDEXTYPE* pIndexType) { 101 return getBase(hComponent)->getExtensionIndex(cParameterName, pIndexType); 102 } 103 104 static OMX_ERRORTYPE GetStateWrapper( 105 OMX_IN OMX_HANDLETYPE hComponent, 106 OMX_OUT OMX_STATETYPE* pState) { 107 return getBase(hComponent)->getState(pState); 108 } 109 110 static OMX_ERRORTYPE UseBufferWrapper( 111 OMX_IN OMX_HANDLETYPE hComponent, 112 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr, 113 OMX_IN OMX_U32 nPortIndex, 114 OMX_IN OMX_PTR pAppPrivate, 115 OMX_IN OMX_U32 nSizeBytes, 116 OMX_IN OMX_U8* pBuffer) { 117 return getBase(hComponent)->useBuffer( 118 ppBufferHdr, nPortIndex, pAppPrivate, nSizeBytes, pBuffer); 119 } 120 121 static OMX_ERRORTYPE AllocateBufferWrapper( 122 OMX_IN OMX_HANDLETYPE hComponent, 123 OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer, 124 OMX_IN OMX_U32 nPortIndex, 125 OMX_IN OMX_PTR pAppPrivate, 126 OMX_IN OMX_U32 nSizeBytes) { 127 return getBase(hComponent)->allocateBuffer( 128 ppBuffer, nPortIndex, pAppPrivate, nSizeBytes); 129 } 130 131 static OMX_ERRORTYPE FreeBufferWrapper( 132 OMX_IN OMX_HANDLETYPE hComponent, 133 OMX_IN OMX_U32 nPortIndex, 134 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) { 135 return getBase(hComponent)->freeBuffer(nPortIndex, pBuffer); 136 } 137 138 static OMX_ERRORTYPE EmptyThisBufferWrapper( 139 OMX_IN OMX_HANDLETYPE hComponent, 140 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) { 141 return getBase(hComponent)->emptyThisBuffer(pBuffer); 142 } 143 144 static OMX_ERRORTYPE FillThisBufferWrapper( 145 OMX_IN OMX_HANDLETYPE hComponent, 146 OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) { 147 return getBase(hComponent)->fillThisBuffer(pBuffer); 148 } 149 150 static OMX_ERRORTYPE ComponentDeInitWrapper( 151 OMX_IN OMX_HANDLETYPE hComponent) { 152 delete getBase(hComponent); 153 delete (OMX_COMPONENTTYPE *)hComponent; 154 155 return OMX_ErrorNone; 156 } 157 158 static OMX_ERRORTYPE ComponentRoleEnumWrapper( 159 OMX_IN OMX_HANDLETYPE hComponent, 160 OMX_OUT OMX_U8 *cRole, 161 OMX_IN OMX_U32 nIndex) { 162 return getBase(hComponent)->enumerateRoles(cRole, nIndex); 163 } 164 165 // static 166 OMX_COMPONENTTYPE *OMXComponentBase::MakeComponent(OMXComponentBase *base) { 167 OMX_COMPONENTTYPE *result = new OMX_COMPONENTTYPE; 168 169 result->nSize = sizeof(OMX_COMPONENTTYPE); 170 result->nVersion.s.nVersionMajor = 1; 171 result->nVersion.s.nVersionMinor = 0; 172 result->nVersion.s.nRevision = 0; 173 result->nVersion.s.nStep = 0; 174 result->pComponentPrivate = base; 175 result->pApplicationPrivate = NULL; 176 177 result->GetComponentVersion = NULL; 178 result->SendCommand = SendCommandWrapper; 179 result->GetParameter = GetParameterWrapper; 180 result->SetParameter = SetParameterWrapper; 181 result->GetConfig = GetConfigWrapper; 182 result->SetConfig = SetConfigWrapper; 183 result->GetExtensionIndex = GetExtensionIndexWrapper; 184 result->GetState = GetStateWrapper; 185 result->ComponentTunnelRequest = NULL; 186 result->UseBuffer = UseBufferWrapper; 187 result->AllocateBuffer = AllocateBufferWrapper; 188 result->FreeBuffer = FreeBufferWrapper; 189 result->EmptyThisBuffer = EmptyThisBufferWrapper; 190 result->FillThisBuffer = FillThisBufferWrapper; 191 result->SetCallbacks = NULL; 192 result->ComponentDeInit = ComponentDeInitWrapper; 193 result->UseEGLImage = NULL; 194 result->ComponentRoleEnum = ComponentRoleEnumWrapper; 195 196 base->setComponentHandle(result); 197 198 return result; 199 } 200 201 } // namespace android 202