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

📄 monclientdlg.cpp

📁 基于SAA7113的MPEG-4程序
💻 CPP
字号:
  // MonClientDlg.cpp : implementation file
//

#include "stdafx.h"
#include <time.h>
#include "MonClient.h"
#include "MonClientDlg.h"

#include "VideoIOMgr.h"


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

/*
unsigned char bmp_header_qvga[54] = {0x42,0x4d,0x36,0x84,0x03,0x00,0x00,0x00,0x00,0x00,0x36,0x00,
                                0x00,0x00,0x28,0x00,0x00,0x00,0x40,0x01,0x00,0x00,0xf0,0x00,
								0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x84,
								0x03,0x00,0xc4,0x0e,0x00,0x00,0xc4,0x0e,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00
								};
*/
unsigned char bmp_header_qcif[54] = {0x42,0x4d,0x36,0x29,0x01,0x00,0x00,0x00,0x00,0x00,0x36,0x00,
                                0x00,0x00,0x28,0x00,0x00,0x00,0xB0,0x00,0x00,0x00,0x90,0x00,
								0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x29,
								0x01,0x00,0xc4,0x0e,0x00,0x00,0xc4,0x0e,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00
								};


/* Bmp header file for CIF image */
unsigned char bmp_header_qvga[54] = {0x42,0x4d,0x36,0xa4,0x04,0x00,0x00,0x00,0x00,0x00,0x36,0x00,
                                0x00,0x00,0x28,0x00,0x00,0x00,0x60,0x01,0x00,0x00,0x20,0x01,
								0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0xa4,
								0x04,0x00,0xc4,0x0e,0x00,0x00,0xc4,0x0e,0x00,0x00,0x00,0x00,
								0x00,0x00,0x00,0x00,0x00,0x00
								};


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

/////////////////////////////////////////////////////////////////////////////
// CMonClientDlg dialog

CMonClientDlg::CMonClientDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMonClientDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMonClientDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_pMontUnit = NULL;
}

void CMonClientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMonClientDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMonClientDlg, CDialog)
	//{{AFX_MSG_MAP(CMonClientDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_SETTING_BUTTON, OnSettingButton)
	ON_BN_CLICKED(ID_CONNECT_BUTTON, OnConnectButton)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMonClientDlg message handlers

BOOL CMonClientDlg::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

	CWnd* pShowPicWnd = (CWnd*)GetDlgItem(IDC_PIC_FRAME);
	CWnd* pShowAddrWnd = (CWnd*)GetDlgItem(IDC_MONTERM_ADDR_TEXT);
	CWnd* pShowRateWnd = (CWnd*)GetDlgItem(IDC_VIDEO_RATE_TEXT);
	m_pMontUnit = new CMontUnit();
	m_pMontUnit->InitUnit(1,pShowPicWnd,pShowAddrWnd,pShowRateWnd);

	//Generate MP4 decoder class
	m_pMp4Decoder = new CMp4Decoder();

	//Fill BMP header
	for(int i=0;i<m_pMp4Decoder->m_iBmpHeaderSize;i++)
		m_pDecBuf[i] = bmp_header_qcif[i];
	


	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMonClientDlg::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 CMonClientDlg::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 CMonClientDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMonClientDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

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

void CMonClientDlg::OnSettingButton() 
{
	// TODO: Add your control notification handler code here
	CSetSrvDlg dlg;
	BYTE IPAddr[4]={0,0,0,0};
	UINT iPort=0;
	BYTE iSize = 0;
	int i;

	if(m_pMontUnit)
		m_pMontUnit->GetAddrData(IPAddr,iPort);

	dlg.InitSetDlg(IPAddr,iPort);
	if(dlg.DoModal()==IDOK)
	{
		dlg.GetSrvAddr(IPAddr,&iPort);
		m_pMontUnit->SetAddrData(IPAddr,iPort);		

		dlg.GetImgSize(&iSize);
		if(iSize)
		{
			m_pMp4Decoder->m_iXdim = 352;
			m_pMp4Decoder->m_iYdim = 288;
			m_pMp4Decoder->m_iDecBufLen = 3*m_pMp4Decoder->m_iXdim*m_pMp4Decoder->m_iYdim + m_pMp4Decoder->m_iBmpHeaderSize;
			for(i=0;i<m_pMp4Decoder->m_iBmpHeaderSize;i++)
				m_pDecBuf[i] = bmp_header_qvga[i];

		}
		else
		{
			m_pMp4Decoder->m_iXdim = 176;
			m_pMp4Decoder->m_iYdim = 144;
			m_pMp4Decoder->m_iDecBufLen = 3*m_pMp4Decoder->m_iXdim*m_pMp4Decoder->m_iYdim + m_pMp4Decoder->m_iBmpHeaderSize;
			for(i=0;i<m_pMp4Decoder->m_iBmpHeaderSize;i++)
				m_pDecBuf[i] = bmp_header_qcif[i];

		}

	}	
}



void CMonClientDlg::OnConnectButton() 
{
	// TODO: Add your control notification handler code here

	CButton* pButton = (CButton*)GetDlgItem(ID_CONNECT_BUTTON);
	CString strButTxt;
	pButton->GetWindowText(strButTxt);
	//启动接收线程
	if(strButTxt.Compare("断开")==0)
	{
//		AfxBeginThread()

		KillTimer(FRAMERATE_TIMER);
		KillTimer(RECEIVE_TIMER);

	
		pButton->SetWindowText("连接");
	}



	//关闭接收线程
	if(strButTxt.Compare("连接")==0)
	{
		//设置周期为1秒的时钟,用来定时更新帧速率
		BYTE IPArr[4];
		UINT port=0;
		m_pMontUnit->GetAddrData(IPArr,port);
		
		CVideoIOMgr::getInstance()->InitSocket(IPArr,port);
		CVideoIOMgr::getInstance()->SetShowDlg(this);
		
		//设置周期为1秒的时钟,用来定时更新帧速率
		//SetTimer(FRAMERATE_TIMER,1000,NULL);	
		SetTimer(RECEIVE_TIMER,10,NULL);	
		
		pButton->SetWindowText("断开");		
	
	}
	
}

void CMonClientDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	static int inum=0;
	if(nIDEvent==FRAMERATE_TIMER)  //1S的定时器
	{
		if(m_pMontUnit)
			m_pMontUnit->ShowFrameRate();
	}
	else 
		if(nIDEvent==RECEIVE_TIMER)
			CVideoIOMgr::getInstance()->RcvSocketData();
	else
		OnConnectButton();
	
	
	CDialog::OnTimer(nIDEvent);
}

void CMonClientDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	if(m_pMontUnit)
	{
		delete m_pMontUnit;
		m_pMontUnit = NULL;
	}
	
}

void CMonClientDlg::RcvPicData(BYTE *pdata, int ilen)
{
	m_pMp4Decoder->Decode(pdata,m_pDecBuf + m_pMp4Decoder->m_iBmpHeaderSize,ilen);  //Skip BMP header
	
	if(m_pMontUnit)
		m_pMontUnit->RcvPicData(m_pDecBuf,m_pMp4Decoder->m_iDecBufLen);
}

⌨️ 快捷键说明

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