📄 localfileplay.cpp
字号:
// LocalFilePlay.cpp : implementation file
//
#include "stdafx.h"
#include "newclient.h"
#include "LocalFilePlay.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLocalFilePlay dialog
#define TIMER_INTERVAL 500
#define USED_PORT 99
extern SERVER_INFO serverinfo[MAXIPNUMBER];
extern CLIENTPARAM ClientParam;
BOOL g_bCapPic=FALSE;
//Finish file reference
void CALLBACK FileRefDone(DWORD nReserved,DWORD nUser)
{
CLocalFilePlay* pOwner=(CLocalFilePlay*)nUser;
pOwner->F_UpdateStepBackUI(TRUE);
}
//Capture picture callback
void CALLBACK DisplayCBFun(long nPort,char * pBuf,long nSize,long nWidth,long nHeight,long nStamp,long nType,long nReceaved)
{
if(!g_bCapPic)
return;
//
CString csDir;
CString csFile;
CTime time=CTime::GetCurrentTime();
csDir.Format("%s",ClientParam.m_csPictureSavePath);
csFile.Format("%s\\Picture_%s_%02d_%4d%02d%02d_%02d%02d%02d_%d.bmp",csDir,CLocalFilePlay::m_csIP,CLocalFilePlay::iSelChannel, \
time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond(), GetTickCount());
if(!PlayM4_ConvertToBmpFile(pBuf,nSize,nWidth,nHeight,nType,csFile.GetBuffer(csFile.GetLength())))
{
TRACE("Convert to Bmp failed!");
}
g_bCapPic=FALSE;
}
CString CLocalFilePlay:: m_csIP="";
int CLocalFilePlay::iSelChannel = -1;
CLocalFilePlay::CLocalFilePlay(CWnd* pParent /*=NULL*/)
: CDialog(CLocalFilePlay::IDD, pParent)
{
//{{AFX_DATA_INIT(CLocalFilePlay)
m_ctTimeStart = 0;
m_ctTimeStop = 0;
m_iChannelSel = -1;
m_ctDateStart = 0;
m_ctDateStop = 0;
//}}AFX_DATA_INIT
m_hPlayEnableIcon = AfxGetApp()->LoadIcon(IDI_PLAY_ENABLE);
m_hPlayDisableIcon = AfxGetApp()->LoadIcon(IDI_PLAY_DISABLE);
m_hPauseEnableIcon = AfxGetApp()->LoadIcon(IDI_PAUSE_ENABLE);
m_hPauseDisableIcon = AfxGetApp()->LoadIcon(IDI_PAUSE_DISABLE);
m_hStopEnableIcon = AfxGetApp()->LoadIcon(IDI_STOP_ENABLE);
m_hStopDisableIcon = AfxGetApp()->LoadIcon(IDI_STOP_DISABLE);
m_hSoundStartIcon= AfxGetApp()->LoadIcon(IDI_SOUND_ENABLE);
m_hSoundStopIcon= AfxGetApp()->LoadIcon(IDI_SOUND_DISABLE);
m_hGotoHeadDisableIcon = AfxGetApp()->LoadIcon(IDI_GOTOSTART_DISABLE);
m_hGotoTailDisableIcon = AfxGetApp()->LoadIcon(IDI_GOTOEND_DISABLE);
m_hFastDisableIcon = AfxGetApp()->LoadIcon(IDI_FASTFORWARD_DISABLE);
m_hSlowDisableIcon= AfxGetApp()->LoadIcon(IDI_FASTBACKWARD_DISABLE);
m_hGotoHeadEnableIcon = AfxGetApp()->LoadIcon(IDI_GOTOSTART_ENABLE);
m_hGotoTailEnableIcon = AfxGetApp()->LoadIcon(IDI_GOTOEND_ENABLE);
m_hFastEnableIcon = AfxGetApp()->LoadIcon(IDI_FASTFORWARD_ENABLE);
m_hSlowEnableIcon = AfxGetApp()->LoadIcon(IDI_FASTBACKWARD_ENABLE);
m_hStepEnableIcon= AfxGetApp()->LoadIcon(IDI_STEP_ENABLE);
m_hStepDisableIcon = AfxGetApp()->LoadIcon(IDI_STEP_DISABLE);
m_hStepBackEnableIcon = AfxGetApp()->LoadIcon(IDI_STEPBACK_ENABLE);
m_hStepBackDisableIcon = AfxGetApp()->LoadIcon(IDI_STEPBACK_DISABLE);
m_hCaptureIcon = AfxGetApp()->LoadIcon(IDI_PIC);
}
void CLocalFilePlay::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLocalFilePlay)
DDX_Control(pDX, IDC_LOCALFILRLIST, m_locFileList);
DDX_Control(pDX, IDC_PROGRESS_SLIDER, m_ctlProgress);
DDX_Control(pDX, IDC_VOLUME_SLIDER, m_ctlVolume);
DDX_Control(pDX, IDC_COMBOSERVER, m_ServerCtrl);
DDX_Control(pDX, IDC_COMBOCHANNEL, m_ChannelCtrl);
DDX_Control(pDX, IDC_COMBOFILETYPE, m_FileTypeCtrl);
DDX_DateTimeCtrl(pDX, IDC_TIMESTART, m_ctTimeStart);
DDX_DateTimeCtrl(pDX, IDC_TIMESTOP, m_ctTimeStop);
DDX_CBIndex(pDX, IDC_COMBOCHANNEL, m_iChannelSel);
DDX_DateTimeCtrl(pDX, IDC_DATESTART, m_ctDateStart);
DDX_DateTimeCtrl(pDX, IDC_DATESTOP, m_ctDateStop);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLocalFilePlay, CDialog)
//{{AFX_MSG_MAP(CLocalFilePlay)
ON_BN_CLICKED(IDC_SEARCHLOCALLIST, OnSearch)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_DELETEALL, OnDeleteall)
ON_BN_CLICKED(IDC_PLAY_FILE, OnPlayFile)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_SLOW, OnSlow)
ON_BN_CLICKED(IDC_FAST, OnFast)
ON_BN_CLICKED(IDC_CAPPIC, OnCappic)
ON_BN_CLICKED(IDC_STEPBACK, OnStepback)
ON_BN_CLICKED(IDC_STEP, OnStep)
ON_BN_CLICKED(IDC_SOUND, OnSound)
ON_WM_DESTROY()
ON_WM_HSCROLL()
ON_WM_LBUTTONDBLCLK()
ON_WM_PAINT()
ON_WM_TIMER()
ON_CBN_SELCHANGE(IDC_COMBOSERVER, OnSelchangeComboserver)
ON_CBN_SELCHANGE(IDC_COMBOFILETYPE, OnSelchangeCombofiletype)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLocalFilePlay message handlers
void CLocalFilePlay::SetParentWnd(HWND *hhWnd, int iParentNum)
{
VERIFY(iParentNum==2);
m_hPareDlgWnd=hhWnd[0];
m_hPareTabWnd=hhWnd[1];
}
BOOL CLocalFilePlay::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rc(0, 0, 0, 0);
GetParent()->GetClientRect(&rc);
((CTabCtrl*)GetParent())->AdjustRect(FALSE, &rc);
MoveWindow(&rc);
m_locFileList.InsertColumn(0,"File Name",LVCFMT_LEFT,120,-1);
m_locFileList.InsertColumn(1,"Channel",LVCFMT_LEFT,40,-1);
m_locFileList.InsertColumn(2,"Type",LVCFMT_LEFT,40,-1);
m_locFileList.InsertColumn(3,"Start Time",LVCFMT_LEFT,120,-1);
m_locFileList.InsertColumn(4,"End Time",LVCFMT_LEFT,120,-1);
m_ServerCtrl.AddString("Please select DVR");
for(int i = 0; i < MAXIPNUMBER; i++)
{
if(serverinfo[i].m_csServerName != "")
m_ServerCtrl.AddString(serverinfo[i].m_csServerName);
}
m_bPlay=FALSE;
m_bPause=FALSE;
m_bSound=FALSE;
m_iTotalSeconds=0;
m_bStep=FALSE;
m_bFileRefCreated=FALSE;
m_hPlayWnd = GetDlgItem(IDC_WND)->m_hWnd;
m_bFullScreen=FALSE;
m_hPareDlgWnd=NULL;
m_hPareTabWnd=NULL;
m_iChannelnumber = 16;
F_InitUI();
GetDlgItem(IDC_WND)->GetWindowRect(m_rcWnd);
ScreenToClient(m_rcWnd);
ShowWindow(SW_SHOW);
CTime time1 = CTime::GetCurrentTime();
CTime time(time1.GetYear(),time1.GetMonth(),time1.GetDay(),0,0,0);
CTime time0(time1.GetYear(),time1.GetMonth(),time1.GetDay(),23,59,59);
m_ctDateStart = time;
m_ctTimeStart = time;
m_ctDateStop = time1;
m_ctTimeStop = time0;
UpdateData(FALSE);
m_ServerCtrl.SetCurSel(0);
m_ChannelCtrl.SetCurSel(0);
m_FileTypeCtrl.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CLocalFilePlay::OnSearch()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int iServerSel;
CString csIP;
CTime tStartTime,tStopTime;
int iSum = 0;
int m_iType;
int i,j;
if(!F_CheckDate(m_ctDateStart,m_ctDateStop))
return;
m_locFileList.DeleteAllItems();
m_iTSum = 0;
if(m_ServerCtrl.GetCurSel() == 0)
{
AfxMessageBox("Please select DVR!");
return;
}
iServerSel = m_ServerCtrl.GetCurSel()-1;
csIP.Format("%s",serverinfo[iServerSel].m_csServerIP);
tStartTime = CTime(m_ctDateStart.GetYear(),m_ctDateStart.GetMonth(),m_ctDateStart.GetDay(),m_ctTimeStart.GetHour(),m_ctTimeStart.GetMinute(),m_ctTimeStart.GetSecond());
tStopTime = CTime(m_ctDateStop.GetYear(),m_ctDateStop.GetMonth(),m_ctDateStop.GetDay(),m_ctTimeStop.GetHour(),m_ctTimeStop.GetMinute(),m_ctTimeStop.GetSecond());
m_iType = m_FileTypeCtrl.GetCurSel();
if(m_iChannelSel == 0)
{
//all channel
for(i=0; i<=m_iChannelnumber; i++)
{
if(m_iType!=0)
iSum = iSum + F_ShowlocalFile(csIP,m_iType,i+m_lStartChan, tStartTime, tStopTime);
else
{
for(j = 1;j<=3;j++)
iSum = iSum + F_ShowlocalFile(csIP,j,i+m_lStartChan, tStartTime, tStopTime);
}
}
}
else
{
if(m_iType!=0)
iSum = F_ShowlocalFile(csIP,m_iType,m_iChannelSel-1+m_lStartChan, tStartTime, tStopTime);
else
{
for(j = 1;j<=3;j++)
iSum = iSum + F_ShowlocalFile(csIP,j,m_iChannelSel-1+m_lStartChan, tStartTime, tStopTime);
}
}
if(iSum > 0)
F_SetStopState();
else
F_InitUI();
TRACE("Find %d files in all.",iSum);
AfxMessageBox("Search Completed!");
UpdateData(FALSE);
}
void CLocalFilePlay::OnDelete()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int fileselpos = 0;
CString csFileName;
POSITION pos = m_locFileList.GetFirstSelectedItemPosition();
if(pos == NULL)
return;
fileselpos = m_locFileList.GetNextSelectedItem(pos);
TRACE("fileselpos = %d", fileselpos);
csFileName=m_locFileList.GetItemText(fileselpos,0);
if(csFileName.GetLength()==0)
return;
TRACE("Delete Mp4 filename = %s", csFileName);
if(IDOK!=MessageBox("Are you sure to delete the file?","Warning",IDOK))
return;
if(DeleteFile(csFileName))
{
m_locFileList.DeleteItem(fileselpos);
}
else
{
CString csError;
csError.Format("Can not delete the file:%s!",csFileName);
MessageBox(csError);
}
}
void CLocalFilePlay::OnDeleteall()
{
// TODO: Add your control notification handler code here
int iCount, i;
CString csFileName;
iCount = m_locFileList.GetItemCount();
TRACE("iCount = %d", iCount);
if(iCount < 1)
return;
if(IDOK!=MessageBox("Are you sure to delete all files?","Warning",IDOK))
return;
for(i = iCount; i > 0; i--)
{
csFileName = m_locFileList.GetItemText(i-1, 0);
if(csFileName.GetLength() == 0)
continue;
if(DeleteFile(csFileName))
{
m_locFileList.DeleteItem(i-1);
}
else
{
CString csError;
csError.Format("Can not delete file:%s!",csFileName);
MessageBox(csError);
}
}
}
void CLocalFilePlay::OnPlayFile()
{
// TODO: Add your control notification handler code here
if(m_bPlay)
{
if(m_bStep)
{
PlayM4_Play(USED_PORT,m_hPlayWnd);
F_SetPlayState();
m_bStep=FALSE;
}
else
F_Pause();
return;
}
F_Play();
if(m_bPlay)
{
F_SetPlayState();
F_Sound(TRUE);
SetTimer(PLAY_TIMER,TIMER_INTERVAL,NULL);
}
}
void CLocalFilePlay::OnStop()
{
// TODO: Add your control notification handler code here
if(!m_bPlay)
return;
m_ctlProgress.SetPos(0);
CString csText;
GetDlgItem(IDC_PLAYSTATUS)->SetWindowText(csText);
KillTimer(PLAY_TIMER);
csText.Format("%d/%d %02d:%02d:%02d/%02d:%02d:%02d",0,0,0,0,0,0,0,0);
UpdateData(FALSE);
Invalidate(TRUE);
F_Stop();
}
void CLocalFilePlay::OnSlow()
{
// TODO: Add your control notification handler code here
PlayM4_Slow(USED_PORT);
}
void CLocalFilePlay::OnFast()
{
// TODO: Add your control notification handler code here
PlayM4_Fast(USED_PORT);
}
void CLocalFilePlay::OnCappic()
{
// TODO: Add your control notification handler code here
g_bCapPic=TRUE;
}
void CLocalFilePlay::OnStepback()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -