📄 psi.c
字号:
PrgNo =*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset);
PrgPMTPid=*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset + 2);
if(PrgNo==0)
HasNIT=0;
else
{
PrgInfo[PrgCnt][0]=PrgNo;
PrgInfo[PrgCnt++][1]=PrgPMTPid;
}
Offset+=4;
Rest-=4;
}
/*-------------------------------------------------------------------------------*/
/*重新生成PAT */
/*-------------------------------------------------------------------------------*/
if(Nit.TS_Count>0)
PAT_Section_Head->Transport_stream_id=Nit.Transport_Stream_ID;
PAT_Section_Head->SectionLength=sizeof(PAT_SECTION_TAG) - 3 + 4;
Offset=sizeof(PAT_SECTION_TAG);
if((Nit.TS_Count>0)&&(HasNIT==0))
{
*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset) =0x0;
*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset + 2)=(0x10)|0xE000;;
Offset+=4;
PAT_Section_Head->SectionLength+=4;
}
for(i=0;i<PrgCnt;i++)
{
*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset) =PrgInfo[i][0];
*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset + 2)=PrgInfo[i][1];
Offset+=4;
PAT_Section_Head->SectionLength+=4;
}
*(unsigned long *)((unsigned char *)PAT_Section_Head + PAT_Section_Head->SectionLength + 3 - 4)=GetCRC((unsigned char *)PAT_Section_Head,PAT_Section_Head->SectionLength + 3 - 4);
g_gen_si_info.pat_section.section_length=PAT_Section_Head->SectionLength + 3;
/*MemCopy(g_gen_si_info.pat_section.section,(unsigned char *)PAT_Section_Head,PAT_Section_Head->SectionLength + 3); */
g_gen_si_info.flag=1;
/*------------------------------------------------------------------------------*/
/*修改SDT */
/*------------------------------------------------------------------------------*/
for(i=0;i<New_SDT.SectionCount;i++)
{
SDT_Section_Head=(SDT_SECTION_TAG *)New_SDT.SectionList[i].Section;
if(Nit.TS_Count>0)
{
SDT_Section_Head->Transport_stream_id=Nit.Transport_Stream_ID;
SDT_Section_Head->Original_network_id=Nit.Network_ID;
}
else
{
SDT_Section_Head->Transport_stream_id=0;
SDT_Section_Head->Original_network_id=0;
}
*(unsigned long *)((unsigned char *)SDT_Section_Head + 3 + SDT_Section_Head->Section_Length - 4)=GetCRC((unsigned char *)SDT_Section_Head,SDT_Section_Head->Section_Length + 3 -4);
}
}
void UpdateSDT(void)
{
SDT_SECTION_TAG *SDT_Section_Head;
SDT_ELEMENT_TAG *SDT_Element_Head;
unsigned char PortNo;
unsigned short NewPrgNo,OldPrgNo;
unsigned short Offset;
short Rest;
int i,j;
short EITItemIndex;
/*------------------------------------------------------------------------------*/
/*修改SDT */
/*------------------------------------------------------------------------------*/
for(i=0;i<New_SDT.SectionCount;i++)
{
SDT_Section_Head=(SDT_SECTION_TAG *)New_SDT.SectionList[i].Section;
/*SDT_Section_Head->Version_number+=1;*/
Rest=SDT_Section_Head->Section_Length - 5;
Offset=sizeof(SDT_SECTION_TAG);
while(Rest>4)
{
SDT_Element_Head=(SDT_ELEMENT_TAG *)((unsigned char *)New_SDT.SectionList[i].Section + Offset);
SDT_Element_Head->REE=0xFC;
NewPrgNo=SDT_Element_Head->Service_id;
for(j=0;j<Select_Mul.Sels;j++)
{
if(Select_Mul.Sel_Item[j].SetPrgNo==NewPrgNo)
{
PortNo =Select_Mul.Sel_Item[j].PortNo;
OldPrgNo=Select_Mul.Sel_Item[j].OldPrgNo;
/*---------------------------------------------------------------------*/
/*修改REE */
/*---------------------------------------------------------------------*/
EITItemIndex=GetEITItemIndex(PortNo,OldPrgNo);
if(EITItemIndex!=-1)
{
if(EIT_Item_List.Item[EITItemIndex].Schedule_Flag)
SDT_Element_Head->REE|=0x02;
if(EIT_Item_List.Item[EITItemIndex].Present_Following_Flag)
SDT_Element_Head->REE|=0x01;
}
break;
}
}
Offset+=sizeof(SDT_ELEMENT_TAG) + SDT_Element_Head->Descriptors_loop_length;
Rest -=sizeof(SDT_ELEMENT_TAG) + SDT_Element_Head->Descriptors_loop_length;
}
*(unsigned long *)((unsigned char *)SDT_Section_Head + 3 + SDT_Section_Head->Section_Length - 4)=GetCRC((unsigned char *)SDT_Section_Head,SDT_Section_Head->Section_Length + 3 -4);
}
}
void ClearPMTNULLPacket(void)
{
PMT_SECTION_TAG *PMT_Section_Head,*pNewPMT_Section_Head;
ES_INFO_Tag *pEs_Info;
unsigned short pmtOffset;
short Rest;
int i;
g_gen_si_info.flag=0;
pNewPMT_Section_Head=(PMT_SECTION_TAG *)MemAlloc(RNG2ID,"CLEARPMTNULLPacket",2048);
if(pNewPMT_Section_Head == NULL)
return;
for(i=0;i<g_gen_si_info.pmt_section_number;i++)
{
PMT_Section_Head=(PMT_SECTION_TAG *)(g_gen_si_info.pmt_sectoin_list[i].section);
MemCopy((unsigned char *)pNewPMT_Section_Head,(unsigned char *)PMT_Section_Head,sizeof(PMT_SECTION_TAG) + PMT_Section_Head->Program_info_length);
pNewPMT_Section_Head->SectionLength=sizeof(PMT_SECTION_TAG) - 3 + PMT_Section_Head->Program_info_length;
pmtOffset=sizeof(PMT_SECTION_TAG) + PMT_Section_Head->Program_info_length;
Rest=PMT_Section_Head->SectionLength - 4 - (sizeof(PMT_SECTION_TAG) - 3) - PMT_Section_Head->Program_info_length;
pEs_Info=(ES_INFO_Tag *)((unsigned char *)PMT_Section_Head + sizeof(PMT_SECTION_TAG) + PMT_Section_Head->Program_info_length);
while(Rest>0)
{
if(pEs_Info->Elelmentary_PID!=0x1FFF)
{
MemCopy((unsigned char *)pNewPMT_Section_Head + pmtOffset,(unsigned char *)pEs_Info,sizeof(ES_INFO_Tag) + pEs_Info->ES_info_length);
pmtOffset +=sizeof(ES_INFO_Tag) + pEs_Info->ES_info_length;
pNewPMT_Section_Head->SectionLength +=sizeof(ES_INFO_Tag) + pEs_Info->ES_info_length;
}
Rest-=sizeof(ES_INFO_Tag) + pEs_Info->ES_info_length;
pEs_Info=(ES_INFO_Tag *)((unsigned char *)pEs_Info + sizeof(ES_INFO_Tag) + pEs_Info->ES_info_length);
}
pNewPMT_Section_Head->SectionLength +=4;
*(unsigned long *)((unsigned char *)pNewPMT_Section_Head + pNewPMT_Section_Head->SectionLength + 3 - 4)=GetCRC((unsigned char *)pNewPMT_Section_Head,pNewPMT_Section_Head->SectionLength + 3 -4);
g_gen_si_info.pmt_sectoin_list[i].section_length=pNewPMT_Section_Head->SectionLength + 3;
MemCopy((unsigned char *)g_gen_si_info.pmt_sectoin_list[i].section,(unsigned char *)pNewPMT_Section_Head,pNewPMT_Section_Head->SectionLength + 3);
}
g_gen_si_info.flag=1;
MemFree(pNewPMT_Section_Head);
}
void UnitePrgUpdatePSI(void)
{
unsigned short PrgInfo[32][2];
int PrgCnt;
PAT_SECTION_TAG *PAT_Section_Head,*pNew_PAT_Section_Head;
PMT_SECTION_TAG *PMT_Section_Head,*pNewPMT_Section_Head;
GEN_SI_INFO *pGenSIInfo;
unsigned short Offset,pmtOffset,SectionLength;
short Rest,rest;
unsigned short PrgNo,PrgPMTPid;
unsigned short UnitePrgNo;
int index,firstmatch;
int i,j;
int NeedUnite,HaveCreatePMT,HasAddedUnitedPrgam,EsDataLen;
char *buf;
int bufLen=0;
PAT_Section_Head=(PAT_SECTION_TAG *)(g_gen_si_info.pat_section.section);
Rest=SectionLength=PAT_Section_Head->SectionLength - 5;
Offset=sizeof(PAT_SECTION_TAG);
PrgCnt=0;
while(Rest>4)
{
PrgNo =*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset);
PrgPMTPid=*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset + 2);
PrgInfo[PrgCnt][0]=PrgNo;
PrgInfo[PrgCnt++][1]=PrgPMTPid;
Offset+=4;
Rest-=4;
}
NeedUnite=0;
for(i=0;i<PrgCnt;i++)
{
PrgNo=PrgInfo[i][0];
for(j=0;j<PrgCnt;j++)
{
if(j==i)
continue;
if(PrgInfo[j][0]==PrgNo)
{
UnitePrgNo=PrgNo;
NeedUnite=1;
break;
}
}
}
if(!NeedUnite)
return;
g_gen_si_info.flag=0;
/*-------------------------------------------------------------------------------*/
/*重新生成PAT */
/*-------------------------------------------------------------------------------*/
pNew_PAT_Section_Head=(PAT_SECTION_TAG *)MemAlloc(RNG2ID,"UnitePrgUpdatePSI",2048);
if(pNew_PAT_Section_Head == NULL)
return;
MemCopy((unsigned char *)pNew_PAT_Section_Head,(unsigned char *)PAT_Section_Head,sizeof(PAT_SECTION_TAG));
pNew_PAT_Section_Head->SectionLength=sizeof(PAT_SECTION_TAG) -3 + 4;
Offset=sizeof(PAT_SECTION_TAG);
HasAddedUnitedPrgam=0;
for(i=0;i<PrgCnt;i++)
{
if((HasAddedUnitedPrgam)&&(PrgInfo[i][0]==UnitePrgNo))
continue;
*(unsigned short *)((unsigned char *)pNew_PAT_Section_Head + Offset) =PrgInfo[i][0];
*(unsigned short *)((unsigned char *)pNew_PAT_Section_Head + Offset + 2)=PrgInfo[i][1];
if(PrgInfo[i][0]==UnitePrgNo)
HasAddedUnitedPrgam=1;
Offset+=4;
pNew_PAT_Section_Head->SectionLength+=4;
}
/*------------------------------------------------------------------------------*/
/*生成CRC校验 */
/*------------------------------------------------------------------------------*/
*(unsigned long *)((unsigned char *)pNew_PAT_Section_Head + pNew_PAT_Section_Head->SectionLength + 3 - 4)=GetCRC((unsigned char *)pNew_PAT_Section_Head,pNew_PAT_Section_Head->SectionLength + 3 -4);
g_gen_si_info.pat_section.section_length=pNew_PAT_Section_Head->SectionLength + 3;
MemCopy(g_gen_si_info.pat_section.section,(unsigned char *)pNew_PAT_Section_Head,pNew_PAT_Section_Head->SectionLength + 3);
MemFree(pNew_PAT_Section_Head);
/*--------------------------------------------------------------------------*/
/*生成新PMT */
/*--------------------------------------------------------------------------*/
pNewPMT_Section_Head=(PMT_SECTION_TAG *)MemAlloc(RNG2ID,"UnitePrgUpdatePSI",2048);
if(pNewPMT_Section_Head == NULL)
return;
HaveCreatePMT=0;
for(i=0;i<g_gen_si_info.pmt_section_number;i++)
{
PMT_Section_Head=(PMT_SECTION_TAG *)(g_gen_si_info.pmt_sectoin_list[i].section);
if(PMT_Section_Head->Program_number==UnitePrgNo)
{
if(!HaveCreatePMT)
{
MemCopy((unsigned char *)pNewPMT_Section_Head,g_gen_si_info.pmt_sectoin_list[i].section,g_gen_si_info.pmt_sectoin_list[i].section_length);
pmtOffset=pNewPMT_Section_Head->SectionLength + 3 - 4;
HaveCreatePMT=1;
}
else
{
EsDataLen=PMT_Section_Head->SectionLength - (sizeof(PMT_SECTION_TAG) - 3) - PMT_Section_Head->Program_info_length - 4;
MemCopy((unsigned char *)pNewPMT_Section_Head + pmtOffset,(unsigned char *)PMT_Section_Head + sizeof(PMT_SECTION_TAG) + PMT_Section_Head->Program_info_length,EsDataLen);
pNewPMT_Section_Head->SectionLength += EsDataLen;
pmtOffset+=EsDataLen;
}
}
}
*(unsigned long *)((unsigned char *)pNewPMT_Section_Head + pNewPMT_Section_Head->SectionLength + 3 - 4)=GetCRC((unsigned char *)pNewPMT_Section_Head,pNewPMT_Section_Head->SectionLength + 3 -4);
/*---------------------------------------------------------------*/
pGenSIInfo=(GEN_SI_INFO *)MemAlloc(RNG2ID,"UnitePrgUpdatePSI",sizeof(GEN_SI_INFO));
if(pGenSIInfo == NULL)
return;
pGenSIInfo->pmt_section_number=g_gen_si_info.pmt_section_number;
for(i=0;i<g_gen_si_info.pmt_section_number;i++)
{
pGenSIInfo->pmt_sectoin_list[i].pid=g_gen_si_info.pmt_sectoin_list[i].pid;
pGenSIInfo->pmt_sectoin_list[i].section_length=g_gen_si_info.pmt_sectoin_list[i].section_length;
MemCopy(pGenSIInfo->pmt_sectoin_list[i].section,g_gen_si_info.pmt_sectoin_list[i].section,g_gen_si_info.pmt_sectoin_list[i].section_length);
}
index=0;
firstmatch=1;
for(i=0;i<pGenSIInfo->pmt_section_number;i++)
{
PMT_Section_Head=(PMT_SECTION_TAG *)(pGenSIInfo->pmt_sectoin_list[i].section);
if(PMT_Section_Head->Program_number!=UnitePrgNo)
{
g_gen_si_info.pmt_sectoin_list[index].pid=pGenSIInfo->pmt_sectoin_list[i].pid;
g_gen_si_info.pmt_sectoin_list[index].section_length=pGenSIInfo->pmt_sectoin_list[i].section_length;
MemCopy(g_gen_si_info.pmt_sectoin_list[index].section,pGenSIInfo->pmt_sectoin_list[i].section,pGenSIInfo->pmt_sectoin_list[i].section_length);
index++;
}
else if(firstmatch)
{
firstmatch=0;
g_gen_si_info.pmt_sectoin_list[index].pid=pGenSIInfo->pmt_sectoin_list[i].pid;
g_gen_si_info.pmt_sectoin_list[index].section_length=pNewPMT_Section_Head->SectionLength + 3;
MemCopy(g_gen_si_info.pmt_sectoin_list[index].section,(unsigned char *)pNewPMT_Section_Head,pNewPMT_Section_Head->SectionLength + 3);
index++;
}
}
g_gen_si_info.pmt_section_number=index;
g_gen_si_info.flag=1;
MemFree(pNewPMT_Section_Head);
MemFree(pGenSIInfo);
}
/*生成新的PMT段*/
int NewPMTSection(unsigned char PortNo,unsigned short OldPrgNo)
{
PMT_SECTION_TAG *PMT_Section_Head,*pSection;
ES_INFO_Tag *ES_Info_Head;
CA_DESCRIPTOR_TAG *CA_Head;
unsigned short Old_PMT_PID,New_PMT_PID;
unsigned short Prg_Info_Length;
unsigned short Es_Info_Length;
unsigned short Total_Es_Info_Length;
short PrgRest,EsRest,Rest;
int Found;
int i,k,MuxIndex=-1;
int offset=0,rmvlen = 0;
int index;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -