OpenMAXBellagio 0.9.3
OMXCoreRMExt.c
Go to the documentation of this file.
00001 
00026 #ifndef _GNU_SOURCE
00027 #define _GNU_SOURCE
00028 #endif
00029 
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include "common.h"
00034 #include "OMXCoreRMExt.h"
00035 #include "st_static_component_loader.h"
00036 
00037 static int data_loaded = 0;
00038 static stLoaderComponentType** qualityList;
00039 static int qualityListItems = 0;
00040 
00041 OMX_ERRORTYPE getSupportedQualityLevels(OMX_STRING cComponentName, OMX_U32** ppQualityLevel, OMX_U32* pNrOfQualityLevels) {
00042     OMX_ERRORTYPE err;
00043     int found = 0;
00044     int j,i,k;
00045     if (pNrOfQualityLevels == NULL) {
00046         return OMX_ErrorUndefined;
00047     }
00048 
00049     if (!data_loaded) {
00050         err = readRegistryFile();
00051         if (err != OMX_ErrorNone) {
00052             return err;
00053         }
00054         data_loaded = 1;
00055     }
00056     for (i = 0; i<qualityListItems; i++) {
00057         if(!strcmp(qualityList[i]->name, cComponentName)) {
00058             DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s found requested component %s with quality levels %i\n", __func__, cComponentName, (int)qualityList[i]->nqualitylevels);
00059             *pNrOfQualityLevels = qualityList[i]->nqualitylevels;
00060             if (ppQualityLevel == NULL) {
00061                 return OMX_ErrorNone;
00062             }
00063             for (k=0; k<qualityList[i]->nqualitylevels; k++) {
00064                 (*ppQualityLevel)[k] = k+1;
00065             }
00066             found = 1;
00067         } else {
00068             for(j=0;j<qualityList[i]->name_specific_length;j++) {
00069             if(!strcmp(qualityList[i]->name_specific[j], cComponentName)) {
00070                     DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested component %s IN SPECIFIC COMPONENT \n", cComponentName);
00071                         *pNrOfQualityLevels = qualityList[i]->nqualitylevels;
00072                         if (ppQualityLevel == NULL) {
00073                             return OMX_ErrorNone;
00074                         }
00075                         for (k=0; k<qualityList[i]->nqualitylevels; k++) {
00076                             (*ppQualityLevel)[k] = k+1;
00077                         }
00078                         found = 1;
00079              }
00080             }
00081         }
00082         if(found) {
00083             break;
00084         }
00085     }
00086     if(!found) {
00087         DEBUG(DEB_LEV_ERR, "Not found any component\n");
00088         *pNrOfQualityLevels = 0;
00089     }
00090     return OMX_ErrorNone;
00091 }
00092 
00093 OMX_ERRORTYPE getMultiResourceEstimates(OMX_STRING cComponentName, OMX_U32 nQualityLevel, multiResourceDescriptor* pMultiResourceEstimates) {
00094     OMX_ERRORTYPE err;
00095     int found = 0;
00096     int j,i = 0;
00097 
00098     if (pMultiResourceEstimates == NULL) {
00099         return OMX_ErrorUndefined;
00100     }
00101     if (!data_loaded) {
00102         err = readRegistryFile();
00103         if (err != OMX_ErrorNone) {
00104             return err;
00105         }
00106         data_loaded = 1;
00107     }
00108     for (i = 0; i<qualityListItems; i++) {
00109         if(!strcmp(qualityList[i]->name, cComponentName)) {
00110             DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s found requested component %s with quality level %i\n", __func__, cComponentName, (int)nQualityLevel);
00111             if ((nQualityLevel>0) && (nQualityLevel<=qualityList[i]->nqualitylevels)) {
00112                 found = 1;
00113                 pMultiResourceEstimates->CPUResourceRequested = qualityList[i]->multiResourceLevel[nQualityLevel-1]->CPUResourceRequested;
00114                 pMultiResourceEstimates->MemoryResourceRequested = qualityList[i]->multiResourceLevel[nQualityLevel-1]->MemoryResourceRequested;
00115                 break;
00116             }
00117         } else {
00118             for(j=0;j<qualityList[i]->name_specific_length;j++) {
00119                 if(!strcmp(qualityList[i]-> name_specific[j], cComponentName)) {
00120                     DEBUG(DEB_LEV_SIMPLE_SEQ, "Found requested component %s IN SPECIFIC COMPONENT \n", cComponentName);
00121                     if ((nQualityLevel>0) && (nQualityLevel<=qualityList[i]->nqualitylevels)) {
00122                         found = 1;
00123                         pMultiResourceEstimates->CPUResourceRequested = qualityList[i]->multiResourceLevel[nQualityLevel-1]->CPUResourceRequested;
00124                         pMultiResourceEstimates->MemoryResourceRequested = qualityList[i]->multiResourceLevel[nQualityLevel-1]->MemoryResourceRequested;
00125                         break;
00126                     }
00127                     if (found) {
00128                         break;
00129                     }
00130                 }
00131             }
00132         }
00133         if(found) {
00134             break;
00135         }
00136     }
00137     if(!found) {
00138         pMultiResourceEstimates->CPUResourceRequested = -1;
00139         pMultiResourceEstimates->MemoryResourceRequested = -1;
00140     }
00141     return OMX_ErrorNone;
00142 }
00143 
00146 OMX_ERRORTYPE readRegistryFile() {
00147     FILE* omxregistryfp;
00148     char* line = NULL;
00149     char *libname;
00150     int index_readline;
00151     int listindex;
00152     char *registry_filename;
00153     int numberOfLines = 0;
00154     int index;
00155     int tempindex;
00156     int wordlength;
00157     int roleindex;
00158     int numlevels;
00159     int i;
00160 
00161     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00162     qualityList = NULL;
00163 
00164     registry_filename = componentsRegistryGetFilenameCheck(1);
00165     omxregistryfp = fopen(registry_filename, "r");
00166     if (omxregistryfp == NULL){
00167         DEBUG(DEB_LEV_ERR, "Cannot open OpenMAX registry file %s\n", registry_filename);
00168         return OMX_ErrorUndefined;
00169     }
00170     free(registry_filename);
00171     libname = malloc(OMX_MAX_STRINGNAME_SIZE * 2);
00172     fseek(omxregistryfp, 0, 0);
00173 
00174       while(1) {
00175           index_readline = 0;
00176           while(index_readline < MAX_LINE_LENGTH) {
00177               *(line+index_readline) = fgetc(omxregistryfp);
00178               if ((*(line+index_readline) == '\n') || (*(line+index_readline) == '\0')) {
00179                   break;
00180               }
00181               index_readline++;
00182           }
00183           *(line+index_readline) = '\0';
00184           if ((index_readline >= MAX_LINE_LENGTH) || (index_readline == 0)) {
00185               break;
00186           }
00187         if ((*line == ' ') && (*(line+1) == '=')) {
00188             numberOfLines++;
00189         } else {
00190             continue;
00191         }
00192     }
00193     fseek(omxregistryfp, 0, 0);
00194     qualityList = malloc(numberOfLines * sizeof (stLoaderComponentType*));
00195     qualityListItems = numberOfLines;
00196     line = malloc(MAX_LINE_LENGTH);
00197     listindex = 0;
00198 
00199       while(1) {
00200           index_readline = 0;
00201           while(index_readline < MAX_LINE_LENGTH) {
00202               *(line+index_readline) = fgetc(omxregistryfp);
00203               if ((*(line+index_readline) == '\n') || (*(line+index_readline) == '\0')) {
00204                   break;
00205               }
00206               index_readline++;
00207           }
00208           *(line+index_readline) = '\0';
00209           if ((index_readline >= MAX_LINE_LENGTH) || (index_readline == 0)) {
00210               break;
00211           }
00212 
00213         if ((*line == ' ') && (*(line+1) == '=')) {
00214             qualityList[listindex] = NULL;
00215             qualityList[listindex] = calloc(1,sizeof(stLoaderComponentType));
00216             index = 5;
00217             wordlength = 0;
00218             while((*(line + index) != ' ') && (*(line + index) != '\0')) {
00219                 wordlength++;
00220                 index++;
00221             }
00222             qualityList[listindex]->name = malloc(wordlength + 1);
00223             strncpy(qualityList[listindex]->name, (line + 5), wordlength);
00224             *(qualityList[listindex]->name + wordlength) = '\0';
00225             // count rules
00226             if (*(line + index) == '\n') {
00227                 listindex++;
00228                 continue;
00229             }
00230             index = index + 5;
00231             tempindex = index;
00232             qualityList[listindex]->name_specific_length = 0;
00233             while((*(line + tempindex) != ' ') && (*(line + tempindex) != '\0')) {
00234                 while(*(line + tempindex) !=':') {
00235                     tempindex++;
00236                 }
00237                 tempindex++;
00238                 qualityList[listindex]->name_specific_length++;
00239             }
00240             qualityList[listindex]->name_specific = calloc(qualityList[listindex]->name_specific_length, sizeof(char *));
00241             roleindex = 0;
00242             while((*(line + index) != ' ') && (*(line + index) != '\n')) {
00243                 wordlength = 0;
00244                 tempindex = index;
00245                 while(*(line + index) !=':') {
00246                     wordlength++;
00247                     index++;
00248                 }
00249                 tempindex = index - tempindex;
00250                 qualityList[listindex]->name_specific[roleindex] = malloc(tempindex + 1);
00251                 strncpy(qualityList[listindex]->name_specific[roleindex], (line+index-tempindex), tempindex);
00252                 *(qualityList[listindex]->name_specific[roleindex]+tempindex) = '\0';
00253                 roleindex++;
00254                 index++;
00255             }
00256             if (*(line + index) == '\0') {
00257                 listindex++;
00258                 continue;
00259             }
00260             // finally reached the quality levels
00261             index = index + 5;
00262             numlevels = 0;
00263             while(1) {
00264                 if (*(line + index) != ' ') {
00265                     numlevels = (numlevels * 10) + (*(line + index) -'0');
00266                     index++;
00267                 } else {
00268                     qualityList[listindex]->nqualitylevels = numlevels;
00269                     qualityList[listindex]->multiResourceLevel = malloc(sizeof(multiResourceDescriptor *) * qualityList[listindex]->nqualitylevels);
00270                     for (i = 0; i<qualityList[listindex]->nqualitylevels; i++) {
00271                         qualityList[listindex]->multiResourceLevel[i] = malloc(sizeof(multiResourceDescriptor));
00272                     }
00273                     break;
00274                 }
00275             }
00276             index++;
00277             for (i = 0; i<qualityList[listindex]->nqualitylevels; i++) {
00278                 qualityList[listindex]->multiResourceLevel[i]->CPUResourceRequested = 0;
00279                 qualityList[listindex]->multiResourceLevel[i]->MemoryResourceRequested = 0;
00280                 while(*(line + index) != ',') {
00281                     qualityList[listindex]->multiResourceLevel[i]->CPUResourceRequested = (qualityList[listindex]->multiResourceLevel[i]->CPUResourceRequested * 10) + (*(line + index) - '0');
00282                     index++;
00283                 }
00284                 index++;
00285                 while((*(line + index) != ' ') && (*(line + index) != '\n')) {
00286                     qualityList[listindex]->multiResourceLevel[i]->MemoryResourceRequested = (qualityList[listindex]->multiResourceLevel[i]->MemoryResourceRequested * 10) + (*(line + index) - '0');
00287                     index++;
00288                 }
00289                 index++;
00290             }
00291             listindex++;
00292         }
00293     }
00294 
00295     if(line) {
00296         free(line);
00297         line = NULL;
00298     }
00299     free(libname);
00300     libname = NULL;
00301     fclose(omxregistryfp);
00302     DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
00303     return OMX_ErrorNone;
00304 }