vmix.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:12k
源码类别:

DVD

开发平台:

C/C++

  1. /*****************************************************************************
  2. File name  : vmix.c
  3. Description: VMIX functions
  4. COPYRIGHT (C) STMicroelectronics 2004.
  5. *****************************************************************************/
  6. /* Includes --------------------------------------------------------------- */
  7. #include <string.h>
  8. #include "stddefs.h"
  9. #include "stlite.h"
  10. #include "stdevice.h"
  11. #include "stvid.h"
  12. #include "stgxobj.h"
  13. #include "sttbx.h"
  14. #include "section.h"   /* memory partitions */
  15. #include "errors.h"
  16. #include "evt.h"
  17. #include "layer.h"
  18. #include "vtg.h"
  19. #include "vout.h"
  20. #include "vmix.h"
  21. #include "avmem.h"
  22. #include "osd.h"
  23. /* Private Types ------------------------------------------------------ */
  24. /* Private Constants -------------------------------------------------- */
  25. #ifdef OSD_SUPPORT
  26. #define NUM_VMIX_LAYERS     (NUM_LAYERS+1)
  27. #else
  28. #define NUM_VMIX_LAYERS     (NUM_LAYERS)
  29. #endif
  30. /* Private Variables -------------------------------------------------- */
  31. static STVMIX_LayerDisplayParams_t *VMIXLayerArray_p[NUM_VMIX_LAYERS];
  32. static STVMIX_LayerDisplayParams_t  VMIXLayerParam[NUM_VMIX_LAYERS];
  33. /* Private Macros ----------------------------------------------------- */
  34. /* Private Function prototypes ---------------------------------------- */
  35. /* Global Variables ------------------------------------------------------- */
  36. STVMIX_Handle_t g_KB_VmixHandle     = 0;
  37. ST_DeviceName_t g_KB_VmixDeviceName = "VMIX";
  38. //added by whale 07/06/26
  39. STGXOBJ_AspectRatio_t g_KB_VmixAspectRatio = STGXOBJ_ASPECT_RATIO_4TO3;
  40. /* Functions -------------------------------------------------------------- */
  41. /*-------------------------------------------------------------------------
  42.  * Function : KB_VmixSetup
  43.  * Input    : None
  44.  * Output   :
  45.  * Return   : Error Code
  46.  * ----------------------------------------------------------------------*/
  47. ST_ErrorCode_t KB_VmixSetup(void)
  48. {
  49.     ST_ErrorCode_t          ST_ErrorCode;
  50.     ST_DeviceName_t         VoutDeviceNames[KB_VOUT_MAX_DEVICES+1];
  51.     STVMIX_InitParams_t     STVMIX_InitParams;
  52.     STVMIX_OpenParams_t     STVMIX_OpenParams = { 0 }; /* dummy parameter */
  53.     U8                      Index;
  54.     STVMIX_InitParams.CPUPartition_p      = SystemPartition;
  55.     STVMIX_InitParams.BaseAddress_p       = (void *)KB_VMIX_BASE_ADDRESS;
  56.     STVMIX_InitParams.DeviceBaseAddress_p = (void *)KB_VMIX_DEVICE_BASE_ADDRESS;
  57.     STVMIX_InitParams.DeviceType          = KB_VMIX_DEVICE_TYPE;
  58.     STVMIX_InitParams.MaxOpen             = 2;
  59.     STVMIX_InitParams.MaxLayer            = NUM_VMIX_LAYERS;
  60.     switch (KB_VMIX_DEVICE_TYPE)
  61.     {
  62.         case STVMIX_OMEGA1_SD :
  63.             strcpy(VoutDeviceNames[0], "" );
  64.             strcpy(VoutDeviceNames[1], "" );
  65.             strcpy(VoutDeviceNames[2], "" );
  66.             break;
  67.         case STVMIX_GENERIC_GAMMA_TYPE_5528 :
  68.             strcpy(VoutDeviceNames[0], "VOUT_CVBS" );
  69.             strcpy(VoutDeviceNames[1], "" );
  70.             strcpy(VoutDeviceNames[2], "" );
  71.             break;
  72.         case STVMIX_COMPOSITOR :
  73.         case STVMIX_COMPOSITOR_FIELD:  /* included for field based composition */
  74.         case STVMIX_COMPOSITOR_FIELD_SDRAM:
  75.         case STVMIX_COMPOSITOR_422:
  76.         case STVMIX_COMPOSITOR_FIELD_422:  /* included for field based composition */
  77.         case STVMIX_COMPOSITOR_FIELD_SDRAM_422:
  78.         case STVMIX_COMPOSITOR_FIELD_COMBINED:
  79.         case STVMIX_COMPOSITOR_FIELD_COMBINED_422:
  80.         case STVMIX_COMPOSITOR_FIELD_COMBINED_SDRAM:
  81.         case STVMIX_COMPOSITOR_FIELD_COMBINED_SDRAM_422:
  82.             {
  83.                 STGXOBJ_Bitmap_t                CacheBitmap;
  84.                 STAVMEM_AllocBlockParams_t      AllocBlockParams;
  85.                 STAVMEM_BlockHandle_t           VMIX_AVMEMHandle;
  86.                 STVMIX_InitParams.RegisterInfo.CompoBaseAddress_p = (void*)KB_VMIX_COMPO_BASE_ADDRESS;
  87.                 STVMIX_InitParams.RegisterInfo.GdmaBaseAddress_p  = (void*)KB_VMIX_GDMA_BASE_ADDRESS;
  88.                 STVMIX_InitParams.RegisterInfo.VoutBaseAddress_p  = (void*)VOUT_BASE_ADDRESS;
  89.                 STVMIX_InitParams.AVMEM_Partition                 = g_KBAvmemPartitionHandle[0];
  90.                 CacheBitmap.ColorType                     = STGXOBJ_COLOR_TYPE_UNSIGNED_YCBCR888_444;
  91.                 CacheBitmap.ColorSpaceConversion          = STGXOBJ_ITU_R_BT601;
  92.                 AllocBlockParams.PartitionHandle          = g_KBAvmemPartitionHandle[0];
  93.                 STVMIX_InitParams.AVMEM_Partition2        = g_KBAvmemPartitionHandle[0];
  94.                 AllocBlockParams.Alignment                = 16;
  95.                 AllocBlockParams.Size                     = 16*1024;
  96.                 AllocBlockParams.AllocMode                = STAVMEM_ALLOC_MODE_BOTTOM_TOP;
  97.                 AllocBlockParams.NumberOfForbiddenRanges  = 0;
  98.                 AllocBlockParams.ForbiddenRangeArray_p    = NULL;
  99.                 AllocBlockParams.NumberOfForbiddenBorders = 0;
  100.                 AllocBlockParams.ForbiddenBorderArray_p   = NULL;
  101.                 ST_ErrorCode= STAVMEM_AllocBlock(&AllocBlockParams,&VMIX_AVMEMHandle);
  102.                 ST_ErrorCode = STAVMEM_GetBlockAddress(VMIX_AVMEMHandle,&CacheBitmap.Data1_p);
  103.                 CacheBitmap.Size1                         = AllocBlockParams.Size;
  104.                 STVMIX_InitParams.CacheBitmap_p           = &CacheBitmap;
  105.             }
  106.             strcpy(VoutDeviceNames[0], "VOUT_CVBS" );
  107.             strcpy(VoutDeviceNames[1], "" );
  108.             strcpy(VoutDeviceNames[2], "" );
  109.             break;
  110.         default :
  111.             break;
  112.     }
  113.     STVMIX_InitParams.OutputArray_p       = VoutDeviceNames;
  114.     strcpy(STVMIX_InitParams.VTGName,        "VTG"          );
  115.     strcpy(STVMIX_InitParams.EvtHandlerName, "EVT" );
  116.     STTBX_Print(("KB_VmixSetup(%s)=", g_KB_VmixDeviceName ));
  117.     ST_ErrorCode = STVMIX_Init(g_KB_VmixDeviceName, &STVMIX_InitParams);
  118.     if (ST_ErrorCode != ST_NO_ERROR)
  119.     {
  120.         STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
  121.         return( ST_ErrorCode );
  122.     }
  123.     STTBX_Print(("%sn", STVMIX_GetRevision() ));
  124.     STTBX_Print(("VMIX_Open="));
  125.     ST_ErrorCode = STVMIX_Open(g_KB_VmixDeviceName, &STVMIX_OpenParams, &g_KB_VmixHandle);
  126.     STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
  127.     if (ST_ErrorCode != ST_NO_ERROR)
  128.         return( ST_ErrorCode );
  129.     ST_ErrorCode = STVMIX_SetTimeBase( g_KB_VmixHandle, g_KB_VtgDeviceName );
  130.     if (ST_ErrorCode != ST_NO_ERROR)
  131.     {
  132.         STTBX_Print(("VMIX_SetTimeBase=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  133.     }
  134.     strcpy(VMIXLayerParam[0].DeviceName, g_KB_LayerDeviceName[LAYER_VIDEO] );
  135. #ifdef PIP_SUPPORT /*! Louie(7/13/2005): PIP */
  136.     strcpy(VMIXLayerParam[1].DeviceName, g_KB_LayerDeviceName[LAYER_AUX_VIDEO] );
  137.     strcpy(VMIXLayerParam[2].DeviceName, g_KB_LayerDeviceName[LAYER_OSD] );
  138. #ifdef MOSAIC_FEATURE_ON_WITH_STILL
  139.     strcpy(VMIXLayerParam[3].DeviceName, g_KB_LayerDeviceName[LAYER_STILL] );
  140. #endif
  141. #else
  142.     strcpy(VMIXLayerParam[1].DeviceName, g_KB_LayerDeviceName[LAYER_OSD] );
  143. #ifdef MOSAIC_FEATURE_ON_WITH_STILL
  144.     strcpy(VMIXLayerParam[2].DeviceName, g_KB_LayerDeviceName[LAYER_STILL] );
  145. #endif
  146. #endif
  147.     for ( Index = 0; Index < NUM_LAYERS; Index++ )
  148.     {
  149. #if defined(MOSAIC_FEATURE_ON) || defined(MOSAIC_FEATURE_ON_WITH_STILL) 
  150.         strcpy(VMIXLayerParam[Index].DeviceName, g_KB_LayerDeviceName[Index] );
  151. #else
  152.         strcpy(VMIXLayerParam[Index].DeviceName, g_KB_LayerDeviceName[Index] );
  153. #endif /* defined(MOSAIC_FEATURE_ON) */
  154.         VMIXLayerParam[Index].ActiveSignal = TRUE;
  155.         VMIXLayerArray_p[Index] = &VMIXLayerParam[Index];
  156.     }
  157. #ifdef OSD_SUPPORT
  158.     ST_ErrorCode = STOSD_GetLayerName(VMIXLayerParam[Index].DeviceName);
  159.     if (ST_ErrorCode != ST_NO_ERROR)
  160.     {
  161.         STTBX_Print(("STOSD_GetLayerName=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  162.         return( ST_ErrorCode );
  163.     }
  164.     VMIXLayerParam[Index].ActiveSignal = TRUE;
  165.     VMIXLayerArray_p[Index] = &VMIXLayerParam[Index];
  166. #endif
  167.     ST_ErrorCode = STVMIX_ConnectLayers(g_KB_VmixHandle,
  168.                                         (const STVMIX_LayerDisplayParams_t*  const *)VMIXLayerArray_p,
  169.                                         NUM_VMIX_LAYERS);
  170.     if (ST_ErrorCode != ST_NO_ERROR)
  171.     {
  172.         STTBX_Print(("VMIX_ConnectLayers=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  173.         return( ST_ErrorCode );
  174.     }
  175.     ST_ErrorCode = KB_VmixSetScreenParams();
  176.     if (ST_ErrorCode != ST_NO_ERROR)
  177.     {
  178.         STTBX_Print(("KB_VmixSetScreenParams=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  179.         return( ST_ErrorCode );
  180.     }
  181.     ST_ErrorCode = STVMIX_Enable(g_KB_VmixHandle);
  182.     if (ST_ErrorCode != ST_NO_ERROR)
  183.     {
  184.         STTBX_Print(("VMIX_Enable=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  185.     }
  186.     return( ST_ErrorCode );
  187. }
  188. /*-------------------------------------------------------------------------
  189.  * Function : KB_VmixSetScreenParams
  190.  * Input    : None
  191.  * Output   :
  192.  * Return   : Error Code
  193.  * ----------------------------------------------------------------------*/
  194. ST_ErrorCode_t KB_VmixSetScreenParams(void)
  195. {
  196.     ST_ErrorCode_t          ST_ErrorCode;
  197.     STVMIX_ScreenParams_t   STVMIX_ScreenParams;
  198.     ST_ErrorCode = KB_VtgGetMode();   /* get Active area */
  199.     if (ST_ErrorCode != ST_NO_ERROR)
  200.         return( ST_ErrorCode );
  201. #if 0   /* has to enable when STVMIX_CLDelayWA does not hang */
  202.     /* KB_VmixSetScreenParams is called whenever there is change in Frame Rate in which case STVTG_SetMode is called */
  203.     ST_ErrorCode = STVMIX_CLDelayWA(g_KB_VmixHandle, g_KB_VtgTimingMode);
  204.     if (ST_ErrorCode != ST_NO_ERROR)
  205.     {
  206.         STTBX_Print(("VMIX_CLDelayWA=%sn", KB_ErrorGetText(ST_ErrorCode)));
  207.         return( ST_ErrorCode );
  208.     }
  209. #endif
  210.     /* Set VMIX mode same as VTG */
  211.     //modified by whale 07/06/26
  212.     //STVMIX_ScreenParams.AspectRatio = STGXOBJ_ASPECT_RATIO_4TO3;
  213.     STVMIX_ScreenParams.AspectRatio = g_KB_VmixAspectRatio;
  214.     STVMIX_ScreenParams.ScanType    = g_KB_VtgModeParams.ScanType;
  215.     STVMIX_ScreenParams.FrameRate   = g_KB_VtgModeParams.FrameRate;
  216.     STVMIX_ScreenParams.Width       = g_KB_VtgModeParams.ActiveAreaWidth;
  217.     STVMIX_ScreenParams.Height      = g_KB_VtgModeParams.ActiveAreaHeight;
  218.     STVMIX_ScreenParams.XStart      = g_KB_VtgModeParams.ActiveAreaXStart;
  219.     STVMIX_ScreenParams.YStart      = g_KB_VtgModeParams.ActiveAreaYStart;
  220.     ST_ErrorCode = STVMIX_SetScreenParams(g_KB_VmixHandle, &STVMIX_ScreenParams);
  221.     if (ST_ErrorCode != ST_NO_ERROR)
  222.     {
  223.         STTBX_Print(("KB_VmixSetScreenParams=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  224.         return( ST_ErrorCode );
  225.     }
  226.     STTBX_Print(("KB_VmixSetScreenParams(%s, %d,%d,%d,%d, %d,%d,%d)n", g_KB_VmixDeviceName,
  227.             STVMIX_ScreenParams.XStart,    STVMIX_ScreenParams.YStart,
  228.             STVMIX_ScreenParams.Width,     STVMIX_ScreenParams.Height,
  229.             STVMIX_ScreenParams.FrameRate, STVMIX_ScreenParams.ScanType,
  230.             STVMIX_ScreenParams.AspectRatio ));
  231.    return( ST_ErrorCode );
  232. }
  233. //added by whale 07/06/26 start
  234. ST_ErrorCode_t KB_VmixSetAspectRatio(STGXOBJ_AspectRatio_t nAspectRatio)
  235. {
  236. ST_ErrorCode_t ST_ErrorCode;
  237. g_KB_VmixAspectRatio = nAspectRatio;
  238. ST_ErrorCode = KB_VmixSetScreenParams();
  239. if (ST_ErrorCode != ST_NO_ERROR)
  240. {
  241. STTBX_Print(("KB_VmixSetAspectRatio=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  242. return( ST_ErrorCode );
  243. }
  244. return( ST_ErrorCode );
  245. }
  246. //added by whale 07/06/26 end
  247. /* EOF --------------------------------------------------------------------- */