omx_videosrc_component.c

Go to the documentation of this file.
00001 
00031 #include <omxcore.h>
00032 #include <omx_base_video_port.h>
00033 #include <omx_videosrc_component.h>
00034 
00035 #define MAX_COMPONENT_VIDEOSRC 1
00036 
00038 static OMX_U32 noViderSrcInstance=0;
00039 
00040 #define DEFAULT_FILENAME_LENGTH 256
00041 
00044 OMX_ERRORTYPE omx_videosrc_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName) {
00045  
00046   OMX_ERRORTYPE err = OMX_ErrorNone;  
00047   omx_base_video_PortType *pPort;
00048   omx_videosrc_component_PrivateType* omx_videosrc_component_Private;
00049   OMX_U32 i;
00050 
00051   DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00052 
00053   if (!openmaxStandComp->pComponentPrivate) {
00054     openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_videosrc_component_PrivateType));
00055     if(openmaxStandComp->pComponentPrivate == NULL) {
00056       return OMX_ErrorInsufficientResources;
00057     }
00058   }
00059 
00060   omx_videosrc_component_Private = openmaxStandComp->pComponentPrivate;
00061   omx_videosrc_component_Private->ports = NULL;
00062   omx_videosrc_component_Private->deviceHandle = -1;
00063   
00064   err = omx_base_source_Constructor(openmaxStandComp, cComponentName);
00065   
00067   if (omx_videosrc_component_Private->sPortTypesParam.nPorts && !omx_videosrc_component_Private->ports) {
00068     omx_videosrc_component_Private->ports = calloc(omx_videosrc_component_Private->sPortTypesParam.nPorts, sizeof(omx_base_PortType *));
00069     if (!omx_videosrc_component_Private->ports) {
00070       return OMX_ErrorInsufficientResources;
00071     }
00072     for (i=0; i < omx_videosrc_component_Private->sPortTypesParam.nPorts; i++) {
00073       omx_videosrc_component_Private->ports[i] = calloc(1, sizeof(omx_base_video_PortType));
00074       if (!omx_videosrc_component_Private->ports[i]) {
00075         return OMX_ErrorInsufficientResources;
00076       }
00077     }
00078   }
00079 
00080   base_video_port_Constructor(openmaxStandComp, &omx_videosrc_component_Private->ports[0], 0, OMX_FALSE);
00081   omx_videosrc_component_Private->ports[0]->Port_AllocateBuffer = videosrc_port_AllocateBuffer;
00082   omx_videosrc_component_Private->ports[0]->Port_FreeBuffer = videosrc_port_FreeBuffer;
00083   omx_videosrc_component_Private->ports[0]->Port_AllocateTunnelBuffer = videosrc_port_AllocateTunnelBuffer;
00084   omx_videosrc_component_Private->ports[0]->Port_FreeTunnelBuffer = videosrc_port_FreeTunnelBuffer;
00085 
00086   pPort = (omx_base_video_PortType *) omx_videosrc_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX];
00087   
00093   /*Input pPort buffer size is equal to the size of the output buffer of the previous component*/
00094   pPort->sPortParam.format.video.nFrameWidth = 176;
00095   pPort->sPortParam.format.video.nFrameHeight= 144;
00096   pPort->sPortParam.format.video.eColorFormat= OMX_COLOR_FormatYUV420Planar;
00097   pPort->sVideoParam.eColorFormat = OMX_COLOR_FormatYUV420Planar;
00098 
00099   pPort->sPortParam.nBufferSize = pPort->sPortParam.format.video.nFrameWidth*
00100                                   pPort->sPortParam.format.video.nFrameHeight*3; // RGB
00101   omx_videosrc_component_Private->iFrameSize = pPort->sPortParam.nBufferSize;
00102 
00103   omx_videosrc_component_Private->BufferMgmtCallback = omx_videosrc_component_BufferMgmtCallback;
00104   omx_videosrc_component_Private->destructor = omx_videosrc_component_Destructor;
00105   omx_videosrc_component_Private->messageHandler = omx_videosrc_component_MessageHandler;
00106 
00107   noViderSrcInstance++;
00108   if(noViderSrcInstance > MAX_COMPONENT_VIDEOSRC) {
00109     return OMX_ErrorInsufficientResources;
00110   }
00111 
00112   openmaxStandComp->SetParameter  = omx_videosrc_component_SetParameter;
00113   openmaxStandComp->GetParameter  = omx_videosrc_component_GetParameter;
00114 
00115   /* Write in the default paramenters */
00116   omx_videosrc_component_Private->videoReady = OMX_FALSE;
00117   if(!omx_videosrc_component_Private->videoSyncSem) {
00118     omx_videosrc_component_Private->videoSyncSem = calloc(1,sizeof(tsem_t));
00119     if(omx_videosrc_component_Private->videoSyncSem == NULL) return OMX_ErrorInsufficientResources;
00120     tsem_init(omx_videosrc_component_Private->videoSyncSem, 0);
00121   }
00122 
00123   omx_videosrc_component_Private->mmaps = NULL;
00124   omx_videosrc_component_Private->memoryMap = NULL;
00125   omx_videosrc_component_Private->bOutBufferMemoryMapped = OMX_FALSE;
00126 
00127   /* Test if Camera Attached */
00128   omx_videosrc_component_Private->deviceHandle = open(VIDEO_DEV_NAME, O_RDWR);
00129   if (omx_videosrc_component_Private->deviceHandle < 0) {
00130     DEBUG(DEB_LEV_ERR, "In %s Unable to open video capture device %s! errno=%d  ENODEV : %d \n", 
00131       __func__,VIDEO_DEV_NAME,errno,ENODEV);
00132     return OMX_ErrorHardware;
00133   } 
00134 
00135   if ((omx_videosrc_component_Private->capability.type & VID_TYPE_SCALES) != 0)
00136   {       // supports the ability to scale captured images
00137     
00138     omx_videosrc_component_Private->captureWindow.x = 0;
00139     omx_videosrc_component_Private->captureWindow.y = 0;
00140     omx_videosrc_component_Private->captureWindow.width = pPort->sPortParam.format.video.nFrameWidth;
00141     omx_videosrc_component_Private->captureWindow.height = pPort->sPortParam.format.video.nFrameHeight;
00142     omx_videosrc_component_Private->captureWindow.chromakey = -1;
00143     omx_videosrc_component_Private->captureWindow.flags = 0;
00144     omx_videosrc_component_Private->captureWindow.clips = 0;
00145     omx_videosrc_component_Private->captureWindow.clipcount = 0;
00146     if (ioctl (omx_videosrc_component_Private->deviceHandle, VIDIOCSWIN, &omx_videosrc_component_Private->captureWindow) == -1)
00147     {       // could not set window values for capture
00148       DEBUG(DEB_LEV_ERR,"could not set window values for capture\n");
00149     }
00150   }
00151   if (ioctl (omx_videosrc_component_Private->deviceHandle, VIDIOCGMBUF, &omx_videosrc_component_Private->memoryBuffer) == -1)
00152   { // failed to retrieve information about capture memory space
00153     DEBUG(DEB_LEV_ERR,"failed to retrieve information about capture memory space\n");
00154   }
00155  
00156   // obtain memory mapped area
00157   omx_videosrc_component_Private->memoryMap = mmap (0, omx_videosrc_component_Private->memoryBuffer.size, PROT_READ | PROT_WRITE, MAP_SHARED, omx_videosrc_component_Private->deviceHandle, 0);
00158   if (omx_videosrc_component_Private->memoryMap == NULL)
00159   { // failed to retrieve pointer to memory mapped area
00160     DEBUG(DEB_LEV_ERR,"failed to retrieve pointer to memory mapped area\n");
00161   }
00162 
00163   return err;
00164 }
00165 
00168 OMX_ERRORTYPE omx_videosrc_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp) {
00169   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = openmaxStandComp->pComponentPrivate;
00170   OMX_U32 i;
00171   
00172   if(omx_videosrc_component_Private->videoSyncSem) {
00173     tsem_deinit(omx_videosrc_component_Private->videoSyncSem);
00174     free(omx_videosrc_component_Private->videoSyncSem);
00175     omx_videosrc_component_Private->videoSyncSem=NULL;
00176   }
00177 
00178   /* free the video_mmap structures */
00179   if(omx_videosrc_component_Private->mmaps != NULL) {
00180     DEBUG(DEB_LEV_FULL_SEQ, "In %s Freeing mmaps \n",__func__);
00181     free (omx_videosrc_component_Private->mmaps);
00182     omx_videosrc_component_Private->mmaps = NULL;
00183   }
00184 
00185   /* unmap the capture memory */
00186   if(omx_videosrc_component_Private->memoryMap != NULL) {
00187     DEBUG(DEB_LEV_FULL_SEQ, "In %s Freeing memoryMap \n",__func__);
00188     munmap (omx_videosrc_component_Private->memoryMap, omx_videosrc_component_Private->memoryBuffer.size);
00189     omx_videosrc_component_Private->memoryMap = NULL;
00190   }
00191  
00192   if(omx_videosrc_component_Private->deviceHandle != -1) {
00193     if(-1 == close(omx_videosrc_component_Private->deviceHandle)) {
00194       DEBUG(DEB_LEV_ERR, "In %s Closing video capture device failed \n",__func__);
00195     }
00196     omx_videosrc_component_Private->deviceHandle = -1;
00197   }
00198 
00199   /* frees port/s */
00200   if (omx_videosrc_component_Private->ports) {
00201     for (i=0; i < omx_videosrc_component_Private->sPortTypesParam.nPorts; i++) {
00202       if(omx_videosrc_component_Private->ports[i])
00203         omx_videosrc_component_Private->ports[i]->PortDestructor(omx_videosrc_component_Private->ports[i]);
00204     }
00205     free(omx_videosrc_component_Private->ports);
00206     omx_videosrc_component_Private->ports=NULL;
00207   }
00208 
00209   noViderSrcInstance--;
00210   DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00211   return omx_base_source_Destructor(openmaxStandComp);
00212 }
00213 
00216 OMX_ERRORTYPE omx_videosrc_component_Init(OMX_COMPONENTTYPE *openmaxStandComp) {
00217 
00218   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = openmaxStandComp->pComponentPrivate;
00219   omx_base_video_PortType *pPort = (omx_base_video_PortType *)omx_videosrc_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX];
00220   OMX_U32 i = 0;
00221   struct video_channel vchannel;
00222   struct video_audio audio;
00223 
00224   DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00225 
00227   if (ioctl (omx_videosrc_component_Private->deviceHandle, VIDIOCGCAP, &omx_videosrc_component_Private->capability) != -1)
00228   {       // query was successful
00229     DEBUG(DEB_LEV_FULL_SEQ, "Video Capability Query Successful\n");
00230   }
00231   else
00232   {       // query failed
00233     DEBUG(DEB_LEV_ERR, "Video Capability Query Failed\n");
00234   }
00235 
00236   if ((omx_videosrc_component_Private->capability.type & VID_TYPE_CAPTURE) != 0)
00237   {       // this device can capture video to memory
00238     DEBUG(DEB_LEV_FULL_SEQ,"This device can capture video to memory\n");
00239 
00240     DEBUG(DEB_LEV_PARAMS,"Name=%s,Type=%x,channel=%d,audios=%d, \nmaxW=%d,maxH=%d,minW=%d,minH=%d\n",omx_videosrc_component_Private->capability.name,
00241         omx_videosrc_component_Private->capability.type,
00242         omx_videosrc_component_Private->capability.channels,   /* Num channels */
00243         omx_videosrc_component_Private->capability.audios,     /* Num audio devices */
00244         omx_videosrc_component_Private->capability.maxwidth,   /* Supported width */
00245         omx_videosrc_component_Private->capability.maxheight,  /* And height */
00246         omx_videosrc_component_Private->capability.minwidth,   /* Supported width */
00247         omx_videosrc_component_Private->capability.minheight  /* And height */);
00248   }
00249   else
00250   {       // this device cannot capture video to memory
00251     DEBUG(DEB_LEV_ERR,"This device cannot capture video to memory\n");
00252   }
00253 
00254   DEBUG(DEB_LEV_FULL_SEQ,"CaptureWindow Type=%x x=%d,y=%d,w=%d,h=%d, chromakey=%d,flags =%x clipcount=%x\n",
00255     omx_videosrc_component_Private->capability.type,
00256       omx_videosrc_component_Private->captureWindow.x,
00257     omx_videosrc_component_Private->captureWindow.y,
00258     omx_videosrc_component_Private->captureWindow.width,
00259     omx_videosrc_component_Private->captureWindow.height ,
00260     omx_videosrc_component_Private->captureWindow.chromakey ,
00261     omx_videosrc_component_Private->captureWindow.flags ,
00262     omx_videosrc_component_Private->captureWindow.clipcount);
00263 
00264   if ((omx_videosrc_component_Private->capability.type & VID_TYPE_SCALES) != 0)
00265   {       // supports the ability to scale captured images
00266     
00267     omx_videosrc_component_Private->captureWindow.x = 0;
00268     omx_videosrc_component_Private->captureWindow.y = 0;
00269     omx_videosrc_component_Private->captureWindow.width = pPort->sPortParam.format.video.nFrameWidth;
00270     omx_videosrc_component_Private->captureWindow.height = pPort->sPortParam.format.video.nFrameHeight;
00271     omx_videosrc_component_Private->captureWindow.chromakey = -1;
00272     omx_videosrc_component_Private->captureWindow.flags = 0;
00273     omx_videosrc_component_Private->captureWindow.clips = 0;
00274     omx_videosrc_component_Private->captureWindow.clipcount = 0;
00275     if (ioctl (omx_videosrc_component_Private->deviceHandle, VIDIOCSWIN, &omx_videosrc_component_Private->captureWindow) == -1)
00276     {       // could not set window values for capture
00277       DEBUG(DEB_LEV_ERR,"could not set window values for capture\n");
00278     }
00279   }
00280 
00281   /*Default output frame size*/
00282   omx_videosrc_component_Private->iFrameSize = pPort->sPortParam.format.video.nFrameWidth*
00283                                                pPort->sPortParam.format.video.nFrameHeight*3/2;
00284   
00285   // get image properties
00286   if (ioctl (omx_videosrc_component_Private->deviceHandle, VIDIOCGPICT, &omx_videosrc_component_Private->imageProperties) != -1)
00287   {       // successfully retrieved the default image properties
00288 
00289     DEBUG(DEB_LEV_PARAMS,"Imp Prop br=%d hue=%d,col=%d,con=%d,white=%d, depth=%d,palette =%d \n",
00290       omx_videosrc_component_Private->imageProperties.brightness,
00291       omx_videosrc_component_Private->imageProperties.hue,
00292       omx_videosrc_component_Private->imageProperties.colour,
00293       omx_videosrc_component_Private->imageProperties.contrast,
00294       omx_videosrc_component_Private->imageProperties.whiteness,      /* Black and white only */
00295       omx_videosrc_component_Private->imageProperties.depth,          /* Capture depth */
00296       omx_videosrc_component_Private->imageProperties.palette);        /* Palette in use */
00297 
00298     omx_videosrc_component_Private->imageProperties.depth = 12;
00299 
00300     /*Presently VIDEO_PALETTE_YUV420P format is supported by the camera*/
00301     switch(pPort->sPortParam.format.video.eColorFormat) {
00302     case OMX_COLOR_FormatYUV420Planar:
00303       omx_videosrc_component_Private->imageProperties.palette = VIDEO_PALETTE_YUV420P;
00304       break;
00305     case OMX_COLOR_Format16bitRGB565:
00306       omx_videosrc_component_Private->imageProperties.palette = VIDEO_PALETTE_RGB565 ;       /* 565 16 bit RGB */
00307       omx_videosrc_component_Private->iFrameSize = pPort->sPortParam.format.video.nFrameWidth*
00308                                                    pPort->sPortParam.format.video.nFrameHeight*2;
00309       omx_videosrc_component_Private->imageProperties.depth = 16;
00310       omx_videosrc_component_Private->iFrameSize = pPort->sPortParam.format.video.nFrameWidth*
00311                                                  pPort->sPortParam.format.video.nFrameHeight*2;
00312       break;
00313     case OMX_COLOR_Format24bitRGB888:
00314       omx_videosrc_component_Private->imageProperties.palette = VIDEO_PALETTE_RGB24  ;       /* 24bit RGB */
00315       omx_videosrc_component_Private->iFrameSize = pPort->sPortParam.format.video.nFrameWidth*
00316                                                    pPort->sPortParam.format.video.nFrameHeight*3;
00317       omx_videosrc_component_Private->imageProperties.depth = 24;
00318       break;
00319     case OMX_COLOR_Format32bitARGB8888:
00320       omx_videosrc_component_Private->imageProperties.palette = VIDEO_PALETTE_RGB32     ;       /* 32bit RGB */
00321       omx_videosrc_component_Private->iFrameSize = pPort->sPortParam.format.video.nFrameWidth*
00322                                                    pPort->sPortParam.format.video.nFrameHeight*4;
00323       omx_videosrc_component_Private->imageProperties.depth = 32;
00324       break;
00325     case OMX_COLOR_FormatYUV422Planar:
00326       omx_videosrc_component_Private->imageProperties.palette = VIDEO_PALETTE_YUV422P   ;      /* YUV 4:2:2 Planar */
00327       omx_videosrc_component_Private->iFrameSize = pPort->sPortParam.format.video.nFrameWidth*
00328                                                    pPort->sPortParam.format.video.nFrameHeight*2;
00329       omx_videosrc_component_Private->imageProperties.depth = 16;
00330       break;
00331     case OMX_COLOR_FormatYUV411Planar:
00332       omx_videosrc_component_Private->imageProperties.palette = VIDEO_PALETTE_YUV411P   ;      /* YUV 4:1:1 Planar */
00333       break;
00334     default:
00335       omx_videosrc_component_Private->imageProperties.palette = VIDEO_PALETTE_YUV420P;
00336       break;
00337     }
00338     
00339     DEBUG(DEB_LEV_FULL_SEQ,"Frame Size=%d\n",(int)omx_videosrc_component_Private->iFrameSize);
00340 
00341     if (ioctl (omx_videosrc_component_Private->deviceHandle, VIDIOCSPICT, &omx_videosrc_component_Private->imageProperties) == -1)
00342     {       // failed to set the image properties
00343       DEBUG(DEB_LEV_ERR,"failed to set the image properties\n");
00344     }
00345   }
00346   
00347   vchannel.channel=0;
00348   if(ioctl(omx_videosrc_component_Private->deviceHandle, VIDIOCGCHAN, &vchannel)==-1) {
00349     DEBUG(DEB_LEV_ERR,"failed to get video channel\n");
00350   } else {
00351     DEBUG(DEB_LEV_FULL_SEQ,"video channel=%d,name=%s,tuners=%d,flags=%d,type=%x norm=%d\n",
00352        vchannel.channel,
00353        vchannel.name,
00354        vchannel.tuners,
00355        vchannel.flags,
00356        vchannel.type,
00357        vchannel.norm);
00358 
00359     vchannel.flags = VIDEO_VC_TUNER;
00360     vchannel.norm = VIDEO_MODE_AUTO;
00361 
00362     if(ioctl(omx_videosrc_component_Private->deviceHandle, VIDIOCSCHAN, &vchannel)==-1) {
00363       DEBUG(DEB_LEV_ERR,"failed to set video channel\n");
00364     }
00365   } 
00366 
00367   /* mute audio */
00368   audio.audio = 0;
00369   if(ioctl(omx_videosrc_component_Private->deviceHandle, VIDIOCGAUDIO, &audio)==-1) {
00370     DEBUG(DEB_LEV_ERR,"failed to get audio\n");
00371   } else {
00372     DEBUG(DEB_LEV_FULL_SEQ,"audio=%d,vol=%d,bass=%d,treble=%d,flags=%x \nname=%s,mode=%d,balance=%d,step=%d\n",
00373       audio.audio,          /* Audio channel */
00374       audio.volume,         /* If settable */
00375       audio.bass, audio.treble,
00376       audio.flags,
00377       audio.name,
00378       audio.mode,
00379       audio.balance,        /* Stereo balance */
00380       audio.step);           /* Step actual volume uses */
00381 
00382     audio.flags = VIDEO_AUDIO_MUTE;
00383     audio.volume=0;
00384     if(ioctl(omx_videosrc_component_Private->deviceHandle, VIDIOCSAUDIO, &audio)==-1){
00385       DEBUG(DEB_LEV_ERR,"failed to set audio\n");
00386     } 
00387   }
00388 
00398   omx_videosrc_component_Private->mmaps = (malloc (omx_videosrc_component_Private->memoryBuffer.frames * sizeof (struct video_mmap)));
00399 
00400   i = 0;
00401   // fill out the fields
00402   while (i < omx_videosrc_component_Private->memoryBuffer.frames)
00403   {
00404     omx_videosrc_component_Private->mmaps[i].frame = i;
00405     omx_videosrc_component_Private->mmaps[i].width = pPort->sPortParam.format.video.nFrameWidth;
00406     omx_videosrc_component_Private->mmaps[i].height = pPort->sPortParam.format.video.nFrameHeight;
00407     omx_videosrc_component_Private->mmaps[i].format = omx_videosrc_component_Private->imageProperties.palette;
00408     ++ i;
00409   }
00410   
00412   omx_videosrc_component_Private->bIsEOSSent = OMX_FALSE;
00413   omx_videosrc_component_Private->iFrameIndex = 0 ;
00414   
00415   omx_videosrc_component_Private->videoReady = OMX_TRUE;
00416   /*Indicate that video is ready*/
00417   tsem_up(omx_videosrc_component_Private->videoSyncSem);
00418 
00419   DEBUG(DEB_LEV_FULL_SEQ,"Memory Buf Size=%d\n",omx_videosrc_component_Private->memoryBuffer.size);
00420 
00421   return OMX_ErrorNone;
00422 }
00423 
00426 OMX_ERRORTYPE omx_videosrc_component_Deinit(OMX_COMPONENTTYPE *openmaxStandComp) {
00427 
00428   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = openmaxStandComp->pComponentPrivate;
00429 
00430   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s \n",__func__);
00432   omx_videosrc_component_Private->videoReady = OMX_FALSE;
00433   tsem_reset(omx_videosrc_component_Private->videoSyncSem);
00434 
00435   return OMX_ErrorNone;
00436 }
00437 
00442 void omx_videosrc_component_BufferMgmtCallback(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE* pOutputBuffer) {
00443 
00444   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = openmaxStandComp->pComponentPrivate;
00445   
00446   DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00447 
00448   if (omx_videosrc_component_Private->videoReady == OMX_FALSE) {
00449     if(omx_videosrc_component_Private->state == OMX_StateExecuting) {
00450       /*wait for video to be ready*/
00451       tsem_down(omx_videosrc_component_Private->videoSyncSem);
00452     } else {
00453       return;
00454     }
00455   }
00456 
00457   pOutputBuffer->nOffset = 0;
00458 
00459   //Capturing using MMIO.
00460   if (ioctl (omx_videosrc_component_Private->deviceHandle, VIDIOCMCAPTURE, &omx_videosrc_component_Private->mmaps[omx_videosrc_component_Private->iFrameIndex]) == -1)
00461   {       // capture request failed
00462     DEBUG(DEB_LEV_ERR,"capture request failed\n");
00463   }
00464   // wait for the currently indexed frame to complete capture
00465   if (ioctl (omx_videosrc_component_Private->deviceHandle, VIDIOCSYNC, &omx_videosrc_component_Private->iFrameIndex) == -1)
00466   {       // sync request failed
00467     pOutputBuffer->nFilledLen = 0;
00468     DEBUG(DEB_LEV_ERR,"sync request failed\n");
00469     return;
00470   }
00471 
00472   DEBUG(DEB_LEV_FULL_SEQ,"%d-%d\n",(int)omx_videosrc_component_Private->iFrameIndex,(int)omx_videosrc_component_Private->memoryBuffer.frames);
00473   if(omx_videosrc_component_Private->bOutBufferMemoryMapped == OMX_FALSE) { // In case OMX_UseBuffer copy frame to buffer metadata
00474     DEBUG(DEB_LEV_ERR,"In %s copy frame to metadata\n",__func__);
00475     memcpy(pOutputBuffer->pBuffer,omx_videosrc_component_Private->memoryMap + omx_videosrc_component_Private->memoryBuffer.offsets[omx_videosrc_component_Private->iFrameIndex],omx_videosrc_component_Private->iFrameSize);
00476   }
00477   pOutputBuffer->nFilledLen = omx_videosrc_component_Private->iFrameSize;
00478 
00479   omx_videosrc_component_Private->iFrameIndex++;
00480   /*Wrap the frame buffer to the first buffer*/
00481   if(omx_videosrc_component_Private->iFrameIndex == omx_videosrc_component_Private->memoryBuffer.frames) {
00482     omx_videosrc_component_Private->iFrameIndex =0;
00483   }
00485   return;
00486 }
00487 
00488 OMX_ERRORTYPE omx_videosrc_component_SetParameter(
00489   OMX_IN  OMX_HANDLETYPE hComponent,
00490   OMX_IN  OMX_INDEXTYPE nParamIndex,
00491   OMX_IN  OMX_PTR ComponentParameterStructure) {
00492 
00493   OMX_ERRORTYPE err = OMX_ErrorNone;
00494   OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;
00495   OMX_U32 portIndex;
00496 
00497   /* Check which structure we are being fed and make control its header */
00498   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
00499   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = openmaxStandComp->pComponentPrivate;
00500   omx_base_video_PortType* pPort = (omx_base_video_PortType *) omx_videosrc_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX];
00501 
00502   if(ComponentParameterStructure == NULL) {
00503     return OMX_ErrorBadParameter;
00504   }
00505 
00506   DEBUG(DEB_LEV_SIMPLE_SEQ, "   Setting parameter %i\n", nParamIndex);
00507 
00508   switch(nParamIndex) {
00509   case OMX_IndexParamVideoPortFormat:
00510     pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00511     portIndex = pVideoPortFormat->nPortIndex;
00512     /*Check Structure Header and verify component state*/
00513     err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00514     if(err!=OMX_ErrorNone) { 
00515       DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err); 
00516       break;
00517     }
00518     if (portIndex < 1) {
00519       memcpy(&pPort->sVideoParam,pVideoPortFormat,sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00520     } else {
00521       return OMX_ErrorBadPortIndex;
00522     }
00523     break;
00524   case OMX_IndexParamPortDefinition: 
00525     err = omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00526     if(err == OMX_ErrorNone) {
00527       if(pPort->sPortParam.format.video.nFrameWidth > 640 || pPort->sPortParam.format.video.nFrameWidth <160 || 
00528         pPort->sPortParam.format.video.nFrameHeight > 480 || pPort->sPortParam.format.video.nFrameHeight < 120) {
00529         pPort->sPortParam.format.video.nFrameWidth = 160;
00530         pPort->sPortParam.format.video.nFrameHeight = 120;
00531         DEBUG(DEB_LEV_ERR, "In %s Frame Width Range[160..640] Frame Height Range[120..480]\n",__func__); 
00532         return OMX_ErrorBadParameter;
00533       } else {
00534         pPort->sPortParam.nBufferSize = pPort->sPortParam.format.video.nFrameWidth*
00535                                   pPort->sPortParam.format.video.nFrameHeight*3/2; // YUV
00536       }
00537     }
00538   default: /*Call the base component function*/
00539     return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00540   }
00541   return err;
00542 }
00543 
00544 OMX_ERRORTYPE omx_videosrc_component_GetParameter(
00545   OMX_IN  OMX_HANDLETYPE hComponent,
00546   OMX_IN  OMX_INDEXTYPE nParamIndex,
00547   OMX_INOUT OMX_PTR ComponentParameterStructure) {
00548 
00549   OMX_ERRORTYPE err = OMX_ErrorNone;
00550   OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;  
00551   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
00552   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = openmaxStandComp->pComponentPrivate;
00553   omx_base_video_PortType *pPort = (omx_base_video_PortType *) omx_videosrc_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX];  
00554   if (ComponentParameterStructure == NULL) {
00555     return OMX_ErrorBadParameter;
00556   }
00557 
00558   DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Getting parameter %08x\n",__func__, nParamIndex);
00559   
00560   /* Check which structure we are being fed and fill its header */
00561   switch(nParamIndex) {
00562   case OMX_IndexParamVideoInit:
00563     if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) { 
00564       break;
00565     }
00566     memcpy(ComponentParameterStructure, &omx_videosrc_component_Private->sPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
00567     break;    
00568   case OMX_IndexParamVideoPortFormat:
00569     pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00570     if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) { 
00571       break;
00572     }
00573     if (pVideoPortFormat->nPortIndex < 1) {
00574       memcpy(pVideoPortFormat, &pPort->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00575     } else {
00576       return OMX_ErrorBadPortIndex;
00577     }
00578     break;  
00579   case OMX_IndexVendorFileReadInputFilename : 
00580     strcpy((char *)ComponentParameterStructure, "still no filename");
00581     break;
00582   default: /*Call the base component function*/
00583     return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00584   }
00585   return err;
00586 }
00587 
00591 OMX_ERRORTYPE omx_videosrc_component_MessageHandler(OMX_COMPONENTTYPE* openmaxStandComp,internalRequestMessageType *message) {
00592   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = (omx_videosrc_component_PrivateType*)openmaxStandComp->pComponentPrivate;
00593   OMX_ERRORTYPE err = OMX_ErrorNone;
00594   OMX_STATETYPE oldState = omx_videosrc_component_Private->state;
00595 
00596   DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s\n", __func__);
00597 
00598   /* Execute the base message handling */
00599   err = omx_base_component_MessageHandler(openmaxStandComp,message);
00600 
00601   if (message->messageType == OMX_CommandStateSet && err == OMX_ErrorNone){ 
00602     if ((message->messageParam == OMX_StateExecuting) && (oldState == OMX_StateIdle)) {    
00603       err = omx_videosrc_component_Init(openmaxStandComp);
00604       if(err!=OMX_ErrorNone) { 
00605         DEBUG(DEB_LEV_ERR, "In %s Video Source Init Failed Error=%x\n",__func__,err); 
00606       }
00607     } else if ((message->messageParam == OMX_StateIdle) && (oldState == OMX_StateExecuting)) {
00608       err = omx_videosrc_component_Deinit(openmaxStandComp);
00609       if(err!=OMX_ErrorNone) { 
00610         DEBUG(DEB_LEV_ERR, "In %s Video Source Deinit Failed Error=%x\n",__func__,err); 
00611       }
00612     }
00613   }
00614   return err;
00615 }
00616 
00617 OMX_ERRORTYPE videosrc_port_AllocateBuffer(
00618   omx_base_PortType *openmaxStandPort,
00619   OMX_BUFFERHEADERTYPE** pBuffer,
00620   OMX_U32 nPortIndex,
00621   OMX_PTR pAppPrivate,
00622   OMX_U32 nSizeBytes) {
00623   
00624   int i;
00625   OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
00626   omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
00627   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = (omx_videosrc_component_PrivateType*)omx_base_component_Private;
00628   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00629 
00630   if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
00631     return OMX_ErrorBadPortIndex;
00632   }
00633   if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
00634     return OMX_ErrorBadPortIndex;
00635   }
00636 
00637   if (omx_base_component_Private->transientState != OMX_TransStateLoadedToIdle) {
00638     if (!openmaxStandPort->bIsTransientToEnabled) {
00639       DEBUG(DEB_LEV_ERR, "In %s: The port is not allowed to receive buffers\n", __func__);
00640       return OMX_ErrorIncorrectStateTransition;
00641     }
00642   }
00643 
00644   if(nSizeBytes < openmaxStandPort->sPortParam.nBufferSize) {
00645     DEBUG(DEB_LEV_ERR, "In %s: Requested Buffer Size %lu is less than Minimum Buffer Size %lu\n", __func__, nSizeBytes, openmaxStandPort->sPortParam.nBufferSize);
00646     return OMX_ErrorIncorrectStateTransition;
00647   }
00648   
00649   for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
00650     if (openmaxStandPort->bBufferStateAllocated[i] == BUFFER_FREE) {
00651       openmaxStandPort->pInternalBufferStorage[i] = calloc(1,sizeof(OMX_BUFFERHEADERTYPE));
00652       if (!openmaxStandPort->pInternalBufferStorage[i]) {
00653         return OMX_ErrorInsufficientResources;
00654       }
00655       setHeader(openmaxStandPort->pInternalBufferStorage[i], sizeof(OMX_BUFFERHEADERTYPE));
00656       /* Map the buffer with the device's memory area*/
00657       if(i > omx_videosrc_component_Private->memoryBuffer.frames) {
00658         DEBUG(DEB_LEV_ERR, "In %s returning error i=%d, nframe=%d\n", __func__,i,omx_videosrc_component_Private->memoryBuffer.frames);
00659         return OMX_ErrorInsufficientResources;
00660       }
00661       omx_videosrc_component_Private->bOutBufferMemoryMapped = OMX_TRUE;
00662       openmaxStandPort->pInternalBufferStorage[i]->pBuffer = (OMX_U8*)(omx_videosrc_component_Private->memoryMap + omx_videosrc_component_Private->memoryBuffer.offsets[i]);
00663       openmaxStandPort->pInternalBufferStorage[i]->nAllocLen = (int)nSizeBytes;
00664       openmaxStandPort->pInternalBufferStorage[i]->pPlatformPrivate = openmaxStandPort;
00665       openmaxStandPort->pInternalBufferStorage[i]->pAppPrivate = pAppPrivate;
00666       *pBuffer = openmaxStandPort->pInternalBufferStorage[i];
00667       openmaxStandPort->bBufferStateAllocated[i] = BUFFER_ALLOCATED;
00668       openmaxStandPort->bBufferStateAllocated[i] |= HEADER_ALLOCATED;
00669       if (openmaxStandPort->sPortParam.eDir == OMX_DirInput) {
00670         openmaxStandPort->pInternalBufferStorage[i]->nInputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
00671       } else {
00672         openmaxStandPort->pInternalBufferStorage[i]->nOutputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
00673       }
00674       openmaxStandPort->nNumAssignedBuffers++;
00675       DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
00676 
00677       if (openmaxStandPort->sPortParam.nBufferCountActual == openmaxStandPort->nNumAssignedBuffers) {
00678         openmaxStandPort->sPortParam.bPopulated = OMX_TRUE;
00679         openmaxStandPort->bIsFullOfBuffers = OMX_TRUE;
00680         DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s nPortIndex=%d\n",__func__,(int)nPortIndex);
00681         tsem_up(openmaxStandPort->pAllocSem);
00682       }
00683       return OMX_ErrorNone;
00684     }
00685   }
00686   DEBUG(DEB_LEV_ERR, "In %s Error: no available buffers\n",__func__);
00687   return OMX_ErrorInsufficientResources;
00688 }
00689 OMX_ERRORTYPE videosrc_port_FreeBuffer(
00690   omx_base_PortType *openmaxStandPort,
00691   OMX_U32 nPortIndex,
00692   OMX_BUFFERHEADERTYPE* pBuffer) {
00693 
00694   int i;
00695   OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
00696   omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
00697   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = (omx_videosrc_component_PrivateType*)omx_base_component_Private;
00698   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00699 
00700   if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
00701     return OMX_ErrorBadPortIndex;
00702   }
00703   if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
00704     return OMX_ErrorBadPortIndex;
00705   }
00706 
00707   if (omx_base_component_Private->transientState != OMX_TransStateIdleToLoaded) {
00708     if (!openmaxStandPort->bIsTransientToDisabled) {
00709       DEBUG(DEB_LEV_FULL_SEQ, "In %s: The port is not allowed to free the buffers\n", __func__);
00710       (*(omx_base_component_Private->callbacks->EventHandler))
00711         (omxComponent,
00712         omx_base_component_Private->callbackData,
00713         OMX_EventError, /* The command was completed */
00714         OMX_ErrorPortUnpopulated, /* The commands was a OMX_CommandStateSet */
00715         nPortIndex, /* The state has been changed in message->messageParam2 */
00716         NULL);
00717     }
00718   }
00719   
00720   for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
00721     if (openmaxStandPort->bBufferStateAllocated[i] & (BUFFER_ASSIGNED | BUFFER_ALLOCATED)) {
00722 
00723       openmaxStandPort->bIsFullOfBuffers = OMX_FALSE;
00724       if (openmaxStandPort->bBufferStateAllocated[i] & BUFFER_ALLOCATED) {
00725         if(openmaxStandPort->pInternalBufferStorage[i]->pBuffer){
00726           DEBUG(DEB_LEV_PARAMS, "In %s freeing %i pBuffer=%x\n",__func__, (int)i, (int)openmaxStandPort->pInternalBufferStorage[i]->pBuffer);
00727           //free(openmaxStandPort->pInternalBufferStorage[i]->pBuffer);
00728           openmaxStandPort->pInternalBufferStorage[i]->pBuffer=NULL;
00729           omx_videosrc_component_Private->bOutBufferMemoryMapped = OMX_FALSE;
00730         }
00731       } else if (openmaxStandPort->bBufferStateAllocated[i] & BUFFER_ASSIGNED) {
00732         free(pBuffer);
00733         pBuffer=NULL;
00734       }
00735       if(openmaxStandPort->bBufferStateAllocated[i] & HEADER_ALLOCATED) {
00736         free(openmaxStandPort->pInternalBufferStorage[i]);
00737         openmaxStandPort->pInternalBufferStorage[i]=NULL;
00738       }
00739 
00740       openmaxStandPort->bBufferStateAllocated[i] = BUFFER_FREE;
00741 
00742       openmaxStandPort->nNumAssignedBuffers--;
00743       DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
00744 
00745       if (openmaxStandPort->nNumAssignedBuffers == 0) {
00746         openmaxStandPort->sPortParam.bPopulated = OMX_FALSE;
00747         openmaxStandPort->bIsEmptyOfBuffers = OMX_TRUE;
00748         tsem_up(openmaxStandPort->pAllocSem);
00749       }
00750       return OMX_ErrorNone;
00751     }
00752   }
00753   return OMX_ErrorInsufficientResources;
00754 }
00755 
00756 OMX_ERRORTYPE videosrc_port_AllocateTunnelBuffer(omx_base_PortType *openmaxStandPort,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_U32 nSizeBytes)
00757 {
00758   int i;
00759   OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
00760   omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
00761   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = (omx_videosrc_component_PrivateType*)omx_base_component_Private;
00762   OMX_U8* pBuffer=NULL;
00763   OMX_ERRORTYPE eError=OMX_ErrorNone;
00764   OMX_U32 numRetry=0;
00765   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00766 
00767   if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
00768     DEBUG(DEB_LEV_ERR, "In %s: Bad Port Index\n", __func__);
00769     return OMX_ErrorBadPortIndex;
00770   }
00771   if (! PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
00772     DEBUG(DEB_LEV_ERR, "In %s: Port is not tunneled Flag=%x\n", __func__, (int)openmaxStandPort->nTunnelFlags);
00773     return OMX_ErrorBadPortIndex;
00774   }
00775 
00776   if (omx_base_component_Private->transientState != OMX_TransStateLoadedToIdle) {
00777     if (!openmaxStandPort->bIsTransientToEnabled) {
00778       DEBUG(DEB_LEV_ERR, "In %s: The port is not allowed to receive buffers\n", __func__);
00779       return OMX_ErrorIncorrectStateTransition;
00780     }
00781   }
00782   
00783   for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
00784     if (openmaxStandPort->bBufferStateAllocated[i] == BUFFER_FREE) {
00785       /* Map the buffer with the device's memory area*/
00786       if(i > omx_videosrc_component_Private->memoryBuffer.frames) {
00787         DEBUG(DEB_LEV_ERR, "In %s returning error i=%d, nframe=%d\n", __func__,i,omx_videosrc_component_Private->memoryBuffer.frames);
00788         return OMX_ErrorInsufficientResources;
00789       }
00790       omx_videosrc_component_Private->bOutBufferMemoryMapped = OMX_TRUE;
00791       pBuffer = (OMX_U8*)(omx_videosrc_component_Private->memoryMap + omx_videosrc_component_Private->memoryBuffer.offsets[i]);
00792 
00793       /*Retry more than once, if the tunneled component is not in Loaded->Idle State*/
00794       while(numRetry <TUNNEL_USE_BUFFER_RETRY) {
00795         eError=OMX_UseBuffer(openmaxStandPort->hTunneledComponent,&openmaxStandPort->pInternalBufferStorage[i],
00796                              openmaxStandPort->nTunneledPort,NULL,nSizeBytes,pBuffer); 
00797         if(eError!=OMX_ErrorNone) {
00798           DEBUG(DEB_LEV_FULL_SEQ,"Tunneled Component Couldn't Use buffer %i From Comp=%s Retry=%d\n",
00799           i,omx_base_component_Private->name,(int)numRetry);
00800 
00801           if((eError ==  OMX_ErrorIncorrectStateTransition) && numRetry<TUNNEL_USE_BUFFER_RETRY) {
00802             DEBUG(DEB_LEV_FULL_SEQ,"Waiting for next try %i \n",(int)numRetry);
00803             usleep(TUNNEL_USE_BUFFER_RETRY_USLEEP_TIME);
00804             numRetry++;
00805             continue;
00806           }
00807           return eError;
00808         }
00809         else {
00810           break;
00811         }
00812       }
00813       openmaxStandPort->bBufferStateAllocated[i] = BUFFER_ALLOCATED;
00814       openmaxStandPort->nNumAssignedBuffers++;
00815       DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
00816 
00817       if (openmaxStandPort->sPortParam.nBufferCountActual == openmaxStandPort->nNumAssignedBuffers) {
00818         openmaxStandPort->sPortParam.bPopulated = OMX_TRUE;
00819         openmaxStandPort->bIsFullOfBuffers = OMX_TRUE;
00820         DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s nPortIndex=%d\n",__func__, (int)nPortIndex);
00821       }
00822       queue(openmaxStandPort->pBufferQueue, openmaxStandPort->pInternalBufferStorage[i]);
00823     }
00824   }
00825   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s Allocated all buffers\n",__func__);
00826   return OMX_ErrorNone;
00827 }
00828 
00829 OMX_ERRORTYPE videosrc_port_FreeTunnelBuffer(omx_base_PortType *openmaxStandPort,OMX_U32 nPortIndex)
00830 {
00831   int i;
00832   OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
00833   omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
00834   omx_videosrc_component_PrivateType* omx_videosrc_component_Private = (omx_videosrc_component_PrivateType*)omx_base_component_Private;
00835   OMX_ERRORTYPE eError=OMX_ErrorNone;
00836   OMX_U32 numRetry=0;
00837   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00838 
00839   if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
00840     DEBUG(DEB_LEV_ERR, "In %s: Bad Port Index\n", __func__);
00841     return OMX_ErrorBadPortIndex;
00842   }
00843   if (! PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
00844     DEBUG(DEB_LEV_ERR, "In %s: Port is not tunneled\n", __func__);
00845     return OMX_ErrorBadPortIndex;
00846   }
00847 
00848   if (omx_base_component_Private->transientState != OMX_TransStateIdleToLoaded) {
00849     if (!openmaxStandPort->bIsTransientToDisabled) {
00850       DEBUG(DEB_LEV_FULL_SEQ, "In %s: The port is not allowed to free the buffers\n", __func__);
00851       (*(omx_base_component_Private->callbacks->EventHandler))
00852         (omxComponent,
00853         omx_base_component_Private->callbackData,
00854         OMX_EventError, /* The command was completed */
00855         OMX_ErrorPortUnpopulated, /* The commands was a OMX_CommandStateSet */
00856         nPortIndex, /* The state has been changed in message->messageParam2 */
00857         NULL);
00858     }
00859   }
00860 
00861   for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
00862     if (openmaxStandPort->bBufferStateAllocated[i] & (BUFFER_ASSIGNED | BUFFER_ALLOCATED)) {
00863 
00864       openmaxStandPort->bIsFullOfBuffers = OMX_FALSE;
00865       if (openmaxStandPort->bBufferStateAllocated[i] & BUFFER_ALLOCATED) {
00866         openmaxStandPort->pInternalBufferStorage[i]->pBuffer = NULL;
00867         omx_videosrc_component_Private->bOutBufferMemoryMapped = OMX_FALSE;
00868       }
00869       /*Retry more than once, if the tunneled component is not in Idle->Loaded State*/
00870       while(numRetry <TUNNEL_USE_BUFFER_RETRY) {
00871         eError=OMX_FreeBuffer(openmaxStandPort->hTunneledComponent,openmaxStandPort->nTunneledPort,openmaxStandPort->pInternalBufferStorage[i]);
00872         if(eError!=OMX_ErrorNone) {
00873           DEBUG(DEB_LEV_ERR,"Tunneled Component Couldn't free buffer %i \n",i);
00874           if((eError ==  OMX_ErrorIncorrectStateTransition) && numRetry<TUNNEL_USE_BUFFER_RETRY) {
00875             DEBUG(DEB_LEV_ERR,"Waiting for next try %i \n",(int)numRetry);
00876             usleep(TUNNEL_USE_BUFFER_RETRY_USLEEP_TIME);
00877             numRetry++;
00878             continue;
00879           }
00880           return eError;
00881         } else {
00882           break;
00883         }
00884       }
00885       openmaxStandPort->bBufferStateAllocated[i] = BUFFER_FREE;
00886 
00887       openmaxStandPort->nNumAssignedBuffers--;
00888       DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
00889 
00890       if (openmaxStandPort->nNumAssignedBuffers == 0) {
00891         openmaxStandPort->sPortParam.bPopulated = OMX_FALSE;
00892         openmaxStandPort->bIsEmptyOfBuffers = OMX_TRUE;
00893         //tsem_up(openmaxStandPort->pAllocSem);
00894       }
00895     }
00896   }
00897   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s Qelem=%d BSem=%d\n", __func__,openmaxStandPort->pBufferQueue->nelem,openmaxStandPort->pBufferSem->semval);
00898   return OMX_ErrorNone;
00899 }

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