📄 repid.c
字号:
/*------------------------------------------------------------------*/
/* PID 再映射处理模块 */
/* 复用器软件第二版新增加的功能 */
/* 2001.5.10 */
/*------------------------------------------------------------------*/
#include "psos.h"
#include "constant.h"
#include "structure.h"
#include "command.h"
#include "repid.h"
#include "psi.h"
#include "caproc.h"
#include "pidproc.h"
#include "src\board.h"
extern GEN_SI_INFO g_gen_si_info;
extern CA_CONFIG g_ca_config;
extern void my_Delay(unsigned long int dly_ms);
extern System_Data SystemData;
extern unsigned char PanelOK; /* 面板对测试包的应答是否正确 */
extern unsigned char Connected;
extern unsigned long MemCount;
extern unsigned long GetCRC(unsigned char *pucHead, unsigned long ulLength);
extern unsigned long CRC_Verify(unsigned char *head,unsigned short len);
extern unsigned long SST39VF512_Sector_Erase(unsigned long Sector_Off);
extern unsigned long SST39VF512_Byte_Write(unsigned long Off,unsigned char Ch);
extern void GetConnectState(unsigned char *p);
static unsigned char TS_Buf[8][188*6*32];
unsigned char PortCtr[8];
static unsigned char SDT_Buffer[1024*16];
static GET_PSI_RESULT Get_PSI_Result[8];
EIT_ITEM_LIST EIT_Item_List;
PID_INFO PID_Info[8];
SDT_INFO SDT_Info[8];
SDT_Service_INFO SDT_Service_Info[8];
SDT_Service_INFO Origin_SDT_Service_Info[8];
/*-----------------------------------------------------------------------*/
/* PID 强制直通,added 2003-08-04 */
/*-----------------------------------------------------------------------*/
PORT_PID_FILTER PID_Filter[8];
extern unsigned long PID_Remap_Table_Item_Count[8];
extern PID_REMAP_TABLE_ITEM PID_Remap_Table_List[8][256];
void LoadPIDFilter(void);
NEW_SDT New_SDT;
NEW_DESCRIPTION New_Description; /* 复用输出最多32套节目 */
SELECT_MUL Select_Mul;
SELECT_MUL MySel;
NIT_TABLE_TS Nit;
TDT_TABLE_TS Tdt;
EIT_TABLE_TS Eit;
unsigned char PAT_Ver;
unsigned char CAT_Ver;
unsigned char SDT_Ver;
unsigned char SDT_Continue_Counter;
unsigned char TDT_Coninue_Counter;
/*******************************************************************/
/* 代码 */
/*******************************************************************/
/*初始化PID信息列表*/
unsigned long Init_PID_Info(void)
{
int i,j;
PAT_Ver=0;
CAT_Ver=0;
SDT_Ver=0;
TDT_Coninue_Counter=0;
for(i=0;i<8;i++)
{
PID_Info[i].PAT.PAT_Section =NULL;
PID_Info[i].PAT.Section_Length =0;
for(j=0;j<32;j++)
{
PID_Info[i].PMT[j].PMT_Section =NULL;
PID_Info[i].PMT[j].Section_Length =0;
}
PID_Info[i].PMTs =0;
PID_Info[i].PIDs =0;
/************************************************************/
/* Init SDT section */
/************************************************************/
SDT_Info[i].SectionCount=0;
for(j=0;j<256;j++)
{
SDT_Info[i].PortSections[j].Section=NULL;
SDT_Info[i].PortSections[j].SectionLength=0;
}
SDT_Service_Info[i].ServiceCount=0;
Origin_SDT_Service_Info[i].ServiceCount=0;
for(j=0;j<256;j++)
{
SDT_Service_Info[i].PortService[j].Service_Desc=NULL;
Origin_SDT_Service_Info[i].PortService[j].Service_Desc=NULL;
}
/************************************************************/
/* end of init sdt section and service */
/************************************************************/
}
Select_Mul.Sels=0;
Nit.Transport_Stream_ID=1;
Nit.Network_ID =1;
}
/*------------------------------------------------------------------*/
/* 复位端口对应PSI FIFO, 往对应的地址写任意值 */
/*------------------------------------------------------------------*/
void Reset_PSI_FIFO(unsigned char PortNo)
{
*(unsigned char *)(PSI_FIFO_RESET_REG_BASE_ADDR + 0x100*PortNo)=0x0;
*(unsigned char *)(PSI_FIFO_RESET_REG_BASE_ADDR + 0x100*PortNo)=0x1;
}
unsigned char IsSame(unsigned long *TS,unsigned long *Buf)
{
unsigned long C1,C2;
unsigned char i;
C1=*TS++;
C2=*Buf++;
C1&=0xFFFFFFF0;
C2&=0xFFFFFFF0;
if(C1!=C2)
return 0;
for(i=0;i<184/4;i++)
if(*TS++!=*Buf++)
return 0;
return 1;
}
/*获得相应端口和指定PID的TS包*/
unsigned long GetPSITS(unsigned char PortNo,unsigned short PID,unsigned char *Buf)
{
unsigned char volatile Pid_High,Pid_Low;
unsigned char volatile FIFO_Flag;
unsigned char TS[188];
unsigned long volatile TS_Count;
TS_TAG *TS_Head;
SECTION_TAG *Section_Head;
CAT_SECTION_TAG *CAT_Section_Head;
PMT_SECTION_TAG *PMT_Section_Head;
SDT_SECTION_TAG *SDT_Section_Head;
unsigned char volatile Adaption_field_length;
unsigned char volatile Point_field;
unsigned short volatile SectionLength;
unsigned short volatile PayLoadLength;
short volatile RestLength;
unsigned short volatile Offset=0;
int volatile Loop,GetTSCount;
unsigned char volatile GotPSI,Completed;
unsigned char volatile ReadVal;
unsigned char CState[8];
int i;
unsigned short volatile Times;
/*获得各端口连接状态*/
GetConnectState(CState);
if(CState[PortNo]==0)
return 0;
TS_Count=0;
Pid_High=(unsigned char)((PID&0xFF00)>>8);
Pid_Low =(unsigned char)(PID&0x00FF);
Times=250;
/*------------------------------------------------------------*/
/* 提取第一个TS包 */
/*------------------------------------------------------------*/
GotPSI=0;
for(Loop=0;Loop<5;Loop++)
{
*(unsigned char *)(PSI_PID_L_REG_BASE_ADDR + 0x100*PortNo)=0xFF;
*(unsigned char *)(PSI_PID_H_REG_BASE_ADDR + 0x100*PortNo)=0x1F;
PID_REMAP_REG=0xFF;
Reset_PSI_FIFO(PortNo);
*(unsigned char *)(PSI_PID_L_REG_BASE_ADDR + 0x100*PortNo)=Pid_Low;
*(unsigned char *)(PSI_PID_H_REG_BASE_ADDR + 0x100*PortNo)=Pid_High;
for(i=0;i<Times;i++)
{
FIFO_Flag=*(unsigned char *)(PSI_FIFO_FLAG_REG_BASE_ADDR + 0x100*PortNo);
/*--------------------------------------------------------------------*/
/* D2=0 ,FIFO 满 */
/*--------------------------------------------------------------------*/
if(!(FIFO_Flag|0xFB))
{
/* ResetFPGA(); */
*(unsigned char *)(PSI_PID_L_REG_BASE_ADDR + 0x100*PortNo)=0xFF;
*(unsigned char *)(PSI_PID_H_REG_BASE_ADDR + 0x100*PortNo)=0x1F;
my_Delay(1);/*by xu*/
PID_REMAP_REG=0xFF;
Reset_PSI_FIFO(PortNo);
*(unsigned char *)(PSI_PID_L_REG_BASE_ADDR + 0x100*PortNo)=Pid_Low;
*(unsigned char *)(PSI_PID_H_REG_BASE_ADDR + 0x100*PortNo)=Pid_High;
continue;
}
if(FIFO_Flag&0x01)
{
GotPSI=1;
break;
}
my_Delay(1);/*by xu*/
}
if(GotPSI==0)
{
Display("Got first PSI TS failed, no data in FIFO!\n");
return 0;
}
else
{/*开始读取TS包数据*/
for(i=0;i<188;i++)
TS[i]=*(unsigned char *)(PSI_FIFO_BASE_ADDR + 0x100*PortNo);
/*----------------------------------------------------------------------------*/
/* 写包结束寄存器 */
/*----------------------------------------------------------------------------*/
ReadVal=*(unsigned char *)(PSI_FIFO_PACKET_END_REG_BASE_ADDR + 0x100*PortNo);
TS_Head=(TS_TAG *)TS;
if(TS_Head->Sync_byte!=0x47)
continue;
if(TS_Head->PID!=PID)
continue;
if(TS_Head->Payload_unit_start_indicator!=1)
continue;
if(TS_Head->Adaption_field_control==0)
continue;
/*---------------------------------------------------------------------------------*/
/* 找到第一个TS包 */
/*---------------------------------------------------------------------------------*/
if((TS_Head->Adaption_field_control==2)||(TS_Head->Adaption_field_control==3))
{
Adaption_field_length=*(unsigned char *)(TS + sizeof(TS_TAG));
Point_field=*(unsigned char *)(TS + sizeof(TS_TAG) + Adaption_field_length + 1);
Section_Head=(SECTION_TAG *)(TS + sizeof(TS_TAG) + Adaption_field_length + 1 + 1+Point_field);
}
if(TS_Head->Adaption_field_control==1)
{
Point_field=*(unsigned char *)(TS + sizeof(TS_TAG));
Section_Head=(SECTION_TAG *)(TS + sizeof(TS_TAG) + 1 + Point_field);
}
/*
if(Section_Head->Current_next_indicator==0)
continue;
*/
if(PID==0x11)
{
SDT_Section_Head=(SDT_SECTION_TAG *)Section_Head;
/*
if(SDT_Section_Head->TableID!=0x42)
continue;
*/
if(SDT_Section_Head->Section_number!=0)
continue;
if(SDT_Section_Head->Current_next_indicator!=1)
continue;
}
if(PID==0x01)
{
CAT_Section_Head=(CAT_SECTION_TAG *)Section_Head;
if(CAT_Section_Head->Current_next_indicator!=1)
continue;
}
else
{
PMT_Section_Head=(PMT_SECTION_TAG *)Section_Head;
if(PMT_Section_Head->Current_next_indicator!=1)
continue;
}
MemCopy(Buf + TS_Count*188,TS,188);
TS_Count++;
break;
}
}
/*-------------------------------------------------------------------------------------------------*/
/* 处理后续的TS包 */
/*-------------------------------------------------------------------------------------------------*/
Completed=0;
while(!Completed)
{
if(TS_Count>32*5)
return 0;
/*----------------------------------------------------------------------------*/
/*提取一个TS包 */
/*----------------------------------------------------------------------------*/
GotPSI=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -