📄 dvb_filt.c
字号:
/*! \fn bool8 DVB_FilterForceToGetSection (u8 u8FID, u8* pu8Section, u16 u16MaxLength)
\brief Force to get section in section buffer of some filter if possible.
\param u8FID (Input) get section from which circular buffer.
\param pu8Section (Input) a point to section buffer.
\param u16MaxLength (Input) max length of receiver buffer.
\return TRUE - got a section.
\return FALSE - no available section or wrong parameters.
*/
bool8 DVB_FilterForceToGetSection (u8 u8FID, u8* pu8Section, u16 u16MaxLength)
{
bool8 b8result = FALSE;
u8 u8Buffer[4];
u16 u16SecLenInByte = 0;
CT_OS_WaitOnSemaphore (&DVBFilterSemaphore, CTOS_WAIT);
if ((u8FID >= MAX_FILTER_NUMBER)
|| (astSectionFilter[u8FID].b8Allocated == FALSE)
|| (pu8Section == NULL))
{
FILT_DBG(( "{dvb_filtergetsection} FAIL u8FID[0x%x] b8Allocated[0x%x]\n",
u8FID, astSectionFilter[u8FID].b8Allocated));
CT_OS_FreeSemaphore (&DVBFilterSemaphore);
return (FALSE);
}
if (CT_FILT_PeekData (astSectionFilter[u8FID].u32SecFltNo, u8Buffer, 4) != DRV_OK)
{
FILT_DBG(( "{DVB_FilterForceToGetSection} call CT_FILT_PeekData FAIL u8FID[0x%x]\n",u8FID));
CT_OS_FreeSemaphore (&DVBFilterSemaphore);
return (FALSE);
}
/* get section length */
u16SecLenInByte = ((u8Buffer[1]&0x0f) << 8);
u16SecLenInByte |= ((u8Buffer[2]&0xff) << 0);
//FILT_DBG( ("u16SecLenInByte[0x%x]\n", u16SecLenInByte));
if (u16SecLenInByte > 0)
{
u16SecLenInByte += 3;
}
else
{
FILT_DBG(("{DVB_FilterForceToGetSection} FAIL total section length = %d \n", (int)u16SecLenInByte));
CT_OS_FreeSemaphore (&DVBFilterSemaphore);
return (FALSE); //<--- Invalid section length
}
if (CT_FILT_GetBufferFullness(astSectionFilter[u8FID].u32SecFltNo) >= u16SecLenInByte)
{
b8result = _filtergetsection (u8FID, pu8Section, u16MaxLength);
}
else
{
}
CT_OS_FreeSemaphore (&DVBFilterSemaphore);
return b8result;
}
/*! \fn u8 DVB_FilterTotalUnusedFilter(void)
\brief Get number of unused filter.
\return number of available filter.
*/
u8 DVB_FilterTotalUnusedFilter(void)
{
// return CT_DEMUX_GetUnusedFilter ();
return 1;
}
static u8 dvb_filteropen (u32 u32UsrBfrSize)
{
u8 u8FID;
u32 u32SecFltNo, u32PidFltNo;
u8* pu8Buffer;
gen_point = 995;
pu8Buffer = DVB_MemoryAllocate(u32UsrBfrSize+1024); // allocate larger buffer size, ct_filter will reduce size for alligment.
if( pu8Buffer==NULL )
return INVALID_FILTER_ID;
// Matt, test only
// CT_DEMUX_SetPreScan(TRUE);
/* alocate a section filter */
u32SecFltNo = CT_FILT_Open ();
if (u32SecFltNo == INVALID_FILT_HANDLE)
{
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} call CT_FILT_Open FAIL u32SecFltNo[0x%x]\n",
u32SecFltNo));
return (INVALID_FILTER_ID);
}
u8FID = (u8) u32SecFltNo;
if (u8FID >= MAX_FILTER_NUMBER)
{
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} FAIL u8FID[0x%x] over\n", u8FID));
return (INVALID_FILTER_ID);
}
if (astSectionFilter[u8FID].b8Allocated == TRUE)
{
CT_FILT_Close (u32SecFltNo);
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} FAIL u8FID[0x%x] already used\n",
u8FID));
return (INVALID_FILTER_ID);
}
/* set request */
if (CT_FILT_SetInterruptRequest (u32SecFltNo, 0, 0) != DRV_OK)
{
CT_FILT_Close (u32SecFltNo);
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} FAIL CT_FILT_SetInterruptRequest u32SecFltNo[0x%x]\n",
u32SecFltNo));
return (INVALID_FILTER_ID);
}
/* set filter type only for section filter */
if (CT_FILT_SetFilterType (u32SecFltNo, FILTER_TYPE_SEC) != DRV_OK)
{
CT_FILT_Close (u32SecFltNo);
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} FAIL CT_FILT_SetFilterType u32SecFltNo[0x%x]\n",
u32SecFltNo));
return (INVALID_FILTER_ID);
}
/* set section filter FIFO ring buffer */
if (CT_FILT_SetBuffer(u32SecFltNo, pu8Buffer, u32UsrBfrSize+1024) != DRV_OK)
{
CT_FILT_Close (u32SecFltNo);
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} FAIL CT_FILT_SetBuffer u32SecFltNo[0x%x]\n",
u32SecFltNo));
return (INVALID_FILTER_ID);
}
/* reset ring buffer */
if (CT_FILT_ResetBuffer (u32SecFltNo) != DRV_OK)
{
CT_FILT_Close (u32SecFltNo);
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} FAIL CT_FILT_ResetBuffer u32SecFltNo[0x%x]\n",
u32SecFltNo));
return (INVALID_FILTER_ID);
}
#if 0 // move to DVB_FilterStart
/* register call back function ,
note that all register the same call back function */
if (CT_FILT_Register (u32SecFltNo, SECTION_RDY_MASK_BIT, DVB_Filter_CallBack, NULL) != DRV_OK)
{
CT_FILT_Close (u32SecFltNo);
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} FAIL CT_FILT_Register u32SecFltNo[0x%x]\n",
u32SecFltNo));
return (INVALID_FILTER_ID);
}
#endif
/* allocate a PID filter */
u32PidFltNo = CT_PF_Open (DEMUX_PID_TYPE_NO_REMAP);
if (u32PidFltNo == INVALID_PIDFILT_HANDLE)
{
CT_FILT_Close (u32SecFltNo);
DVB_MemoryFree(pu8Buffer);
FILT_DBG(( "{dvb_filteropen} FAIL CT_PF_Open u8FID[0x%x]\n", u8FID));
return (INVALID_FILTER_ID);
}
/* reset section filter status */
astSectionFilter[u8FID].u32PidFltNo = u32PidFltNo;
astSectionFilter[u8FID].u32SecFltNo = u32SecFltNo;
astSectionFilter[u8FID].b8OneShot = TRUE;
astSectionFilter[u8FID].pfCallBack = NULL;
astSectionFilter[u8FID].u8AvailableSection = 0;
astSectionFilter[u8FID].b8Running = FALSE;
astSectionFilter[u8FID].u16TimeoutMilliSec = TIMEOUT_INFINITE;
astSectionFilter[u8FID].u32TimerEnd = 0;
astSectionFilter[u8FID].b8Allocated = TRUE;
astSectionFilter[u8FID].pu8RingBufferAddress = pu8Buffer;
//FILT_DBG( ("{dvb_filteropen} u8FID[0x%x]\n",u8FID));
return(u8FID);
}
/*! \fn u8 DVB_FilterOpen (u32 u32UsrBfrSize)
\brief Open a filter to receive section with ring buffer size u32UsrBfrSize.
\return filter ID or INVALID_FILTER_ID when fail.
*/
u8 DVB_FilterOpen (u32 u32UsrBfrSize)
{
u8 u8FID;
CT_OS_WaitOnSemaphore (&DVBFilterSemaphore, CTOS_WAIT);
gen_point = 106;
u8FID = dvb_filteropen (u32UsrBfrSize);
CT_OS_FreeSemaphore (&DVBFilterSemaphore);
//FILT_DBG( ("{DVB_FilterOpen} u8FID[0x%x]\n",u8FID));
return (u8FID);
}
static void dvb_filterclose (u8 u8FID)
{
/* check parameter and status */
if ((u8FID >= MAX_FILTER_NUMBER) || (astSectionFilter[u8FID].b8Allocated == FALSE))
{
FILT_DBG(( "{dvb_filterclose} FAIL u8FID[0x%x] b8Allocated[0x%x]\n",
u8FID, astSectionFilter[u8FID].b8Allocated));
FILT_DBG( ("{dvb_filterclose} FAIL u8FID[0x%x] b8Allocated[0x%x]\n",
u8FID, astSectionFilter[u8FID].b8Allocated));
return;
}
astSectionFilter[u8FID].pfCallBack = NULL;
/* unregister */
CT_FILT_Unregister (astSectionFilter[u8FID].u32SecFltNo);
// CT_Secisr_Unregister(u8FID);
/* stop the setion filter */
dvb_filterstop (u8FID);
/* close PID filter */
CT_PF_Close (astSectionFilter[u8FID].u32PidFltNo);
/* close section filter */
CT_FILT_Close (astSectionFilter[u8FID].u32SecFltNo);
DVB_MemoryFree(astSectionFilter[u8FID].pu8RingBufferAddress);
/* reset the filter status */
astSectionFilter[u8FID].b8Allocated = FALSE;
astSectionFilter[u8FID].u32SecFltNo = INVALID_FILT_HANDLE;
astSectionFilter[u8FID].u32PidFltNo = INVALID_PIDFILT_HANDLE;
astSectionFilter[u8FID].b8OneShot = TRUE;
astSectionFilter[u8FID].u8AvailableSection = 0;
astSectionFilter[u8FID].pfCallBack = NULL;
astSectionFilter[u8FID].u16TimeoutMilliSec = TIMEOUT_INFINITE; // 0
astSectionFilter[u8FID].u32TimerEnd = TIMEOUT_INFINITE; // 0
astSectionFilter[u8FID].u16PID = 0xffff;
astSectionFilter[u8FID].u16TableID = 0xffff;
astSectionFilter[u8FID].pu8RingBufferAddress = NULL;
memset (astSectionFilter[u8FID].u8TaskName, 0x00, CTOS_MAX_NAME + 1);
//FILT_DBG( ("{dvb_filterclose} end u8FID[0x%x]\n", u8FID));
}
/*! \fn void DVB_FilterClose (u8 u8FID)
\brief Close a filter.
\param u8FID (Input) the filter ID which want to close.
*/
void DVB_FilterClose (u8 u8FID)
{
CT_OS_WaitOnSemaphore (&DVBFilterSemaphore, CTOS_WAIT);
dvb_filterclose (u8FID);
CT_OS_FreeSemaphore (&DVBFilterSemaphore);
}
/*! \fn void DVB_FilterTerminate(void)
\brief Close all filters.
*/
void DVB_FilterTerminate(void)
{
/* no one call this */
}
void DVB_Filter_CallBack (u32 u32FilterHandle, u16 u16MsgType, void *pUsrPara)
{
MSG_PARAMETER stDFSendMsg;
u8 u8FID = (u8)u32FilterHandle;
//FILT_DBG( ("{FilterCallBack} FID[0x%x] AvailableSection[%d] PID[0x%x] TID[0x%x] Name[%s]\n",
// u8FID, astSectionFilter[u8FID].u8AvailableSection,
// astSectionFilter[u8FID].u16PID, astSectionFilter[u8FID].u16TableID,
// astSectionFilter[u8FID].u8TaskName));
if (astSectionFilter[u8FID].b8Running != TRUE)
{
FILT_DBG( ("{DVB_Filter_CallBack} but this u8FID[0x%x] has already closed\n", u8FID));
}
if ((astSectionFilter[u8FID].u8AvailableSection % 5 == 0)
&& (astSectionFilter[u8FID].u8AvailableSection))
{
#if 0
FILT_DBG( ("{FilterCallBack} FID[%d] AvailableSection[%d] PID[0x%x] TID[0x%x] Name[%s]\n",
u8FID, astSectionFilter[u8FID].u8AvailableSection,
astSectionFilter[u8FID].u16PID, astSectionFilter[u8FID].u16TableID,
astSectionFilter[u8FID].u8TaskName));
#endif
}
stDFSendMsg.u8Cmd = u8FID;
#if (defined(CT216S)||defined(CT216T) || defined (CT216H))
if (u16MsgType==RING_BFR_OVRFLOW_MASK_BIT)
{
stDFSendMsg.unData.u32MsgData = (u32)DVB_FILTER_MSG_DATA_RING_BUFFER_OVERFLOW;
//FILT_DBG(("\n(C)FID[%ld] Ring Buffer Overflow\n", (u32)u8FID));
}
else
#endif //#if (defined(CT216S)||defined(CT216T))
{
stDFSendMsg.unData.u32MsgData = (u32)DVB_FILTER_MSG_DATA_INCREASE_AVAILABLE_NUM;
}
CT_OS_PutMsg(&stDFQueue, &stDFSendMsg, CTOS_NO_WAIT);
//FILT_DBG(("P u32MsgData = 0x%08lX\n", stDFSendMsg.unData.u32MsgData));
}
static void dvb_filterset (u8 u8FID, u16 u16PID, DVB_SectionHeader* pstMask, DVB_SectionHeader* pstMatch,
void (*sec_cb)(u8 u8FID, EN_FILTER_STATUS enStatus))
{
u8 pu8MatchByte[12]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
u8 pu8MaskByte [12]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
/* check parameter and status */
if ((u8FID >= MAX_FILTER_NUMBER)
|| (astSectionFilter[u8FID].b8Allocated == FALSE)
|| (astSectionFilter[u8FID].b8Running == TRUE)
|| (u16PID > 8192))
{
FILT_DBG(( "{dvb_filterset} FAIL u8FID[0x%x] Allocated[%d] Running[%d] u16PID[%d]\n",
u8FID, astSectionFilter[u8FID].b8Allocated, astSectionFilter[u8FID].b8Running, u16PID));
return;
}
#if (defined (CT216U)||defined (CT956))
/* set filter PID*/
CT_FILT_SetFilterPID (astSectionFilter[u8FID].u32SecFltNo, u16PID);
#endif
/* set call back function */
astSectionFilter[u8FID].pfCallBack = sec_cb;
/* set PID Filter PID value */
CT_PF_SetPid (astSectionFilter[u8FID].u32PidFltNo, u16PID);
/* reset PID Filter DataPath */
CT_PF_SelectDataPath (astSectionFilter[u8FID].u32PidFltNo, DEMUX_DATAPATH_NON);
/* set PID Filter DataPath */
//CT_PF_SelectDataPath (astSectionFilter[u8FID].u32PidFltNo, DEMUX_DATAPATH_0);
#ifdef CT_INSTANT_DELAY
if(DVB_TSS_ComparePid(u16PID))
CT_PF_SelectDataPath (astSectionFilter[u8FID].u32PidFltNo, DEMUX_DATAPATH_0);
else
CT_PF_SelectDataPath (astSectionFilter[u8FID].u32PidFltNo, DEMUX_DATAPATH_2);
#else
CT_PF_SelectDataPath (astSectionFilter[u8FID].u32PidFltNo, DVB_Filter_GetCtDemuxDpByDvbNimDp(DVB_Filter_GetLiveTsNimDp()));
#endif
/* set pattern */
pu8MatchByte[0] = ((pstMatch->u8TableID >>0)&0xff);
pu8MaskByte [0] = ((pstMask ->u8TableID >>0)&0xff);
pu8MatchByte[3] = ((pstMatch->u16SubTableID >>8)&0xff);
pu8MatchByte[4] = ((pstMatch->u16SubTableID >>0)&0xff);
pu8MaskByte [3] = ((pstMask ->u16SubTableID >>8)&0xff);
pu8MaskByte [4] = ((pstMask ->u16SubTableID >>0)&0xff);
pu8MatchByte[6] = ((pstMatch->u8SectionNumber>>0)&0xff);
pu8MaskByte [6] = ((pstMask ->u8SectionNumber>>0)&0xff);
// u8 u8LastSectionNumber;
pu8MatchByte[7] = ((pstMatch->u8LastSectionNumber>>0)&0xff);
pu8MaskByte [7] = ((pstMask ->u8LastSectionNumber>>0)&0xff);
// u8 au8ExtendIDs[4];
pu8MatchByte[8] = ((pstMatch->au8ExtendIDs[0]>>0)&0xff);
pu8MaskByte [8] = ((pstMask ->au8ExtendIDs[0]>>0)&0xff);
pu8MatchByte[9] = ((pstMatch->au8ExtendIDs[1]>>0)&0xff);
pu8MaskByte [9] = ((pstMask ->au8ExtendIDs[1]>>0)&0xff);
pu8MatchByte[10] = ((pstMatch->au8ExtendIDs[2]>>0)&0xff);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -