PrivateSection.cpp
资源名称:PSParse.rar [点击查看]
上传用户:thjx518
上传日期:2022-03-16
资源大小:179k
文件大小:2k
源码类别:
mpeg/mp3
开发平台:
Visual C++
- // PrivateSection.cpp: implementation of the CPrivateSection class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "PSParse.h"
- #include "PrivateSection.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CPrivateSection::CPrivateSection(CTSParse*ts,USHORT pid)
- :m_ts(ts),m_pid(pid){}
- CPrivateSection::~CPrivateSection()
- {}
- int CPrivateSection::GetSection(UCHAR*buf,UCHAR sectionno,UCHAR tableid,USHORT extid)
- {
- UCHAR *pbuf;
- DWORD tm=GetTickCount();
- do{
- pbuf=buf;
- while(m_ts->GetPacket(m_pid,true)!=ptFirst);
- pbuf+=m_ts->GetData(pbuf);
- int m;
- if( ((pbuf-buf)>=6 && GET_8(buf,6)!=sectionno)||
- (GET_8(buf,0)!=INVALID_TABLEID && GET_8(buf,0)!=tableid)||
- (GET_16(buf,3)!=0xFFFF && GET_16(buf,3)!=extid))
- continue;
- while((m=m_ts->GetPacket(m_pid))==ptPayLoad){
- pbuf+=m_ts->GetData(pbuf);
- if(GetTickCount()-tm>2000)return -1;
- }//if(m!=ptPayLoad)break;
- }while( (GET_8(buf,6)!=sectionno)||
- (GET_8(buf,0)!=INVALID_TABLEID && GET_8(buf,0)!=tableid)||
- (GET_16(buf,3)!=0xFFFF && GET_16(buf,3)!=extid));
- return pbuf-buf;
- }
- int CPrivateSection::GetSections(UCHAR*buf,UCHAR tableid,USHORT extid)
- {
- UCHAR*pbuf=buf;
- UCHAR secno=0,lsecno=0;
- do{
- secno=lsecno;
- int size;
- do{
- size=GetSection(pbuf,secno,tableid,extid);
- }while(size<=0);
- lsecno=(UCHAR)pbuf[7];
- pbuf+=size;
- }while(lsecno>secno);
- return pbuf-buf;
- }
- int CPrivateSection::GetSection(UCHAR *buf,UCHAR sectionno,UCHAR tableid)
- {
- UCHAR *pbuf;
- DWORD tm=GetTickCount();
- do{
- pbuf=buf;
- while(m_ts->GetPacket(m_pid,true)!=ptFirst);
- pbuf+=m_ts->GetData(pbuf);
- if( ((pbuf-buf)>=6 && GET_8(buf,6)!=sectionno)||
- (GET_8(buf,0)!=INVALID_TABLEID && GET_8(buf,0)!=tableid))
- continue;
- while(m_ts->GetPacket(m_pid)==ptPayLoad){
- pbuf+=m_ts->GetData(pbuf);
- if(GetTickCount()-tm>2000)return -1;
- }
- }while( (GET_8(buf,6)!=sectionno)||
- (GET_8(buf,0)!=INVALID_TABLEID && GET_8(buf,0)!=tableid));
- return pbuf-buf;
- }
- int CPrivateSection::GetSections(UCHAR *buf, UCHAR tableid)
- {
- UCHAR*pbuf=buf;
- UCHAR secno=0,lsecno=0;
- do{
- secno=lsecno;
- int size;
- do{
- size=GetSection(pbuf,secno,tableid);
- }while(size<=0);
- lsecno=(UCHAR)pbuf[7];
- pbuf+=size;
- }while(lsecno>secno);
- return pbuf-buf;
- }