📄 playerdlg.cpp
字号:
pButton = (CButton *)GetDlgItem(IDC_PAUSE);
pButton->SetIcon(m_hPauseEnableIcon);
pButton->EnableWindow(TRUE);
pButton = (CButton *)GetDlgItem(IDC_STOP);
pButton->SetIcon(m_hStopEnableIcon);
pButton->EnableWindow(TRUE);
//m_pMainMenu->EnableMenuItem(ID_FILE_PLAY, FALSE);
//m_pMainMenu->EnableMenuItem(IDC_STOP, FALSE);
m_pMainMenu->EnableMenuItem(ID_FILE_CLOSE, FALSE);
m_pMainMenu->EnableMenuItem(ID_VIEW_FULLSCREEN, FALSE);
m_bFastForwardPlay = TRUE;
UpdateData(FALSE);
}
//////////////////////////////////////////////////////////////////////////////
//Funtion:sort the controls
//////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::SortControl()
{
TRACE("init SORT\n");
if(!m_bInitialized)
return ;
CRect rcWin,rcClient;
GetWindowRect(&rcWin);
GetClientRect(&rcClient);
DWORD x=LEFT_EDGE+10,y=rcClient.bottom-STATE_HEIGHT;
//STATE
GetDlgItem(IDC_PLAYSTATETEXT)->MoveWindow(0,y,rcClient.Width()+1,STATE_HEIGHT,TRUE);
y-=BUTTON_SIZE+STATE_UP;
////////////////////////////////////////////////////////
GetDlgItem(IDC_SLIDERB)->MoveWindow(x,y,70,20,TRUE);
GetDlgItem(IDC_STATIC1)->MoveWindow(LEFT_EDGE,y,10,20,TRUE);
x+=90;
GetDlgItem(IDC_SLIDERC)->MoveWindow(x,y,70,20,TRUE);
GetDlgItem(IDC_STATIC2)->MoveWindow(x-15,y,10,20,TRUE);
x+=90;
GetDlgItem(IDC_SLIDERS)->MoveWindow(x,y,70,20,TRUE);
GetDlgItem(IDC_STATIC3)->MoveWindow(x-15,y,10,20,TRUE);
x+=90;
GetDlgItem(IDC_SLIDERH)->MoveWindow(x,y,70,20,TRUE);
GetDlgItem(IDC_STATIC4)->MoveWindow(x-15,y,10,20,TRUE);
//////////////////////////////////////////////////////////
x=LEFT_EDGE;
y-=30;
//BUTTON
GetDlgItem(IDC_PLAY)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
GetDlgItem(IDC_PAUSE)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
GetDlgItem(IDC_STOP)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
x+=INTERVAL;
GetDlgItem(IDC_INTER1)->MoveWindow(x,y,INTERVAL_SIZE,BUTTON_SIZE,TRUE);
x+=INTERVAL_SIZE;
x+=INTERVAL;
GetDlgItem(IDC_GOTOSTART)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
GetDlgItem(IDC_SLOW)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
GetDlgItem(IDC_FAST)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
GetDlgItem(IDC_GOTOEND)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
x+=INTERVAL;
GetDlgItem(IDC_INTER2)->MoveWindow(x,y,INTERVAL_SIZE,BUTTON_SIZE,TRUE);
x+=INTERVAL_SIZE;
x+=INTERVAL;
GetDlgItem(IDC_STEPBACK)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
GetDlgItem(IDC_STEP)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
GetDlgItem(IDC_CAPPIC)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
x+=BUTTON_SIZE;
m_nPlayButtonsWidth=x;
//SOUND
x=rcClient.right-SOUND_SLIDER_WIDTH;
GetDlgItem(IDC_SOUND_SLIDER)->MoveWindow(x,y+BUTTON_SIZE-SOUND_SLIDER_HEIGHT,SOUND_SLIDER_WIDTH,SOUND_SLIDER_HEIGHT,TRUE);
x-=BUTTON_SIZE;
GetDlgItem(IDC_SOUND)->MoveWindow(x,y,BUTTON_SIZE,BUTTON_SIZE,TRUE);
y-=BUTTON_SIZE+BUTTON_UP;
//PLAY SLIDER
x=0;
GetDlgItem(IDC_PLAY_SLIDER)->MoveWindow(x,y,rcClient.Width(),PLAY_SLIDER_HEIGHT,TRUE);
y-=PLAY_SLIDER_UP;
//pic show
GetDlgItem(IDC_SHOW)->MoveWindow(0,0,rcClient.Width(),y,TRUE);
GetDlgItem(IDC_SHOW)->GetClientRect(&rcWin);
// this->RedrawWindow();
Hik_PlayM4_RefreshPlay(PORT);
TRACE("exit SORT\n");
}
////////////////////////////////////////////////////////////////////////////////
//Funtion:Change interface to slow
////////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::SetFastBackWardState()
{
CButton *pButton;
pButton = (CButton *)GetDlgItem(IDC_PLAY);
pButton->SetIcon(m_hPlayEnableIcon);
pButton->EnableWindow(TRUE);
pButton = (CButton *)GetDlgItem(IDC_PAUSE);
pButton->SetIcon(m_hPauseEnableIcon);
pButton->EnableWindow(TRUE);
pButton = (CButton *)GetDlgItem(IDC_STOP);
pButton->SetIcon(m_hStopEnableIcon);
pButton->EnableWindow(TRUE);
//m_pMainMenu->EnableMenuItem(ID_FILE_PLAY, FALSE);
//m_pMainMenu->EnableMenuItem(IDC_STOP, FALSE);
m_pMainMenu->EnableMenuItem(ID_FILE_CLOSE, FALSE);
m_pMainMenu->EnableMenuItem(ID_VIEW_FULLSCREEN, FALSE);
UpdateData(FALSE);
}
/////////////////////////////////////////////////////////////////////
//Timer funtion
/////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==PLAY_TIMER)
{
DrawStatus();
}
CDialog::OnTimer(nIDEvent);
}
//////////////////////////////////////////////////////////////////////////
//Funtion: Draw the status .
//////////////////////////////////////////////////////////////////////////
void CPlayerDlg::DrawStatus()
{
DWORD nCurrentTime=Hik_PlayM4_GetPlayedTime(PORT);
//TRACE("Get time is:%d\n",nCurrentTime);
DWORD nHour=(nCurrentTime/3600)%24;
DWORD nMinute=(nCurrentTime%3600)/60;
DWORD nSecond=nCurrentTime%60;
int nPos=0;
if(m_bStreamType)
{
DWORD nFilePos=SetFilePointer(m_hStreamFile,0,0,FILE_CURRENT);
nPos=nFilePos*m_dwPlaySliderMax/m_nMaxFileSize;
}
else
{
#ifdef _FILE_POS
float fPos=Hik_PlayM4_GetPlayPos(PORT);
nPos=int(fPos*m_dwPlaySliderMax);
#else
nPos=nCurrentTime*m_dwPlaySliderMax/m_nMaxFileTime;
#endif
}
DWORD nCurrentFrame=Hik_PlayM4_GetCurrentFrameNum(PORT);
m_strPlayStateText.Format("%d/%d %02d:%02d:%02d/%02d:%02d:%02d",nCurrentFrame,m_nTotalFrames,nHour,nMinute,nSecond,m_nTotalHour,m_nTotalMinute,m_nTotalSecond);
if(m_bConvert)
m_strPlayStateText.Format("Converting…… %d/%d %02d:%02d:%02d/%02d:%02d:%02d",nCurrentFrame,m_nTotalFrames,nHour,nMinute,nSecond,m_nTotalHour,m_nTotalMinute,m_nTotalSecond);
GetDlgItem(IDC_PLAYSTATETEXT)->SetWindowText(m_strPlayStateText);
if(m_nPrePlayPos==nPos)
return;
//adjust the slider.
INT nAdjust=(m_nPrePlayPos<nPos)?1:0;
m_PlaySlider.SetPos(nPos+nAdjust);
m_nPrePlayPos=nPos;
//test
//TRACE("Current frame rate:%d\n",Hik_PlayM4_GetCurrentFrameRate(PORT));
//TRACE("Current time use ms:%d\n",Hik_PlayM4_GetPlayedTimeEx(PORT));
}
/////////////////////////////////////////////////////////////////////
//Funtion: play sound
////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnSound()
{
// TODO: Add your control notification handler code here
CButton *pButton;
if(m_bSound)
{
if(Hik_PlayM4_StopSound())
{
m_bSound=FALSE;
pButton = (CButton *)GetDlgItem(IDC_SOUND);
pButton->SetIcon(m_hSoundStopIcon);
}
}
else
{
if(Hik_PlayM4_PlaySound(PORT))
{
pButton = (CButton *)GetDlgItem(IDC_SOUND);
pButton->SetIcon(m_hSoundStartIcon);
m_bSound=TRUE;
}
}
}
//////////////////////////////////////////////////////////////
//Funtion:Play step by step.
//////////////////////////////////////////////////////////////
void CPlayerDlg::OnStep()
{
// TODO: Add your control notification handler code here
//you can do it like the followed too.
//DWORD nCurrentFrame=Hik_PlayM4_GetCurrentFrameNum(PORT);
//Hik_PlayM4_SetCurrentFrameNum(PORT,nCurrentFrame+1);
Hik_PlayM4_OneByOne(PORT);
CButton *pButton;
pButton = (CButton *)GetDlgItem(IDC_PLAY);
pButton->SetIcon(m_hPlayEnableIcon);
pButton->EnableWindow(TRUE);
}
///////////////////////////////////////////////////////////////
//Funtion: Init window size.
////////////////////////////////////////////////////////////////
void CPlayerDlg::InitWindowSize(DWORD cx,DWORD cy)
{
TRACE("init window\n");
CRect rcWin,rcClient;
GetWindowRect(&rcWin);
GetClientRect(&rcClient);
m_nDlgEdge=(rcWin.Width()-rcClient.Width())>>1;
ClientToScreen(&rcClient);
m_nDlgTopSize=rcClient.top-rcWin.top;
DWORD nWindowHeight=cy+PANNEL_HEIGHT+m_nDlgTopSize+m_nDlgEdge;
DWORD nWindowWidth = cx+(m_nDlgEdge<<1);
MoveWindow(
(m_nScreenWidth-nWindowWidth)/2,
(m_nScreenHeight-nWindowHeight)/2,
nWindowWidth,
nWindowHeight,
TRUE);
TRACE("init window!!!!\n");
SortControl();
TRACE("exit window!\n");
//add by lgl; at 2003-6-18;
//for the small picture size.The menu will be high.
GetWindowRect(&rcWin);
GetClientRect(&rcClient);
m_nDlgEdge=(rcWin.Width()-rcClient.Width())>>1;
ClientToScreen(&rcClient);
DWORD nTopSize=rcClient.top-rcWin.top;
if(nTopSize!=m_nDlgTopSize)
{
TRACE("re init window!!!!!!\n");
m_nDlgTopSize=nTopSize;
nWindowHeight=cy+PANNEL_HEIGHT+m_nDlgTopSize+m_nDlgEdge;
nWindowWidth = cx+(m_nDlgEdge<<1);
MoveWindow(
(m_nScreenWidth-nWindowWidth)/2,
(m_nScreenHeight-nWindowHeight)/2,
nWindowWidth,
nWindowHeight,
TRUE);
SortControl();
}
}
/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
void CPlayerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
SortControl();
}
//////////////////////////////////////////////////////////////////
//Function:The call back funtion for capture image!
/////////////////////////////////////////////////////////////////
void CALLBACK DisplayCBFun(long nPort,\
char * pBuf,long nSize,\
long nWidth,long nHeight,\
long nStamp,long nType,long nReceaved)
{
if(!g_bCapPic)
return;
CString csFile;
csFile.Format("capture%02d.bmp",pic);
/* switch(nType)
{
case T_UYVY:
csFile="uyvy.bmp";
break;
case T_YV12:
csFile="yv12.bmp";
break;
case T_RGB32:
csFile="rgb.bmp";
break;
default:
return ;
}*/
//Note:this funtion is slow,so if you want to save as a .bmp file,don't call!
if(!Hik_PLayM4_ConvertToBmpFile(pBuf,nSize,nWidth,nHeight,nType,csFile.GetBuffer(csFile.GetLength())))
{
CString csErr;
csErr.Format("Convert to bmp faild(%d).",Hik_PlayM4_GetLastError(nPort));
AfxMessageBox(csErr);
}
pic++;
g_bCapPic=FALSE;
}
////////////////////////////////////
//Function: Capture;
///////////////////////////////////
void CPlayerDlg::OnCappic()
{
// TODO: Add your control notification handler code here
g_bCapPic=TRUE;
}
void CALLBACK funEncChange(long nPort,long nUser)
{
// return;
CPlayerDlg* pOwner=(CPlayerDlg*)nUser;
pOwner->SetWindowSize();
}
void CPlayerDlg::SetWindowSize()
{
// TRACE("init window size!\n");
// Hik_PlayM4_GetPictureSize(PORT,&m_nWidth,&m_nHeight);
// TRACE("get window size ok\n");
CRect rcWin,rcClient;
GetWindowRect(&rcWin);
GetClientRect(&rcClient);
m_nDlgEdge=(rcWin.Width()-rcClient.Width())>>1;
ClientToScreen(&rcClient);
m_nDlgTopSize=rcClient.top-rcWin.top;
TRACE("init window size!\n");
Hik_PlayM4_GetPictureSize(PORT,&m_nWidth,&m_nHeight);
TRACE("get window size ok\n");
DWORD nWindowHeight=m_nHeight+PANNEL_HEIGHT+m_nDlgTopSize+m_nDlgEdge;
DWORD nWindowWidth = m_nWidth+(m_nDlgEdge<<1);
MoveWindow(
(m_nScreenWidth-nWindowWidth)/2,
(m_nScreenHeight-nWindowHeight)/2,
nWindowWidth,
nWindowHeight,
TRUE);
TRACE("exit window size\n");
}
/////////////////////////////////////////////////////////////////////////////////
//Function: The dec call back funtion.
////////////////////////////////////////////////////////////////////////////////
void CALLBACK DecCBFun(long nPort,char * pBuf,long nSize,
FRAME_INFO * pFrameInfo,
long nReserved1,long nReserved2)
{
TRACE("nPort=%d,TYPE=%d;Width=%d;Height=%d\n",nPort,pFrameInfo->nType,pFrameInfo->nWidth,pFrameInfo->nHeight);
Hik_PlayM4_GetPictureSize(0,&frameWidth,&frameHeight);
if(!m_bFirst)
{
if ((yuvBuf = (char *)malloc( frameWidth*frameHeight*3/2 )) == NULL )
{
MessageBox( NULL,"Error: can't allocate YUV buffer\n",NULL,MB_OK );
}
m_bFirst=true;
if ( (outFile = riffCreate( LPCTSTR(szFileName) )) == NULL )
{
MessageBox(NULL,"Error: can't open output file \n",NULL,MB_OK );
SendMessage(AfxGetApp()->GetMainWnd()->m_hWnd,WM_FILE_END,PORT,0);
return;
}
}
if ((pFrameInfo->nWidth!=0)&&(pFrameInfo->nHeight!=0))
{
memcpy(yuvBuf,pBuf,nSize);
frameWidth=pFrameInfo->nWidth;
frameHeight=pFrameInfo->nHeight;
Y_PLANE_SIZE = (frameWidth)*(frameHeight);
//U4_PLANE_SIZE = (frameWidth/4)*(frameHeight/4);
//V4_PLANE_SIZE = (frameWidth/4)*(frameHeight/4);
U2_PLANE_SIZE = (frameWidth/2)*(frameHeight/2);
V2_PLANE_SIZE = (frameWidth/2)*(frameHeight/2);
inputFrameSize = Y_PLANE_SIZE + U2_PLANE_SIZE + V2_PLANE_SIZE;
outputFrameSize = Y_PLANE_SIZE + V2_PLANE_SIZE + U2_PLANE_SIZE;
fps = pFrameInfo->nFrameRate;
maxFrameSize = outputFrameSize;
if(!m_bFirstWrite)
{
writeHeaders();
m_bFirstWrite=true;
}
addFileToAVI(frameNum);
frameNum++;
if(frameNum>=MAX_FRAMES)
{
SendMessage(AfxGetApp()->GetMainWnd()->m_hWnd,WM_FILE_END,PORT,0);
}
}
Sleep(1);
}
//////////////////////////////////////////////////////////////////////////////////
//Funtion: test the capability of your system.
/////////////////////////////////////////////////////////////////////////////////
void CPlayerDlg::TestCapability(DWORD nDeviceNum)
{
CString csCap="";
#if (WINVER > 0x0400)
int nFlag=Hik_PlayM4_GetCapsEx(nDeviceNum);
#else
int nFlag=Hik_PlayM4_GetCaps();
#endif
if(!(nFlag&SUPPORT_SSE))
csCap+="Don't support SSE instruction set;\r\n";
if(!(nFlag&SUPPORT_DDRAW))
csCap+="Create DirectDraw faild;\r\n";
if(!(nFlag&SUPPORT_BLT))
csCap+="Don't support BLT;\r\n";
if(!(nFlag&SUPPORT_BLTFOURCC))
csCap+="Don't support color-space conversions;\r\n";
if(!(nFlag&SUPPORT_BLTSHRINKX))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -