📄 hkvisiondlg.cpp
字号:
if((gCurrentFileLen[wparam] > gFileSize * 1000 * 1000) && breakable){
TRACE("switch file:frametype=%x\n", frameType);
_close(gFileHandle[wparam]);
// create new file
char fileName[256];
sprintf(fileName, "stream%d_%d.mp4", wparam, gFileNum++/GetTotalDSPs());
gFileHandle[wparam] = _open(fileName, _O_CREAT | _O_BINARY | _O_WRONLY| _O_TRUNC, _S_IREAD | _S_IWRITE);
// write the header first
_write(gFileHandle[wparam], FileHeader, FileHeaderLen);
gCurrentFileLen[wparam] -= gFileSize * 1000 * 1000;
}
*/
if(frameType ==PktAudioFrames)
{
_write(gFileHandleQcif[channelNum],StreamBuf,length);
MP4_ServerWriteDataEx(channelNum,(unsigned char *)StreamBuf, length,frameType,status,1);
_write(gFileHandle[channelNum], StreamBuf, length);
MP4_ServerWriteDataEx(channelNum,(unsigned char *)StreamBuf, length,frameType,status,0);
}else if (frameType ==PktSubIFrames || frameType ==PktSubPFrames || frameType == PktSubBBPFrames || frameType == PktSubSysHeader)
{
_write(gFileHandleQcif[channelNum],StreamBuf,length);
MP4_ServerWriteDataEx(channelNum,(unsigned char *)StreamBuf, length,frameType,status,1);
}else
{
_write(gFileHandle[channelNum], StreamBuf, length);
MP4_ServerWriteDataEx(channelNum,(unsigned char *)StreamBuf, length,frameType,status,0);
}
return 0;
}
void CHKVisionDlg::OnSettings()
{
// TODO: Add your control notification handler code here
int i;
CSettingsDlg dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK){
// TRACE("quant = %d file size = %d streamType = %d\n",
// dlg.m_Quant, dlg.m_FileSize , dlg.m_StreamType);
// setup quant value
USHORT Format1[40] = {48, 16, 'H','I','K','V', 'I','S','I','O','N', '\0'};
USHORT Format2[40] = {24, 50, _OSD_YEAR4, '-',_OSD_MONTH2,'-',_OSD_DAY,'-', _OSD_HOUR24, ':', _OSD_MINUTE,':', _OSD_SECOND, '\0'};
PictureFormat_t encodeType ;
for( i = 0; i < GetTotalDSPs(); i++){
StopVideoCapture(ChannelHandle[i]);
}
switch(dlg.m_iEncodeType)
{
case 0:
encodeType = ENC_4CIF_FORMAT;
break;
case 1:
encodeType = ENC_2CIF_FORMAT;
break;
case 2:
encodeType = ENC_DCIF_FORMAT;
break;
case 3:
encodeType = ENC_CIF_FORMAT;
break;
case 4:
encodeType = ENC_QCIF_FORMAT;
break;
default:
encodeType = ENC_CIF_FORMAT;
break;
}
for(i = 0; i < GetTotalDSPs(); i++)
{
if(encodeType != ENC_4CIF_FORMAT)
{
SetEncoderPictureFormat(ChannelHandle[i],encodeType);
}
else if ((i%4==0)||(i%4==1))
{
SetEncoderPictureFormat(ChannelHandle[i],encodeType);
}
}
for(i = 0; i < GetTotalDSPs(); i++){
SetBitrateControlMode(ChannelHandle[i], dlg.m_bCbr ?brCBR : brVBR );
}
for( i = 0; i < GetTotalDSPs(); i++)
{
if (!dlg.m_bCbr)
{
SetDefaultQuant(ChannelHandle[i], dlg.m_iQuant, dlg.m_pQuant, dlg.m_bQuant);
SetupBitrateControl(ChannelHandle[i],dlg.m_dwbitrate);
}
else
SetupBitrateControl(ChannelHandle[i],dlg.m_dwbitrate);
}
if(dlg.m_OsdEnable){
for(i = 0; i < GetTotalDSPs(); i++){
SetOsdDisplayMode(ChannelHandle[i], 255, TRUE, 0, Format1, Format2);
SetOsd(ChannelHandle[i], TRUE);
}
}else {
for(i = 0; i < GetTotalDSPs(); i++){
SetOsd(ChannelHandle[i], FALSE);
}
}
if(dlg.m_IFramesIntervals < 12){
AfxMessageBox("Invalid Key Frames Invervals\n");
return;
}else{
if((dlg.m_FrameRate > 25) || (dlg.m_FrameRate <=0))
dlg.m_FrameRate = 25;
for( i = 0; i < GetTotalDSPs(); i++){
SetIBPMode(ChannelHandle[i], dlg.m_IFramesIntervals, 2, 1, dlg.m_FrameRate);
}
}
if(dlg.m_MotionDetect){
for( i = 0; i < GetTotalDSPs(); i++){
StartMotionDetection(ChannelHandle[i]);
}
}else{
for( i = 0; i < GetTotalDSPs(); i++){
StopMotionDetection(ChannelHandle[i]);
}
}
USHORT streamType = STREAM_TYPE_AVSYNC;
switch(dlg.m_StreamType){
case 0:
streamType = STREAM_TYPE_VIDEO;
break;
case 1:
streamType = STREAM_TYPE_AUDIO;
break;
case 2:
streamType = STREAM_TYPE_AVSYNC;
break;
}
for(i = 0; i < GetTotalDSPs(); i++){
SetStreamType(ChannelHandle[i], streamType);
}
if(dlg.m_logoEnable){
int w,h;
unsigned char *bitsBuffer = (unsigned char *)malloc(128 * 128 * 2);
if(bitsBuffer == NULL)
return;
LoadYUVFromBmpFile("logo.bmp", bitsBuffer, 128 * 128 * 2, &w, &h);
for( i = 0; i < GetTotalDSPs(); i++){
SetLogo(ChannelHandle[i], 0, 110, 128, 128, (UCHAR *)bitsBuffer);
SetLogoDisplayMode(ChannelHandle[i], RGB(0,0,0),TRUE, 0);
}
free(bitsBuffer);
}else{
for( i = 0; i < GetTotalDSPs(); i++){
StopLogo(ChannelHandle[i]);
}
}
gFileSize = dlg.m_FileSize;
for( i = 0; i < GetTotalDSPs(); i++){
if(encodeType != ENC_4CIF_FORMAT)
{
StartVideoCapture(ChannelHandle[i]);
}
else if ((i%4==0)||(i%4==1))
{
StartVideoCapture(ChannelHandle[i]);
}
}
}
}
void CHKVisionDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent == 1)
{
for(int i = 0; i < GetTotalDSPs(); i++){
if(!GetVideoSignal(ChannelHandle[i])){
CheckDlgButton(IDC_CHECK2 + i, BST_CHECKED);
}else{
// TRACE("Channel%d Video lost !\n", i);
CheckDlgButton(IDC_CHECK2 + i, BST_UNCHECKED);
}
}
}
else if (nIDEvent == 2)
{
CString str;
WORD num;
MP4_ServerGetState(&num);
str.Format("%d",num);
GetDlgItem(IDC_FPS)->SetWindowText((LPCTSTR)str);
}
else if (nIDEvent == 10)
{
CaptureIFrame(ChannelHandle[0]);
}
//CPLAYER_API STATISTIC* __stdcall MP4_ServerGetStatistic(DWORD nChannel,int *returnnum);
CDialog::OnTimer(nIDEvent);
}
void CHKVisionDlg::OnCapimage()
{
// TODO: Add your control notification handler code here
}
void CHKVisionDlg::OnDestroy()
{
if (usframe)
KillTimer(usframe);
CDialog::OnDestroy();
}
void CHKVisionDlg::OnMyCommand(WPARAM wParam, LPARAM lParam)
{
if ((BYTE)wParam == GETSTRING)
{
char ts[1000];
char ips[30];
WORD tlen;
memset(ts,0,1000);
MP4_ServerReadLastMessage(ips,ts,&tlen);
sprintf(&(ts[tlen]),"\r\n");
AfxMessageBox(ts);
// TRACE(ts);
}
}
void CHKVisionDlg::OnButton5()
{
MP4_ServerCommandToClient(20,0);
}
void CHKVisionDlg::OnButton6()
{
char sendcont[500];
CString firstco;
firstco = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
int testnum=0;
MP4_ServerSetWait(3000,5);
UpdateData(TRUE);
// for(int i=0;i<100;i++)
{
memset(sendcont,0,500);
UpdateData(TRUE);
sprintf(sendcont,"%s send content %d",firstco,testnum);
testnum++;
if (testnum > 200)
testnum=0;
MP4_ServerStringToClient(m_ip,sendcont,400);
Sleep(100);
}
}
void CHKVisionDlg::OnButton7()
{
MP4_ServerResetChannel(1);
}
void CHKVisionDlg::OnButton8()
{
MP4_ServerStringToClient_other(0,"123456789",10);
}
void CHKVisionDlg::OnCapturesframe()
{
UpdateData(TRUE);
if (m_sframe)
{
usframe = SetTimer(10,1000,NULL);
}
else
{
if (usframe)
KillTimer(usframe);
}
}
void CHKVisionDlg::OnButton9()
{
if (chantype)
{
for(int i = 0; i < GetTotalDSPs(); i++)
{
StopVideoCapture(ChannelHandle[i]);
MP4_ServerChangeChanType(i,NORMAL);
SetIBPMode(ChannelHandle[i],211,2,2,25);
SetDefaultQuant(ChannelHandle[i],15,15,20);
SetEncoderPictureFormat(ChannelHandle[i], ENC_CIF_FORMAT);
StartVideoCapture(ChannelHandle[i]);
}
chantype = FALSE;
}
else
{
for(int i = 0; i < GetTotalDSPs(); i++)
{
StopVideoCapture(ChannelHandle[i]);
MP4_ServerChangeChanType(i,DIALING);
SetIBPMode(ChannelHandle[i],211,2,2,8);
SetDefaultQuant(ChannelHandle[i],18,18,23);
SetStreamType(ChannelHandle[i],STREAM_TYPE_VIDEO);
SetEncoderPictureFormat(ChannelHandle[i], ENC_QCIF_FORMAT);
StartVideoCapture(ChannelHandle[i]);
}
chantype = TRUE;
}
}
//typedef int (*STREAM_DIRECT_READ_CALLBACK)(ULONG channelNumber,void *DataBuf,DWORD Length,int FrameType,void *context);
int __cdecl StreamDirectReadCallback(ULONG channelNum,void *DataBuf,DWORD Length,int frameType,void *context)
{
int i,status=0;
CString ctip;
int nframetype =0;
// if cap images we need clean the queue here
// if (!bCapture)
// return 0;
// no errors
if(frameType > 0) {
if(frameType == PktSysHeader){
// store the file header
memcpy(FileHeader[channelNum], DataBuf, Length);
FileHeaderLen = Length;
TRACE("channel %d get the file header !\n",channelNum);
}
if(frameType == PktIFrames || frameType ==PktSubIFrames){
status = 1;
}
else{
status = 0;
}
if(frameType == PktMotionDetection){
// m_VideoWin.DrawVect(channelNum, (char *)DataBuf, 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;
CHKVisionDlg *pMain = (CHKVisionDlg *)AfxGetMainWnd();
pMain->GetDlgItem(IDC_BPS)->SetWindowText((LPCTSTR)str);
}
// if (m_sframe && channelNum ==0)
// {
// if((frameType == PktSFrames && nframetype ==4 )||(frameType == PktSysHeader))
// {
// MP4_ServerWriteData(channelNum,(unsigned char *)DataBuf, Length,frameType,status);
// }
// }
// MP4_ServerWriteData(channelNum,(unsigned char *)DataBuf, Length,frameType,status);
if(frameType ==PktAudioFrames)
{
_write(gFileHandleQcif[channelNum],DataBuf,Length);
MP4_ServerWriteDataEx(channelNum,(unsigned char *)DataBuf, Length,frameType,status,1);
_write(gFileHandle[channelNum], DataBuf, Length);
MP4_ServerWriteDataEx(channelNum,(unsigned char *)DataBuf, Length,frameType,status,0);
}else if (frameType ==PktSubIFrames || frameType ==PktSubPFrames || frameType == PktSubBBPFrames || frameType == PktSubSysHeader)
{
_write(gFileHandleQcif[channelNum],DataBuf,Length);
MP4_ServerWriteDataEx(channelNum,(unsigned char *)DataBuf, Length,frameType,status,1);
}else
{
_write(gFileHandle[channelNum], DataBuf, Length);
MP4_ServerWriteDataEx(channelNum,(unsigned char *)DataBuf, Length,frameType,status,0);
}
return 0;
}
void CHKVisionDlg::OnSubstart()
{
// TODO: Add your control notification handler code here
for(int i=0; i < GetTotalChannels(); i++)
{
char fileName[256];
sprintf(fileName,"d:\\streamqcif%d_%d.264",i,gFileNum++);
gFileHandleQcif[i]= _open(fileName,_O_CREAT|_O_BINARY|_O_WRONLY|_O_TRUNC,_S_IREAD|_S_IWRITE);
if(gFileHandleQcif[i] ==-1)
{
TRACE("file Open error!\n");
AfxMessageBox("can not open file!\n");
return ;
}
SetSubStreamType(ChannelHandle[i],STREAM_TYPE_AVSYNC);
SetSubEncoderPictureFormat(ChannelHandle[i],ENC_CIF_FORMAT);
SetupSubChannel(ChannelHandle[i],1);// switch to sub channel for setting
SetBitrateControlMode(ChannelHandle[i], brVBR );
SetupBitrateControl(ChannelHandle[i],2000000);
SetDefaultQuant(ChannelHandle[i], 16, 16, 18);
SetIBPMode(ChannelHandle[i],100,2,2,25);
StartSubVideoCapture(ChannelHandle[i]);
SetupSubChannel(ChannelHandle[i],0);//switch to main channel
}
GetDlgItem(IDC_SUBSTART)->EnableWindow(FALSE);
GetDlgItem(IDC_STOPSUBCAP)->EnableWindow(TRUE);
}
void CHKVisionDlg::OnStopsubcap()
{
// TODO: Add your control notification handler code here
for(int i=0; i < GetTotalChannels(); i++)
{
StopSubVideoCapture(ChannelHandle[i]);
}
GetDlgItem(IDC_SUBSTART)->EnableWindow(TRUE);
GetDlgItem(IDC_STOPSUBCAP)->EnableWindow(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -