📄 repid.c
字号:
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=0;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=0;
}
while(1)
{
if(TSRest>(Section_Head->SectionLength + 3))
{
MemCopy(Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].Section,(char *)Section_Head,Section_Head->SectionLength + 3);
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=Section_Head->SectionLength + 3;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=Section_Head->SectionLength + 3;
Get_PSI_Result[PortNo].SectionCount++;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].PID=PID;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=0;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=0;
/*-----------------------------------------------*/
/* 这个包的后面还有另外一个SECTION的数据吗 */
/*-----------------------------------------------*/
TSEND=0;
CheckVal=*(unsigned char *)((unsigned char *)Section_Head + Section_Head->SectionLength + 3);
/*------------------------------------------------------------------------*/
/* SDT的TABLE ID =0x42/0x46 */
/*------------------------------------------------------------------------*/
if(PID==0x11)
{
if((CheckVal!=0x42)&&(CheckVal!=0x46))
TSEND=1;
}
else
{
if((CheckVal!=0x2))
TSEND=1;
}
if(TSEND)
break;
TSRest-=(Section_Head->SectionLength + 3);
Section_Head=(SECTION_TAG *)((unsigned char *)Section_Head + Section_Head->SectionLength + 3);
SectionRest=SectionLength=Section_Head->SectionLength + 3;
}
else/* copy the part of section */
{
sectionoffset=Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength;
MemCopy(Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].Section + sectionoffset,(char *)Section_Head,TSRest);
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=Section_Head->SectionLength + 3;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength+=TSRest;
break;
}
}
}
/*----------------------------------------------------------------------------------------------------*/
/* 此TS包没有section head */
/* 将净荷组装到section中 */
/*----------------------------------------------------------------------------------------------------*/
else
{
sectionoffset=Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength;
if((sectionoffset==0)||(sectionoffset>=Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength))
{
Display("[AnalysePSITS]:empty section found when no section head!\n");
return Get_PSI_Result[PortNo].SectionCount;
}
SectionRest=Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength - sectionoffset;
TSRest =188 - sizeof(TS_TAG);
if(TSRest>SectionRest)
{
MemCopy(Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].Section + sectionoffset,(unsigned char *)TS_Head + sizeof(TS_TAG),SectionRest);
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength+=SectionRest;
Get_PSI_Result[PortNo].SectionCount++;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].PID=PID;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=0;
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=0;
}
else
{
MemCopy(Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].Section + sectionoffset,(unsigned char *)TS_Head + sizeof(TS_TAG),TSRest);
Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength+=TSRest;
}
}
TS_Head = (TS_TAG *)((unsigned char *)TS_Head + 188);
}
return Get_PSI_Result[PortNo].SectionCount;
}
}
else
return 0;
}
#endif
/*从端口获取PAT段*/
unsigned long GetPATSection(unsigned char PortNo,unsigned char *Buf)
{
int i;
unsigned char Result;
PAT_SECTION_TAG *PAT_Section_Head;
Result=0;
for(i=0;i<2;i++)
{
Result=AnalysePSITS(PortNo,0);
if(Result>0)
break;
}
if(Result==0)
return 0;
MemCopy(Buf,Get_PSI_Result[PortNo].Sections[0].Section,Get_PSI_Result[PortNo].Sections[0].SectionLength);
return Get_PSI_Result[PortNo].Sections[0].SectionLength;
}
unsigned long GetCATSection(unsigned char PortNo,unsigned char *Buf)
{
int i;
unsigned char Result;
CAT_SECTION_TAG *CAT_Section_Head;
Result=0;
for(i=0;i<2;i++)
{
Result=AnalysePSITS(PortNo,0x01);
if(Result>0)
break;
}
if(Result==0)
return 0;
MemCopy(Buf,Get_PSI_Result[PortNo].Sections[0].Section,Get_PSI_Result[PortNo].Sections[0].SectionLength);
return Get_PSI_Result[PortNo].Sections[0].SectionLength;
}
unsigned long GetPMTSection(unsigned char PortNo,unsigned short PID,unsigned short PrgNo, unsigned char *Buf)
{
int i;
unsigned char Result;
PMT_SECTION_TAG *PMT_Section_Head;
for(i=0;i<Get_PSI_Result[PortNo].SectionCount;i++)
{
PMT_Section_Head=(PMT_SECTION_TAG *)Get_PSI_Result[PortNo].Sections[i].Section;
if((PMT_Section_Head->Program_number==PrgNo)&&(Get_PSI_Result[PortNo].Sections[i].PID==PID))
{
MemCopy(Buf,Get_PSI_Result[PortNo].Sections[i].Section,Get_PSI_Result[PortNo].Sections[i].SectionLength);
return Get_PSI_Result[PortNo].Sections[i].SectionLength;
}
}
Result=0;
for(i=0;i<2;i++)
{
Result=AnalysePSITS(PortNo,PID);
if(Result>0)
break;
}
if(Result==0)
return 0;
for(i=0;i<Get_PSI_Result[PortNo].SectionCount;i++)
{
PMT_Section_Head=(PMT_SECTION_TAG *)Get_PSI_Result[PortNo].Sections[i].Section;
if(PMT_Section_Head->Program_number==PrgNo)
{
MemCopy(Buf,Get_PSI_Result[PortNo].Sections[i].Section,Get_PSI_Result[PortNo].Sections[i].SectionLength);
return Get_PSI_Result[PortNo].Sections[i].SectionLength;
}
}
}
/*从相应端口获取SDT信息*/
unsigned long GetSDT(unsigned char PortNo)
{
SDT_SECTION_TAG *SDT_Section_Head;
unsigned char Sections;
unsigned char SDT_Section_Count;
int i;
SDT_Info[PortNo].SectionCount=0;
SDT_Service_Info[PortNo].ServiceCount=0;
/*读取SDT信息*/
Sections=AnalysePSITS(PortNo,0x11);
if(Sections==0)
return 0;
else
{
SDT_Section_Count=0;
for(i=0;i<Get_PSI_Result[PortNo].SectionCount;i++)
{
SDT_Section_Head=(SDT_SECTION_TAG *)Get_PSI_Result[PortNo].Sections[i].Section;
if(SDT_Section_Head->TableID!=0x42)
continue;
/*--------------------------------------------------------------------------*/
/* CRC校验 */
/*--------------------------------------------------------------------------*/
if(CRC_Verify((unsigned char *)SDT_Section_Head,SDT_Section_Head->Section_Length + 3))
{
Display("SDT CRC verify error!\n");
return 0;
}
else
{
SDT_Info[PortNo].PortSections[SDT_Section_Count].SectionLength=SDT_Section_Head->Section_Length + 3;
if(SDT_Info[PortNo].PortSections[SDT_Section_Count].Section!=NULL)
MemFree(SDT_Info[PortNo].PortSections[SDT_Section_Count].Section);
SDT_Info[PortNo].PortSections[SDT_Section_Count].Section=(unsigned char *)MemAlloc(RNG2ID,"GetSDT",SDT_Info[PortNo].PortSections[SDT_Section_Count].SectionLength);
if(SDT_Info[PortNo].PortSections[SDT_Section_Count].Section == NULL)
return 0;
MemCopy((unsigned char *)SDT_Info[PortNo].PortSections[SDT_Section_Count].Section,(unsigned char *)SDT_Section_Head,SDT_Info[PortNo].PortSections[SDT_Section_Count].SectionLength);
Display("Found section %d of SDT \n",SDT_Section_Count);
SDT_Section_Count++;
}
}
}
SDT_Info[PortNo].SectionCount=SDT_Section_Count;
return SDT_Section_Count;
}
void ClearPIDInfo(unsigned char PortNo)
{
int j;
if(PID_Info[PortNo].PAT.PAT_Section!=NULL)
{
MemFree(PID_Info[PortNo].PAT.PAT_Section);
PID_Info[PortNo].PAT.PAT_Section=NULL;
}
PID_Info[PortNo].PAT.Section_Length =0;
for(j=0;j<32;j++)
{
PID_Info[PortNo].PMT[j].Section_Length =0;
}
PID_Info[PortNo].PMTs =0;
PID_Info[PortNo].PIDs =0;
/************************************************************/
/* Init SDT section */
/************************************************************/
SDT_Info[PortNo].SectionCount=0;
for(j=0;j<256;j++)
{
SDT_Info[PortNo].PortSections[j].SectionLength=0;
}
SDT_Service_Info[PortNo].ServiceCount=0;
}
/*------------------------------------------------------------------*/
/* 提取一个端口的PID信息,如果端口无输入,返回0 */
/*------------------------------------------------------------------*/
unsigned long GetPATPMT(unsigned char PortNo)
{
unsigned char *Section=NULL;
unsigned short Section_Length;
unsigned char PATs;
PMT_SECTION_TAG *PMT_Section_Head;
CAT_SECTION_TAG *CAT_Section_Head;
CA_DESCRIPTOR_TAG *CA_Head;
unsigned char PMT_Sections;
unsigned char GotPMTs;
unsigned char Index;
unsigned short PMT_Pid[32];
unsigned short PrgNo[32];
unsigned char PMTs;
unsigned char PIDs;
unsigned char *DataAddr;
unsigned char CA_PID_Index;
unsigned short CA_PID_List[8]={0x1F00,0x1F10,0x1F20,0x1F30,0x1F40,0x1F50,0x1F60,0x1F70};
int i,j,k;
unsigned long rc;
int Loop;
short Rest;
int haveprocessed;
unsigned char GotPAT=0;
unsigned char GotPMT=0;
ClearPIDInfo(PortNo);
PID_Info[PortNo].PMTs=0;
PID_Info[PortNo].PIDs=0;
PID_Info[PortNo].CAT.Section_Length=0;
Section=(unsigned char *)MemAlloc(RNG2ID,"GetPATPMT---section", 188*16);
if(Section == NULL)
{
Display("Alloc Memory false!",errno);
return;
}
/*--------------------------------------------------------*/
/* 先提取PAT */
/*--------------------------------------------------------*/
for(Loop=0;Loop<2;Loop++)
{
/*提取PAT*/
Section_Length=GetPATSection(PortNo,Section);
if(Section_Length==0)
continue;
/*----------------------------------------------------*/
/* 对PAT进行CRC校验 */
/*----------------------------------------------------*/
if(CRC_Verify(Section,Section_Length)==0)
{
/*------------------------------------------------*/
/* 校验正确,保存到全局变量中 */
/*------------------------------------------------*/
PID_Info[PortNo].PAT.Section_Length=Section_Length;
if(PID_Info[PortNo].PAT.PAT_Section!=NULL)
MemFree(PID_Info[PortNo].PAT.PAT_Section);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -