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

📄 vcdlg.cpp

📁 主要完成了对mpeg2的ES流文件的分析工作
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// VCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "VC.h"
#include "VCDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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()

/////////////////////////////////////////////////////////////////////////////
// CVCDlg dialog

CVCDlg::CVCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CVCDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVCDlg)
	m_Show = _T("");
	m_Num_Group_Picture = 0;
	m_Num_Picture = 0;
	m_Num_Slice = 0;
	m_Num_Sequence = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CVCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVCDlg)
	DDX_Control(pDX, IDC_SAVE, m_SaveFile);
	DDX_Control(pDX, IDC_GET_SEQUENCE, m_Get_Sequence);
	DDX_Control(pDX, IDC_GET_SLICE, m_Get_Slice);
	DDX_Control(pDX, IDC_GET_PICTURE, m_Get_Picture);
	DDX_Control(pDX, IDC_GET_GROUP_PICTURE, m_Get_Group_Picture);
	DDX_Text(pDX, IDC_Show, m_Show);
	DDV_MaxChars(pDX, m_Show, 102400);
	DDX_Text(pDX, IDC_GROUP_PICTURE, m_Num_Group_Picture);
	DDV_MinMaxDWord(pDX, m_Num_Group_Picture, 0, 4294967295);
	DDX_Text(pDX, IDC_PICTURE, m_Num_Picture);
	DDV_MinMaxDWord(pDX, m_Num_Picture, 0, 4294967295);
	DDX_Text(pDX, IDC_SLICE, m_Num_Slice);
	DDV_MinMaxDWord(pDX, m_Num_Slice, 0, 4294967295);
	DDX_Text(pDX, IDC_SEQUENCE, m_Num_Sequence);
	DDV_MinMaxDWord(pDX, m_Num_Sequence, 0, 4294967295);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CVCDlg, CDialog)
	//{{AFX_MSG_MAP(CVCDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPEN, OnBtnOpen)
	ON_BN_CLICKED(IDC_GET_GROUP_PICTURE, OnBtnGetGroupPicture)
	ON_BN_CLICKED(IDC_GET_PICTURE, OnBtnGetPicture)
	ON_BN_CLICKED(IDC_GET_SLICE, OnBtnGetSlice)
	ON_BN_CLICKED(IDC_GET_SEQUENCE, OnBtnGetSequence)
	ON_BN_CLICKED(IDC_SAVE, OnBtnSave)
	ON_EN_CHANGE(IDC_Show, OnChangeShow)
	ON_EN_CHANGE(IDC_SEQUENCE, OnChangeSequence)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVCDlg message handlers

BOOL CVCDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CVCDlg::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 CVCDlg::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();
	}
}

CString FilePath;   //全局变量,文件路径
DWORD FileSize;     //全局变量,文件大小


CFile FileOpenDlg;  //全局变量,调用指针

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CVCDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CVCDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

void CVCDlg::OnBtnOpen() 
{
	// TODO: Add your control notification handler code here
	char filters[] = "MPEG/DVB ES Files (*.mpg;*.m2v)|*.mpg;*.m2v|All Files (*.*)|*.*|";
	CFileDialog FileDlg(TRUE, NULL, "", NULL, filters, NULL);
	CString s;

	if(FileDlg.DoModal() == IDOK)             ///#define IDOK    1
	{
		FilePath = FileDlg.GetPathName(); 
	
		if(strlen(FilePath)==0)
		{
			MessageBox(FilePath);
		}
		else
		{
			FileOpenDlg.Open(FilePath,CFile::modeRead);

			m_Get_Group_Picture.EnableWindow();
			m_Get_Picture.EnableWindow();
			m_Get_Slice.EnableWindow();
			m_Get_Sequence.EnableWindow();
			m_SaveFile.EnableWindow();

			FileSize = FileOpenDlg.GetLength();
			s.Format("\r\n文件位置:%s\r\n",FilePath);
			m_Show+=s;
			s.Format("文件大小 = %ld 个字节\r\n",FileSize);
			m_Show+=s;
			UpdateData(FALSE);
		}
		Invalidate();
	}
}

void CVCDlg::OnBtnGetGroupPicture() 
{
	// TODO: Add your control notification handler code here
    unsigned int drop_frame_flag;
    unsigned int time_code_hours;
    unsigned int time_code_minutes;
    unsigned int marker_bit;
    unsigned int time_code_seconds;
    unsigned int time_code_pictures;
    unsigned int closed_gop;

	DWORD t;
	CString s;
    UpdateData(TRUE);
	if(m_Num_Group_Picture==0)
	{
         MessageBox("Group Picture Number shouldn't be '0'!");
         goto stop;
    }
    FileOpenDlg.SeekToBegin();

	if(m_Num_Sequence==1) m_Num_Sequence--;

	if(SeekHeader(m_Num_Sequence,0x01b3,0x01b3)==FALSE) 
    {
         MessageBox("Sequence Head not found!");
         goto stop;
    }
	if(SeekHeader(m_Num_Group_Picture,0x01b8,0x01b8)==FALSE) 
    {
         MessageBox("Group Picture Head not found!");
         goto stop;
    }
    FileOpenDlg.Read(&t,4);
    transform(&t,4);

	if(m_Num_Sequence==0) m_Num_Sequence++;
	UpdateData(FALSE);
	
	s.Format("\r\n第%d个序列,\r\n",m_Num_Sequence);
	m_Show+=s;
	s.Format("第%d个图像组:\r\n",m_Num_Group_Picture);
	m_Show+=s;
    drop_frame_flag = getbits(t,1,1);
	s.Format("\tdrop_frame_flag = %d\r\n",drop_frame_flag);
	m_Show+=s;
	time_code_hours = getbits(t,2,6);
	s.Format("\t小时 = %d\r\n",time_code_hours);
	m_Show+=s;
	time_code_minutes = getbits(t,7,12);
	s.Format("\t分钟 = %d\r\n",time_code_minutes);
	m_Show+=s;
	marker_bit = getbits(t,13,13);
	s.Format("\tmarker_bit = %d\r\n",marker_bit);
	m_Show+=s;
	time_code_seconds = getbits(t,14,19);
	s.Format("\t秒 = %d\r\n",time_code_seconds);
	m_Show+=s;
	time_code_pictures = getbits(t,20,25);
	s.Format("\t起始帧数 = %d\r\n",time_code_pictures);
	m_Show+=s;
	closed_gop = getbits(t,26,26);
	s.Format("\tclosed_gop = %d\r\n",closed_gop);
	m_Show+=s;
	if(closed_gop==1)
	{
		s.Format("\t本图像组可被独立解码,无需依靠其他图像组。\r\n");
	    m_Show+=s;
	}
    stop: UpdateData(FALSE);
}

void CVCDlg::OnBtnGetPicture() 
{
	// TODO: Add your control notification handler code here	
    unsigned int temporal_reference;
    unsigned int picture_coding_type;
    unsigned int vbv_delay;

	unsigned int f_code_00;
    unsigned int f_code_01;
    unsigned int f_code_10;
    unsigned int f_code_11;
    unsigned int intra_dc_precision;
    unsigned int picture_structure;

	CString s;
	DWORD t;
    UpdateData(TRUE);
	if(m_Num_Picture==0)
	{
         MessageBox("Picture Number shouldn't be '0'!");
         goto stop;
    }
    FileOpenDlg.SeekToBegin();

	if(m_Num_Sequence==1) m_Num_Sequence--;
	if(m_Num_Group_Picture==1) m_Num_Group_Picture--;

	if(SeekHeader(m_Num_Sequence,0x01b3,0x01b3)==FALSE) 
    {
         MessageBox("Sequence Head not found!");
         goto stop;
    }
	if(SeekHeader(m_Num_Group_Picture,0x01b8,0x01b8)==FALSE) 
    {
         MessageBox("Group Picture Head not found!");
         goto stop;
    }
       
	if(SeekHeader(m_Num_Picture,0x0100,0x0100)==FALSE)       
	{             
		MessageBox("Picture Head not found!");             
		goto stop; 
	}

	if(m_Num_Sequence==0) m_Num_Sequence++;
	if(m_Num_Group_Picture==0) m_Num_Group_Picture++;
	UpdateData(FALSE);

	s.Format("\r\n第%d个序列,\r\n",m_Num_Sequence);
	m_Show+=s;
	s.Format("第%d个图像组,\r\n",m_Num_Group_Picture);
	m_Show+=s;
	s.Format("第%d帧图像:\r\n",m_Num_Picture);
	m_Show+=s;
	FileOpenDlg.Read(&t,4);       
	transform(&t,4);
	temporal_reference = getbits(t,1,10);
	s.Format("\ttemporal_reference = %d,",temporal_reference);
	m_Show+=s;
	s.Format("所在图像组的第%d帧图像\r\n",temporal_reference+1);
	m_Show+=s;
	picture_coding_type = getbits(t,11,13);
	s.Format("\tpicture_coding_type = %d,",picture_coding_type);
	m_Show+=s;
	switch(picture_coding_type)
	{
	    case 1: s.Format("帧内编码(I帧)\r\n");m_Show+=s;break;
		case 2: s.Format("前向预测编码(P帧)\r\n");m_Show+=s;break;
		case 3: s.Format("双向预测编码(B帧)\r\n");m_Show+=s;break;
		case 4: s.Format("不应使用编码\r\n");m_Show+=s;break;
		default: s.Format("\r\n");m_Show+=s;
	}
	
	vbv_delay = getbits(t,14,29);
	s.Format("\tvbv_delay = %d,",vbv_delay);
	m_Show+=s;
	s.Format("缓冲延时 = %1.4f秒\r\n",vbv_delay/90000.0);
	m_Show+=s;
	if(SeekExtension(8,0x0100)==TRUE)
	{
		FileOpenDlg.Seek(-1,CFile::current);
		FileOpenDlg.Read(&t,4);       
	    transform(&t,4);
		f_code_00 = getbits(t,5,8);
		s.Format("\tf_code_00 = %d,",f_code_00);
	    m_Show+=s;
		s.Format("运动矢量在正向水平方向的搜索范围 = %d\r\n",f_code_00);
	    m_Show+=s;
	    f_code_01 = getbits(t,9,12);
		s.Format("\tf_code_01 = %d,",f_code_01);
	    m_Show+=s;
		s.Format("运动矢量在正向垂直方向的搜索范围 = %d\r\n",f_code_01);
	    m_Show+=s;
	    f_code_10 = getbits(t,13,16);
		s.Format("\tf_code_10 = %d,",f_code_10);
	    m_Show+=s;
		s.Format("运动矢量在反向水平方向的搜索范围 = %d\r\n",f_code_10);
	    m_Show+=s;
	    f_code_11 = getbits(t,17,20);
		s.Format("\tf_code_11 = %d,",f_code_11);
	    m_Show+=s;
		s.Format("运动矢量在反向垂直方向的搜索范围 = %d\r\n",f_code_11);
	    m_Show+=s;
	    intra_dc_precision = getbits(t,21,22);
		s.Format("\tintra_dc_precision = %d,",intra_dc_precision);
	    m_Show+=s;
		switch(intra_dc_precision)
		{
		    case 0: s.Format("帧内直流系数的精度 = 8 bits\r\n");m_Show+=s;break;
			case 1: s.Format("帧内直流系数的精度 = 9 bits\r\n");m_Show+=s;break;
			case 2: s.Format("帧内直流系数的精度 = 10 bits\r\n");m_Show+=s;break;
			case 3: s.Format("帧内直流系数的精度 = 11 bits\r\n");m_Show+=s;break;
			default: s.Format("\r\n");m_Show+=s;
		}

	    picture_structure = getbits(t,23,24);
		s.Format("\tpicture_structure = %d,",picture_structure);
	    m_Show+=s;
		switch(picture_structure)
		{
		    case 1: s.Format("图像结构为顶场\r\n");m_Show+=s;break;
			case 2: s.Format("图像结构为底场\r\n");m_Show+=s;break;
			case 3: s.Format("图像结构为帧图像\r\n");m_Show+=s;break;
			default: s.Format("\r\n");m_Show+=s;
		}

	}
	stop: UpdateData(FALSE);

}

void CVCDlg::OnBtnGetSlice() 
{
	// TODO: Add your control notification handler code here
	DWORD slice_vertical_postition;
    DWORD slice_vertical_postition_extension;
	unsigned int quantiser_scale_code;	
	int n=0;

⌨️ 快捷键说明

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