PatParse.cpp
资源名称:PSParse.rar [点击查看]
上传用户:thjx518
上传日期:2022-03-16
资源大小:179k
文件大小:7k
源码类别:
mpeg/mp3
开发平台:
Visual C++
- // PatParse.cpp: implementation of the CPatParse class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "PSParse.h"
- #include "PatParse.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- int ParsePat(CTSParse*ts,PATType*pat)
- {
- CPrivateSection ps(ts,0);
- UCHAR buf[1024];
- memset(buf,0,1024);
- ps.GetSections(buf,0);
- pat->tableId =GET_8(buf,0);
- pat->streamId =GET_16(buf,3);
- pat->versionNo =GET_5(buf,5,5);
- pat->sectionLength =GET_12((buf+1),0);
- int len=pat->sectionLength-4-5;
- UCHAR *p=buf+8;
- pat->numProgs=0;
- for(int i=0;len>0;i++){
- pat->programs[i].programNumber=GET_16(p,0);
- pat->programs[i].programMapPID=GET_13(p,2);
- pat->numProgs++;
- len-=4;p+=4;
- }
- return pat->numProgs;
- }
- int ParsePmt(CTSParse*ts,PMTType*pmt,USHORT pmtpid)
- {
- CPrivateSection ps(ts,pmtpid);
- UCHAR buf[102400];
- ps.GetSections(buf,2);
- pmt->tableId=GET_8(buf,0);
- pmt->programNumber =GET_16(buf,3);
- pmt->versionNo =GET_5(buf,5,1);
- pmt->tableId = GET_8(buf, 0);
- pmt->sectionLength = GET_12(buf, 1);
- pmt->programNumber = GET_16(buf, 3);
- pmt->versionNo = GET_5(buf, 5, 5);
- pmt->pcrPid = GET_13(buf, 8);
- int len=GET_12(buf,10);
- int offset=12;
- int i;
- pmt->numDescriptors=0;
- for(i=0;len>0;i++){
- pmt->descriptor[i].tag=GET_8(buf,offset++);
- int dsclen=GET_8(buf,offset++);
- pmt->descriptor[i].length=dsclen;
- memcpy(pmt->descriptor[i].data,buf+offset,dsclen);
- len-=dsclen+2;
- offset+=dsclen;
- pmt->numDescriptors++;
- }
- pmt->numStreams=0;
- for(i=0;offset<pmt->sectionLength-4;i++)
- {
- pmt->stream[i].typeOfStream=GET_8(buf,offset++);
- pmt->stream[i].pid=GET_13(buf,offset);
- offset+=2;
- len=GET_12(buf,offset);
- offset+=2;
- pmt->stream[i].numDescriptors=0;
- for(int j=0;len>0;j++){
- pmt->stream[i].descriptor[i].tag=GET_8(buf,offset++);
- int dsclen=GET_8(buf,offset++);
- pmt->stream[i].descriptor[i].length=dsclen;
- memcpy(pmt->stream[i].descriptor[i].data,buf+offset,dsclen);
- len-=dsclen+2;
- offset+=dsclen;
- pmt->stream[i].numDescriptors++;
- }
- pmt->numStreams++;
- }
- return 0;
- }
- int ParseNit(CTSParse*ts,NITType*nit,bool actual)
- {
- CPrivateSection ps(ts,0x10);
- UCHAR buf[102400];
- ps.GetSections(buf,actual?0x40:0x41);
- nit->tableId=GET_8(buf,0);
- nit->networkId =GET_16(buf,3);
- nit->versionNo =GET_5(buf,5,1);
- nit->tableId = GET_8(buf, 0);
- nit->sectionLength = GET_12(buf, 1);
- nit->versionNo = GET_5(buf, 5, 5);
- int len=GET_12(buf,8);//get network descriptor length
- int offset=10;
- int i;
- nit->numDescriptors=0;
- for(i=0;len>0;i++){
- nit->descriptor[i].tag=GET_8(buf,offset++);
- int dsclen=GET_8(buf,offset++);
- nit->descriptor[i].length=dsclen;
- memcpy(nit->descriptor[i].data,buf+offset,dsclen);
- len-=dsclen+2;
- offset+=dsclen;
- nit->numDescriptors++;
- }
- len=GET_12(buf,offset);
- offset+=2;
- nit->numStreams=0;
- for(i=0;offset<nit->sectionLength-4;i++)
- {
- nit->stream[i].streamId=GET_16(buf,offset);
- nit->stream[i].networkId=GET_16(buf,offset+2);
- int len=GET_12(buf,offset+4);
- offset+=6;
- nit->stream[i].numDescriptors=0;
- for(int j=0;len>0;j++)
- {
- nit->stream[i].descriptor[j].tag=GET_8(buf,offset++);
- int dsclen=GET_8(buf,offset++);
- nit->stream[i].descriptor[j].length=dsclen;
- memcpy(nit->stream[i].descriptor[j].data,buf+offset,dsclen);
- offset+=dsclen;
- len-=2+dsclen;
- nit->stream[i].numDescriptors++;
- }
- nit->numStreams++;
- }
- return 0;
- }
- int ParseSdt(CTSParse*ts,SDTType*sdt,bool actual)
- {
- CPrivateSection ps(ts,0x11);
- UCHAR buf[102400];
- ps.GetSections(buf,actual?0x42:0x46);
- sdt->tableId=GET_8(buf,0);
- sdt->streamId =GET_16(buf,3);
- sdt->versionNo =GET_5(buf,5,1);
- sdt->tableId =GET_8(buf, 0);
- sdt->sectionLength =GET_12(buf, 1);
- sdt->versionNo =GET_5(buf, 5, 5);
- sdt->origNetId =GET_16(buf,8);//get original network id
- int offset=11;
- sdt->numServices=0;
- for(int i=0;offset<sdt->sectionLength-4;i++)
- {
- sdt->service[i].serviceId=GET_16(buf,offset);
- offset+=2;
- sdt->service[i].eitSchedule=GET_1(buf, offset, 1);
- sdt->service[i].eitPresent= GET_1(buf, offset, 0);
- offset++;
- sdt->service[i].runningStatus= GET_3(buf, offset, 7);
- sdt->service[i].freeCAMode = GET_1(buf, offset, 4);
- int len=GET_12(buf,offset);
- offset+=2;
- sdt->service[i].numDescriptors=0;
- for(int j=0;len>0;j++){
- sdt->service[i].descriptor[j].tag=GET_8(buf,offset++);
- int dsclen=GET_8(buf,offset++);
- sdt->service[i].descriptor[j].length=dsclen;
- memcpy(sdt->service[i].descriptor[j].data,buf+offset,dsclen);
- len-=2+dsclen;
- offset+=dsclen;
- sdt->service[i].numDescriptors++;
- }
- sdt->numServices++;
- }
- return 0;
- }
- int ParseEit(CTSParse*ts,EITType*eit,UCHAR tableid,USHORT serviceid)
- {
- CPrivateSection ps(ts,0x12);
- UCHAR buf[102400];
- ps.GetSections(buf,tableid,serviceid);
- eit->tableId=GET_8(buf,0);
- eit->serviceId =GET_16(buf,3);
- eit->versionNo =GET_5(buf,5,1);
- eit->tableId =GET_8(buf, 0);
- eit->sectionLength =GET_12(buf, 1);
- eit->versionNo =GET_5(buf, 5, 5);
- eit->streamId =GET_16(buf,8);//get original network id
- eit->numEvents=0;
- int offset=14;
- eit->numEvents=0;
- for(int i=0;offset<eit->sectionLength-4;i++)
- {
- eit->event[i].eventId=GET_16(buf,offset);
- offset+=2;
- eit->event[i].startTimeHi=GET_32(buf,offset);
- offset+=4;
- eit->event[i].startTimeLo=GET_8(buf,offset++);
- eit->event[i].duration=GET_24(buf,offset);
- offset+=3;
- eit->event[i].runningStatus=(RunStatusType)GET_3(buf,offset,5);
- eit->event[i].caMode=(CAModeType)GET_1(buf,offset,4);
- int len=GET_12(buf,offset);
- offset+=2;
- eit->event[i].numDescriptors=0;
- for(int j=0;len>0;j++)
- {
- eit->event[i].descriptor[j].tag=GET_8(buf,offset++);
- int dsclen=GET_8(buf,offset++);
- eit->event[i].descriptor[j].length=dsclen;
- memcpy(eit->event[i].descriptor[j].data,buf+offset,dsclen);
- offset+=dsclen;
- len-=2+dsclen;
- eit->event[i].numDescriptors++;
- }
- eit->numEvents++;
- }
- return 0;
- }
- void GetDateTimeFromMJD(__int64 mjd,char*tmstr)
- {
- UINT y1,m1,yy,mm,dd;
- USHORT k,hh,min,sec;
- UINT utc=mjd&0xffffff;
- mjd=mjd>>24;
- y1=(int)((mjd-15078.2)/365.25);
- m1=(int)((mjd-14956.1-(int)(y1*365.25))/30.6001);
- dd=mjd-14956-(int)(y1*365.25)-(int)(m1*30.6001);
- k=(m1==14||m1==15)?1:0;
- yy=y1+k;
- mm=m1-1-k*12;
- hh=(utc>>16)&0xff;
- min=(utc>>8)&0xff;
- sec=utc&0xff;
- sprintf(tmstr,"%04d-%02d-%02d %02x:%02x:%02x",
- 1900+yy,mm,dd,hh,min,sec);
- }