PSParseDlg.cpp
资源名称:PSParse.rar [点击查看]
上传用户:thjx518
上传日期:2022-03-16
资源大小:179k
文件大小:10k
源码类别:
mpeg/mp3
开发平台:
Visual C++
- // PSParseDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "PSParse.h"
- #include "PSParseDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #include <afxwin.h>
- #define TSFILE "TestTS_11100"
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- DWORD WINAPI CardThread(void*param){
- UCHAR buf[18800],rest[188];
- UCHAR *p=buf;
- CRecvCard card;
- HWND hWnd=NULL;
- MessageBox(hWnd,TSFILE,NULL,MB_OK);
- card.Open(TSFILE);
- int restlen=0;
- CQueue *qq=(CQueue*)param;
- while(true){
- int size=restlen;
- p=buf+restlen;
- memcpy(buf,rest,restlen);
- size+=card.Read(p,18800-(p-buf));
- for(int i=0;i<188;i++){
- bool is47=true;
- for(int j=i;j<size;j+=188)
- if(buf[j]!=0x47){
- is47=false;
- break;
- }
- if(is47==false)continue;
- restlen=(size-i)%188;
- memcpy(rest,buf+(size-restlen),restlen);
- for(int k=0;k<size;k+=188)
- if(p[k]==0x47)qq->Push(buf+k);
- break;
- }//end of for i
- }//end of while
- }
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPSParseDlg dialog
- CPSParseDlg::CPSParseDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPSParseDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CPSParseDlg)
- m_hex = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CPSParseDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPSParseDlg)
- DDX_Control(pDX, IDC_PROGRAMS, m_progs);
- DDX_Text(pDX, IDC_HEX, m_hex);
- DDV_MaxChars(pDX, m_hex, 102400);
- //}}AFX_DATA_MAP
- DDX_Control(pDX, IDC_EDIT1, m_edit4);
- }
- BEGIN_MESSAGE_MAP(CPSParseDlg, CDialog)
- //{{AFX_MSG_MAP(CPSParseDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_GETDATA, OnGetdata)
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPSParseDlg message handlers
- BOOL CPSParseDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- DWORD threadid;
- CreateThread(NULL,0,CardThread,&Queue,0,&threadid);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CPSParseDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CPSParseDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CPSParseDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CPSParseDlg::OnGetdata()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- m_hex="";
- MessageBox("aaaaa",NULL,MB_OK);
- GetPATPMT();
- //GetNIT();
- //GetSDT();
- //GetEIT();
- UpdateData(FALSE);
- }
- void CPSParseDlg::GetPATPMT()
- {
- // char buf[409600];
- int i;
- CString s;
- PATType pat;
- USHORT pids[4]={0,0,0,0};
- Queue.SetFilter(pids,1);
- CTSParse ts(&Queue);
- ParsePat(&ts,&pat);
- s.Format("PAT table contained %d Programs SectionLen=%drn",
- pat.numProgs,pat.sectionLength);
- m_hex+=s;
- s.Format("Version=%Xrn",pat.versionNo);
- m_hex+=s;
- s.Format("Transport Stream ID=%Xrnrn",pat.streamId);
- m_hex+=s;
- for(int n=0;n<pat.numProgs;n++)
- {
- s.Format("Program %04X PMT PID=%04Xrn",
- pat.programs[n].programNumber,
- pat.programs[n].programMapPID);
- TRACE(s);
- m_hex+=s;
- }
- m_hex+="rn============================================rnrn";
- PMTType pmt;
- for(int j=0;j<pat.numProgs;j++){
- s.Format("Program %04X PMT_PID=%04X ",
- pat.programs[j].programNumber,
- pat.programs[j].programMapPID);
- m_progs.AddString(s);
- m_hex+=s;
- pids[0]=pat.programs[j].programMapPID;
- Queue.SetFilter(pids,1);
- ParsePmt(&ts,&pmt,pat.programs[j].programMapPID);
- s.Format(" Descriptor Number=%XrntVersion=%Xrn",
- pmt.numDescriptors,pmt.versionNo);
- m_hex+=s;
- for(i=0;i<pmt.numStreams;i++)
- {
- s.Format("tStream Type=%2X Stream PID=%4Xrn",
- pmt.stream[i].typeOfStream,pmt.stream[i].pid);
- m_hex+=s;
- s.Format("ttDescriptor Number=%Xrn",
- pmt.stream[i].numDescriptors);
- m_hex+=s;
- }
- }
- UpdateData(FALSE);
- }
- void CPSParseDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
- CWnd*w=this->GetDlgItem(IDC_HEX);
- RECT r;
- GetWindowRect(&r);
- ScreenToClient(&r);
- if(w)
- w->SetWindowPos(&wndTop,r.left+10,r.top+100,r.right-10,r.bottom-90,SWP_SHOWWINDOW );
- }
- void CPSParseDlg::GetNIT()
- {
- NITType nit;
- CTSParse ts(&Queue);
- USHORT pids[2]={0x10};
- Queue.SetFilter(pids,1);
- ParseNit(&ts,&nit,true);
- CString s;
- m_hex+="rn=============================================rn";
- s.Format("rnNIT networkID=%X Descriptor Number=%XrntVersion=%xrn",
- nit.networkId,nit.numDescriptors,nit.versionNo);
- m_hex+=s;
- for(int i=0;i<nit.numStreams;i++)
- {
- s.Format("tStreamID=%X NetworkID=%Xrn",
- nit.stream[i].streamId,nit.stream[i].networkId);
- m_hex+=s;
- s.Format("ttDescriptor Number=%Xrn",nit.stream[i].numDescriptors);
- m_hex+=s;
- }
- UpdateData(FALSE);
- }
- void CPSParseDlg::GetSDT()
- {
- for(int a=0;a<2;a++){
- SDTType sdt;
- USHORT pids[2]={0x11,0};
- CTSParse ts(&Queue);
- Queue.SetFilter(pids,1);
- ParseSdt(&ts,&sdt,a==1);
- CString s;
- m_hex+="rn=============================================rn";
- s.Format("Service Description Table of Transport Stream %X ,Service Count=%XrntVersion=%XtTableID=%Xrn",
- sdt.streamId,sdt.numServices,sdt.versionNo,sdt.tableId);
- m_hex+=s;
- for(int i=0;i<sdt.numServices;i++){
- char buf[64];
- memset(buf,0,64);
- int pp=sdt.service[i].descriptor[0].data[1];
- int dl=sdt.service[i].descriptor[0].data[pp+2];
- memcpy(buf,sdt.service[i].descriptor[0].data+pp+2,dl+1);
- buf[dl]=0;
- s.Format("tService ID=%X ServiceName="%s" Descriptor Number=%Xrn",
- sdt.service[i].serviceId,
- buf,sdt.service[i].numDescriptors);
- m_hex+=s;
- }
- }
- }
- void CPSParseDlg::GetEIT()
- {
- EITType eit;
- CTSParse ts(&Queue);
- USHORT pids[2]={0x12,0};
- Queue.SetFilter(pids,1);
- ParseEit(&ts,&eit,0x4f,0x12d);
- CString s;
- m_hex+="rn=============================================rn";
- s.Format("Service %x Event Count=%XrntVersion=%Xrn",
- eit.serviceId ,eit.numEvents,eit.versionNo);
- m_hex+=s;
- for(int i=0;i<eit.numEvents;i++)
- {
- __int64 i64=(__int64)eit.event[i].startTimeHi<<8|eit.event[i].startTimeLo;
- UINT du=eit.event[i].duration;
- char tmstr[64];
- s.Format("tEvent %X EventID=%X Descriptor Number=%Xrn",
- i+1,eit.event[i].eventId,eit.event[i].numDescriptors);
- m_hex+=s;
- GetDateTimeFromMJD(i64,tmstr);
- s.Format("ttStart Time=%s Duration=%02x:%02x:%02xrn",
- tmstr,du>>16,du>>8&&0xff,du&0xff);
- m_hex+=s;
- for(int j=0;j<eit.event[i].numDescriptors;j++){
- char eventname[64];
- memset(eventname,0,64);
- if(eit.event[i].descriptor[j].tag==0x4d){
- DescriptorType*dsc=eit.event[i].descriptor+j;
- memcpy(eventname,dsc->data+4,dsc->data[3]+1);
- m_hex+="ttEvent Name=";
- m_hex+=eventname;
- m_hex+="rn";
- }
- s.Format("ttDescription %X Tag=%X Length=%Xrn",j,
- eit.event[i].descriptor[j].tag,
- eit.event[i].descriptor[j].length);
- m_hex+=s;
- }
- }
- }
- void CPSParseDlg::OnBnClickedButton1()
- {
- // TODO: 在此添加控件通知处理程序代码
- char ssss[255];
- char filters[] =
- "DVB TS Files (*.ts)|*.ts|All Files (*.*)|*.*|";
- CFileDialog fileDlg(TRUE, NULL, "*.ts",
- NULL, filters, NULL);
- int result = fileDlg.DoModal();
- if (result == IDOK)
- {
- m_openFileName = fileDlg.GetFileName();
- m_openFilePath = fileDlg.GetPathName();
- //sprintf(buff,"%s",str);
- m_edit4.SetWindowText(m_openFilePath);
- if(strlen(m_openFilePath)==0){
- MessageBox(m_openFilePath);
- }else{
- sprintf(ssss,"you chosed:%s",m_openFilePath);
- //MessageBox(ssss);
- }
- Invalidate();
- }
- }