sipsi.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:168k
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include "gendef.h"
- #include "osp.h"
- #include "dmx.h"
- #include "timer.h"
- #include "sipsi.h"
- #include "sipsiprv.h"
- #include "unicode.h"
- #include "appltype.h"
- #include "db.h"
- #include "Ca_user.h"
- #include "task.h"
- #define J_SI_Print DBGPrint
- #define J_SI_Malloc KB_OSPMalloc
- #define J_SI_Free KB_OSPFree
- #define SI_TIMER_TICK_PERIOD (500)
- #define SI_HEADER_LENGTH (13)
- #define SI_FILTER_DEPTH (8)
- #define SI_SECTION_NOT_RECEIVED ((MepgData*)0x00000000)
- #define SI_SECTION_RECEIVED ((MepgData*)0xFFFFFFFF)
- #define J_SI_EIT_PF_TIMEOUT 20
- #define J_SI_EIT_SCHEDULE_TIMEOUT 50
- extern BOOL TFReceiveNitFlag;
- static T_SubTableID PATSubTableID;
- static T_SubTableID NITSubTableID;
- static T_SubTableID SDTSubTableID;
- static T_SubTableID PMTSubTableID[SI_NO_PMT_TABLES];
- static T_SubTableID EITSubTableID;
- static T_SubTableID CATSubTableID;
- static T_SubTableID TDTSubTableID;
- static T_SubTableID RSTSubTableID;
- static T_SubTableID TOTSubTableID;
- static T_SubTable SISubTable[SI_MAX_SUB_TABLES];
- static UINT32 l_nQueueId;
- static UINT32 l_nTaskId;
- static UINT32 SITimer = KB_TIMER_INVALID_ID;
- static INT8 l_nInitFlag = 0;
- static UINT32 l_nHandle = 1;
- static PATINFO* l_pstCurrPatPara;
- static PATINFO* l_pstPendingPatPara;
- static NITINFO* l_pstCurrNitPara;
- static NITINFO* l_pstPendingNitPara;
- static PMTINFO* l_pstCurrPmtPara[SI_NO_PMT_TABLES];
- static PMTINFO* l_pstPendingPmtPara[SI_NO_PMT_TABLES_QUEUE];
- static SDTINFO* l_pstCurrSdtPara;
- static SDTINFO* l_pstPendingSdtPara;
- static BATINFO* l_pstCurrBatPara;
- static BATINFO* l_pstPendingBatPara;
- static EITPFINFO* l_pstCurrEitPFPara[SI_NO_EIT_PF_FILTERS];
- static EITPFINFO* l_pstPendingEitPFPara[SI_NO_EIT_PF_TABLES_QUEUE];
- static EITSCHINFO* l_pstCurrEinSchInfoPara[KB_SI_EIT_SCHEDULE_SERVICE_COUNT];
- static EITSCHINFO* l_pstPendingEinSchInfoPara[KB_SI_EIT_SCHEDULE_SERVICE_COUNT];
- static MULTEITSCHINFO* l_pstCurrMultiEinSchInfoPara;
- static MULTEITSCHINFO* l_pstPendingMultiEinSchInfoPara;
- static TDTINFO* l_pstCurrTdtPara;
- static TDTINFO* l_pstPendingTdtPara;
- static TOTINFO* l_pstCurrTotPara;
- static TOTINFO* l_pstPendingTotPara;
- static CATINFO* l_pstCurrCatPara;
- static CATINFO* l_pstPendingCatPara;
- static RSTINFO* l_pstCurrRstPara;
- static RSTINFO* l_pstPendingRstPara;
- static T_EIT_SCHEDULE_TIME_SHIFT_PARA *gptCurrSchShiftPara[SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS];
- static T_EIT_SCHEDULE_TIME_SHIFT_PARA *gptPendingSchShiftPara[SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS];
- static MepgData SISectionSmallData[SI_MAX_SECTION_SMALL_DATA];
- static MepgData SISectionLargeData[SI_MAX_SECTION_LARGE_DATA];
- static T_ChannelToSubtable SIChannelToSubTableMap[SI_DMX_NO_CHANNELS];
- static T_SubTableFilter SIFilters[SI_DMX_NO_FILTERS];
- static UINT32 SICurrentFilter;
- static UINT32 SISubTableListData[SI_MAX_SUB_TABLES];
- static UINT32 SISectionLargeDataListBuffer[SI_MAX_SECTION_LARGE_DATA];
- static UINT32 SISectionSmallDataListBuffer[SI_MAX_SECTION_SMALL_DATA];
- static SIFIFO SISubTableList = {SI_MAX_SUB_TABLES, SISubTableListData};
- static SIFIFO SISectionLargeDataList = {SI_MAX_SECTION_LARGE_DATA, SISectionLargeDataListBuffer};
- static SIFIFO SISectionSmallDataList = {SI_MAX_SECTION_SMALL_DATA, SISectionSmallDataListBuffer};
- static T_SubTableDetails PATDetails = { 0x0000, 33, TRUE, 0x00, -1, 10, 1, FALSE };
- static T_SubTableDetails CATDetails = { 0x0001, 33, TRUE, 0x01, -1, 10, 1, FALSE };
- static T_SubTableDetails PMTDetails = { -1, 33, TRUE, 0x02, -1, 10, 1, FALSE };
- static T_SubTableDetails NITDetails = { 0x0010, 33, TRUE, 0x40, -1, 40, 1, FALSE };
- static T_SubTableDetails SDTDetails = { 0x0011, 33, TRUE, 0x42, -1, 40, 2, FALSE };
- static T_SubTableDetails EITDetails = { 0x0012, 33, TRUE, 0x4E, -1, 25, SI_NO_EIT_FILTERS, FALSE };
- static T_SubTableDetails TDTDetails = { 0x0014, 33, FALSE, 0x70, -1, 120, 1, FALSE };
- static T_SubTableDetails RSTDetails = { 0x0013, 33, FALSE, 0x71, -1, -1, 1, FALSE };
- static T_SubTableDetails TOTDetails = { 0x0014, 33, FALSE, 0x73, -1, 120, 1, FALSE };
- static UINT32 semCritical; /* 保护LIFO的资源共享的信号量 */
- static KB_SICallbackFunc gptSiCallbackFunction = NULL;
- static KB_SICallbackFunc gptSiEitCallbackFunction = NULL;
- /*******************************************************************************
- ** Local Function Prototype
- *******************************************************************************/
- static void SIToLower(char* str);
- static void SIGetSection(UINT32 nChannelID, UINT8 *pData, UINT32 nDataLength);
- static int KD_DTVSendMsg(KB_OSPMsgNode * pMsg);
- static void SiEitSetup(T_SubTableID subTableID, UINT32 filterNumber,
- INT32 version, UINT32 handle);
- static UINT32 SIGetFilterNum(T_SubTableID subTableID, INT32 tableId,
- INT32 tableIDExt);
- static INT32 SIStopEitPF(INT32 nSvcID, INT32 nTableId);
- INT32 KB_SIInit()
- {
- int i;
- if(l_nInitFlag == 1)
- {
- return RETOK;
- }
- l_nInitFlag = 1;
- if(KB_OSPSemInit("SI-S", 1, J_OSP_WAIT_FIFO, &semCritical) != Ret_OK)
- {
- return RETFIAL1;
- }
-
- for(i=0; i<SI_DMX_NO_CHANNELS; i++)
- {
- SIChannelToSubTableMap[i].valid = 0;
- }
-
- if (SIAlloc() != SI_OK)
- {
- return RETFIAL1;
- }
-
- if (SISubTableInitialize() != SI_OK)
- {
- return RETFIAL1;
- }
- return RETOK;
- }
-
- INT32 KB_SIDestroy()
- {
- if(l_nInitFlag == 0)
- {
- return 0;
- }
- l_nInitFlag = 0;
- KB_SIStopAllSection();
- SISubTableDestroy();
- SIFree();
- KB_OSPSemDel(semCritical);
- return 0;
- }
- static INT32 SIAlloc(void)
- {
- int i;
- if( (l_pstCurrPatPara = J_SI_Malloc( sizeof(PATINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrPatPara, 0, sizeof(PATINFO));
- if( (l_pstPendingPatPara = J_SI_Malloc( sizeof(PATINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingPatPara, 0, sizeof(PATINFO));
- if( (l_pstCurrNitPara = J_SI_Malloc( sizeof(NITINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrNitPara, 0, sizeof(NITINFO));
- if( (l_pstPendingNitPara = J_SI_Malloc( sizeof(NITINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingNitPara, 0, sizeof(NITINFO));
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if( (l_pstCurrPmtPara[i] = J_SI_Malloc( sizeof(PMTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrPmtPara[i], 0, sizeof(PMTINFO));
- }
-
- for(i = 0; i < SI_NO_PMT_TABLES_QUEUE; i++)
- {
- if( (l_pstPendingPmtPara[i] = J_SI_Malloc( sizeof(PMTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingPmtPara[i], 0, sizeof(PMTINFO));
- }
- if( (l_pstCurrSdtPara = J_SI_Malloc( sizeof(SDTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrSdtPara, 0, sizeof(SDTINFO));
- if( (l_pstPendingSdtPara = J_SI_Malloc( sizeof(SDTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingSdtPara, 0, sizeof(SDTINFO));
- if( (l_pstCurrBatPara = J_SI_Malloc( sizeof(BATINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrBatPara, 0, sizeof(BATINFO));
- if( (l_pstPendingBatPara = J_SI_Malloc( sizeof(BATINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingBatPara, 0, sizeof(BATINFO));
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if( (l_pstCurrEitPFPara[i] = J_SI_Malloc( sizeof(EITPFINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- }
-
- for(i = 0; i < SI_NO_EIT_PF_TABLES_QUEUE; i++)
- {
- if( (l_pstPendingEitPFPara[i] = J_SI_Malloc( sizeof(EITPFINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingEitPFPara[i], 0, sizeof(EITPFINFO));
- }
-
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if( (l_pstCurrEinSchInfoPara[i] = J_SI_Malloc( sizeof(EITSCHINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- if( (l_pstPendingEinSchInfoPara[i] = J_SI_Malloc( sizeof(EITSCHINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- }
- if( (l_pstCurrMultiEinSchInfoPara = J_SI_Malloc( sizeof(MULTEITSCHINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrMultiEinSchInfoPara, 0, sizeof(MULTEITSCHINFO));
- if( (l_pstPendingMultiEinSchInfoPara = J_SI_Malloc( sizeof(MULTEITSCHINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingMultiEinSchInfoPara, 0, sizeof(MULTEITSCHINFO));
- if( (l_pstCurrTdtPara = J_SI_Malloc( sizeof(TDTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrTdtPara, 0, sizeof(TDTINFO));
- if( (l_pstPendingTdtPara = J_SI_Malloc( sizeof(TDTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingTdtPara, 0, sizeof(TDTINFO));
- if( (l_pstCurrCatPara = J_SI_Malloc( sizeof(CATINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrCatPara, 0, sizeof(CATINFO));
- if( (l_pstPendingCatPara = J_SI_Malloc( sizeof(CATINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingCatPara, 0, sizeof(CATINFO));
- if( (l_pstCurrRstPara = J_SI_Malloc( sizeof(RSTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrRstPara, 0, sizeof(RSTINFO));
- if( (l_pstPendingRstPara = J_SI_Malloc( sizeof(RSTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingRstPara, 0, sizeof(RSTINFO));
- if( (l_pstCurrTotPara = J_SI_Malloc( sizeof(TOTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstCurrTotPara, 0, sizeof(TOTINFO));
- if( (l_pstPendingTotPara = J_SI_Malloc( sizeof(TOTINFO) )) == NULL )
- {
- return SI_MEMORY_FULL;
- }
- memset(l_pstPendingTotPara, 0, sizeof(TOTINFO));
- for (i = 0;i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- gptCurrSchShiftPara[i] = J_SI_Malloc(sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- if (gptCurrSchShiftPara[i] == NULL)
- {
- return SI_MEMORY_FULL;
- }
- memset(gptCurrSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- gptPendingSchShiftPara[i] = J_SI_Malloc(sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- if (gptPendingSchShiftPara[i] == NULL)
- {
- return SI_MEMORY_FULL;
- }
- memset(gptPendingSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- }
-
- return SI_OK;
- }
- void SIFree(void)
- {
- int i;
-
- J_SI_Free(l_pstCurrPatPara);
- J_SI_Free(l_pstPendingPatPara);
- J_SI_Free(l_pstCurrNitPara);
- J_SI_Free(l_pstPendingNitPara);
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- J_SI_Free(l_pstCurrPmtPara[i]);
- }
- for(i = 0; i < SI_NO_PMT_TABLES_QUEUE; i++)
- {
- J_SI_Free(l_pstPendingPmtPara[i]);
- }
- J_SI_Free(l_pstCurrSdtPara);
- J_SI_Free(l_pstPendingSdtPara);
- J_SI_Free(l_pstCurrBatPara);
- J_SI_Free(l_pstPendingBatPara);
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- J_SI_Free(l_pstCurrEitPFPara[i]);
- }
- for(i = 0; i < SI_NO_EIT_PF_TABLES_QUEUE; i++)
- {
- J_SI_Free(l_pstPendingEitPFPara[i]);
- }
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if (l_pstCurrEinSchInfoPara[i])
- {
- J_SI_Free(l_pstCurrEinSchInfoPara[i]);
- }
- if (l_pstPendingEinSchInfoPara[i])
- {
- J_SI_Free(l_pstPendingEinSchInfoPara[i]);
- }
- }
- J_SI_Free(l_pstCurrMultiEinSchInfoPara);
- J_SI_Free(l_pstPendingMultiEinSchInfoPara);
- J_SI_Free(l_pstCurrTdtPara);
- J_SI_Free(l_pstPendingTdtPara);
- J_SI_Free(l_pstCurrCatPara);
- J_SI_Free(l_pstPendingCatPara);
- J_SI_Free(l_pstCurrRstPara);
- J_SI_Free(l_pstPendingRstPara);
- J_SI_Free(l_pstCurrTotPara);
- J_SI_Free(l_pstPendingTotPara);
- for (i = 0;i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if (gptCurrSchShiftPara[i])
- {
- J_SI_Free(gptCurrSchShiftPara[i]);
- }
-
- if (gptPendingSchShiftPara[i])
- {
- J_SI_Free(gptPendingSchShiftPara[i]);
- }
- }
- }
- INT32 KB_SIStopAllSection()
- {
- UINT32 i;
-
- SISubTableStop(PATSubTableID);
- SISubTableStop(NITSubTableID);
- SISubTableStop(SDTSubTableID);
- SISubTableStop(EITSubTableID);
- SISubTableStop(CATSubTableID);
- SISubTableStop(TDTSubTableID);
- SISubTableStop(RSTSubTableID);
- SISubTableStop(TOTSubTableID);
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- SISubTableStop(PMTSubTableID[i]);
- memset(l_pstCurrPatPara, 0, sizeof(PATINFO));
- memset(l_pstPendingPatPara, 0, sizeof(PATINFO));
- memset(l_pstCurrNitPara, 0, sizeof(NITINFO));
- memset(l_pstPendingNitPara, 0, sizeof(NITINFO));
- memset(l_pstCurrSdtPara, 0, sizeof(SDTINFO));
- memset(l_pstPendingSdtPara, 0, sizeof(SDTINFO));
- memset(l_pstCurrBatPara, 0, sizeof(BATINFO));
- memset(l_pstPendingBatPara, 0, sizeof(BATINFO));
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- memset(l_pstCurrPmtPara[i], 0, sizeof(PMTINFO));
- memset(l_pstPendingPmtPara[i], 0, sizeof(PMTINFO));
- }
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- memset(l_pstPendingEitPFPara[i], 0, sizeof(EITPFINFO));
- }
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- memset(l_pstCurrEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- memset(l_pstPendingEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- }
- memset(l_pstCurrMultiEinSchInfoPara, 0, sizeof(MULTEITSCHINFO));
- memset(l_pstPendingMultiEinSchInfoPara, 0, sizeof(MULTEITSCHINFO));
- memset(l_pstCurrTdtPara, 0, sizeof(TDTINFO));
- memset(l_pstPendingTdtPara, 0, sizeof(TDTINFO));
- memset(l_pstCurrCatPara, 0, sizeof(CATINFO));
- memset(l_pstPendingCatPara, 0, sizeof(CATINFO));
- memset(l_pstCurrRstPara, 0, sizeof(RSTINFO));
- memset(l_pstPendingRstPara, 0, sizeof(RSTINFO));
- memset(l_pstCurrTotPara, 0, sizeof(TOTINFO));
- memset(l_pstPendingTotPara, 0, sizeof(TOTINFO));
- for (i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- memset(gptCurrSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- memset(gptPendingSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- }
- return 0;
- }
- static INT32 SISubTableInitialize(void)
- {
- INT32 status;
- INT32 i;
- LIFOInitialize(&SISubTableList);
- LIFOInitialize(&SISectionSmallDataList);
- LIFOInitialize(&SISectionLargeDataList);
- for(i = 0; i < SI_MAX_SUB_TABLES; i++)
- {
- LIFOPush(&SISubTableList, i);
- }
-
- for(i = 0; i < SI_MAX_SECTION_SMALL_DATA; i++)
- {
- SISectionSmallData[i].data = NULL;
-
- LIFOPush(&SISectionSmallDataList, (UINT32)&SISectionSmallData[i]);
- }
-
- for(i = 0; i < SI_MAX_SECTION_LARGE_DATA; i++)
- {
- SISectionLargeData[i].data = NULL;
-
- LIFOPush(&SISectionLargeDataList, (UINT32)&SISectionLargeData[i]);
- }
- status = KB_OSPQueInit("SI_Q", 128, &l_nQueueId);
- if (status != Ret_OK)
- {
- return SI_OSP_ERROR;
- }
- status = KB_OSPTaskInit ("SI_T", 8 * 1024, (void (*)(void*))SITask, SIPSI_PRIORITY, NULL, (UINT32*)&l_nTaskId);
- if (status != Ret_OK)
- {
- return SI_OSP_ERROR;
- }
- /*
- ** Initialize the number of filters
- */
- SICurrentFilter = 0;
- /* Create the various sub tables: */
- PATSubTableID = SISubTableCreate(&PATDetails, SIParsePAT, SIHandlePat, SIHandlePatTimeout, NULL);
- if (PATSubTableID < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
-
- NITSubTableID = SISubTableCreate(&NITDetails, SIParseNIT, SIHandleNit, SIHandleNitTimeout, NULL);
- if (NITSubTableID < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
-
- SDTSubTableID = SISubTableCreate(&SDTDetails, SIParseSDT, SIHandleSdt, SIHandleSdtTimeout, NULL);
- if (SDTSubTableID < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
-
- EITSubTableID = SISubTableCreate(&EITDetails, SIParseEit, SIHandleEit, SIHandleEitTimeout, SiEitSetup);
- if (EITSubTableID < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
-
- CATSubTableID = SISubTableCreate(&CATDetails, SIParseCAT, SIHandleCat, SIHandleCatTimeout, NULL);
- if (CATSubTableID < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
-
- TDTSubTableID = SISubTableCreate(&TDTDetails, SIParseTDT, NULL, SIHandleTdtTimeout, NULL);
- if (TDTSubTableID < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
-
- RSTSubTableID = SISubTableCreate(&RSTDetails, SIParseRST, NULL, NULL, NULL);
- if (RSTSubTableID < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
-
- TOTSubTableID = SISubTableCreate(&TOTDetails, SIParseTOT, NULL, SIHandleTotTimeout, NULL);
- if (TOTSubTableID < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
- PMTDetails.noFilters = SI_NO_PMT_FILTERS;
- PMTSubTableID[0] = SISubTableCreate(&PMTDetails, SIParsePMT, SIHandlePmt, SIHandlePmtTimeout, NULL);
- if (PMTSubTableID[0] < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
-
- PMTDetails.noFilters = 1;
- for(i = 1; i < SI_NO_PMT_TABLES; i++)
- {
- PMTSubTableID[i] = SISubTableCreate(&PMTDetails, SIParsePMT, SIHandlePmt, SIHandlePmtTimeout, NULL);
- if (PMTSubTableID[i] < 0)
- {
- return SI_NO_FREE_SUBTABLES;
- }
- }
- SITimer = KB_TimerCreate(KB_TIMER_REPEAT , (KB_TIMER_FUNC_POINTER)SISendTimerMessage,NULL);
- if(SITimer == KB_TIMER_INVALID_ID )
- {
-
- return SI_UNKNOWN_ERROR;
- }
-
- status = KB_TimerEnable(SITimer, SI_TIMER_TICK_PERIOD);
- if(status != RETOK)
- {
-
- return SI_UNKNOWN_ERROR;
- }
- return SI_OK;
- }
- static INT32 SISubTableDestroy(void)
- {
- INT32 status;
- INT32 i, j;
- /*
- ** Stop the SI Timer tick.
- */
- KB_TimerDisable(SITimer);
- status = KB_TimerDel(SITimer);
- for(i = 0; i < SI_MAX_SUB_TABLES; i++)
- {
- INT32 nFilterNumber;
- nFilterNumber = SISubTable[i].details.noFilters;
- for(j = 0; j < nFilterNumber; j++)
- {
- KB_DmxFreeFilter( SISubTable[i].filter[j].filterID);
- }
- KB_DmxFreeChnnl(SISubTable[i].details.channelID);
-
- }
- KB_OSPTaskDel(l_nTaskId);
- KB_OSPQueDel(l_nQueueId);
-
- return SI_OK;
- }
- static T_SubTableID SISubTableCreate(T_SubTableDetails* details,
- T_SectionCallback sectionCallback,
- T_SubTableCallback tableCallback,
- T_TimeoutCallback timeoutCallback,
- T_SetupCallback setupCallback)
- {
- UINT32 i;
- UINT32 subTableID, channelID;
- INT32 nReturn;
- UINT32 filterID;
- UINT32 j;
- T_SubTableFilter *filterDetails;
-
- /*
- ** Get a free sub-table. Return an error if no free storage is available.
- */
- if(LIFOPop(&SISubTableList, &subTableID) != LIFO_OK)
- {
- return SI_NO_FREE_SUBTABLES;
- }
- /*
- ** Allocate the Demux resources
- */
- if (details == &EITDetails)
- {
- nReturn = KB_DmxAllocateChnnl(DMX_CHANNEL_SECTION, 256 * 1024, FALSE, &channelID);
- }
- else
- {
- nReturn = KB_DmxAllocateChnnl(DMX_CHANNEL_SECTION, SI_DMX_BUFFER_SIZE, FALSE, &channelID);
- }
- if(nReturn != RETOK)
- {
- channelID = 0xFFFFFFFF;
- return SI_NO_AVAILABLE_CHANNELS;
- }
-
- KB_DmxRegNotice(channelID, SIGetSection);
- SISubTable[subTableID].filter = &SIFilters[SICurrentFilter];
- SICurrentFilter += details->noFilters;
- if(SICurrentFilter > SI_DMX_NO_FILTERS)
- {
- SICurrentFilter -= details->noFilters;
- LIFOPush(&SISubTableList, subTableID);
- return SI_NO_AVAILABLE_FILTERS;
- }
- /*
- ** Store the sub-table details
- */
- SISubTable[subTableID].sectionCallback = sectionCallback;
- SISubTable[subTableID].tableCallback = tableCallback;
- SISubTable[subTableID].setupCallback = setupCallback;
- SISubTable[subTableID].details.PID = details->PID;
- SISubTable[subTableID].details.channelID = channelID;
- SISubTable[subTableID].details.multipleSections = details->multipleSections;
- SISubTable[subTableID].details.tableID = details->tableID;
- SISubTable[subTableID].details.tableIDExt = details->tableIDExt;
- SISubTable[subTableID].details.timeout = details->timeout;
- SISubTable[subTableID].details.noFilters = details->noFilters;
- SISubTable[subTableID].details.channelStarted = FALSE;
- /*
- ** Store which sub table is using the channel
- */
- /* SIChannelToSubTableMap[channelID] = subTableID; */
- for(i=0; i<SI_DMX_NO_CHANNELS; i++)
- {
- if(!SIChannelToSubTableMap[i].valid)
- {
- SIChannelToSubTableMap[i].channelId = channelID;
- SIChannelToSubTableMap[i].subTableId = subTableID;
- SIChannelToSubTableMap[i].valid = 1;
- break;
- }
- }
- /*
- ** Allocate the filters
- */
- /* EIT只使用一个硬件filter */
- if (details == &EITDetails)
- {
- nReturn = KB_DmxAllocateFilter(DMX_SECTION_FILTER, SI_FILTER_DEPTH, &filterID);
- if(nReturn != RETOK)
- {
- return SI_NO_AVAILABLE_FILTERS;
- }
- for(i = 0; i < details->noFilters; i++)
- {
- filterDetails = &SISubTable[subTableID].filter[i];
- /* Store the initial values for the filter */
- filterDetails->tableID = details->tableID;
- filterDetails->tableIDExt = details->tableIDExt;
- filterDetails->version = -1;
- filterDetails->timeout = -1; //details->timeout
- filterDetails->filterID = filterID;
- filterDetails->filterNumber = i;
- filterDetails->timeoutCallback = timeoutCallback;
- filterDetails->subTableID = subTableID;
- filterDetails->enabled = FALSE;
- filterDetails->used = FALSE;
-
- for( j = 0; j < SI_MAX_SECTION_PER_TABLE; j++ )
- {
- filterDetails->data.sectionData[j] = SI_SECTION_NOT_RECEIVED;
- }
- }
- }
- else
- {
- for(i = 0; i < details->noFilters; i++)
- {
- /*
- ** Setup the static parts of the H/W
- */
- nReturn = KB_DmxAllocateFilter(DMX_SECTION_FILTER, SI_FILTER_DEPTH, &filterID);
- if(nReturn != RETOK)
- {
- return SI_NO_AVAILABLE_FILTERS;
- }
-
- filterDetails = &SISubTable[subTableID].filter[i];
- /* Store the initial values for the filter */
- filterDetails->tableID = details->tableID;
- filterDetails->tableIDExt = details->tableIDExt;
- filterDetails->version = -1;
- filterDetails->timeout = -1; //details->timeout
- filterDetails->filterID = filterID;
- filterDetails->filterNumber = i;
- filterDetails->timeoutCallback = timeoutCallback;
- filterDetails->subTableID = subTableID;
- filterDetails->enabled = FALSE;
- filterDetails->used = FALSE;
-
- for( j = 0; j < SI_MAX_SECTION_PER_TABLE; j++ )
- {
- filterDetails->data.sectionData[j] = SI_SECTION_NOT_RECEIVED;
- }
-
- }
- }
-
- return subTableID;
- }
- INT32 SIFreeSectionData(MepgData *section)
- {
- INT32 status = SI_INVALID_SECTION_DATA_ID;
- /* Validate the sectionData before adding it to the free list */
- if(section != NULL)
- {
- if(section >= &SISectionSmallData[0] && section <= &SISectionSmallData[SI_MAX_SECTION_SMALL_DATA])
- {
- KB_DmxUnlock(SISubTable[section->subTableID].details.channelID,
- section->data);
- section->data = NULL;
-
- LIFOPush(&SISectionSmallDataList, (UINT32)section);
- status = SI_OK;
- }
- else if(section >= &SISectionLargeData[0] && section <= &SISectionLargeData[SI_MAX_SECTION_LARGE_DATA])
- {
- KB_DmxUnlock(SISubTable[section->subTableID].details.channelID,
- section->data);
- section->data = NULL;
-
- LIFOPush(&SISectionLargeDataList, (UINT32)section);
- status = SI_OK;
- }
-
- }
-
- return status;
- }
- /*
- ** Private Functions
- */
- static void SIFilterStopHelper(UINT32 channelID, T_SubTableFilter *filter)
- {
- int i;
- T_SubTableID subTableID = 0;
-
- for(i=0; i<SI_DMX_NO_CHANNELS; i++)
- {
- if(SIChannelToSubTableMap[i].valid &&
- (SIChannelToSubTableMap[i].channelId == channelID))
- {
- subTableID = SIChannelToSubTableMap[i].subTableId;
- break;
- }
- }
- if(i >= SI_DMX_NO_CHANNELS)
- {
- return;
- }
-
- /* Reset the timer */
- filter->timeout = -1;
- /* 把sub table filter设为不可用状态 */
- filter->enabled = FALSE;
- //filter->used = FALSE;
-
- if (subTableID == EITSubTableID)
- {
- for (i = 0; i < SI_NO_EIT_FILTERS; i++)
- {
- if (SISubTable[subTableID].filter[i].enabled == TRUE)
- {
- break;
- }
- }
- /* 当所有过滤器都停止时才停止通道和过滤器 */
- if(i >= SI_NO_EIT_FILTERS)
- {
- if (SISubTable[subTableID].details.channelStarted == TRUE)
- {
- SISubTable[subTableID].details.channelStarted = FALSE;
- DBGPrint("Stop helper eitn");
- KB_DmxControlChnnl(channelID, KB_DMX_STOP);
- KB_DmxDisassociateFilter(channelID, filter->filterID);
- }
- }
- }
- else
- {
- SISubTable[subTableID].details.channelStarted = FALSE;
- KB_DmxControlChnnl(channelID, KB_DMX_STOP);
- KB_DmxDisassociateFilter(channelID, filter->filterID);
- }
- //KB_DmxControlChnnl(channelID, KB_DMX_START);
- }
- static void SIFilterStop(UINT32 channelID, T_SubTableFilter *filter)
- {
- SIFilterStopHelper(channelID, filter);
- }
- static void SIFilterDetach(UINT32 channelID, T_SubTableFilter *filter)
- {
- /* Reset the timer */
- filter->timeout = -1;
- KB_DmxDisassociateFilter(channelID, filter->filterID);
- filter->enabled = FALSE;
- filter->used = FALSE;
- }
- static void SISubTableStop(T_SubTableID subTableID)
- {
- UINT32 i;
- KB_DmxControlChnnl(SISubTable[subTableID].details.channelID, KB_DMX_STOP);
- SISubTable[subTableID].details.channelStarted = FALSE;
- for(i = 0; i < SISubTable[subTableID].details.noFilters; i++)
- {
- SIFilterDetach(SISubTable[subTableID].details.channelID, &SISubTable[subTableID].filter[i]);
- }
- }
- static void SISubTableStart(T_SubTableID subTableID, UINT32 filterNumber, INT32 version, UINT32 handle)
- {
- UINT32 i;
- T_SubTableFilter *filterDetails;
- UINT32 channelID;
- UINT32 filterID;
- UINT8 filterMask[16];
- UINT8 filterMatch[16];
- UINT32 filterNegate;
- memset(filterMatch, 0, sizeof(filterMatch));
- memset(filterMask, 0, sizeof(filterMask));
- /*
- ** Update the filter values
- */
- filterDetails = &SISubTable[subTableID].filter[filterNumber];
- filterID = filterDetails->filterID;
- channelID = SISubTable[subTableID].details.channelID;
- /*
- ** First of all stop the demux channel to prevent any more data from being received.
- */
- if (subTableID == EITSubTableID)
- {
- if (SISubTable[subTableID].details.channelStarted != TRUE)
- {
- KB_DmxControlChnnl(channelID, KB_DMX_STOP);
- SISubTable[subTableID].details.channelStarted = FALSE;
- }
- }
- else
- {
- KB_DmxControlChnnl(channelID, KB_DMX_STOP);
- SISubTable[subTableID].details.channelStarted = FALSE;
- }
- task_lock();
- if( SISubTable[subTableID].setupCallback != NULL )
- {
- SISubTable[subTableID].setupCallback(subTableID, filterNumber, version, handle);
- }
- else
- {
- /*
- ** Update the filter values
- */
- filterDetails = &SISubTable[subTableID].filter[filterNumber];
- filterDetails->data.total = -1;
- filterDetails->data.received = 0;
- for(i = 0; i < SI_MAX_SECTION_PER_TABLE; i++)
- {
- /* Before resetting the section data list check to make sure no section data buffers are still waiting for data */
- //防止内存泄漏
- if( (filterDetails->data.sectionData[i] != SI_SECTION_NOT_RECEIVED) &&
- (filterDetails->data.sectionData[i] != SI_SECTION_RECEIVED) )
- {
- SIFreeSectionData(filterDetails->data.sectionData[i]);
- }
- filterDetails->data.sectionData[i] = SI_SECTION_NOT_RECEIVED;
- }
- filterDetails->tableID = SISubTable[subTableID].details.tableID;
- filterDetails->tableIDExt = SISubTable[subTableID].details.tableIDExt;
- filterDetails->version = version;
- filterDetails->timeout = SISubTable[subTableID].details.timeout;
- filterDetails->handle = handle;
- if( filterDetails->tableID != -1 )
- {
- filterMask[0] = 0xFF;
- filterMatch[0] = (UINT8) (filterDetails->tableID & 0xFF);
- }
- else
- {
- filterMask[0] = 0x00;
- filterMatch[0] = 0x00;
- }
- if( filterDetails->tableIDExt != -1 )
- {
- filterMask[3] = 0xFF;
- filterMask[4] = 0xFF;
- filterMatch[3] = (UINT8)((filterDetails->tableIDExt >> 8) & 0xFF);
- filterMatch[4] = (UINT8) (filterDetails->tableIDExt & 0xFF);
- }
- else
- {
- filterMask[3] = 0x00;
- filterMask[4] = 0x00;
- filterMatch[3] = 0x00;
- filterMatch[4] = 0x00;
- }
- if( filterDetails->version != -1 )
- {
- filterMask[5] = 0x3E;
- filterMatch[5] = (UINT8)((filterDetails->version & 0x1F) << 1);
- filterNegate = (1 << 5);
- }
- else
- {
- filterMask[5] = 0x00;
- filterMatch[5] = 0x00;
- filterNegate = 0;
- }
-
- filterDetails->enabled = TRUE;
- filterDetails->used = TRUE;
- KB_DmxAssociateFilter(channelID, filterID);
- KB_DmxSetFilter(filterID, filterMatch, filterMask, filterNegate);
- }
- task_unlock();
-
- if (subTableID == EITSubTableID)
- {
- if (SISubTable[subTableID].details.channelStarted != TRUE)
- {
- KB_DmxSetChnnlPID(channelID, (UINT16)SISubTable[subTableID].details.PID);
- SISubTable[subTableID].details.channelStarted = TRUE;
- }
- }
- else
- {
- KB_DmxSetChnnlPID(channelID, (UINT16)SISubTable[subTableID].details.PID);
- SISubTable[subTableID].details.channelStarted = TRUE;
- }
-
- }
- static BOOL SIHandleNewSection(UINT8* headerMPEGSection, T_DMX_Notify* notifyData)
- {
- T_SubTableID subTableID = 0;
- T_SubTableFilter *filter;
- UINT32 filterNumber;
- UINT32 sectionNumber;
- UINT32 sectionLength;
- UINT32 i;
- UINT16 tableIDExt;
- UINT8 *data;
- UINT8 version;
- UINT8 tableID;
- MepgData *sectionData;
- SIFIFO *sectionDataList;
- int nIsMulti = 0;
- /* Assume we do not want the section. */
- notifyData->copyLength = 0;
- if(notifyData->whichChannel == 0xFFFFFFFF)
- {
- return (FALSE);
- }
- /*
- ** Get the subTable ID associated with this section.
- */
- /* subTableID = SIChannelToSubTableMap[notifyData->whichChannel]; */
- for(i=0; i<SI_DMX_NO_CHANNELS; i++)
- {
- if (SIChannelToSubTableMap[i].valid
- && (SIChannelToSubTableMap[i].channelId == notifyData->whichChannel))
- {
- subTableID = SIChannelToSubTableMap[i].subTableId;
- break;
- }
- }
- if(i >= SI_DMX_NO_CHANNELS)
- {
- return FALSE;
- }
-
- if(subTableID > SI_MAX_SUB_TABLES || subTableID < 0)
- {
- return (FALSE);
- }
- data = headerMPEGSection;
- /*
- ** Store the section information
- */
- tableID = data[0];
- sectionLength = ((((UINT32)data[1] & 0x0F) << 8) + (UINT32)data[2]) + 3;
- tableIDExt = (UINT16)(data[3] << 8) | data[4];
- version = (UINT8)((data[5] & 0x3E) >> 1);
-
- /*
- ** If the section syntax is set then remove the CRC from the data to be
- ** copied
- */
- if( data[1] & 0x80 )
- {
- sectionLength -= 4;
- }
- /*
- ** Ensure there is enough space to perform the copy. Note. The only DVB
- ** section allowed to be longer than 1024 bytes are EIT scheduling
- ** information.
- */
- if(sectionLength > 4096)
- {
- return (FALSE);
- }
- else
- {
- if(sectionLength > 1024)
- {
- sectionDataList = &SISectionLargeDataList;
- }
- else
- {
- sectionDataList = &SISectionSmallDataList;
- }
- }
- /*
- ** Locate which filter this section passed. Initially assume it was the
- ** first.
- */
- filter = &SISubTable[subTableID].filter[0];
- filterNumber = 0;
- /*
- ** Check to ensure that the section we have just received is one we currently want.
- */
- for(i = 0; i < SISubTable[subTableID].details.noFilters; i++)
- {
- filter = &SISubTable[subTableID].filter[i];
- if((filter->enabled == TRUE) &&
- (filter->tableID == tableID || filter->tableID == -1 ) &&
- (filter->tableIDExt == tableIDExt || filter->tableIDExt == -1 ) &&
- (filter->version == version || filter->version == -1 ) )
- {
- filterNumber = i;
- break;
- }
- }
-
- if( i == SISubTable[subTableID].details.noFilters )
- {
- return (FALSE);
- }
- if(SISubTable[subTableID].details.multipleSections == TRUE)
- {
- if(filter->tableID == 0x50 && filter->tableIDExt == -1)
- {
- nIsMulti = 1;
- }
- /*
- ** Is this section needed.
- */
- sectionNumber = data[6];
-
- if( nIsMulti ? 1 :(filter->data.sectionData[sectionNumber] == SI_SECTION_NOT_RECEIVED))
- {
- /*
- ** Get the next free section data area. If there are none available,
- ** then do nothing and wait for the section to be repeated.
- */
- if( LIFOPop(sectionDataList, (UINT32*)§ionData) == LIFO_OK)
- {
- //J_SI_Print("Success....n");
- /*
- ** Update the sub table details
- */
- filter->data.sectionData[sectionNumber] = sectionData;
- /*
- ** Check to see if this is the first section received.
- */
- if( filter->data.total == -1 )
- {
- filter->data.total = data[7];
- }
- if(tableID == 0x50
- || tableID == 0x51
- || tableID == 0x60
- || tableID == 0x61
- || tableID == 0x4F) /* EIT Specific */
- {
- /* data[6] :section_number, data[7]:last_section_number,
- ** data[12]: segment_last_section_number
- ** 每一个segment可以包含8个section,同时包含三个小时内开始的事件信息。
- */
- if( (sectionNumber == data[12]) && (data[7] != data[12]) )
- {
- filter->data.received += (0x7 - (sectionNumber & 0x7));
- }
- }
- filter->data.version = version;
- filter->data.tableIDExt = tableIDExt;
- /*
- ** Update the section data details.
- */
- sectionData->length = sectionLength;
- sectionData->subTableID = subTableID;
- sectionData->filterNumber = filterNumber;
- /*
- ** Is there any data to copy. If not call SISectionCopied directly,
- ** which will in turn call the high level.
- */
- if( sectionData->length != 0 )
- {
- sectionData->data = headerMPEGSection;
- notifyData->skipLength = 0;
- notifyData->copyLength = sectionData->length + 4; // 包含了CRC_32
- notifyData->tag = (void*)sectionData;
- notifyData->outputBuffer = (UINT8*)sectionData->data;
- }
- else
- {
- SISectionCopied( DMX_AVAILABLE,
- (UINT8*)sectionData->data,
- 0, (void*)sectionData );
- return FALSE;
- }
- }
- else
- {
- return FALSE;
- }
- }
- else
- {
- return FALSE;
- }
- }
- else /* multipleSections == FALSE */
- {
- if(LIFOPop(sectionDataList, (UINT32*)§ionData) == LIFO_OK)
- {
- sectionData->length = sectionLength;
- sectionData->subTableID = subTableID;
- sectionData->filterNumber = filterNumber;
- sectionData->data = headerMPEGSection;
-
- /*
- ** Setup the information for the copy.
- */
- notifyData->skipLength = 0;
- notifyData->copyLength = sectionData->length;
- notifyData->tag = (void*)sectionData;
- notifyData->outputBuffer = (UINT8*)sectionData->data;
- }
- else
- {
- return FALSE;
- }
- }
- return( TRUE );
- }
- /****************************************************************************
- ** Function SISectionCopied()
- **
- ** Description Called by the Demux driver when a section has been copied.
- ** Performs the following:
- ** o Inform the SI Task of the new section
- ** o If all the section of the sub table have been received then:
- ** Inform the SI task that the table is complete
- ** Stop the reception of the table.
- **
- ** Input INT32 condition
- ** Whether the section was copied successfully or not.
- ** UINT8* buffer
- ** The buffer containing the data. NOT USED
- ** UINT32 length
- ** The total number of bytes copied. NOT USED
- ** void *tag
- ** The section data identifier passed to the section copy
- ** routine by the header notify callback. Indicates which
- ** section the data belongs to.
- **
- ** Modified None
- **
- ** Return Nothing
- **
- *****************************************************************************/
- static void SISectionCopied( INT32 condition, UINT8 *buffer, UINT32 length, void *tag)
- {
- KB_OSPMsgNode message;
- T_SubTableFilter *filter;
- T_SubTableID subTableID;
- UINT32 filterNumber;
- MepgData *sectionData;
- UINT32 channelID;
- UINT32 sectionNumber;
- UINT8 nitbuffer[300];
- UINT32 i;
- int nIsMulti = 0;
- int nCurrentNo;
- sectionData = (MepgData*)tag;
- /* Validate the tag */
- if( (sectionData < &SISectionSmallData[0] ||
- sectionData > &SISectionSmallData[SI_MAX_SECTION_SMALL_DATA]) &&
- (sectionData < &SISectionLargeData[0] ||
- sectionData > &SISectionLargeData[SI_MAX_SECTION_LARGE_DATA]) )
- {
- J_SI_Print("[SI] Near Fatal Error: Tag invalid: %x (%d %x %d)n",
- (int)tag, (int)condition, (int)buffer, (int)length );
- return;
- }
- subTableID = sectionData->subTableID;
- if(subTableID==NITSubTableID)
- {
-
- if (TFReceiveNitFlag == TRUE)
- {
- KB_CASetNIT(buffer,length);
- TFReceiveNitFlag = FALSE;
- }
- else
- {
- for(i=0;i<length;i++)
- {
- if (buffer[i] == 0xa1 && buffer[i+1] == 0x2B && buffer[i+2] ==0x00 && buffer[i+3] ==0xDF )
- {
- break;
- }
- }
- if (i<length-43)
- {
- memcpy(nitbuffer,&buffer[i],43);
- CA_CheckNit(nitbuffer, 43);
- }
- }
- }
-
- filterNumber = sectionData->filterNumber;
- filter = &SISubTable[subTableID].filter[filterNumber];
- channelID = SISubTable[subTableID].details.channelID;
-
- if(filter->tableIDExt == -1 && buffer[0] == 0x50)
- {
- nIsMulti = 1;
- }
-
- //End addition
- if(condition != DMX_AVAILABLE)
- {
- //if(!nIsMulti)
- J_SI_Print("[SI] Lost section %xn", (int)sectionData);
- if( SISubTable[subTableID].details.multipleSections == TRUE )
- {
- sectionNumber = buffer[6];
- if(filter->data.sectionData[sectionNumber] == sectionData)
- {
- filter->data.sectionData[sectionNumber] = SI_SECTION_NOT_RECEIVED;
- }
- }
- SIFreeSectionData(sectionData);
- return;
- }
- message.Word1 = SI_MSG_COPY;
- message.Word2/*sectionData*/ = (UINT32)sectionData;
- message.Word3/*handle*/ = filter->handle;
- message.Word4/*filterNumber*/ = filterNumber;
- if( KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK )
- {
- /* Error sending message so clean up section */
- SIFreeSectionData(sectionData);
- /*
- ** Since the section wasn't sent correctly, remove it from the received
- ** list. The total value has yet to be incremented, so we do not need to
- ** decrement it.
- */
- if(SISubTable[subTableID].details.multipleSections == TRUE)
- {
- sectionNumber = buffer[6];
- if(filter->data.sectionData[sectionNumber] == sectionData)
- {
- filter->data.sectionData[sectionNumber] = SI_SECTION_NOT_RECEIVED;
- }
- }
- }
- else
- {
- /*
- ** Check to see whether this sub-table is completed.
- */
- if(nIsMulti)
- {
- static int nMsgSent = 0; //SI_MSG_COMPLETED的消息已发出
- INT16 nServiceNum;
- int i, nDone = 1;
- nServiceNum = l_pstCurrMultiEinSchInfoPara->nServiceNum;
- for(i = 0; i < nServiceNum; i ++)
- {
- if(l_pstCurrMultiEinSchInfoPara->nTableDone[i][0] != 1)
- {
- nDone = 0;
- break;
- }
- }
- if(nDone)
- {
- if(!nMsgSent)
- {
- //所有的EIT schedule表接收完
- nMsgSent = 1;
- message.Word1 = SI_MSG_COMPLETED;
- /*
- ** Completed the sub-table, so reset the current filter to block
- ** all data and then inform the user.
- */
- SIFilterStopHelper(channelID, filter);
- KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message);
- }
- else
- { nMsgSent = 0;} //保证下一次接收完的正确判断
- }
- else
- nMsgSent = 0;
- return;
- }
- if( SISubTable[subTableID].details.multipleSections == TRUE )
- {
- /*
- ** The message has been successfully sent to the SI task, so we can now
- ** updated the section state to say it has been received.
- */
- sectionNumber = buffer[6];
- if( filter->data.sectionData[sectionNumber] == sectionData )
- {
- filter->data.sectionData[sectionNumber] = SI_SECTION_RECEIVED;
- }
- }
- /* 以下一段代码应该考虑去掉,因为在这里判断影响了程序的处理流程,不易修改 */
- if( SISubTable[subTableID].details.multipleSections == TRUE )
- {
- if(filter->data.received == filter->data.total)
- {
- if(subTableID == EITSubTableID && filterNumber < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT)
- {
- int i;
-
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if(l_pstCurrEinSchInfoPara[i]->handle == filter->handle)
- {
- nCurrentNo = i;
- break;
- }
- }
-
- if(l_pstCurrEinSchInfoPara[nCurrentNo]->nTableDone[1] == 0)
- {
- // 兼容前端系统只发table_id=50的情形
- if(buffer[13]/* last_table_id */ == 0x50)
- {
- l_pstCurrEinSchInfoPara[nCurrentNo]->nTableDone[1] = 1;
- }
- }
- if (filter->tableID == 0x50)
- {
- l_pstCurrEinSchInfoPara[nCurrentNo]->nTableDone[0] = 1;
- }
- else
- {
- if (filter->tableID == 0x51)
- {
- l_pstCurrEinSchInfoPara[nCurrentNo]->nTableDone[1] = 1;
- }
- }
- if(l_pstCurrEinSchInfoPara[nCurrentNo]->nTableDone[0] == 1 &&
- l_pstCurrEinSchInfoPara[nCurrentNo]->nTableDone[1] == 1)
- {
- message.Word1 = SI_MSG_COMPLETED;
-
- /*
- ** Completed the sub-table, so reset the current filter to block
- ** all data and then inform the user.
- */
-
- if (filter->tableID == 0x50)
- {
- SIFilterStopHelper(channelID, &SISubTable[EITSubTableID].filter[filterNumber]);
- filterNumber = SIGetFilterNum(EITSubTableID, 0x51, filter->tableIDExt);
- if (filterNumber != 0xFFFFFFFF)
- {
- SIFilterStopHelper(channelID, &SISubTable[EITSubTableID].filter[filterNumber]);
- }
- }
- else
- {
- if (filter->tableID == 0x51)
- {
- SIFilterStopHelper(channelID, &SISubTable[EITSubTableID].filter[filterNumber]);
- filterNumber = SIGetFilterNum(EITSubTableID, 0x50, filter->tableIDExt);
- if (filterNumber != 0xFFFFFFFF)
- {
- SIFilterStopHelper(channelID, &SISubTable[EITSubTableID].filter[filterNumber]);
- }
- }
- }
- KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) ;
-
- }
- }
- else
- {
- message.Word1 = SI_MSG_COMPLETED;
-
- /*
- ** Completed the sub-table, so reset the current filter to block
- ** all data and then inform the user.
- */
-
- SIFilterStopHelper(channelID, filter);
-
- KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) ;
-
- }
- }
- else
- {
- filter->data.received++;
- }
- }
- else
- {
- SIFilterStopHelper(channelID, filter);
- }
- }
- }
- static void SITask(void)
- {
- KB_OSPMsgNode message;
- MepgData *sectionData;
- T_SubTableID subTableID;
- INT32 status;
- while(TRUE)
- {
- status = KB_OSPMsgGet(l_nQueueId, KB_Wait, 0, (KB_OSPMsgNode *)&message);
- if(status != Ret_OK)
- {
- continue;
- }
- switch (message.Word1)
- {
- case SI_MSG_TIMER_TICK:
- SIHandleTimerTick();
- break;
- case SI_MSG_COPY:
- sectionData = (MepgData*)message.Word2/*sectionData*/;
- subTableID = sectionData->subTableID;
- /*
- ** Has the application made a new request.
- */
- #if 1
- if(message.Word3/*handle*/ != SISubTable[subTableID].filter[message.Word4/*filterNumber*/].handle)
- {
- J_SI_Print("message.Word3=%d, message.Word4/*filterNumber*/].handle=%dn",
- (int)message.Word3, (int)SISubTable[subTableID].filter[message.Word4/*filterNumber*/].handle);
-
-
- /* Check to ensure no buffers are left if the message is discarded */
- SIFreeSectionData(sectionData);
- if(subTableID == TDTSubTableID || subTableID == RSTSubTableID)
- {
- SISubTable[subTableID].filter[message.Word4/*filterNumber*/].enabled = FALSE;
- SISubTable[subTableID].filter[message.Word4/*filterNumber*/].used = FALSE;
- }
- break;
- }
- #endif
- /*
- ** Inform the user the section copy has completed
- */
- if( SISubTable[subTableID].sectionCallback != NULL )
- {
- SISubTable[subTableID].sectionCallback(sectionData);
- }
- if(subTableID == TDTSubTableID || subTableID == RSTSubTableID || subTableID == TOTSubTableID)
- {
- SISubTable[subTableID].filter[message.Word4/*filterNumber*/].enabled = FALSE;
- SISubTable[subTableID].filter[message.Word4/*filterNumber*/].used = FALSE;
- }
- break;
- case SI_MSG_COMPLETED:
- sectionData = (MepgData*)message.Word2/*sectionData*/;
- subTableID = sectionData->subTableID;
- /*
- ** Has the application made a new request.
- */
- if(message.Word3/*handle*/ != SISubTable[subTableID].filter[message.Word4/*filterNumber*/].handle)
- {
- J_SI_Print("[SI] handle difference message.Word3 = %ld message.Word4 = %ld handle = %ldn",
- message.Word3, message.Word4,
- SISubTable[subTableID].filter[message.Word4/*filterNumber*/].handle);
- break;
- }
- /*
- ** Inform the user the table has been completed.
- */
- if( SISubTable[subTableID].tableCallback != NULL )
- {
- SISubTable[subTableID].tableCallback(subTableID, message.Word4/*filterNumber*/, message.Word3/*handle*/);
- }
- break;
- case MSG_SI_PAT_RECEIVE:
- SIGetPAT();
- break;
- case MSG_SI_PAT_STOP_RECEIVE:
- SIStopPAT();
- break;
- case MSG_SI_NIT_RECEIVE:
- SIGetNIT();
- break;
- case MSG_SI_NIT_STOP_RECEIVE:
- SIStopNIT();
- break;
- case MSG_SI_PMT_RECEIVE:
- SIGetPmt(message.Word2);
- break;
- case MSG_SI_PMT_STOP_RECEIVE:
- SIStopPmt(message.Word2);
- break;
- case MSG_SI_SDT_RECEIVE:
- SIGetSDT();
- break;
- case MSG_SI_SDT_STOP_RECEIVE:
- SIStopSdt();
- break;
- case MSG_SI_BAT_RECEIVE:
- SIGetBat();
- break;
- case MSG_SI_BAT_STOP_RECEIVE:
- SIStopBat();
- break;
- case MSG_SI_EIT_PF_RECEIVE:
- SIGetEitPF(message.Word2);
- break;
- case MSG_SI_EIT_PF_STOP_RECEIVE:
- SIStopEitPF(message.Word2, message.Word3);
- break;
- case MSG_SI_EIT_SCHEDULE_RECEIVE:
- SIGetEitSCH(message.Word2);
- break;
- case MSG_SI_MULTI_EIT_SCHEDULE_RECEIVE:
- SIGetMultEitSCH();
- break;
- case MSG_SI_EIT_SCHEDULE_STOP_RECEIVE:
- SIStopEitSCH(message.Word2);
- break;
- case MSG_SI_MULTI_EIT_SCHEDULE_STOP_RECEIVE:
- SIStopMultEitSCH();
- break;
- case MSG_SI_TDT_RECEIVE:
- SIGetTDT();
- break;
- case MSG_SI_TDT_STOP_RECEIVE:
- SIStopTDT();
- break;
- case MSG_SI_CAT_RECEIVE:
- SIGetCAT();
- break;
- case MSG_SI_CAT_STOP_RECEIVE:
- SIStopCAT();
- break;
- case MSG_SI_RST_RECEIVE:
- SIGetRst();
- break;
- case MSG_SI_RST_STOP_RECEIVE:
- SIStopRst();
- break;
- case MSG_SI_TOT_RECEIVE:
- SIGetTOT();
- break;
- case MSG_SI_TOT_STOP_RECEIVE:
- SIStopTOT();
- break;
- case MSG_SI_EIT_SCHEDULE_SHIFT_RECEIVE:
- SIGetEitSCHShift(message.Word2, message.Word3);
- break;
- case MSG_SI_EIT_SCHEDULE_SHIFT_STOP_RECEIVE:
- SIStopEitSCHShift(message.Word2, message.Word3);
- break;
-
- default:
- J_SI_Print( "SI: Internal case state error. Line %dn", __LINE__ );
- break;
- }
- }
- }
- /*****************************************************************************
- **
- ** Part 2 - SubTable Parsing
- **
- *****************************************************************************/
- /****************************************************************************
- ** Function SISendTimerMessage
- **
- ** Description Timer callback. Called periodically as a timer tick. Generates
- ** messages to the SI Task informing it of the tick.
- **
- ** Input None
- **
- ** Modified None
- **
- ** Return Nothing
- **
- *****************************************************************************/
- static void SISendTimerMessage(void)
- {
- KB_OSPMsgNode message;
- message.Word1 = SI_MSG_TIMER_TICK;
- KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode*)&message);
- }
- extern void LED_ShowNum(int i);
- /****************************************************************************
- ** Function SIHandleTimerTick
- **
- ** Description Called by SI Task whenever an SI Tick occurs. Performs the
- ** following:
- ** o For each filter decrement the timer (if enabled)
- ** o If the timer expires:
- ** Generate the timeout callback (if present)
- ** Reset the timer (if requested by the callback)
- **
- ** Input None
- **
- ** Modified None
- **
- ** Return Nothing
- **
- *****************************************************************************/
- static void SIHandleTimerTick(void)
- {
- UINT32 i;
- /*
- ** Check each of the filters for a timeout.
- */
- for(i = 0; i < SICurrentFilter; i++)
- {
- if(SIFilters[i].version == -1 && SIFilters[i].timeout != -1)
- {
- #if 0
- DBGPrint("i = %d, o = %dn", i, SIFilters[i].timeout);
- #endif
- //LED_ShowNum((int)SIFilters[i].timeout);
- SIFilters[i].timeout--;
- if(SIFilters[i].timeout == 0)
- {
- /* Timer expired so call the associated callback if present */
- if(SIFilters[i].timeoutCallback != NULL)
- {
- SIFilters[i].timeout = SIFilters[i].timeoutCallback(i);
- }
- else
- {
- /*
- ** Since there is no timer callback associated disable the
- ** timeout
- */
- SIFilters[i].timeout = -1;
- }
- }
- }
- }
- }
- /****************************************************************************
- ** Function SIStoreText
- **
- ** Description Helper function for SI parsing which will take any DVB
- ** encoded text streams and store them, taking into account any
- ** control codes. This may be better performed by the applets or
- ** font engine.
- **
- ** Input UINT8* dst
- ** Pointer to the destination.
- ** UINT8* src
- ** Pointer to the source of the data
- ** UINT32 length
- ** Amount of data (in bytes) to copy.
- **
- ** Modified none
- **
- ** Return nothing
- **
- *****************************************************************************/
- static void SIStoreText(UINT8 *dst, UINT8 *src, UINT32 length)
- {
- INT32 nCharSet = 0x13; // 0x13 gb2312 0x11 unicode
- UINT16 gb2312_code;
- if(length == 0)
- {
- *dst = 0;
- return;
- }
-
- if(*src < 0x20)
- {
- nCharSet = *src;
- length--;
- src++;
- }
- while(length-- > 0)
- {
- if(nCharSet == 0x11)
- {
- if(length == 0)
- break;
- if(*src != 0)
- {
- gb2312_code = UnicodeToGB2312((UINT16)(*src * 0x100 + *(src+1)));
- length--;
- src += 2;
- if(gb2312_code)
- {
- *dst++ = (UINT8)(gb2312_code>>8);
- *dst++ = (UINT8)(gb2312_code & 0xFF);
- }
- else
- {
- *dst++ = ' ';
- *dst++ = ' ';
- }
- }
- else
- {
- length--;
- src++;
- if(*src >= 0x20 && *src < 0x7F)
- {
- *dst++ = *src++;
- }
- else
- {
- src++;
- }
- }
- continue;
- }
- if(*src < 0x20)
- {
- src++;
- continue;
- }
- if(*src > 0x7F)
- {
- if(length == 0)
- break;
- length--;
- *dst++ = *src++;
- *dst++ = *src++;
- continue;
- }
- *dst++ = *src++;
-
- }
- *dst = ' ';
- }
- /****************************************************************************
- **
- ** LIFO (Last-In First-Out)
- **
- ** The following set of functions implement a generic LIFO. The current
- ** implementation isn't very space efficient, however it is reasonably quick
- **
- ***************************************************************************/
- /****************************************************************************
- ** Function LIFOInitialize()
- **
- ** Description
- **
- ** Input none
- **
- ** Modified none
- **
- ** Return INT32 - Always LIFO_OK
- **
- *****************************************************************************/
- static INT32 LIFOInitialize(SIFIFO* lifo)
- {
- lifo->end = lifo->buffer + lifo->size;
- lifo->position = lifo->buffer;
- return LIFO_OK;
- }
- /****************************************************************************
- ** Function LIFOPush()
- **
- ** Description Place a new entry on the list
- **
- ** Input T_FIFODetails* - the list to use
- ** UINT32 - item to add
- **
- ** Modified none
- **
- ** Return INT32 -
- ** LIFO_OK - item added
- ** LIFO_FULL - no space left on the list
- **
- *****************************************************************************/
- static INT32 LIFOPush(SIFIFO* lifo, UINT32 newItem)
- {
- INT32 status = LIFO_OK;
- KB_OSPSemGet(semCritical, KB_Wait, 0);
-
- /* Check size */
- if(lifo->position == lifo->end)
- {
- status = LIFO_FULL;
- }
- else
- {
- /* Add item to list */
- *(lifo->position++) = newItem;
- }
- KB_OSPSemSet(semCritical);
- return status;
- }
- /****************************************************************************
- ** Function LIFOPop()
- **
- ** Description Get the next item from the list
- **
- ** Input T_FIFODetails* - the list to use
- **
- ** Modified UINT32 - item removed from list
- **
- ** Return INT32 -
- ** LIFO_OK - item removed
- ** LIFO_EMPTY - no items available
- **
- *****************************************************************************/
- static INT32 LIFOPop(SIFIFO* lifo, UINT32* item)
- {
- INT32 status = LIFO_OK;
- KB_OSPSemGet(semCritical, KB_Wait, 0);
- /* Check size */
- if(lifo->position == lifo->buffer)
- {
- status = LIFO_EMPTY;
- }
- else
- {
- /* Update pointers */
- lifo->position--;
- /* Get item from list */
- *item = *(lifo->position);
- }
- KB_OSPSemSet(semCritical);
- return status;
- }
- INT32 KB_SIGetPat(const KB_SIPatStruct* i_pstPat, INT32 nType, INT32 i_nVersionNumber)
- {
- KB_OSPMsgNode message;
-
- memset(l_pstPendingPatPara, 0, sizeof(PATINFO));
- l_pstPendingPatPara->handle = l_nHandle++;
- l_pstPendingPatPara->pstPat = (KB_SIPatStruct*)i_pstPat;
- l_pstPendingPatPara->nType = (UINT8)nType;
- if(nType == KB_SI_RECEIVE_CHANGE)
- l_pstPendingPatPara->nVersionNumber = (INT8)i_nVersionNumber;
- else
- l_pstPendingPatPara->nVersionNumber = -1;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_PAT_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopPat()
- {
- //KB_OSPMsgNode message;
- SIStopPAT();
-
- return 0;
- }
- INT32 KB_SIGetNit(UINT32 i_nNitPid, const KB_SINitStruct* i_pstNit, INT32 nType, INT32 i_nVersionNumber)
- {
- KB_OSPMsgNode message;
- memset(l_pstPendingNitPara, 0, sizeof(NITINFO));
- l_pstPendingNitPara->handle = l_nHandle++;
- l_pstPendingNitPara->nNitPid = (UINT16)i_nNitPid;
- l_pstPendingNitPara->pstNit = (KB_SINitStruct*)i_pstNit;
- l_pstPendingNitPara->nType = (UINT8)nType;
- if(nType == KB_SI_RECEIVE_CHANGE)
- l_pstPendingNitPara->nVersionNumber = (INT8)i_nVersionNumber;
- else
- l_pstPendingNitPara->nVersionNumber = -1;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_NIT_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopNit()
- {
- KB_OSPMsgNode message;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_NIT_STOP_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIGetPmt(INT32 i_nProgramMapPid, INT32 nSvcID, const KB_SIPmtStruct* i_pstPmt, INT32 nType, INT32 i_nVersionNumber)
- {
- KB_OSPMsgNode message;
- int i;
- for(i = 0; i < SI_NO_PMT_TABLES_QUEUE; i++)
- {
- if(l_pstPendingPmtPara[i]->nUsedFlag == 0)
- {
- memset(l_pstPendingPmtPara[i], 0, sizeof(PMTINFO));
- l_pstPendingPmtPara[i]->nUsedFlag = 1;
- l_pstPendingPmtPara[i]->handle = l_nHandle++;
- l_pstPendingPmtPara[i]->nProgramMapPid = (UINT16)i_nProgramMapPid;
- l_pstPendingPmtPara[i]->nSvcNO = (UINT16)nSvcID;
- l_pstPendingPmtPara[i]->pstPmt = (KB_SIPmtStruct*)i_pstPmt;
- l_pstPendingPmtPara[i]->nType = (UINT8)nType;
- if(nType == KB_SI_RECEIVE_CHANGE)
- l_pstPendingPmtPara[i]->nVersionNumber = (INT8)i_nVersionNumber;
- else
- l_pstPendingPmtPara[i]->nVersionNumber = -1;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_PMT_RECEIVE;
- message.Word2 = i;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- memset(l_pstPendingPmtPara[i], 0, sizeof(PMTINFO));
- return KB_SI_ERR_SEND_MESSAGE;
- }
- break;
- }
- }
- if(i == SI_NO_PMT_TABLES_QUEUE)
- {
- return KB_SI_ERR_TOO_MANY_PROGRAMS;
- }
- return 0;
- }
- INT32 KB_SIStopPmt(INT32 nSvcID)
- {
- //KB_OSPMsgNode message;
- SIStopPmt(nSvcID);
- return 0;
- }
- INT32 KB_SIGetSdt(INT32 nSvcID, INT32 i_nMaxServiceNum, const KB_SISdtStruct* i_pstSdt, INT32 nType, INT32 i_nVersionNumber)
- {
- KB_OSPMsgNode message;
- memset(l_pstPendingSdtPara, 0, sizeof(SDTINFO));
- l_pstPendingSdtPara->handle = l_nHandle++;
- l_pstPendingSdtPara->nSvcID = nSvcID;
- l_pstPendingSdtPara->nMaxServiceNum = (INT16)i_nMaxServiceNum;
- l_pstPendingSdtPara->pstSdt = (KB_SISdtStruct*)i_pstSdt;
- l_pstPendingSdtPara->nType = (UINT8)nType;
- if(nType & KB_SI_RECEIVE_CHANGE)
- l_pstPendingSdtPara->nVersionNumber = (INT8)i_nVersionNumber;
- else
- l_pstPendingSdtPara->nVersionNumber = -1;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_SDT_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopSdt()
- {
- KB_OSPMsgNode message;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_SDT_STOP_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIGetBat(INT32 nbatID, const KB_SIBatStruct* i_pstBat, INT32 nType, INT32 i_nVersionNumber)
- {
- KB_OSPMsgNode message;
- memset(l_pstPendingBatPara, 0, sizeof(BATINFO));
- l_pstPendingBatPara->handle = l_nHandle++;
- l_pstPendingBatPara->nBouquetId = nbatID;
- l_pstPendingBatPara->pstBat = (KB_SIBatStruct*)i_pstBat;
- l_pstPendingBatPara->nType = (UINT8)nType;
- if(nType & KB_SI_RECEIVE_CHANGE)
- l_pstPendingBatPara->nVersionNumber = (INT8)i_nVersionNumber;
- else
- l_pstPendingBatPara->nVersionNumber = -1;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_BAT_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopBat()
- {
- KB_OSPMsgNode message;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_BAT_STOP_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIGetEitPF(INT32 nSvcID, KB_SIEitTs eTs, const KB_SIEitPF* i_pstEitPresent, const KB_SIEitPF* i_pstEitFollow, INT32 nType, INT32 i_nVersionNumber)
- {
- KB_OSPMsgNode message;
- int i;
- INT32 nTableId;
- nTableId = 0;
- switch (eTs)
- {
- case KB_SI_EIT_CURRENT_TS:
- nTableId = 0x4e;
- break;
- case KB_SI_EIT_OTHER_TS:
- nTableId = 0x4f;
- break;
-
- default:
- break;
- }
- for(i = 0; i < SI_NO_EIT_PF_TABLES_QUEUE; i++)
- {
- if(l_pstPendingEitPFPara[i]->nUsedFlag == 0)
- {
- memset(l_pstPendingEitPFPara[i], 0, sizeof(EITPFINFO));
- l_pstPendingEitPFPara[i]->nUsedFlag = 1;
- l_pstPendingEitPFPara[i]->handle = l_nHandle++;
- l_pstPendingEitPFPara[i]->nSvcID = (UINT16)nSvcID;
- l_pstPendingEitPFPara[i]->pstEitPresent = (KB_SIEitPF*)i_pstEitPresent;
- l_pstPendingEitPFPara[i]->pstEitFollow = (KB_SIEitPF*)i_pstEitFollow;
- l_pstPendingEitPFPara[i]->nType = (UINT8)nType;
- l_pstPendingEitPFPara[i]->nTableId = (INT16)nTableId;
- if(nType == KB_SI_RECEIVE_CHANGE)
- l_pstPendingEitPFPara[i]->nVersionNumber = (INT8)i_nVersionNumber;
- else
- l_pstPendingEitPFPara[i]->nVersionNumber = -1;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_EIT_PF_RECEIVE;
- message.Word2 = i;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- memset(l_pstPendingEitPFPara[i], 0, sizeof(EITPFINFO));
- return KB_SI_ERR_SEND_MESSAGE;
- }
- break;
- }
- }
- if(i == SI_NO_EIT_PF_TABLES_QUEUE)
- {
- return KB_SI_ERR_TOO_MANY_PROGRAMS;
- }
- return 0;
- }
- INT32 KB_SIStopEitPF(INT32 nSvcID, KB_SIEitTs eTs)
- {
- INT32 i, nTableId = 0;
-
- switch (eTs)
- {
- case KB_SI_EIT_CURRENT_TS:
- nTableId = 0x4e;
- break;
- case KB_SI_EIT_OTHER_TS:
- nTableId = 0x4f;
- break;
-
- default:
- break;
- }
- if(nSvcID == -1)
- {
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i]));
- SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i].used = FALSE;
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- }
- }
- else
- {
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(l_pstCurrEitPFPara[i]->nUsedFlag == 1 &&
- l_pstCurrEitPFPara[i]->nSvcID == nSvcID
- && l_pstCurrEitPFPara[i]->nTableId == nTableId)
- {
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- break;
- }
- }
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i].enabled == TRUE &&
- SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i].tableIDExt == nSvcID)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i]));
- SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i].used = FALSE;
- break;
- }
- }
- }
- return 0;
- }
- INT32 KB_SIGetEitSCH(INT32 nSvcID, const KB_SIEitSch* i_pstEinSchInfo)
- {
- KB_OSPMsgNode message;
- int i;
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if (l_pstPendingEinSchInfoPara[i]->nUsedFlag == 0)
- {
- memset(l_pstPendingEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- l_pstPendingEinSchInfoPara[i]->nUsedFlag = 1;
- l_pstPendingEinSchInfoPara[i]->handle = l_nHandle++;
- l_pstPendingEinSchInfoPara[i]->nSvcID = nSvcID;
- l_pstPendingEinSchInfoPara[i]->pstEinSchInfo = (KB_SIEitSch*)i_pstEinSchInfo;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_EIT_SCHEDULE_RECEIVE;
- message.Word2 = i;
- break;
- }
- }
-
- if(i >= KB_SI_EIT_SCHEDULE_SERVICE_COUNT)
- {
- return KB_SI_ERR_TOO_MANY_PROGRAMS;
- }
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopEitSCH(INT32 nSvcID)
- {
- int i;
-
- if (nSvcID == KB_SI_STOP_ALL)
- {
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i++)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[i]));
- SISubTable[EITSubTableID].filter[i].used = FALSE;
- }
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- memset(l_pstCurrEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- }
- }
- else
- {
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i++)
- {
- if (SISubTable[EITSubTableID].filter[i].tableIDExt == nSvcID)
- {
- /* 注意:schedule中可能用到两个fileter,所以不能用break */
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[i]));
- SISubTable[EITSubTableID].filter[i].used = FALSE;
- }
- }
-
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if (l_pstCurrEinSchInfoPara[i]->nUsedFlag == 1
- && l_pstCurrEinSchInfoPara[i]->nSvcID == nSvcID)
- {
- memset(l_pstCurrEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- break;
- }
- }
- }
-
- return 0;
- }
- INT32 KB_SIGetTime(time_t* pTimeNode)
- {
- KB_OSPMsgNode message;
- SIStopTOT();
-
- memset(l_pstPendingTdtPara, 0, sizeof(TDTINFO));
- l_pstPendingTdtPara->handle = l_nHandle++;
- l_pstPendingTdtPara->ptCurrentTime = (time_t*)pTimeNode;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_TDT_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopTDT()
- {
- KB_OSPMsgNode message;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_TDT_STOP_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopTOT()
- {
- KB_OSPMsgNode message;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_TOT_STOP_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIGetTOT(KB_SITot* pTot)
- {
- return 0;
- }
- INT32 KB_SIGetCat(const KB_SICatStruct* pCatNode, INT32 nType, INT32 i_nVersionNumber)
- {
- KB_OSPMsgNode message;
- memset(l_pstPendingCatPara, 0, sizeof(CATINFO));
- l_pstPendingCatPara->handle = l_nHandle++;
- l_pstPendingCatPara->pstCat = (KB_SICatStruct*)pCatNode;
- l_pstPendingCatPara->nType = (UINT8)nType;
- if(nType & KB_SI_RECEIVE_CHANGE)
- l_pstPendingCatPara->nVersionNumber = (INT8)i_nVersionNumber;
- else
- l_pstPendingCatPara->nVersionNumber = -1;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_CAT_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopCat()
- {
- //KB_OSPMsgNode message;
- SIStopCAT();
-
- return 0;
- }
- INT32 KB_SIGetRst(INT32 nMaxEvent, const KB_SIRstStruct* i_pstRst)
- {
- KB_OSPMsgNode message;
- memset(l_pstPendingRstPara, 0, sizeof(RSTINFO));
- l_pstPendingRstPara->handle = l_nHandle++;
- l_pstPendingRstPara->nMaxEventStatusNum = (INT16)nMaxEvent;
- l_pstPendingRstPara->pstRst = (KB_SIRstStruct*)i_pstRst;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_RST_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- INT32 KB_SIStopRst()
- {
- KB_OSPMsgNode message;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_RST_STOP_RECEIVE;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- static INT32 SIGetPAT()
- {
- memcpy(l_pstCurrPatPara, l_pstPendingPatPara, sizeof(PATINFO));
- l_pstCurrPatPara->nCurrVersionNumber = -1;
- l_pstCurrPatPara->nUsedFlag = 1;
- SISubTableStart(PATSubTableID, 0, l_pstCurrPatPara->nVersionNumber, l_pstCurrPatPara->handle);
- return 0;
- }
- static INT32 SIStopPAT()
- {
- SISubTableStop(PATSubTableID);
- memset(l_pstCurrPatPara, 0, sizeof(PATINFO));
- return 0;
- }
- INT32 SIGetNIT()
- {
- memcpy(l_pstCurrNitPara, l_pstPendingNitPara, sizeof(NITINFO));
- l_pstCurrNitPara->nCurrVersionNumber = -1;
- l_pstCurrNitPara->nUsedFlag = 1;
- SISubTableStart(NITSubTableID, 0, l_pstCurrNitPara->nVersionNumber, l_pstCurrNitPara->handle);
- return 0;
- }
- static INT32 SIStopNIT()
- {
- SISubTableStop(NITSubTableID);
- memset(l_pstCurrNitPara, 0, sizeof(NITINFO));
- return 0;
- }
- static INT32 SIGetPmt(INT32 nPendingNo)
- {
- KB_OSPMsgNode message;
- UINT32 i, j;
- INT8 done;
- INT32 nTempProgramNumber;
- INT32 nCurrNo = 0;
- INT32 nTempEnabled;
-
- if(l_pstPendingPmtPara[nPendingNo]->nType == KB_SI_RECEIVE_CHANGE)
- {
- nTempProgramNumber = -1;
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if(l_pstCurrPmtPara[i]->nUsedFlag == 1 &&
- l_pstCurrPmtPara[i]->nType == KB_SI_RECEIVE_CHANGE)
- {
- nTempProgramNumber = l_pstCurrPmtPara[i]->nSvcNO;
- memset(l_pstCurrPmtPara[i], 0, sizeof(PMTINFO));
- break;
- }
- }
- if(i < SI_NO_PMT_TABLES)
- {
- done = 0;
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- for(j = 0; j < SISubTable[PMTSubTableID[i]].details.noFilters; j++)
- {
- if(SISubTable[PMTSubTableID[i]].filter[j].enabled == TRUE &&
- SISubTable[PMTSubTableID[i]].filter[j].tableIDExt == nTempProgramNumber)
- {
- SIFilterStop(SISubTable[PMTSubTableID[i]].details.channelID, &(SISubTable[PMTSubTableID[i]].filter[j]));
- done = 1;
- break;
- }
- }
- if(done)
- break;
- }
- }
- }
- done = 0;
- nTempProgramNumber = l_pstPendingPmtPara[nPendingNo]->nSvcNO;
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if(l_pstCurrPmtPara[i]->nUsedFlag == 1 &&
- l_pstCurrPmtPara[i]->nSvcNO == nTempProgramNumber)
- {
- memset(l_pstCurrPmtPara[i], 0, sizeof(PMTINFO));
- break;
- }
- }
- if(i < SI_NO_PMT_TABLES)
- {
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- for(j = 0; j < SISubTable[PMTSubTableID[i]].details.noFilters; j++)
- {
- if(SISubTable[PMTSubTableID[i]].filter[j].enabled == TRUE &&
- SISubTable[PMTSubTableID[i]].filter[j].tableIDExt == nTempProgramNumber)
- {
- SIFilterStop(SISubTable[PMTSubTableID[i]].details.channelID, &(SISubTable[PMTSubTableID[i]].filter[j]));
- done = 1;
- break;
- }
- }
- if(done)
- break;
- }
- }
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if(l_pstCurrPmtPara[i]->nUsedFlag == 0)
- {
- break;
- }
- }
- if(i == SI_NO_PMT_TABLES)
- {
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_PMT_RECEIVE;
- message.Word2 = nPendingNo;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- memset(l_pstPendingPmtPara[nPendingNo], 0, sizeof(PMTINFO));
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- done = 0;
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- for(j = 0; j < SISubTable[PMTSubTableID[i]].details.noFilters; j++)
- {
- if(SISubTable[PMTSubTableID[i]].filter[j].enabled == TRUE &&
- SISubTable[PMTSubTableID[i]].details.PID == l_pstPendingPmtPara[nPendingNo]->nProgramMapPid)
- {
- if(i > 0)
- {
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_PMT_RECEIVE;
- message.Word2 = nPendingNo;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- memset(l_pstPendingPmtPara[nPendingNo], 0, sizeof(PMTINFO));
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- done = 1;
- break;
- }
- }
- if(done == 1)
- break;
- }
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if(l_pstCurrPmtPara[i]->nUsedFlag == 0)
- {
- memcpy(l_pstCurrPmtPara[i], l_pstPendingPmtPara[nPendingNo], sizeof(PMTINFO));
- memset(l_pstPendingPmtPara[nPendingNo], 0, sizeof(PMTINFO));
- l_pstCurrPmtPara[i]->nCurrVersionNumber = -1;
- l_pstCurrPmtPara[i]->nUsedFlag = 1;
- nCurrNo = i;
- break;
- }
- }
- nTempEnabled = FALSE;
- for(j = 0; j < SISubTable[PMTSubTableID[0]].details.noFilters; j++)
- {
- if(SISubTable[PMTSubTableID[0]].filter[j].enabled == TRUE)
- {
- nTempEnabled = TRUE;
- break;
- }
- }
- if(nTempEnabled == TRUE &&
- SISubTable[PMTSubTableID[0]].details.PID == l_pstCurrPmtPara[nCurrNo]->nProgramMapPid)
- {
- for(j = 0; j < SISubTable[PMTSubTableID[0]].details.noFilters; j++)
- {
- if(SISubTable[PMTSubTableID[0]].filter[j].enabled == FALSE)
- {
- SISubTable[PMTSubTableID[0]].details.tableIDExt = l_pstCurrPmtPara[nCurrNo]->nSvcNO;
- SISubTable[PMTSubTableID[0]].details.PID = l_pstCurrPmtPara[nCurrNo]->nProgramMapPid;
- SISubTableStart(PMTSubTableID[0], j, l_pstCurrPmtPara[nCurrNo]->nVersionNumber, l_pstCurrPmtPara[nCurrNo]->handle);
- break;
- }
- }
- }
- else
- {
- INT32 nStart = 0;
- if(nTempEnabled == TRUE)
- {
- nStart = 1;
- }
- for(i = nStart; i < SI_NO_PMT_TABLES; i++)
- {
- if(SISubTable[PMTSubTableID[i]].filter[0].enabled == FALSE)
- {
- /* Start the PMT filtering. */
- SISubTable[PMTSubTableID[i]].details.tableIDExt = l_pstCurrPmtPara[nCurrNo]->nSvcNO;
- SISubTable[PMTSubTableID[i]].details.PID = l_pstCurrPmtPara[nCurrNo]->nProgramMapPid;
- SISubTableStart(PMTSubTableID[i], 0, l_pstCurrPmtPara[nCurrNo]->nVersionNumber, l_pstCurrPmtPara[nCurrNo]->handle);
- break;
- }
- }
- }
- return 0;
- }
- static INT32 SIStopPmt(INT32 nSvcID)
- {
- UINT32 i, j;
- INT8 done = 0;
- if(nSvcID == -1)
- {
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- SISubTableStop(PMTSubTableID[i]);
- memset(l_pstCurrPmtPara[i], 0, sizeof(PMTINFO));
- }
- }
- else
- {
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if(l_pstCurrPmtPara[i]->nUsedFlag == 1 &&
- l_pstCurrPmtPara[i]->nSvcNO == nSvcID)
- {
- memset(l_pstCurrPmtPara[i], 0, sizeof(PMTINFO));
- break;
- }
- }
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- for(j = 0; j < SISubTable[PMTSubTableID[i]].details.noFilters; j++)
- {
- if(SISubTable[PMTSubTableID[i]].filter[j].enabled == TRUE &&
- SISubTable[PMTSubTableID[i]].filter[j].tableIDExt == nSvcID)
- {
- SIFilterStop(SISubTable[PMTSubTableID[i]].details.channelID, &(SISubTable[PMTSubTableID[i]].filter[j]));
- done = 1;
- break;
- }
- }
- if(done)
- break;
- }
- }
- return 0;
- }
- static INT32 SIGetSDT()
- {
- memcpy(l_pstCurrSdtPara, l_pstPendingSdtPara, sizeof(SDTINFO));
- l_pstCurrSdtPara->nCurrVersionNumber = -1;
- l_pstCurrSdtPara->nUsedFlag = 1;
- SISubTable[SDTSubTableID].details.tableID = 0x42;
- SISubTable[SDTSubTableID].details.tableIDExt = -1;
- SISubTableStart(SDTSubTableID, 0, l_pstCurrSdtPara->nVersionNumber, l_pstCurrSdtPara->handle);
- return 0;
- }
- static INT32 SIStopSdt()
- {
- SIFilterStop(SISubTable[SDTSubTableID].details.channelID, &(SISubTable[SDTSubTableID].filter[0]));
- memset(l_pstCurrSdtPara, 0, sizeof(SDTINFO));
- return 0;
- }
- static INT32 SIGetBat()
- {
- memcpy(l_pstCurrBatPara, l_pstPendingBatPara, sizeof(BATINFO));
- l_pstCurrBatPara->nCurrVersionNumber = -1;
- l_pstCurrBatPara->nUsedFlag = 1;
- SISubTable[SDTSubTableID].details.tableID = 0x4A;
- SISubTable[SDTSubTableID].details.tableIDExt = l_pstCurrBatPara->nBouquetId;
- SISubTableStart(SDTSubTableID, 1, l_pstCurrBatPara->nVersionNumber, l_pstCurrBatPara->handle);
- return 0;
- }
- static INT32 SIStopBat()
- {
- SIFilterStop(SISubTable[SDTSubTableID].details.channelID, &(SISubTable[SDTSubTableID].filter[1]));
- memset(l_pstCurrBatPara, 0, sizeof(BATINFO));
- return 0;
- }
- static INT32 SIGetEitPF(INT32 nPendingNo)
- {
- KB_OSPMsgNode message;
- INT32 i;
- INT32 nTempServiceId = 0;
- INT32 nCurrNo = 0;
-
- if(l_pstPendingEitPFPara[nPendingNo]->nType == KB_SI_RECEIVE_CHANGE)
- {
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(l_pstCurrEitPFPara[i]->nUsedFlag == 1 &&
- l_pstCurrEitPFPara[i]->nType == KB_SI_RECEIVE_CHANGE)
- {
- nTempServiceId = l_pstCurrEitPFPara[i]->nSvcID;
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- break;
- }
- }
- if(i < SI_NO_EIT_PF_FILTERS)
- {
- for(i = KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i < SI_NO_EIT_PF_FILTERS + KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i++)
- {
- if(SISubTable[EITSubTableID].filter[i].enabled == TRUE &&
- SISubTable[EITSubTableID].filter[i].tableIDExt == nTempServiceId
- && SISubTable[EITSubTableID].filter[i].tableID == l_pstPendingEitPFPara[nPendingNo]->nTableId)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[i]));
- break;
- }
- }
- }
- }
- nTempServiceId = l_pstPendingEitPFPara[nPendingNo]->nSvcID;
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(l_pstCurrEitPFPara[i]->nUsedFlag == 1 &&
- l_pstCurrEitPFPara[i]->nSvcID == nTempServiceId)
- {
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- break;
- }
- }
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(l_pstCurrEitPFPara[i]->nUsedFlag == 0)
- {
- memcpy(l_pstCurrEitPFPara[i], l_pstPendingEitPFPara[nPendingNo], sizeof(EITPFINFO));
- memset(l_pstPendingEitPFPara[nPendingNo], 0, sizeof(EITPFINFO));
- l_pstCurrEitPFPara[i]->nCurrVersionNumber = -1;
- l_pstCurrEitPFPara[i]->nUsedFlag = 1;
- nCurrNo = i;
- break;
- }
- }
- if(i == SI_NO_EIT_PF_FILTERS)//无可用空间
- {
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_EIT_PF_RECEIVE;
- message.Word2 = nPendingNo;
-
- if(KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&message) != Ret_OK)
- {
- memset(l_pstPendingEitPFPara[nPendingNo], 0, sizeof(EITPFINFO));
- return KB_SI_ERR_SEND_MESSAGE;
- }
- return 0;
- }
- for(i = KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i < SI_NO_EIT_PF_FILTERS + KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i++)
- {
- if(SISubTable[EITSubTableID].filter[i].used == FALSE)
- {
- SISubTable[EITSubTableID].details.tableID = l_pstCurrEitPFPara[nCurrNo]->nTableId;
- SISubTable[EITSubTableID].details.timeout = J_SI_EIT_PF_TIMEOUT;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEitPFPara[nCurrNo]->nSvcID;
- SISubTableStart(EITSubTableID, i, l_pstCurrEitPFPara[nCurrNo]->nVersionNumber, l_pstCurrEitPFPara[nCurrNo]->handle);
- break;
- }
- }
- return 0;
- }
- static INT32 SIStopEitPF(INT32 nSvcID, INT32 nTableId)
- {
- INT32 i;
- if(nSvcID == -1)
- {
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i]));
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- }
- }
- else
- {
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(l_pstCurrEitPFPara[i]->nUsedFlag == 1 &&
- l_pstCurrEitPFPara[i]->nSvcID == nSvcID
- && l_pstCurrEitPFPara[i]->nTableId == nTableId)
- {
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- break;
- }
- }
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i].enabled == TRUE &&
- SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i].tableIDExt == nSvcID)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + i]));
- break;
- }
- }
- }
- return 0;
- }
- static INT32 SIGetEitSCH(UINT32 nPendingNo)
- {
- int i, nCurrentParaNum;
- KB_OSPMsgNode msgNode;
-
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if(l_pstCurrEinSchInfoPara[i]->nUsedFlag == 0)
- {
- memcpy(l_pstCurrEinSchInfoPara[i], l_pstPendingEinSchInfoPara[nPendingNo], sizeof(EITSCHINFO));
- l_pstCurrEinSchInfoPara[i]->nCurrVersionNumber = -1;
- l_pstCurrEinSchInfoPara[i]->nUsedFlag = 1;
- //memset(l_pstCurrEinSchInfoPara[i]->pstEinSchInfo, 0, sizeof(KB_SIEitSch));
- l_pstCurrEinSchInfoPara[i]->pstEinSchInfo->num = 0;
- nCurrentParaNum = i;
- #if 0
- DBGPrint("[j_sipsi.c] i = %d ServiceId = %dn", i, l_pstCurrEinSchInfoPara[i]->nSvcID);
- #endif
- break;
- }
- }
- if (i >= KB_SI_EIT_SCHEDULE_SERVICE_COUNT)
- {
- memset(&msgNode, 0, sizeof(KB_OSPMsgNode));
- msgNode.Word1 = MSG_SI_EIT_SCHEDULE_RECEIVE;
- msgNode.Word2 = nPendingNo;
- KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&msgNode);
- }
- /* 把当前pending结构清零 */
- memset(l_pstPendingEinSchInfoPara[nPendingNo], 0, sizeof(EITSCHINFO));
-
-
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i++)
- {
- if (SISubTable[EITSubTableID].filter[i].used == FALSE)
- {
- SISubTable[EITSubTableID].details.tableID = 0x50;
- SISubTable[EITSubTableID].details.timeout = J_SI_EIT_SCHEDULE_TIMEOUT;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEinSchInfoPara[nCurrentParaNum]->nSvcID;
- SISubTableStart(EITSubTableID, i, -1, l_pstCurrEinSchInfoPara[nCurrentParaNum]->handle);
- break;
- }
- }
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i++)
- {
- if (SISubTable[EITSubTableID].filter[i].used == FALSE)
- {
- SISubTable[EITSubTableID].details.tableID = 0x51;
- SISubTable[EITSubTableID].details.timeout = J_SI_EIT_SCHEDULE_TIMEOUT;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEinSchInfoPara[nCurrentParaNum]->nSvcID;
- SISubTableStart(EITSubTableID, i, -1, l_pstCurrEinSchInfoPara[nCurrentParaNum]->handle);
- break;
- }
- }
- return 0;
- }
- static INT32 SIStopEitSCH(INT32 nSvcID)
- {
- int i;
-
- if (nSvcID == KB_SI_STOP_ALL)
- {
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i++)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[i]));
- }
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- memset(l_pstCurrEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- }
- }
- else
- {
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT; i++)
- {
- if (SISubTable[EITSubTableID].filter[i].tableIDExt == nSvcID)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[i]));
- }
- }
-
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if (l_pstCurrEinSchInfoPara[i]->nUsedFlag == 1
- && l_pstCurrEinSchInfoPara[i]->nSvcID == nSvcID)
- {
- memset(l_pstCurrEinSchInfoPara[i], 0, sizeof(EITSCHINFO));
- break;
- }
- }
- }
-
- return 0;
- }
- INT32 SIGetTDT()
- {
- memcpy(l_pstCurrTdtPara, l_pstPendingTdtPara, sizeof(TDTINFO));
- l_pstCurrTdtPara->nUsedFlag = 1;
- SISubTableStart(TDTSubTableID, 0, -1, l_pstCurrTdtPara->handle);
- return 0;
- }
- static INT32 SIStopTDT()
- {
- SISubTableStop(TDTSubTableID);
- memset(l_pstCurrTdtPara, 0, sizeof(TDTINFO));
- return 0;
- }
- INT32 SIGetTOT()