omx_fbdev_sink_component.c

Go to the documentation of this file.
00001 
00030 #include <errno.h>
00031 #include <omxcore.h>
00032 #include <omx_fbdev_sink_component.h>
00033 
00035 #define HEIGHT_OFFSET 10
00036 
00038 static OMX_U32 nFrameProcessTime = 40000; // in micro second
00039 
00041 static OMX_U32 nofbdev_sinkInstance=0;
00042 
00048 long GetTime() {
00049     struct timeval now;
00050     gettimeofday(&now, NULL);
00051     return ((long)now.tv_sec) * 1000 + ((long)now.tv_usec) / 1000;
00052 }
00053 
00057 OMX_ERRORTYPE omx_fbdev_sink_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName) {
00058   OMX_ERRORTYPE err = OMX_ErrorNone;  
00059   omx_fbdev_sink_component_PortType *pPort;
00060   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private;
00061   OMX_U32 i;
00062 
00063   if (!openmaxStandComp->pComponentPrivate) {
00064     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s, allocating component\n", __func__);
00065     openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_fbdev_sink_component_PrivateType));
00066     if(openmaxStandComp->pComponentPrivate == NULL) {
00067       return OMX_ErrorInsufficientResources;
00068     }
00069   } else {
00070     DEBUG(DEB_LEV_FUNCTION_NAME, "In %s, Error Component %x Already Allocated\n", __func__, (int)openmaxStandComp->pComponentPrivate);
00071   }
00072 
00073   omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
00074   omx_fbdev_sink_component_Private->ports = NULL;
00075   
00079   err = omx_base_sink_Constructor(openmaxStandComp, cComponentName);
00080   
00082   if (omx_fbdev_sink_component_Private->sPortTypesParam.nPorts && !omx_fbdev_sink_component_Private->ports) {
00083     omx_fbdev_sink_component_Private->ports = calloc(omx_fbdev_sink_component_Private->sPortTypesParam.nPorts, sizeof(omx_base_PortType *));
00084     if (!omx_fbdev_sink_component_Private->ports) {
00085       return OMX_ErrorInsufficientResources;
00086     }
00087     for (i=0; i < omx_fbdev_sink_component_Private->sPortTypesParam.nPorts; i++) {
00088       omx_fbdev_sink_component_Private->ports[i] = calloc(1, sizeof(omx_fbdev_sink_component_PortType));
00089       if (!omx_fbdev_sink_component_Private->ports[i]) {
00090         return OMX_ErrorInsufficientResources;
00091       }
00092     }
00093   }
00094 
00095   base_video_port_Constructor(openmaxStandComp, &omx_fbdev_sink_component_Private->ports[0], 0, OMX_TRUE);
00096 
00097   pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
00098 
00101   pPort->sPortParam.format.video.nFrameWidth = 352;
00102   pPort->sPortParam.format.video.nFrameHeight = 288;
00103   pPort->sPortParam.format.video.nBitrate = 0;
00104   pPort->sPortParam.format.video.xFramerate = 25;
00105   pPort->sPortParam.format.video.eColorFormat = OMX_COLOR_Format24bitRGB888;
00106 
00107   //  Figure out stride, slice height, min buffer size
00108   pPort->sPortParam.format.video.nStride = calcStride(pPort->sPortParam.format.video.nFrameWidth, pPort->sPortParam.format.video.eColorFormat);
00109   pPort->sPortParam.format.video.nSliceHeight = pPort->sPortParam.format.video.nFrameHeight;  //  No support for slices yet
00110   pPort->sPortParam.nBufferSize = (OMX_U32) abs(pPort->sPortParam.format.video.nStride) * pPort->sPortParam.format.video.nSliceHeight;
00111 
00112   pPort->sVideoParam.eColorFormat = OMX_COLOR_Format24bitRGB888;
00113   pPort->sVideoParam.xFramerate = 25;
00114 
00115   DEBUG(DEB_LEV_PARAMS, "In %s, bSize=%d stride=%d\n", __func__,(int)pPort->sPortParam.nBufferSize,(int)pPort->sPortParam.format.video.nStride);
00116   
00118   setHeader(&pPort->omxConfigCrop, sizeof(OMX_CONFIG_RECTTYPE));  
00119   pPort->omxConfigCrop.nPortIndex = OMX_BASE_SINK_INPUTPORT_INDEX;
00120   pPort->omxConfigCrop.nLeft = pPort->omxConfigCrop.nTop = 0;
00121   pPort->omxConfigCrop.nWidth = pPort->omxConfigCrop.nHeight = 0;
00122 
00123   setHeader(&pPort->omxConfigRotate, sizeof(OMX_CONFIG_ROTATIONTYPE));  
00124   pPort->omxConfigRotate.nPortIndex = OMX_BASE_SINK_INPUTPORT_INDEX;
00125   pPort->omxConfigRotate.nRotation = 0;  //Default: No rotation (0 degrees)
00126 
00127   setHeader(&pPort->omxConfigMirror, sizeof(OMX_CONFIG_MIRRORTYPE));  
00128   pPort->omxConfigMirror.nPortIndex = OMX_BASE_SINK_INPUTPORT_INDEX;
00129   pPort->omxConfigMirror.eMirror = OMX_MirrorNone;  //Default: No mirroring
00130 
00131   setHeader(&pPort->omxConfigScale, sizeof(OMX_CONFIG_SCALEFACTORTYPE));  
00132   pPort->omxConfigScale.nPortIndex = OMX_BASE_SINK_INPUTPORT_INDEX;
00133   pPort->omxConfigScale.xWidth = pPort->omxConfigScale.xHeight = 0x10000;  //Default: No scaling (scale factor = 1)
00134 
00135   setHeader(&pPort->omxConfigOutputPosition, sizeof(OMX_CONFIG_POINTTYPE));  
00136   pPort->omxConfigOutputPosition.nPortIndex = OMX_BASE_SINK_INPUTPORT_INDEX;
00137   pPort->omxConfigOutputPosition.nX = pPort->omxConfigOutputPosition.nY = 0; //Default: No shift in output position (0,0)
00138 
00140   omx_fbdev_sink_component_Private->destructor = omx_fbdev_sink_component_Destructor;
00141   omx_fbdev_sink_component_Private->BufferMgmtCallback = omx_fbdev_sink_component_BufferMgmtCallback;
00142   openmaxStandComp->SetParameter = omx_fbdev_sink_component_SetParameter;
00143   openmaxStandComp->GetParameter = omx_fbdev_sink_component_GetParameter;
00144   omx_fbdev_sink_component_Private->messageHandler = omx_fbdev_sink_component_MessageHandler;
00145 
00146   nofbdev_sinkInstance++;
00147   if(nofbdev_sinkInstance > MAX_NUM_OF_fbdev_sink_component_INSTANCES) {
00148     DEBUG(DEB_LEV_ERR, "Reached Max Instances %d\n",(int)nofbdev_sinkInstance);
00149     return OMX_ErrorInsufficientResources;
00150   }
00151 
00152   return err;
00153 }
00154 
00157 OMX_ERRORTYPE omx_fbdev_sink_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp) {
00158   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
00159   OMX_U32 i;
00160  
00161   /* frees port/s */
00162   if (omx_fbdev_sink_component_Private->ports) {
00163     for (i=0; i < omx_fbdev_sink_component_Private->sPortTypesParam.nPorts; i++) {
00164       if(omx_fbdev_sink_component_Private->ports[i])
00165         omx_fbdev_sink_component_Private->ports[i]->PortDestructor(omx_fbdev_sink_component_Private->ports[i]);
00166     }
00167     free(omx_fbdev_sink_component_Private->ports);
00168     omx_fbdev_sink_component_Private->ports=NULL;
00169   }
00170 
00171   omx_base_sink_Destructor(openmaxStandComp);
00172   nofbdev_sinkInstance--;
00173 
00174   return OMX_ErrorNone;
00175 }
00176 
00177 
00178 OMX_S32 calcStride2(omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private) {
00179   OMX_U32 stride;
00180 
00181   if(omx_fbdev_sink_component_Private->vscr_info.bits_per_pixel == 32){
00182     stride = omx_fbdev_sink_component_Private->fscr_info.line_length;
00183   } else if(omx_fbdev_sink_component_Private->vscr_info.bits_per_pixel == 8){
00184     stride = omx_fbdev_sink_component_Private->fscr_info.line_length*4;
00185   } else{
00186     stride = omx_fbdev_sink_component_Private->fscr_info.line_length*
00187            omx_fbdev_sink_component_Private->vscr_info.bits_per_pixel/8;
00188   }
00189   return stride;
00190 }
00195 OMX_ERRORTYPE omx_fbdev_sink_component_Init(OMX_COMPONENTTYPE *openmaxStandComp) {
00196   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
00197   omx_fbdev_sink_component_PortType* pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
00198 
00199   omx_fbdev_sink_component_Private->fd = open(FBDEV_FILENAME, O_RDWR);
00200   if (omx_fbdev_sink_component_Private->fd < 0) {
00201     DEBUG(DEB_LEV_ERR, "Unable to open framebuffer %s!  open returned: %i, errno=%d  ENODEV : %d \n", FBDEV_FILENAME, omx_fbdev_sink_component_Private->fd,errno,ENODEV);
00202     return OMX_ErrorHardware;
00203   } 
00204 
00206   if(ioctl(omx_fbdev_sink_component_Private->fd, FBIOGET_VSCREENINFO, &omx_fbdev_sink_component_Private->vscr_info) != 0 ||
00207     ioctl(omx_fbdev_sink_component_Private->fd, FBIOGET_FSCREENINFO, &omx_fbdev_sink_component_Private->fscr_info) != 0) {
00208     DEBUG(DEB_LEV_ERR, "Error during ioctl to get framebuffer parameters!\n");
00209     return OMX_ErrorHardware;
00210   }
00211 
00215   omx_fbdev_sink_component_Private->fbpxlfmt = find_omx_pxlfmt(&omx_fbdev_sink_component_Private->vscr_info);
00216   if (omx_fbdev_sink_component_Private->fbpxlfmt == OMX_COLOR_FormatUnused) {
00217     DEBUG(DEB_LEV_ERR,"\n in %s finding omx pixel format returned error\n", __func__);
00218     return OMX_ErrorUnsupportedSetting;
00219   }
00220 
00221   DEBUG(DEB_LEV_PARAMS, "xres=%u,yres=%u,xres_virtual %u,yres_virtual=%u,xoffset=%u,yoffset=%u,bits_per_pixel=%u,grayscale=%u,nonstd=%u,height=%u,width=%u\n",
00222           omx_fbdev_sink_component_Private->vscr_info.xres                     /* visible resolution           */
00223         , omx_fbdev_sink_component_Private->vscr_info.yres
00224         , omx_fbdev_sink_component_Private->vscr_info.xres_virtual             /* virtual resolution           */
00225         , omx_fbdev_sink_component_Private->vscr_info.yres_virtual
00226         , omx_fbdev_sink_component_Private->vscr_info.xoffset                  /* offset from virtual to visible */
00227         , omx_fbdev_sink_component_Private->vscr_info.yoffset                  /* resolution                   */
00228         , omx_fbdev_sink_component_Private->vscr_info.bits_per_pixel           /* guess what                   */
00229         , omx_fbdev_sink_component_Private->vscr_info.grayscale                /* != 0 Graylevels instead of colors */
00230         , omx_fbdev_sink_component_Private->vscr_info.nonstd                   /* != 0 Non standard pixel format */
00231         , omx_fbdev_sink_component_Private->vscr_info.height                   /* height of picture in mm    */
00232         , omx_fbdev_sink_component_Private->vscr_info.width);
00233 
00234   DEBUG(DEB_LEV_PARAMS, "Red Off=%u len=%u,Green off=%u,len=%u,blue off=%u len=%u,trans off=%u,len=%u\n",
00235     omx_fbdev_sink_component_Private->vscr_info.red.offset,omx_fbdev_sink_component_Private->vscr_info.red.length,
00236   omx_fbdev_sink_component_Private->vscr_info.green.offset, omx_fbdev_sink_component_Private->vscr_info.green.length,
00237   omx_fbdev_sink_component_Private->vscr_info.blue.offset,omx_fbdev_sink_component_Private->vscr_info.blue.length,
00238   omx_fbdev_sink_component_Private->vscr_info.transp.offset,omx_fbdev_sink_component_Private->vscr_info.transp.length);
00239 
00240 
00241   omx_fbdev_sink_component_Private->fbwidth = omx_fbdev_sink_component_Private->vscr_info.xres;
00242   omx_fbdev_sink_component_Private->fbheight = pPort->sPortParam.format.video.nFrameHeight;
00243   omx_fbdev_sink_component_Private->fbbpp = omx_fbdev_sink_component_Private->vscr_info.bits_per_pixel;
00244   //omx_fbdev_sink_component_Private->fbstride = calcStride(omx_fbdev_sink_component_Private->fbwidth, omx_fbdev_sink_component_Private->fbpxlfmt);
00245   //omx_fbdev_sink_component_Private->fbstride = omx_fbdev_sink_component_Private->fscr_info.line_length*
00246     //         omx_fbdev_sink_component_Private->vscr_info.bits_per_pixel/8;
00247   omx_fbdev_sink_component_Private->fbstride = calcStride2(omx_fbdev_sink_component_Private);
00248 
00252   omx_fbdev_sink_component_Private->product = omx_fbdev_sink_component_Private->fbstride * (omx_fbdev_sink_component_Private->fbheight + HEIGHT_OFFSET); 
00253 
00255   omx_fbdev_sink_component_Private->scr_ptr = (unsigned char*) mmap(0, omx_fbdev_sink_component_Private->product, PROT_READ | PROT_WRITE, MAP_SHARED, omx_fbdev_sink_component_Private->fd,0);
00256   if (omx_fbdev_sink_component_Private->scr_ptr == NULL) {
00257     DEBUG(DEB_LEV_ERR, "in %s Failed to mmap framebuffer memory!\n", __func__);
00258     close (omx_fbdev_sink_component_Private->fd);
00259     return OMX_ErrorHardware;
00260   }
00261 
00262   DEBUG(DEB_LEV_SIMPLE_SEQ, "mmap framebuffer memory =%x omx_fbdev_sink_component_Private->product=%d stride=%d\n",(int)omx_fbdev_sink_component_Private->scr_ptr,(int)omx_fbdev_sink_component_Private->product,(int)omx_fbdev_sink_component_Private->fbstride);
00263   DEBUG(DEB_LEV_SIMPLE_SEQ, "Successfully opened %s for display.\n", "/dev/fb0");
00264   DEBUG(DEB_LEV_SIMPLE_SEQ, "Display Size: %u x %u\n", (int)omx_fbdev_sink_component_Private->fbwidth, (int)omx_fbdev_sink_component_Private->fbheight);
00265   DEBUG(DEB_LEV_SIMPLE_SEQ, "Bitdepth: %u\n", (int)omx_fbdev_sink_component_Private->fbbpp);
00266 
00267   return OMX_ErrorNone;
00268 }
00269 
00273 OMX_ERRORTYPE omx_fbdev_sink_component_Deinit(OMX_COMPONENTTYPE *openmaxStandComp) {
00274   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
00275 
00276   if (omx_fbdev_sink_component_Private->scr_ptr) {
00277     munmap(omx_fbdev_sink_component_Private->scr_ptr, omx_fbdev_sink_component_Private->product);
00278   }
00279   if (close(omx_fbdev_sink_component_Private->fd) == -1) {
00280     return OMX_ErrorHardware;
00281   }
00282   return OMX_ErrorNone;
00283 }
00284 
00291 OMX_S32 calcStride(OMX_U32 width, OMX_COLOR_FORMATTYPE omx_pxlfmt) {
00292   OMX_U32 stride;
00293   OMX_U32 bpp; // bit per pixel
00294 
00295   switch(omx_pxlfmt) {
00296     case OMX_COLOR_FormatMonochrome:
00297       bpp = 1;
00298       break;
00299     case OMX_COLOR_FormatL2:
00300       bpp = 2;
00301     case OMX_COLOR_FormatL4:
00302       bpp = 4;
00303       break;
00304     case OMX_COLOR_FormatL8:
00305     case OMX_COLOR_Format8bitRGB332:
00306     case OMX_COLOR_FormatRawBayer8bit:
00307     case OMX_COLOR_FormatRawBayer8bitcompressed:
00308       bpp = 8;  
00309       break;
00310     case OMX_COLOR_FormatRawBayer10bit:
00311       bpp = 10;
00312       break;
00313     case OMX_COLOR_FormatYUV411Planar:
00314     case OMX_COLOR_FormatYUV411PackedPlanar:
00315     case OMX_COLOR_Format12bitRGB444:
00316     case OMX_COLOR_FormatYUV420Planar:
00317     case OMX_COLOR_FormatYUV420PackedPlanar:
00318     case OMX_COLOR_FormatYUV420SemiPlanar:
00319     case OMX_COLOR_FormatYUV444Interleaved:
00320       bpp = 12;
00321       break;
00322     case OMX_COLOR_FormatL16:
00323     case OMX_COLOR_Format16bitARGB4444:
00324     case OMX_COLOR_Format16bitARGB1555:
00325     case OMX_COLOR_Format16bitRGB565:
00326     case OMX_COLOR_Format16bitBGR565:
00327     case OMX_COLOR_FormatYUV422Planar:
00328     case OMX_COLOR_FormatYUV422PackedPlanar:
00329     case OMX_COLOR_FormatYUV422SemiPlanar:
00330     case OMX_COLOR_FormatYCbYCr:
00331     case OMX_COLOR_FormatYCrYCb:
00332     case OMX_COLOR_FormatCbYCrY:
00333     case OMX_COLOR_FormatCrYCbY:
00334       bpp = 16;
00335       break;
00336     case OMX_COLOR_Format18bitRGB666:
00337     case OMX_COLOR_Format18bitARGB1665:
00338       bpp = 18;
00339       break;
00340     case OMX_COLOR_Format19bitARGB1666:
00341       bpp = 19;
00342       break;
00343     case OMX_COLOR_FormatL24:
00344     case OMX_COLOR_Format24bitRGB888:
00345     case OMX_COLOR_Format24bitBGR888:
00346     case OMX_COLOR_Format24bitARGB1887:
00347       bpp = 24;
00348       break;
00349     case OMX_COLOR_Format25bitARGB1888:
00350       bpp = 25;
00351       break;
00352     case OMX_COLOR_FormatL32:
00353     case OMX_COLOR_Format32bitBGRA8888:
00354     case OMX_COLOR_Format32bitARGB8888:
00355       bpp = 32;
00356       break;
00357     default:
00358       bpp = 0;
00359       break;
00360   }
00361   stride = (width * bpp) >> 3; // division by 8 to get byte per pixel value
00362   return (OMX_S32) stride;
00363 }
00364 
00365 
00373 OMX_COLOR_FORMATTYPE find_omx_pxlfmt(struct fb_var_screeninfo *vscr_info) {
00374   OMX_COLOR_FORMATTYPE omx_pxlfmt = OMX_COLOR_FormatUnused;
00375 
00377   if (vscr_info->grayscale) {
00378     switch (vscr_info->bits_per_pixel) {
00379       case 2:
00380         omx_pxlfmt = OMX_COLOR_FormatL2;
00381         break;
00382       case 4:
00383         omx_pxlfmt = OMX_COLOR_FormatL4;
00384         break;
00385       case 8:
00386         omx_pxlfmt = OMX_COLOR_FormatL8;
00387         break;
00388       case 16:
00389         omx_pxlfmt = OMX_COLOR_FormatL16;
00390         break;
00391       case 24:
00392         omx_pxlfmt = OMX_COLOR_FormatL24;
00393         break;
00394       case 32:
00395         omx_pxlfmt = OMX_COLOR_FormatL32;
00396         break;
00397       default:
00398         omx_pxlfmt = OMX_COLOR_FormatUnused;
00399         break;
00400     }
00401   } else {
00403     if(vscr_info->bits_per_pixel == 1) {
00404       omx_pxlfmt = OMX_COLOR_FormatMonochrome;
00405     } else if ( vscr_info->red.length == 3 && vscr_info->red.offset == 5 &&
00406                 vscr_info->green.length == 3 && vscr_info->green.offset == 2 &&
00407                 vscr_info->blue.length == 2 && vscr_info->blue.offset == 0 &&
00408                 vscr_info->transp.length == 0) {
00409       omx_pxlfmt = OMX_COLOR_Format8bitRGB332;
00410     } else if ( vscr_info->red.length == 4 && vscr_info->red.offset == 8 &&
00411                 vscr_info->green.length == 4 && vscr_info->green.offset == 4 &&
00412                 vscr_info->blue.length == 4 && vscr_info->blue.offset == 0 &&
00413                 vscr_info->transp.length == 0) {
00414       omx_pxlfmt = OMX_COLOR_Format12bitRGB444;
00415     } else if ( vscr_info->transp.length == 4 && vscr_info->transp.offset == 12 &&
00416                 vscr_info->red.length == 4 && vscr_info->red.offset == 8 &&
00417                 vscr_info->green.length == 4 && vscr_info->green.offset == 4 &&
00418                 vscr_info->blue.length == 4 && vscr_info->blue.offset == 0) {
00419       omx_pxlfmt = OMX_COLOR_Format16bitARGB4444;
00420     } else if ( vscr_info->red.length == 5 && vscr_info->blue.length == 5 && 
00421                 vscr_info->transp.length == 1 && vscr_info->transp.offset == 15 &&
00422                 vscr_info->green.length == 5 && vscr_info->green.offset == 5 &&
00423                 vscr_info->red.offset == 10 && vscr_info->blue.offset == 0) {
00424       omx_pxlfmt = OMX_COLOR_Format16bitARGB1555;
00425     } else if ( vscr_info->red.length == 5 && vscr_info->blue.length == 5 && 
00426                 vscr_info->green.length == 6 && vscr_info->green.offset == 5 && 
00427                 vscr_info->red.offset == 11 && vscr_info->blue.offset == 0) {
00428       omx_pxlfmt = OMX_COLOR_Format16bitRGB565;
00429     } else if ( vscr_info->red.length == 5 && vscr_info->blue.length == 5 && 
00430                 vscr_info->green.length == 6 && vscr_info->green.offset == 5 &&
00431                 vscr_info->red.offset == 0 && vscr_info->blue.offset == 11) {
00432       omx_pxlfmt = OMX_COLOR_Format16bitBGR565;
00433     } else if ( vscr_info->red.length == 6 && vscr_info->green.length == 6 &&
00434                 vscr_info->transp.length == 0 && vscr_info->red.offset == 12 && vscr_info->green.offset == 6 &&
00435                 vscr_info->blue.length == 6 && vscr_info->blue.offset == 0) {
00436       omx_pxlfmt = OMX_COLOR_Format18bitRGB666;
00437     } else if ( vscr_info->red.length == 6 && vscr_info->green.length == 6 && 
00438                 vscr_info->transp.length == 1 && vscr_info->transp.offset == 17 &&
00439                 vscr_info->red.offset == 11 && vscr_info->green.offset == 5 &&
00440                 vscr_info->blue.length == 5 && vscr_info->blue.offset == 0) {
00441       omx_pxlfmt = OMX_COLOR_Format18bitARGB1665;
00442     } else if ( vscr_info->transp.length == 1 && vscr_info->transp.offset == 18 &&
00443                 vscr_info->red.length == 6 && vscr_info->red.offset ==  12 &&
00444                 vscr_info->green.length == 6 && vscr_info->green.offset == 6 &&
00445                 vscr_info->blue.length == 6 && vscr_info->blue.offset == 0) {
00446       omx_pxlfmt = OMX_COLOR_Format19bitARGB1666;
00447     } else if ( vscr_info->transp.length == 0 && vscr_info->red.length == 8 &&
00448                 vscr_info->green.length == 8 && vscr_info->blue.length == 8 &&
00449                 vscr_info->green.offset == 8 && vscr_info->red.offset == 16 && vscr_info->blue.offset == 0) {
00450       omx_pxlfmt = OMX_COLOR_Format24bitRGB888;
00451     } else if ( vscr_info->transp.length == 0 && vscr_info->red.length == 8 &&
00452                 vscr_info->green.length == 8 && vscr_info->blue.length == 8 &&
00453                 vscr_info->green.offset == 8 && vscr_info->red.offset == 0 && vscr_info->blue.offset == 16) {
00454       omx_pxlfmt = OMX_COLOR_Format24bitBGR888;
00455     } else if ( vscr_info->transp.length == 1 && vscr_info->transp.offset == 23 &&
00456                 vscr_info->red.length == 8 && vscr_info->red.offset == 15 &&
00457                 vscr_info->green.length == 8 && vscr_info->green.offset == 7 &&
00458                 vscr_info->blue.length == 7 && vscr_info->blue.offset == 0) {
00459       omx_pxlfmt = OMX_COLOR_Format24bitARGB1887;
00460     } else if ( vscr_info->transp.length == 1 && vscr_info->transp.offset == 24 &&
00461                 vscr_info->red.length == 8 && vscr_info->red.offset == 16 &&
00462                 vscr_info->green.length == 8 && vscr_info->green.offset == 8 &&
00463                 vscr_info->blue.length == 8 && vscr_info->blue.offset == 0) {
00464       omx_pxlfmt = OMX_COLOR_Format25bitARGB1888;
00465     } else if ( vscr_info->transp.length == 8 && vscr_info->red.length == 8 &&
00466                 vscr_info->green.length == 8 && vscr_info->blue.length == 8 &&
00467                 vscr_info->transp.offset == 24 && vscr_info->red.offset == 16 &&
00468                 vscr_info->green.offset == 8 && vscr_info->blue.offset == 0) {
00469       omx_pxlfmt = OMX_COLOR_Format32bitARGB8888;
00470     } else if ( vscr_info->transp.length == 8 && vscr_info->red.length == 8 &&
00471                 vscr_info->green.length == 8 && vscr_info->blue.length == 8 && 
00472                 vscr_info->transp.offset == 0 && vscr_info->red.offset == 8 &&
00473                 vscr_info->green.offset == 16 && vscr_info->blue.offset == 24) {
00474       omx_pxlfmt = OMX_COLOR_Format32bitBGRA8888;
00475     } else if ( vscr_info->transp.length == 8 && vscr_info->red.length == 8 &&
00476                 vscr_info->green.length == 8 && vscr_info->blue.length == 8 && 
00477                 vscr_info->transp.offset == 0 && vscr_info->red.offset == 0 &&
00478                 vscr_info->green.offset == 0 && vscr_info->blue.offset == 0) {
00479       omx_pxlfmt = OMX_COLOR_Format8bitRGB332;
00480     } else {
00481       omx_pxlfmt = OMX_COLOR_FormatUnused;
00482     }
00483   }
00484   return omx_pxlfmt;
00485 }
00486 
00487 
00501 void omx_img_copy(OMX_U8* src_ptr, OMX_S32 src_stride, OMX_U32 src_width, OMX_U32 src_height, 
00502                   OMX_S32 src_offset_x, OMX_S32 src_offset_y,
00503                   OMX_U8* dest_ptr, OMX_S32 dest_stride, OMX_U32 dest_width,  OMX_U32 dest_height, 
00504                   OMX_S32 dest_offset_x, OMX_S32 dest_offset_y, 
00505                   OMX_S32 cpy_width, OMX_U32 cpy_height, OMX_COLOR_FORMATTYPE colorformat,OMX_COLOR_FORMATTYPE fbpxlfmt) {  
00506 
00507   OMX_U32 i,j;
00508   OMX_U32 cp_byte; //equal to source image byte per pixel value
00509   OMX_U8 r,g,b,a;
00510   OMX_U8* org_src_cpy_ptr;
00511   OMX_U8* org_dst_cpy_ptr;
00516   if (colorformat == OMX_COLOR_FormatYUV411Planar ||    
00517       colorformat == OMX_COLOR_FormatYUV411PackedPlanar || 
00518       colorformat == OMX_COLOR_FormatYUV420Planar ||
00519       colorformat == OMX_COLOR_FormatYUV420PackedPlanar ||
00520       colorformat == OMX_COLOR_FormatYUV422Planar ||
00521       colorformat == OMX_COLOR_FormatYUV422PackedPlanar ) {
00522 
00523     OMX_U32 src_luma_width;      //  Width (in columns) of the source Y plane
00524     OMX_U32 src_luma_height;     //  Height (in rows) of source Y plane
00525     OMX_S32 src_luma_stride;     //  Stride in bytes of each source Y row
00526     OMX_U32 src_luma_offset_x;   //  Horizontal byte offset
00527     OMX_U32 src_luma_offset_y;   //  Vertical offset in rows from top of plane
00528     OMX_U32 src_luma_offset;     //  Total byte offset to rectangle
00529 
00530     OMX_U32 src_chroma_width;    //  Width (in columns) of source chroma planes
00531     OMX_U32 src_chroma_height;   //  Height (in rows) of source chroma planes
00532     OMX_S32 src_chroma_stride;   //  Stride in bytes of each source chroma row
00533     OMX_U32 src_chroma_offset_x; //  Horizontal byte offset
00534     OMX_U32 src_chroma_offset_y; //  Vertical offset in rows from top of plane
00535     OMX_U32 src_chroma_offset;   //  Bytes to crop rectangle from start of chroma plane
00536 
00537     OMX_U32 dest_luma_width;     //  Width (in columns) of the destination Y plane
00538     OMX_U32 dest_luma_height;    //  Height (in rows) of destination Y plane
00539     OMX_S32 dest_luma_stride;    //  Stride in bytes of each destination Y row
00540     OMX_U32 dest_luma_offset_x;  //  Horizontal byte offset
00541     OMX_U32 dest_luma_offset_y;  //  Vertical offset in rows from top of plane
00542     OMX_U32 dest_luma_offset;    //  Bytes to crop rectangle from start of Y plane
00543 
00544     OMX_U32 dest_chroma_width;   //  Width (in columns) of destination chroma planes
00545     OMX_U32 dest_chroma_height;  //  Height (in rows) of destination chroma planes
00546     OMX_S32 dest_chroma_stride;  //  Stride in bytes of each destination chroma row
00547     OMX_U32 dest_chroma_offset_x;//  Horizontal byte offset
00548     OMX_U32 dest_chroma_offset_y;//  Vertical offset in rows from top of plane
00549     OMX_U32 dest_chroma_offset;  //  Bytes to crop rectangle from start of chroma plane
00550 
00551     OMX_U32 luma_crop_width;     //  Width in bytes of a luma row in the crop rectangle
00552     OMX_U32 luma_crop_height;    //  Number of luma rows in the crop rectangle
00553     OMX_U32 chroma_crop_width;   //  Width in bytes of a chroma row in the crop rectangle
00554     OMX_U32 chroma_crop_height;  //  Number of chroma rows in crop rectangle
00555 
00556     switch (colorformat) {
00559       case OMX_COLOR_FormatYUV411Planar:    
00560       case OMX_COLOR_FormatYUV411PackedPlanar:
00565         src_luma_width = src_width;
00566         src_luma_height = src_height;
00567         src_luma_stride = (OMX_S32) src_luma_width;
00568         src_luma_offset_x = src_offset_x;
00569         src_luma_offset_y = src_offset_y;
00570 
00571         src_chroma_width = src_luma_width  >> 2; 
00572         src_chroma_height = src_luma_height;
00573         src_chroma_stride = (OMX_S32) src_chroma_width;
00574         src_chroma_offset_x = src_luma_offset_x  >> 2; 
00575         src_chroma_offset_y = src_luma_offset_y;
00576 
00577         dest_luma_width = dest_width;
00578         dest_luma_height = dest_height;
00579         dest_luma_stride = (OMX_S32) dest_luma_width;
00580         dest_luma_offset_x = dest_offset_x;
00581         dest_luma_offset_y = dest_offset_y;
00582 
00583         dest_chroma_width = dest_luma_width  >> 2;
00584         dest_chroma_height = dest_luma_height;
00585         dest_chroma_stride = (OMX_S32) dest_chroma_width;
00586         dest_chroma_offset_x = dest_luma_offset_x  >> 2; 
00587         dest_chroma_offset_y = dest_luma_offset_y;
00588 
00589         luma_crop_width = (OMX_U32) abs(cpy_width);
00590         luma_crop_height = cpy_height;
00591         chroma_crop_width = luma_crop_width  >> 2; 
00592         chroma_crop_height = luma_crop_height;
00593         break;  
00594 
00596       case OMX_COLOR_FormatYUV420Planar:    
00597       case OMX_COLOR_FormatYUV420PackedPlanar:
00598         src_luma_width = src_width;
00599         src_luma_height = src_height;
00600         src_luma_stride = (OMX_S32) src_luma_width;
00601         src_luma_offset_x = src_offset_x;
00602         src_luma_offset_y = src_offset_y;
00603 
00604         src_chroma_width = src_luma_width >> 1;
00605         src_chroma_height = src_luma_height >> 1;
00606         src_chroma_stride = (OMX_S32) src_chroma_width;
00607         src_chroma_offset_x = src_luma_offset_x >> 1;
00608         src_chroma_offset_y = src_luma_offset_y >> 1;
00609 
00610         dest_luma_width = dest_width;
00611         dest_luma_height = dest_height;
00612         dest_luma_stride = (OMX_S32) dest_luma_width;
00613         dest_luma_offset_x = dest_offset_x;
00614         dest_luma_offset_y = dest_offset_y;
00615 
00616         dest_chroma_width = dest_luma_width >> 1;
00617         dest_chroma_height = dest_luma_height >> 1;
00618         dest_chroma_stride = (OMX_S32) dest_chroma_width;
00619         dest_chroma_offset_x = dest_luma_offset_x >> 1;
00620         dest_chroma_offset_y = dest_luma_offset_y >> 1;
00621 
00622         luma_crop_width = cpy_width;
00623         luma_crop_height = cpy_height;
00624         chroma_crop_width = luma_crop_width >> 1;
00625         chroma_crop_height = luma_crop_height >> 1;
00626         break;
00628       case OMX_COLOR_FormatYUV422Planar:    
00629       case OMX_COLOR_FormatYUV422PackedPlanar:
00630         src_luma_width = src_width;
00631         src_luma_height = src_height;
00632         src_luma_stride = (OMX_S32) src_luma_width;
00633         src_luma_offset_x = src_offset_x;
00634         src_luma_offset_y = src_offset_y;
00635 
00636         src_chroma_width = src_luma_width >> 1;
00637         src_chroma_height = src_luma_height;
00638         src_chroma_stride = (OMX_S32) src_chroma_width;
00639         src_chroma_offset_x = src_luma_offset_x >> 1;
00640         src_chroma_offset_y = src_luma_offset_y;
00641 
00642         dest_luma_width = dest_width;
00643         dest_luma_height = dest_height;
00644         dest_luma_stride = (OMX_S32) dest_luma_width;
00645         dest_luma_offset_x = dest_offset_x;
00646         dest_luma_offset_y = dest_offset_y;
00647 
00648         dest_chroma_width = dest_luma_width >> 1;
00649         dest_chroma_height = dest_luma_height;
00650         dest_chroma_stride = (OMX_S32) dest_chroma_width;
00651         dest_chroma_offset_x = dest_luma_offset_x >> 1;
00652         dest_chroma_offset_y = dest_luma_offset_y;
00653 
00654         luma_crop_width = (OMX_U32) abs(cpy_width);
00655         luma_crop_height = cpy_height;
00656         chroma_crop_width = luma_crop_width >> 1;
00657         chroma_crop_height = luma_crop_height;
00658         break;
00659       default:
00660         DEBUG(DEB_LEV_ERR,"\n color format not supported --error \n");
00661         return;
00662     }
00663 
00665     OMX_U8* Y_input_ptr = src_ptr;
00666     OMX_U8* U_input_ptr = Y_input_ptr + ((OMX_U32) abs(src_luma_stride) * src_luma_height);
00667     OMX_U8* V_input_ptr = U_input_ptr + ((OMX_U32) abs(src_chroma_stride) * src_chroma_height);
00668 
00670     src_luma_offset = (src_luma_offset_y * (OMX_U32) abs(src_luma_stride)) + src_luma_offset_x;
00671     src_chroma_offset = (src_chroma_offset_y * (OMX_U32) abs(src_chroma_stride)) + src_chroma_offset_x;
00672 
00674     if (src_stride < 0) {
00675       src_luma_offset += ((OMX_U32) abs(src_luma_stride)) * (src_luma_height - 1);
00676       src_chroma_offset += ((OMX_U32) abs(src_chroma_stride)) * (src_chroma_height - 1);
00677 
00678       if (src_luma_stride > 0) {
00679         src_luma_stride *= -1;
00680       }
00681 
00682       if (src_chroma_stride > 0) {
00683         src_chroma_stride *= -1;  
00684       }
00685     }
00686 
00688     OMX_U8* src_Y_ptr = Y_input_ptr + src_luma_offset;    
00689     OMX_U8* src_U_ptr = U_input_ptr + src_chroma_offset;
00690     OMX_U8*  src_V_ptr = V_input_ptr + src_chroma_offset;
00691 
00693     OMX_U8* Y_output_ptr = dest_ptr;
00694     OMX_U8* U_output_ptr = Y_output_ptr + ((OMX_U32) abs(dest_luma_stride) * dest_luma_height);
00695     OMX_U8* V_output_ptr = U_output_ptr + ((OMX_U32) abs(dest_chroma_stride) * dest_chroma_height);  
00696 
00698     dest_luma_offset = (dest_luma_offset_y * (OMX_U32) abs(dest_luma_stride)) + dest_luma_offset_x;
00699     dest_chroma_offset = (dest_chroma_offset_y * (OMX_U32) abs(dest_chroma_stride)) + dest_chroma_offset_x;
00700 
00702     if (dest_stride < 0) {
00703       dest_luma_offset += ((OMX_U32) abs(dest_luma_stride)) * (dest_luma_height - 1);
00704       dest_chroma_offset += ((OMX_U32) abs(dest_chroma_stride)) * (dest_chroma_height - 1);
00705       if (dest_luma_stride > 0) {
00706         dest_luma_stride *= -1;
00707       }
00708       if (dest_chroma_stride > 0) {
00709         dest_chroma_stride *= -1;  
00710       }
00711     }
00712 
00714     OMX_U8* dest_Y_ptr = Y_output_ptr + dest_luma_offset;    
00715     OMX_U8* dest_U_ptr = U_output_ptr + dest_chroma_offset;
00716     OMX_U8*  dest_V_ptr = V_output_ptr + dest_chroma_offset;
00717 
00718     //  Y
00719     for (i = 0; i < luma_crop_height; ++i, src_Y_ptr += src_luma_stride, dest_Y_ptr += dest_luma_stride) {
00720       memcpy(dest_Y_ptr, src_Y_ptr, luma_crop_width);    //  Copy Y rows into in_buffer
00721     }
00722     //  U
00723     for (i = 0; i < chroma_crop_height; ++i, src_U_ptr += src_chroma_stride, dest_U_ptr += dest_chroma_stride) {
00724       memcpy(dest_U_ptr, src_U_ptr, chroma_crop_width);  //  Copy U rows into in_buffer
00725     }
00726     //  V
00727     for (i = 0; i < chroma_crop_height; ++i, src_V_ptr += src_chroma_stride, dest_V_ptr += dest_chroma_stride) {
00728       memcpy(dest_V_ptr, src_V_ptr, chroma_crop_width);  //  Copy V rows into in_buffer
00729     }
00730   } else {  
00731 
00732     OMX_U32 cpy_byte_width = calcStride((OMX_U32) abs(cpy_width), colorformat);  //  Bytes width to copy
00733     OMX_U32 src_byte_offset_x = calcStride((OMX_U32) abs(src_offset_x), colorformat);
00734     OMX_U32 dest_byte_offset_x = calcStride((OMX_U32) abs(dest_offset_x), colorformat);
00735     OMX_U32 src_byte_offset_y = src_offset_y * (OMX_U32) abs(src_stride);
00736     OMX_U32 dest_byte_offset_y = dest_offset_y * (OMX_U32) abs(dest_stride);
00737 
00738     if (src_stride < 0)  {
00739       //  If input stride is negative, start from bottom
00740       src_byte_offset_y += cpy_height * (OMX_U32) abs(src_stride);
00741     }  
00742     if (dest_stride < 0) {
00743       //  If output stride is negative, start from bottom
00744       dest_byte_offset_y += cpy_height * (OMX_U32) abs(dest_stride);
00745     }
00746 
00747     OMX_U8* src_cpy_ptr = src_ptr + src_byte_offset_y + src_byte_offset_x;
00748     OMX_U8* dest_cpy_ptr = dest_ptr + dest_byte_offset_y + dest_byte_offset_x;
00749 
00756     DEBUG(DEB_LEV_SIMPLE_SEQ, "height=%d,width=%d,dest_stride=%d\n",(int)cpy_height,(int)cpy_byte_width,(int)dest_stride);
00757 
00758     if(fbpxlfmt == OMX_COLOR_Format8bitRGB332 && colorformat == OMX_COLOR_Format24bitRGB888) {
00759       cp_byte = 3;
00760       for (i = 0; i < cpy_height; ++i) { 
00761         // copy rows
00762         org_src_cpy_ptr = src_cpy_ptr; 
00763         org_dst_cpy_ptr = dest_cpy_ptr;
00764         for(j = 0; j < cpy_byte_width; j += cp_byte) {
00765           //extract source rgba components
00766           r = *(src_cpy_ptr + 0);
00767           g = *(src_cpy_ptr + 1);
00768           b = *(src_cpy_ptr + 2);
00769 
00770           *(dest_cpy_ptr + 0) = b; 
00771           *(dest_cpy_ptr + 1) = g; 
00772           *(dest_cpy_ptr + 2) = r;
00773           //last byte - all 1
00774           *(dest_cpy_ptr + 3) = 0xff;
00775           src_cpy_ptr += cp_byte;     
00776           dest_cpy_ptr += 4;     
00777 
00778           
00779         }
00780         dest_cpy_ptr = org_dst_cpy_ptr + dest_stride;
00781         src_cpy_ptr =  org_src_cpy_ptr + src_stride;
00782       }
00783     } else if(fbpxlfmt == OMX_COLOR_Format16bitRGB565 && colorformat == OMX_COLOR_Format24bitRGB888) {
00784       cp_byte = 3;
00785       for (i = 0; i < cpy_height; ++i) { 
00786         // copy rows
00787         org_src_cpy_ptr = src_cpy_ptr; 
00788         org_dst_cpy_ptr = dest_cpy_ptr;
00789         for(j = 0; j < cpy_byte_width; j += cp_byte) {
00790           //extract source rgba components
00791           r = *(src_cpy_ptr + 0);
00792           g = *(src_cpy_ptr + 1);
00793           b = *(src_cpy_ptr + 2);
00794 
00795           *(dest_cpy_ptr + 0) = b; 
00796           *(dest_cpy_ptr + 1) = g; 
00797           *(dest_cpy_ptr + 2) = r;
00798           //last byte - all 1
00799           *(dest_cpy_ptr + 3) = 0xff;
00800           src_cpy_ptr += cp_byte;     
00801           dest_cpy_ptr += 4;     
00802 
00803           
00804         }
00805         dest_cpy_ptr = org_dst_cpy_ptr + dest_stride;
00806         src_cpy_ptr =  org_src_cpy_ptr + src_stride;
00807       }
00808     } else if(fbpxlfmt == OMX_COLOR_Format24bitRGB888 && colorformat == OMX_COLOR_Format24bitRGB888) {
00809       cp_byte = 3;
00810       for (i = 0; i < cpy_height; ++i) { 
00811         // copy rows
00812         org_src_cpy_ptr = src_cpy_ptr; 
00813         org_dst_cpy_ptr = dest_cpy_ptr;
00814         for(j = 0; j < cpy_byte_width; j += cp_byte) {
00815           //extract source rgba components
00816           r = *(src_cpy_ptr + 0);
00817           g = *(src_cpy_ptr + 1);
00818           b = *(src_cpy_ptr + 2);
00819           //assign to detination 
00820           *(dest_cpy_ptr + 0) = b; 
00821           *(dest_cpy_ptr + 1) = g; 
00822           *(dest_cpy_ptr + 2) = r;
00823           //last byte - all 1
00824           *(dest_cpy_ptr + 3) = 0xff;
00825           src_cpy_ptr += cp_byte;     
00826           dest_cpy_ptr += 4;     
00827         }
00828         dest_cpy_ptr = org_dst_cpy_ptr + dest_stride;
00829         src_cpy_ptr =  org_src_cpy_ptr + src_stride;
00830       }
00831     }else if(fbpxlfmt == OMX_COLOR_Format32bitARGB8888 && colorformat == OMX_COLOR_Format24bitRGB888) {
00832       cp_byte = 3;
00833       for (i = 0; i < cpy_height; ++i) { 
00834         // copy rows
00835         org_src_cpy_ptr = src_cpy_ptr; 
00836         org_dst_cpy_ptr = dest_cpy_ptr;
00837         for(j = 0; j < cpy_byte_width; j += cp_byte) {
00838           //extract source rgba components
00839           r = *(src_cpy_ptr + 0);
00840           g = *(src_cpy_ptr + 1);
00841           b = *(src_cpy_ptr + 2);
00842           //assign to detination 
00843           *(dest_cpy_ptr + 0) = b; 
00844           *(dest_cpy_ptr + 1) = g; 
00845           *(dest_cpy_ptr + 2) = r;
00846           //last byte - all 1
00847           *(dest_cpy_ptr + 3) = 0xff;
00848           src_cpy_ptr += cp_byte;     
00849           dest_cpy_ptr += 4;     
00850         }
00851         dest_cpy_ptr = org_dst_cpy_ptr + dest_stride;
00852         src_cpy_ptr =  org_src_cpy_ptr + src_stride;
00853       }
00854     } else if(fbpxlfmt == OMX_COLOR_Format32bitARGB8888 && colorformat == OMX_COLOR_Format24bitBGR888) {
00855       cp_byte = 3;
00856       for (i = 0; i < cpy_height; ++i) { 
00857         // copy rows
00858         org_src_cpy_ptr = src_cpy_ptr; 
00859         org_dst_cpy_ptr = dest_cpy_ptr;
00860         for(j = 0; j < cpy_byte_width; j += cp_byte) {
00861           //extract source rgba components
00862           b = *(src_cpy_ptr + 0);
00863           g = *(src_cpy_ptr + 1);
00864           r = *(src_cpy_ptr + 2);
00865           //assign to detination 
00866           *(dest_cpy_ptr + 0) = b; 
00867           *(dest_cpy_ptr + 1) = g; 
00868           *(dest_cpy_ptr + 2) = r; 
00869           //last byte - all 1
00870           *(dest_cpy_ptr + 3) = 0xff;
00871           src_cpy_ptr += cp_byte;     
00872           dest_cpy_ptr += 4;     
00873         }
00874         dest_cpy_ptr = org_dst_cpy_ptr + dest_stride;
00875         src_cpy_ptr =  org_src_cpy_ptr + src_stride;
00876       }
00877     } else if(fbpxlfmt == OMX_COLOR_Format32bitARGB8888 && (colorformat == OMX_COLOR_Format32bitBGRA8888 || colorformat == OMX_COLOR_Format32bitARGB8888)) {
00878       for (i = 0; i < cpy_height; ++i, src_cpy_ptr += src_stride, dest_cpy_ptr += dest_stride ) { 
00879         // same color format - so no extraction - only simple memcpy
00880         memcpy(dest_cpy_ptr, src_cpy_ptr, cpy_byte_width);  //  Copy rows
00881       }
00882     } else if(fbpxlfmt == OMX_COLOR_Format32bitARGB8888 && colorformat == OMX_COLOR_Format16bitARGB1555) { 
00883       cp_byte = 2;
00884       for (i = 0; i < cpy_height; ++i) { 
00885         // copy rows
00886         org_src_cpy_ptr = src_cpy_ptr; 
00887         org_dst_cpy_ptr = dest_cpy_ptr;
00888         for(j = 0; j < cpy_byte_width; j += cp_byte) {
00889           // individual argb components are less than 1 byte 
00890           OMX_U16 temp_old, temp, *temp1;
00891           temp1=(OMX_U16*)src_cpy_ptr;
00892           temp = *temp1;
00893           temp_old = temp;
00894           a = (OMX_U8) ((temp >> 15) && 0x0001); //getting the 1 bit of a and setting all other bits to 0
00895           temp = temp_old;
00896           r = (OMX_U8) ((temp >> 10) & 0x001f); //getting 5 bits of r and setting all other bits to 0
00897           temp = temp_old;
00898           g = (OMX_U8) ((temp >> 5) & 0x001f); //getting 5 bits of g and setting all other bits to 0
00899           temp = temp_old;
00900           b = (OMX_U8) (temp & 0x001f); //getting 5 bits of b and setting all other bits to 0
00901           temp = temp_old;
00902           // assign them in perfect order
00903           *(dest_cpy_ptr + 0) = b<<3; 
00904           *(dest_cpy_ptr + 1) = g<<3; 
00905           *(dest_cpy_ptr + 2) = r<<3; 
00906           *(dest_cpy_ptr + 3) = a<<7; 
00907           src_cpy_ptr += cp_byte;     
00908           dest_cpy_ptr += 4;     
00909         }
00910         dest_cpy_ptr = org_dst_cpy_ptr + dest_stride;
00911         src_cpy_ptr =  org_src_cpy_ptr + src_stride;
00912       }
00913     } else if(fbpxlfmt == OMX_COLOR_Format32bitARGB8888 && (colorformat == OMX_COLOR_Format16bitRGB565 || OMX_COLOR_Format16bitBGR565)) {
00914       cp_byte = 2;
00915       for (i = 0; i < cpy_height; ++i) { 
00916         // copy rows
00917         org_src_cpy_ptr = src_cpy_ptr; 
00918         org_dst_cpy_ptr = dest_cpy_ptr;
00919         for(j = 0; j < cpy_byte_width; j += cp_byte) {
00920           // individual rgb components are less than 1 byte 
00921           OMX_U16 temp_old, temp,*temp1;
00922           temp1=(OMX_U16*)src_cpy_ptr;
00923           temp = *temp1;
00924           temp_old = temp;
00925           r = (OMX_U8) ((temp >> 11) & 0x001f); //getting 5 bits of r and setting all other bits to 0
00926           temp = temp_old;
00927           g = (OMX_U8) ((temp >> 5) & 0x003f); //getting 6 bits of g and setting all other bits to 0
00928           temp = temp_old;
00929           b = (OMX_U8) (temp & 0x001f); //getting 5 bits of b and setting all other bits to 0
00930           temp = temp_old;
00931           // assign them in perfect order
00932           *(dest_cpy_ptr + 0) = b<<3; 
00933           *(dest_cpy_ptr + 1) = g<<2; 
00934           *(dest_cpy_ptr + 2) = r<<3; 
00935           // last byte  - all 1
00936           *(dest_cpy_ptr + 3) = 0xff; 
00937           src_cpy_ptr += cp_byte;     
00938           dest_cpy_ptr += 4;     
00939         }
00940         dest_cpy_ptr = org_dst_cpy_ptr + dest_stride;
00941         src_cpy_ptr =  org_src_cpy_ptr + src_stride;
00942       }
00943     } else {
00944       DEBUG(DEB_LEV_ERR, "the frame buffer pixel format %d and colorformat %d NOT supported\n",fbpxlfmt,colorformat);
00945       DEBUG(DEB_LEV_ERR, "or the input rgb format is not supported\n");
00946     }
00947   }
00948 }
00949 
00950 
00951 
00955 void omx_fbdev_sink_component_BufferMgmtCallback(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE* pInputBuffer) {
00956   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
00957   omx_fbdev_sink_component_PortType *pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
00958   static long old_time = 0, new_time = 0;
00959   long timediff=0;
00960 
00961   OMX_COLOR_FORMATTYPE input_colorformat = pPort->sVideoParam.eColorFormat;
00962   OMX_S32 input_cpy_width = (OMX_S32) pPort->omxConfigCrop.nWidth;      //  Width (in columns) of the crop rectangle
00963   OMX_U32 input_cpy_height = pPort->omxConfigCrop.nHeight;          //  Height (in rows) of the crop rectangle
00964 
00965   OMX_U8* input_src_ptr = (OMX_U8*) (pInputBuffer->pBuffer);
00966   OMX_S32 input_src_stride = pPort->sPortParam.format.video.nStride;      //  Negative means bottom-to-top (think Windows bmp)
00967   OMX_U32 input_src_width = pPort->sPortParam.format.video.nFrameWidth;
00968   OMX_U32 input_src_height = pPort->sPortParam.format.video.nSliceHeight;
00969 
00974   OMX_S32 input_src_offset_x = pPort->omxConfigCrop.nLeft;    //  Offset (in columns) to left side of crop rectangle
00975   OMX_S32 input_src_offset_y = pPort->omxConfigCrop.nTop;    //  Offset (in rows) from top of the image to crop rectangle
00976 
00977   OMX_U8* input_dest_ptr = (OMX_U8*) omx_fbdev_sink_component_Private->scr_ptr + (omx_fbdev_sink_component_Private->fbstride * HEIGHT_OFFSET); 
00978   //OMX_U8* input_dest_ptr = (OMX_U8*) omx_fbdev_sink_component_Private->scr_ptr; 
00979   OMX_S32 input_dest_stride = (input_src_stride < 0) ? -1 * omx_fbdev_sink_component_Private->fbstride : omx_fbdev_sink_component_Private->fbstride;
00980 
00981   if (pPort->omxConfigMirror.eMirror == OMX_MirrorVertical || pPort->omxConfigMirror.eMirror == OMX_MirrorBoth) {
00982     input_dest_stride *= -1;
00983   }
00984 
00985   OMX_U32 input_dest_width = omx_fbdev_sink_component_Private->fbwidth;
00986   OMX_U32 input_dest_height = omx_fbdev_sink_component_Private->fbheight;
00987 
00988   OMX_U32 input_dest_offset_x = pPort->omxConfigOutputPosition.nX;
00989   OMX_U32 input_dest_offset_y = pPort->omxConfigOutputPosition.nY;
00990 
00992   new_time = GetTime();
00993   if(old_time == 0) {
00994     old_time = new_time;
00995   } else {
00996     timediff = nFrameProcessTime - ((new_time - old_time) * 1000);
00997     if(timediff>0) {
00998       usleep(timediff);
00999     }
01000     old_time = GetTime();
01001   }
01002 
01004   omx_img_copy(  input_src_ptr, input_src_stride, input_src_width, input_src_height, 
01005                 input_src_offset_x, input_src_offset_y,
01006                 input_dest_ptr, input_dest_stride, input_dest_width, input_dest_height, 
01007                 input_dest_offset_x, input_dest_offset_y,
01008                 input_cpy_width, input_cpy_height, input_colorformat,omx_fbdev_sink_component_Private->fbpxlfmt);
01009 
01010   pInputBuffer->nFilledLen = 0;
01011 }
01012 
01013 
01014 OMX_ERRORTYPE omx_fbdev_sink_component_SetConfig(
01015   OMX_IN  OMX_HANDLETYPE hComponent,
01016   OMX_IN  OMX_INDEXTYPE nIndex,
01017   OMX_IN  OMX_PTR pComponentConfigStructure) {
01018 
01019   OMX_ERRORTYPE err = OMX_ErrorNone;
01020   OMX_U32 portIndex;
01021   OMX_CONFIG_RECTTYPE *omxConfigCrop;
01022   OMX_CONFIG_ROTATIONTYPE *omxConfigRotate;
01023   OMX_CONFIG_MIRRORTYPE *omxConfigMirror;
01024   OMX_CONFIG_SCALEFACTORTYPE *omxConfigScale;
01025   OMX_CONFIG_POINTTYPE *omxConfigOutputPosition;
01026 
01027   /* Check which structure we are being fed and make control its header */
01028   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
01029   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
01030   omx_fbdev_sink_component_PortType *pPort;
01031   if (pComponentConfigStructure == NULL) {
01032     return OMX_ErrorBadParameter;
01033   }
01034 
01035   DEBUG(DEB_LEV_SIMPLE_SEQ, "   Setting parameter %i\n", nIndex);
01036 
01037   switch (nIndex) {
01038     case OMX_IndexConfigCommonInputCrop:
01039       omxConfigCrop = (OMX_CONFIG_RECTTYPE*)pComponentConfigStructure;
01040       portIndex = omxConfigCrop->nPortIndex;
01041       if ((err = checkHeader(pComponentConfigStructure, sizeof(OMX_CONFIG_RECTTYPE))) != OMX_ErrorNone) { 
01042         break;
01043       }
01044       if (portIndex == OMX_BASE_SINK_INPUTPORT_INDEX) {
01045         pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[portIndex];
01046         pPort->omxConfigCrop.nLeft = omxConfigCrop->nLeft;
01047         pPort->omxConfigCrop.nTop = omxConfigCrop->nTop;
01048         pPort->omxConfigCrop.nWidth = omxConfigCrop->nWidth;
01049         pPort->omxConfigCrop.nHeight = omxConfigCrop->nHeight;
01050       } else {
01051         return OMX_ErrorBadPortIndex;
01052       }
01053       break;
01054     case OMX_IndexConfigCommonRotate:
01055       omxConfigRotate = (OMX_CONFIG_ROTATIONTYPE*)pComponentConfigStructure;
01056       portIndex = omxConfigRotate->nPortIndex;
01057       if ((err = checkHeader(pComponentConfigStructure, sizeof(OMX_CONFIG_ROTATIONTYPE))) != OMX_ErrorNone) { 
01058         break;
01059       }
01060       if (portIndex == 0) {
01061         pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[portIndex];
01062         if (omxConfigRotate->nRotation != 0) {
01063           //  Rotation not supported (yet)
01064           return OMX_ErrorUnsupportedSetting;
01065         }
01066         pPort->omxConfigRotate.nRotation = omxConfigRotate->nRotation;
01067       } else {
01068         return OMX_ErrorBadPortIndex;
01069       }
01070       break;
01071     case OMX_IndexConfigCommonMirror:
01072       omxConfigMirror = (OMX_CONFIG_MIRRORTYPE*)pComponentConfigStructure;
01073       portIndex = omxConfigMirror->nPortIndex;
01074       if ((err = checkHeader(pComponentConfigStructure, sizeof(OMX_CONFIG_MIRRORTYPE))) != OMX_ErrorNone) { 
01075         break;
01076       }
01077       if (portIndex == 0) {
01078         if (omxConfigMirror->eMirror == OMX_MirrorBoth || omxConfigMirror->eMirror == OMX_MirrorHorizontal)  {
01079           //  Horizontal mirroring not yet supported
01080           return OMX_ErrorUnsupportedSetting;
01081         }
01082         pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[portIndex];
01083         pPort->omxConfigMirror.eMirror = omxConfigMirror->eMirror;
01084       } else {
01085         return OMX_ErrorBadPortIndex;
01086       }
01087       break;
01088     case OMX_IndexConfigCommonScale:
01089       omxConfigScale = (OMX_CONFIG_SCALEFACTORTYPE*)pComponentConfigStructure;
01090       portIndex = omxConfigScale->nPortIndex;
01091       if ((err = checkHeader(pComponentConfigStructure, sizeof(OMX_CONFIG_SCALEFACTORTYPE))) != OMX_ErrorNone) { 
01092         break;
01093       }
01094       if (portIndex == 0) {
01095         if (omxConfigScale->xWidth != 0x10000 || omxConfigScale->xHeight != 0x10000)  {
01096           //  Scaling not yet supported
01097           return OMX_ErrorUnsupportedSetting;
01098         }
01099         pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[portIndex];
01100         pPort->omxConfigScale.xWidth = omxConfigScale->xWidth;
01101         pPort->omxConfigScale.xHeight = omxConfigScale->xHeight;
01102       } else {
01103         return OMX_ErrorBadPortIndex;
01104       }
01105       break;
01106     case OMX_IndexConfigCommonOutputPosition:
01107       omxConfigOutputPosition = (OMX_CONFIG_POINTTYPE*)pComponentConfigStructure;
01108       portIndex = omxConfigOutputPosition->nPortIndex;
01109       if ((err = checkHeader(pComponentConfigStructure, sizeof(OMX_CONFIG_POINTTYPE))) != OMX_ErrorNone) { 
01110         break;
01111       }
01112       if (portIndex == 0) {
01113         pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[portIndex];
01114         pPort->omxConfigOutputPosition.nX = omxConfigOutputPosition->nX;
01115         pPort->omxConfigOutputPosition.nY = omxConfigOutputPosition->nY;
01116       } else {
01117         return OMX_ErrorBadPortIndex;
01118       }
01119       break;
01120     default: // delegate to superclass
01121       return omx_base_component_SetConfig(hComponent, nIndex, pComponentConfigStructure);
01122   }
01123   return err;
01124 }
01125 
01126 
01127 
01128 OMX_ERRORTYPE omx_fbdev_sink_component_GetConfig(
01129   OMX_IN  OMX_HANDLETYPE hComponent,
01130   OMX_IN  OMX_INDEXTYPE nIndex,
01131   OMX_INOUT OMX_PTR pComponentConfigStructure) {
01132 
01133   OMX_CONFIG_RECTTYPE *omxConfigCrop;
01134   OMX_CONFIG_ROTATIONTYPE *omxConfigRotate;
01135   OMX_CONFIG_MIRRORTYPE *omxConfigMirror;
01136   OMX_CONFIG_SCALEFACTORTYPE *omxConfigScale;
01137   OMX_CONFIG_POINTTYPE *omxConfigOutputPosition;
01138 
01139   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
01140   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
01141   omx_fbdev_sink_component_PortType *pPort;
01142   if (pComponentConfigStructure == NULL) {
01143     return OMX_ErrorBadParameter;
01144   }
01145   DEBUG(DEB_LEV_SIMPLE_SEQ, "   Getting configuration %i\n", nIndex);
01146   /* Check which structure we are being fed and fill its header */
01147   switch (nIndex) {
01148     case OMX_IndexConfigCommonInputCrop:
01149       omxConfigCrop = (OMX_CONFIG_RECTTYPE*)pComponentConfigStructure;
01150       setHeader(omxConfigCrop, sizeof(OMX_CONFIG_RECTTYPE));
01151       if (omxConfigCrop->nPortIndex == 0) {
01152         pPort = (omx_fbdev_sink_component_PortType *)omx_fbdev_sink_component_Private->ports[omxConfigCrop->nPortIndex];
01153         memcpy(omxConfigCrop, &pPort->omxConfigCrop, sizeof(OMX_CONFIG_RECTTYPE));
01154       } else {
01155         return OMX_ErrorBadPortIndex;
01156       }
01157     break;    
01158     case OMX_IndexConfigCommonRotate:
01159       omxConfigRotate = (OMX_CONFIG_ROTATIONTYPE*)pComponentConfigStructure;
01160       setHeader(omxConfigRotate, sizeof(OMX_CONFIG_ROTATIONTYPE));
01161       if (omxConfigRotate->nPortIndex == 0) {
01162         pPort = (omx_fbdev_sink_component_PortType *)omx_fbdev_sink_component_Private->ports[omxConfigRotate->nPortIndex];
01163         memcpy(omxConfigRotate, &pPort->omxConfigRotate, sizeof(OMX_CONFIG_ROTATIONTYPE));
01164       } else {
01165         return OMX_ErrorBadPortIndex;
01166       }
01167       break;    
01168     case OMX_IndexConfigCommonMirror:
01169       omxConfigMirror = (OMX_CONFIG_MIRRORTYPE*)pComponentConfigStructure;
01170       setHeader(omxConfigMirror, sizeof(OMX_CONFIG_MIRRORTYPE));
01171       if (omxConfigMirror->nPortIndex == 0) {
01172         pPort = (omx_fbdev_sink_component_PortType *)omx_fbdev_sink_component_Private->ports[omxConfigMirror->nPortIndex];
01173         memcpy(omxConfigMirror, &pPort->omxConfigMirror, sizeof(OMX_CONFIG_MIRRORTYPE));
01174       } else {
01175         return OMX_ErrorBadPortIndex;
01176       }
01177       break;      
01178     case OMX_IndexConfigCommonScale:
01179       omxConfigScale = (OMX_CONFIG_SCALEFACTORTYPE*)pComponentConfigStructure;
01180       setHeader(omxConfigScale, sizeof(OMX_CONFIG_SCALEFACTORTYPE));
01181       if (omxConfigScale->nPortIndex == 0) {
01182         pPort = (omx_fbdev_sink_component_PortType *)omx_fbdev_sink_component_Private->ports[omxConfigScale->nPortIndex];
01183         memcpy(omxConfigScale, &pPort->omxConfigScale, sizeof(OMX_CONFIG_SCALEFACTORTYPE));
01184       } else {
01185         return OMX_ErrorBadPortIndex;
01186       }
01187       break;    
01188     case OMX_IndexConfigCommonOutputPosition:
01189       omxConfigOutputPosition = (OMX_CONFIG_POINTTYPE*)pComponentConfigStructure;
01190       setHeader(omxConfigOutputPosition, sizeof(OMX_CONFIG_POINTTYPE));
01191       if (omxConfigOutputPosition->nPortIndex == 0) {
01192         pPort = (omx_fbdev_sink_component_PortType *)omx_fbdev_sink_component_Private->ports[omxConfigOutputPosition->nPortIndex];
01193         memcpy(omxConfigOutputPosition, &pPort->omxConfigOutputPosition, sizeof(OMX_CONFIG_POINTTYPE));
01194       } else {
01195         return OMX_ErrorBadPortIndex;
01196       }
01197       break;    
01198     default: // delegate to superclass
01199       return omx_base_component_GetConfig(hComponent, nIndex, pComponentConfigStructure);
01200   }
01201   return OMX_ErrorNone;
01202 }
01203 
01204 
01205 
01206 OMX_ERRORTYPE omx_fbdev_sink_component_SetParameter(
01207   OMX_IN  OMX_HANDLETYPE hComponent,
01208   OMX_IN  OMX_INDEXTYPE nParamIndex,
01209   OMX_IN  OMX_PTR ComponentParameterStructure) {
01210 
01211   OMX_ERRORTYPE err = OMX_ErrorNone;
01212   OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
01213   OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;
01214   OMX_U32 portIndex;
01215 
01216   /* Check which structure we are being fed and make control its header */
01217   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
01218   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
01219   omx_fbdev_sink_component_PortType *pPort;
01220   if (ComponentParameterStructure == NULL) {
01221     return OMX_ErrorBadParameter;
01222   }
01223 
01224   DEBUG(DEB_LEV_SIMPLE_SEQ, "   Setting parameter %i\n", nParamIndex);
01225   switch(nParamIndex) {
01226      case OMX_IndexParamPortDefinition:
01227       pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE*) ComponentParameterStructure;
01228       portIndex = pPortDef->nPortIndex;
01229       err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
01230       if(err!=OMX_ErrorNone) { 
01231         DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err); 
01232         break;
01233       }
01234       pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[portIndex];
01235       if(portIndex != 0) {
01236         return OMX_ErrorBadPortIndex;
01237       }
01238       pPort->sPortParam.nBufferCountActual = pPortDef->nBufferCountActual;
01239 
01240       //  Copy stuff from OMX_VIDEO_PORTDEFINITIONTYPE structure
01241       if(pPortDef->format.video.cMIMEType != NULL) {
01242         strcpy(pPort->sPortParam.format.video.cMIMEType , pPortDef->format.video.cMIMEType);
01243       }
01244       pPort->sPortParam.format.video.nFrameWidth = pPortDef->format.video.nFrameWidth;
01245       pPort->sPortParam.format.video.nFrameHeight = pPortDef->format.video.nFrameHeight;
01246       pPort->sPortParam.format.video.nBitrate = pPortDef->format.video.nBitrate;
01247       pPort->sPortParam.format.video.xFramerate = pPortDef->format.video.xFramerate;
01248       pPort->sPortParam.format.video.bFlagErrorConcealment = pPortDef->format.video.bFlagErrorConcealment;  
01249 
01250       //  Figure out stride, slice height, min buffer size
01251       pPort->sPortParam.format.video.nStride = calcStride(pPort->sPortParam.format.video.nFrameWidth, pPort->sVideoParam.eColorFormat);
01252       pPort->sPortParam.format.video.nSliceHeight = pPort->sPortParam.format.video.nFrameHeight;  //  No support for slices yet
01253       // Read-only field by spec
01254 
01255       pPort->sPortParam.nBufferSize = (OMX_U32) abs(pPort->sPortParam.format.video.nStride) * pPort->sPortParam.format.video.nSliceHeight;
01256       pPort->omxConfigCrop.nWidth = pPort->sPortParam.format.video.nFrameWidth;
01257       pPort->omxConfigCrop.nHeight = pPort->sPortParam.format.video.nFrameHeight;
01258       break;
01259 
01260     case OMX_IndexParamVideoPortFormat:
01261       //  FIXME: How do we handle the nIndex member?
01262       pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
01263       portIndex = pVideoPortFormat->nPortIndex;
01264       err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
01265       if(err!=OMX_ErrorNone) { 
01266         DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err); 
01267         break;
01268       }
01269       pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[portIndex];
01270       if(portIndex != 0) {
01271         return OMX_ErrorBadPortIndex;
01272       }
01273       if (pVideoPortFormat->eCompressionFormat != OMX_VIDEO_CodingUnused)  {
01274         //  No compression allowed
01275         return OMX_ErrorUnsupportedSetting;
01276       }
01277 
01278       if(pVideoPortFormat->xFramerate > 0) {
01279         nFrameProcessTime = 1000000 / pVideoPortFormat->xFramerate;
01280       }
01281       pPort->sVideoParam.xFramerate = pVideoPortFormat->xFramerate;
01282       pPort->sVideoParam.eCompressionFormat = pVideoPortFormat->eCompressionFormat;
01283       pPort->sVideoParam.eColorFormat = pVideoPortFormat->eColorFormat;
01284       //  Figure out stride, slice height, min buffer size
01285       pPort->sPortParam.format.video.nStride = calcStride(pPort->sPortParam.format.video.nFrameWidth, pPort->sVideoParam.eColorFormat);
01286       pPort->sPortParam.format.video.nSliceHeight = pPort->sPortParam.format.video.nFrameHeight;  //  No support for slices yet
01287       break;
01288     default: /*Call the base component function*/
01289       return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
01290   }
01291   return err;
01292 }
01293 
01294 
01295 OMX_ERRORTYPE omx_fbdev_sink_component_GetParameter(
01296   OMX_IN  OMX_HANDLETYPE hComponent,
01297   OMX_IN  OMX_INDEXTYPE nParamIndex,
01298   OMX_INOUT OMX_PTR ComponentParameterStructure) {
01299 
01300   OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;  
01301   OMX_ERRORTYPE err = OMX_ErrorNone;
01302   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
01303   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = openmaxStandComp->pComponentPrivate;
01304   omx_fbdev_sink_component_PortType *pPort = (omx_fbdev_sink_component_PortType *) omx_fbdev_sink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];  
01305   if (ComponentParameterStructure == NULL) {
01306     return OMX_ErrorBadParameter;
01307   }
01308   DEBUG(DEB_LEV_SIMPLE_SEQ, "   Getting parameter %i\n", nParamIndex);
01309   /* Check which structure we are being fed and fill its header */
01310   switch(nParamIndex) {
01311     case OMX_IndexParamVideoInit:
01312       if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) { 
01313         break;
01314       }
01315       memcpy(ComponentParameterStructure, &omx_fbdev_sink_component_Private->sPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
01316       break;    
01317     case OMX_IndexParamVideoPortFormat:
01318       pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
01319       if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) { 
01320         break;
01321       }
01322       if (pVideoPortFormat->nPortIndex < 1) {
01323         memcpy(pVideoPortFormat, &pPort->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
01324       } else {
01325         return OMX_ErrorBadPortIndex;
01326       }
01327       break;  
01328     default: /*Call the base component function*/
01329       return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
01330   }
01331   return err;
01332 }
01333 
01334 
01335 OMX_ERRORTYPE omx_fbdev_sink_component_MessageHandler(OMX_COMPONENTTYPE* openmaxStandComp,internalRequestMessageType *message) {
01336 
01337   omx_fbdev_sink_component_PrivateType* omx_fbdev_sink_component_Private = (omx_fbdev_sink_component_PrivateType*)openmaxStandComp->pComponentPrivate;
01338   OMX_ERRORTYPE err;
01339   OMX_STATETYPE eState;
01340 
01341   DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s\n", __func__);
01342   eState = omx_fbdev_sink_component_Private->state; //storing current state
01343 
01344   if (message->messageType == OMX_CommandStateSet){
01345     if ((message->messageParam == OMX_StateExecuting ) && (omx_fbdev_sink_component_Private->state == OMX_StateIdle)) {
01346       DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s sink component from loaded to idle \n", __func__);
01347       err = omx_fbdev_sink_component_Init(openmaxStandComp);
01348       if(err!=OMX_ErrorNone) { 
01349         DEBUG(DEB_LEV_ERR, "In %s Video Sink Init Failed Error=%x\n",__func__,err); 
01350         return err;
01351       }
01352     } 
01353   }
01354   // Execute the base message handling
01355   err = omx_base_component_MessageHandler(openmaxStandComp,message);
01356 
01357   if (message->messageType == OMX_CommandStateSet) {
01358     if ((message->messageParam == OMX_StateIdle ) && (omx_fbdev_sink_component_Private->state == OMX_StateIdle) && eState == OMX_StateExecuting) {
01359       err = omx_fbdev_sink_component_Deinit(openmaxStandComp);
01360       if(err!=OMX_ErrorNone) { 
01361         DEBUG(DEB_LEV_ERR, "In %s Video Sink Deinit Failed Error=%x\n",__func__,err); 
01362         return err;
01363       }
01364     }
01365   }
01366   return err;
01367 }

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