omxcore.c

Go to the documentation of this file.
00001 
00030 #ifndef __SYMBIAN32__
00031 #define _GNU_SOURCE
00032 #endif
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <sys/types.h>
00037 #include <dirent.h>
00038 #include <strings.h>
00039 #include <errno.h>
00040 #include <assert.h>
00041 
00042 #include <OMX_Types.h>
00043 #include <OMX_Core.h>
00044 #include <OMX_Component.h>
00045 
00046 #include "omxcore.h"
00047 #include "omx_create_loaders.h"
00048 
00052 static int initialized;
00053 
00056 static int bosa_loaders;
00057 
00065 BOSA_COMPONENTLOADER **loadersList = NULL;
00066 
00067 OMX_ERRORTYPE BOSA_AddComponentLoader(BOSA_COMPONENTLOADER *pLoader) 
00068 {
00069     BOSA_COMPONENTLOADER **newLoadersList = NULL;
00070     assert(pLoader);
00071     
00072     bosa_loaders++;
00073     newLoadersList = (BOSA_COMPONENTLOADER **) realloc(loadersList, bosa_loaders * sizeof(BOSA_COMPONENTLOADER *));
00074     
00075     if (!newLoadersList)
00076         return OMX_ErrorInsufficientResources;
00077 
00078     loadersList = newLoadersList;
00079     
00080     loadersList[bosa_loaders - 1] = pLoader;
00081     
00082     DEBUG(DEB_LEV_SIMPLE_SEQ, "Loader added at index %d\n", bosa_loaders - 1);
00083     
00084     return OMX_ErrorNone;   
00085 }
00086 
00095 OMX_ERRORTYPE OMX_Init() {
00096     int i = 0;
00097     OMX_ERRORTYPE err;
00098 
00099     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s \n", __func__);
00100     if(initialized == 0) {
00101         initialized = 1;
00102 
00103         createComponentLoaders();
00104         
00105         for (i = 0; i < bosa_loaders; i++) 
00106         {
00107             err = loadersList[i]->BOSA_InitComponentLoader(loadersList[i]);
00108             if (err != OMX_ErrorNone) 
00109             {
00110                 DEBUG(DEB_LEV_ERR, "A Component loader constructor fails. Exiting\n");
00111                 return OMX_ErrorInsufficientResources;
00112             }
00113         }       
00114     }
00115 
00116     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00117     return OMX_ErrorNone;
00118 }
00119 
00124 OMX_ERRORTYPE OMX_Deinit() {
00125     int i = 0;
00126     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00127     if(initialized == 1) {
00128         for (i = 0; i < bosa_loaders; i++) {
00129             loadersList[i]->BOSA_DeInitComponentLoader(loadersList[i]);
00130             free(loadersList[i]);
00131             loadersList[i] = 0;
00132         }
00133     }   
00134     free(loadersList);
00135     loadersList = 0;
00136     initialized = 0;
00137     bosa_loaders = 0;
00138     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00139     return OMX_ErrorNone;
00140 }
00141 
00154 OMX_ERRORTYPE OMX_GetHandle(OMX_OUT OMX_HANDLETYPE* pHandle,
00155     OMX_IN  OMX_STRING cComponentName,
00156     OMX_IN  OMX_PTR pAppData,
00157     OMX_IN  OMX_CALLBACKTYPE* pCallBacks) {
00158     
00159     int i;
00160     OMX_ERRORTYPE err;
00161     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00162 
00163     for (i = 0; i < bosa_loaders; i++) {
00164         err = loadersList[i]->BOSA_CreateComponent(
00165                     loadersList[i],
00166                     pHandle,
00167                     cComponentName,
00168                     pAppData,
00169                     pCallBacks);
00170         if (err == OMX_ErrorNone) {
00171             // the component has been found
00172             return OMX_ErrorNone;
00173         }
00174     }
00175     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00176     return OMX_ErrorComponentNotFound;
00177 }
00178 
00182 OMX_ERRORTYPE OMX_FreeHandle(OMX_IN OMX_HANDLETYPE pHandle) 
00183 {
00184     int i;
00185     OMX_ERRORTYPE err;
00186 
00187     for (i = 0; i < bosa_loaders; i++) 
00188     {
00189         err = loadersList[i]->BOSA_DestroyComponent(
00190                     loadersList[i],
00191                     pHandle);
00192 
00193         if (err == OMX_ErrorNone) 
00194         {
00195             // the component has been found and destroyed
00196             return OMX_ErrorNone;
00197         }
00198     }
00199 
00200     return OMX_ErrorComponentNotFound;
00201 }
00202 
00210 OMX_ERRORTYPE 
00211 OMX_ComponentNameEnum(OMX_OUT OMX_STRING cComponentName,
00212                         OMX_IN OMX_U32 nNameLength,
00213                         OMX_IN OMX_U32 nIndex) 
00214 {
00215     OMX_ERRORTYPE err = OMX_ErrorNone;
00216     int i = 0; 
00217     int index = 0;
00218     int offset = 0;
00219     
00220     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00221 
00222     for (i = 0; i < bosa_loaders; i++) 
00223     {
00224         offset = 0;
00225 
00226         while((err = loadersList[i]->BOSA_ComponentNameEnum(loadersList[i],
00227                 cComponentName,
00228                 nNameLength,
00229                 offset)) != OMX_ErrorNoMore)
00230         {
00231             if (index == nIndex)
00232             {
00233                 return err;
00234             }
00235             offset++;
00236             index++;       
00237         }
00238     }
00239 
00240     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00241     return OMX_ErrorNoMore;
00242 }
00243 
00248 OMX_ERRORTYPE OMX_SetupTunnel(
00249     OMX_IN  OMX_HANDLETYPE hOutput,
00250     OMX_IN  OMX_U32 nPortOutput,
00251     OMX_IN  OMX_HANDLETYPE hInput,
00252     OMX_IN  OMX_U32 nPortInput) {
00253 
00254     OMX_ERRORTYPE err;
00255     OMX_COMPONENTTYPE* component;
00256     OMX_TUNNELSETUPTYPE* tunnelSetup;
00257     
00258     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00259     tunnelSetup = malloc(sizeof(OMX_TUNNELSETUPTYPE));
00260     component = (OMX_COMPONENTTYPE*)hOutput;
00261     tunnelSetup->nTunnelFlags = 0;
00262     tunnelSetup->eSupplier = OMX_BufferSupplyUnspecified;
00263 
00264     if (hOutput == NULL && hInput == NULL)
00265         return OMX_ErrorBadParameter;
00266     if (hOutput){
00267         err = (component->ComponentTunnelRequest)(hOutput, nPortOutput, hInput, nPortInput, tunnelSetup);
00268         if (err != OMX_ErrorNone) {
00269         DEBUG(DEB_LEV_ERR, "Tunneling failed: output port rejects it - err = %i\n", err);
00270         free(tunnelSetup);
00271         tunnelSetup = NULL;
00272         return err;
00273         }
00274     }
00275     DEBUG(DEB_LEV_PARAMS, "First stage of tunneling acheived:\n");
00276     DEBUG(DEB_LEV_PARAMS, "       - supplier proposed = %i\n", (int)tunnelSetup->eSupplier);
00277     DEBUG(DEB_LEV_PARAMS, "       - flags             = %i\n", (int)tunnelSetup->nTunnelFlags);
00278     
00279     component = (OMX_COMPONENTTYPE*)hInput;
00280     if (hInput) {
00281         err = (component->ComponentTunnelRequest)(hInput, nPortInput, hOutput, nPortOutput, tunnelSetup);
00282         if (err != OMX_ErrorNone) {
00283             DEBUG(DEB_LEV_ERR, "Tunneling failed: input port rejects it - err = %08x\n", err);
00284             // the second stage fails. the tunnel on poutput port has to be removed
00285             component = (OMX_COMPONENTTYPE*)hOutput;
00286             err = (component->ComponentTunnelRequest)(hOutput, nPortOutput, NULL, 0, tunnelSetup);
00287             if (err != OMX_ErrorNone) {
00288                 // This error should never happen. It is critical, and not recoverable
00289                 free(tunnelSetup);
00290                 tunnelSetup = NULL;
00291                 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s with OMX_ErrorUndefined\n", __func__);
00292                 return OMX_ErrorUndefined;
00293             }
00294             free(tunnelSetup);
00295             tunnelSetup = NULL;
00296             DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s with OMX_ErrorPortsNotCompatible\n", __func__);
00297             return OMX_ErrorPortsNotCompatible;
00298         }
00299     }
00300     DEBUG(DEB_LEV_PARAMS, "Second stage of tunneling acheived:\n");
00301     DEBUG(DEB_LEV_PARAMS, "       - supplier proposed = %i\n", (int)tunnelSetup->eSupplier);
00302     DEBUG(DEB_LEV_PARAMS, "       - flags             = %i\n", (int)tunnelSetup->nTunnelFlags);
00303     free(tunnelSetup);
00304     tunnelSetup = NULL;
00305     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00306     return OMX_ErrorNone;
00307 }
00308 
00311 OMX_ERRORTYPE OMX_GetRolesOfComponent ( 
00312   OMX_IN      OMX_STRING CompName, 
00313   OMX_INOUT   OMX_U32 *pNumRoles,
00314   OMX_OUT     OMX_U8 **roles) {
00315     OMX_ERRORTYPE err = OMX_ErrorNone;
00316     int i;
00317     
00318     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00319     for (i = 0; i < bosa_loaders; i++) {
00320         err = loadersList[i]->BOSA_GetRolesOfComponent(
00321                     loadersList[i],
00322                     CompName,
00323                     pNumRoles,
00324                     roles);
00325         if (err == OMX_ErrorNone) {
00326             return OMX_ErrorNone;
00327         }
00328     }
00329     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00330     return OMX_ErrorComponentNotFound;
00331 }
00332 
00338 OMX_ERRORTYPE OMX_GetComponentsOfRole ( 
00339   OMX_IN      OMX_STRING role,
00340   OMX_INOUT   OMX_U32 *pNumComps,
00341   OMX_INOUT   OMX_U8  **compNames) {
00342   OMX_ERRORTYPE err = OMX_ErrorNone;
00343     int i,j;
00344     int only_number_requested = 0, full_number=0;
00345     OMX_U32 temp_num_comp = 0;
00346     
00347     OMX_U8 **tempCompNames;
00348     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00349     if (compNames == NULL) {
00350         only_number_requested = 1;
00351     } else {
00352         only_number_requested = 0;
00353     }
00354     for (i = 0; i < bosa_loaders; i++) {
00355         temp_num_comp = *pNumComps;
00356         err = loadersList[i]->BOSA_GetComponentsOfRole(
00357                     loadersList[i],
00358                     role,
00359                     &temp_num_comp,
00360                     NULL);
00361         if (err != OMX_ErrorNone) {
00362             DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00363             return OMX_ErrorComponentNotFound;
00364         }
00365         if (only_number_requested == 0) {
00366             tempCompNames = malloc(temp_num_comp * sizeof(OMX_STRING));
00367             for (j=0; j<temp_num_comp; j++) {
00368                 tempCompNames[j] = malloc(OMX_MAX_STRINGNAME_SIZE * sizeof(char));
00369             }
00370             err = loadersList[i]->BOSA_GetComponentsOfRole(
00371                     loadersList[i],
00372                     role,
00373                     &temp_num_comp,
00374                     tempCompNames);
00375             if (err != OMX_ErrorNone) {
00376                 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00377                 return OMX_ErrorComponentNotFound;
00378             }
00379             
00380             for (j = 0; j<temp_num_comp; j++) {
00381                 if (full_number + j < *pNumComps) {
00382                     strncpy((char *)compNames[full_number + j], (const char *)tempCompNames[j], 128);
00383                 }
00384             }
00385         }
00386         full_number += temp_num_comp;
00387     }
00388     *pNumComps = full_number;
00389     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00390     return OMX_ErrorNone;
00391 }
00392 
00393 
00394 OMX_API OMX_ERRORTYPE   OMX_GetContentPipe(
00395     OMX_OUT OMX_HANDLETYPE *hPipe,
00396     OMX_IN OMX_STRING szURI) {
00397     (void)hPipe;
00398     (void)szURI;
00399     return OMX_ErrorUndefined;      
00400 }
00401 

Generated for OpenMAX Bellagio rel. 0.3.5-svn by  doxygen 1.5.1
SourceForge.net Logo