Home | History | Annotate | Download | only in common
      1 /*--------------------------------------------------------------------------
      2 Copyright (c) 2009, The Linux Foundation. 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 The Linux Foundation 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 %p\n", 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 %p, %s , %p\n", hComp, componentName, 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 %p, %d , %d\n", 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 %p, %p , %d\n", hComp, 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 %p, %p , %d\n", hComp, 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 %p\n", 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 %p\n", 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 %p\n", 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   (void) hComp, (void) port, (void) peerComponent, (void) peerPort, (void) tunnelSetup;
    245   DEBUG_PRINT("Error: qc_omx_component_tunnel_request Not Implemented\n");
    246   return OMX_ErrorNotImplemented;
    247 }
    248 
    249  OMX_ERRORTYPE
    250 qc_omx_component_use_buffer(OMX_IN OMX_HANDLETYPE                hComp,
    251           OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
    252           OMX_IN OMX_U32                        port,
    253           OMX_IN OMX_PTR                     appData,
    254           OMX_IN OMX_U32                       bytes,
    255           OMX_IN OMX_U8*                      buffer)
    256 {
    257   OMX_ERRORTYPE eRet = OMX_ErrorBadParameter;
    258   qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL;
    259   DEBUG_PRINT("OMXCORE: qc_omx_component_use_buffer %p\n", hComp);
    260 
    261   if(pThis)
    262   {
    263      eRet = pThis->use_buffer(hComp,
    264                               bufferHdr,
    265                               port,
    266                               appData,
    267                               bytes,
    268                               buffer);
    269   }
    270   return eRet;
    271 }
    272 
    273 
    274 // qc_omx_component_allocate_buffer  -- API Call
    275  OMX_ERRORTYPE
    276 qc_omx_component_allocate_buffer(OMX_IN OMX_HANDLETYPE                hComp,
    277                OMX_INOUT OMX_BUFFERHEADERTYPE** bufferHdr,
    278                OMX_IN OMX_U32                        port,
    279                OMX_IN OMX_PTR                     appData,
    280                OMX_IN OMX_U32                       bytes)
    281 {
    282 
    283   OMX_ERRORTYPE eRet = OMX_ErrorBadParameter;
    284   qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL;
    285   DEBUG_PRINT("OMXCORE: qc_omx_component_allocate_buffer %p, %p , %d\n",hComp, bufferHdr,(unsigned)port);
    286 
    287   if(pThis)
    288   {
    289     eRet = pThis->allocate_buffer(hComp,bufferHdr,port,appData,bytes);
    290   }
    291   return eRet;
    292 }
    293 
    294  OMX_ERRORTYPE
    295 qc_omx_component_free_buffer(OMX_IN OMX_HANDLETYPE         hComp,
    296            OMX_IN OMX_U32                 port,
    297            OMX_IN OMX_BUFFERHEADERTYPE* buffer)
    298 {
    299 
    300   OMX_ERRORTYPE eRet = OMX_ErrorBadParameter;
    301   qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL;
    302   DEBUG_PRINT("OMXCORE: qc_omx_component_free_buffer[%d] %p, %p\n", (unsigned)port, hComp, buffer);
    303 
    304   if(pThis)
    305   {
    306     eRet = pThis->free_buffer(hComp,port,buffer);
    307   }
    308   return eRet;
    309 }
    310 
    311  OMX_ERRORTYPE
    312 qc_omx_component_empty_this_buffer(OMX_IN OMX_HANDLETYPE         hComp,
    313                 OMX_IN OMX_BUFFERHEADERTYPE* buffer)
    314 {
    315   OMX_ERRORTYPE eRet = OMX_ErrorBadParameter;
    316   qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL;
    317   DEBUG_PRINT("OMXCORE: qc_omx_component_empty_this_buffer %p, %p\n",hComp, buffer);
    318 
    319   if(pThis)
    320   {
    321     eRet = pThis->empty_this_buffer(hComp,buffer);
    322   }
    323   return eRet;
    324 }
    325 
    326  OMX_ERRORTYPE
    327 qc_omx_component_fill_this_buffer(OMX_IN OMX_HANDLETYPE         hComp,
    328                OMX_IN OMX_BUFFERHEADERTYPE* buffer)
    329 {
    330   OMX_ERRORTYPE eRet = OMX_ErrorBadParameter;
    331   qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL;
    332   DEBUG_PRINT("OMXCORE: qc_omx_component_fill_this_buffer %p, %p\n", hComp, buffer);
    333   if(pThis)
    334   {
    335     eRet = pThis->fill_this_buffer(hComp,buffer);
    336   }
    337   return eRet;
    338 }
    339 
    340  OMX_ERRORTYPE
    341 qc_omx_component_set_callbacks(OMX_IN OMX_HANDLETYPE        hComp,
    342              OMX_IN OMX_CALLBACKTYPE* callbacks,
    343              OMX_IN OMX_PTR             appData)
    344 {
    345   OMX_ERRORTYPE eRet = OMX_ErrorBadParameter;
    346   qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL;
    347   DEBUG_PRINT("OMXCORE: qc_omx_component_set_callbacks %p, %p , %p\n", hComp, callbacks, appData);
    348 
    349   if(pThis)
    350   {
    351     eRet = pThis->set_callbacks(hComp,callbacks,appData);
    352   }
    353   return eRet;
    354 }
    355 
    356  OMX_ERRORTYPE
    357 qc_omx_component_deinit(OMX_IN OMX_HANDLETYPE hComp)
    358 {
    359   OMX_ERRORTYPE eRet = OMX_ErrorBadParameter;
    360   qc_omx_component *pThis = (hComp)? (qc_omx_component *)(((OMX_COMPONENTTYPE *)hComp)->pComponentPrivate):NULL;
    361   DEBUG_PRINT("OMXCORE: qc_omx_component_deinit %p\n", hComp);
    362 
    363   if(pThis)
    364   {
    365     // call the deinit fuction first
    366     OMX_STATETYPE state;
    367     pThis->get_state(hComp,&state);
    368     DEBUG_PRINT("Calling FreeHandle in state %d \n", state);
    369     eRet = pThis->component_deinit(hComp);
    370     // destroy the component.
    371     delete pThis;
    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 %p, %p , %d\n", hComp, 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 %p, %p , %d\n", hComp, role,(unsigned)index);
    401 
    402   if(pThis)
    403   {
    404     eRet = pThis->component_role_enum(hComp,role,index);
    405   }
    406   return eRet;
    407 }
    408