avslot.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:7k
- #include <string.h>
- #include "stevt.h"
- #include "stsys.h"
- #include "stcommon.h"
- #include "stpti.h"
- #include "errors.h"
- #include "osp.h"
- #include "stpti_hal.h"
- #include "avslot.h"
- /*********************** Use for video, audio and pcr slot *********************/
- STPTI_Slot_t PTI_SlotHandle_Multiple[KB_PTI_MAX_NUM][NUM_PTI_SLOTS];
- /* Keep audio and video buffer handle */
- STPTI_Buffer_t PTI_AudioBufferHandle, PTI_VideoBufferHandle_Multiple[KB_PTI_MAX_NUM];
- const STPTI_SlotType_t STPTI_AVSlotTypes[] =
- {
- STPTI_SLOT_TYPE_PES, /* VIDEO */
- STPTI_SLOT_TYPE_PES, /* AUDIO */
- STPTI_SLOT_TYPE_PCR, /* PCR */
- };
- /* For each slot we need to keep this information */
- typedef struct Pti_SlotKeepInfo_s
- {
- STPTI_Slot_t SlotHandle; /* Slot handle */
- STPTI_Pid_t Pid; /* PID */
- STPTI_Filter_t FilterHandle; /* Filter handle */
- STPTI_Buffer_t BufferHandle; /* PTI Destination Buffer handle */
- U32 BufferSize; /* PTI Destination Buffer size */
- STPTI_Signal_t SignalHandle; /* PTI Destination Signal handle */
- U8 *UserBuffer_p; /* User Buffer */
- U32 UserBufferSize; /* User Buffer */
- BOOL InUse; /* In use ? */
- } Pti_SlotKeepInfo_t;
- Pti_SlotKeepInfo_t Pti_SlotKeepInfo[NUM_PTI_SLOTS];
- /* Semaphore to ensure correct multi thread */
- static BOOL pti_SemInit = FALSE;
- static UINT32 pti_SemLock;
- /*-----------------------------------------------------------------------------
- * Function : PTI_Protect
- * Protect by semaphore shared data
- * Do the initialisation if needed.
- * Input : N/A
- * Output : N/A
- * Return : ErrCode
- * -------------------------------------------------------------------------- */
- static ST_ErrorCode_t PTI_Protect(void)
- {
- /* First check if init of the semaphore is already done */
- if (pti_SemInit == FALSE)
- {
- /* Init the semaphore to 1 and wait on the semaphore is the same as */
- /* setting directly the semaphore to 0. */
- KB_OSPSemInit("DMXS", 0, J_OSP_WAIT_FIFO, &pti_SemLock);
- /* We are now in critical section */
- pti_SemInit = TRUE;
- }
- else
- {
- KB_OSPSemGet(pti_SemLock, KB_Wait, 0);
- }
- return ST_NO_ERROR;
- } /* PTI_Proctect */
- /*------------------------------------------------------------------------------
- * Function : PTI_UnProtect
- * Protect by semaphore shared data
- * Input : N/A
- * Output : N/A
- * Return : ErrCode
- * -------------------------------------------------------------------------- */
- static ST_ErrorCode_t PTI_UnProtect(void)
- {
- /* Wake up locked task on semaphore (if any) */
- KB_OSPSemSet(pti_SemLock);
- return ST_NO_ERROR;
- } /* PTI_UnProctect */
- ST_ErrorCode_t AVSlotInit(void)
- {
- STPTI_SlotData_t STPTI_SlotData;
- int pti_slot;
- ST_ErrorCode_t ST_ErrorCode = ST_NO_ERROR;
-
- //Allocate Video, Audio and PCR slot
- for (pti_slot = SLOTVID; pti_slot < NUM_PTI_SLOTS; pti_slot++)
- {
- STPTI_SlotData.SlotType = STPTI_AVSlotTypes[pti_slot];
- STPTI_SlotData.SlotFlags.SignalOnEveryTransportPacket = FALSE;
- STPTI_SlotData.SlotFlags.CollectForAlternateOutputOnly = FALSE;
- STPTI_SlotData.SlotFlags.AlternateOutputInjectCarouselPacket = FALSE;
- STPTI_SlotData.SlotFlags.StoreLastTSHeader = FALSE;
- STPTI_SlotData.SlotFlags.InsertSequenceError = FALSE;
- STPTI_SlotData.SlotFlags.OutPesWithoutMetadata = FALSE;
- STPTI_SlotData.SlotFlags.ForcePesLengthToZero = FALSE;
- STPTI_SlotData.SlotFlags.AppendSyncBytePrefixToRawData = FALSE;
- if (pti_slot == SLOTVID || pti_slot == SLOTAUD)
- {
- STPTI_SlotData.SlotFlags.SoftwareCDFifo = TRUE; /*Should be set to TRUE for 5105 device type*/
- }
- else
- {
- STPTI_SlotData.SlotFlags.SoftwareCDFifo = FALSE;
- }
- /* Allocates free slots */
- ST_ErrorCode = STPTI_SlotAllocate( g_KB_PTIHandleMultiple[0],
- &PTI_SlotHandle[pti_slot],
- &STPTI_SlotData);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- //STTBX_Print((" ***PTI_SlotAllocate(%d)=%s %08X *** ", pti_slot, KB_ErrorGetText(ST_ErrorCode), ST_ErrorCode ));
- return( ST_ErrorCode );
- }
- /* Clears slot PID */
- ST_ErrorCode = STPTI_SlotClearPid(PTI_SlotHandle[pti_slot]);
- if (ST_ErrorCode != ST_NO_ERROR)
- {
- //STTBX_Print((" ***PTI_SlotClearPid(%d)=%s*** ", pti_slot, KB_ErrorGetText(ST_ErrorCode) ));
- return( ST_ErrorCode );
- }
- }
- return( ST_ErrorCode );
- }
- UINT32 StartAud(UINT16 AudioPid)
- {
- ST_ErrorCode_t ST_ErrorCode;
- ST_ErrorCode = STPTI_SlotSetPid(PTI_SlotHandle[SLOTAUD], AudioPid);
- if(ST_ErrorCode != ST_NO_ERROR) //no harm doing again
- {
- ST_ErrorCode = STPTI_SlotClearPid(PTI_SlotHandle[SLOTAUD]);
- ST_ErrorCode |= STPTI_SlotSetPid(PTI_SlotHandle[SLOTAUD], AudioPid);
- if(ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("nn 2x STPTI_SlotSetPid(SLOTAUD,%d)=%snn", AudioPid, KB_ErrorGetText(ST_ErrorCode) ));
- }
- }
- return ST_ErrorCode;
- }
- UINT32 StopAud(void)
- {
- ST_ErrorCode_t ErrCode;
- /* Enter Critical section */
- PTI_Protect();
- ErrCode = STPTI_SlotClearPid(PTI_SlotHandle[SLOTAUD]);
- /* Leave Critical section */
- PTI_UnProtect();
- return ( ErrCode );
- }
- UINT32 StartVid(UINT16 VideoPid)
- {
- ST_ErrorCode_t ST_ErrorCode;
- ST_ErrorCode = STPTI_SlotSetPid(PTI_SlotHandle[SLOTVID], VideoPid);
- if(ST_ErrorCode != ST_NO_ERROR) //no harm doing again
- {
- ST_ErrorCode = STPTI_SlotClearPid(PTI_SlotHandle[SLOTVID]);
- ST_ErrorCode |= STPTI_SlotSetPid(PTI_SlotHandle[SLOTVID], VideoPid);
- if(ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("nn 2x STPTI_SlotSetPid(SLOTVID,%d)=%snn", VideoPid, KB_ErrorGetText(ST_ErrorCode) ));
- }
- }
- return ST_ErrorCode;
- }
- UINT32 StopVid(void)
- {
- ST_ErrorCode_t ErrCode;
- ErrCode = STPTI_SlotClearPid(PTI_SlotHandle[SLOTVID]);
- return ErrCode;
- }
- UINT32 StartPCR(UINT16 PCRPid)
- {
- ST_ErrorCode_t ST_ErrorCode;
- /* Enter Critical section */
- PTI_Protect();
- ST_ErrorCode = STPTI_SlotSetPid(PTI_SlotHandle[SLOTPCR], PCRPid);
- if(ST_ErrorCode != ST_NO_ERROR) //no harm doing again
- {
- ST_ErrorCode = STPTI_SlotClearPid(PTI_SlotHandle[SLOTPCR]);
- ST_ErrorCode |= STPTI_SlotSetPid(PTI_SlotHandle[SLOTPCR], PCRPid);
- if(ST_ErrorCode != ST_NO_ERROR)
- {
- STTBX_Print(("nn 2x STPTI_SlotSetPid(SLOTAUD,%d)=%snn", PCRPid, KB_ErrorGetText(ST_ErrorCode) ));
- }
- }
-
- /* Leave Critical section */
- PTI_UnProtect();
- return ST_ErrorCode;
-
- }
- UINT32 StopPCR(void)
- {
- ST_ErrorCode_t ErrCode;
- /* Enter Critical section */
- PTI_Protect();
- ErrCode = STPTI_SlotClearPid(PTI_SlotHandle[SLOTPCR]);
- /* Leave Critical section */
- PTI_UnProtect();
- return ( ErrCode );
- }