video_hd.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.11.00.00 11-04-03 (ddk-b13)" */
  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.     Int i;
  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;
  72.     Int cPitch;
  73.     Int xOffset;
  74.     Int yOffset = numLinesDis - numLines;
  75.     Int numLines2;
  76.     Int numPixels2;
  77. #endif
  78. #endif                
  79.  
  80.     numLines *= 2; /* both fields */
  81.     /******************************************************/
  82.     /* allocate both capture and display frame buffers    */
  83.     /* in external heap memory                            */
  84.     /******************************************************/
  85.         EVMDM642_vCapParamsChan.segId = EXTERNALHEAP;
  86.         EVMDM642_vDisParamsChan.segId = EXTERNALHEAP;
  87.         EVMDM642_vDisParamsSAA7105.hI2C = EVMDM642_I2C_hI2C;
  88.         EVMDM642_vCapParamsSAA7115.hI2C = EVMDM642_I2C_hI2C;
  89.     /******************************************************/
  90.     /* initialization of capture driver                   */
  91.     /******************************************************/
  92. #ifdef _LOOPBACK
  93.     capChan = FVID_create("/VP0CAPTURE/A/0", 
  94.             IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan, NULL);
  95. #ifdef _PIP
  96.     if(EVMDM642_vDisParamsChan.fldOp == VPORT_FLDOP_FRAME) {
  97.         yPitch = capLinePitch ;
  98.         cPitch = capLinePitch >> 1;
  99.         yOffset <<= 1;
  100.         numLines2 = numLines;
  101.         numPixels2 = numPixels;
  102.      }else {
  103.         EVMDM642_vCapParamsChan2.scale = VPORT_SCALING_ENABLE;
  104.             EVMDM642_vCapParamsChan2.fldOp = VPORT_FLDOP_FLD1;        
  105.             EVMDM642_vCapParamsChan2.thrld >>=1;
  106.         yPitch = capLinePitch >> 1;
  107.         cPitch = ((capLinePitch >> 2) + 7) & (~ 7);
  108.         numLines2 = numLines >> 1;
  109.         numPixels2 = numPixels >> 1;
  110.     }
  111.     xOffset = disLinePitch - yPitch;
  112.     capChan2 = FVID_create("/VP1CAPTURE/A/1", 
  113.             IOM_INPUT, &status, (Ptr)&EVMDM642_vCapParamsChan2, NULL);
  114. #endif          
  115. #endif          
  116.     /******************************************************/
  117.     /* initialization of display driver                   */
  118.     /******************************************************/
  119.     disChan = FVID_create("/VP2DISPLAY", IOM_OUTPUT, 
  120.         &status, (Ptr)&EVMDM642_vDisParamsChan, NULL);
  121.     
  122.     /******************************************************/
  123.     /* configure video encoder & decoder                  */
  124.     /******************************************************/
  125.     FVID_control(disChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, 
  126.         (Ptr)&EVMDM642_vDisParamsSAA7105);
  127. #ifdef _LOOPBACK
  128.     FVID_control(capChan, VPORT_CMD_EDC_BASE + EDC_CONFIG, 
  129.         (Ptr)&EVMDM642_vCapParamsSAA7115);
  130. #ifdef _PIP
  131.     EVMDM642_vCapParamsSAA7115.aFmt = SAA7115_AFMT_COMPOSITE;
  132.     FVID_control(capChan2, VPORT_CMD_EDC_BASE+EDC_CONFIG, 
  133.         (Ptr)&EVMDM642_vCapParamsSAA7115);
  134. #endif
  135. #endif
  136.     EVMDM642_rset(0x10, 0x20);
  137.     EVMDM642_rset(0x10, 0x00);
  138.     while(!(EVMDM642_rget(0x13) & 0x40));
  139.     /******************************************************/
  140.     /* start capture & display operation                  */    
  141.     /******************************************************/
  142.     FVID_control(disChan, VPORT_CMD_START, NULL);
  143. #ifdef _LOOPBACK
  144.     FVID_control(capChan, VPORT_CMD_START, NULL);
  145. #ifdef _PIP
  146.     FVID_control(capChan2, VPORT_CMD_START, NULL);
  147. #endif    
  148. #endif    
  149.     
  150.     /********************************************************/
  151.     /* request a frame buffer from display & capture driver */
  152.     /********************************************************/
  153.     FVID_alloc(disChan, &disFrameBuf);
  154. #ifdef _LOOPBACK
  155.     FVID_alloc(capChan, &capFrameBuf);
  156. #ifdef _PIP
  157.     FVID_alloc(capChan2, &capFrameBuf2);
  158. #endif      
  159. #endif
  160.     frames ++;
  161.     CACHE_clean(CACHE_L2ALL, 0, 0);
  162.     while(1){/* loop forever */
  163. #ifdef _LOOPBACK
  164.         /* copy data from capture buffer to display buffer */
  165.         /***************************************************/
  166.         for(i = 0; i < numLines; i ++) {
  167.             DAT_copy(capFrameBuf->frame.iFrm.y1 + i * capLinePitch, 
  168.                      disFrameBuf->frame.iFrm.y1 + i * disLinePitch,
  169.                      numPixels);
  170.             DAT_copy(capFrameBuf->frame.iFrm.cb1 + i * (capLinePitch >> 1), 
  171.                      disFrameBuf->frame.iFrm.cb1 + i * (disLinePitch >> 1),
  172.                      numPixels>>1);
  173.             DAT_copy(capFrameBuf->frame.iFrm.cr1 + i * (capLinePitch >> 1), 
  174.                      disFrameBuf->frame.iFrm.cr1 + i * (disLinePitch >> 1),
  175.                      numPixels>>1);
  176.         }
  177. #ifdef _PIP  
  178.         for(i = 0; i < numLines2; i ++) {
  179.             DAT_copy(capFrameBuf2->frame.iFrm.y1 + i * yPitch, 
  180.                      disFrameBuf->frame.iFrm.y1 + (i + yOffset) * disLinePitch
  181.                      + xOffset,
  182.                      numPixels2);
  183.                      
  184.             DAT_copy(capFrameBuf2->frame.iFrm.cb1 + i * cPitch, 
  185.                      disFrameBuf->frame.iFrm.cb1 + (i + yOffset) * (disLinePitch >> 1)
  186.                      + (xOffset >> 1),
  187.                      (numPixels2 >> 1));
  188.             DAT_copy(capFrameBuf2->frame.iFrm.cr1 + i * cPitch, 
  189.                      disFrameBuf->frame.iFrm.cr1 + (i + yOffset) * (disLinePitch >> 1)
  190.                      +(xOffset >> 1),
  191.                      (numPixels2 >> 1));
  192.         }
  193. #endif
  194.         FVID_exchange(capChan, &capFrameBuf);
  195. #ifdef _PIP
  196.         FVID_exchange(capChan2, &capFrameBuf2);
  197. #endif
  198. #else
  199.         fillFrmBuf(&disFrameBuf->frame.iFrm, EVMDM642_vDisParamsChan.imgHSizeFld1,
  200.           EVMDM642_vDisParamsChan.imgVSizeFld1 
  201.             + EVMDM642_vDisParamsChan.imgVSizeFld2,
  202.           frames % 360);
  203. #endif
  204.         FVID_exchange(disChan, &disFrameBuf);
  205.         
  206.         frames ++;              
  207.    }
  208. }