www.pudn.com > DVR-MPEG4±àÂë²¥·ÅÆ÷ .rar > Mp4PlayerDlg.cpp


// Mp4PlayerDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Mp4Player.h" 
#include "Mp4PlayerDlg.h" 
#include "Decode.h" 
#include "STiLink.h" 
#include "SystemSetup.h" 
#include "MisceSetup.h" 
#include "Schedule.h" 
#include "Search.h" 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
#define		PORT	2003 
///////////////////////////////////////////////////////////////////////////// 
// CMp4PlayerDlg dialog 
 
CMp4PlayerDlg::CMp4PlayerDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CMp4PlayerDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CMp4PlayerDlg) 
	m_MotionDetect = FALSE; 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CMp4PlayerDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CMp4PlayerDlg) 
	DDX_Control(pDX, IDC_CHANNEL6, m_ctrChannel6); 
	DDX_Control(pDX, IDC_CHANNEL5, m_ctrChannel5); 
	DDX_Control(pDX, IDC_MOTIONDETECT, m_Motion); 
	DDX_Control(pDX, IDC_CHANNEL4, m_ctrChannel4); 
	DDX_Control(pDX, IDC_CHANNEL3, m_ctrChannel3); 
	DDX_Control(pDX, IDC_CHANNEL2, m_ctrChannel2); 
	DDX_Control(pDX, IDC_CHANNEL1, m_ctrChannel1); 
	DDX_Control(pDX, IDC_CONNECT_IP, m_CtlConnectIP); 
	DDX_Control(pDX, IDC_WIN, m_Win); 
	DDX_Check(pDX, IDC_MOTIONCHECK, m_MotionDetect); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CMp4PlayerDlg, CDialog) 
	//{{AFX_MSG_MAP(CMp4PlayerDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_FILEPS, OnFileps) 
	ON_BN_CLICKED(IDC_FILETS, OnFilets) 
	ON_BN_CLICKED(IDC_NETPS, OnNetps) 
	ON_BN_CLICKED(IDC_FULLSCREEN, OnFullscreen) 
	ON_BN_CLICKED(IDC_STOP, OnStop) 
	ON_BN_CLICKED(IDC_FAST, OnFast) 
	ON_BN_CLICKED(IDC_SAVEFILE, OnSavefile) 
	ON_BN_CLICKED(IDC_BACK, OnBack) 
	ON_BN_CLICKED(IDC_STEPFAST, OnStepfast) 
	ON_BN_CLICKED(IDC_STEPBACK, OnStepback) 
	ON_BN_CLICKED(IDC_NORMAL, OnNormal) 
	ON_BN_CLICKED(IDC_GRAB, OnGrab) 
	ON_BN_CLICKED(IDC_DISPLAY, OnDisplay) 
	ON_BN_CLICKED(IDC_CHANNEL1, OnChannel1) 
	ON_BN_CLICKED(IDC_CHANNEL2, OnChannel2) 
	ON_BN_CLICKED(IDC_CHANNEL3, OnChannel3) 
	ON_BN_CLICKED(IDC_CHANNEL4, OnChannel4) 
	ON_BN_CLICKED(IDC_CONNECT, OnConnect) 
	ON_BN_CLICKED(IDC_SETP, OnSystemSetp) 
	ON_BN_CLICKED(IDC_MISCE, OnMisce) 
	ON_BN_CLICKED(IDC_SCHEDULE, OnSchedule) 
	ON_BN_CLICKED(IDC_SEARCH, OnSearch) 
	ON_BN_CLICKED(IDC_PTZ, OnPtz) 
	ON_WM_TIMER() 
	ON_BN_CLICKED(IDC_MOTIONDETECT, OnMotiondetect) 
	ON_BN_CLICKED(IDC_CHANNEL5, OnChannel5) 
	ON_BN_CLICKED(IDC_CHANNEL6, OnChannel6) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMp4PlayerDlg message handlers 
 
BOOL CMp4PlayerDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// 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 
	CoInitialize(NULL); 
	ifPlay = true; 
	InitPlay(); 
	m_Channel=0; 
	m_ChannelCount=0; 
	m_CtlConnectIP.SetCurSel(0); 
	m_ctrChannel1.EnableWindow(false); 
	m_ctrChannel2.EnableWindow(false); 
	m_ctrChannel3.EnableWindow(false); 
	m_ctrChannel4.EnableWindow(false); 
	m_ctrChannel5.EnableWindow(false); 
	m_ctrChannel6.EnableWindow(false); 
	 
	::EnableWindow(GetDlgItem(IDC_NETPS)->GetSafeHwnd(),false); 
	 
	CMp4PlayerApp *play = (CMp4PlayerApp *)::AfxGetApp(); 
	play->SetPlayStatus(ifPlay); 
 
	ifLink = false; 
	for(int n=0;n<8;n++) 
	{ 
		MotionDetect[n]=0; 
	} 
		 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// 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 CMp4PlayerDlg::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 CMp4PlayerDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CMp4PlayerDlg::OnFileps()  
{ 
	// TODO: Add your control notification handler code here 
	HWND hWnd = m_Win.GetSafeHwnd(); 
	RECT rc ; 
	::GetClientRect(hWnd,&rc);  
 
	if(!ifPlay)	 
		InitPlay(); 
 
	GetFileName(); 
 
	IfDeInterlace(TRUE); 
	StartPlay(FilenameStr,IFPS, hWnd,rc);  
	ifPlay = true; 
 
	CMp4PlayerApp *play = (CMp4PlayerApp *)::AfxGetApp(); 
	play->SetPlayStatus(ifPlay); 
 
 
} 
 
void CMp4PlayerDlg::OnFilets() //Player 
{ 
	// TODO: Add your control notification handler code here 
	/* 
	HWND hWnd = m_Win.GetSafeHwnd(); 
	RECT rc ; 
	::GetClientRect(hWnd,&rc); 
 
	if(!ifPlay)	 
		InitPlay(); 
	memset(&Trans_File2,0,sizeof(TRANS_FILE2)); 
	IfDeInterlace(TRUE); 
	Trans_File2.FileCounter = 1; 
	 
	 
	Trans_File2.Buf_File[0].FileLen = 0; 
	strcpy(Trans_File2.Buf_File[0].FileName,"E:\\42_0.mpg"); 
	 
	SendFile((char *)&Trans_File2);  
	StartPlay(NULL,IFPLAYER, hWnd,rc);  
	*/ 
	 
} 
 
void CMp4PlayerDlg::OnNetps()  
{ 
	HWND hWnd = m_Win.GetSafeHwnd(); 
	RECT rc ; 
	::GetClientRect(hWnd,&rc);  
	 
	if(!ifPlay)	 
		InitPlay(); 
 
 
	IfDeInterlace(TRUE); 
	SetUDP(m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()),m_Channel); 
	StartPlay(NULL,IFNETPS, hWnd,rc);  
	ifPlay = true; 
 
	CMp4PlayerApp *play = (CMp4PlayerApp *)::AfxGetApp(); 
	play->SetPlayStatus(ifPlay); 
 
} 
 
void CMp4PlayerDlg::OnFullscreen()  
{ 
	// TODO: Add your control notification handler code here 
	FullScreen(); 
 
} 
 
void CMp4PlayerDlg::OnStop()  
{ 
	// TODO: Add your control notification handler code here 
	// ResetPlay(); 
	StopPlay(); 
 
	ifPlay = false; 
 
	CMp4PlayerApp *play = (CMp4PlayerApp *)::AfxGetApp(); 
	play->SetPlayStatus(ifPlay); 
 
	m_Channel = 0; 
 
} 
 
void CMp4PlayerDlg::GetFileName() 
{ 
	CFileDialog *dlg; 
	 
	dlg= new CFileDialog(TRUE,"mpg","*.mpg",OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,NULL); 
	dlg->m_ofn.lpstrInitialDir=NULL; 
	dlg->m_ofn.lpstrTitle= "Open Target File"; 
	dlg->m_ofn.lpstrFilter="Mpeg Files - *.mpg;*.mpeg\0*.mpg;*.mpeg\0All Files - *.*\0*.*\0"; 
	if ( dlg->DoModal()==IDOK) 
	{ 
		strcpy(m_FilenamesStr,dlg->GetPathName()); 
		SetFileAttributes(m_FilenamesStr,FILE_ATTRIBUTE_NORMAL);   
		::sprintf(FilenameStr,"%s",m_FilenamesStr); 
	} 
	delete dlg; 
} 
 
 
 
 
void CMp4PlayerDlg::OnSavefile()  
{ 
	static bool Start = true; 
	static int i=0; 
	char   buf[20]; 
	i++; 
	sprintf(buf,"D:\\mpg\\%d.mpg",i); 
	if(Start) 
	{ 
		SaveFileFromNet(buf,true); 
		Start = false; 
	} 
	else 
	{ 
		SaveFileFromNet(NULL,false); 
		Start = true; 
	} 
} 
 
void CMp4PlayerDlg::OnFast()  
{ 
	// TODO: Add your control notification handler code here 
    GH_FastForward(); 
 
} 
void CMp4PlayerDlg::OnBack()  
{ 
	// TODO: Add your control notification handler code here 
	GH_FastBackward(); 
 
} 
 
void CMp4PlayerDlg::OnStepfast()  
{ 
	// TODO: Add your control notification handler code here 
	GH_SingleStepForward(); 
} 
 
void CMp4PlayerDlg::OnStepback()  
{ 
	// TODO: Add your control notification handler code here 
	GH_SingleStepBackward(); 
} 
 
void CMp4PlayerDlg::OnNormal()  
{ 
	GH_NormalPlay(); 
} 
 
void CMp4PlayerDlg::OnGrab()  
{ 
	// TODO: Add your control notification handler code here 
	static int i=0; 
	char buf[255]; 
	sprintf(buf,"D:\\bmp\\%d.bmp",i); 
	i++; 
	strcpy(Path,buf); 
	StartGrab(buf);	 
} 
 
void CMp4PlayerDlg::OnDisplay()  
{ 
	// TODO: Add your control notification handler code here 
	 ShellExecute(this->GetSafeHwnd(), TEXT("open\0"), Path,  
                 NULL, NULL, SW_SHOWNORMAL);	 
} 
 
 
void CMp4PlayerDlg::OnChannel1()  
{ 
	// TODO: Add your control notification handler code here 
	m_Channel=0; 
	ChannelSet(); 
} 
 
void CMp4PlayerDlg::OnChannel2()  
{ 
	// TODO: Add your control notification handler code here 
	m_Channel=1; 
	ChannelSet(); 
} 
 
void CMp4PlayerDlg::OnChannel3()  
{ 
	// TODO: Add your control notification handler code here 
	m_Channel=2; 
	ChannelSet(); 
} 
 
void CMp4PlayerDlg::OnChannel4()  
{ 
	// TODO: Add your control notification handler code here 
	m_Channel=3; 
	ChannelSet(); 
} 
 
void CMp4PlayerDlg::OnConnect()  
{ 
	// TODO: Add your control notification handler code here 
	int i; 
	char Cmd[2]; 
	i = m_CtlConnectIP.GetCurSel(); 
    m_CtlConnectIP.GetLBText( i, m_StrIPAddress); 
	InitVRTLink(m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()),PORT); 
 
	Cmd[0]=0x2e; 
	SendVRTData(Cmd,1); 
	RecvVRTData((char *)&m_ChannelCount,sizeof(m_ChannelCount)); 
	CloseVRTLink(); 
	for(i=0;iGetSafeHwnd(),true); 
	} 
	::EnableWindow(GetDlgItem(IDC_NETPS)->GetSafeHwnd(),true); 
 
	::EnableWindow(GetDlgItem(IDC_SEARCH)->GetSafeHwnd(),true); 
	::EnableWindow(GetDlgItem(IDC_SETP)->GetSafeHwnd(),true); 
	::EnableWindow(GetDlgItem(IDC_SCHEDULE)->GetSafeHwnd(),true); 
	::EnableWindow(GetDlgItem(IDC_MISCE)->GetSafeHwnd(),true); 
	 
 
	if(m_ChannelCount == 0) return ; 
	ConnectToServer(); 
 
	CMp4PlayerApp *playip = (CMp4PlayerApp *)::AfxGetApp(); 
	playip->SetConnectIPAddress(m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()),PORT); 
 
	int do_mar = 0; 
	char cmd[1]; 
	Motion = false; 
	cmd[0]=VRTGetMotionState; 
	InitVRTLink(m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()),PORT); 
	SendVRTData(cmd,1); 
	Sleep(1); 
	RecvVRTData((char *)&do_mar,sizeof(do_mar));	 
	CloseVRTLink(); 
 
	if(do_mar == 1) 
	{ 
		Motion = true; 
		m_Motion.SetWindowText("StopMotion(?)");   
		SetTimer(0,500,NULL);  
	} 
} 
 
void CMp4PlayerDlg::ChannelSet() 
{ 
	CMp4PlayerApp *play = (CMp4PlayerApp *)::AfxGetApp(); 
	if(ifPlay == true) 
	{ 
		StopPlay(); 
		ifPlay = false; 
		play->SetPlayStatus(ifPlay); 
 
	} 
	HWND hWnd = m_Win.GetSafeHwnd(); 
	RECT rc ; 
	::GetClientRect(hWnd,&rc);  
	 
	if(!ifPlay)	 
		InitPlay(); 
 
 
	IfDeInterlace(TRUE); 
	SetUDP(m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()),m_Channel); 
	StartPlay(NULL,IFNETPS, hWnd,rc);  
 
	ifPlay = true; 
	play->SetPlayStatus(ifPlay); 
 
} 
 
void CMp4PlayerDlg::OnSystemSetp()  
{ 
	// TODO: Add your control notification handler code here 
	CSystemSetup dlg; 
	dlg.DoModal(); 
} 
 
void CMp4PlayerDlg::OnMisce()  
{ 
	CMisceSetup dlg; 
	dlg.DoModal(); 
} 
 
void CMp4PlayerDlg::OnSchedule()  
{ 
	// TODO: Add your control notification handler code here 
	CSchedule dlg; 
	dlg.DoModal(); 
} 
 
void CMp4PlayerDlg::OnSearch()  
{ 
	// TODO: Add your control notification handler code here 
	CSearch  dlg; 
	dlg.DoModal(); 
} 
 
void CMp4PlayerDlg::ConnectToServer() 
{ 
	DWORD dwResult;  
	NETRESOURCE net; 
	HANDLE    hFile  = INVALID_HANDLE_VALUE;    
 
	char ipaddress[64]; 
	 
	strcpy(ipaddress, m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()));  
	if(ifLink == false) 
	{ 
		char buf[100]; 
		char buf2[100]; 
 
		memset(buf,0,sizeof(buf)); 
		memset(buf2,0,sizeof(buf2)); 
		 
		sprintf(buf,"%s","\\\\"); 
		sprintf(buf2,"%s",ipaddress); 
		strcat(buf,buf2); 
		strcat(buf,"\\mpg"); 
 
		 
		net.dwScope = RESOURCE_GLOBALNET; 
		net.dwType = RESOURCETYPE_ANY; 
		net.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE; 
		net.dwUsage = RESOURCEUSAGE_CONNECTABLE; 
		net.lpRemoteName = buf; 
		net.lpLocalName = NULL;//"Q:";//NULL;// LocalDriver; 
		 
		net.lpComment = NULL; 
		net.lpProvider = NULL; 
		 
		if(strcmp(NetLink,buf) != 0) 
		{ 
			 
			dwResult = WNetAddConnection2(&net,"20030820","stonecomputer",0); 
			if(dwResult == NO_ERROR) 
				printf("Connection added \n", net.lpRemoteName); 
			else 
				printf("Error: %ld\n", dwResult); 
	 
			strcpy(NetLink,buf); 
 
		} 
		ifLink = true; 
		return; 
	} 
	else 
	{		 
		WNetCancelConnection2(NULL,CONNECT_UPDATE_PROFILE, TRUE); //LocalDriver; 
		ifLink = false; 
	} 
 
} 
 
void CMp4PlayerDlg::OnPtz()  
{ 
	// TODO: Add your control notification handler code here 
	m_MotionDetect = false; 
	UpdateData(false); 
		 
} 
 
 
void CMp4PlayerDlg::OnTimer(UINT nIDEvent)  
{ 
	//TODO: Add your message handler code here and/or call default 
	bool Detect = false; 
	char cmd[1]; 
	int	 m=0; 
	switch(nIDEvent) 
	{ 
	case 0: 
		memset(&MotionDetect,0,sizeof(MotionDetect)); 
		InitVRTLink(m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()),PORT); 
		cmd[0]=VRTGetMotionDetect; 
		SendVRTData(cmd,1); 
		Sleep(1); 
		RecvVRTData((char *)&MotionDetect,sizeof(MotionDetect)); 
		CloseVRTLink(); 
		 
		for(m=0;m<8;m++) 
		{ 
			if(MotionDetect[m]!=0) 
			{ 
				Detect = true; 
				break; 
			} 
		} 
		if(Detect) 
		{ 
			m_MotionDetect = true; 
			UpdateData(false); 
		} 
		else 
		{ 
			m_MotionDetect = false; 
			UpdateData(false); 
		} 
		break; 
	default: 
		break; 
	} 
//	::KillTimer(NULL,0);  
	CDialog::OnTimer(nIDEvent); 
} 
 
void CMp4PlayerDlg::OnMotiondetect()  
{ 
	// TODO: Add your control notification handler code here 
	 
	char cmd[1]; 
	int do_mar; 
	cmd[0]=VRTSetMotionDetect; 
	if(!Motion) 
	{ 
		do_mar = 1; 
		InitVRTLink(m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()),PORT); 
		SendVRTData(cmd,1); 
		Sleep(1); 
		SendVRTData((char *)&do_mar,sizeof(do_mar)); 
		CloseVRTLink(); 
		Motion = true; 
		m_Motion.SetWindowText("Í£Ö¹¼ì²â(?)");   
		SetTimer(0,500,NULL);  
	} 
	else 
	{ 
		do_mar = 0; 
		InitVRTLink(m_StrIPAddress.GetBuffer(m_StrIPAddress.GetLength()),PORT); 
		SendVRTData(cmd,1); 
		Sleep(1); 
		SendVRTData((char *)&do_mar,sizeof(do_mar)); 
		CloseVRTLink(); 
		Motion = false; 
		m_Motion.SetWindowText("¶¯Ì¬¼ì²â");   
		KillTimer(0);  
 
	}		 
} 
 
void CMp4PlayerDlg::OnChannel5()  
{ 
	// TODO: Add your control notification handler code here 
	m_Channel=4; 
	ChannelSet(); 
	 
} 
 
void CMp4PlayerDlg::OnChannel6()  
{ 
	// TODO: Add your control notification handler code here 
	m_Channel=5; 
	ChannelSet(); 
	 
}