1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2009, Code Aurora Forum. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions are met: 6 * Redistributions of source code must retain the above copyright 7 notice, this list of conditions and the following disclaimer. 8 * Redistributions in binary form must reproduce the above copyright 9 notice, this list of conditions and the following disclaimer in the 10 documentation and/or other materials provided with the distribution. 11 * Neither the name of Code Aurora nor 12 the names of its contributors may be used to endorse or promote 13 products derived from this software without specific prior written 14 permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 --------------------------------------------------------------------------*/ 28 /*============================================================================ 29 O p e n M A X w r a p p e r s 30 O p e n M A X C o r e 31 32 This module contains the implementation of the OpenMAX core Macros which 33 operate directly on the component. 34 35 *//*========================================================================*/ 36 37 ////////////////////////////////////////////////////////////////////////////// 38 // Include Files 39 ////////////////////////////////////////////////////////////////////////////// 40 #include "qc_omx_common.h" 41 #include "omx_core_cmp.h" 42 #include "qc_omx_component.h" 43 #include <string.h> 44 45 46 void * qc_omx_create_component_wrapper(OMX_PTR obj_ptr) 47 { 48 qc_omx_component *pThis = (qc_omx_component *)obj_ptr; 49 OMX_COMPONENTTYPE* component = &(pThis->m_cmp); 50 memset(&pThis->m_cmp,0,sizeof(OMX_COMPONENTTYPE)); 51 52 component->nSize = sizeof(OMX_COMPONENTTYPE); 53 component->nVersion.nVersion = OMX_SPEC_VERSION; 54 component->pApplicationPrivate = 0; 55 component->pComponentPrivate = obj_ptr; 56 57 component->AllocateBuffer = &qc_omx_component_allocate_buffer; 58 component->FreeBuffer = &qc_omx_component_free_buffer; 59 component->GetParameter = &qc_omx_component_get_parameter; 60 component->SetParameter = &qc_omx_component_set_parameter; 61 component->SendCommand = &qc_omx_component_send_command; 62 component->FillThisBuffer = &qc_omx_component_fill_this_buffer; 63 component->EmptyThisBuffer = &qc_omx_component_empty_this_buffer; 64 component->GetState = &qc_omx_component_get_state; 65 component->GetComponentVersion = &qc_omx_component_get_version; 66 component->GetConfig = &qc_omx_component_get_config; 67 component->SetConfig = &qc_omx_component_set_config; 68 component->GetExtensionIndex = &qc_omx_component_get_extension_index; 69 component->ComponentTunnelRequest = &qc_omx_component_tunnel_request; 70 component->UseBuffer = &qc_omx_component_use_buffer; 71 component->SetCallbacks = &qc_omx_component_set_callbacks; 72 component->UseEGLImage = &qc_omx_component_use_EGL_image; 73 component->ComponentRoleEnum = &qc_omx_component_role_enum; 74 component->ComponentDeInit = &qc_omx_component_deinit; 75 return (void *)component; 76 } 77 78 79 80 /************************************************************************/ 81 /* COMPONENT INTERFACE */ 82 /************************************************************************/ 83 84 OMX_ERRORTYPE 85 qc_omx_component_init(OMX_IN OMX_HANDLETYPE hComp, OMX_IN OMX_STRING componentName) 86 { 87 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 88 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 89 DEBUG_PRINT("OMXCORE: qc_omx_component_init %x\n",(unsigned)hComp); 90 91 if(pThis) 92 { 93 // call the init fuction 94 eRet = pThis->component_init(componentName); 95 96 if(eRet != OMX_ErrorNone) 97 { 98 // in case of error, please destruct the component created 99 delete pThis; 100 } 101 } 102 return eRet; 103 } 104 105 106 OMX_ERRORTYPE 107 qc_omx_component_get_version(OMX_IN OMX_HANDLETYPE hComp, 108 OMX_OUT OMX_STRING componentName, 109 OMX_OUT OMX_VERSIONTYPE* componentVersion, 110 OMX_OUT OMX_VERSIONTYPE* specVersion, 111 OMX_OUT OMX_UUIDTYPE* componentUUID) 112 { 113 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 114 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 115 DEBUG_PRINT("OMXCORE: qc_omx_component_get_version %x, %s , %x\n",(unsigned)hComp,componentName,(unsigned)componentVersion); 116 if(pThis) 117 { 118 eRet = pThis->get_component_version(hComp,componentName,componentVersion,specVersion,componentUUID); 119 } 120 return eRet; 121 } 122 123 OMX_ERRORTYPE 124 qc_omx_component_send_command(OMX_IN OMX_HANDLETYPE hComp, 125 OMX_IN OMX_COMMANDTYPE cmd, 126 OMX_IN OMX_U32 param1, 127 OMX_IN OMX_PTR cmdData) 128 { 129 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 130 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 131 DEBUG_PRINT("OMXCORE: qc_omx_component_send_command %x, %d , %d\n",(unsigned)hComp,(unsigned)cmd,(unsigned)param1); 132 133 if(pThis) 134 { 135 eRet = pThis->send_command(hComp,cmd,param1,cmdData); 136 } 137 return eRet; 138 } 139 140 OMX_ERRORTYPE 141 qc_omx_component_get_parameter(OMX_IN OMX_HANDLETYPE hComp, 142 OMX_IN OMX_INDEXTYPE paramIndex, 143 OMX_INOUT OMX_PTR paramData) 144 { 145 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 146 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 147 DEBUG_PRINT("OMXCORE: qc_omx_component_get_parameter %x, %x , %d\n",(unsigned)hComp,(unsigned)paramData,paramIndex); 148 149 if(pThis) 150 { 151 eRet = pThis->get_parameter(hComp,paramIndex,paramData); 152 } 153 return eRet; 154 } 155 156 OMX_ERRORTYPE 157 qc_omx_component_set_parameter(OMX_IN OMX_HANDLETYPE hComp, 158 OMX_IN OMX_INDEXTYPE paramIndex, 159 OMX_IN OMX_PTR paramData) 160 { 161 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 162 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 163 DEBUG_PRINT("OMXCORE: qc_omx_component_set_parameter %x, %x , %d\n",(unsigned)hComp,(unsigned)paramData,paramIndex); 164 165 if(pThis) 166 { 167 eRet = pThis->set_parameter(hComp,paramIndex,paramData); 168 } 169 return eRet; 170 } 171 172 OMX_ERRORTYPE 173 qc_omx_component_get_config(OMX_IN OMX_HANDLETYPE hComp, 174 OMX_IN OMX_INDEXTYPE configIndex, 175 OMX_INOUT OMX_PTR configData) 176 { 177 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 178 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 179 DEBUG_PRINT("OMXCORE: qc_omx_component_get_config %x\n",(unsigned)hComp); 180 181 if(pThis) 182 { 183 eRet = pThis->get_config(hComp, 184 configIndex, 185 configData); 186 } 187 return eRet; 188 } 189 190 OMX_ERRORTYPE 191 qc_omx_component_set_config(OMX_IN OMX_HANDLETYPE hComp, 192 OMX_IN OMX_INDEXTYPE configIndex, 193 OMX_IN OMX_PTR configData) 194 { 195 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 196 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 197 DEBUG_PRINT("OMXCORE: qc_omx_component_set_config %x\n",(unsigned)hComp); 198 199 if(pThis) 200 { 201 eRet = pThis->set_config(hComp, 202 configIndex, 203 configData); 204 } 205 return eRet; 206 } 207 208 OMX_ERRORTYPE 209 qc_omx_component_get_extension_index(OMX_IN OMX_HANDLETYPE hComp, 210 OMX_IN OMX_STRING paramName, 211 OMX_OUT OMX_INDEXTYPE* indexType) 212 { 213 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 214 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 215 if(pThis) 216 { 217 eRet = pThis->get_extension_index(hComp,paramName,indexType); 218 } 219 return eRet; 220 } 221 222 OMX_ERRORTYPE 223 qc_omx_component_get_state(OMX_IN OMX_HANDLETYPE hComp, 224 OMX_OUT OMX_STATETYPE* state) 225 { 226 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 227 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 228 DEBUG_PRINT("OMXCORE: qc_omx_component_get_state %x\n",(unsigned)hComp); 229 230 if(pThis) 231 { 232 eRet = pThis->get_state(hComp,state); 233 } 234 return eRet; 235 } 236 237 OMX_ERRORTYPE 238 qc_omx_component_tunnel_request(OMX_IN OMX_HANDLETYPE hComp, 239 OMX_IN OMX_U32 port, 240 OMX_IN OMX_HANDLETYPE peerComponent, 241 OMX_IN OMX_U32 peerPort, 242 OMX_INOUT OMX_TUNNELSETUPTYPE* tunnelSetup) 243 { 244 DEBUG_PRINT("Error: qc_omx_component_tunnel_request Not Implemented\n"); 245 return OMX_ErrorNotImplemented; 246 } 247 248 OMX_ERRORTYPE 249 qc_omx_component_use_buffer(OMX_IN OMX_HANDLETYPE hComp, 250 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, 251 OMX_IN OMX_U32 port, 252 OMX_IN OMX_PTR appData, 253 OMX_IN OMX_U32 bytes, 254 OMX_IN OMX_U8* buffer) 255 { 256 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 257 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 258 DEBUG_PRINT("OMXCORE: qc_omx_component_use_buffer %x\n",(unsigned)hComp); 259 260 if(pThis) 261 { 262 eRet = pThis->use_buffer(hComp, 263 bufferHdr, 264 port, 265 appData, 266 bytes, 267 buffer); 268 } 269 return eRet; 270 } 271 272 273 // qc_omx_component_allocate_buffer -- API Call 274 OMX_ERRORTYPE 275 qc_omx_component_allocate_buffer(OMX_IN OMX_HANDLETYPE hComp, 276 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, 277 OMX_IN OMX_U32 port, 278 OMX_IN OMX_PTR appData, 279 OMX_IN OMX_U32 bytes) 280 { 281 282 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 283 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 284 DEBUG_PRINT("OMXCORE: qc_omx_component_allocate_buffer %x, %x , %d\n",(unsigned)hComp,(unsigned)bufferHdr,(unsigned)port); 285 286 if(pThis) 287 { 288 eRet = pThis->allocate_buffer(hComp,bufferHdr,port,appData,bytes); 289 } 290 return eRet; 291 } 292 293 OMX_ERRORTYPE 294 qc_omx_component_free_buffer(OMX_IN OMX_HANDLETYPE hComp, 295 OMX_IN OMX_U32 port, 296 OMX_IN OMX_BUFFERHEADERTYPE* buffer) 297 { 298 299 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 300 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 301 DEBUG_PRINT("OMXCORE: qc_omx_component_free_buffer[%d] %x, %x\n", (unsigned)port, (unsigned)hComp, (unsigned)buffer); 302 303 if(pThis) 304 { 305 eRet = pThis->free_buffer(hComp,port,buffer); 306 } 307 return eRet; 308 } 309 310 OMX_ERRORTYPE 311 qc_omx_component_empty_this_buffer(OMX_IN OMX_HANDLETYPE hComp, 312 OMX_IN OMX_BUFFERHEADERTYPE* buffer) 313 { 314 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 315 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 316 DEBUG_PRINT("OMXCORE: qc_omx_component_empty_this_buffer %x, %x\n",(unsigned)hComp,(unsigned)buffer); 317 318 if(pThis) 319 { 320 eRet = pThis->empty_this_buffer(hComp,buffer); 321 } 322 return eRet; 323 } 324 325 OMX_ERRORTYPE 326 qc_omx_component_fill_this_buffer(OMX_IN OMX_HANDLETYPE hComp, 327 OMX_IN OMX_BUFFERHEADERTYPE* buffer) 328 { 329 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 330 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 331 DEBUG_PRINT("OMXCORE: qc_omx_component_fill_this_buffer %x, %x\n",(unsigned)hComp,(unsigned)buffer); 332 if(pThis) 333 { 334 eRet = pThis->fill_this_buffer(hComp,buffer); 335 } 336 return eRet; 337 } 338 339 OMX_ERRORTYPE 340 qc_omx_component_set_callbacks(OMX_IN OMX_HANDLETYPE hComp, 341 OMX_IN OMX_CALLBACKTYPE* callbacks, 342 OMX_IN OMX_PTR appData) 343 { 344 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 345 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 346 DEBUG_PRINT("OMXCORE: qc_omx_component_set_callbacks %x, %x , %x\n",(unsigned)hComp,(unsigned)callbacks,(unsigned)appData); 347 348 if(pThis) 349 { 350 eRet = pThis->set_callbacks(hComp,callbacks,appData); 351 } 352 return eRet; 353 } 354 355 OMX_ERRORTYPE 356 qc_omx_component_deinit(OMX_IN OMX_HANDLETYPE hComp) 357 { 358 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 359 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 360 DEBUG_PRINT("OMXCORE: qc_omx_component_deinit %x\n",(unsigned)hComp); 361 362 if(pThis) 363 { 364 // call the deinit fuction first 365 OMX_STATETYPE state; 366 pThis->get_state(hComp,&state); 367 DEBUG_PRINT("Calling FreeHandle in state %d \n", state); 368 eRet = pThis->component_deinit(hComp); 369 // destroy the component. 370 delete pThis; 371 ((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate = NULL; 372 } 373 return eRet; 374 } 375 376 OMX_ERRORTYPE 377 qc_omx_component_use_EGL_image(OMX_IN OMX_HANDLETYPE hComp, 378 OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr, 379 OMX_IN OMX_U32 port, 380 OMX_IN OMX_PTR appData, 381 OMX_IN void* eglImage) 382 { 383 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 384 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 385 DEBUG_PRINT("OMXCORE: qc_omx_component_use_EGL_image %x, %x , %d\n",(unsigned)hComp,(unsigned)bufferHdr,(unsigned)port); 386 if(pThis) 387 { 388 eRet = pThis->use_EGL_image(hComp,bufferHdr,port,appData,eglImage); 389 } 390 return eRet; 391 } 392 393 OMX_ERRORTYPE 394 qc_omx_component_role_enum(OMX_IN OMX_HANDLETYPE hComp, 395 OMX_OUT OMX_U8* role, 396 OMX_IN OMX_U32 index) 397 { 398 OMX_ERRORTYPE eRet = OMX_ErrorBadParameter; 399 qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL; 400 DEBUG_PRINT("OMXCORE: qc_omx_component_role_enum %x, %x , %d\n",(unsigned)hComp,(unsigned)role,(unsigned)index); 401 402 if(pThis) 403 { 404 eRet = pThis->component_role_enum(hComp,role,index); 405 } 406 return eRet; 407 } 408