📄 playerdlg.cpp
字号:
csCap+="Don't support arbitrary shrinking of a surface along the x-axis\r\n";
if(!(nFlag&SUPPORT_BLTSHRINKY))
csCap+="Don't supports arbitrary shrinking of a surface along the y-axis (vertically);\r\n";
if(!(nFlag&SUPPORT_BLTSTRETCHX))
csCap+="Don't supports arbitrary stretching of a surface along the x-axis;\r\n";
if(!(nFlag&SUPPORT_BLTSTRETCHY))
csCap+="Don't supports arbitrary stretching of a surface along the y-axis;\r\n";
if(csCap.GetLength()>0)
{
csCap+="If your video adapter chip is made by nVidia,please update the new driver!\r\n";
MessageBox(csCap,"Warning",MB_OK);
}
}
//////////////////////////////////////////////////////////////////////
//Function: Limit the window size.
//////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnSizing(UINT fwSide, LPRECT pRect)
{
if((pRect->right-pRect->left)<100)
pRect->right=pRect->left+100;
if((pRect->bottom-pRect->top)<150)
pRect->bottom=pRect->top+150;
CDialog::OnSizing(fwSide, pRect);
// TODO: Add your message handler code here
}
/////////////////////////////////////////////////////////////////////
//Funtion: Rewind
/////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnRepeat()
{
// TODO: Add your command handler code here
if(m_bRepeatPlay)
{
m_pMainMenu->CheckMenuItem(ID_REPEAT,MF_UNCHECKED );
m_bRepeatPlay=FALSE;
}
else
{
m_pMainMenu->CheckMenuItem(ID_REPEAT,MF_CHECKED );
m_bRepeatPlay=TRUE;
}
}
//////////////////////////////////////////////////////////////////////
//Function: Close.
//////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
Hik_PlayM4_Stop(PORT);
Hik_PlayM4_CloseFile(PORT);
Hik_PlayM4_RealeseDDraw();
#if (WINVER > 0x0400)
Hik_PlayM4_ReleaseDDrawDevice();
#endif
m_pSeek->DestroyWindow();
delete m_pSeek;
m_pDisplayRegion->DestroyWindow();
delete m_pDisplayRegion;
if(yuvBuf!=NULL)
{
free(yuvBuf);
yuvBuf=NULL;
}
if(outFile) free(outFile);
CDialog::OnClose();
}
///////////////////////////////////////////////////////////////////////
//Function: Set imagequality.
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnQuality()
{
// TODO: Add your command handler code here
if(m_bPicQuality)
{
m_pMainMenu->CheckMenuItem(ID_QUALITY,MF_UNCHECKED );
m_bPicQuality=FALSE;
}
else
{
m_pMainMenu->CheckMenuItem(ID_QUALITY,MF_CHECKED );
m_bPicQuality=TRUE;
}
Hik_PlayM4_SetPicQuality(PORT,m_bPicQuality);
}
///////////////////////////////////////////////////////////////////////
//Function:change the image quality by windows size.
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
CDialog::OnWindowPosChanged(lpwndpos);
// TODO: Add your message handler code here
//delete by lgl at 2003-6-18, don't change qulity.Suggest high quality!
/* CRect rcPlay;
GetDlgItem(IDC_SHOW)->GetClientRect(rcPlay);
if(rcPlay.Width()>352||rcPlay.Height()>288)
{
//TRACE("RECT BIG\n");
if(!m_bPicQuality)
{
m_bPicQuality=TRUE;
Hik_PlayM4_SetPicQuality(PORT,m_bPicQuality);
m_pMainMenu->CheckMenuItem(ID_QUALITY,MF_CHECKED );
}
}
else
{
//TRACE("RECT LITTLE\n");
if(m_bPicQuality)
{
m_bPicQuality=FALSE;
Hik_PlayM4_SetPicQuality(PORT,m_bPicQuality);
m_pMainMenu->CheckMenuItem(ID_QUALITY,MF_UNCHECKED );
}
}
*/
}
///////////////////////////////////////////////////////////////////////
//Function:normal video size;
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnViewZoom100()
{
InitWindowSize(m_nWidth,m_nHeight);
}
///////////////////////////////////////////////////////////////////////
//Funtion: Double video size.
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnViewZoom200()
{
// TODO: Add your command handler code here
InitWindowSize(m_nWidth<<1,m_nHeight<<1);
}
///////////////////////////////////////////////////////////////////////
//half video size.
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnViewZoom50()
{
// TODO: Add your command handler code here
InitWindowSize(m_nWidth>>1,m_nHeight>>1);
}
///////////////////////////////////////////////////////////////////////
//Funtion: Open the file by stream type.
////////////////////////////////////////////////////////////////////////
BOOL CPlayerDlg::OpenStream()
{
m_nTotalHour= 0;
m_nTotalMinute= 0;
m_nTotalSecond= 0;
m_nTotalFrames= 0;
m_bFileEnd= FALSE;
m_hStreamFile=CreateFile(m_strPlayFileName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(m_hStreamFile==INVALID_HANDLE_VALUE)
{
MessageBox("Open file failed");
return FALSE;
}
m_nMaxFileSize=::GetFileSize(m_hStreamFile,NULL);
Hik_PlayM4_SetSourceBufCallBack(PORT,10000,SourceBufFun,(DWORD)this,NULL);
Hik_PlayM4_SetStreamOpenMode(PORT,STREAME_FILE);
m_nHeadSize=Hik_PlayM4_GetFileHeadLength();
PBYTE pBuf;
char csError[50];
DWORD dw;
m_hThread=NULL;
m_hEventInput=NULL;
m_hEventKill=NULL;
__try
{
m_hThread= CreateThread(NULL,0, LPTHREAD_START_ROUTINE (InputStreamThread),this,0,&dw);
m_hEventInput= CreateEvent(NULL,TRUE,FALSE,NULL);
m_hEventKill= CreateEvent(NULL,FALSE,FALSE,NULL);
if(!(m_hThread&&m_hEventInput&&m_hEventKill))
{
MessageBox("Create thread failed");
return FALSE;
}
pBuf=new BYTE[m_nHeadSize];
if(!pBuf)
{
MessageBox("Alloc memory failed");
return FALSE;
}
DWORD nRealRead;
ReadFile(m_hStreamFile,pBuf,m_nHeadSize,&nRealRead,NULL);
if(nRealRead!=m_nHeadSize)
{
MessageBox("File is too small");
return FALSE;
}
if(!Hik_PlayM4_OpenStream(PORT,pBuf,m_nHeadSize,200000))
{
sprintf(csError,"Open stream failed(%d)",Hik_PlayM4_GetLastError(PORT));
MessageBox(csError);
return FALSE;
}
}
__finally
{
if(pBuf)
{
delete []pBuf;
pBuf=NULL;
}
if(AbnormalTermination())
{
CloseStream();
}
}
SetOpenState();
Play();
return TRUE;
}
///////////////////////////////////////////////////////////////////////
//Function:Close the stream.
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::CloseStream()
{
Stop();
Hik_PlayM4_CloseStream(PORT);
if(m_hStreamFile)
{
CloseHandle(m_hStreamFile);
m_hStreamFile=NULL;
}
if(m_hThread)
{
SetEvent(m_hEventKill);
DWORD dwStatus;
for(int i=0;i<5;i++)
{
if(!::GetExitCodeThread(m_hThread, &dwStatus)||i==4)
{
TerminateThread(m_hThread,0);
TRACE("GetExitCode option error!-decodethread\n");
}
else
{
if(dwStatus==STILL_ACTIVE)
{
SetEvent(m_hEventKill);
Sleep(2);
}
else
break;
}
}
CloseHandle(m_hThread);
m_hThread=NULL;
}
if(m_hEventInput)
{
CloseHandle(m_hEventInput);
m_hEventInput=NULL;
}
if(m_hEventKill)
{
CloseHandle(m_hEventKill);
m_hEventKill=NULL;
}
SetCloseState();
}
///////////////////////////////////////////////////////////////////////
//Funtion:The source buffer call back funtion.
////////////////////////////////////////////////////////////////////////
void CALLBACK SourceBufFun(long nPort,DWORD nBufSize,DWORD dwUser,void*pContext)
{
CPlayerDlg* pOwner=(CPlayerDlg*)dwUser;
//do after play!
if(!pOwner->m_bPlaying)
return ;
Hik_PlayM4_ResetSourceBufFlag(nPort);
if(pOwner->m_bFileEnd)
{
PostMessage(pOwner->m_hWnd,WM_FILE_END,PORT,0);
pOwner->m_bFileEnd=FALSE;
}
else
SetEvent(pOwner->m_hEventInput);
}
///////////////////////////////////////////////////////////////////////
//Function: thread.
////////////////////////////////////////////////////////////////////////
#define BUF_SIZE 4096
DWORD WINAPI InputStreamThread( LPVOID lpParameter)
{
CPlayerDlg* pOwner=(CPlayerDlg*)lpParameter;
HANDLE hMulEvents[2];
hMulEvents[0]=pOwner->m_hEventKill;
hMulEvents[1]=pOwner->m_hEventInput;
BYTE pBuf[BUF_SIZE];
DWORD nRealRead;
BOOL bBufFull=FALSE;
while(WAIT_OBJECT_0!=WaitForMultipleObjects(2,hMulEvents,FALSE,INFINITE))
{
if(!bBufFull)
{
if(!(ReadFile(pOwner->m_hStreamFile,pBuf,BUF_SIZE,&nRealRead,NULL)&&nRealRead==BUF_SIZE))
{
//File end;
pOwner->m_bFileEnd=TRUE;
bBufFull=FALSE;
ResetEvent(pOwner->m_hEventInput);
}
}
if(!Hik_PlayM4_InputData(PORT,pBuf,BUF_SIZE))
{
bBufFull=TRUE;
ResetEvent(pOwner->m_hEventInput);
}
else
bBufFull=FALSE;
}
return 1;
}
///////////////////////////////////////////////////////////////////////
//Function: Change interface to open.
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::SetOpenState()
{
m_bOpen=TRUE;
Hik_PlayM4_GetPictureSize(PORT,&m_nWidth,&m_nHeight);
//HCIF
/* if(m_nWidth==WIDTH*2&&m_nHeight<=HEIGHT_PAL)
m_nHeight*=2;
*/
InitWindowSize(m_nWidth,m_nHeight);
CMenu *pSubMenue=m_pMainMenu->GetSubMenu(1);
pSubMenue->EnableMenuItem(1,MF_ENABLED |MF_BYPOSITION);
//try overlay mode!
Hik_PlayM4_SetOverlayMode(PORT,TRUE,RGB(255,0,255));
m_pMainMenu->EnableMenuItem(ID_STREAM_TYPE,MF_GRAYED|MF_DISABLED);
//Disalbe TIMER SELECT
m_pMainMenu->EnableMenuItem(ID_TIMER2,MF_GRAYED|MF_DISABLED);
m_pMainMenu->EnableMenuItem(ID_TIMER1,MF_GRAYED|MF_DISABLED);
}
///////////////////////////////////////////////////////////////////////
//Funtion: change interface to close.
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::SetCloseState()
{
if(!m_bPlaying)
{
m_pMainMenu->EnableMenuItem(ID_FILE_CLOSE, TRUE);
}
CMenu *pSubMenue=m_pMainMenu->GetSubMenu(1);
pSubMenue->EnableMenuItem(1,MF_DISABLED|MF_GRAYED|MF_BYPOSITION);
m_pMainMenu->EnableMenuItem(ID_STREAM_TYPE,MF_ENABLED);
m_pMainMenu->EnableMenuItem(ID_CUT_FILE,MF_GRAYED);
m_pMainMenu->EnableMenuItem(ID_SEEK,MF_GRAYED);
m_strPlayFileName="";
m_bOpen=FALSE;
// Add 2004-4-26;
m_SliderB.SetPos(COLOR_DEFAULT);
m_SliderC.SetPos(COLOR_DEFAULT);
m_SliderS.SetPos(COLOR_DEFAULT);
m_SliderH.SetPos(COLOR_DEFAULT);
#ifdef WAVE_ADJ
m_SoundSlider.SetPos(0);
#else
m_SoundSlider.SetPos(0xffff>>1);
#endif
GetDlgItem(IDC_PLAY)->EnableWindow(FALSE);
}
///////////////////////////////////////////////////////////////////////
//Funcion: select the open mode,stream or file.
////////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnStreamType()
{
// TODO: Add your command handler code here
if(m_bStreamType)
{
m_pMainMenu->CheckMenuItem(ID_STREAM_TYPE,MF_UNCHECKED );
m_bStreamType=FALSE;
}
else
{
m_pMainMenu->CheckMenuItem(ID_STREAM_TYPE,MF_CHECKED );
m_bStreamType=TRUE;
}
}
///////////////////////////////////////////////////////////////////////
//Function:Step back;
//////////////////////////////////////////////////////////////////////
void CPlayerDlg::OnStepback()
{
// TODO: Add your control notification handler code here
//you can do as the followed.
//DWORD nCurrentFrame=Hik_PlayM4_GetCurrentFrameNum(PORT);
//Hik_PlayM4_SetCurrentFrameNum(PORT,nCurrentFrame-1);
Hik_PlayM4_OneByOneBack(PORT);
CButton *pButton;
pButton = (CButton *)GetDlgItem(IDC_PLAY);
pButton->SetIcon(m_hPlayEnableIcon);
pButton->EnableWindow(TRUE);
}
////////////////////////////////////////////////////////////////////////
//Functon:File reference call back function.
///////////////////////////////////////////////////////////////////////
void CALLBACK FileRefDone(DWORD nReserved,DWORD nUser)
{
CPlayerDlg* pOwner=(CPlayerDlg*)nUser;
pOwner->m_bFileRefCreated=TRUE;
pOwner->ChangeUI();
TRACE("File reference created!\n");
}
//////////////////////////////////////////////////////////////////////////
//Function:Change UI when the file ref call back function is called.
//////////////////////////////////////////////////////////////////////////
void CPlayerDlg::ChangeUI()
{
if(m_bFileRefCreated)
{
CButton *pButton;
pButton = (CButton *)GetDlgIt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -