📄 psi.c
字号:
for(k=0;k<Map.PIDs;k++)
{
if(Map.PID9[k]==PID9)
{
Found=1;
Index=k;
break;
}
}
if(!Found)
{
Index=Map.PIDs;
/*--------------------------------------------------*/
/* 如果生成的Index=0x0F,跳过不用 */
/*--------------------------------------------------*/
if(Index==0x0F)
{
Map.PID9[Index++]=0x1FFF;
Map.PIDs++;
}
Map.PID9[Index]=PID9;
Map.PIDs++;
}
/*------------------------------------------------------*/
/*级连口不超过64,其他口不超过32 */
/*------------------------------------------------------*/
if(i==0)
{
if(Index==0x40)
break;
}
else
{
if(Index==0x20)
break;
}
/*--------------------------------------------------*/
/* 如果是要复用的,需要将要复用的节目PID最高位置0 */
/* 反之要置为1 */
/*--------------------------------------------------*/
NewPID=NewPID&0x7FFF;
Msb =(unsigned char)((OldPID&0x1FFF)>>12);
MiddleByte =(unsigned char)((OldPID&0x0FF0)>>4);
Low4bits =(unsigned char)(OldPID&0x000F);
/*将PID映射信息写入FPGA*/
*(unsigned char *)(HIGH_INDEX_ADDR_REG_H_BASE_ADDR + i*0x100)=Msb;
*(unsigned char *)(HIGH_INDEX_ADDR_REG_L_BASE_ADDR + i*0x100)=MiddleByte;
*(unsigned char *)(HIGH_INDEX_REG_BASE_ADDR + i*0x100) =Index;
*(unsigned char *)(PID_DATA_H_REG_BASE_ADDR + i*0x100) =(unsigned char)((NewPID&0xFF00)>>8);
*(unsigned char *)(PID_DATA_L_REG_BASE_ADDR + i*0x100) =(unsigned char)(NewPID&0x00FF);
*(unsigned char *)(LOW_INDEX_REG_BASE_ADDR + i*0x100) =Low4bits;
}
else
{
PID_Remap_Table_List[i][j].Output=0;
continue;
}
}
/*------------------------------------------------------------------------*/
/* write the remap table for PIDs that need pass through */
/* added by JohnnyLing 2003-08-04 */
/*------------------------------------------------------------------------*/
if(PID_Filter[i].Filter_Count)
{
for(l=0;l<PID_Filter[i].Filter_Count;l++,j++)
{
OldPID=PID_Remap_Table_List[i][j].OldPID=PID_Filter[i].Pid_Filter_List[l].Old_PID;
NewPID=PID_Remap_Table_List[i][j].NewPID=PID_Filter[i].Pid_Filter_List[l].New_PID;
PID_Remap_Table_Item_Count[i]++;
PID_Remap_Table_List[i][j].Output=0xF1;
PID9=OldPID&0x1FF0;
/*----------------------------------------------*/
/* 搜索该PID9在MAP TABLE中的位置 */
/*----------------------------------------------*/
Found = 0;
for(k=0;k<Map.PIDs;k++)
{
if(Map.PID9[k] == PID9)
{
Found = 1;
Index = k;
break;
}
}
if(!Found)
{
Index = Map.PIDs;
/*-----------------------------------------------*/
/* 如果生成的Index=0x0F,跳过不用 */
/*-----------------------------------------------*/
if(Index==0x0F)
{
Map.PID9[Index++]=0x1FFF;
Map.PIDs++;
}
Map.PID9[Index]=PID9;
Map.PIDs++;
}
/*------------------------------------------------------*/
/*级连口不超过64,其他口不超过32 */
/*------------------------------------------------------*/
if(i==0)
{
if(Index==0x40)
break;
}
else
{
if(Index==0x20)
break;
}
/*--------------------------------------------------*/
/* 如果是要复用的,需要将要复用的节目PID最高位置0 */
/* 反之要置为1 */
/*--------------------------------------------------*/
NewPID=NewPID&0x7FFF;
Msb =(unsigned char)((OldPID&0x1FFF)>>12);
MiddleByte =(unsigned char)((OldPID&0x0FF0)>>4);
Low4bits =(unsigned char)(OldPID&0x000F);
*(unsigned char *)(HIGH_INDEX_ADDR_REG_H_BASE_ADDR + i*0x100)=Msb;
*(unsigned char *)(HIGH_INDEX_ADDR_REG_L_BASE_ADDR + i*0x100)=MiddleByte;
*(unsigned char *)(HIGH_INDEX_REG_BASE_ADDR + i*0x100) =Index;
*(unsigned char *)(PID_DATA_H_REG_BASE_ADDR + i*0x100) =(unsigned char)((NewPID&0xFF00)>>8);
*(unsigned char *)(PID_DATA_L_REG_BASE_ADDR + i*0x100) =(unsigned char)(NewPID&0x00FF);
*(unsigned char *)(LOW_INDEX_REG_BASE_ADDR + i*0x100) =Low4bits;
}
}
}
return 0;
}
/*--------------------------------------------------------------*/
/* 该节目是否被选择复用 */
/* 检查 PMT列表中是否包含该节目 */
/*--------------------------------------------------------------*/
unsigned long IsMul(unsigned char PortNo,unsigned short OldPrgNo,unsigned short NewPrgNo)
{
int i,j;
PMT_SECTION_TAG *PMT_Section_Head;
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==NewPrgNo)
{
/*---------------------------------------------------------*/
/*该节目是否复用 */
/*---------------------------------------------------------*/
for(j=0;j<Select_Mul.Sels;j++)
{
/*if((Select_Mul.Sel_Item[j].OldPrgNo==OldPrgNo)&&(Select_Mul.Sel_Item[j].SetPrgNo==NewPrgNo))*/
if((Select_Mul.Sel_Item[j].OldPrgNo==OldPrgNo)&&(Select_Mul.Sel_Item[j].PortNo==PortNo))
return 1;
}
}
}
return 0;
}
unsigned long IsRemoveScramble(unsigned char PortNo,unsigned short OldPrgNo,unsigned short NewPrgNo)
{
int i,j;
PMT_SECTION_TAG *PMT_Section_Head;
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==NewPrgNo)
{
/*---------------------------------------------------------*/
/*该节目是否复用 */
/*---------------------------------------------------------*/
for(j=0;j<Select_Mul.Sels;j++)
{
/*if((Select_Mul.Sel_Item[j].OldPrgNo==OldPrgNo)&&(Select_Mul.Sel_Item[j].SetPrgNo==NewPrgNo))*/
if((Select_Mul.Sel_Item[j].OldPrgNo==OldPrgNo)&&(Select_Mul.Sel_Item[j].PortNo==PortNo)
&& Select_Mul.Sel_Item[j].ucRmvScramble == 1)
return 1;
}
}
}
return 0;
}
void DelUserChannelPSI(void)
{
unsigned short PrgInfo[32][2];
int PrgCnt;
PAT_SECTION_TAG *PAT_Section_Head;
PMT_SECTION_TAG *PMT_Section_Head;
unsigned short Offset;
unsigned short SectionLength;
short Rest;
unsigned short PrgNo,PrgPMTPid;
int i,j;
int HasNIT,HasUserchannelPrg;
HasNIT=HasUserchannelPrg=0;
g_gen_si_info.flag=0;
PAT_Section_Head=(PAT_SECTION_TAG *)(g_gen_si_info.pat_section.section);
Rest=SectionLength=PAT_Section_Head->SectionLength - 5 - 4;
Offset=sizeof(PAT_SECTION_TAG);
PrgCnt=0;
while(Rest)
{
PrgNo =*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset);
PrgPMTPid=*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset + 2);
if(PrgNo!=0x1F8)
{
PrgInfo[PrgCnt][0]=PrgNo;
PrgInfo[PrgCnt++][1]=PrgPMTPid;
}
Offset+=4;
Rest-=4;
}
PAT_Section_Head->SectionLength=sizeof(PAT_SECTION_TAG) -3 + 4;
Offset=sizeof(PAT_SECTION_TAG);
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);*/
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==0x1F8)
{
if(i==(g_gen_si_info.pmt_section_number - 1))
{
g_gen_si_info.pmt_section_number--;
}
else
{
for(j=i;j<g_gen_si_info.pmt_section_number;j++)
{
g_gen_si_info.pmt_sectoin_list[j].pid=g_gen_si_info.pmt_sectoin_list[j+1].pid;
g_gen_si_info.pmt_sectoin_list[j].section_length=g_gen_si_info.pmt_sectoin_list[j+1].section_length;
MemCopy(g_gen_si_info.pmt_sectoin_list[j].section,g_gen_si_info.pmt_sectoin_list[j+1].section,g_gen_si_info.pmt_sectoin_list[j+1].section_length);
}
g_gen_si_info.pmt_section_number--;
}
}
}
g_gen_si_info.flag=1;
}
void AddUserChannelPSI(void)
{
unsigned short PrgInfo[32][2];
int PrgCnt;
PAT_SECTION_TAG *PAT_Section_Head;
PMT_SECTION_TAG *PMT_Section_Head;
unsigned short Offset;
unsigned short SectionLength;
short Rest;
unsigned short PrgNo,PrgPMTPid;
int i,j;
int HasNIT,HasUserchannelPrg;
HasNIT=HasUserchannelPrg=0;
g_gen_si_info.flag=0;
PAT_Section_Head=(PAT_SECTION_TAG *)(g_gen_si_info.pat_section.section);
Rest=SectionLength=PAT_Section_Head->SectionLength - 5 - 4;
Offset=sizeof(PAT_SECTION_TAG);
PrgCnt=0;
while(Rest)
{
PrgNo =*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset);
PrgPMTPid=*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset + 2);
if(PrgNo!=0x1F8)
{
PrgInfo[PrgCnt][0]=PrgNo;
PrgInfo[PrgCnt++][1]=PrgPMTPid;
}
Offset+=4;
Rest-=4;
}
PAT_Section_Head->SectionLength=sizeof(PAT_SECTION_TAG) -3 + 4;
Offset=sizeof(PAT_SECTION_TAG);
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;
}
if(SystemData.UserChannel.Type!=USERCHANNELNOTUSE)
{
*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset) =0x01F8;
*(unsigned short *)((unsigned char *)PAT_Section_Head + Offset + 2)=((0x01F8<<4)&0x1FFF)|0xE000;
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);*/
NewPMTSectionForUserChannel(0x1F8);
g_gen_si_info.flag=1;
}
/*-----------------------------------------------------------------------------------*/
/* 根据NIT的设置情况重新修改PSI */
/*-----------------------------------------------------------------------------------*/
void ReGenPSI(void)
{
unsigned short PrgInfo[32][2];
int PrgCnt;
PAT_SECTION_TAG *PAT_Section_Head;
SDT_SECTION_TAG *SDT_Section_Head;
unsigned short Offset;
unsigned short SectionLength;
short Rest;
unsigned short PrgNo,PrgPMTPid;
int i,j;
int HasNIT;
HasNIT=0;
/*-------------------------------------------------------------------------------*/
/*检查PAT中是否包含NIT的配置 */
/*-------------------------------------------------------------------------------*/
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)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -