⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sitable.c

📁 MiniWinOuterSM MiniWinOuterSM
💻 C
📖 第 1 页 / 共 3 页
字号:
{
	short tslen=GetNitTSLoopLen(section);
	UCHAR*p=section+12+GetNitFirstLoopLen(section);
	USHORT tsCount=0;
	for(;tslen>0&&tsCount<index;){
		USHORT len=((p[4]&0x0F)<<8)|p[5];
		tslen-=6+len;
		tsCount++;
		p+=6+len;
	}
	stream->transport_stream_id=(p[0]<<8)|p[1];
	stream->original_network_id=(p[2]<<8)|p[3];
	stream->transport_descriptor_length=((p[4]&0x0F)<<8)|p[5];
	stream->descriptors=p+6;	
}
USHORT GetNitNetID(UCHAR*section)
{return GetExtTableID(section);}
USHORT GetBatBouquetID(UCHAR*section)
{	return 	GetExtTableID(section); }
UCHAR GetNitNetworkName(UCHAR*section,UCHAR*name,UCHAR*lan)
{
	int len=GetNitFirstLoopLen(section);
	int rc=0;
	UCHAR*des=FindDescriptor(section+10,len,NETWORK_NAME_DESCRIPTOR_TAG);
	if(des)
		rc=GetName(des,name);
	des=FindDescriptor(section+10,len,MULTILINGUAL_NETWORK_NAME_DESCRIPTOR_TAG);
	if(des&&lan)
		return GetMultiName(des,name,lan);
	return rc;
}
UCHAR GetBatBouquetName(UCHAR*section,UCHAR*name,UCHAR*lan)
{
	int rc=0,len=GetNitFirstLoopLen(section);
	UCHAR*des=FindDescriptor(section+10,len,BOUQUET_NAME_DESCRIPTOR_TAG);
	if(des)
		rc=GetName(des,name);
	des=FindDescriptor(section+10,len,MULTILINGUAL_BOUQUET_NAME_DESCRIPTOR_TAG);
	if(des&&lan)
		return GetMultiName(des,name,lan);
	return rc;
}

//=====for SDT=================================
USHORT GetSdtStreamID(UCHAR*section)
{ return GetExtTableID(section); }
USHORT GetSdtNetID(UCHAR*section)
{	return (section[8]<<8)|section[9]; }
void GetSdtService(UCHAR*section,DVBService*service,int index)
{
	UCHAR*p=section+11;
	short slen=GetSectionLength(section)-12;
	int serviceCount=0;
	for(;slen>0&&serviceCount<index;){
		USHORT dlen=((p[3]&0x0f)<<8)|p[4];
		slen-=dlen+5;
		p+=dlen+5;
		serviceCount++;
	}
	service->service_id=p[0]<<8|p[1];
	service->reserved_future_use=p[2]>>2;
	service->EIT_schedule_flag=(p[2]>>1)&0x01;
	service->EIT_present_following_flag=p[2]&0x01;
	service->running_status=(p[3]>>5);
	service->free_CA_mode=(p[3]>>4)&0x01;
	service->descriptor_loop_length=((p[3]&0x0f)<<8)|p[4];
	service->descriptors=p+5;	
}
short GetSdtServiceCount(UCHAR*section)
{
	UCHAR*p=section+11;
	short slen=GetSectionLength(section)-12;
	USHORT serviceCount=0;
	for(;slen>0;){
		USHORT dlen=((p[3]&0x0f)<<8)|p[4];
		slen-=dlen+5;
		p+=dlen+5;
		serviceCount++;
	}
	return serviceCount;
}
//////////////////////////////////////////////////////////////////////////
//for EIT============================================================
short GetEitEventCount(UCHAR*section)
{
	short len=GetSectionLength(section)-15;
	UCHAR*p=section+14;
	USHORT ecount=0;
	for(;len>0;){
		USHORT elen=((p[10]&0x0f)<<8)|p[11];
		len-=elen+12;
		p+=elen+12;
		ecount++;
	}
	return ecount;	
}
#if 1
void GetYMDFromMJD(USHORT _mjd,UINT16*year,UINT16*month,UINT16*day)
{
	USHORT k;
	UINT32 y,m,d;
	UINT32 mjd=_mjd;
	y=(UINT16) ((mjd*100-1507820)/36525);
	m=(UINT16) ((mjd*10000-149561000-(y*3652500))/306001);
	d=(UINT16) (mjd-14956-(y*3652500)/10000-(m*306001)/10000 );
	k=((m==14)||(m==15))?1:0;
	(*year)=y+k;
	(*month)=m-1-k*12;
	*day=d;
}
#else
void GetYMDFromMJD(USHORT _mjd,UINT16*year,UINT16*month,UINT16*day)
{
	USHORT k;
	UINT16 y,m,d;
	UINT32 mjd=_mjd;
	y=(UINT16) ((mjd-15078.2)/365.25);
	m=(UINT16) ((mjd-14956.1-(UINT16)(y*365.25))/30.6001);
	d=(UINT16) (mjd-14956-(UINT16)(y*365.25)-(UINT16)(m*30.6001));
	k=((m==14)||(m==15))?1:0;
	(*year)=y+k;
	(*month)=m-1-k*12;
	*day=d;
}
#endif
UCHAR GetWeekDay(USHORT mjd)
{
	return(mjd + 2) % 7+ 1;//monday as 1 .etc...
}
void GetUTCTime(UCHAR*section,USHORT *mjd,UINT*time)
{
	UCHAR*p=section+3;
	*mjd=(p[0]<<8)|p[1];
	*time=(p[2]<<16)|(p[3]<<8)|p[4];
}
void GetHMSFromUTC(INT32 utc,UINT16*hh,UINT16*min,UINT16*sec)
{
	UCHAR t;
	utc&=0xFFFFFF;
	*hh =BCD2Int(utc>>16);
	t=((utc>>8)&0xFF);
	*min=BCD2Int((utc>>8)&0xFF);
	*sec=BCD2Int(utc&0xFF);
}
UINT32 UTC2Seconds(INT32 utc)
{
	UINT16 h,m,s;
	GetHMSFromUTC(utc,&h,&m,&s);
	return h*3600+m*60+s;
}
void GetTOTTime(UINT8*section,UINT16*mjd,UINT32*utc)
{
	UINT8*p=section+3;
	*mjd=(p[0]<<8)|p[1];
	*utc=(p[2]<<16)|(p[3]<<8)|p[4];
}
INT32 GetTOTOffsetInfo(UINT8*section,TIMEOFFSETINFO*tos)
{
	UINT8*p=section+8;
	INT16 dlen=(p[0]<<8)|p[1];
	INT32 i,rc=0;
	dlen&=0xFFF;
	p+=2;
	rc=0;
	for(;dlen>0;){
		INT32 sdlen=p[1];
		dlen-=(sdlen+2);p+=2;
		for(;sdlen>0;rc++,tos++){
			memcpy(tos->CountryCode,p,3);
			tos->CountryCode[3]=0;			p+=3;
			tos->LocalTimeOffsetPolarity=p[0]&1;
			tos->CountryRegionId=(p[0]>>2);	p++;
			tos->LocalTimeOffset=(p[0]<<8)|p[1];p+=2;
			tos->TimeOfChangeMJD=(p[0]<<8)|p[1];p+=2;
			tos->TimeOfChangeUTC=(p[0]<<16)|(p[1]<<8)|p[2];p+=3;
			tos->NextTimeOffset=(p[0]<<8)|p[1];p+=2;
			sdlen-=13;
		}
	}
	return rc;
}
void GetEventInfo(UCHAR*buf,DVBEvent*event)
{
	UCHAR*p=buf;
	UINT utc;
	event->event_id=(p[0]<<8)|p[1];
	event->mjdDate=(p[2]<<8)|p[3];
	event->utcTime=(p[4]<<16)|(p[5]<<8)|p[6];
	//GetYMDFromMJD(mjd,&(event->styear),&(event->stmonth),&(event->stday));
	utc=(p[7]<<16)|(p[8]<<8)|p[9];
	event->duration=utc;
	event->runing_status=p[10]>>5;
	event->free_CA_mode=(p[10]>>4)&0x01;
	event->descriptor_loop_length=((p[10]&0x0f)<<8)|p[11];
	event->descriptors=p+12;	
}
UCHAR* GetEitEvent(UCHAR*section,DVBEvent*event,int index)
{
	short len=GetSectionLength(section)-15;
	UCHAR*p=section+14;
	short ecount=0;
	for(;len>0&&ecount<index;){
		USHORT elen=((p[10]&0x0f)<<8)|p[11];
		len-=elen+12;
		p+=elen+12;
		ecount++;
	}
	GetEventInfo(p,event);	
	return p;
}
UCHAR GetEitSegmentLastSecNo(UCHAR*section)
{	return section[12]; }
UCHAR GetEitLastTableID(UCHAR*section)
{	return section[13]; }
USHORT GetEitNetID(UCHAR*section)
{	return (section[10]<<8)|section[11]; }
USHORT GetEitStreamID(UCHAR*section)
{	return (section[8]<<8)|section[9]; }
USHORT GetEitServiceID(UCHAR*section)
{	return GetExtTableID(section); }

//===========PAT==============================================
USHORT GetPatStreamID(UCHAR*section)
{	return GetExtTableID(section); }
USHORT GetPatProgramCount(UCHAR*section)
{	return (GetSectionLength(section)-9)/4;  }
void GetPatProgram(UCHAR*section,DVBProgram*prog,int index)
{
	UCHAR*p=section+8;
	p+=index*4;
	prog->program_number=(p[0]<<8)|p[1];
	//prog->reserved=p[2]>>5;
	prog->pmt_PID=((p[2]&0x1f)<<8)|p[3];
}


//=========================PAT==PMT=====================================
USHORT GetPmtPCRPID(UCHAR*section)
{	return (section[8]<<8|section[9])&0x1FFF; }
USHORT GetPmtPID(UCHAR*section,USHORT serviceId)
{
	int len=GetSectionLength(section)-9;
	UCHAR*p=section+8;
	for(;len>0;len-=4,p+=4){
		unsigned sid=(p[0]<<8)|p[1];
		if(sid==serviceId)
			return ((p[2]<<8)|p[3])&0x1FFF;
	}
	return 0;
}
USHORT GetPmtServiceID(UCHAR*section)
{
	return GetExtTableID(section);
}
void GetPmtElement(UCHAR*section,ProgElement*comp,int index)
{
	short len=GetSectionLength(section)-13;
	UCHAR*p=section+12+GetPmtProgramInfoLen(section);
	USHORT cc=0;
	for(;(len>0)&&(cc<index);){
		USHORT cl=((p[3]&0x0F)<<8)|p[4];
		len-=cl+5;
		p+=cl+5;
		cc++;
	}
	comp->stream_type=p[0];
	//comp->reserved=p[1]>>5;
	comp->elementary_PID=((p[1]&0x0f)<<8)|p[2];
//	comp->reserved1=p[3]>>4;
	comp->ES_info_length=((p[3]&0x0F)<<8)|p[4];
	comp->descriptors=p+5;
}
int GetPmtMosaicInfo(UCHAR*section,MOSAICINFO*mosaic)
{
	UCHAR*des;
	des=FindDescriptor(section+12,GetPmtProgramInfoLen(section),MOSAIC_DESCRIPTOR_TAG);
	return (des==NULL)?0:GetMosaicInfo(des,mosaic);
}
short GetPmtElementCount(UCHAR*section)
{
	short len=GetSectionLength(section)-13-GetPmtProgramInfoLen(section);
	UCHAR*p=section+12+GetPmtProgramInfoLen(section);
	short cc=0;
	for(;len>0;){
		USHORT cl=((p[3]&0x0F)<<8)|p[4];
		len-=cl+5;
		p+=cl+5;
		cc++;
	}
	return cc;	
}
short GetPmtProgramInfoLen(UCHAR*section)
{
	return ((section[10]&0x0F)<<8)|section[11];	
}
UCHAR  GetTeletextInfo(ProgElement*element,TeletextInfo*teletextInfo)
{
	UCHAR*des=FindDescriptor(element->descriptors,element->ES_info_length,TELETEXT_DESCRIPTOR_TAG);
	UCHAR tc=0;
	int i;
	TeletextInfo*pt=teletextInfo;
	if((des==NULL)||(element->stream_type!=6))
		return 0;
	for(i=2;i<des[1];i+=5){
		memcpy(pt->Language,des+i,3);
		if(teletextInfo!=NULL){
			pt->Language[3]=0;
			pt->teletext_type=des[i+3]>>3;
			pt->teletext_magazine_number=des[i+3]&7;
			pt->teletext_page_number=des[i+4];
			pt++;
		}
		tc++;
	}
	return tc;
}
//////////////////////////////////////////////////////////////////////////
//   common for DSMCC
int GetMsgHeaderLength(UCHAR*section)
{
	UCHAR*p=section+17;
	USHORT adptlen=*p;
	return 12+adptlen;
}
int GetDSMCCMessage(UCHAR*section,DSMCCMessage*msg)
{
	UCHAR*p=section+8;
	msg->protocalDisminator=*p++;
	msg->dsmccType=*p++;
	msg->messageId=(p[0]<<8)|p[1];		p+=2;
	msg->transactionId=p[0]<<24;
	msg->transactionId|=p[1]<<16;
	msg->transactionId|=p[2]<<8;
	msg->transactionId|=p[3];			p+=4;
	msg->reserved=*p++;
	msg->adaptationLength=*p++;
	msg->messageLength=(p[0]<<8)+p[1];	p+=2;
	return 0;
}
static USHORT GetCompatibilityDescriptorLength(UCHAR*section){
	UCHAR*p=section+GetMsgHeaderLength(section)+8+20;
	return (p[0]<<8)|p[1];
}
static USHORT GetDSIPrivateLength(UCHAR*section){
	UCHAR*p=section+GetMsgHeaderLength(section)+8+20;
	p+=GetCompatibilityDescriptorLength(section)+2;
	return (p[0]<<8)|p[1];
}
static int GetMsgHeaderAdapLength(UCHAR *section)
{
	UCHAR *p=section;
	p=section+8+9;
	return *p;
}
//////////////////////////////////////////////////////////////////////////
//for DSI
int GetDownloadServerInitiate(UCHAR*section,DOWNLOADSERVERINITIATE *dsi)
{
	UCHAR*p=section+8+GetMsgHeaderLength(section);
	USHORT  compatibilityLength; 
	UCHAR*sp=p;
	dsi->serverid=p;
	p+=20;
	dsi->compatibilityDescriptor=p;
	dsi->compatibilityDescriptorLength=compatibilityLength=(p[0]<<8)|p[1];

	p+=2+compatibilityLength;//skip compatibility Descriptor Length and descriptor bytes
	dsi->privateDataLength=(p[0]<<8)|p[1];
	p+=2;
	dsi->privateDataBytes=p;
	p+=dsi->privateDataLength;
	return p-sp;
}
int GetServiceGatewayInfo(UCHAR*section,ServiceGatewayInfo*gi)
{
	DOWNLOADSERVERINITIATE dsi;
	UCHAR*p;
	int i;
	GetDownloadServerInitiate(section,&dsi);
	p=dsi.privateDataBytes;
	gi->iopior.typeId_length=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
	gi->iopior.typeId=p+4;
	p+=4+gi->iopior.typeId_length;
	gi->iopior.taggedProfileCount=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];p+=4;
	gi->iopior.profileBytes=p;
	for(i=0;i<gi->iopior.taggedProfileCount;i++){
		UINT tag,len;
		tag=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
		len=(p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];	p+=4;
		p+=len;
	}
	gi->downloadTapCount=*p++;
	gi->downloadTapBytes=p;
	p+=gi->downloadTapCount;

	gi->serviceContextCount=*p++;
	gi->serviceContextBytes=p;
	p+=gi->serviceContextCount;

	gi->userInfoLength=(p[0]<<8)|p[1];	p+=2;
	gi->userInfoBytes=p;

	return gi->iopior.taggedProfileCount;
}
int GetGroupInfo(UCHAR*section,int index,GroupInfo*gi)
{
	int i;
	UCHAR*p=section+8+GetMsgHeaderLength(section)+24;
	p+=2;//skip the field numberOfGoup
	for(i=0;i<index;i++){
		int gilen=(p[10]<<8)|p[11];
		p+=12+gilen;
	}
	gi->groupId=p[0]<<24;
	gi->groupId|=p[1]<<16;
	gi->groupId|=p[2]<<8;
	gi->groupId|=p[3];
	gi->groupSize=p[4]<<24;
	gi->groupSize|=p[5]<<16;
	gi->groupSize|=p[6]<<8;
	gi->groupSize|=p[7];
	gi->GroupCompatibility=(char*)(p+8);
	p+=10;
	gi->GroupInfoLength=(p[0]<<8)|p[1];
	p+=2;
	gi->GroupInfoBytes=(char*)p;
	return 0;	
}

int GetGroupCount(UCHAR*section)
{
	UCHAR*p=section+8+GetMsgHeaderLength(section)+24;
	int count=(p[0]<<8)|p[1];
	return count;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -