video.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:7k
源码类别:

DSP编程

开发平台:

C/C++

  1. /*
  2.  *  Copyright 2003 by Texas Instruments Incorporated.
  3.  *  All rights reserved. Property of Texas Instruments Incorporated.
  4.  *  Restricted rights to use, duplicate or disclose this code are
  5.  *  granted through contract.
  6.  *  
  7.  */
  8. /* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
  9. #include <std.h>
  10. #include <tsk.h>  
  11. #include <sem.h>   
  12. #include <gio.h>
  13. #include <csl_dat.h>
  14. #include <csl_cache.h>
  15. #include <fvid.h>
  16. #include <edc.h>
  17. #include <vport.h>
  18. #include <vportcap.h>
  19. #include <vportdis.h>
  20. #include "saa7121.h"
  21. #include <saa7115.h>    
  22. #include <evmdm642.h>
  23. #include "vcapparams.h"
  24. #include "vdisparams.h"   
  25. /* heap IDs defined in the BIOS configuration file */
  26. extern Int EXTERNALHEAP;
  27. #include "ICETEK-DM642-C.h"
  28. extern unsigned int m_uVideoStatus,m_bFreeze;
  29. extern unsigned char m_dbFrameY[SIMGWIDTH*SIMGHEIGHT];
  30. extern unsigned char m_dbFrameU[SIMGWIDTH1*SIMGHEIGHT1];
  31. extern unsigned char m_dbFrameV[SIMGWIDTH1*SIMGHEIGHT1];
  32. /*
  33.  * ======== main ========
  34.  */
  35. main()
  36. {
  37.     ICETEKDM642CInit();
  38.     /******************************************************/
  39.     /* open CSL DAT module for fast copy                  */
  40.     /******************************************************/
  41.     CSL_init();                                             
  42.     CACHE_clean(CACHE_L2ALL, 0, 0);
  43.     CACHE_setL2Mode(CACHE_256KCACHE);       
  44.     CACHE_enableCaching(CACHE_EMIFA_CE00);
  45.     CACHE_enableCaching(CACHE_EMIFA_CE01);
  46.     DAT_open(DAT_CHAANY, DAT_PRI_LOW, DAT_OPEN_2D);
  47. }
  48. /*
  49.  * ======== tskVideoLoopback ========
  50.  * video loopback function.
  51.  */
  52. void tskVideoLoopback()
  53. {
  54.     Int i;
  55.     unsigned int m_nID;
  56.     Int status;
  57.     FVID_Handle disChan; 
  58.     Int frames = 0;
  59.     FVID_Frame *disFrameBuf;
  60.     Int numLinesDis = EVMDM642_vDisParamsChan.imgVSizeFld1;
  61.     Int numLinesCap = EVMDM642_vCapParamsChan.fldYStop1 -
  62.        EVMDM642_vCapParamsChan.fldYStrt1+1;
  63.     
  64.     Int numLines = (numLinesDis > numLinesCap) ? numLinesCap : numLinesDis;
  65.     FVID_Handle capChan; 
  66.     Int numPixels = EVMDM642_vCapParamsChan.fldXStop1 - 
  67.        EVMDM642_vCapParamsChan.fldXStrt1+1;
  68.     FVID_Frame *capFrameBuf;
  69.     Int capLinePitch = EVMDM642_vCapParamsChan.fldXStop1 - 
  70.        EVMDM642_vCapParamsChan.fldXStrt1+1;
  71.     Int disLinePitch = EVMDM642_vDisParamsChan.imgHSizeFld1;
  72.     numLines *= 2; /* both fields */
  73.     /******************************************************/
  74.     /* allocate both capture and display frame buffers    */
  75.     /* in external heap memory                            */
  76.     /******************************************************/
  77.         EVMDM642_vCapParamsChan.segId = EXTERNALHEAP;
  78.         EVMDM642_vDisParamsChan.segId = EXTERNALHEAP;
  79.         EVMDM642_vDisParamsSAA7121.hI2C = EVMDM642_I2C_hI2C;
  80.         EVMDM642_vCapParamsSAA7115.hI2C = EVMDM642_I2C_hI2C;
  81.     /******************************************************/
  82.     /* initialization of capture driver                   */
  83.     /******************************************************/
  84.     capChan = FVID_create("/VP0CAPTURE/A/0", 
  85.             IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan, NULL);
  86.     /******************************************************/
  87.     /* initialization of display driver                   */
  88.     /******************************************************/
  89.     disChan = FVID_create("/VP2DISPLAY/1", IOM_OUTPUT, 
  90.         &status, (Ptr)&EVMDM642_vDisParamsChan, NULL);
  91.     
  92.     /******************************************************/
  93.     /* configure video encoder & decoder                  */
  94.     /******************************************************/
  95.     FVID_control(disChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, 
  96.         (Ptr)&EVMDM642_vDisParamsSAA7121);
  97.     FVID_control(capChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, 
  98.         (Ptr)&EVMDM642_vCapParamsSAA7115);
  99.     /******************************************************/
  100.     /* start capture & display operation                  */    
  101.     /******************************************************/
  102.     FVID_control(disChan, VPORT_CMD_START, NULL);
  103.     FVID_control(capChan, VPORT_CMD_START, NULL);
  104.     
  105.     /********************************************************/
  106.     /* request a frame buffer from display & capture driver */
  107.     /********************************************************/
  108.     FVID_alloc(disChan, &disFrameBuf);
  109.     FVID_alloc(capChan, &capFrameBuf);
  110.     frames ++;
  111.     while ( 1 )
  112.     {
  113.         switch ( m_uVideoStatus )
  114.         {
  115.          case FREEZE:
  116.         DAT_copy2d(DAT_2D2D,
  117.          m_dbFrameY,
  118.          disFrameBuf->frame.iFrm.y1,
  119.          numPixels,
  120.          numLines,
  121.          numPixels);
  122.         DAT_copy2d(DAT_2D2D,
  123.          m_dbFrameV,
  124.          disFrameBuf->frame.iFrm.cb1,
  125.          numPixels>>1,
  126.          numLines,
  127.          numPixels>>1);
  128.         DAT_copy2d(DAT_2D2D,
  129.          m_dbFrameU,
  130.          disFrameBuf->frame.iFrm.cr1,
  131.          numPixels>>1,
  132.          numLines,
  133.          numPixels>>1);
  134. if ( !m_bFreeze )
  135. {
  136. ICETEKDM642CYUVRGB();
  137. m_bFreeze=1;
  138. }
  139.          break;
  140.          case LOOPBACK:
  141. default:
  142.         DAT_copy2d(DAT_2D2D,
  143.          capFrameBuf->frame.iFrm.y1,
  144.          disFrameBuf->frame.iFrm.y1,
  145.          numPixels,
  146.          numLines,
  147.          numPixels);
  148.         DAT_copy2d(DAT_2D2D,
  149.          capFrameBuf->frame.iFrm.y1,
  150.          m_dbFrameY,
  151.          numPixels,
  152.          numLines,
  153.          numPixels);
  154.         DAT_copy2d(DAT_2D2D,
  155.          capFrameBuf->frame.iFrm.cb1,
  156.          disFrameBuf->frame.iFrm.cb1,
  157.          numPixels>>1,
  158.          numLines,
  159.          numPixels>>1);
  160.         DAT_copy2d(DAT_2D2D,
  161.          capFrameBuf->frame.iFrm.cb1,
  162.          m_dbFrameV,
  163.          numPixels>>1,
  164.          numLines,
  165.          numPixels>>1);
  166.         DAT_copy2d(DAT_2D2D,
  167.          capFrameBuf->frame.iFrm.cr1,
  168.          disFrameBuf->frame.iFrm.cr1,
  169.          numPixels>>1,
  170.          numLines,
  171.          numPixels>>1);
  172.         DAT_copy2d(DAT_2D2D,
  173.          capFrameBuf->frame.iFrm.cr1,
  174.          m_dbFrameU,
  175.          numPixels>>1,
  176.          numLines,
  177.          numPixels>>1);
  178. m_bFreeze=0;
  179.          break;
  180.         }
  181.         DAT_wait(DAT_XFRID_WAITALL);
  182.         FVID_exchange(capChan, &capFrameBuf);
  183.         FVID_exchange(disChan, &disFrameBuf);        
  184.         frames ++;              
  185.    }
  186. }