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

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 <saa7105.h>
  21. #include <saa7115.h>    
  22. #include <saa7121.h>  //change
  23. #include <evmdm642.h>
  24. #include "colorbar.h"
  25. #include "evmdm642_vcapparams.h"
  26. #include "evmdm642_vdisparams.h"   
  27. /* heap IDs defined in the BIOS configuration file */
  28. extern Int EXTERNALHEAP;
  29. /*
  30.  * ======== main ========
  31.  */
  32. main()
  33. {
  34.     /******************************************************/
  35.     /* open CSL DAT module for fast copy                  */
  36.     /******************************************************/
  37.     CSL_init();                                             
  38.     CACHE_clean(CACHE_L2ALL, 0, 0);
  39.     CACHE_setL2Mode(CACHE_256KCACHE);       
  40.     CACHE_enableCaching(CACHE_EMIFA_CE00);
  41.     CACHE_enableCaching(CACHE_EMIFA_CE01);
  42.     DAT_open(DAT_CHAANY, DAT_PRI_LOW, DAT_OPEN_2D);
  43. }
  44. /*
  45.  * ======== tskVideoLoopback ========
  46.  * video loopback function.
  47.  */
  48. void tskVideoLoopback()
  49. {
  50.     Int status;
  51.     FVID_Handle disChan; 
  52.     Int frames = 0;
  53.     FVID_Frame *disFrameBuf;
  54.     Int numLinesDis = EVMDM642_vDisParamsChan.imgVSizeFld1;
  55.     Int numLinesCap = EVMDM642_vCapParamsChan.fldYStop1 -
  56.        EVMDM642_vCapParamsChan.fldYStrt1+1;
  57.     
  58.     Int numLines = (numLinesDis > numLinesCap) ? numLinesCap : numLinesDis;
  59. #ifdef _LOOPBACK
  60.     FVID_Handle capChan; 
  61.     Int numPixels = EVMDM642_vCapParamsChan.fldXStop1 - 
  62.        EVMDM642_vCapParamsChan.fldXStrt1+1;
  63.     FVID_Frame *capFrameBuf;
  64.     Int capLinePitch = EVMDM642_vCapParamsChan.fldXStop1 - 
  65.        EVMDM642_vCapParamsChan.fldXStrt1+1;
  66.     Int disLinePitch = EVMDM642_vDisParamsChan.imgHSizeFld1;
  67. #ifdef _PIP
  68.     VPORTCAP_Params EVMDM642_vCapParamsChan2 = EVMDM642_vCapParamsChan;
  69.     FVID_Handle capChan2; 
  70.     FVID_Frame *capFrameBuf2;
  71.     Int yPitch = capLinePitch >> 1;
  72.     Int cPitch = ((capLinePitch >> 2) + 7) & (~ 7);
  73. #endif
  74. #endif                
  75.  
  76.     numLines *= 2; /* both fields */
  77.     /******************************************************/
  78.     /* allocate both capture and display frame buffers    */
  79.     /* in external heap memory                            */
  80.     /******************************************************/
  81.         EVMDM642_vCapParamsChan.segId = EXTERNALHEAP;
  82.         EVMDM642_vDisParamsChan.segId = EXTERNALHEAP;
  83. #ifdef _SAA7105
  84.         EVMDM642_vDisParamsSAA7105.hI2C = EVMDM642_I2C_hI2C;
  85. #endif        
  86. #ifdef _SAA7121
  87.         EVMDM642_vDisParamsSAA7121.hI2C = EVMDM642_I2C_hI2C;
  88. #endif        
  89.         EVMDM642_vCapParamsSAA7115.hI2C = EVMDM642_I2C_hI2C;
  90.     /******************************************************/
  91.     /* initialization of capture driver                   */
  92.     /******************************************************/
  93. #ifdef _LOOPBACK
  94.     capChan = FVID_create("/VP0CAPTURE/A/0", 
  95.             IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan, NULL);
  96. #ifdef _PIP
  97.     EVMDM642_vCapParamsChan2.scale = VPORT_SCALING_ENABLE;
  98.         EVMDM642_vCapParamsChan2.fldOp = VPORT_FLDOP_FLD1;        
  99.         EVMDM642_vCapParamsChan2.thrld >>=1;
  100.     capChan2 = FVID_create("/VP1CAPTURE/A/1", 
  101.             IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan2, NULL);
  102. #endif          
  103. #endif          
  104.     /******************************************************/
  105.     /* initialization of display driver                   */
  106.     /******************************************************/
  107.     //disChan = FVID_create("/VP2DISPLAY", IOM_OUTPUT,  //change
  108.     disChan = FVID_create("/VP2DISPLAY/0", IOM_OUTPUT,  //change
  109.         &status, (Ptr)&EVMDM642_vDisParamsChan, NULL);
  110.     
  111.     /******************************************************/
  112.     /* configure video encoder & decoder                  */
  113.     /******************************************************/
  114.   
  115. #ifdef _SAA7105    
  116.     FVID_control(disChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, 
  117.         (Ptr)&EVMDM642_vDisParamsSAA7105);  
  118. #endif
  119.         
  120. #ifdef _LOOPBACK
  121.     FVID_control(capChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, 
  122.        (Ptr)&EVMDM642_vCapParamsSAA7115);
  123. #ifdef _PIP
  124.     EVMDM642_vCapParamsSAA7115.aFmt = SAA7115_AFMT_COMPOSITE;
  125.     FVID_control(capChan2, VPORT_CMD_EDC_BASE+EDC_CONFIG, 
  126.         (Ptr)&EVMDM642_vCapParamsSAA7115);
  127. #endif
  128. #endif
  129. #ifdef _SAA7121    
  130.     FVID_control(disChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, 
  131.         (Ptr)&EVMDM642_vDisParamsSAA7121);  
  132. #endif
  133.     /******************************************************/
  134.     /* start capture & display operation                  */    
  135.     /******************************************************/
  136.     FVID_control(disChan, VPORT_CMD_START, NULL);
  137. #ifdef _LOOPBACK
  138.     FVID_control(capChan, VPORT_CMD_START, NULL);
  139. #ifdef _PIP
  140.     FVID_control(capChan2, VPORT_CMD_START, NULL);
  141. #endif    
  142. #endif    
  143.     
  144.     /********************************************************/
  145.     /* request a frame buffer from display & capture driver */
  146.     /********************************************************/
  147.     FVID_alloc(disChan, &disFrameBuf);
  148. #ifdef _LOOPBACK
  149.     FVID_alloc(capChan, &capFrameBuf);
  150. #ifdef _PIP
  151.     FVID_alloc(capChan2, &capFrameBuf2);
  152. #endif      
  153. #endif
  154.     frames ++;
  155.     while(1){/* loop forever */
  156. #ifdef _LOOPBACK
  157.         Int i;
  158.         /* copy data from capture buffer to display buffer */
  159.         /***************************************************/
  160.         for(i = 0; i < numLines; i ++) {
  161.             DAT_copy(capFrameBuf->frame.iFrm.y1 + i * capLinePitch, 
  162.                      disFrameBuf->frame.iFrm.y1 + i * disLinePitch,
  163.                      numPixels);
  164.             DAT_copy(capFrameBuf->frame.iFrm.cb1 + i * (capLinePitch >> 1), 
  165.                      disFrameBuf->frame.iFrm.cb1 + i * (disLinePitch >> 1),
  166.                      numPixels>>1);
  167.             DAT_copy(capFrameBuf->frame.iFrm.cr1 + i * (capLinePitch >> 1), 
  168.                      disFrameBuf->frame.iFrm.cr1 + i * (disLinePitch >> 1),
  169.                      numPixels>>1);
  170.         }
  171. #ifdef _PIP  
  172.         for(i = 0; i < (numLines>>1); i ++) {
  173.             DAT_copy(capFrameBuf2->frame.iFrm.y1 + i * yPitch, 
  174.                      disFrameBuf->frame.iFrm.y1 + i * disLinePitch
  175.                      + (disLinePitch >> 1),
  176.                      (numPixels>>1));
  177.             DAT_copy(capFrameBuf2->frame.iFrm.cb1 + i * cPitch, 
  178.                      disFrameBuf->frame.iFrm.cb1 + i * (disLinePitch >> 1)
  179.                      + (disLinePitch >>2 ),
  180.                      (numPixels >> 2));
  181.             DAT_copy(capFrameBuf2->frame.iFrm.cr1 + i * cPitch, 
  182.                      disFrameBuf->frame.iFrm.cr1 + i * (disLinePitch >> 1)
  183.                      +(disLinePitch >> 2),
  184.                      (numPixels >> 2));
  185.         }
  186. #endif
  187.         DAT_wait(DAT_XFRID_WAITALL);
  188.         FVID_exchange(capChan, &capFrameBuf);
  189. #ifdef _PIP
  190.         FVID_exchange(capChan2, &capFrameBuf2);
  191. #endif
  192. #else
  193.         fillFrmBuf(&disFrameBuf->frame.iFrm, EVMDM642_vDisParamsChan.imgHSizeFld1,
  194.           EVMDM642_vDisParamsChan.imgVSizeFld1 
  195.             + EVMDM642_vDisParamsChan.imgVSizeFld2,
  196.           frames % 360);
  197. #endif
  198.         FVID_exchange(disChan, &disFrameBuf);        
  199.         frames ++;              
  200.    }
  201. }