sipsi.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:168k
- {
- memcpy(l_pstCurrTotPara, l_pstPendingTotPara, sizeof(TOTINFO));
- l_pstCurrTotPara->nUsedFlag = 1;
- SISubTableStart(TOTSubTableID, 0, -1, l_pstCurrTotPara->handle);
- return 0;
- }
- static INT32 SIStopTOT()
- {
- SISubTableStop(TOTSubTableID);
- memset(l_pstCurrTotPara, 0, sizeof(TOTINFO));
- return 0;
- }
- INT32 SIGetCAT()
- {
- memcpy(l_pstCurrCatPara, l_pstPendingCatPara, sizeof(CATINFO));
- l_pstCurrCatPara->nCurrVersionNumber = -1;
- l_pstCurrCatPara->nUsedFlag = 1;
- SISubTableStart(CATSubTableID, 0, l_pstCurrCatPara->nVersionNumber, l_pstCurrCatPara->handle);
- return 0;
- }
- static INT32 SIStopCAT()
- {
- SISubTableStop(CATSubTableID);
- memset(l_pstCurrCatPara, 0, sizeof(CATINFO));
- return 0;
- }
- INT32 SIGetRst()
- {
- memcpy(l_pstCurrRstPara, l_pstPendingRstPara, sizeof(RSTINFO));
- l_pstCurrRstPara->nUsedFlag = 1;
- SISubTableStart(RSTSubTableID, 0, -1, l_pstCurrRstPara->handle);
- return 0;
- }
- static INT32 SIStopRst()
- {
- SISubTableStop(RSTSubTableID);
- memset(l_pstCurrRstPara, 0, sizeof(RSTINFO));
- return 0;
- }
- static void SIParsePAT(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- INT32 dataLength;
- KB_SIPatStruct* pstPat;
- INT32 i;
- INT8 version_number;
- INT32 nOldNum;
-
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- if(l_pstCurrPatPara->handle != filter->handle)
- {
- SIFreeSectionData(section);
- return;
- }
- pInData = section->data;
- dataLength = section->length;
- pstPat = l_pstCurrPatPara->pstPat;
- version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- if(l_pstCurrPatPara->nCurrVersionNumber == -1)
- {
- l_pstCurrPatPara->nCurrVersionNumber = version_number;
- memset(pstPat, 0, sizeof(KB_SIPatStruct));
- }
- else if(l_pstCurrPatPara->nCurrVersionNumber != version_number)
- {
- SIFreeSectionData(section);
- l_pstCurrPatPara->handle = l_nHandle++;
- l_pstCurrPatPara->nCurrVersionNumber = -1;
- SISubTableStart(PATSubTableID, 0, l_pstCurrPatPara->nVersionNumber, l_pstCurrPatPara->handle);
- return;
- }
-
- pstPat->transport_stream_id = (UINT16)(pInData[3] * 0x100 + pInData[4]);
- pstPat->version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- pInData += 8;
- dataLength -= 8;
- if( dataLength <= 0 )
- {
- SIFreeSectionData(section);
- return;
- }
- nOldNum = pstPat->num;
- pstPat->num += (UINT16)(dataLength / 4);
- if(pstPat->num > KB_SI_MAX_PAT_PROGRAM_NUM)
- {
- pstPat->num = KB_SI_MAX_PAT_PROGRAM_NUM;
- }
- for(i = 0; i < pstPat->num - nOldNum; i++)
- {
- pstPat->program[i + nOldNum].program_number = (UINT16)(pInData[i * 4] * 0x100 + pInData[i * 4 + 1]);
- pstPat->program[i + nOldNum].program_map_PID = (UINT16)((pInData[i * 4 + 2] * 0x100 + pInData[i * 4 + 3]) & 0x1FFF);
- }
- pInData += dataLength;
- pstPat->CRC_32 = (UINT32)pInData[0] * 0x1000000 + (UINT32)pInData[1] * 0x10000 + (UINT32)pInData[2] * 0x100 + (UINT32)pInData[3];
- SIFreeSectionData(section);
- }
- static void SIParseNIT(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- UINT8 *endPtr;
- INT32 dataLength;
- KB_SINitStruct* pstNit;
- INT32 network_descriptors_length;
- INT32 transport_stream_loop_length;
- INT8 version_number;
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- if(l_pstCurrNitPara->handle != filter->handle)
- {
- SIFreeSectionData(section);
- return;
- }
- pInData = section->data;
- dataLength = section->length;
- pstNit = l_pstCurrNitPara->pstNit;
- version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- if(l_pstCurrNitPara->nCurrVersionNumber == -1)
- {
- l_pstCurrNitPara->nCurrVersionNumber = version_number;
- memset(pstNit, 0, sizeof(KB_SINitStruct));
- }
- else if(l_pstCurrNitPara->nCurrVersionNumber != version_number)
- {
- SIFreeSectionData(section);
- l_pstCurrNitPara->handle = l_nHandle++;
- l_pstCurrNitPara->nCurrVersionNumber = -1;
- /* Start the NIT filtering. */
- SISubTableStart(NITSubTableID, 0, l_pstCurrNitPara->nVersionNumber, l_pstCurrNitPara->handle);
- return;
- }
-
- pstNit->network_id = (UINT16)(pInData[3] * 0x100 + pInData[4]);
- pstNit->version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- /*
- ** Skip past the standard SI Table header (contains tableID, section Length, etc)
- */
- pInData += 8;
- dataLength -= 8;
- if( dataLength <= 0 )
- {
- SIFreeSectionData(section);
- return;
- }
- network_descriptors_length = ((INT32)pInData[0] * 0x100 + (INT32)pInData[1]) & 0x0FFF;
- pInData += 2;
- SINITDescs(pInData, network_descriptors_length, pstNit);
- pInData += network_descriptors_length;
- transport_stream_loop_length = ((INT32)pInData[0] * 0x100 + (INT32)pInData[1]) & 0x0FFF;
- pInData += 2;
- endPtr = pInData + transport_stream_loop_length;
- while( pInData < endPtr && pstNit->num < KB_SI_MAX_NIT_CHANNEL_NUM)
- {
- int transport_descriptors_length;
- pstNit->network[pstNit->num].transport_stream_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- pstNit->network[pstNit->num].original_network_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- transport_descriptors_length = (pInData[0] * 0x100 + pInData[1]) & 0x0FFF;
- pInData += 2;
- SINITDescs(pInData, transport_descriptors_length, pstNit);
- pInData += transport_descriptors_length;
- pstNit->num++;
- }
- pInData = endPtr;
- pstNit->CRC_32 = (UINT32)pInData[0] * 0x1000000 + (UINT32)pInData[1] * 0x10000 + (UINT32)pInData[2] * 0x100 + (UINT32)pInData[3];
- SIFreeSectionData(section);
- }
- static void SIParsePMT(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- INT32 dataLength;
- KB_SIPmtStruct* pstPmt = NULL;
- UINT32 program_info_length;
- UINT32 ES_info_length;
- INT32 i;
- INT8 version_number;
-
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- pInData = section->data;
- dataLength = section->length;
- //cCopyFlag = FALSE;
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if(l_pstCurrPmtPara[i]->handle == filter->handle &&
- l_pstCurrPmtPara[i]->nUsedFlag == 1 &&
- l_pstCurrPmtPara[i]->nSvcNO == filter->tableIDExt)
- {
- pstPmt = l_pstCurrPmtPara[i]->pstPmt;
- version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- if(l_pstCurrPmtPara[i]->nCurrVersionNumber == -1)
- {
- l_pstCurrPmtPara[i]->nCurrVersionNumber = version_number;
- memset(pstPmt, 0, sizeof(KB_SIPmtStruct));
- }
- else if(l_pstCurrPmtPara[i]->nCurrVersionNumber != version_number)
- {
- INT32 subTableID;
- subTableID = section->subTableID;
- SIFreeSectionData(section);
- l_pstCurrPmtPara[i]->handle = l_nHandle++;
- l_pstCurrPmtPara[i]->nCurrVersionNumber = -1;
- SISubTable[subTableID].details.tableIDExt = l_pstCurrPmtPara[i]->nSvcNO;
- SISubTable[subTableID].details.PID = l_pstCurrPmtPara[i]->nProgramMapPid;
- SISubTableStart(subTableID, 0, l_pstCurrPmtPara[i]->nVersionNumber, l_pstCurrPmtPara[i]->handle);
- return;
- }
- break;
- }
- }
- if(pstPmt == NULL)
- {
- SIFreeSectionData(section);
- return;
- }
- pstPmt->program_number = (UINT16)(pInData[3] * 0x100 + pInData[4]);
- pstPmt->version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- pInData += 8;
- dataLength -= 8;
- if( dataLength <= 0 )
- {
- SIFreeSectionData(section);
- return;
- }
- pstPmt->PCR_PID = (UINT16)((pInData[0] * 0x100 + pInData[1]) & 0x1FFF);
- program_info_length = ((UINT32)pInData[2] * 0x100 + (UINT32)pInData[3]) & 0x0FFF;
- pInData += 4;
- dataLength -= 4;
- SIPMTDescs(pInData, program_info_length, pstPmt, 0);
- pInData += program_info_length;
- dataLength -= program_info_length;
- while((dataLength > 0) && (pstPmt->num < KB_SI_MAX_PMT_STREAM_NUM)) //Modified by dts 2005-8-8
- {
- pstPmt->stream[pstPmt->num].stream_type = pInData[0];
- pstPmt->stream[pstPmt->num].elementary_PID = (UINT16)((pInData[1] * 0x100 + pInData[2]) & 0x1FFF);
- ES_info_length = ((UINT32)pInData[3] * 0x100 + (UINT32)pInData[4]) & 0x0FFF;
- pInData += 5;
- dataLength -= 5;
- SIPMTDescs(pInData, ES_info_length, pstPmt, 1);
- pInData += ES_info_length;
- dataLength -= ES_info_length;
- pstPmt->num++;
- }
- SIFreeSectionData(section);
- }
- static INT32 SIParseDuration(UINT8* pInData, UINT32* pOutDuration)
- {
- INT32 nHour, nMin, nSec;
- nHour = ((INT32)pInData[0] >> 4) * 10 + ((INT32)pInData[0] & 0x0F);
- nMin = ((INT32)pInData[1] >> 4) * 10 + ((INT32)pInData[1] & 0x0F);
- nSec = ((INT32)pInData[2] >> 4) * 10 + ((INT32)pInData[2] & 0x0F);
- *pOutDuration = nHour * 3600 + nMin * 60 + nSec;
- return 0;
- }
- static INT32 SIParseTime(UINT8* pInData, time_t* pOutTime)
- {
- UINT16 MJD;
- INT32 nYear, nYear1, nMon, nMon1, nDay, nHour, nMin, nSec, nAdjust;
- struct tm tm;
- memset(&tm, 0, sizeof(struct tm));
- MJD = (UINT16)(pInData[0] << 8) | (pInData[1]);
- nYear1 = (INT32)((MJD - 15078.2) / 365.25);
- nMon1 = (INT32)((MJD - 14956.1 - (INT32)(nYear1 * 365.25)) / 30.6001);
- nDay = (INT32)MJD - 14956 - (INT32)(nYear1 * 365.25) - (INT32)(nMon1 * 30.6001);
- nAdjust = 0;
- if(nMon1 == 14 || nMon1 == 15)
- {
- nAdjust = 1;
- }
- nYear = nYear1 + nAdjust + 1900;
- nMon = nMon1 - 1 - nAdjust * 12;
- nHour = ((INT32)pInData[2] >> 4) * 10 + ((INT32)pInData[2] & 0x0F);
- nMin = ((INT32)pInData[3] >> 4) * 10 + ((INT32)pInData[3] & 0x0F);
- nSec = ((INT32)pInData[4] >> 4) * 10 + ((INT32)pInData[4] & 0x0F);
- tm.tm_isdst = 0;
- tm.tm_year = (UINT16)(nYear - 1900);
- tm.tm_mon = (UINT16)(nMon - 1);
- tm.tm_mday = (UINT16)nDay;
- tm.tm_hour = (UINT16)nHour;
- tm.tm_min = (UINT16)nMin;
- tm.tm_sec = (UINT16)nSec;
- *(pOutTime) = mktime(&tm);
- return 0;
- }
- static void SIParseTDT(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- INT32 dataLength;
- KB_OSPMsgNode message;
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- if(l_pstCurrTdtPara->handle != filter->handle)
- {
- SIFreeSectionData(section);
- return;
- }
- pInData = section->data;
- dataLength = section->length;
- pInData += 3;
- dataLength -= 3;
- if(dataLength <= 0)
- {
- SIFreeSectionData(section);
- return;
- }
- if(l_pstCurrTdtPara->ptCurrentTime == NULL)
- {
- SIFreeSectionData(section);
- return;
- }
- SIParseTime(pInData, l_pstCurrTdtPara->ptCurrentTime);
- SIFreeSectionData(section);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_TDT_DONE;
- message.Word3 = (UINT32)l_pstCurrTdtPara->ptCurrentTime;
-
- KD_DTVSendMsg(&message);
- memset(l_pstCurrTdtPara, 0, sizeof(TDTINFO));
- }
- static void SIParseTOT(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData, *ptr;
- INT32 dataLength;
- KB_OSPMsgNode message;
- INT16 total_descriptor_length;
- UINT8 descriptor_length;
- UINT8 descriptor_tag;
- INT16 i;
- KB_SITot *pTot;
- UINT8 tmp;
- UINT8 count=0;
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- if(l_pstCurrTotPara->handle != filter->handle)
- {
- J_SI_Print("nerr1");
- SIFreeSectionData(section);
- return;
- }
- pInData = section->data;
- if(*pInData != 0x73)
- {
- J_SI_Print("nid %d",*pInData);
- return;
- }
- dataLength = section->length;
- pInData += 8;
- dataLength -= 8;
- if(dataLength <= 0)
- {
- J_SI_Print("nlen=%d",(int)dataLength);
- SIFreeSectionData(section);
- return;
- }
-
- if(l_pstCurrTotPara->pTot == NULL)
- {
- J_SI_Print("ntot null");
- SIFreeSectionData(section);
- return;
- }
-
- pTot = l_pstCurrTotPara->pTot;
- total_descriptor_length = (INT16)(*((INT16 *)pInData) & 0x0fff);
- pInData += 2;
- ptr = pInData;
- J_SI_Print("n");
- for(i=0;i<total_descriptor_length;i++)
- {
- J_SI_Print("%02x ",*pInData);
- pInData++;
- }
- pInData = ptr;
- while(total_descriptor_length >= 15)
- {
- descriptor_tag = *pInData;
- pInData++;
- descriptor_length = *pInData;
- pInData++;
- total_descriptor_length -= 2;
- if(descriptor_tag != KB_FILTER_SI_LOCAL_TIME_OFFSET)
- {
- total_descriptor_length -= descriptor_length;
- pInData += descriptor_length;
- continue;
- }
- if(descriptor_length != 13)
- {
- total_descriptor_length -= descriptor_length;
- pInData += descriptor_length;
- continue;
- }
- pTot->country_code[0] = *pInData;
- pInData++;
- pTot->country_code[1] = *pInData;
- pInData++;
- pTot->country_code[2] = *pInData;
- pInData++;
- tmp = *pInData;
- pInData++;
- pTot->country_region_id = (UINT8)((tmp >> 2) & 0x3f);
- pTot->polarity = (UINT8)(tmp & 1);
- pTot->local_time_offset = *((UINT16 *)pInData);
- pInData+=2;
- pInData+=7;
- total_descriptor_length -= 13;
- count++;
- if(count >= KB_SI_MAX_TOT_SECTION)
- break;
- }
- SIFreeSectionData(section);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_TOT_DONE;
- message.Word3 = (UINT32)l_pstCurrTotPara->pTot;
- message.Word4 = count;
- KD_DTVSendMsg(&message);
- memset(l_pstCurrTotPara, 0, sizeof(TOTINFO));
- }
- static void SIParseCAT(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- INT32 dataLength;
- KB_SICatStruct* pstCat;
- UINT8 version_number;
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- if(l_pstCurrCatPara->handle != filter->handle)
- {
- SIFreeSectionData(section);
- return;
- }
- pInData = section->data;
- dataLength = section->length;
- pstCat = l_pstCurrCatPara->pstCat;
- version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- if(l_pstCurrCatPara->nCurrVersionNumber == -1)
- {
- l_pstCurrCatPara->nCurrVersionNumber = version_number;
- memset(pstCat, 0, sizeof(KB_SICatStruct));
- }
- else if(l_pstCurrCatPara->nCurrVersionNumber != version_number)
- {
- SIFreeSectionData(section);
- l_pstCurrCatPara->handle = l_nHandle++;
- l_pstCurrCatPara->nCurrVersionNumber = -1;
- SISubTableStart(CATSubTableID, 0, l_pstCurrCatPara->nVersionNumber, l_pstCurrCatPara->handle);
- return;
- }
-
- pstCat->version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- pInData += 8;
- dataLength -= 8;
- if( dataLength <= 0 )
- {
- SIFreeSectionData(section);
- return;
- }
- SICATDescs(pInData, dataLength, pstCat);
- SIFreeSectionData(section);
- }
- static void SIParseRST(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- INT32 dataLength;
- KB_OSPMsgNode message;
- KB_SIRstStruct* pstRst;
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- if(l_pstCurrRstPara->handle != filter->handle)
- {
- SIFreeSectionData(section);
- return;
- }
- pInData = section->data;
- dataLength = section->length;
- pInData += 3;
- dataLength -= 3;
- if(dataLength <= 0)
- {
- SIFreeSectionData(section);
- return;
- }
- if(l_pstCurrRstPara->pstRst == NULL)
- {
- SIFreeSectionData(section);
- return;
- }
- l_pstCurrRstPara->nEventStatusNum = 0;
- while(dataLength > 0 &&
- l_pstCurrRstPara->nEventStatusNum < l_pstCurrRstPara->nMaxEventStatusNum)
- {
- pstRst = &l_pstCurrRstPara->pstRst[l_pstCurrRstPara->nEventStatusNum];
- memset(pstRst, 0, sizeof(KB_SIRstStruct));
- pstRst->transport_stream_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- dataLength -= 2;
- pstRst->original_network_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- dataLength -= 2;
- pstRst->service_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- dataLength -= 2;
- pstRst->event_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- dataLength -= 2;
- pstRst->running_status = (UINT8)(pInData[0] & 0x7);
- pInData++;
- dataLength--;
- l_pstCurrRstPara->nEventStatusNum++;
- }
-
- SIFreeSectionData(section);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_RST_DONE;
- message.Word3 = (UINT32)l_pstCurrRstPara->pstRst;
- message.Word4 = (UINT32)l_pstCurrRstPara->nEventStatusNum;
- KD_DTVSendMsg(&message);
- SISubTableStart(RSTSubTableID, 0, -1, l_pstCurrRstPara->handle);
- }
- static void SINITDescs( UINT8* pInData, INT32 dataLen, KB_SINitStruct* pstNit)
- {
- UINT8 *data;
- UINT8 tag;
- UINT8 length;
- UINT16 transport_stream_id;
- UINT16 original_network_id;
- UINT16 service_id;
- UINT8 linkage_type;
- UINT8 service_num;
-
- while( dataLen > 0 )
- {
- tag = *pInData++;
- length = *pInData++;
- data = pInData;
- pInData += length;
- dataLen -= ((INT32)length + 2);
- if(length == 0)
- continue;
- switch(tag)
- {
- case KB_FILTER_SI_NETWORK_NAME:
- SIStoreText(pstNit->network_name, data, ((length > KB_SI_MAX_NETWORK_NAME_LEN)
- ? KB_SI_MAX_NETWORK_NAME_LEN : length) );
- break;
- case KB_FILTER_SI_LINKAGE:
- transport_stream_id = (UINT16)(data[0] * 0x100 + data[1]);
- original_network_id = (UINT16)(data[2] * 0x100 + data[3]);
- service_id = (UINT16)(data[4] * 0x100 + data[5]);
- data += 6;
- linkage_type = data[0];
- data++;
- if(linkage_type == 0x84 && length >= 12) // 确保足够的长度
- {
- UINT8 descriptor_tag;
- UINT8 stbVersion;
- UINT8 Flags;
- UINT8 descriptor_length;
- descriptor_tag = data[0];
- data++;
- if(descriptor_tag == 0x81)
- {
- stbVersion = (UINT8)(data[0]>>2);
- Flags = (UINT8)(data[0] & 0x3);
- data++;
- if(Flags == 3)
- {
- INT32 i;
- UINT16 bouquet_id;
- descriptor_length = data[0];
- data++;
- for(i = 0; i < descriptor_length; i += 2)
- {
- bouquet_id = (UINT16)(data[i] * 0x100 + data[i+1]);
- if(bouquet_id == 0x0A)
- {
- pstNit->loader_flag = 1;
- pstNit->loader.transport_stream_id = transport_stream_id;
- pstNit->loader.original_network_id = original_network_id;
- pstNit->loader.service_id = service_id;
- pstNit->loader.stbVersion = stbVersion;
- break;
- }
- }
- }
- }
- }
- break;
- case KB_FILTER_SI_CABLE_DELIVERY:
- pstNit->network[pstNit->num].frequency = ((UINT32)data[0] >> 4) * 10000000 +
- ((UINT32)data[0] & 0x0F) * 1000000 +
- ((UINT32)data[1] >> 4) * 100000 +
- ((UINT32)data[1] & 0x0F) * 10000 +
- ((UINT32)data[2] >> 4) * 1000 +
- ((UINT32)data[2] & 0x0F) * 100 +
- ((UINT32)data[3] >> 4) * 10 +
- ((UINT32)data[3] & 0x0F) * 1;
- data += 4 + 1;
- pstNit->network[pstNit->num].FEC_outer = data[0] & 0x0F;
- data++;
- pstNit->network[pstNit->num].modulation = data[0];
- data++;
-
- pstNit->network[pstNit->num].symbol_rate = ((UINT32)data[0] >> 4) * 1000000 +
- ((UINT32)data[0] & 0x0F) * 100000 +
- ((UINT32)data[1] >> 4) * 10000 +
- ((UINT32)data[1] & 0x0F) * 1000 +
- ((UINT32)data[2] >> 4) * 100 +
- ((UINT32)data[2] & 0x0F) * 10 +
- ((UINT32)data[3] >> 4) * 1;
- data += 3;
- pstNit->network[pstNit->num].FEC_inner = data[0] & 0x0F;
- break;
- case KB_FILTER_SI_SERVICE_LIST:
- service_num = 0;
-
- while( data < pInData && service_num < KB_SI_MAX_CHANNEL_SERVIC_NUM)
- {
- pstNit->network[pstNit->num].service_list[service_num].service_id = (UINT16)(data[0] * 0x100 + data[1]);
- pstNit->network[pstNit->num].service_list[service_num].service_type = data[2];
- data +=3;
-
- service_num ++;
- }
- pstNit->network[pstNit->num].service_num = service_num;
- break;
- case KB_FILTER_SI_STUFFING:
- case KB_FILTER_SI_SATELLITE_DELIVERY:
- case KB_FILTER_SI_TERRESTRIAL_DELIVERY:
- case KB_FILTER_SI_MULTILINGUAL_NETWORK_NAME:
- case KB_FILTER_SI_PRIVATE_DATA_SPECIFIER:
- break;
- default:
- break;
- }
- }
- }
- static void SIPMTDescs(UINT8* pInData, INT32 dataLen, KB_SIPmtStruct* pstPmt, INT32 inLoop)
- {
- UINT8 *data;
- UINT32 tag;
- UINT8 length;
- UINT16 oldLength;
- while(dataLen >= 2)
- {
- tag = *pInData++;
- length = *pInData++;
- data = pInData;
- pInData += length;
- dataLen -= ((INT32)length + 2);
- if(length == 0)
- continue;
- switch(tag)
- {
- case KB_FILTER_SI_CA:
- if(!inLoop)
- {
- oldLength = pstPmt->CA_descriptor_buffer_len;
- pstPmt->CA_descriptor_buffer_len += (UINT16)(2 + length);
- if(pstPmt->CA_descriptor_buffer_len > KB_SI_MAX_CA_BUFFER_LEN)
- {
- pstPmt->CA_descriptor_buffer_len = KB_SI_MAX_CA_BUFFER_LEN;
- }
- memcpy(pstPmt->CA_descriptor + oldLength, data - 2, pstPmt->CA_descriptor_buffer_len - oldLength);
- }
- else
- {
- INT32 nCurrNo;
- nCurrNo = pstPmt->num;
- oldLength = pstPmt->stream[nCurrNo].CA_descriptor_buffer_len;
- pstPmt->stream[nCurrNo].CA_descriptor_buffer_len += (UINT16)(2 + length);
- if(pstPmt->stream[nCurrNo].CA_descriptor_buffer_len > KB_SI_MAX_CA_BUFFER_LEN)
- {
- pstPmt->stream[nCurrNo].CA_descriptor_buffer_len = KB_SI_MAX_CA_BUFFER_LEN;
- }
- memcpy(pstPmt->stream[nCurrNo].CA_descriptor + oldLength, data - 2, pstPmt->stream[nCurrNo].CA_descriptor_buffer_len - oldLength);
- }
- break;
- case KB_FILTER_SI_STREAM_IDENTIFIER:
- if(inLoop)
- {
- pstPmt->stream[pstPmt->num].component_tag = *data;
- }
- break;
- case KB_FILTER_SI_TELETEXT:
- case KB_FILTER_SI_SUBTITLING:
- case KB_FILTER_SI_LANGUAGE:
- case KB_FILTER_SI_COPYRIGHT:
- case KB_FILTER_SI_MOSAIC:
- case KB_FILTER_SI_PRIVATE_DATA_SPECIFIER:
- case KB_FILTER_SI_SERVICE_MOVE:
- case KB_FILTER_SI_CA_SYSTEM:
- case KB_FILTER_SI_DATA_BROADCAST_ID:
- break;
- default:
- break;
- }
- }
- }
- static void SIParseSDT(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- INT32 dataLength;
- KB_SISdtStruct stTempSdt;
- KB_SISdtStruct* pstSdt = NULL;
- KB_SIBatStruct* pstBat = NULL;
- UINT16 table_id_extension;
- UINT8 version_number;
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- if(filter->filterNumber == 0)
- {
- if(l_pstCurrSdtPara->handle != filter->handle)
- {
- SIFreeSectionData(section);
- return;
- }
- pstSdt = &stTempSdt;
- }
- else
- {
- if(l_pstCurrBatPara->handle != filter->handle)
- {
- SIFreeSectionData(section);
- return;
- }
- pstBat = &l_pstCurrBatPara->pstBat[l_pstCurrBatPara->nBatNumber];
- }
- pInData = section->data;
- dataLength = section->length;
-
- table_id_extension = (UINT16)(pInData[3] * 0x100 + pInData[4]);
- version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- if(filter->filterNumber == 0)
- {
- if(l_pstCurrSdtPara->nCurrVersionNumber == -1)
- {
- l_pstCurrSdtPara->nCurrVersionNumber = version_number;
- }
- else if(l_pstCurrSdtPara->nCurrVersionNumber != version_number)
- {
- SIFreeSectionData(section);
- l_pstCurrSdtPara->handle = l_nHandle++;
- l_pstCurrSdtPara->nServiceNum = 0;
- l_pstCurrSdtPara->nCurrVersionNumber = -1;
- /* Start the SDT filtering. */
- SISubTable[SDTSubTableID].details.tableID = 0x42;
- SISubTable[SDTSubTableID].details.tableIDExt = -1;
- SISubTableStart(SDTSubTableID, 0, l_pstCurrSdtPara->nVersionNumber, l_pstCurrSdtPara->handle);
- return;
- }
- }
- else
- {
- if(l_pstCurrBatPara->nCurrVersionNumber == -1)
- {
- l_pstCurrBatPara->nCurrVersionNumber = version_number;
- memset(pstBat, 0, sizeof(KB_SIBatStruct));
- }
- else if(l_pstCurrBatPara->nCurrVersionNumber != version_number)
- {
- SIFreeSectionData(section);
- l_pstCurrBatPara->handle = l_nHandle++;
- l_pstCurrBatPara->nCurrVersionNumber = -1;
- SISubTable[SDTSubTableID].details.tableID = 0x4A;
- SISubTable[SDTSubTableID].details.tableIDExt = l_pstCurrBatPara->nBouquetId;
- SISubTableStart(SDTSubTableID, 1, l_pstCurrBatPara->nVersionNumber, l_pstCurrBatPara->handle);
- return;
- }
- }
- pInData += 8;
- dataLength -= 8;
- if( dataLength <= 0 )
- {
- SIFreeSectionData(section);
- return;
- }
- if(filter->filterNumber == 0)
- {
- pInData += 3;
- dataLength -= 3;
- while(dataLength > 0 && l_pstCurrSdtPara->nServiceNum < l_pstCurrSdtPara->nMaxServiceNum)
- {
- INT32 descriptors_loop_length;
-
- memset(pstSdt, 0, sizeof(KB_SISdtStruct));
- pstSdt->TSID = table_id_extension;
- pstSdt->version_number = version_number;
-
- pstSdt->service_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- dataLength -= 2;
-
- pstSdt->EIT_schedule_flag = (UINT8)((pInData[0] & 0x2) >> 1);
- pstSdt->EIT_present_following_flag = pInData[0] & 0x1;
- pInData++;
- dataLength--;
-
- pstSdt->running_status = (UINT8)(pInData[0] >> 5);
- pstSdt->free_CA_mode = (UINT8)((pInData[0] & 0x10) >> 4);
- descriptors_loop_length = ((INT32)pInData[0] & 0x0F) * 0x100 + (INT32)pInData[1];
- pInData += 2;
- dataLength -= 2;
-
- SISDTDescs(pInData, descriptors_loop_length, pstSdt);
- pInData += descriptors_loop_length;
- dataLength -= descriptors_loop_length;
-
- if(l_pstCurrSdtPara->nSvcID == pstSdt->service_id)
- {
- memcpy(l_pstCurrSdtPara->pstSdt, pstSdt, sizeof(KB_SISdtStruct));
- l_pstCurrSdtPara->nServiceNum++;
- break;
- }
- else if(l_pstCurrSdtPara->nSvcID == -1)
- {
- if((l_pstCurrSdtPara->nType & KB_SI_RECEIVE_DTV) == 0 ||
- pstSdt->service_type == SI_SERVICE_TYPE_DTV)
- {
- memcpy(&(l_pstCurrSdtPara->pstSdt[l_pstCurrSdtPara->nServiceNum]),
- pstSdt, sizeof(KB_SISdtStruct));
- l_pstCurrSdtPara->nServiceNum++;
- }
-
- }
- }
- }
- else
- {
- INT32 bouquet_descriptors_length;
- INT32 transport_stream_loop_length;
- bouquet_descriptors_length = ((INT32)pInData[0] * 0x100 + (INT32)pInData[1]) & 0x0FFF;
- pInData += 2;
- pstBat->bouquet_id = table_id_extension;
- pstBat->version_number = version_number;
- SIBATDescs(pInData, bouquet_descriptors_length, pstBat, 0);
- pInData += bouquet_descriptors_length;
- transport_stream_loop_length = ((INT32)pInData[0] * 0x100 + (INT32)pInData[1]) & 0x0FFF;
- pInData += 2;
- while(transport_stream_loop_length > 0 && pstBat->num < KB_SI_MAX_NIT_CHANNEL_NUM)
- {
- INT32 transport_descriptors_length;
- pstBat->transport_stream[pstBat->num].transport_stream_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- transport_stream_loop_length -= 2;
- pstBat->transport_stream[pstBat->num].original_network_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- transport_stream_loop_length -= 2;
- transport_descriptors_length = ((INT32)pInData[0] * 0x100 + (INT32)pInData[1]) & 0x0FFF;
- pInData += 2;
- transport_stream_loop_length -= 2;
- SIBATDescs(pInData, transport_descriptors_length, pstBat, 1);
- pInData += transport_descriptors_length;
- transport_stream_loop_length -= transport_descriptors_length;
- pstBat->num++;
- }
- l_pstCurrBatPara->nBatNumber ++;
- }
- SIFreeSectionData(section);
- }
- static void SISDTDescs( UINT8* pInData, INT32 dataLen, KB_SISdtStruct* pstSdt)
- {
- UINT8 *data;
- UINT32 tag;
- UINT8 length;
- int i;
- int service_provider_name_length;
- int service_name_length;
- char ISO_639_language_code[4];
- while( dataLen > 0 )
- {
- tag = *pInData++;
- length = *pInData++;
- data = pInData;
- pInData += length;
- dataLen -= ((INT32)length + 2);
- if(length == 0)
- continue;
- switch(tag)
- {
- case KB_FILTER_SI_SERVICE:
- pstSdt->service_type = *data++;
- service_provider_name_length = *data++;
- SIStoreText(pstSdt->chinese.service_provider_name, data, ((service_provider_name_length > KB_SI_MAX_SERVICE_PROVIDER_NAME_LEN)
- ? KB_SI_MAX_SERVICE_PROVIDER_NAME_LEN : service_provider_name_length) );
- data += service_provider_name_length;
- service_name_length = *data++;
- SIStoreText(pstSdt->chinese.service_name, data, ((service_name_length > KB_SI_MAX_SERVICE_NAME_LEN)
- ? KB_SI_MAX_SERVICE_NAME_LEN : service_name_length) );
- break;
- case KB_FILTER_SI_MULTILINGUAL_SERVICE_NAME:
- memcpy(ISO_639_language_code, data, 3);
- ISO_639_language_code[3] = ' ';
- SIToLower(ISO_639_language_code);
- data += 3;
- service_provider_name_length = *data++;
- if(!strcmp(ISO_639_language_code, "chi") ||
- !strcmp(ISO_639_language_code, "chn") ||
- !strcmp(ISO_639_language_code, "zho"))
- {
- SIStoreText(pstSdt->chinese.service_provider_name, data, ((service_provider_name_length > KB_SI_MAX_SERVICE_PROVIDER_NAME_LEN)
- ? KB_SI_MAX_SERVICE_PROVIDER_NAME_LEN : service_provider_name_length) );
- }
- else if(!strcmp(ISO_639_language_code, "eng"))
- {
- SIStoreText(pstSdt->english.service_provider_name, data, ((service_provider_name_length > KB_SI_MAX_SERVICE_PROVIDER_NAME_LEN)
- ? KB_SI_MAX_SERVICE_PROVIDER_NAME_LEN : service_provider_name_length) );
- }
- data += service_provider_name_length;
- service_name_length = *data++;
- if(!strcmp(ISO_639_language_code, "chi") ||
- !strcmp(ISO_639_language_code, "chn") ||
- !strcmp(ISO_639_language_code, "zho"))
- {
- SIStoreText(pstSdt->chinese.service_name, data, ((service_name_length > KB_SI_MAX_SERVICE_NAME_LEN)
- ? KB_SI_MAX_SERVICE_NAME_LEN : service_name_length) );
- }
- else if(!strcmp(ISO_639_language_code, "eng"))
- {
- SIStoreText(pstSdt->english.service_name, data, ((service_name_length > KB_SI_MAX_SERVICE_NAME_LEN)
- ? KB_SI_MAX_SERVICE_NAME_LEN : service_name_length) );
- }
-
- break;
- case KB_FILTER_SI_DATA_BROADCAST:
- data += 2;
- pstSdt->component_tag = *data;
- break;
- case KB_FILTER_SI_COUNTRY_AVAILABILITY:
- case KB_FILTER_SI_LINKAGE:
- case KB_FILTER_SI_NVOD_REFERENCE:
- case KB_FILTER_SI_TIME_SHIFTED_SERVICE:
- case KB_FILTER_SI_MOSAIC:
- case KB_FILTER_SI_CA_IDENTIFIER:
- case KB_FILTER_SI_TELEPHONE:
- case KB_FILTER_SI_PRIVATE_DATA_SPECIFIER:
- case KB_FILTER_SI_STUFFING:
- case KB_FILTER_SI_BOUQUET_NAME:
- switch(tag)
- {
- case 0x4B:
- pstSdt->TimeShiftedNum = (UINT8)(length / 6);
- for(i = 0; i < pstSdt->TimeShiftedNum; i ++)
- {
- pstSdt->TimeShift[i].TS_ID = (data[0] << 8) | (data[1]);
- data += 2;
- pstSdt->TimeShift[i].OrgnetID = (data[0] << 8) | (data[1]);
- data += 2;
- pstSdt->TimeShift[i].ServiceID = (data[0] << 8) | (data[1]);
- data += 2;
- }
- break;
- case 0x4C:
- pstSdt->reference_service_id = (data[0] << 8) | (data[1]);
-
- break;
- }
- break;
- default:
- break;
- }
- }
- }
- static void SIBATDescs(UINT8* pInData, INT32 dataLen, KB_SIBatStruct* pstBat, INT32 inLoop)
- {
- UINT8 *data;
- UINT32 tag;
- UINT8 length;
- char ISO_639_language_code[4];
- while(dataLen > 0)
- {
- tag = *pInData++;
- length = *pInData++;
- data = pInData;
- pInData += length;
- dataLen -= ((INT32)length + 2);
- if(length == 0)
- continue;
- switch(tag)
- {
- case KB_FILTER_SI_BOUQUET_NAME:
- if(!inLoop)
- {
- SIStoreText(pstBat->bouquet_name, data, ((length > KB_SI_MAX_BOUQUET_NAME_LEN)
- ? KB_SI_MAX_BOUQUET_NAME_LEN : length) );
- }
- break;
- case KB_FILTER_SI_MULTILINGUAL_BOUQUET_NAME:
- if(!inLoop)
- {
- INT32 bouquet_name_length;
- memcpy(ISO_639_language_code, data, 3);
- ISO_639_language_code[3] = ' ';
- SIToLower(ISO_639_language_code);
- data += 3;
-
- bouquet_name_length = *data++;
- if(!strcmp(ISO_639_language_code, "chi") ||
- !strcmp(ISO_639_language_code, "chn") ||
- !strcmp(ISO_639_language_code, "zho"))
- {
- SIStoreText(pstBat->bouquet_name, data, ((bouquet_name_length > KB_SI_MAX_BOUQUET_NAME_LEN)
- ? KB_SI_MAX_BOUQUET_NAME_LEN : bouquet_name_length) );
- }
- else if(!strcmp(ISO_639_language_code, "eng"))
- {
- SIStoreText(pstBat->english_bouquet_name, data, ((bouquet_name_length > KB_SI_MAX_BOUQUET_NAME_LEN)
- ? KB_SI_MAX_BOUQUET_NAME_LEN : bouquet_name_length) );
- }
- }
- break;
- case KB_FILTER_SI_SERVICE_LIST:
- if(inLoop)
- {
- while(length > 0 && pstBat->transport_stream[pstBat->num].num < KB_SI_MAX_BAT_SERVICE_NUM_PER_TS)
- {
- if((l_pstCurrBatPara->nType & KB_SI_RECEIVE_DTV) == 0 ||
- data[2] == SI_SERVICE_TYPE_DTV)
- {
- INT32 service_num;
- service_num = pstBat->transport_stream[pstBat->num].num;
- pstBat->transport_stream[pstBat->num].service[service_num].service_id =
- (UINT16)(data[0] * 0x100 + data[1]);
- pstBat->transport_stream[pstBat->num].service[service_num].service_type = data[2];
- pstBat->transport_stream[pstBat->num].num++;
- }
- data += 3;
- length -= 3;
- }
- }
- break;
- case KB_FILTER_SI_COUNTRY_AVAILABILITY:
- case KB_FILTER_SI_LINKAGE:
- case KB_FILTER_SI_CA_IDENTIFIER:
- case KB_FILTER_SI_PRIVATE_DATA_SPECIFIER:
- case KB_FILTER_SI_STUFFING:
- break;
- default:
- break;
- }
- }
- }
- static void SIEitPFDescs(UINT8* pInData, INT32 dataLen, KB_SIEitPF* pstEitPF)
- {
- UINT8 *data;
- UINT32 tag;
- UINT8 length;
- UINT8 event_name_length;
- UINT8 text_length;
- char ISO_639_language_code[4];
- while(dataLen > 0)
- {
- tag = *pInData++;
- length = *pInData++;
- data = pInData;
- pInData += length;
- dataLen -= ((INT32)length + 2);
- if(length == 0)
- continue;
- switch(tag)
- {
- case KB_FILTER_SI_SHORT_EVENT:
- memcpy(ISO_639_language_code, data, 3);
- ISO_639_language_code[3] = ' ';
- SIToLower(ISO_639_language_code);
- data += 3;
-
- event_name_length = *data++;
- if(!strcmp(ISO_639_language_code, "chi") ||
- !strcmp(ISO_639_language_code, "chn") ||
- !strcmp(ISO_639_language_code, "zho") ||
- !strcmp(ISO_639_language_code, "eng"))
- {
- SIStoreText(pstEitPF->chinese.event_name, data, ((event_name_length > KB_SI_MAX_EVENT_NAME_LEN)
- ? KB_SI_MAX_EVENT_NAME_LEN : event_name_length));
- }
- data += event_name_length;
- text_length = *data++;
- if(!strcmp(ISO_639_language_code, "chi") ||
- !strcmp(ISO_639_language_code, "chn") ||
- !strcmp(ISO_639_language_code, "zho") ||
- !strcmp(ISO_639_language_code, "eng"))
- {
- SIStoreText(pstEitPF->chinese.text, data, ((text_length > KB_SI_MAX_EVENT_TEXT_LEN)
- ? KB_SI_MAX_EVENT_TEXT_LEN: text_length));
- }
-
- break;
-
- case KB_FILTER_SI_EXTENDED_EVENT:
- data ++;
-
- memcpy(ISO_639_language_code, data, 3);
- ISO_639_language_code[3] = ' ';
- SIToLower(ISO_639_language_code);
- data += 4;
- text_length = *data++;
- if(!strcmp(ISO_639_language_code, "chi") ||
- !strcmp(ISO_639_language_code, "chn") ||
- !strcmp(ISO_639_language_code, "zho") ||
- !strcmp(ISO_639_language_code, "eng"))
- {
- SIStoreText(pstEitPF->extended_event.text_char, data, ((text_length > KB_SI_MAX_TEXT_CHAR_LEN)
- ? KB_SI_MAX_TEXT_CHAR_LEN : text_length));
- }
- break;
-
- case KB_FILTER_SI_STUFFING:
- case KB_FILTER_SI_LINKAGE:
- case KB_FILTER_SI_TIME_SHIFTED_EVENT:
- case KB_FILTER_SI_COMPONENT:
- case KB_FILTER_SI_CA_IDENTIFIER:
- case KB_FILTER_SI_CONTENT:
- case KB_FILTER_SI_PARENTAL_RATING:
- case KB_FILTER_SI_TELEPHONE:
- case KB_FILTER_SI_MULTILINGUAL_COMPONENT:
- case KB_FILTER_SI_PRIVATE_DATA_SPECIFIER:
- case KB_FILTER_SI_SHORT_SMOOTHING_BUFFER:
- case KB_FILTER_SI_DATA_BROADCAST:
- break;
- default:
- break;
- }
- }
- }
- static void SIEitSCHDescs(UINT8* pInData, INT32 dataLen, KB_SIEitSchEvent* pstEvent)
- {
- UINT8 *data;
- UINT32 tag;
- UINT8 length;
- UINT8 event_name_length;
- UINT8 text_length;
- char ISO_639_language_code[4];
- while(dataLen > 0)
- {
- tag = *pInData++;
- length = *pInData++;
- data = pInData;
- pInData += length;
- dataLen -= ((INT32)length + 2);
- if(length == 0)
- continue;
- switch(tag)
- {
- case KB_FILTER_SI_SHORT_EVENT:
- memcpy(ISO_639_language_code, data, 3);
- ISO_639_language_code[3] = ' ';
- SIToLower(ISO_639_language_code);
- data += 3;
- event_name_length = *data++;
- if(!strcmp(ISO_639_language_code, "chi") ||
- !strcmp(ISO_639_language_code, "chn") ||
- !strcmp(ISO_639_language_code, "zho"))
- {
- SIStoreText(pstEvent->chinese.event_name, data, ((event_name_length > KB_SI_MAX_EVENT_NAME_LEN)
- ? KB_SI_MAX_EVENT_NAME_LEN : event_name_length));
- }
- else if(!strcmp(ISO_639_language_code, "eng"))
- {
- SIStoreText(pstEvent->chinese.event_name, data, ((event_name_length > KB_SI_MAX_EVENT_NAME_LEN)
- ? KB_SI_MAX_EVENT_NAME_LEN : event_name_length));
- }
- data += event_name_length;
- text_length = *data++;
- if(!strcmp(ISO_639_language_code, "chi") ||
- !strcmp(ISO_639_language_code, "chn") ||
- !strcmp(ISO_639_language_code, "zho"))
- {
- if (NULL != pstEvent->chinese.text)
- {
- SIStoreText(pstEvent->chinese.text, data, ((text_length > KB_SI_MAX_EVENT_TEXT_LEN)
- ? KB_SI_MAX_EVENT_TEXT_LEN: text_length));
- }
- else
- {
- printf("nSIEitSCHDescs::serious error! pointer text is NULL!");
- }
- }
- else if(!strcmp(ISO_639_language_code, "eng"))
- {
- if (NULL != pstEvent->chinese.text)
- {
- SIStoreText(pstEvent->chinese.text, data, ((text_length > KB_SI_MAX_EVENT_TEXT_LEN)
- ? KB_SI_MAX_EVENT_TEXT_LEN: text_length));
- }
- else
- {
- printf("nSIEitSCHDescs::serious error! pointer text is NULL!");
- }
- }
-
- break;
- case KB_FILTER_SI_STUFFING:
- case KB_FILTER_SI_LINKAGE:
- case KB_FILTER_SI_EXTENDED_EVENT:
- case KB_FILTER_SI_COMPONENT:
- case KB_FILTER_SI_CA_IDENTIFIER:
- case KB_FILTER_SI_CONTENT:
- case KB_FILTER_SI_PARENTAL_RATING:
- case KB_FILTER_SI_TELEPHONE:
- case KB_FILTER_SI_MULTILINGUAL_COMPONENT:
- case KB_FILTER_SI_PRIVATE_DATA_SPECIFIER:
- case KB_FILTER_SI_SHORT_SMOOTHING_BUFFER:
- case KB_FILTER_SI_DATA_BROADCAST:
- break;
- case KB_FILTER_SI_TIME_SHIFTED_EVENT:
- pstEvent->reference_service_id = (data[0] << 8) | (data[1]);
- data += 2;
- pstEvent->reference_event_id = (data[0] << 8) | (data[1]);
- break;
- default:
- break;
- }
- }
- }
- static void SICATDescs(UINT8* pInData, INT32 dataLen, KB_SICatStruct* pstCat)
- {
- UINT8 *data;
- UINT32 tag;
- UINT8 length;
- UINT16 oldLength;
- while( dataLen > 0 )
- {
- tag = *pInData++;
- length = *pInData++;
- data = pInData;
- pInData += length;
- dataLen -= ((INT32)length + 2);
- if(length == 0)
- continue;
- switch(tag)
- {
- case KB_FILTER_SI_CA:
- oldLength = pstCat->CA_descriptor_buffer_len;
- pstCat->CA_descriptor_buffer_len += (UINT16)(2 + length);
- if(pstCat->CA_descriptor_buffer_len > KB_SI_MAX_CA_BUFFER_LEN)
- {
- pstCat->CA_descriptor_buffer_len = KB_SI_MAX_CA_BUFFER_LEN;
- }
- memcpy(pstCat->CA_descriptor + oldLength, data - 2, pstCat->CA_descriptor_buffer_len - oldLength);
- break;
- default:
- break;
- }
- }
- }
- static void SIHandlePat(T_SubTableID subTableID, UINT32 filterNumber, UINT32 handle)
- {
- KB_OSPMsgNode message;
- T_SubTableFilter *filter;
- filter = &SISubTable[subTableID].filter[filterNumber];
- filter->tableIDExt = filter->data.tableIDExt;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(l_pstCurrPatPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- message.Word2 = KB_SI_MSG_PAT_CHANGE;
- }
- else
- {
- message.Word2 = KB_SI_MSG_PAT_DONE;
- }
- message.Word3 = (UINT32)l_pstCurrPatPara->pstPat;
- KD_DTVSendMsg(&message);
- if(l_pstCurrPatPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- l_pstCurrPatPara->nCurrVersionNumber = -1;
- SISubTableStart(subTableID, filterNumber, filter->data.version, handle);
- }
- else
- {
- memset(l_pstCurrPatPara, 0, sizeof(PATINFO));
- }
- }
- static void SIHandleNit(T_SubTableID subTableID, UINT32 filterNumber, UINT32 handle)
- {
- KB_OSPMsgNode message;
- T_SubTableFilter *filter;
- filter = &SISubTable[subTableID].filter[filterNumber];
- filter->tableIDExt = filter->data.tableIDExt;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(l_pstCurrNitPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- message.Word2 = KB_SI_MSG_NIT_CHANGE;
- }
- else
- {
- message.Word2 = KB_SI_MSG_NIT_DONE;
- }
- message.Word3 = (UINT32)l_pstCurrNitPara->pstNit;
- KD_DTVSendMsg(&message);
- if(l_pstCurrNitPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- l_pstCurrNitPara->nCurrVersionNumber = -1;
- SISubTableStart(subTableID, filterNumber, filter->data.version, handle);
- }
- else
- {
- memset(l_pstCurrNitPara, 0, sizeof(NITINFO));
- }
- }
- static void SIHandlePmt(T_SubTableID subTableID, UINT32 filterNumber, UINT32 handle)
- {
- KB_OSPMsgNode message;
- T_SubTableFilter *filter;
- INT32 i;
- filter = &SISubTable[subTableID].filter[filterNumber];
- filter->tableIDExt = filter->data.tableIDExt;
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if(l_pstCurrPmtPara[i]->nUsedFlag == 1 &&
- l_pstCurrPmtPara[i]->nSvcNO == filter->tableIDExt)
- {
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(l_pstCurrPmtPara[i]->nType & KB_SI_RECEIVE_CHANGE)
- {
- message.Word2 = KB_SI_MSG_PMT_CHANGE;
- }
- else
- {
- message.Word2 = KB_SI_MSG_PMT_DONE;
- }
- message.Word3 = (UINT32)l_pstCurrPmtPara[i]->pstPmt;
-
- KD_DTVSendMsg(&message);
-
- if(l_pstCurrPmtPara[i]->nType & KB_SI_RECEIVE_CHANGE)
- {
- l_pstCurrPmtPara[i]->nCurrVersionNumber = -1;
- SISubTable[subTableID].details.tableIDExt = l_pstCurrPmtPara[i]->nSvcNO;
- SISubTable[subTableID].details.PID = l_pstCurrPmtPara[i]->nProgramMapPid;
- SISubTableStart(subTableID, filterNumber, filter->data.version, handle);
- }
- else
- {
- memset(l_pstCurrPmtPara[i], 0, sizeof(PMTINFO));
- }
- break;
- }
- }
- }
- static void SIHandleSdt(T_SubTableID subTableID, UINT32 filterNumber, UINT32 handle)
- {
- KB_OSPMsgNode message;
- T_SubTableFilter *filter;
- filter = &SISubTable[subTableID].filter[filterNumber];
- filter->tableIDExt = filter->data.tableIDExt;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(filter->tableID == 0x42)
- {
- if(l_pstCurrSdtPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- message.Word2 = KB_SI_MSG_SDT_CHANGE;
- }
- else
- {
- message.Word2 = KB_SI_MSG_SDT_DONE;
- }
- message.Word3 = (UINT32)l_pstCurrSdtPara->pstSdt;
- message.Word4 = l_pstCurrSdtPara->nServiceNum;
- }
- else
- {
- if(l_pstCurrBatPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- message.Word2 = KB_SI_MSG_BAT_CHANGE;
- }
- else
- {
- message.Word2 = KB_SI_MSG_BAT_DONE;
- }
- message.Word3 = (UINT32)l_pstCurrBatPara->pstBat;
- message.Word4 = l_pstCurrBatPara->nBatNumber;
- }
- KD_DTVSendMsg(&message);
- if(filter->tableID == 0x42)
- {
- if(l_pstCurrSdtPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- l_pstCurrSdtPara->nServiceNum = 0;
- l_pstCurrSdtPara->nCurrVersionNumber = -1;
- SISubTable[SDTSubTableID].details.tableID = 0x42;
- SISubTable[SDTSubTableID].details.tableIDExt = -1;
- SISubTableStart(subTableID, filterNumber, filter->data.version, handle);
- }
- else
- {
- memset(l_pstCurrSdtPara, 0, sizeof(SDTINFO));
- }
- }
- else
- {
- if(l_pstCurrBatPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- l_pstCurrBatPara->nCurrVersionNumber = -1;
- l_pstCurrBatPara->nBatNumber = 0;
- SISubTable[SDTSubTableID].details.tableID = 0x4A;
- //J_SI_Print("sipsi rec bat:::[%d]n",l_pstCurrBatPara->nBouquetId);
- SISubTable[SDTSubTableID].details.tableIDExt = l_pstCurrBatPara->nBouquetId;
- SISubTableStart(subTableID, filterNumber, filter->data.version, handle);
- }
- else
- {
- memset(l_pstCurrBatPara, 0, sizeof(BATINFO));
- }
- }
- }
- static void SIHandleEit(T_SubTableID subTableID, UINT32 filterNumber, UINT32 handle)
- {
- KB_OSPMsgNode message;
- T_SubTableFilter *filter;
- int nIsMulti = 0;
- int i, nCurrentNo;
- filter = &SISubTable[subTableID].filter[filterNumber];
-
- if(filter->subTableID == 0x50 && filter->tableIDExt == -1)
- nIsMulti = 1;
- if(filterNumber < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT)
- {
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if(l_pstCurrEinSchInfoPara[i]->handle == filter->handle)
- {
- nCurrentNo = i;
- break;
- }
- }
-
- if (i >= KB_SI_EIT_SCHEDULE_SERVICE_COUNT)
- {
- return;
- }
-
- filter->tableIDExt = filter->data.tableIDExt;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(nIsMulti)
- {
- message.Word2 = KB_SI_MSG_EIT_SCHEDULE_DONE;
- message.Word3 = (UINT32)l_pstCurrMultiEinSchInfoPara->pstEinSchInfo;
- KD_DTVSendMsg(&message);
- memset(l_pstCurrMultiEinSchInfoPara, 0, sizeof(MULTEITSCHINFO));
- }
- else
- {
- message.Word2 = KB_SI_MSG_EIT_SCHEDULE_DONE;
- message.Word3 = (UINT32)l_pstCurrEinSchInfoPara[nCurrentNo]->pstEinSchInfo;
- message.Word4 = l_pstCurrEinSchInfoPara[nCurrentNo]->nSvcID;
- KD_DTVSendMsg(&message);
- memset(l_pstCurrEinSchInfoPara[nCurrentNo], 0, sizeof(EITSCHINFO));
- }
- }
- else
- {
- if (filterNumber >= SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER
- && filterNumber < SI_EIT_SCHEDULE_SHIFT_FILTER_END_NUMBER)
- {
- for (i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if(gptCurrSchShiftPara[i]->handle == filter->handle)
- {
- nCurrentNo = i;
- break;
- }
- }
-
- if (i >= SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS)
- {
- return;
- }
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_EIT_SCHEDULE_DONE;
- message.Word3 = (UINT32)gptCurrSchShiftPara[nCurrentNo]->ptTimeShift;
-
- KD_DTVSendMsg(&message);
- }
- else
- {
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(l_pstCurrEitPFPara[i]->nUsedFlag == 1 &&
- l_pstCurrEitPFPara[i]->nSvcID == filter->data.tableIDExt
- && l_pstCurrEitPFPara[i]->nTableId == filter->tableID)
- {
- filter->tableIDExt = filter->data.tableIDExt;
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(l_pstCurrEitPFPara[i]->nType & KB_SI_RECEIVE_CHANGE)
- {
- message.Word2 = KB_SI_MSG_EIT_PF_CHANGE;
- }
- else
- {
- message.Word2 = KB_SI_MSG_EIT_PF_DONE;
- }
- message.Word3 = (UINT32)l_pstCurrEitPFPara[i]->pstEitPresent;
- message.Word4 = (UINT32)l_pstCurrEitPFPara[i]->pstEitFollow;
- KD_DTVSendMsg(&message);
- if(l_pstCurrEitPFPara[i]->nType & KB_SI_RECEIVE_CHANGE)
- {
- l_pstCurrEitPFPara[i]->nCurrVersionNumber = -1;
- SISubTable[EITSubTableID].details.tableID = l_pstCurrEitPFPara[i]->nTableId;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEitPFPara[i]->nSvcID;
- SISubTableStart(subTableID, filterNumber, filter->data.version, handle);
- }
- else
- {
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- }
- break;
- }
- }
- }
- }
- }
- static void SIHandleCat(T_SubTableID subTableID, UINT32 filterNumber, UINT32 handle)
- {
- KB_OSPMsgNode message;
- T_SubTableFilter *filter;
- filter = &SISubTable[subTableID].filter[filterNumber];
- filter->tableIDExt = filter->data.tableIDExt;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(l_pstCurrCatPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- message.Word2 = KB_SI_MSG_CAT_CHANGE;
- }
- else
- {
- message.Word2 = KB_SI_MSG_CAT_DONE;
- }
- message.Word3 = (UINT32)l_pstCurrCatPara->pstCat;
- KD_DTVSendMsg(&message);
- if(l_pstCurrCatPara->nType & KB_SI_RECEIVE_CHANGE)
- {
- l_pstCurrCatPara->nCurrVersionNumber = -1;
- SISubTableStart(subTableID, filterNumber, filter->data.version, handle);
- }
- else
- {
- memset(l_pstCurrCatPara, 0, sizeof(CATINFO));
- }
- }
- static INT32 SIHandlePatTimeout(UINT32 filterID)
- {
- KB_OSPMsgNode message;
- SISubTableStop(PATSubTableID);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_PAT_TIMEOUT;
- KD_DTVSendMsg(&message);
- memset(l_pstCurrPatPara, 0, sizeof(PATINFO));
- return -1;
- }
- static INT32 SIHandleNitTimeout(UINT32 filterID)
- {
- KB_OSPMsgNode message;
- SISubTableStop(NITSubTableID);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_NIT_TIMEOUT;
- KD_DTVSendMsg(&message);
- memset(l_pstCurrNitPara, 0, sizeof(NITINFO));
- return -1;
- }
- static INT32 SIHandlePmtTimeout(UINT32 filterID)
- {
- KB_OSPMsgNode message;
- INT32 i;
- SIFilterStop(SISubTable[SIFilters[filterID].subTableID].details.channelID, &SIFilters[filterID]);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_PMT_TIMEOUT;
- message.Word3 = SIFilters[filterID].tableIDExt;
- KD_DTVSendMsg(&message);
- for(i = 0; i < SI_NO_PMT_TABLES; i++)
- {
- if(l_pstCurrPmtPara[i]->nUsedFlag == 1 &&
- l_pstCurrPmtPara[i]->nSvcNO == SIFilters[filterID].tableIDExt)
- {
- memset(l_pstCurrPmtPara[i], 0, sizeof(PMTINFO));
- break;
- }
- }
- return -1;
- }
- static INT32 SIHandleSdtTimeout(UINT32 filterID)
- {
- KB_OSPMsgNode message;
- SIFilterStop(SISubTable[SDTSubTableID].details.channelID, &SIFilters[filterID]);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(SIFilters[filterID].tableID == 0x42 /* SDT */)
- {
- message.Word2 = KB_SI_MSG_SDT_TIMEOUT;
- }
- else
- {
- message.Word2 = KB_SI_MSG_BAT_TIMEOUT;
- message.Word3 = SIFilters[filterID].tableIDExt;
- }
-
- KD_DTVSendMsg(&message);
- if(SIFilters[filterID].tableID == 0x42 /* SDT */)
- {
- memset(l_pstCurrSdtPara, 0, sizeof(SDTINFO));
- }
- else
- {
- memset(l_pstCurrBatPara, 0, sizeof(BATINFO));
- }
- return -1;
- }
- static INT32 SIHandleEitTimeout(UINT32 filterID)
- {
- KB_OSPMsgNode message;
- INT32 i, nCurrentNo, filterNumber;
- T_SubTableFilter *filter;
- filter = &SIFilters[filterID];
-
- if(SIFilters[filterID].tableID == 0x4E || SIFilters[filterID].tableID == 0x4F)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &SIFilters[filterID]);
- SIFilters[filterID].used = FALSE;
- }
- else
- {
- if (filterNumber >= SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER
- && filterNumber < SI_EIT_SCHEDULE_SHIFT_FILTER_END_NUMBER)
- {
- for (i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if(gptCurrSchShiftPara[i]->handle == filter->handle)
- {
- nCurrentNo = i;
- break;
- }
- }
-
- if (i >= SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS)
- {
- return -1;
- }
- memset(gptCurrSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
-
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &SIFilters[filterID]);
- SISubTable[EITSubTableID].filter[filterNumber].used = FALSE;
- }
- else
- {
- if (filter->tableID == 0x50)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, filter);
- SIFilters[filterID].used = FALSE;
- filterNumber = SIGetFilterNum(EITSubTableID, 0x51, filter->tableIDExt);
- if (filterNumber != 0xFFFFFFFF)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID,
- &SISubTable[EITSubTableID].filter[filterNumber]);
- SISubTable[EITSubTableID].filter[filterNumber].used = FALSE;
- }
- }
- else
- {
- if (filter->tableID == 0x51)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, filter);
- SIFilters[filterID].used = FALSE;
- filterNumber = SIGetFilterNum(EITSubTableID, 0x50, filter->tableIDExt);
- if (filterNumber != 0xFFFFFFFF)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID,
- &SISubTable[EITSubTableID].filter[filterNumber]);
- SISubTable[EITSubTableID].filter[filterNumber].used = FALSE;
- }
- }
- }
- }
- }
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- if(SIFilters[filterID].tableID == 0x4E || SIFilters[filterID].tableID == 0x4F)
- {
- message.Word2 = KB_SI_MSG_EIT_PF_TIMEOUT;
- }
- else
- {
- message.Word2 = KB_SI_MSG_EIT_SCHEDULE_TIMEOUT;
- }
- message.Word4 = SIFilters[filterID].tableIDExt;
-
- KD_DTVSendMsg(&message);
- if(SIFilters[filterID].tableID == 0x4E || SIFilters[filterID].tableID == 0x4F)
- {
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(l_pstCurrEitPFPara[i]->nUsedFlag == 1 &&
- l_pstCurrEitPFPara[i]->nSvcID == SIFilters[filterID].tableIDExt
- && l_pstCurrEitPFPara[i]->nTableId == SIFilters[filterID].tableID)
- {
- memset(l_pstCurrEitPFPara[i], 0, sizeof(EITPFINFO));
- }
- }
- }
- else
- {
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- if(l_pstCurrEinSchInfoPara[i]->handle == filter->handle)
- {
- nCurrentNo = i;
- break;
- }
- }
- if (i >= KB_SI_EIT_SCHEDULE_SERVICE_COUNT)
- {
- return -1;
- }
- memset(l_pstCurrEinSchInfoPara[nCurrentNo], 0, sizeof(EITSCHINFO));
- }
- return -1;
- }
- static INT32 SIHandleTdtTimeout(UINT32 filterID)
- {
- KB_OSPMsgNode message;
- SIFilterStop(SISubTable[TDTSubTableID].details.channelID, &SIFilters[filterID]);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_TDT_TIMEOUT;
- KD_DTVSendMsg(&message);
- memset(l_pstCurrTdtPara, 0, sizeof(TDTINFO));
- return -1;
- }
- static INT32 SIHandleTotTimeout(UINT32 filterID)
- {
- KB_OSPMsgNode message;
- SIFilterStop(SISubTable[TOTSubTableID].details.channelID, &SIFilters[filterID]);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_TOT_TIMEOUT;
- KD_DTVSendMsg(&message);
- memset(l_pstCurrTotPara, 0, sizeof(TOTINFO));
- return -1;
- }
- static INT32 SIHandleCatTimeout(UINT32 filterID)
- {
- KB_OSPMsgNode message;
- SISubTableStop(CATSubTableID);
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = KB_SI_MSG_CAT_TIMEOUT;
- KD_DTVSendMsg(&message);
- memset(l_pstCurrCatPara, 0, sizeof(CATINFO));
- return -1;
- }
- static INT32 SIStopMultEitSCH()
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[0]));
- memset(l_pstCurrMultiEinSchInfoPara, 0, sizeof(MULTEITSCHINFO));
- return 0;
- }
- static INT32 SIGetMultEitSCH()
- {
- memcpy(l_pstCurrMultiEinSchInfoPara, l_pstPendingMultiEinSchInfoPara, sizeof(MULTEITSCHINFO));
- l_pstCurrMultiEinSchInfoPara->nCurrVersionNumber = -1;
- l_pstCurrMultiEinSchInfoPara->nUsedFlag = 1;
- memset(l_pstCurrMultiEinSchInfoPara->pstEinSchInfo, 0,
- l_pstCurrMultiEinSchInfoPara->nServiceNum * sizeof(KB_SIMultiEitSchedule));
- //SISubTable[EITSubTableID].details.noFilters = 1;
- SISubTable[EITSubTableID].details.tableID = 0x50;
- SISubTable[EITSubTableID].details.timeout = 20;
- SISubTable[EITSubTableID].details.tableIDExt = -1;//l_pstCurrMultiEinSchInfoPara->nSvcID[0];//-1;//l_pstCurrMultiEinSchInfoPara->nSvcID;
- SISubTableStart(EITSubTableID, 0, -1, l_pstCurrMultiEinSchInfoPara->handle);
- return 0;
- }
- static void SIParseEit(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- INT32 dataLength;
- KB_SIEitPF* pstEitPF;
- KB_SINVODEitPF *ptEitNvod;
-
- UINT16 table_id;
- UINT16 table_id_extension;
- UINT8 version_number;
- UINT8 section_number;
- UINT8 last_section_number;
- UINT16 serID;
- UINT16 transport_stream_id;
- UINT8 segment_last_section_number;
- int i;
- INT32 nCurrNo = 0;
- time_t start_time;
- KB_SIEitPF siEitPF;
- UINT32 duration;
- int nvod=0;
- int circle;
- INT32 filterNumber;
- //INT16 section_length = 0;
- //KB_OSPMsgNode message;
-
- memset(&siEitPF,0,sizeof(KB_SIEitPF));
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- pInData = section->data;
- dataLength = section->length;
-
- table_id = pInData[0];
- table_id_extension = (UINT16)(pInData[3] * 0x100 + pInData[4]); //ServiceID
- serID = pInData[3] << 8 | pInData[4];
- if (table_id == 0x50 || table_id == 0x51 || table_id == 0x60 || table_id == 0x61)
- {
- SISectionEinSchInfo(section);
- SIFreeSectionData(section);
- return;
- }
- version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- section_number = pInData[6];
- last_section_number = pInData[7];
- transport_stream_id = pInData[8] << 8 | pInData[9];
- pInData += 8;
- dataLength -= 8;
- if( dataLength <= 0 )
- {
- SIFreeSectionData(section);
- return;
- }
- segment_last_section_number = pInData[4];
- pInData += 6;
- dataLength -= 6;
- if(table_id == 0x4E || table_id == 0x4f)
- {
- int descriptors_loop_length;
-
- for(i = 0; i < SI_NO_EIT_PF_FILTERS; i++)
- {
- if(l_pstCurrEitPFPara[i]->handle == filter->handle &&
- l_pstCurrEitPFPara[i]->nUsedFlag == 1 &&
- l_pstCurrEitPFPara[i]->nSvcID == table_id_extension
- && l_pstCurrEitPFPara[i]->nTableId == table_id)
- {
- nCurrNo = i;
- break;
- }
- }
- if(i == SI_NO_EIT_PF_FILTERS)
- {
- SIFreeSectionData(section);
- return;
- }
- if(section_number == 0)
- {
- pstEitPF = l_pstCurrEitPFPara[nCurrNo]->pstEitPresent;
- }
- else if(section_number == 1)
- {
- pstEitPF = l_pstCurrEitPFPara[nCurrNo]->pstEitFollow;
- }
- else
- {
- pstEitPF = NULL;
- }
- if(pstEitPF == NULL)
- {
- SIFreeSectionData(section);
- return;
- }
-
- pstEitPF->NVODEventNum = 0;
- pstEitPF->service_id = table_id_extension;
- if(l_pstCurrEitPFPara[nCurrNo]->nCurrVersionNumber == -1)
- {
- l_pstCurrEitPFPara[nCurrNo]->nCurrVersionNumber = version_number;
- }
- else if(l_pstCurrEitPFPara[nCurrNo]->nCurrVersionNumber != version_number)
- {
- filterNumber = section->filterNumber;
- SIFreeSectionData(section);
- l_pstCurrEitPFPara[nCurrNo]->handle = l_nHandle++;
- l_pstCurrEitPFPara[nCurrNo]->nCurrVersionNumber = -1;
- SISubTable[EITSubTableID].details.tableID = l_pstCurrEitPFPara[nCurrNo]->nTableId;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEitPFPara[nCurrNo]->nSvcID;
- SISubTable[EITSubTableID].details.timeout = J_SI_EIT_PF_TIMEOUT;
-
- SISubTableStart(EITSubTableID, filterNumber, l_pstCurrEitPFPara[nCurrNo]->nVersionNumber, l_pstCurrEitPFPara[nCurrNo]->handle);
- return;
- }
- pstEitPF->version_number = version_number;
- circle = 0;
- while(dataLength > 0)
- {
- siEitPF.event_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- siEitPF.service_id = serID;
- pInData += 2;
- dataLength -= 2;
-
- if(pInData[0] != 0xFF || pInData[1] != 0xFF || pInData[2] != 0xFF
- || pInData[3] != 0xFF || pInData[4] != 0xFF)
- {
- SIParseTime(pInData, &start_time);
- }
- else
- {
- nvod = 1;
- start_time = 0;
- }
- pInData += 5;
- dataLength -= 5;
- siEitPF.start_time = start_time;
-
- SIParseDuration(pInData, &duration);
- siEitPF.duration = duration;
- pInData += 3;
- dataLength -= 3;
-
- if(circle == 0)
- {
- pstEitPF->running_status = (UINT8)(pInData[0] >> 5);
- pstEitPF->free_CA_mode = (UINT8)((pInData[0] & 0x10) >> 4);
- }
- descriptors_loop_length = (pInData[0] & 0x0F) * 0x100 + pInData[1];
- pInData += 2;
- dataLength -= 2;
- SIEitPFDescs(pInData, descriptors_loop_length, &siEitPF);
- if(circle == 0)
- {
- siEitPF.NVODEvent = pstEitPF->NVODEvent;
- siEitPF.NVODEventNum = pstEitPF->NVODEventNum;
- memcpy(pstEitPF,&siEitPF,sizeof(KB_SIEitPF));
- }
- if (nvod == 1
- && pstEitPF->NVODEvent != NULL
- && pstEitPF->NVODEventNum < KB_SI_EIT_PF_MAX_NVOD_EVENT_NUMBER)
- {
- ptEitNvod = pstEitPF->NVODEvent + pstEitPF->NVODEventNum;
- ptEitNvod->service_id = siEitPF.service_id;
- ptEitNvod->event_id = siEitPF.event_id;
- ptEitNvod->duration = siEitPF.duration;
- strcpy((char*)ptEitNvod->chinese.event_name, (char*)siEitPF.chinese.event_name);
- strcpy((char*)ptEitNvod->chinese.text, (char*)siEitPF.chinese.text);
- pstEitPF->NVODEventNum++;
- }
-
- pInData += descriptors_loop_length;
- dataLength -= (INT32)descriptors_loop_length;
- circle ++;
- }
- }
-
- SIFreeSectionData(section);
- return;
- }
- void SIToLower(char* str)
- {
- short len;
- short i;
- #ifdef _DBG_
- if (str == NULL)
- {
- J_SI_Print("[SIPSI] The string is emptyn");
- return;
- }
- #endif
- len = strlen(str);
- for (i = 0; i < len; i++)
- {
- str[i] = tolower(str[i]);
- }
- }
- static void SIGetSection(UINT32 nChannelID, UINT8 *pData, UINT32 nDataLength)
- {
- T_DMX_Notify notify;
- if (pData == NULL)
- {
- return;
- }
-
- /* Parpare the notify header */
- memset(¬ify, 0, sizeof(notify));
- notify.whichChannel = nChannelID;
- /* Call SIHandleNewSection first */
- if(!SIHandleNewSection(pData, ¬ify))
- {
- KB_DmxUnlock(nChannelID, pData);
-
- return;
- }
- /* Check length */
- if((notify.copyLength + notify.skipLength) > nDataLength)
- {
- J_SI_Print("nSI: Copy section length too large");
- }
- /*
- ** When parameters ara illegal, call the SISectionCopied so to
- ** release buffers.
- */
- if(!notify.outputBuffer || !notify.copyLength || ((notify.copyLength + notify.skipLength) > nDataLength))
- {
- SISectionCopied(DMX_ERROR, pData, nDataLength, notify.tag);
- return;
- }
- notify.outputBuffer = pData + notify.skipLength;
- SISectionCopied(DMX_AVAILABLE, notify.outputBuffer, notify.copyLength, notify.tag);
-
- }
- static int KD_DTVSendMsg(KB_OSPMsgNode * pMsg)
- {
- if (pMsg->Word2 >= KB_SI_MSG_EIT_PF_DONE
- && pMsg->Word2 <= KB_SI_MSG_EIT_SCHEDULE_TIMEOUT)
- {
- if (gptSiEitCallbackFunction && pMsg->Word2 != KB_SI_MSG_EIT_SCHEDULE_EVENT_DONE)
- {
- gptSiEitCallbackFunction(pMsg);
- }
- }
- else
- {
- if (gptSiCallbackFunction)
- {
- gptSiCallbackFunction(pMsg);
- }
- }
- return 0;
- }
- KB_SICallbackFunc KB_SICallback(KB_SICallbackFunc callback)
- {
- KB_SICallbackFunc ptPrvCallback;
- ptPrvCallback = gptSiCallbackFunction;
- gptSiCallbackFunction = callback;
- return ptPrvCallback;
- }
- KB_SICallbackFunc KB_SIRegisterEitCallBack(KB_SICallbackFunc callback)
- {
- KB_SICallbackFunc ptPrvCallback;
- ptPrvCallback = gptSiEitCallbackFunction;
- gptSiEitCallbackFunction = callback;
- return ptPrvCallback;
- }
- static void SiEitSetup(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));
-
- filterDetails = &SISubTable[subTableID].filter[filterNumber];
- filterID = filterDetails->filterID;
- channelID = SISubTable[subTableID].details.channelID;
-
- filterDetails->data.total = -1;
- filterDetails->data.received = 0;
- for(i = 0; i < SI_MAX_SECTION_PER_TABLE; i++)
- {
- 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;
-
- filterDetails->enabled = TRUE;
- filterDetails->used = TRUE;
- if (SISubTable[subTableID].details.channelStarted != TRUE)
- {
- KB_DmxAssociateFilter(channelID, filterID);
- KB_DmxSetFilter(filterID, filterMatch, filterMask, filterNegate);
- }
- }
- static UINT32 SIGetFilterNum(T_SubTableID subTableID, INT32 tableId,
- INT32 tableIDExt)
- {
- UINT32 i, nNumber;
- nNumber = 0XFFFFFFFF;
- for (i = 0; i < SISubTable[subTableID].details.noFilters; i++)
- {
- if (SISubTable[subTableID].filter[i].tableID == tableId
- && SISubTable[subTableID].filter[i].tableIDExt == tableIDExt)
- {
- nNumber = i;
- break;
- }
- }
- return nNumber;
- }
- INT32 KB_SIGetEITSCHShift(INT32 nSvcID,
- KB_SIEitTs eTs,
- KB_SIEitSchTimeShift *ptSchShift)
- {
- int i;
- KB_OSPMsgNode message;
- INT16 nTableId;
-
- nTableId = 0;
- switch (eTs)
- {
- case KB_SI_EIT_CURRENT_TS:
- nTableId = 0x50;
- break;
- case KB_SI_EIT_CURRENT_TS_FOR_0x51_table:
- nTableId = 0x51;
- break;
- case KB_SI_EIT_OTHER_TS:
- nTableId = 0x60;
- break;
-
- case KB_SI_EIT_OTHER_TS_FOR_0x61_table:
- nTableId = 0x61;
- break;
-
- default:
- break;
- }
- for (i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if (gptPendingSchShiftPara[i]->nUsedFlag == 0)
- {
- memset(gptPendingSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- gptPendingSchShiftPara[i]->nUsedFlag = 1;
- gptPendingSchShiftPara[i]->handle = l_nHandle++;
- gptPendingSchShiftPara[i]->nSvcID = nSvcID;
- gptPendingSchShiftPara[i]->nTableId[0] = nTableId;
- gptPendingSchShiftPara[i]->ptTimeShift = ptSchShift;
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MSG_SI_EIT_SCHEDULE_SHIFT_RECEIVE;
- message.Word2 = i;
- break;
- }
- }
-
- if(i >= SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS)
- {
- 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_SIStopEitSCHShift(INT32 nSvcID, KB_SIEitTs eTs)
- {
- //KB_OSPMsgNode message;
- INT32 nTableId;
-
- nTableId = 0;
- //对于nSvcID为KB_SI_STOP_ALL的情况,ets类型对后面的处理无影响
- switch (eTs)
- {
- case KB_SI_EIT_CURRENT_TS:
- nTableId = 0x50;
- break;
- case KB_SI_EIT_CURRENT_TS_FOR_0x51_table:
- nTableId = 0x51;
- break;
- case KB_SI_EIT_OTHER_TS:
- nTableId = 0x60;
- break;
-
- case KB_SI_EIT_OTHER_TS_FOR_0x61_table:
- nTableId = 0x61;
- break;
-
- default:
- break;
- }
- SIStopEitSCHShiftEX(nSvcID, nTableId);
- return 0;
- }
- static void SIGetEitSCHShift(UINT32 nPendingNo, UINT32 nSvcID)
- {
- int i, nCurrentParaNum;
- KB_OSPMsgNode msgNode;
-
- for (i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if(gptCurrSchShiftPara[i]->nUsedFlag == 0)
- {
- memcpy(gptCurrSchShiftPara[i], gptPendingSchShiftPara[nPendingNo], sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- gptCurrSchShiftPara[i]->nCurrVersionNumber = -1;
- gptCurrSchShiftPara[i]->nUsedFlag = 1;
-
- gptCurrSchShiftPara[i]->ptTimeShift->num = 0;
- gptCurrSchShiftPara[i]->ptTimeShift->service_id = (UINT16)gptCurrSchShiftPara[i]->nSvcID;
- nCurrentParaNum = i;
- break;
- }
- }
- if (i >= SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS)
- {
- memset(&msgNode, 0, sizeof(KB_OSPMsgNode));
- msgNode.Word1 = MSG_SI_EIT_SCHEDULE_SHIFT_RECEIVE;
- msgNode.Word2 = nPendingNo;
- KB_OSPMsgSend(l_nQueueId, (KB_OSPMsgNode *)&msgNode);
- return;
- }
- /* 把当前pending结构清零 */
- memset(gptPendingSchShiftPara[nPendingNo], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
-
- for (i = SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER; i < SI_EIT_SCHEDULE_SHIFT_FILTER_END_NUMBER; i++)
- {
- if (SISubTable[EITSubTableID].filter[i].used == FALSE)
- {
- SISubTable[EITSubTableID].details.tableID = gptCurrSchShiftPara[nCurrentParaNum]->nTableId[0];
- SISubTable[EITSubTableID].details.timeout = J_SI_EIT_SCHEDULE_TIMEOUT;
- SISubTable[EITSubTableID].details.tableIDExt = gptCurrSchShiftPara[nCurrentParaNum]->nSvcID;
- //DBGPrint("SIGetEitSCHShift i = %d nSvcID = 0x%xn", i, gptCurrSchShiftPara[nCurrentParaNum]->nSvcID);
- SISubTableStart(EITSubTableID, i, -1, gptCurrSchShiftPara[nCurrentParaNum]->handle);
- break;
- }
- }
- return;
- }
- static INT32 SIStopEitSCHShift(INT32 nSvcID, INT32 nTableId)
- {
- INT32 i;
- if(nSvcID == -1)
- {
- for(i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i]));
- memset(gptCurrSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- }
- }
- else
- {
- for(i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if(gptCurrSchShiftPara[i]->nUsedFlag == 1 &&
- gptCurrSchShiftPara[i]->nSvcID == nSvcID
- && gptCurrSchShiftPara[i]->nTableId[0] == nTableId)
- {
- memset(gptCurrSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- break;
- }
- }
- for(i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if(SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i].enabled == TRUE &&
- SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i].tableIDExt == nSvcID)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i]));
- break;
- }
- }
- }
- return 0;
- }
- static INT32 SIStopEitSCHShiftEX(INT32 nSvcID, INT32 nTableId)
- {
- INT32 i;
- if(nSvcID == -1)
- {
- for(i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i]));
- SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i].used = FALSE;
- memset(gptCurrSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- }
- }
- else
- {
- for(i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if(gptCurrSchShiftPara[i]->nUsedFlag == 1 &&
- gptCurrSchShiftPara[i]->nSvcID == nSvcID
- && gptCurrSchShiftPara[i]->nTableId[0] == nTableId)
- {
- memset(gptCurrSchShiftPara[i], 0, sizeof(T_EIT_SCHEDULE_TIME_SHIFT_PARA));
- break;
- }
- }
- for(i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i++)
- {
- if(SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i].enabled == TRUE &&
- SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i].tableIDExt == nSvcID)
- {
- SIFilterStop(SISubTable[EITSubTableID].details.channelID, &(SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i]));
- SISubTable[EITSubTableID].filter[SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER + i].used = FALSE;
- break;
- }
- }
- }
- return 0;
- }
- static void SISectionEinSchInfo(MepgData *section)
- {
- T_SubTableFilter *filter;
- UINT8 *pInData;
- INT32 dataLength;
- KB_SIEitSchEvent stEvent;
- KB_SIEitSchEvent* pstEvent;
- UINT8 text[KB_SI_MAX_EVENT_TEXT_LEN + 1];
- KB_SIEitSch* pstEinSchInfo;
- UINT16 table_id;
- UINT16 table_id_extension;
- UINT8 version_number;
- UINT8 section_number;
- UINT8 last_section_number;
- UINT16 serID;
- UINT16 transport_stream_id;
- UINT8 segment_last_section_number;
-
- int i;
- INT32 nWday;
- INT32 nOneDayFinishedFlag = 0;
- int nCurrentNo, nStartPos;
- int nIsMulti = 0;
- int nServicePos = 0;
- INT32 filterNumber;
- KB_OSPMsgNode message;
-
- if (section->filterNumber >= KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT && section->filterNumber < KB_SI_EIT_SCHEDULE_SOFT_FILTER_COUNT + SI_NO_EIT_PF_FILTERS)
- {
- J_SI_Print("SISectionEinSchInfo filter not match!n");
- return;
- }
- else
- {
- if (section->filterNumber >= SI_EIT_SCHEDULE_SHIFT_FILTER_START_NUMBER && section->filterNumber < SI_EIT_SCHEDULE_SHIFT_FILTER_END_NUMBER)
- {
- SISectionEinSchInfoShift(section);
- return;
- }
- }
- stEvent.chinese.text = text;
-
- pstEvent = &stEvent;
-
- pInData = section->data;
- dataLength = section->length;
-
- table_id = pInData[0];
- table_id_extension = (UINT16)(pInData[3] * 0x100 + pInData[4]); //ServiceID
- serID = pInData[3] << 8 | pInData[4];
-
- version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- section_number = pInData[6];
- last_section_number = pInData[7];
- transport_stream_id = pInData[8] << 8 | pInData[9];
- filter = &SISubTable[section->subTableID].filter[section->filterNumber];
- for (i = 0; i < KB_SI_EIT_SCHEDULE_SERVICE_COUNT; i++)
- {
- //是否需要匹配tableid、servid,校验usedflag?
- if(l_pstCurrEinSchInfoPara[i]->handle == filter->handle)
- {
- nCurrentNo = i;
- break;
- }
- }
- /* 无法找到匹配的指针,直接返回错误。 */
- if (i >= KB_SI_EIT_SCHEDULE_SERVICE_COUNT)
- {
- return;
- }
- l_pstCurrEinSchInfoPara[nCurrentNo]->nReceivedFlag[section_number + (table_id - 0x50) * 256] = 1;
- /*
- ** Skip past the standard SI Table header (contains tableID, section Length, etc)
- */
- pInData += 8;
- dataLength -= 8;
- if( dataLength <= 0 || (table_id == 0x51 && section_number >= 192)/* 不存储第八天 */)
- {
- return;
- }
- segment_last_section_number = pInData[4];
- if(section_number == segment_last_section_number)
- {
- for(i = (int)section_number + 1; i < ((int)segment_last_section_number / 8 + 1)* 8; i++)
- {
- if(nIsMulti)
- l_pstCurrMultiEinSchInfoPara->nReceivedFlag[nServicePos][i + (table_id - 0x50) * 256] = 1;
- else
- l_pstCurrEinSchInfoPara[nCurrentNo]->nReceivedFlag[i + (table_id - 0x50) * 256] = 1;
- }
- }
- nStartPos = (int)section_number / 64 * 64 + ((int)table_id - 0x50) * 256;
- nOneDayFinishedFlag = 1;
- for(i = nStartPos; i < nStartPos + 64 && i <= (int)last_section_number + (table_id - 0x50) * 256; i++)
- {
- if(l_pstCurrEinSchInfoPara[nCurrentNo]->nReceivedFlag[i] != 1)
- {
- break;
- }
- }
- pInData += 6;
- dataLength -= 6;
-
- if(l_pstCurrEinSchInfoPara[nCurrentNo]->handle != filter->handle)
- {
- return;
- }
- if(l_pstCurrEinSchInfoPara[nCurrentNo]->nCurrVersionNumber == -1)
- {
- l_pstCurrEinSchInfoPara[nCurrentNo]->nCurrVersionNumber = version_number;
- l_pstCurrEinSchInfoPara[nCurrentNo]->pstEinSchInfo->num = 0;
- }
- else if(l_pstCurrEinSchInfoPara[nCurrentNo]->nCurrVersionNumber != version_number)
- {
- l_pstCurrEinSchInfoPara[nCurrentNo]->handle = l_nHandle++;
- l_pstCurrEinSchInfoPara[nCurrentNo]->nCurrVersionNumber = -1;
- l_pstCurrEinSchInfoPara[nCurrentNo]->nTableDone[0] = 0;
- l_pstCurrEinSchInfoPara[nCurrentNo]->nTableDone[1] = 0;
- SISubTable[EITSubTableID].details.timeout = J_SI_EIT_SCHEDULE_TIMEOUT;
- if (filter->tableID == 0x50)
- {
- SISubTable[EITSubTableID].details.tableID = 0x50;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEinSchInfoPara[nCurrentNo]->nSvcID;
- SISubTableStart(EITSubTableID, filter->filterNumber, -1,
- l_pstCurrEinSchInfoPara[nCurrentNo]->handle);
-
- filterNumber = SIGetFilterNum(EITSubTableID, 0x51, filter->tableIDExt);
- if (filterNumber != 0xFFFFFFFF)
- {
- SISubTable[EITSubTableID].details.tableID = 0x51;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEinSchInfoPara[nCurrentNo]->nSvcID;
- SISubTableStart(EITSubTableID, filterNumber, -1,
- l_pstCurrEinSchInfoPara[nCurrentNo]->handle);
- }
- }
- else
- {
- SISubTable[EITSubTableID].details.tableID = 0x51;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEinSchInfoPara[nCurrentNo]->nSvcID;
- SISubTableStart(EITSubTableID, filter->filterNumber, -1,
- l_pstCurrEinSchInfoPara[nCurrentNo]->handle);
-
- filterNumber = SIGetFilterNum(EITSubTableID, 0x50, filter->tableIDExt);
- if (filterNumber != 0xFFFFFFFF)
- {
- SISubTable[EITSubTableID].details.tableID = 0x50;
- SISubTable[EITSubTableID].details.tableIDExt = l_pstCurrEinSchInfoPara[nCurrentNo]->nSvcID;
- SISubTableStart(EITSubTableID, filterNumber, -1,
- l_pstCurrEinSchInfoPara[nCurrentNo]->handle);
- }
- }
- return ;
- }
- pstEinSchInfo = l_pstCurrEinSchInfoPara[nCurrentNo]->pstEinSchInfo;
- if(pstEinSchInfo == NULL)
- {
- return;
- }
- pstEinSchInfo->service_id = table_id_extension;
- nWday = -1;
- while(dataLength > 0)
- {
- int descriptors_loop_length;
- memset(pstEvent, 0, sizeof(KB_SIEitSchEvent));
- memset(text, 0, sizeof(text));
- pstEvent->chinese.text = text;
- pstEvent->event_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- dataLength -= 2;
- if(pInData[0] != 0xFF || pInData[1] != 0xFF || pInData[2] != 0xFF
- || pInData[3] != 0xFF || pInData[4] != 0xFF)
- {
- SIParseTime(pInData, &(pstEvent->start_time));
- }
- else
- {
- pstEvent->start_time = 0;
- }
- pInData += 5;
- dataLength -= 5;
- SIParseDuration(pInData, &(pstEvent->duration));
- pInData += 3;
- dataLength -= 3;
- pstEvent->running_status = (UINT8)(pInData[0] >> 5);
- pstEvent->free_CA_mode = (UINT8)((pInData[0] & 0x10) >> 4);
- descriptors_loop_length = (pInData[0] & 0x0F) * 0x100 + pInData[1];
- pInData += 2;
- dataLength -= 2;
- SIEitSCHDescs(pInData, descriptors_loop_length, pstEvent);
- pInData += descriptors_loop_length;
- dataLength -= descriptors_loop_length;
- if(pstEinSchInfo->num < KB_SI_MAX_EVENT_NUM_PER_SERVICE)
- {
- KB_SIEitSchEvent *pTmp = pstEinSchInfo->ptEvent + pstEinSchInfo->num;
- pTmp->chinese.text = (UINT8 *)KB_OSPMalloc(KB_SI_MAX_EVENT_TEXT_LEN + 1);
-
- if (NULL != pTmp->chinese.text)
- {
- pTmp->event_id = pstEvent->event_id;
- pTmp->start_time = pstEvent->start_time;
- pTmp->duration = pstEvent->duration;
- pTmp->running_status = pstEvent->running_status;
- pTmp->free_CA_mode = pstEvent->free_CA_mode;
- pTmp->content_level1 = pstEvent->content_level1;
- pTmp->reference_service_id = pstEvent->reference_service_id;
- pTmp->reference_event_id = pstEvent->reference_event_id;
- memcpy(pTmp->chinese.event_name,
- pstEvent->chinese.event_name,
- KB_SI_MAX_EVENT_NAME_LEN + 1);
- memcpy(pTmp->chinese.text,
- pstEvent->chinese.text,
- KB_SI_MAX_EVENT_TEXT_LEN + 1);
- }
- else
- {
- printf("nSISectionEinSchInfo::KB_OSPMalloc text fail!n");
- }
- pstEinSchInfo->num++;
- }
- }
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = (UINT32)(KB_SI_MSG_EIT_SCHEDULE_EVENT_DONE);
- message.Word3 = (UINT32)pstEinSchInfo;
- message.Word4 = (UINT32)pstEinSchInfo->num;
- //KD_DTVSendMsg(&message);
- return;
- }
- static void SISectionEinSchInfoShift(MepgData *section)
- {
- UINT8 *pInData;
- INT32 dataLength;
- KB_SIEitSchTimeShiftNode tShiftEvent;
- KB_SIEitSchTimeShift *ptShift;
- KB_SIEitSchTimeShiftNode *ptShiftEvent;
- UINT16 table_id;
- UINT16 table_id_extension;
- UINT8 version_number;
- UINT8 section_number;
- UINT8 last_section_number;
- UINT16 serID;
- UINT16 transport_stream_id;
- UINT8 segment_last_section_number;
-
- int i;
-
- INT32 nCurrParaNum;
- KB_OSPMsgNode message;
- ptShiftEvent = &tShiftEvent;
-
- pInData = section->data;
- dataLength = section->length;
-
- table_id = pInData[0];
- table_id_extension = (UINT16)(pInData[3] * 0x100 + pInData[4]); //ServiceID
- serID = pInData[3] << 8 | pInData[4];
- for(i = 0; i < SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS; i ++)
- {
- if(gptCurrSchShiftPara[i]->nSvcID == table_id_extension)
- {
- nCurrParaNum = i;
- ptShift = gptCurrSchShiftPara[i]->ptTimeShift;
- break;
- }
- if (i >= SI_NO_EIT_SCHEDULE_TIME_SHIFT_FILTERS)
- {
- return;
- }
- }
-
- version_number = (UINT8)((pInData[5] & 0x3E) >> 1);
- section_number = pInData[6];
- last_section_number = pInData[7];
- transport_stream_id = pInData[8] << 8 | pInData[9];
-
- if (gptCurrSchShiftPara[nCurrParaNum]->nReceivedFlag[section_number] == 1)
- {
- return;
- }
- else
- {
- gptCurrSchShiftPara[nCurrParaNum]->nReceivedFlag[section_number] = 1;
- }
- pInData += 8;
- dataLength -= 8;
- if( dataLength <= 0)
- {
- return;
- }
- segment_last_section_number = pInData[4];
- if(section_number == segment_last_section_number)
- {
- for(i = (int)section_number + 1; i < ((int)segment_last_section_number / 8 + 1)* 8; i++)
- {
- gptCurrSchShiftPara[nCurrParaNum]->nReceivedFlag[i] = 1;
- }
- }
-
- pInData += 6;
- dataLength -= 6;
-
- {
- while(dataLength > 0)
- {
- int descriptors_loop_length;
- memset(ptShiftEvent, 0, sizeof(KB_SIEitSchTimeShiftNode));
- ptShiftEvent->event_id = (UINT16)(pInData[0] * 0x100 + pInData[1]);
- pInData += 2;
- dataLength -= 2;
- if(pInData[0] != 0xFF || pInData[1] != 0xFF || pInData[2] != 0xFF
- || pInData[3] != 0xFF || pInData[4] != 0xFF)
- {
- SIParseTime(pInData, &(ptShiftEvent->start_time));
- }
- else
- {
- ptShiftEvent->start_time = 0;
- }
- pInData += 5;
- dataLength -= 5;
-
- pInData += 3;
- dataLength -= 3;
- descriptors_loop_length = (pInData[0] & 0x0F) * 0x100 + pInData[1];
- pInData += 2;
- dataLength -= 2;
- SISectionEITScheduleShiftDescriptors(pInData, descriptors_loop_length, ptShiftEvent);
- pInData += descriptors_loop_length;
- dataLength -= descriptors_loop_length;
- {
- if(ptShift->num < KB_SI_MAX_SHIFT_EVENT_NUM_PER_SERVICE)
- {
- memcpy(ptShift->ptTimeShift+ ptShift->num, ptShiftEvent, sizeof(KB_SIEitSchTimeShiftNode));
- ptShift->num++;
- }
- }
- }
-
- memset(&message, 0, sizeof(KB_OSPMsgNode));
- message.Word1 = MOD_SIPSI;
- message.Word2 = (UINT32)(KB_SI_MSG_EIT_SCHEDULE_EVENT_DONE);
- message.Word3 = (UINT32)ptShift;
- message.Word4 = (UINT32)ptShift->num;
- //KD_DTVSendMsg(&message);
- }
-
- }
- static void SISectionEITScheduleShiftDescriptors(UINT8* pInData,
- INT32 dataLen,
- KB_SIEitSchTimeShiftNode* pstEvent)
- {
- UINT8 *data;
- UINT32 tag;
- UINT8 length;
- UINT8 event_name_length;
- UINT8 text_length;
- while(dataLen > 0)
- {
- tag = *pInData++;
- length = *pInData++;
- data = pInData;
- pInData += length;
- dataLen -= ((INT32)length + 2);
- if(length == 0)
- continue;
- switch(tag)
- {
- case KB_FILTER_SI_SHORT_EVENT:
- data += 3;
- event_name_length = *data++;
- data += event_name_length;
- text_length = *data++;
- //data += text_length;
- break;
- case KB_FILTER_SI_STUFFING:
- case KB_FILTER_SI_LINKAGE:
- case KB_FILTER_SI_EXTENDED_EVENT:
- case KB_FILTER_SI_COMPONENT:
- case KB_FILTER_SI_CA_IDENTIFIER:
- case KB_FILTER_SI_CONTENT:
- case KB_FILTER_SI_PARENTAL_RATING:
- case KB_FILTER_SI_TELEPHONE:
- case KB_FILTER_SI_MULTILINGUAL_COMPONENT:
- case KB_FILTER_SI_PRIVATE_DATA_SPECIFIER:
- case KB_FILTER_SI_SHORT_SMOOTHING_BUFFER:
- case KB_FILTER_SI_DATA_BROADCAST:
- break;
- case KB_FILTER_SI_TIME_SHIFTED_EVENT:
- pstEvent->reference_service_id = (data[0] << 8) | (data[1]);
- data += 2;
- pstEvent->reference_event_id = (data[0] << 8) | (data[1]);
-
- break;
- default:
- break;
- }
- }
- }
- /* EOF */