1 /* 2 * Copyright (C) 2011 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 //#define LOG_NDEBUG 0 18 #define LOG_TAG "SoftOMXComponent" 19 #include <utils/Log.h> 20 21 #include "include/SoftOMXComponent.h" 22 23 #include <media/stagefright/foundation/ADebug.h> 24 25 namespace android { 26 27 SoftOMXComponent::SoftOMXComponent( 28 const char *name, 29 const OMX_CALLBACKTYPE *callbacks, 30 OMX_PTR appData, 31 OMX_COMPONENTTYPE **component) 32 : mName(name), 33 mCallbacks(callbacks), 34 mComponent(new OMX_COMPONENTTYPE), 35 mLibHandle(NULL) { 36 mComponent->nSize = sizeof(*mComponent); 37 mComponent->nVersion.s.nVersionMajor = 1; 38 mComponent->nVersion.s.nVersionMinor = 0; 39 mComponent->nVersion.s.nRevision = 0; 40 mComponent->nVersion.s.nStep = 0; 41 mComponent->pComponentPrivate = this; 42 mComponent->pApplicationPrivate = appData; 43 44 mComponent->GetComponentVersion = NULL; 45 mComponent->SendCommand = SendCommandWrapper; 46 mComponent->GetParameter = GetParameterWrapper; 47 mComponent->SetParameter = SetParameterWrapper; 48 mComponent->GetConfig = GetConfigWrapper; 49 mComponent->SetConfig = SetConfigWrapper; 50 mComponent->GetExtensionIndex = GetExtensionIndexWrapper; 51 mComponent->GetState = GetStateWrapper; 52 mComponent->ComponentTunnelRequest = NULL; 53 mComponent->UseBuffer = UseBufferWrapper; 54 mComponent->AllocateBuffer = AllocateBufferWrapper; 55 mComponent->FreeBuffer = FreeBufferWrapper; 56 mComponent->EmptyThisBuffer = EmptyThisBufferWrapper; 57 mComponent->FillThisBuffer = FillThisBufferWrapper; 58 mComponent->SetCallbacks = NULL; 59 mComponent->ComponentDeInit = NULL; 60 mComponent->UseEGLImage = NULL; 61 mComponent->ComponentRoleEnum = NULL; 62 63 *component = mComponent; 64 } 65 66 SoftOMXComponent::~SoftOMXComponent() { 67 delete mComponent; 68 mComponent = NULL; 69 } 70 71 void SoftOMXComponent::setLibHandle(void *libHandle) { 72 CHECK(libHandle != NULL); 73 mLibHandle = libHandle; 74 } 75 76 void *SoftOMXComponent::libHandle() const { 77 return mLibHandle; 78 } 79 80 OMX_ERRORTYPE SoftOMXComponent::initCheck() const { 81 return OMX_ErrorNone; 82 } 83 84 const char *SoftOMXComponent::name() const { 85 return mName.c_str(); 86 } 87 88 void SoftOMXComponent::notify( 89 OMX_EVENTTYPE event, 90 OMX_U32 data1, OMX_U32 data2, OMX_PTR data) { 91 (*mCallbacks->EventHandler)( 92 mComponent, 93 mComponent->pApplicationPrivate, 94 event, 95 data1, 96 data2, 97 data); 98 } 99 100 void SoftOMXComponent::notifyEmptyBufferDone(OMX_BUFFERHEADERTYPE *header) { 101 (*mCallbacks->EmptyBufferDone)( 102 mComponent, mComponent->pApplicationPrivate, header); 103 } 104 105 void SoftOMXComponent::notifyFillBufferDone(OMX_BUFFERHEADERTYPE *header) { 106 (*mCallbacks->FillBufferDone)( 107 mComponent, mComponent->pApplicationPrivate, header); 108 } 109 110 // static 111 OMX_ERRORTYPE SoftOMXComponent::SendCommandWrapper( 112 OMX_HANDLETYPE component, 113 OMX_COMMANDTYPE cmd, 114 OMX_U32 param, 115 OMX_PTR data) { 116 SoftOMXComponent *me = 117 (SoftOMXComponent *) 118 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 119 120 return me->sendCommand(cmd, param, data); 121 } 122 123 // static 124 OMX_ERRORTYPE SoftOMXComponent::GetParameterWrapper( 125 OMX_HANDLETYPE component, 126 OMX_INDEXTYPE index, 127 OMX_PTR params) { 128 SoftOMXComponent *me = 129 (SoftOMXComponent *) 130 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 131 132 return me->getParameter(index, params); 133 } 134 135 // static 136 OMX_ERRORTYPE SoftOMXComponent::SetParameterWrapper( 137 OMX_HANDLETYPE component, 138 OMX_INDEXTYPE index, 139 OMX_PTR params) { 140 SoftOMXComponent *me = 141 (SoftOMXComponent *) 142 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 143 144 return me->setParameter(index, params); 145 } 146 147 // static 148 OMX_ERRORTYPE SoftOMXComponent::GetConfigWrapper( 149 OMX_HANDLETYPE component, 150 OMX_INDEXTYPE index, 151 OMX_PTR params) { 152 SoftOMXComponent *me = 153 (SoftOMXComponent *) 154 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 155 156 return me->getConfig(index, params); 157 } 158 159 // static 160 OMX_ERRORTYPE SoftOMXComponent::SetConfigWrapper( 161 OMX_HANDLETYPE component, 162 OMX_INDEXTYPE index, 163 OMX_PTR params) { 164 SoftOMXComponent *me = 165 (SoftOMXComponent *) 166 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 167 168 return me->setConfig(index, params); 169 } 170 171 // static 172 OMX_ERRORTYPE SoftOMXComponent::GetExtensionIndexWrapper( 173 OMX_HANDLETYPE component, 174 OMX_STRING name, 175 OMX_INDEXTYPE *index) { 176 SoftOMXComponent *me = 177 (SoftOMXComponent *) 178 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 179 180 return me->getExtensionIndex(name, index); 181 } 182 183 // static 184 OMX_ERRORTYPE SoftOMXComponent::UseBufferWrapper( 185 OMX_HANDLETYPE component, 186 OMX_BUFFERHEADERTYPE **buffer, 187 OMX_U32 portIndex, 188 OMX_PTR appPrivate, 189 OMX_U32 size, 190 OMX_U8 *ptr) { 191 SoftOMXComponent *me = 192 (SoftOMXComponent *) 193 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 194 195 return me->useBuffer(buffer, portIndex, appPrivate, size, ptr); 196 } 197 198 // static 199 OMX_ERRORTYPE SoftOMXComponent::AllocateBufferWrapper( 200 OMX_HANDLETYPE component, 201 OMX_BUFFERHEADERTYPE **buffer, 202 OMX_U32 portIndex, 203 OMX_PTR appPrivate, 204 OMX_U32 size) { 205 SoftOMXComponent *me = 206 (SoftOMXComponent *) 207 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 208 209 return me->allocateBuffer(buffer, portIndex, appPrivate, size); 210 } 211 212 // static 213 OMX_ERRORTYPE SoftOMXComponent::FreeBufferWrapper( 214 OMX_HANDLETYPE component, 215 OMX_U32 portIndex, 216 OMX_BUFFERHEADERTYPE *buffer) { 217 SoftOMXComponent *me = 218 (SoftOMXComponent *) 219 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 220 221 return me->freeBuffer(portIndex, buffer); 222 } 223 224 // static 225 OMX_ERRORTYPE SoftOMXComponent::EmptyThisBufferWrapper( 226 OMX_HANDLETYPE component, 227 OMX_BUFFERHEADERTYPE *buffer) { 228 SoftOMXComponent *me = 229 (SoftOMXComponent *) 230 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 231 232 return me->emptyThisBuffer(buffer); 233 } 234 235 // static 236 OMX_ERRORTYPE SoftOMXComponent::FillThisBufferWrapper( 237 OMX_HANDLETYPE component, 238 OMX_BUFFERHEADERTYPE *buffer) { 239 SoftOMXComponent *me = 240 (SoftOMXComponent *) 241 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 242 243 return me->fillThisBuffer(buffer); 244 } 245 246 // static 247 OMX_ERRORTYPE SoftOMXComponent::GetStateWrapper( 248 OMX_HANDLETYPE component, 249 OMX_STATETYPE *state) { 250 SoftOMXComponent *me = 251 (SoftOMXComponent *) 252 ((OMX_COMPONENTTYPE *)component)->pComponentPrivate; 253 254 return me->getState(state); 255 } 256 257 //////////////////////////////////////////////////////////////////////////////// 258 259 OMX_ERRORTYPE SoftOMXComponent::sendCommand( 260 OMX_COMMANDTYPE cmd, OMX_U32 param, OMX_PTR data) { 261 return OMX_ErrorUndefined; 262 } 263 264 OMX_ERRORTYPE SoftOMXComponent::getParameter( 265 OMX_INDEXTYPE index, OMX_PTR params) { 266 return OMX_ErrorUndefined; 267 } 268 269 OMX_ERRORTYPE SoftOMXComponent::setParameter( 270 OMX_INDEXTYPE index, const OMX_PTR params) { 271 return OMX_ErrorUndefined; 272 } 273 274 OMX_ERRORTYPE SoftOMXComponent::getConfig( 275 OMX_INDEXTYPE index, OMX_PTR params) { 276 return OMX_ErrorUndefined; 277 } 278 279 OMX_ERRORTYPE SoftOMXComponent::setConfig( 280 OMX_INDEXTYPE index, const OMX_PTR params) { 281 return OMX_ErrorUndefined; 282 } 283 284 OMX_ERRORTYPE SoftOMXComponent::getExtensionIndex( 285 const char *name, OMX_INDEXTYPE *index) { 286 return OMX_ErrorUndefined; 287 } 288 289 OMX_ERRORTYPE SoftOMXComponent::useBuffer( 290 OMX_BUFFERHEADERTYPE **buffer, 291 OMX_U32 portIndex, 292 OMX_PTR appPrivate, 293 OMX_U32 size, 294 OMX_U8 *ptr) { 295 return OMX_ErrorUndefined; 296 } 297 298 OMX_ERRORTYPE SoftOMXComponent::allocateBuffer( 299 OMX_BUFFERHEADERTYPE **buffer, 300 OMX_U32 portIndex, 301 OMX_PTR appPrivate, 302 OMX_U32 size) { 303 return OMX_ErrorUndefined; 304 } 305 306 OMX_ERRORTYPE SoftOMXComponent::freeBuffer( 307 OMX_U32 portIndex, 308 OMX_BUFFERHEADERTYPE *buffer) { 309 return OMX_ErrorUndefined; 310 } 311 312 OMX_ERRORTYPE SoftOMXComponent::emptyThisBuffer( 313 OMX_BUFFERHEADERTYPE *buffer) { 314 return OMX_ErrorUndefined; 315 } 316 317 OMX_ERRORTYPE SoftOMXComponent::fillThisBuffer( 318 OMX_BUFFERHEADERTYPE *buffer) { 319 return OMX_ErrorUndefined; 320 } 321 322 OMX_ERRORTYPE SoftOMXComponent::getState(OMX_STATETYPE *state) { 323 return OMX_ErrorUndefined; 324 } 325 326 } // namespace android 327