📄 psi.c
字号:
PMT_Section_Head=(PMT_SECTION_TAG *)MemAlloc(RNG2ID,"NewPMTSection",2048);
if(PMT_Section_Head == NULL)
return 1;
Found=0;
for(i=0;i<PID_Info[PortNo].PMTs;i++)
{
pSection=(PMT_SECTION_TAG *)(PID_Info[PortNo].PMT[i].PMT_Section);
if(pSection->Program_number==OldPrgNo)
{
Old_PMT_PID=PID_Info[PortNo].PMT[i].PMT_PID;
/*根据旧的PID和节目号,获得设置的新的PID*/
New_PMT_PID=GetSetPIDEx(PortNo,OldPrgNo,Old_PMT_PID,STREAM_TYPE_PMT);
MemCopy(PMT_Section_Head,pSection,PID_Info[PortNo].PMT[i].Section_Length + 3);
Found=1;
for(k=0;k<Select_Mul.Sels;k++)
{/*找到相对应的复用设置的列表项*/
if(Select_Mul.Sel_Item[k].OldPrgNo == OldPrgNo)
{
MuxIndex = k;
break;
}
}
break;
}
}
if(!Found)
{
MemFree(PMT_Section_Head);
return 1;
}
Prg_Info_Length=PMT_Section_Head->Program_info_length;
/*-----------------------------------------------------------------*/
/* 将Section的内容直接拷贝到PMT中,并替换掉相应的PID */
/*-----------------------------------------------------------------*/
PMT_Section_Head->PCR_PID=GetSetPIDEx(PortNo,OldPrgNo,PMT_Section_Head->PCR_PID,STREAM_TYPE_PCR);
PrgRest=PMT_Section_Head->Program_info_length;
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)PMT_Section_Head + sizeof(PMT_SECTION_TAG));
if(Select_Mul.Sel_Item[MuxIndex].ucRmvScramble)
{/*要求取消加扰描述*/
while(PrgRest>0)
{/*去掉Program_info中的加扰描述*/
offset += CA_Head->Descriptor_length + 2;
if(CA_Head->Descriptor_tag == 0x09)
{
rmvlen += CA_Head->Descriptor_length + 2;
/*覆盖前面的CA描述*/
MemCopy((unsigned char *)CA_Head, (unsigned char *)CA_Head+ CA_Head->Descriptor_length+2, PMT_Section_Head->SectionLength - (sizeof(PMT_SECTION_TAG) -3) -offset);
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head);
}
else
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head + CA_Head->Descriptor_length + 2);
if(offset >= PrgRest)
break;
}
PMT_Section_Head->Program_info_length -= rmvlen;
PMT_Section_Head->SectionLength -= rmvlen;
ES_Info_Head=(ES_INFO_Tag *)((unsigned char *)PMT_Section_Head + sizeof(PMT_SECTION_TAG) + PMT_Section_Head->Program_info_length);
Rest=PMT_Section_Head->SectionLength - (sizeof(PMT_SECTION_TAG) -3) - PMT_Section_Head->Program_info_length - 4;
offset = sizeof(PMT_SECTION_TAG) -3 + PMT_Section_Head->Program_info_length;
while(Rest)
{/*去掉节目中的加扰描述*/
/****************************************************************/
/* 基本流ECM */
/****************************************************************/
EsRest=ES_Info_Head->ES_info_length;
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)ES_Info_Head + sizeof(ES_INFO_Tag));
offset += sizeof(ES_INFO_Tag);
rmvlen = 0;
while(EsRest>0)
{
offset += CA_Head->Descriptor_length + 2;
EsRest-=CA_Head->Descriptor_length + 2;
if(CA_Head->Descriptor_tag==0x09)
{
rmvlen += CA_Head->Descriptor_length + 2;
/*覆盖前面的CA描述*/
MemCopy((unsigned char *)CA_Head, (unsigned char *)CA_Head+ CA_Head->Descriptor_length+2, PMT_Section_Head->SectionLength -offset);
offset -= rmvlen;
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head);
}
else
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head + CA_Head->Descriptor_length + 2);
}
ES_Info_Head->Elelmentary_PID=GetSetPIDEx(PortNo,OldPrgNo,ES_Info_Head->Elelmentary_PID,ES_Info_Head->Stream_type);
Rest-=(sizeof(ES_INFO_Tag) + ES_Info_Head->ES_info_length);
ES_Info_Head->ES_info_length -= rmvlen;
PMT_Section_Head->SectionLength -= rmvlen;
ES_Info_Head=(ES_INFO_Tag *)((unsigned char *)ES_Info_Head + sizeof(ES_INFO_Tag) + ES_Info_Head->ES_info_length);
}
}
else
{
while(PrgRest>0)
{
if(CA_Head->Descriptor_tag==0x09)
{
CA_Head->CA_PID=GetSetPIDEx(PortNo,OldPrgNo,CA_Head->CA_PID,STREAM_TYPE_ECM);
/*----------------------------------------------------------*/
/* modified by johnnyling 2003-09-16 */
/*----------------------------------------------------------*/
/* break; */
}
PrgRest-=CA_Head->Descriptor_length + 2;
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head + CA_Head->Descriptor_length + 2);
}
ES_Info_Head=(ES_INFO_Tag *)((unsigned char *)PMT_Section_Head + sizeof(PMT_SECTION_TAG) + Prg_Info_Length);
Rest=PMT_Section_Head->SectionLength - (sizeof(PMT_SECTION_TAG) -3) - Prg_Info_Length - 4;
while(Rest)
{
/****************************************************************/
/* 基本流ECM */
/****************************************************************/
EsRest=ES_Info_Head->ES_info_length;
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)ES_Info_Head + sizeof(ES_INFO_Tag));
while(EsRest>0)
{
if(CA_Head->Descriptor_tag==0x09)
{
CA_Head->CA_PID=GetSetPIDEx(PortNo,OldPrgNo,CA_Head->CA_PID,STREAM_TYPE_ECM);
}
EsRest-=CA_Head->Descriptor_length + 2;
CA_Head=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head + CA_Head->Descriptor_length + 2);
}
ES_Info_Head->Elelmentary_PID=GetSetPIDEx(PortNo,OldPrgNo,ES_Info_Head->Elelmentary_PID,ES_Info_Head->Stream_type);
Rest-=(sizeof(ES_INFO_Tag) + ES_Info_Head->ES_info_length);
ES_Info_Head=(ES_INFO_Tag *)((unsigned char *)ES_Info_Head + sizeof(ES_INFO_Tag) + ES_Info_Head->ES_info_length);
}
}
/*---------------------------------------------------------------------*/
/* 生成CRC校验 */
/*---------------------------------------------------------------------*/
PMT_Section_Head->Program_number=GetSetPrgNo(PortNo,OldPrgNo);
*(unsigned long *)((unsigned char *)PMT_Section_Head + PMT_Section_Head->SectionLength + 3 - 4)=GetCRC((unsigned char *)PMT_Section_Head,PMT_Section_Head->SectionLength + 3 - 4);
/*---------------------------------------------------------------------*/
/* add to the g_gen_si_info */
/*---------------------------------------------------------------------*/
index=g_gen_si_info.pmt_section_number;
g_gen_si_info.pmt_sectoin_list[index].section_length=PMT_Section_Head->SectionLength + 3;
g_gen_si_info.pmt_sectoin_list[index].pid=New_PMT_PID;
MemCopy(g_gen_si_info.pmt_sectoin_list[index].section,PMT_Section_Head,PMT_Section_Head->SectionLength + 3);
g_gen_si_info.pmt_section_number++;
MemFree(PMT_Section_Head);
return 0;
}
#if 0
int NewCATSection(void)
{
int i,j;
CAT_SECTION_TAG *CAT_Section_Head,*Port_CAT_Section_Head;
CA_DESCRIPTOR_TAG *CA_Head_Src,*CA_Head_Dest;
short Rest;
unsigned char NeedToBeAdded;
unsigned char CAT[188];
unsigned long CRC;
/*---------------------------------------------------------------------*/
/* CAT section */
/*---------------------------------------------------------------------*/
CAT_Section_Head=(CAT_SECTION_TAG *)MemAlloc(RNG2ID,"NewCATSection",2048);
CAT_Section_Head->TableID=0x01;
CAT_Section_Head->Section_syntax_indicator=1;
CAT_Section_Head->Zero=0;
CAT_Section_Head->Reserved1 =3;
CAT_Section_Head->SectionLength=sizeof(CAT_SECTION_TAG) -3 + 4; /* 初始值,需要根据节目的个数修改 */
CAT_Section_Head->Reserved2 =0xFFFF;
CAT_Section_Head->Reserved3 =0x3;
CAT_Section_Head->Version_number =0;
CAT_Section_Head->Current_next_indicator = 1;
CAT_Section_Head->Section_number=0;
CAT_Section_Head->Last_section_number=0;
CA_Head_Dest=(CA_DESCRIPTOR_TAG *)((unsigned char *)CAT_Section_Head + sizeof(CAT_SECTION_TAG));
for(i=0;i<8;i++)
{
if(PID_Info[i].CAT.Section_Length>0)
{
CA_Head_Src =(CA_DESCRIPTOR_TAG *)((unsigned char *)PID_Info[i].CAT.CAT_Section + sizeof(CAT_SECTION_TAG));
Port_CAT_Section_Head=(CAT_SECTION_TAG *)PID_Info[i].CAT.CAT_Section;
Rest=Port_CAT_Section_Head->SectionLength-(sizeof(CAT_SECTION_TAG)-3) - 4;
while(Rest>0)
{
if(CA_Head_Src->Descriptor_tag==0x9)
{
for(j=0;j<Select_Mul.SelsEMM;j++)
{
/*-------------------------------------------------------------*/
/* 选择输出的EMM才加入到CAT中 2002-03-12 更新 */
/*-------------------------------------------------------------*/
if((Select_Mul.Sel_EMM[i].PortNo==i)&&(Select_Mul.Sel_EMM[i].Old_EMM_Pid==CA_Head_Dest->CA_PID))
{
MemCopy((unsigned char *)CA_Head_Dest,(unsigned char *)CA_Head_Src,CA_Head_Src->Descriptor_length + 2);
CA_Head_Dest->CA_PID = GetSetPIDEx(i,0,CA_Head_Dest->CA_PID,STREAM_TYPE_EMM);
CAT_Section_Head->SectionLength +=CA_Head_Dest->Descriptor_length + 2;
CA_Head_Dest=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head_Dest + CA_Head_Dest->Descriptor_length + 2);
break;
}
}
}
Rest-=CA_Head_Src->Descriptor_length + 2;
CA_Head_Src=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head_Src + CA_Head_Src->Descriptor_length + 2);
}
}
}
/*---------------------------------------------------------------------*/
/*生成CAT的校验 */
/*---------------------------------------------------------------------*/
*(unsigned long *)((unsigned char *)CAT_Section_Head + CAT_Section_Head->SectionLength + 3 - 4)=GetCRC((unsigned char *)CAT_Section_Head,CAT_Section_Head->SectionLength + 3 -4);
g_gen_si_info.cat_section.continue_counter=0;
g_gen_si_info.cat_section.pid =1;
g_gen_si_info.cat_section.section_length =CAT_Section_Head->SectionLength + 3;
MemCopy(g_gen_si_info.cat_section.section,(unsigned char *)CAT_Section_Head,CAT_Section_Head->SectionLength + 3);
MemFree(CAT_Section_Head);
return 0;
}
#endif
int IsEMMOutput(unsigned short EMMPid)
{
CAT_SECTION_TAG *CAT_Section_Head;
CA_DESCRIPTOR_TAG *CA_Head_Dest;
int Rest;
CAT_Section_Head=(CAT_SECTION_TAG *)g_gen_si_info.cat_section.section;
Rest=CAT_Section_Head->SectionLength - sizeof(CAT_SECTION_TAG) + 3 -4;
CA_Head_Dest=(CA_DESCRIPTOR_TAG *)((unsigned char *)CAT_Section_Head + sizeof(CAT_SECTION_TAG));
while(Rest>0)
{
if(CA_Head_Dest->CA_PID==EMMPid)
return 1;
Rest-=sizeof(CA_DESCRIPTOR_TAG) /*+ CA_Head_Dest->Descriptor_length*/;
CA_Head_Dest=(CA_DESCRIPTOR_TAG *)((unsigned char *)CA_Head_Dest + sizeof(CA_DESCRIPTOR_TAG) /*+ CA_Head_Dest->Descriptor_length*/);
}
return 0;
}
/*生成新的CAT段*/
int NewCATSection(void)
{
int i;
CAT_SECTION_TAG *CAT_Section_Head;
CA_DESCRIPTOR_TAG *CA_Head_Dest;
/*---------------------------------------------------------------------*/
/* CAT section */
/*---------------------------------------------------------------------*/
CAT_Section_Head=(CAT_SECTION_TAG *)MemAlloc(RNG2ID,"NewCATSection",2048);
if(CAT_Section_Head == NULL)
return -1;
CAT_Section_Head->TableID=0x01;
CAT_Section_Head->Section_syntax_indicator=1;
CAT_Section_Head->Zero=0;
CAT_Section_Head->Reserved1 =3;
CAT_Section_Head->SectionLength=sizeof(CAT_SECTION_TAG) -3 + 4; /* 初始值,需要根据节目的个数修改 */
CAT_Section_Head->Reserved2 =0xFFFF;
CAT_Section_Head->Reserved3 =0x3;
CAT_Section_Head->Version_number =0;
CAT_Section_Head->Current_next_indicator = 1;
CAT_Section_Head->Section_number=0;
CAT_Section_Head->Last_section_number=0;
CA_Head_Dest=(CA_DESCRIPTOR_TAG *)((unsigned char *)CAT_Section_Head + sizeof(CAT_SECTION_TAG));
for(i=0;i<Select_Mul.SelsEMM;i++)
{
/*-------------------------------------------------------------*/
/* 选择输出的EMM才加入到CAT中 2002-03-12 更新 */
/*-------------------------------------------------------------*/
CA_Head_Dest->Descriptor_tag =0x09;
CA_Head_Dest->CA_system_ID =GetCaSytemID(Select_Mul.Sel_EMM[i].PortNo,Select_Mul.Sel_EMM[i].Old_EMM_Pid);
CA_Head_Dest->CA_PID =GetSetPIDEx(Select_Mul.Sel_EMM[i].PortNo,0,Select_Mul.Sel_EMM[i].Old_EMM_Pid,STREAM_TYPE_EMM);
CA_Head_Dest->Descriptor_length =4;
CA_Head_Dest->Reserved =0x7;
CAT_Section_Head->SectionLength +=sizeof(CA_DESCRIPTOR_TAG);
CA_Head_Dest++;
}
/*---------------------------------------------------------------------*/
/*生成CAT的校验 */
/*---------------------------------------------------------------------*/
*(unsigned long *)((unsigned char *)CAT_Section_Head + CAT_Section_Head->SectionLength + 3 - 4)=GetCRC((unsigned char *)CAT_Section_Head,CAT_Section_Head->SectionLength + 3 -4);
g_gen_si_info.cat_section.continue_counter=0;
g_gen_si_info.cat_section.pid =1;
g_gen_si_info.cat_section.section_length =CAT_Section_Head->SectionLength + 3;
MemCopy(g_gen_si_info.cat_section.section,(unsigned char *)CAT_Section_Head,CAT_Section_Head->SectionLength + 3);
MemFree(CAT_Section_Head);
return 0;
}
#if 0
void UpdateCATSectionWithEMM(unsigned short EMMPid,unsigned short CA_system_id)
{
int i;
CAT_SECTION_TAG *CAT_Section_Head;
CA_DESCRIPTOR_TAG *CA_Head_Dest;
/*---------------------------------------------------------------------*/
/* CAT section */
/*---------------------------------------------------------------------*/
CAT_Section_Head=(CAT_SECTION_TAG *)MemAlloc(RNG2ID,"NewCATSection",2048);
MemCopy((unsigned char *)CAT_Section_Head,g_gen_si_info.cat_section.section,g_gen_si_info.cat_section.section_length);
CA_Head_Dest=(CA_DESCRIPTOR_TAG *)((unsigned char *)CAT_Section_Head + CAT_Section_Head->SectionLength + 3 -4);
CA_Head_Dest->Descriptor_tag=0x09;
CA_Head_Dest->Descriptor_length=4;
CA_Head_Dest->CA_PID=EMMPid;
CA_Head_Dest->CA_system_ID=CA_system_id;
CA_Head_Dest->Reserved=0x07;
CAT_Section_Head->SectionLength +=sizeof(CA_DESCRIPTOR_TAG);
/*---------------------------------------------------------------------*/
/*生成CAT的校验 */
/*---------------------------------------------------------------------*/
*(unsigned long *)((unsigned char *)CAT_Section_Head + CAT_Section_Head->SectionLength + 3 - 4)=GetCRC((unsigned char *)CAT_Section_Head,CAT_Section_Head->SectionLength + 3 -4);
g_gen_si_info.flag=0;
g_gen_si_info.updated_cat_section.pid =1;
g_gen_si_info.updated_cat_section.section_length =CAT_Section_Head->SectionLength + 3;
MemCopy(g_gen_si_info.updated_cat_section.section,(unsigned char *)CAT_Section_Head,CAT_Section_Head->SectionLength + 3);
g_gen_si_info.flag=1;
MemFree(CAT_Section_Head);
}
#else
/*在CAT段中加入EMM信息*/
/*void UpdateCATSectionWithEMM(unsigned short EMMPid,unsigned short CA_system_id)*/
void UpdateCATSectionWithEMM()
{
int i;
int iLen=0;
CAT_SECTION_TAG *CAT_Section_Head;
CA_DESCRIPTOR_TAG *CA_Head_Dest;
CA_PARA_CONFIG* Para_Config;
/*---------------------------------------------------------------------*/
/* CAT se
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -