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

DVD

开发平台:

C/C++

  1. /*****************************************************************************
  2. File name: vid.c
  3. Description: STVID interface
  4. COPYRIGHT (C) 2004 STMicroelectronics
  5. *****************************************************************************/
  6. /* Includes --------------------------------------------------------------- */
  7. #include <string.h>
  8. #include <stdio.h>
  9. #include "stddefs.h"
  10. #include "stlite.h"
  11. #include "stdevice.h"
  12. #include "stsys.h"
  13. #include "stvid.h"
  14. #include "sttbx.h"
  15. #include "section.h"   /* memory partitions */
  16. #include "errors.h"
  17. #include "evt.h"
  18. #include "avmem.h"
  19. #include "clkrv.h"
  20. #include "layer.h"
  21. #include "vtg.h"
  22. #include "vid.h"
  23. #include "vmix.h"
  24. #include "stpti_hal.h"
  25. #include "avslot.h"
  26. /* Private Types ------------------------------------------------------ */
  27. /* Private Constants -------------------------------------------------- */
  28. #define NUM_INSTANCE        0
  29. /* Private Variables -------------------------------------------------- */
  30. /* Private Macros ----------------------------------------------------- */
  31. /* Private Function prototypes ---------------------------------------- */
  32. /* Global Variables ------------------------------------------------------- */
  33. STVID_ViewPortHandle_t  VID_ViewPortHandle_Multiple[VIDEO_USED];
  34. STVID_Handle_t          VID_Handle_Multiple[VIDEO_USED];
  35. #if (VIDEO_USED==2)
  36.     ST_DeviceName_t     VID_DeviceName_Multiple[VIDEO_USED] = { "VID", "AUX_VID" };
  37. #else
  38.     ST_DeviceName_t     VID_DeviceName_Multiple[VIDEO_USED] = { "VID" };
  39. #endif
  40. /* Functions ---------------------------------------------------------- */
  41. /* INTERFACE OBJECT: WRAPPER FCT TO LINK PTI AND VIDEO */
  42. /*-------------------------------------------------------------------------
  43.  * Function: GetWritePtrFct
  44.  * Decription: Gets the PES Buffer Write Pointer from PTI
  45.  * Input   : PTI Buffer Handle
  46.  * Output  :
  47.  * Return  : Error code and the Video Input Buffer Address
  48.  * ----------------------------------------------------------------------*/
  49. ST_ErrorCode_t GetWritePtrFct(void * const Handle_p, void ** const Address_p)
  50. {
  51.     ST_ErrorCode_t Err;
  52.     /* just cast the handle */
  53.     Err = STPTI_BufferGetWritePointer((STPTI_Buffer_t)Handle_p,Address_p);
  54.     return(Err);
  55. }
  56. /*-------------------------------------------------------------------------
  57.  * Function: SetReadPtrFct
  58.  * Decription: Sets the PTI Read Pointer.
  59.  * Input   : PTI Buffer Handle and the Video Buffer Address
  60.  * Output  :
  61.  * Return  : Error code
  62.  * ----------------------------------------------------------------------*/
  63. void SetReadPtrFct(void * const Handle_p, void * const Address_p)
  64. {
  65.     ST_ErrorCode_t Err;
  66.     /* just cast the handle */
  67.     Err = STPTI_BufferSetReadPointer((STPTI_Buffer_t)Handle_p,Address_p);
  68.     if ( Err != ST_NO_ERROR )
  69.     {
  70.         STTBX_Print(( "STPTI_BufferSetReadPointer()Failed %sn", KB_ErrorGetText(Err)));
  71.     }
  72.     return;
  73. }
  74. /*-------------------------------------------------------------------------
  75.  * Function : VID_Setup
  76.  * Input    : nothing
  77.  * Output   :
  78.  * Return   : Error Code
  79.  * ----------------------------------------------------------------------*/
  80. ST_ErrorCode_t VID_Setup(void)
  81. {
  82.     ST_ErrorCode_t         ST_ErrorCode;
  83.     STVID_InitParams_t     STVID_InitParams;
  84.     STVID_OpenParams_t     STVID_OpenParams;
  85.     STVID_ViewPortParams_t STVID_ViewPortParams;
  86.     STVID_MemoryProfile_t  STVID_MemoryProfile;
  87.     STVID_DisplayAspectRatioConversion_t STVID_darc = STVID_DISPLAY_AR_CONVERSION_LETTER_BOX;//STVID_DISPLAY_AR_CONVERSION_LETTER_BOX;//STVID_DISPLAY_AR_CONVERSION_PAN_SCAN;
  88.     U8                      Index;
  89.     memset(&STVID_InitParams, 0, sizeof(STVID_InitParams) );    /* clear every parameter */
  90.     STVID_InitParams.DeviceType                   = VID_DEVICE_TYPE;
  91.     STVID_InitParams.BaseAddress_p                = NULL;
  92.     STVID_InitParams.BaseAddress2_p               = (void *) VID_BASE_ADDRESS2;
  93.     STVID_InitParams.BaseAddress3_p               = (void *) VID_BASE_ADDRESS3;
  94.     STVID_InitParams.InstallVideoInterruptHandler = TRUE;
  95.     STVID_InitParams.InterruptNumber              = VIDEO_INTERRUPT;
  96.     STVID_InitParams.InterruptLevel               = VIDEO_INTERRUPT_LEVEL;
  97.     STVID_InitParams.CPUPartition_p               = SystemPartition;
  98.     STVID_InitParams.SharedMemoryBaseAddress_p    = (void*)NULL;
  99.     STVID_InitParams.AVMEMPartition               = g_KBAvmemPartitionHandle[0];
  100.     STVID_InitParams.DeviceBaseAddress_p          = (void *)VIDEO_BASE_ADDRESS;
  101.     STVID_InitParams.BitBufferAllocated           = FALSE;
  102.     STVID_InitParams.BitBufferAddress_p           = NULL;
  103.     STVID_InitParams.BitBufferSize                = 0;
  104.     STVID_InitParams.InterruptEvent               = 0;
  105.     STVID_InitParams.MaxOpen                      = 1;
  106.     STVID_InitParams.UserDataSize                 = 75;
  107.     STVID_InitParams.AVSYNCDriftThreshold         = 0;
  108.     strcpy(STVID_InitParams.InterruptEventName, "EVT" );
  109.     strcpy(STVID_InitParams.EvtHandlerName,     "EVT" );
  110.     strcpy(STVID_InitParams.ClockRecoveryName,  "CLKRV"        );
  111.     for ( Index = 0; Index < VIDEO_USED; Index++ )
  112.     {
  113.         STTBX_Print(("VID_Setup(%s)=", VID_DeviceName_Multiple[Index] ));
  114.         ST_ErrorCode = STVID_Init(VID_DeviceName_Multiple[Index], &STVID_InitParams);
  115.         if (ST_ErrorCode != ST_NO_ERROR)
  116.         {
  117.             STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
  118.             return( ST_ErrorCode );
  119.         }
  120.         STTBX_Print(("%sn", STVID_GetRevision() ));
  121.         STVID_OpenParams.SyncDelay = -(STC_OFFSET);
  122.         STTBX_Print(("VID_Open="));
  123.         ST_ErrorCode = STVID_Open(VID_DeviceName_Multiple[Index], &STVID_OpenParams, &VID_Handle_Multiple[Index]);
  124.         STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
  125.         if (ST_ErrorCode != ST_NO_ERROR)
  126.             return( ST_ErrorCode );
  127.         STVID_MemoryProfile.MaxWidth         = 720;
  128.         STVID_MemoryProfile.MaxHeight        = 576;
  129.         if((KB_VMIX_DEVICE_TYPE == STVMIX_COMPOSITOR_FIELD_COMBINED)||((KB_VMIX_DEVICE_TYPE == STVMIX_COMPOSITOR_FIELD_COMBINED_422)))
  130.             STVID_MemoryProfile.NbFrameStore     = 4;   /* Must be 6 for supporting DVR trickmodes */
  131.         else
  132.             STVID_MemoryProfile.NbFrameStore     = 5;   /* Must be 6 for supporting DVR trickmodes */
  133.         STVID_MemoryProfile.CompressionLevel = STVID_COMPRESSION_LEVEL_NONE;
  134.         STVID_MemoryProfile.DecimationFactor = STVID_DECIMATION_FACTOR_NONE;
  135.         ST_ErrorCode = STVID_SetMemoryProfile(VID_Handle_Multiple[Index], &STVID_MemoryProfile );
  136.         if (ST_ErrorCode != ST_NO_ERROR)
  137.         {
  138.             STTBX_Print(("VID_SetMemoryProfile(%d,%d,%d,%d,%d)=%sn",
  139.                     STVID_MemoryProfile.MaxWidth,
  140.                     STVID_MemoryProfile.MaxHeight,
  141.                     STVID_MemoryProfile.NbFrameStore,
  142.                     STVID_MemoryProfile.CompressionLevel,
  143.                     STVID_MemoryProfile.DecimationFactor, KB_ErrorGetText(ST_ErrorCode) ));
  144.             return( ST_ErrorCode );
  145.         }
  146.         memset(&STVID_ViewPortParams, 0, sizeof(STVID_ViewPortParams));
  147.         /* Connect layer to mixer */
  148.         strcpy(STVID_ViewPortParams.LayerName, g_KB_LayerDeviceName[Index] );
  149.         STTBX_Print(("VID_OpenViewPort(%s,%s)=", VID_DeviceName_Multiple[Index], g_KB_LayerDeviceName[Index] ));
  150.         ST_ErrorCode = STVID_OpenViewPort(VID_Handle_Multiple[Index], &STVID_ViewPortParams, &VID_ViewPortHandle_Multiple[Index] );
  151.         STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
  152.         if (ST_ErrorCode != ST_NO_ERROR)
  153.             return( ST_ErrorCode );
  154.         ST_ErrorCode = STVID_SetDisplayAspectRatioConversion(VID_ViewPortHandle_Multiple[Index], STVID_darc);
  155.         if (ST_ErrorCode != ST_NO_ERROR)
  156.         {
  157.             STTBX_Print(("VID_SetDisplayAspectRatioConversion()=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  158.         }
  159.         ST_ErrorCode = STVID_EnableOutputWindow(VID_ViewPortHandle_Multiple[Index]);
  160.         if (ST_ErrorCode != ST_NO_ERROR)
  161.         {
  162.             STTBX_Print(("VID_EnableOutputindow()=%sn", KB_ErrorGetText(ST_ErrorCode) ));
  163.         }
  164.         /* Link corresponding Video and PTI */
  165.         STTBX_Print(("VID_Link(%d,%d)=", Index, Index));
  166.         ST_ErrorCode = VID_Link(Index, Index);
  167.         STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode)));
  168.         if (ST_ErrorCode != ST_NO_ERROR)
  169.             return( ST_ErrorCode );
  170.     }
  171.     return ( ST_ErrorCode );
  172. }
  173. /*-------------------------------------------------------------------------
  174.  * Function : VID_Link
  175.  *            Link the correspoding PTI to Video
  176.  * Input    :
  177.  * Output   :
  178.  * Return   : ErrorCode
  179.  * ----------------------------------------------------------------------*/
  180. ST_ErrorCode_t VID_Link(U32 VidInst, U32 PTIInst)
  181. {
  182.     ST_ErrorCode_t ST_ErrorCode;
  183.     void*          Video_PESBufferAdd_p;
  184.     U32            Video_PESBufferSize;
  185.     ST_ErrorCode = STVID_GetDataInputBufferParams(VID_Handle_Multiple[VidInst],&Video_PESBufferAdd_p,&Video_PESBufferSize);
  186.     if (ST_ErrorCode != ST_NO_ERROR)
  187.     {
  188.         STTBX_Print (("VID_GetDataInputBufferParams=%sn",KB_ErrorGetText(ST_ErrorCode)));
  189.         return(ST_ErrorCode);
  190.     }
  191.     ST_ErrorCode = STPTI_BufferAllocateManual(  g_KB_PTIHandleMultiple[PTIInst],
  192.                                                 Video_PESBufferAdd_p, Video_PESBufferSize,
  193.                                                 1, &PTI_VideoBufferHandle_Multiple[PTIInst]);
  194.     if (ST_ErrorCode != ST_NO_ERROR)
  195.     {
  196.         STTBX_Print (("PTI_BufferAllocateManual=%sn",KB_ErrorGetText(ST_ErrorCode)));
  197.         return(ST_ErrorCode);
  198.     }
  199.     /* No cd-fifo: Initialise the link between pti and video */
  200.     ST_ErrorCode = STPTI_SlotLinkToBuffer(PTI_SlotHandle_Multiple[PTIInst][SLOTVID], PTI_VideoBufferHandle_Multiple[PTIInst]);
  201.     if (ST_ErrorCode != ST_NO_ERROR)
  202.     {
  203.         STTBX_Print (("PTI_SlotLinkToBuffer=%sn",KB_ErrorGetText(ST_ErrorCode)));
  204.         return(ST_ErrorCode);
  205.     }
  206.     ST_ErrorCode = STPTI_BufferSetOverflowControl(PTI_VideoBufferHandle_Multiple[PTIInst], TRUE);
  207.     if (ST_ErrorCode != ST_NO_ERROR)
  208.     {
  209.         STTBX_Print (("PTI_BufferSetOverflowControl=%sn",KB_ErrorGetText(ST_ErrorCode)));
  210.         return(ST_ErrorCode);
  211.     }
  212.     ST_ErrorCode = STVID_SetDataInputInterface( VID_Handle_Multiple[VidInst],
  213.                                                 GetWritePtrFct, SetReadPtrFct,
  214.                                                 (void * const)PTI_VideoBufferHandle_Multiple[PTIInst]);
  215.     if (ST_ErrorCode != ST_NO_ERROR)
  216.     {
  217.         STTBX_Print (("VID_SetDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
  218.         return(ST_ErrorCode);
  219.     }
  220.     return (ST_ErrorCode);
  221. }
  222. /*-------------------------------------------------------------------------
  223.  * Function : VID_Unlink
  224.  *            Unlink the correspoding PTI to Video
  225.  * Input    :
  226.  * Output   :
  227.  * Return   : ErrorCode
  228.  * ----------------------------------------------------------------------*/
  229. ST_ErrorCode_t VID_Unlink(U32 VidInst, U32 PTIInst)
  230. {
  231.     ST_ErrorCode_t ST_ErrorCode;
  232.     ST_ErrorCode = STVID_DeleteDataInputInterface( VID_Handle_Multiple[VidInst] );
  233.     if (ST_ErrorCode != ST_NO_ERROR)
  234.     {
  235.         STTBX_Print (("VID_DeleteDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
  236.         return(ST_ErrorCode);
  237.     }
  238.     ST_ErrorCode = STPTI_BufferFlush(PTI_VideoBufferHandle_Multiple[PTIInst]);
  239.     if (ST_ErrorCode != ST_NO_ERROR)
  240.     {
  241.         STTBX_Print (("PTI_BufferFlush=%sn",KB_ErrorGetText(ST_ErrorCode)));
  242.         return(ST_ErrorCode);
  243.     }
  244.     ST_ErrorCode = STPTI_SlotUnLink(PTI_SlotHandle_Multiple[PTIInst][SLOTVID]);
  245.     if (ST_ErrorCode != ST_NO_ERROR)
  246.     {
  247.         STTBX_Print (("PTI_SlotUnLink=%sn",KB_ErrorGetText(ST_ErrorCode)));
  248.         return(ST_ErrorCode);
  249.     }
  250.     ST_ErrorCode = STPTI_BufferDeallocate(PTI_VideoBufferHandle_Multiple[PTIInst]);
  251.     if (ST_ErrorCode != ST_NO_ERROR)
  252.     {
  253.         STTBX_Print (("PTI_BufferDeallocate=%sn",KB_ErrorGetText(ST_ErrorCode)));
  254.         return(ST_ErrorCode);
  255.     }
  256.     return (ST_ErrorCode);
  257. }
  258. /*-------------------------------------------------------------------------
  259.  * Function : VID_Start
  260.  *            Start Decoding Video
  261.  * Input    :
  262.  * Output   :
  263.  * Return   : ErrorCode
  264.  * ----------------------------------------------------------------------*/
  265. ST_ErrorCode_t VID_Start(STVID_StartParams_t *STVID_StartParams_p)
  266. {
  267.     ST_ErrorCode_t ST_ErrorCode;
  268.     ST_ErrorCode = STVID_Start(VID_Handle_Multiple[NUM_INSTANCE], STVID_StartParams_p);
  269.     STTBX_Print(("STVID_Start(%d,%d,%d,%d,%d)=%sn",
  270.             STVID_StartParams_p->RealTime,      STVID_StartParams_p->UpdateDisplay,
  271.             STVID_StartParams_p->StreamType,    STVID_StartParams_p->StreamID,
  272.             STVID_StartParams_p->BrdCstProfile, KB_ErrorGetText(ST_ErrorCode) ));
  273.     return ( ST_ErrorCode );
  274. }
  275. /*-------------------------------------------------------------------------
  276.  * Function : VID_ChangeAspectRatio
  277.  *            Change the layer parameters to set the aspect ratio.
  278.  * Input    :
  279.  * Output   :
  280.  * Return   : ErrorCode
  281.  * ----------------------------------------------------------------------*/
  282. ST_ErrorCode_t VID_ChangeAspectRatio(STGXOBJ_AspectRatio_t *Aspect_p)
  283. {
  284.     ST_ErrorCode_t        ST_ErrorCode;
  285.     STVMIX_ScreenParams_t ScreenParams;
  286.     STLAYER_LayerParams_t LayerParams;
  287.     ST_ErrorCode = STLAYER_GetLayerParams(g_KB_LayerHandle[LAYER_VIDEO], &LayerParams);
  288.     if (ST_ErrorCode != ST_NO_ERROR)
  289.         return ST_ErrorCode;
  290.     ST_ErrorCode = STVMIX_GetScreenParams(g_KB_VmixHandle, &ScreenParams);
  291.     if (ST_ErrorCode != ST_NO_ERROR)
  292.         return ST_ErrorCode;
  293.     LayerParams.AspectRatio  = *Aspect_p;
  294.     ScreenParams.AspectRatio = *Aspect_p;
  295.     ST_ErrorCode = STLAYER_SetLayerParams(g_KB_LayerHandle[LAYER_VIDEO], &LayerParams);
  296.     if (ST_ErrorCode != ST_NO_ERROR)
  297.         return ST_ErrorCode;
  298.     ST_ErrorCode = STVMIX_SetScreenParams(g_KB_VmixHandle, &ScreenParams);
  299.     return ST_ErrorCode;
  300. }
  301. /*-------------------------------------------------------------------------
  302.  * Function : VID_ChangeScanType
  303.  *            Change the layer parameters to set the scan type
  304.  * Input    :
  305.  * Output   :
  306.  * Return   : ErrorCode
  307.  * ----------------------------------------------------------------------*/
  308. ST_ErrorCode_t VID_ChangeScanType(STVID_ScanType_t *ScanType_p)
  309. {
  310.     ST_ErrorCode_t        ST_ErrorCode;
  311.     STVMIX_ScreenParams_t ScreenParams;
  312.     STLAYER_LayerParams_t LayerParams;
  313.     ST_ErrorCode = STLAYER_GetLayerParams(g_KB_LayerHandle[LAYER_VIDEO], &LayerParams);
  314.     if (ST_ErrorCode != ST_NO_ERROR)
  315.         return ST_ErrorCode;
  316.     ST_ErrorCode = STVMIX_GetScreenParams(g_KB_VmixHandle, &ScreenParams);
  317.     if (ST_ErrorCode != ST_NO_ERROR)
  318.         return ST_ErrorCode;
  319.     if (*ScanType_p == STVID_SCAN_TYPE_PROGRESSIVE)
  320.     {
  321.         LayerParams.ScanType = STGXOBJ_PROGRESSIVE_SCAN;
  322.         ScreenParams.ScanType = STGXOBJ_PROGRESSIVE_SCAN;
  323.     }
  324.     else if (*ScanType_p == STVID_SCAN_TYPE_INTERLACED)
  325.     {
  326.         LayerParams.ScanType = STGXOBJ_INTERLACED_SCAN;
  327.         ScreenParams.ScanType = STGXOBJ_INTERLACED_SCAN;
  328.     }
  329.     else
  330.     {
  331.         ST_ErrorCode = ST_ERROR_BAD_PARAMETER;
  332.         return ST_ErrorCode;
  333.     }
  334.     ST_ErrorCode = STLAYER_SetLayerParams(g_KB_LayerHandle[LAYER_VIDEO], &LayerParams);
  335.     if (ST_ErrorCode != ST_NO_ERROR)
  336.         return ST_ErrorCode;
  337.     ST_ErrorCode = STVMIX_SetScreenParams(g_KB_VmixHandle, &ScreenParams);
  338.     return ST_ErrorCode;
  339. }
  340. /* EOF --------------------------------------------------------------------- */