📄 dm642helper.cpp
字号:
{
err = write(fd[subboardindex],buffer,err);
if(err < 0)
{
DebugPrint(g_DbgLevel,g_fpLogFile,"write error on dev_%d\n",subboardindex);
return STATUS_ERROR;
}
}
}
}
for(subboardindex=0;subboardindex<map.board_num;subboardindex++)
{
ClearInterrupt(fd[subboardindex]);
EnableInterrupt(fd[subboardindex]);
ClearInterruptSource(fd[subboardindex]);
SetEnable(fd[subboardindex]);
}
for(subboardindex=0;subboardindex<map.board_num;subboardindex++)
{
InterruptTarget(fd[subboardindex]);
//Enable_Dsp_Interrupt(fd[subboardindex]);
g_SubboardInfo[map.vector[subboardindex]-1].SubboardStatus=SUBBOARD_NORMAL;
if(g_BladeInfo.BladeStatus==BLADE_STATUS_WORK)
{
printf("subboard %d:SUBBOARD_WORK\n",map.vector[subboardindex]-1);
g_SubboardInfo[map.vector[subboardindex]-1].SubboardWorkSetting=SUBBOARD_WORK;
}
}
//snmpWriteSubboardTableAll();
signal(SIGALRM, sigroutine);
value.it_value.tv_sec = 0;
value.it_value.tv_usec = 100000;
value.it_interval.tv_sec = 0;
value.it_interval.tv_usec = 100000;
setitimer(ITIMER_REAL, &value, &ovalue);
return STATUS_OK;
}
void* DM642ServeMain(void* param)
{
//local variables
UINT32 nSubboardNo;
UINT32 nVideoPortNo;
UINT32 nProgramNo;
UINT32 nDataType;
UINT32 nSDTSectionSize;
UINT32 nProgramNumber;
UINT32 nCount=0;
//for test
char* test_file_path[4]={
"test0.ts",
"test1.ts",
"test2.ts",
"test3.ts"};
FILE * fp[4];
char* testbuf[4];
UINT32 privateNum = 0;
//int times;
unsigned int count= 0;
//char * data = (char*)malloc(1024*1024*40);
UINT8* pPayload;
char BUF[1344*31];
static UINT32 cur_addr[4] = {0,0,0,0};
//for setitimer
struct itimerval value,ovalue;
int ret;
//for use of privatedata
UINT8 dataPositon;
UINT32 i;
UINT32 j;
UINT32 subboardindex;
UINT32 index;
UINT8 pSDTSectionData[1024];
fd_set readfd;
int maxfd=0;
struct timeval tv;
struct_ProgInfo progInfo;
UINT32 nOriginalPIDNumber;
struct_RTPBuf *pRtpBuf;
struct_RTPBuf *pRtpBufSend;
//for test of Null packet
//UINT32 nullPacketnum=0;
pRtpBuf = (struct_RTPBuf*)malloc(sizeof(struct_RTPBuf));
pRtpBuf->RTPHeader[0] =0x90;
pRtpBuf->RTPHeader[1] = 33;
pRtpBuf->RTPHeader[8] = pRtpBuf->RTPHeader[9] = 0x12;
pRtpBuf->RTPHeader[10] =pRtpBuf->RTPHeader[11] = 0x12;
pRtpBuf->RTPHeader[12] = 'h';
pRtpBuf->RTPHeader[13] = 't';
pRtpBuf->RTPHeader[14] = 0x00;
pRtpBuf->RTPHeader[15] = 0x01;
//thread start
DebugPrint(g_DbgLevel,g_fpLogFile,"Subboard Thread start\n");
if(InitSocket()!=STATUS_OK){
perror("InitSocket");
exit(EXIT_FAILUEE);
}
initRTPSeqNum();
if(InitDM642()!=STATUS_OK)
{
DebugPrint(g_DbgLevel,g_fpLogFile,"init DM642 failed\n");
return (void*)(-1);
}
printf(" g_BladeInfo.BladeStatus= %d,g_SubboardInfo[0].SubboardWorkSetting=%d\n",g_BladeInfo.BladeStatus,g_SubboardInfo[0].SubboardWorkSetting);
FD_ZERO(&readfd);
//find max
for(subboardindex=0;subboardindex<map.board_num;subboardindex++)
{
if(fd[subboardindex]>maxfd)
maxfd = fd[subboardindex];
}
while(1)
{
for(subboardindex=0;subboardindex<map.board_num;subboardindex++)
{
//FD_ZERO(&readfd);
FD_SET(fd[subboardindex],&readfd);
}
// printf("come bo select\n");
ret = select(maxfd+1,&readfd,NULL,NULL,NULL);
// printf("come to select\n");
if(ret<0)
{
/*
if(errno != 4)
DebugPrint(g_DbgLevel,g_fpLogFile,"select error!\n");
*/
//perror("select\n");
//printf("errno == %d\n",errno);
continue;
}
else if(ret == 0)
{
//DebugPrint(g_DbgLevel,g_fpLogFile,"select timeout!\n");
continue;
}
else
{
for(subboardindex=0;subboardindex<map.board_num;subboardindex++)
{
if(FD_ISSET(fd[subboardindex],&readfd))
{
//get nSubboardNo
nSubboardNo=map.vector[subboardindex]-1;//when one board, always the first board
count= read(fd[subboardindex],BUF,31*1344);
if(count < 0)
{
DebugPrint(g_DbgLevel,g_fpLogFile,"write error!\n");
return (void*)(-1);
}
// DebugPrint(g_DbgLevel,g_fpLogFile,"readcount=%d\n",count);
while(count > 0)
{
if(cur_addr[subboardindex] >= BUFFER_LEN)
cur_addr[subboardindex] -= BUFFER_LEN;
/* About data structure read from DM642
//////////////////////////////////////////////////
1. Data Structure
UINT32 VideoPortNo; //(1~2)
UINT32 DataType; //(TS_WITHOUT_PRIVATE,TS_WITH_PRIVATE,PSI,SDT)
UINT32 ProgramNo;
UINT32 Param1; // differ with different DataType
UINT32 Param2;
UINT32 Payload[329]; // differ with different DataType
//////////////////////////////////////////////////
2. Meaning of Param1,Param2 and Payload
switch(DataType)
{
case PSI:
Param1 = ProgramNumber; //?¨2???á¨1¨oy
Payload[329] =
for(int i=0;i<ProgramNumber;i++)
struct_ProgInfo perProgInfo;
break;
case SDT:
Param1 = SDTSectionLength;
Payload[329] = SDTSection;
break;
case TS_WITH_PRIVATE:
Param2:Param1 =where to insert private data and insert which, we can use
///////////////////////////////////////////////////////////////////////////////////////////
//For example:
//TS packet Index 3 2 1 0
//Insert PID Index FF FF FF 03 (Param1)
//TS packet Index 6 5 4
//Insert PID Index FF FF FF FF (Param1)
//From 0~27, every 8 bits is the PID index to insert to the certain packet which is accoding to the TS packet Index,
//if FFFF, then will not insert private data, otherwise, will insert Private data which PID index equals the value of the 4 bits.
//The example shows we will only insert private data which has PID index 3 to the first packet of 7*188
//////////////////////////////////////////////////////////////////////////////////////////
Payload[329]= normal data mixed with private data(stuff empty packet by DSP)
break;
case TS_WITHOUT_PRIVATE:
Payload[329]= 7 TS Packets(7*188)
break;
default:
ERROR
}
////////////////////////////////////////////////////
*/
nVideoPortNo=(*((UINT32*)(mem_ptr[subboardindex]+cur_addr[subboardindex])))-1;
/*
index=nSubboardNo*MAXVIDEOPORT+nVideoPortNo;
if(g_VideoPortInfo[index].VideoPortStatus==NoStream)
{
g_VideoPortInfo[index].VideoPortStatus=HasStream;
}
*/
// DebugPrint(g_DbgLevel,g_fpLogFile,"nVideoPortNo=%x\n",nVideoPortNo);
nDataType=(*((UINT32*)(mem_ptr[subboardindex]+cur_addr[subboardindex])+1));
switch(nDataType)
{
case TS_WITHOUT_PRIVATE:
{
nProgramNo=(*((UINT32*)(mem_ptr[subboardindex]+cur_addr[subboardindex])+2));
index=nSubboardNo*MAXVIDEOPORT*MAXPROGRAM
+nVideoPortNo*MAXPROGRAM
+nProgramNo;
if(g_BladeInfo.BladeStatus==BLADE_STATUS_WORK
//&&IsSDTover==1
//&&g_SubboardInfo[nSubboardNo].SubboardWorkSetting==SUBBOARD_WORK
&&g_ConfTable[index].IsSet==TRUE)
{
BuildRTPHeader(pRtpBuf,index);
memcpy(mem_ptr[subboardindex]+cur_addr[subboardindex],pRtpBuf->RTPHeader,20);
if(TansDVBoverIP((struct_RTPBuf*)(mem_ptr[subboardindex]+cur_addr[subboardindex]),index)!=STATUS_OK)
{
printf("TansDVBoverIP() error\n");
}
}
break;
}
case TS_WITH_PRIVATE :
{
//break;
//DebugPrint(g_DbgLevel,g_fpLogFile,"TS_WITH_PRIVATE\n");
// if ((nullPacketnum++%30) == 0)
// printf("nullPacketnum!!!! = %d\n",nullPacketnum);
nProgramNo=(*((UINT32*)(mem_ptr[subboardindex]+cur_addr[subboardindex])+2));
index=nSubboardNo*MAXVIDEOPORT*MAXPROGRAM
+nVideoPortNo*MAXPROGRAM
+nProgramNo;
// printf("isActive is %d\n",g_PrivateDataPerPrograms[index].isActive);
if(g_ConfTable[index].IsSet==TRUE)
{
for(UINT32 tmpDataBlockIndex=nDataBlockIndex[index]; tmpDataBlockIndex < g_PrivateDataPerPrograms[index].DataBlockNumber; tmpDataBlockIndex++)
{
if(g_PrivateDataPerPrograms[index].PrivateDataBlockInfos[nDataBlockIndex[index]].SendPacketCount
==g_PrivateDataPerPrograms[index].PrivateDataBlockInfos[nDataBlockIndex[index]].BlockPacketNumber)
{
g_PrivateDataPerPrograms[index].PrivateDataBlockInfos[nDataBlockIndex[index]].SendPacketCount = 0;
nNowPrivateDataIndex[index][nDataBlockIndex[index]]++;
}//to ensure that one entire file is sent one time
for(int i=nDataBlockIndex[index]; i<g_PrivateDataPerPrograms[index].DataBlockNumber; i++)
{
if(nNowPrivateDataIndex[index][i] < g_PrivateDataPerPrograms[index].PrivateDataBlockInfos[i].times)
{
nDataBlockIndex[index] = i;
break;
}
if(i == (g_PrivateDataPerPrograms[index].DataBlockNumber-1) ) //最后一个发送完了
{
for(int j=0;j<=i;j++) //clear all to restart
{
nNowPrivateDataIndex[index][j]=0;
}
nDataBlockIndex[index]=0;
}
}
}
for(i=0;i<7;i++)
{
dataPositon =*((UINT8*)(mem_ptr[subboardindex]+cur_addr[subboardindex]+3*sizeof(UINT32)+i));
if((dataPositon!=0xFF) && (g_PrivateDataPerPrograms[index].isActive==TRUE))
{
/*
DebugPrint(g_DbgLevel,g_fpLogFile,"TS_WITH_PRIVATE, i=%d,nDataBlockIndex=%x\n",i,nDataBlockIndex);
gettimeofday(&tv,NULL);
DebugPrint(g_DbgLevel,g_fpLogFile,"tv_inter.tv_sec=%d\ttv.tv_inter_usec=%d\n",tv.tv_sec,tv.tv_usec);
*/
ReplaceWithPrivateData((UINT8*)(mem_ptr[subboardindex]+cur_addr[subboardindex]+DM642_DATA_HEADER+i*188),
nDataBlockIndex[index],
index);
}
}
if(g_BladeInfo.BladeStatus==BLADE_STATUS_WORK)
{
BuildRTPHeader(pRtpBuf,index);
memcpy(mem_ptr[subboardindex]+cur_addr[subboardindex],pRtpBuf->RTPHeader,20);
if(TansDVBoverIP((struct_RTPBuf*)(mem_ptr[subboardindex]+cur_addr[subboardindex]),index)!=STATUS_OK)
{
printf("TansDVBoverIP() error\n");
}
}
}
break;
}
case PSI:
{
DebugPrint(g_DbgLevel,g_fpLogFile,"PSI Updated on nSubboardNo=%d, nVideoPortNo=%d\n",nSubboardNo,nVideoPortNo);
nProgramNumber=(*((UINT32*)(mem_ptr[subboardindex]+cur_addr[subboardindex])+3));
DebugPrint(g_DbgLevel,g_fpLogFile,"nProgramNumber=%d\n",nProgramNumber);
index=nSubboardNo*MAXVIDEOPORT+nVideoPortNo;
g_VideoPortInfo[index].VideoPortStatus=HasStream;
g_VideoPortInfo[index].VideoPortProgramNumber=nProgramNumber;
snmpWriteVideoPortTable(index);
WriteVideoPortInfoToFile(nSubboardNo, nVideoPortNo);
index=nSubboardNo*MAXVIDEOPORT*MAXPROGRAM
+nVideoPortNo*MAXPROGRAM;
for(i=0;i<nProgramNumber;i++)
{
/*
typedef struct
{
UINT32 ProgramNo; //0-9
UINT32 ServiceRate;//single program rate
UINT32 OriginalPIDNumber;//number of PIDs in original PMT
struct_PID OriginalPIDs[MAXORIGINALPID]; // PIDs in original PMT
}struct_ProgInfo;
*/
memcpy((UINT8*)(&progInfo),
mem_ptr[subboardindex]+cur_addr[subboardindex]+DM642_DATA_HEADER+sizeof(struct_ProgInfo)*i,
sizeof(struct_ProgInfo));
nProgramNo=progInfo.ProgramNo;
DebugPrint(g_DbgLevel,g_fpLogFile,"nProgramNo=%d\n",nProgramNo);
g_SITable[index+nProgramNo].ServiceID=progInfo.ServiceID;
DebugPrint(g_DbgLevel,g_fpLogFile,"ServiceID=%d\n",g_SITable[index+nProgramNo].ServiceID);
g_SITable[index+nProgramNo].ServiceRate=progInfo.ServiceRate;
DebugPrint(g_DbgLevel,g_fpLogFile,"ServiceRate=%d\n",g_SITable[index+nProgramNo].ServiceRate);
g_SITable[index+nProgramNo].InputFormat=((g_SITable[index+nProgramNo].ServiceRate>8000000)?HD:SD);
DebugPrint(g_DbgLevel,g_fpLogFile,"InputFormat=%d\n",g_SITable[index+nProgramNo].InputFormat);
nOriginalPIDNumber=progInfo.OriginalPIDNumber;
DebugPrint(g_DbgLevel,g_fpLogFile,"OriginalPIDNumber=%d\n",nOriginalPIDNumber);
/*
for(j=0;j<nOriginalPIDNumber;j++)
{
DebugPrint(g_DbgLevel,g_fpLogFile,"(%d)PID=%d,Type=%d\n",
j,
progInfo.OriginalPIDs[j].PID,
progInfo.OriginalPIDs[j].Type);
}
*/
//find a video PID
for(j=0;j<nOriginalPIDNumber;j++)
{
if(progInfo.OriginalPIDs[j].Type==VIDEOPID)
{
g_SITable[index+nProgramNo].VideoPID=progInfo.OriginalPIDs[j].PID;
break;
}
}
//find a audio PID
for(j=0;j<nOriginalPIDNumber;j++)
{
if(progInfo.OriginalPIDs[j].Type==AUDIOPID)
{
g_SITable[index+nProgramNo].AudioPID=progInfo.OriginalPIDs[j].PID;
break;
}
}
DebugPrint(g_DbgLevel,g_fpLogFile,"g_SITable[index+nProgramNo].VideoPID=%d,g_SITable[index+nProgramNo].AudioPID=%d\n",
g_SITable[index+nProgramNo].VideoPID,
g_SITable[index+nProgramNo].AudioPID);
g_SITable[index+nProgramNo].HasSDT=FALSE;
snmpWriteSITable(index+nProgramNo);
}
snmp_TrapSIInfoChange(5, g_BladeInfo.BladeNo,nSubboardNo, nVideoPortNo,g_BladeInfo.BladeIPv4);
if(IsSingleBoard == FALSE)
snmp_TrapSIInfoChange(5, g_BladeInfo.BladeNo,nSubboardNo, nVideoPortNo,g_BladeInfo.BackBladeIPv4);
break;
}
case SDT:
{
nSDTSectionSize=(*((UINT32*)(mem_ptr[subboardindex]+cur_addr[subboardindex])+3));
//DebugPrint(g_DbgLevel,g_fpLogFile,"nSDTSectionSize=%d\n",nSDTSectionSize);
memcpy(pSDTSectionData,mem_ptr[subboardindex]+cur_addr[subboardindex]+DM642_DATA_HEADER,1024);
parseSDT(pSDTSectionData,nSDTSectionSize,nSubboardNo,nVideoPortNo);
snmp_TrapSIInfoChange(5, g_BladeInfo.BladeNo,nSubboardNo, nVideoPortNo,g_BladeInfo.BladeIPv4);
if(IsSingleBoard == FALSE)
snmp_TrapSIInfoChange(5, g_BladeInfo.BladeNo,nSubboardNo, nVideoPortNo,g_BladeInfo.BackBladeIPv4);
/*
for(int vp=0;vp<MAXSUBBOARD*MAXVIDEOPORT;vp++)
{
if(nSDTServiceNum[vp] != g_VideoPortInfo[vp].VideoPortProgramNumber)
IsSDTover = 0;
}
*/
if(IsSDTover == 1)
{
IsSDTover = 0;
if(snmp_set_SlaveMCUStatus(g_BladeInfo.BackBladeNo, g_BladeInfo.MCUStatus)!=0)
{
DebugPrint(g_DbgLevel,g_fpLogFile,"neighbour snmp may die or not start,can't set BackBlade's SlaveMCUStatus\n");
}
}
break;
}
default:
break;
}
cur_addr[subboardindex] += 1344;
count -= 1344;
}/*while*/
}
}
}/*else*/
}/*while*/
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -