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