📄 hkvisiondlg.cpp
字号:
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CHKVisionDlg::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 CHKVisionDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int LogWrite(const char *Format, ...)
{
return 1;
CHAR Buffer0[1024];
CHAR Buffer1[512];
DWORD ItemsWritten;
va_list ArgumentList;
// if(logFile == -1)return -1;
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
sprintf(Buffer0, "%02d%02d:%02d:%02d:%02d:", sysTime.wMonth, sysTime.wDay, sysTime.wHour,
sysTime.wMinute, sysTime.wSecond);
va_start ( ArgumentList, Format );
ItemsWritten = vsprintf ((char *)Buffer1, Format, ArgumentList );
va_end ( ArgumentList );
strcat(Buffer0, Buffer1);
// return _write ( logFile, Buffer0, strlen((const char *)Buffer0 ));
}
void CHKVisionDlg::OnStart()
{
// TODO: Add your control notification handler code here
CSelectDSP selDialog;
selDialog.DSPPreset(m_bDspPreset, GetTotalDSPs());
// if(selDialog.DoModal() == IDOK){
{
// TRACE("SelectDSP:OK button clicked\n");
selDialog.GetDSPsChoiced(m_bDspPreset);
CString str;
str.Format("%d", 0);
GetDlgItem(IDC_LOST_FRAMES)->SetWindowText((LPCTSTR)str);
GetDlgItem(IDC_TOTALFRAMES)->SetWindowText((LPCTSTR)str);
GetDlgItem(IDC_BPS)->SetWindowText((LPCTSTR)str);
// GetDlgItem(IDC_FPS)->SetWindowText((LPCTSTR)str);
LogWrite("start capture\n");
for(int i = 0; i < GetTotalDSPs(); i++){
m_bDspPreset[i]=TRUE;
if(m_bDspPreset[i]){
char fileName[256];
sprintf(fileName, "d:\\stream%d_%d.264", i, gFileNum++/GetTotalDSPs());
gFileHandle[i] = _open(fileName, _O_CREAT | _O_BINARY | _O_WRONLY| _O_TRUNC, _S_IREAD | _S_IWRITE);
if(gFileHandle[i] == -1){
TRACE("channel %d file open error\n,i");
return;
}
gChannelFrames[i] = 0;
gChannelTotalLength[i] = 0;
gChannelFramesLost[i] = 0;
gChannelOverflow[i] = 0;
gCurrentFileLen[i] = 0;
_write(gFileHandle[i], FileHeader[i], FileHeaderLen);
// could not be start again untill stopped first
//m_bDspPreset[i] = FALSE;
gCaptureStartedNum++;
// let the threads have chance to run
//Sleep(500);
}else
gFileHandle[i] = -1;
}
StartTime = timeGetTime();
LastTime = timeGetTime();
if(gCaptureStartedNum){
GetDlgItem(IDC_STOP)->EnableWindow(TRUE);
GetDlgItem(IDC_START)->EnableWindow(FALSE);
GetDlgItem(IDC_SETTINGS)->EnableWindow(FALSE);
}
}
/*
StartVideoCapture(ChannelHandle[0]);
bCapture = TRUE;
*/
}
void CHKVisionDlg::LogMessage(const unsigned char *buf, void *context)
{
if(!IsWindow(this->m_hWnd))return;
int len = m_Logwin.GetWindowTextLength();
CString str;
if (len >= 16384)
{
m_Logwin.GetWindowText(str);
m_Logwin.SetWindowText(str.GetBuffer(len)+16384);
len -= 16384;
}
str = buf;
m_Logwin.SetSel(len, len);
m_Logwin.ReplaceSel(str);
}
void CHKVisionDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
bCapture = FALSE;
MP4_ServerStop();
m_bLog = FALSE;
KillTimer(gTimer);
if(gCaptureStartedNum)
OnStop();
gCaptureStartedNum = 0;
DeInitDSPs();
// _close(logFile);
CDialog::OnClose();
}
void CHKVisionDlg::OnStop()
{
// TODO: Add your control notification handler code here
CSelectDSP selDialog;
selDialog.DSPPreset(m_bDspPreset, GetTotalDSPs());
// bCapture = FALSE;
// if(selDialog.DoModal() == IDOK){
{
LogWrite("Stop capture\n");
// TRACE("SelectDSP:OK button clicked\n");
selDialog.GetDSPsChoiced(m_bDspPreset);
for(int i = 0; i < GetTotalDSPs(); i++){
if(m_bDspPreset[i]){
ASSERT(gFileHandle[i] != -1);
// StopVideoCapture(ChannelHandle[i]);
//lseek(gFileHandle[i], 0, SEEK_SET);
//FRAMES_STATISTICS fs;
//GetFramesStatistics(ChannelHandle[i], &fs);
//ULONG frames = fs.AudioFrames + fs.VideoFrames;
//TRACE("channel %i has %x frames written\n", i, frames);
#define END_CODE 0x00000002
ULONG endCode = END_CODE;
_write(gFileHandle[i], &endCode, sizeof(ULONG));
_close(gFileHandle[i]);
///add v34
if (bEncodeCifAndQcif[i])
_close(gFileHandleQcif[i]);
gCaptureStartedNum--;
}
}
if(!gCaptureStartedNum){
GetDlgItem(IDC_START)->EnableWindow(TRUE);
GetDlgItem(IDC_SETTINGS)->EnableWindow(TRUE);
GetDlgItem(IDC_STOP)->EnableWindow(FALSE);
}
}
}
void CHKVisionDlg::StartVideoPreview()
{
}
void CHKVisionDlg::StopVideoPreview()
{
// TRACE("StopVideoPreview\n");
for(int i = 0; i < GetTotalDSPs(); i++){
::StopVideoPreview(ChannelHandle[i]);
}
}
void CHKVisionDlg::OnPreview()
{
/*
// TODO: Add your control notification handler code here
static BOOLEAN bVideoStarted = FALSE;
if(bVideoStarted){
StopVideoPreview();
bVideoStarted = FALSE;
}else{
StartVideoPreview();
bVideoStarted = TRUE;
}
*/
//////以下为演示程序
char ctemp[256];
sprintf(ctemp,"192.0.0.214");
MP4_ServerStringToClient((LPCTSTR)ctemp,"receive",7);
}
HBRUSH CHKVisionDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if((nCtlColor== CTLCOLOR_EDIT) && (pWnd->GetDlgCtrlID() == IDC_EDIT1)){
pDC->SetTextColor (RGB (255, 0 , 0));
pDC->SetBkColor(gBackgroundColor);
hbr = (HBRUSH) m_brush1;
}
if((nCtlColor== CTLCOLOR_EDIT) && (pWnd->GetDlgCtrlID() == IDC_LOGWIN)){
pDC->SetTextColor (RGB (255, 0 , 0));
pDC->SetBkColor(RGB(0, 0, 0));
// pDC->SetBkColor(RGB(255, 0, 255));
hbr = (HBRUSH) m_brush2;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CHKVisionDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
// TRACE("Onshowwindow m_hwnd is %x\n", m_hWnd);
m_bLog = TRUE;
}
void CHKVisionDlg::OnMove(int x, int y)
{
CDialog::OnMove(x, y);
if(!dlgInited)return;
// TODO: Add your message handler code here
::SendMessage(GetDlgItem(IDC_VIDEOWIN)->m_hWnd, WM_PAINT, 0, 0);
}
void CHKVisionDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CHKVisionDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
/* // TODO: Add your message handler code here and/or call default
int bright, contrast, sat, hue, standard;
if((GetDlgItem(IDC_SLIDER_BRIGHT) == pScrollBar) && (nSBCode != SB_ENDSCROLL)){
for(int i = 0; i < GetTotalDSPs(); i++){
GetVideoPara(ChannelHandle[i], &standard, &bright, &contrast, &sat, &hue);
bright = (nPos * 255) / 100;
/ TRACE("b=%i c=%i s=%i h=%i\n", bright, contrast, sat, hue);
SetVideoPara(ChannelHandle[i], bright, contrast, sat, hue);
}
}
if((GetDlgItem(IDC_SLIDER_CONTRAST) == pScrollBar) && (nSBCode != SB_ENDSCROLL)){
for(int i = 0; i < GetTotalDSPs(); i++){
GetVideoPara(ChannelHandle[i], &standard, &bright, &contrast, &sat, &hue);
contrast = (nPos * 127) / 100;
TRACE("b=%i c=%i s=%i h=%i\n", bright, contrast, sat, hue);
SetVideoPara(ChannelHandle[i], bright, contrast, sat, hue);
}
}
if((GetDlgItem(IDC_SLIDER_SAT) == pScrollBar) && (nSBCode != SB_ENDSCROLL)){
for(int i = 0; i < GetTotalDSPs(); i++){
GetVideoPara(ChannelHandle[i], &standard, &bright, &contrast, &sat, &hue);
sat = (nPos * 127) / 100;
TRACE("b=%i c=%i s=%i h=%i\n", bright, contrast, sat, hue);
SetVideoPara(ChannelHandle[i], bright, contrast, sat, hue);
}
}
if((GetDlgItem(IDC_SLIDER_HUE) == pScrollBar) && (nSBCode != SB_ENDSCROLL)){
for(int i = 0; i < GetTotalDSPs(); i++){
GetVideoPara(ChannelHandle[i], &standard, &bright, &contrast, &sat, &hue);
hue = (nPos * 255) / 100;
TRACE("b=%i c=%i s=%i h=%i\n", bright, contrast, sat, hue);
SetVideoPara(ChannelHandle[i], bright, contrast, sat, hue);
}
}
*/
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
int CHKVisionDlg::OnUpdateCounters(UINT wparam, INT lparam)
{
CString str;
str.Format("%i", wparam);
GetDlgItem(IDC_IFRAMES)->SetWindowText((LPCTSTR)str);
return 0;
}
void CHKVisionDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
}
int CHKVisionDlg::OnDataReady(UINT channelNum, INT lparam)
{
ULONG length = 1000000;
int frameType;
int status,i;
BOOL breakable;
CString ctip;
int nframetype =0;
// if cap images we need clean the queue here
// if (!bCapture)
// return 0;
status = ReadStreamData(ChannelHandle[channelNum], StreamBuf, &length, &frameType);
// error occured
if(status < 0){
TRACE("error:ReadStreamData %x\n", status);
return 0;
}
///add v34
// nframetype value: 1 cif head; 2 qcif head; 3 cif frame; 4 qcif frame; 5 audio frame; 0 others
//在CIF,QICF同时编码时,要对子通道的数据流分别处理
// CIF的数据存入CIF文件中,QCIF的数据存入QCIF文件中,音频数据要分别存储
// if (bEncodeCifAndQcif[channelNum])
// nframetype = GetSubChannelStreamType(&StreamBuf,frameType);
breakable = status;
// no errors
if(frameType > 0) {
if(frameType == PktSysHeader){
if (bEncodeCifAndQcif[channelNum])
{
if (nframetype == 1) //get cif file header
{
memcpy(FileHeader[channelNum],StreamBuf,length);
FileHeaderLen = length;
}
else if (nframetype ==2) //get qcif or qqcif file header
{
memcpy(FileHeaderQcif[channelNum], StreamBuf, length);
TRACE("Ch%02d get Qcifhead or QQcifhead!\n",channelNum);
FileHeaderLen = length;
}
}
else{
TRACE("channel %d get the file header !\n",channelNum);
// store the file header
memcpy(FileHeader[channelNum], StreamBuf, length);
FileHeaderLen = length;
}
}
if(frameType == PktMotionDetection){
m_VideoWin.DrawVect(channelNum, (char *)StreamBuf, length);
return 0;
}
if(frameType == PktOrigImage){
return 0;
}
}
if(length == 0){
TRACE("no data ?\n");
return 0;
}
if(frameType == PktIFrames){
int iii=1;
}
ULONG currentTime = timeGetTime();
gChannelTotalLength[channelNum] += length;
gCurrentFileLen[channelNum] += length;
if(currentTime > StartTime+1000){
CString str,str2;
str.Format("%d", (gChannelTotalLength[dcurrentwin] *8/(currentTime - StartTime)));
for(i=0;i<g_nChannelTotal;i++)
gChannelTotalLength[i] = 0;
StartTime= currentTime;
GetDlgItem(IDC_BPS)->SetWindowText((LPCTSTR)str);
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -