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   OMX_ERRORTYPE err = OMX_ErrorNone;
00160   int i;
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         /*Required to meet conformance test: do not remove*/
00176         if (err == OMX_ErrorInsufficientResources) {
00177           return OMX_ErrorInsufficientResources;
00178         }
00179   DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00180   return OMX_ErrorComponentNotFound;
00181 }
00182 
00191 OMX_ERRORTYPE OMX_FreeHandle(OMX_IN OMX_HANDLETYPE hComponent) 
00192 {
00193   int i;
00194     OMX_ERRORTYPE err;
00195 
00196     for (i = 0; i < bosa_loaders; i++) 
00197     {
00198     err = loadersList[i]->BOSA_DestroyComponent(
00199           loadersList[i],
00200           hComponent);
00201 
00202     if (err == OMX_ErrorNone) 
00203     {
00204       // the component has been found and destroyed
00205       return OMX_ErrorNone;
00206     }
00207   }
00208 
00209   return OMX_ErrorComponentNotFound;
00210 }
00211 
00219 OMX_ERRORTYPE 
00220 OMX_ComponentNameEnum(OMX_OUT OMX_STRING cComponentName,
00221                       OMX_IN OMX_U32 nNameLength,
00222                       OMX_IN OMX_U32 nIndex) 
00223 {
00224   OMX_ERRORTYPE err = OMX_ErrorNone;
00225   int i = 0; 
00226     int index = 0;
00227     int offset = 0;
00228   
00229   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00230 
00231   for (i = 0; i < bosa_loaders; i++) 
00232     {
00233         offset = 0;
00234 
00235         while((err = loadersList[i]->BOSA_ComponentNameEnum(loadersList[i],
00236                 cComponentName,
00237                 nNameLength,
00238                 offset)) != OMX_ErrorNoMore)
00239         {
00240             if (index == nIndex)
00241             {
00242                 return err;
00243             }
00244             offset++;
00245             index++;       
00246         }
00247     }
00248 
00249     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00250   return OMX_ErrorNoMore;
00251 }
00252 
00265 OMX_ERRORTYPE OMX_SetupTunnel(
00266   OMX_IN  OMX_HANDLETYPE hOutput,
00267   OMX_IN  OMX_U32 nPortOutput,
00268   OMX_IN  OMX_HANDLETYPE hInput,
00269   OMX_IN  OMX_U32 nPortInput) {
00270 
00271   OMX_ERRORTYPE err;
00272   OMX_COMPONENTTYPE* component;
00273   OMX_TUNNELSETUPTYPE* tunnelSetup;
00274   
00275   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00276   tunnelSetup = malloc(sizeof(OMX_TUNNELSETUPTYPE));
00277   component = (OMX_COMPONENTTYPE*)hOutput;
00278   tunnelSetup->nTunnelFlags = 0;
00279   tunnelSetup->eSupplier = OMX_BufferSupplyUnspecified;
00280 
00281   if (hOutput == NULL && hInput == NULL)
00282         return OMX_ErrorBadParameter;
00283   if (hOutput){
00284     err = (component->ComponentTunnelRequest)(hOutput, nPortOutput, hInput, nPortInput, tunnelSetup);
00285     if (err != OMX_ErrorNone) {
00286     DEBUG(DEB_LEV_ERR, "Tunneling failed: output port rejects it - err = %i\n", err);
00287     free(tunnelSetup);
00288     tunnelSetup = NULL;
00289     return err;
00290     }
00291   }
00292   DEBUG(DEB_LEV_PARAMS, "First stage of tunneling acheived:\n");
00293   DEBUG(DEB_LEV_PARAMS, "       - supplier proposed = %i\n", (int)tunnelSetup->eSupplier);
00294   DEBUG(DEB_LEV_PARAMS, "       - flags             = %i\n", (int)tunnelSetup->nTunnelFlags);
00295   
00296   component = (OMX_COMPONENTTYPE*)hInput;
00297   if (hInput) {
00298     err = (component->ComponentTunnelRequest)(hInput, nPortInput, hOutput, nPortOutput, tunnelSetup);
00299     if (err != OMX_ErrorNone) {
00300       DEBUG(DEB_LEV_ERR, "Tunneling failed: input port rejects it - err = %08x\n", err);
00301       // the second stage fails. the tunnel on poutput port has to be removed
00302       component = (OMX_COMPONENTTYPE*)hOutput;
00303       err = (component->ComponentTunnelRequest)(hOutput, nPortOutput, NULL, 0, tunnelSetup);
00304       if (err != OMX_ErrorNone) {
00305         // This error should never happen. It is critical, and not recoverable
00306         free(tunnelSetup);
00307         tunnelSetup = NULL;
00308         DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s with OMX_ErrorUndefined\n", __func__);
00309         return OMX_ErrorUndefined;
00310       }
00311       free(tunnelSetup);
00312       tunnelSetup = NULL;
00313       DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s with OMX_ErrorPortsNotCompatible\n", __func__);
00314       return OMX_ErrorPortsNotCompatible;
00315     }
00316   }
00317   DEBUG(DEB_LEV_PARAMS, "Second stage of tunneling acheived:\n");
00318   DEBUG(DEB_LEV_PARAMS, "       - supplier proposed = %i\n", (int)tunnelSetup->eSupplier);
00319   DEBUG(DEB_LEV_PARAMS, "       - flags             = %i\n", (int)tunnelSetup->nTunnelFlags);
00320   free(tunnelSetup);
00321   tunnelSetup = NULL;
00322   DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00323   return OMX_ErrorNone;
00324 }
00325 
00328 OMX_ERRORTYPE OMX_GetRolesOfComponent ( 
00329   OMX_IN      OMX_STRING CompName, 
00330   OMX_INOUT   OMX_U32 *pNumRoles,
00331   OMX_OUT     OMX_U8 **roles) {
00332   OMX_ERRORTYPE err = OMX_ErrorNone;
00333   int i;
00334   
00335   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00336   for (i = 0; i < bosa_loaders; i++) {
00337     err = loadersList[i]->BOSA_GetRolesOfComponent(
00338           loadersList[i],
00339           CompName,
00340           pNumRoles,
00341           roles);
00342     if (err == OMX_ErrorNone) {
00343       return OMX_ErrorNone;
00344     }
00345   }
00346   DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00347   return OMX_ErrorComponentNotFound;
00348 }
00349 
00360 OMX_ERRORTYPE OMX_GetComponentsOfRole ( 
00361   OMX_IN      OMX_STRING role,
00362   OMX_INOUT   OMX_U32 *pNumComps,
00363   OMX_INOUT   OMX_U8  **compNames) {
00364   OMX_ERRORTYPE err = OMX_ErrorNone;
00365   int i,j;
00366   int only_number_requested = 0, full_number=0;
00367   OMX_U32 temp_num_comp = 0;
00368   
00369   OMX_U8 **tempCompNames;
00370   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00371   if (compNames == NULL) {
00372     only_number_requested = 1;
00373   } else {
00374     only_number_requested = 0;
00375   }
00376   for (i = 0; i < bosa_loaders; i++) {
00377     temp_num_comp = *pNumComps;
00378     err = loadersList[i]->BOSA_GetComponentsOfRole(
00379           loadersList[i],
00380           role,
00381           &temp_num_comp,
00382           NULL);
00383     if (err != OMX_ErrorNone) {
00384       DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00385       return OMX_ErrorComponentNotFound;
00386     }
00387     if (only_number_requested == 0) {
00388       tempCompNames = malloc(temp_num_comp * sizeof(OMX_STRING));
00389       for (j=0; j<temp_num_comp; j++) {
00390         tempCompNames[j] = malloc(OMX_MAX_STRINGNAME_SIZE * sizeof(char));
00391       }
00392       err = loadersList[i]->BOSA_GetComponentsOfRole(
00393           loadersList[i],
00394           role,
00395           &temp_num_comp,
00396           tempCompNames);
00397       if (err != OMX_ErrorNone) {
00398         DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00399         return OMX_ErrorComponentNotFound;
00400       }
00401       
00402       for (j = 0; j<temp_num_comp; j++) {
00403         if (full_number + j < *pNumComps) {
00404           strncpy((char *)compNames[full_number + j], (const char *)tempCompNames[j], 128);
00405         }
00406       }
00407     }
00408     full_number += temp_num_comp;
00409   }
00410   *pNumComps = full_number;
00411   DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00412   return OMX_ErrorNone;
00413 }
00414 
00415 
00416 OMX_API OMX_ERRORTYPE   OMX_GetContentPipe(
00417     OMX_OUT OMX_HANDLETYPE *hPipe,
00418     OMX_IN OMX_STRING szURI) {
00419     (void)hPipe;
00420     (void)szURI;
00421   return OMX_ErrorUndefined;      
00422 }
00423 

Generated for OpenMAX Bellagio rel. 0.9.0 by  doxygen 1.5.1
SourceForge.net Logo