#include "stdafx.h" #include "ClientDemo.h" #include "LocalPlayback.h" IMPLEMENT_DYNAMIC(CLocalPlayback, CDialog) CLocalPlayback::CLocalPlayback(CWnd* pParent) : CDialog(CLocalPlayback::IDD, pParent) { } CLocalPlayback::~CLocalPlayback() { } void CLocalPlayback::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_STATIC_PLAYWINDOW, m_playwindow); } BEGIN_MESSAGE_MAP(CLocalPlayback, CDialog) ON_BN_CLICKED(IDC_BUTTON_OPEN, CLocalPlayback::OnBnClickedButtonOpen) ON_BN_CLICKED(IDC_BUTTON_PLAY, CLocalPlayback::OnBnClickedButtonPlay) ON_BN_CLICKED(IDC_BUTTON_STOP, CLocalPlayback::OnBnClickedButtonStop) ON_WM_CLOSE() ON_BN_CLICKED(IDC_BUTTON_PAUSE, CLocalPlayback::OnBnClickedButtonPause) ON_BN_CLICKED(IDC_BUTTON_FAST, CLocalPlayback::OnBnClickedButtonFast) ON_BN_CLICKED(IDC_BUTTON_SLOW, CLocalPlayback::OnBnClickedButtonSlow) END_MESSAGE_MAP() BOOL CLocalPlayback::OnInitDialog() { CDialog::OnInitDialog(); _CWndCS(this); m_nPort=99; m_bplaythread=false; m_PlayerStatus=STATUS_READY; m_FastSpeed=0; m_SlowSpeed=0; //CRect rs,rs_btn; //GetParent()->GetClientRect(&rs); //m_playwindow.MoveWindow((rs.Width()-(rs.right-rs.left)/1.5)/2,0,(rs.right-rs.left)/1.5,(rs.right-rs.left)/2); return TRUE; } void CLocalPlayback::OnBnClickedButtonOpen() { CFileDialog dlg(TRUE); if(dlg.DoModal()==IDOK) { m_FilePathName=dlg.GetPathName(); m_PlayerStatus=STATUS_STOP; m_bplaythread=false; H264_PLAY_CloseFile(m_nPort); H264_PLAY_CloseStream(m_nPort); H264_PLAY_Stop(m_nPort); m_FastSpeed=0; GetDlgItem(IDC_BUTTON_FAST)->SetWindowText(_CS("PlayBack.Fast")); m_SlowSpeed=0; GetDlgItem(IDC_BUTTON_SLOW)->SetWindowText(_CS("PlayBack.Slow")); GetDlgItem(IDC_BUTTON_PAUSE)->SetWindowText(_CS("PlayBack.Pause")); OnBnClickedButtonPlay(); } } void CLocalPlayback::OnBnClickedButtonPlay() { if(m_PlayerStatus==STATUS_STOP) { m_bplaythread=true; DWORD dwThreadID; m_hPlayThread = CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)StartPlay, this , 0, &dwThreadID ); m_PlayerStatus=STATUS_PLAY; } else if(m_PlayerStatus==STATUS_FAST||m_PlayerStatus==STATUS_SLOW) { H264_PLAY_Play(m_nPort,m_playwindow.m_hWnd); m_PlayerStatus=STATUS_PLAY; m_FastSpeed=0; GetDlgItem(IDC_BUTTON_FAST)->SetWindowText(_CS("PlayBack.Fast")); m_SlowSpeed=0; GetDlgItem(IDC_BUTTON_SLOW)->SetWindowText(_CS("PlayBack.Slow")); } else if(m_PlayerStatus==STATUS_PAUSE) { H264_PLAY_Pause(m_nPort,FALSE); GetDlgItem(IDC_BUTTON_PAUSE)->SetWindowText(_CS("PlayBack.Pause")); m_PlayerStatus=STATUS_PLAY; } } void CLocalPlayback::OnBnClickedButtonStop() { m_bplaythread=false; m_PlayerStatus=STATUS_STOP; H264_PLAY_CloseFile(m_nPort); H264_PLAY_CloseStream(m_nPort); H264_PLAY_Stop(m_nPort); m_FastSpeed=0; GetDlgItem(IDC_BUTTON_FAST)->SetWindowText(_CS("PlayBack.Fast")); m_SlowSpeed=0; GetDlgItem(IDC_BUTTON_SLOW)->SetWindowText(_CS("PlayBack.Slow")); GetDlgItem(IDC_BUTTON_PAUSE)->SetWindowText(_CS("PlayBack.Pause")); Invalidate(TRUE); } void CLocalPlayback::OnClose() { m_bplaythread=false; m_PlayerStatus=STATUS_STOP; H264_PLAY_CloseFile(m_nPort); H264_PLAY_CloseStream(m_nPort); CDialog::OnClose(); } unsigned int CLocalPlayback::StartPlay(LPVOID parm) { CLocalPlayback *pThis = ( CLocalPlayback* ) parm; if(H264_PLAY_OpenFile(pThis->m_nPort,pThis->m_FilePathName)) { if(H264_PLAY_OpenStream(pThis->m_nPort,NULL,0,SOURCE_BUF_MIN*100)) { H264_PLAY_SetStreamOpenMode(pThis->m_nPort, STREAME_FILE); if(H264_PLAY_Play(pThis->m_nPort,pThis->m_playwindow.m_hWnd)==false) { pThis->MessageBox(_CS("Error.PlayFailed")); return 0; } } else { pThis->MessageBox(_CS("Error.StreamOpenFailed")); return 0; } } else { int nErr=H264_PLAY_GetLastError(pThis->m_nPort); if(nErr == H264_PLAY_CHECK_FILE_ERROR) { pThis->MessageBox(_CS("Error.CheckFileError")); } else { pThis->MessageBox(_CS("Error.OpenFileFail")); } return 0; } FILE* fp = fopen(pThis->m_FilePathName,"rb"); BYTE pBuf[32 * 1024]; while (pThis->m_bplaythread) { int len = fread(pBuf, 1, 32 * 1024, fp); if (len <= 0) { break; } while(H264_PLAY_InputData(pThis->m_nPort, pBuf, len) == FALSE) { Sleep(40); } } return 1; } void CLocalPlayback::OnBnClickedButtonPause() { if(m_PlayerStatus==STATUS_PLAY||m_PlayerStatus==STATUS_SLOW||m_PlayerStatus==STATUS_FAST) { H264_PLAY_Pause(m_nPort,TRUE); GetDlgItem(IDC_BUTTON_PAUSE)->SetWindowText(_CS("PlayBack.Recover")); m_PlayerStatus=STATUS_PAUSE; } else if(m_PlayerStatus==STATUS_PAUSE) { H264_PLAY_Pause(m_nPort,FALSE); GetDlgItem(IDC_BUTTON_PAUSE)->SetWindowText(_CS("PlayBack.Pause")); m_PlayerStatus=STATUS_PLAY; } } void CLocalPlayback::OnBnClickedButtonFast() { if(m_PlayerStatus==STATUS_PLAY||m_PlayerStatus==STATUS_FAST||m_PlayerStatus==STATUS_SLOW) { if(m_PlayerStatus==STATUS_SLOW) { H264_PLAY_Play(m_nPort,m_playwindow.m_hWnd); m_SlowSpeed=0; GetDlgItem(IDC_BUTTON_SLOW)->SetWindowText(_CS("PlayBack.Slow")); } if(m_FastSpeed<4) { H264_PLAY_Fast(m_nPort); m_FastSpeed++; CString temp; temp.Format("%d",m_FastSpeed); GetDlgItem(IDC_BUTTON_FAST)->SetWindowText(_CS("PlayBack.Fast")+_T(temp)); m_PlayerStatus=STATUS_FAST; } else { m_FastSpeed=0; H264_PLAY_Play(m_nPort,m_playwindow.m_hWnd); H264_PLAY_Fast(m_nPort); m_FastSpeed++; CString temp; temp.Format("%d",m_FastSpeed); GetDlgItem(IDC_BUTTON_FAST)->SetWindowText(_CS("PlayBack.Fast")+_T(temp)); m_PlayerStatus=STATUS_FAST; } } } void CLocalPlayback::OnBnClickedButtonSlow() { if(m_PlayerStatus==STATUS_PLAY||m_PlayerStatus==STATUS_SLOW||m_PlayerStatus==STATUS_FAST) { if(m_PlayerStatus==STATUS_FAST) { H264_PLAY_Play(m_nPort,m_playwindow.m_hWnd); m_FastSpeed=0; GetDlgItem(IDC_BUTTON_FAST)->SetWindowText(_CS("PlayBack.Fast")); } if(m_SlowSpeed<4) { H264_PLAY_Slow(m_nPort); m_PlayerStatus=STATUS_SLOW; m_SlowSpeed++; CString temp; temp.Format("%d",m_SlowSpeed); GetDlgItem(IDC_BUTTON_SLOW)->SetWindowText(_CS("PlayBack.Slow")+_T(temp)); } else { m_SlowSpeed=0; H264_PLAY_Play(m_nPort,m_playwindow.m_hWnd); H264_PLAY_Slow(m_nPort); m_PlayerStatus=STATUS_SLOW; m_SlowSpeed++; CString temp; temp.Format("%d",m_SlowSpeed); GetDlgItem(IDC_BUTTON_SLOW)->SetWindowText(_CS("PlayBack.Slow")+_T(temp)); } } }