vid.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:16k
- /*****************************************************************************
- File name: vid.c
- Description: STVID interface
- COPYRIGHT (C) 2004 STMicroelectronics
- *****************************************************************************/
- /* Includes --------------------------------------------------------------- */
- #include <string.h>
- #include <stdio.h>
- #include "stddefs.h"
- #include "stlite.h"
- #include "stdevice.h"
- #include "stsys.h"
- #include "stvid.h"
- #include "sttbx.h"
- #include "section.h" /* memory partitions */
- #include "errors.h"
- #include "evt.h"
- #include "avmem.h"
- #include "clkrv.h"
- #include "layer.h"
- #include "vtg.h"
- #include "vid.h"
- #include "vmix.h"
- #include "stpti_hal.h"
- #include "avslot.h"
- /* Private Types ------------------------------------------------------ */
- /* Private Constants -------------------------------------------------- */
- #define NUM_INSTANCE 0
- /* Private Variables -------------------------------------------------- */
- /* Private Macros ----------------------------------------------------- */
- /* Private Function prototypes ---------------------------------------- */
- /* Global Variables ------------------------------------------------------- */
- STVID_ViewPortHandle_t VID_ViewPortHandle_Multiple[VIDEO_USED];
- STVID_Handle_t VID_Handle_Multiple[VIDEO_USED];
- #if (VIDEO_USED==2)
- ST_DeviceName_t VID_DeviceName_Multiple[VIDEO_USED] = { "VID", "AUX_VID" };
- #else
- ST_DeviceName_t VID_DeviceName_Multiple[VIDEO_USED] = { "VID" };
- #endif
- /* Functions ---------------------------------------------------------- */
- /* INTERFACE OBJECT: WRAPPER FCT TO LINK PTI AND VIDEO */
- /*-------------------------------------------------------------------------
- * Function: GetWritePtrFct
- * Decription: Gets the PES Buffer Write Pointer from PTI
- * Input : PTI Buffer Handle
- * Output :
- * Return : Error code and the Video Input Buffer Address
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t GetWritePtrFct(void * const Handle_p, void ** const Address_p)
- {
- ST_ErrorCode_t Err;
- /* just cast the handle */
- Err = STPTI_BufferGetWritePointer((STPTI_Buffer_t)Handle_p,Address_p);
- return(Err);
- }
- /*-------------------------------------------------------------------------
- * Function: SetReadPtrFct
- * Decription: Sets the PTI Read Pointer.
- * Input : PTI Buffer Handle and the Video Buffer Address
- * Output :
- * Return : Error code
- * ----------------------------------------------------------------------*/
- void SetReadPtrFct(void * const Handle_p, void * const Address_p)
- {
- ST_ErrorCode_t Err;
- /* just cast the handle */
- Err = STPTI_BufferSetReadPointer((STPTI_Buffer_t)Handle_p,Address_p);
- if ( Err != ST_NO_ERROR )
- {
- STTBX_Print(( "STPTI_BufferSetReadPointer()Failed %sn", KB_ErrorGetText(Err)));
- }
- return;
- }
- /*-------------------------------------------------------------------------
- * Function : VID_Setup
- * Input : nothing
- * Output :
- * Return : Error Code
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t VID_Setup(void)
- {
- ST_ErrorCode_t ST_ErrorCode;
- STVID_InitParams_t STVID_InitParams;
- STVID_OpenParams_t STVID_OpenParams;
- STVID_ViewPortParams_t STVID_ViewPortParams;
- STVID_MemoryProfile_t STVID_MemoryProfile;
- STVID_DisplayAspectRatioConversion_t STVID_darc = STVID_DISPLAY_AR_CONVERSION_LETTER_BOX;//STVID_DISPLAY_AR_CONVERSION_LETTER_BOX;//STVID_DISPLAY_AR_CONVERSION_PAN_SCAN;
- U8 Index;
- memset(&STVID_InitParams, 0, sizeof(STVID_InitParams) ); /* clear every parameter */
- STVID_InitParams.DeviceType = VID_DEVICE_TYPE;
- STVID_InitParams.BaseAddress_p = NULL;
- STVID_InitParams.BaseAddress2_p = (void *) VID_BASE_ADDRESS2;
- STVID_InitParams.BaseAddress3_p = (void *) VID_BASE_ADDRESS3;
- STVID_InitParams.InstallVideoInterruptHandler = TRUE;
- STVID_InitParams.InterruptNumber = VIDEO_INTERRUPT;
- STVID_InitParams.InterruptLevel = VIDEO_INTERRUPT_LEVEL;
- STVID_InitParams.CPUPartition_p = SystemPartition;
- STVID_InitParams.SharedMemoryBaseAddress_p = (void*)NULL;
- STVID_InitParams.AVMEMPartition = g_KBAvmemPartitionHandle[0];
- STVID_InitParams.DeviceBaseAddress_p = (void *)VIDEO_BASE_ADDRESS;
- STVID_InitParams.BitBufferAllocated = FALSE;
- STVID_InitParams.BitBufferAddress_p = NULL;
- STVID_InitParams.BitBufferSize = 0;
- STVID_InitParams.InterruptEvent = 0;
- STVID_InitParams.MaxOpen = 1;
- STVID_InitParams.UserDataSize = 75;
- STVID_InitParams.AVSYNCDriftThreshold = 0;
- strcpy(STVID_InitParams.InterruptEventName, "EVT" );
- strcpy(STVID_InitParams.EvtHandlerName, "EVT" );
- strcpy(STVID_InitParams.ClockRecoveryName, "CLKRV" );
- for ( Index = 0; Index < VIDEO_USED; Index++ )
- {
- STTBX_Print(("VID_Setup(%s)=", VID_DeviceName_Multiple[Index] ));
- ST_ErrorCode = STVID_Init(VID_DeviceName_Multiple[Index], &STVID_InitParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
- return( ST_ErrorCode );
- }
- STTBX_Print(("%sn", STVID_GetRevision() ));
- STVID_OpenParams.SyncDelay = -(STC_OFFSET);
- STTBX_Print(("VID_Open="));
- ST_ErrorCode = STVID_Open(VID_DeviceName_Multiple[Index], &STVID_OpenParams, &VID_Handle_Multiple[Index]);
- STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
- if (ST_ErrorCode != ST_NO_ERROR)
- return( ST_ErrorCode );
- STVID_MemoryProfile.MaxWidth = 720;
- STVID_MemoryProfile.MaxHeight = 576;
- if((KB_VMIX_DEVICE_TYPE == STVMIX_COMPOSITOR_FIELD_COMBINED)||((KB_VMIX_DEVICE_TYPE == STVMIX_COMPOSITOR_FIELD_COMBINED_422)))
- STVID_MemoryProfile.NbFrameStore = 4; /* Must be 6 for supporting DVR trickmodes */
- else
- STVID_MemoryProfile.NbFrameStore = 5; /* Must be 6 for supporting DVR trickmodes */
- STVID_MemoryProfile.CompressionLevel = STVID_COMPRESSION_LEVEL_NONE;
- STVID_MemoryProfile.DecimationFactor = STVID_DECIMATION_FACTOR_NONE;
- ST_ErrorCode = STVID_SetMemoryProfile(VID_Handle_Multiple[Index], &STVID_MemoryProfile );
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("VID_SetMemoryProfile(%d,%d,%d,%d,%d)=%sn",
- STVID_MemoryProfile.MaxWidth,
- STVID_MemoryProfile.MaxHeight,
- STVID_MemoryProfile.NbFrameStore,
- STVID_MemoryProfile.CompressionLevel,
- STVID_MemoryProfile.DecimationFactor, KB_ErrorGetText(ST_ErrorCode) ));
- return( ST_ErrorCode );
- }
- memset(&STVID_ViewPortParams, 0, sizeof(STVID_ViewPortParams));
- /* Connect layer to mixer */
- strcpy(STVID_ViewPortParams.LayerName, g_KB_LayerDeviceName[Index] );
- STTBX_Print(("VID_OpenViewPort(%s,%s)=", VID_DeviceName_Multiple[Index], g_KB_LayerDeviceName[Index] ));
- ST_ErrorCode = STVID_OpenViewPort(VID_Handle_Multiple[Index], &STVID_ViewPortParams, &VID_ViewPortHandle_Multiple[Index] );
- STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode) ));
- if (ST_ErrorCode != ST_NO_ERROR)
- return( ST_ErrorCode );
- ST_ErrorCode = STVID_SetDisplayAspectRatioConversion(VID_ViewPortHandle_Multiple[Index], STVID_darc);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("VID_SetDisplayAspectRatioConversion()=%sn", KB_ErrorGetText(ST_ErrorCode) ));
- }
- ST_ErrorCode = STVID_EnableOutputWindow(VID_ViewPortHandle_Multiple[Index]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("VID_EnableOutputindow()=%sn", KB_ErrorGetText(ST_ErrorCode) ));
- }
- /* Link corresponding Video and PTI */
- STTBX_Print(("VID_Link(%d,%d)=", Index, Index));
- ST_ErrorCode = VID_Link(Index, Index);
- STTBX_Print(("%sn", KB_ErrorGetText(ST_ErrorCode)));
- if (ST_ErrorCode != ST_NO_ERROR)
- return( ST_ErrorCode );
- }
- return ( ST_ErrorCode );
- }
- /*-------------------------------------------------------------------------
- * Function : VID_Link
- * Link the correspoding PTI to Video
- * Input :
- * Output :
- * Return : ErrorCode
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t VID_Link(U32 VidInst, U32 PTIInst)
- {
- ST_ErrorCode_t ST_ErrorCode;
- void* Video_PESBufferAdd_p;
- U32 Video_PESBufferSize;
- ST_ErrorCode = STVID_GetDataInputBufferParams(VID_Handle_Multiple[VidInst],&Video_PESBufferAdd_p,&Video_PESBufferSize);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("VID_GetDataInputBufferParams=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STPTI_BufferAllocateManual( g_KB_PTIHandleMultiple[PTIInst],
- Video_PESBufferAdd_p, Video_PESBufferSize,
- 1, &PTI_VideoBufferHandle_Multiple[PTIInst]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_BufferAllocateManual=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- /* No cd-fifo: Initialise the link between pti and video */
- ST_ErrorCode = STPTI_SlotLinkToBuffer(PTI_SlotHandle_Multiple[PTIInst][SLOTVID], PTI_VideoBufferHandle_Multiple[PTIInst]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_SlotLinkToBuffer=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STPTI_BufferSetOverflowControl(PTI_VideoBufferHandle_Multiple[PTIInst], TRUE);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_BufferSetOverflowControl=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STVID_SetDataInputInterface( VID_Handle_Multiple[VidInst],
- GetWritePtrFct, SetReadPtrFct,
- (void * const)PTI_VideoBufferHandle_Multiple[PTIInst]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("VID_SetDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- return (ST_ErrorCode);
- }
- /*-------------------------------------------------------------------------
- * Function : VID_Unlink
- * Unlink the correspoding PTI to Video
- * Input :
- * Output :
- * Return : ErrorCode
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t VID_Unlink(U32 VidInst, U32 PTIInst)
- {
- ST_ErrorCode_t ST_ErrorCode;
- ST_ErrorCode = STVID_DeleteDataInputInterface( VID_Handle_Multiple[VidInst] );
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("VID_DeleteDataInputInterface=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STPTI_BufferFlush(PTI_VideoBufferHandle_Multiple[PTIInst]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_BufferFlush=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STPTI_SlotUnLink(PTI_SlotHandle_Multiple[PTIInst][SLOTVID]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_SlotUnLink=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- ST_ErrorCode = STPTI_BufferDeallocate(PTI_VideoBufferHandle_Multiple[PTIInst]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print (("PTI_BufferDeallocate=%sn",KB_ErrorGetText(ST_ErrorCode)));
- return(ST_ErrorCode);
- }
- return (ST_ErrorCode);
- }
- /*-------------------------------------------------------------------------
- * Function : VID_Start
- * Start Decoding Video
- * Input :
- * Output :
- * Return : ErrorCode
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t VID_Start(STVID_StartParams_t *STVID_StartParams_p)
- {
- ST_ErrorCode_t ST_ErrorCode;
- ST_ErrorCode = STVID_Start(VID_Handle_Multiple[NUM_INSTANCE], STVID_StartParams_p);
- STTBX_Print(("STVID_Start(%d,%d,%d,%d,%d)=%sn",
- STVID_StartParams_p->RealTime, STVID_StartParams_p->UpdateDisplay,
- STVID_StartParams_p->StreamType, STVID_StartParams_p->StreamID,
- STVID_StartParams_p->BrdCstProfile, KB_ErrorGetText(ST_ErrorCode) ));
- return ( ST_ErrorCode );
- }
- /*-------------------------------------------------------------------------
- * Function : VID_ChangeAspectRatio
- * Change the layer parameters to set the aspect ratio.
- * Input :
- * Output :
- * Return : ErrorCode
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t VID_ChangeAspectRatio(STGXOBJ_AspectRatio_t *Aspect_p)
- {
- ST_ErrorCode_t ST_ErrorCode;
- STVMIX_ScreenParams_t ScreenParams;
- STLAYER_LayerParams_t LayerParams;
- ST_ErrorCode = STLAYER_GetLayerParams(g_KB_LayerHandle[LAYER_VIDEO], &LayerParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- return ST_ErrorCode;
- ST_ErrorCode = STVMIX_GetScreenParams(g_KB_VmixHandle, &ScreenParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- return ST_ErrorCode;
- LayerParams.AspectRatio = *Aspect_p;
- ScreenParams.AspectRatio = *Aspect_p;
- ST_ErrorCode = STLAYER_SetLayerParams(g_KB_LayerHandle[LAYER_VIDEO], &LayerParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- return ST_ErrorCode;
- ST_ErrorCode = STVMIX_SetScreenParams(g_KB_VmixHandle, &ScreenParams);
- return ST_ErrorCode;
- }
- /*-------------------------------------------------------------------------
- * Function : VID_ChangeScanType
- * Change the layer parameters to set the scan type
- * Input :
- * Output :
- * Return : ErrorCode
- * ----------------------------------------------------------------------*/
- ST_ErrorCode_t VID_ChangeScanType(STVID_ScanType_t *ScanType_p)
- {
- ST_ErrorCode_t ST_ErrorCode;
- STVMIX_ScreenParams_t ScreenParams;
- STLAYER_LayerParams_t LayerParams;
- ST_ErrorCode = STLAYER_GetLayerParams(g_KB_LayerHandle[LAYER_VIDEO], &LayerParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- return ST_ErrorCode;
- ST_ErrorCode = STVMIX_GetScreenParams(g_KB_VmixHandle, &ScreenParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- return ST_ErrorCode;
- if (*ScanType_p == STVID_SCAN_TYPE_PROGRESSIVE)
- {
- LayerParams.ScanType = STGXOBJ_PROGRESSIVE_SCAN;
- ScreenParams.ScanType = STGXOBJ_PROGRESSIVE_SCAN;
- }
- else if (*ScanType_p == STVID_SCAN_TYPE_INTERLACED)
- {
- LayerParams.ScanType = STGXOBJ_INTERLACED_SCAN;
- ScreenParams.ScanType = STGXOBJ_INTERLACED_SCAN;
- }
- else
- {
- ST_ErrorCode = ST_ERROR_BAD_PARAMETER;
- return ST_ErrorCode;
- }
- ST_ErrorCode = STLAYER_SetLayerParams(g_KB_LayerHandle[LAYER_VIDEO], &LayerParams);
- if (ST_ErrorCode != ST_NO_ERROR)
- return ST_ErrorCode;
- ST_ErrorCode = STVMIX_SetScreenParams(g_KB_VmixHandle, &ScreenParams);
- return ST_ErrorCode;
- }
- /* EOF --------------------------------------------------------------------- */