📄 demodlg.cpp
字号:
gCurrentFileLen[channelNum] -= gFileSize * 1000 * 1000;
}
if(bAlarmFileSave){
if(frameType == PktSysHeader)
_write(gFileHandle[channelNum], StreamBuf, length);
else if (bEncodeCifAndQcif[channelNum])
{
if (nframetype ==3 || nframetype ==5) ///add v34
alarmFile[channelNum].FramePush(gFileHandle[channelNum], StreamBuf, \
length, (FrameType_t)frameType, breakable);
}
else
{
alarmFile[channelNum].FramePush(gFileHandle[channelNum], StreamBuf, \
length, (FrameType_t)frameType, breakable);
}
}else {
if(frameType ==PktAudioFrames)
{
_write(gFileHandle[channelNum],StreamBuf,length);
_write(gFileHandleQcif[channelNum],StreamBuf,length);
}else if (frameType ==PktSubIFrames || frameType ==PktSubPFrames || frameType == PktSubBBPFrames || frameType == PktSubSysHeader)
{
_write(gFileHandleQcif[channelNum],StreamBuf,length);
}else
{
_write(gFileHandle[channelNum],StreamBuf,length);
}
}
// }while(length != 0);
return 0;
}
void CHKVisionDlg::OnSettings()
{
// TODO: Add your control notification handler code here
CSettingsDlg dlg;
int i=0;
USHORT Format1[] = {24, 240, _OSD_YEAR2, '-',_OSD_MONTH2,'-',_OSD_DAY,'-', _OSD_HOUR24, ':', _OSD_MINUTE,':', _OSD_SECOND, '\0'};
USHORT Format2[] = { 0, 0, 0x20, 0};
USHORT Format3[8][44] = {{2, 2, '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j',\
'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','\0'},
{2, 25, '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j',\
'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','\0'},
{2, 50, 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',\
'u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','\0'},
{2, 75, 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t',\
'u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','\0'},
{2, 100, _OSD_YEAR4, '-',_OSD_MONTH2,'-',_OSD_DAY,'-',_OSD_HOUR24,':',_OSD_MINUTE,':',_OSD_SECOND,'-',_OSD_MONTH3,'-',_OSD_WEEK3,'星','期',_OSD_CWEEK1,_OSD_HOUR12,'\0'},
{2, 125, 'h','a','n','g','z','h','o','u',' ','h','i','k','v','i','s','i','o','n', '\0'},
{2, 150, '杭','州','海','康','威','视','\0'},{2,175,'D','S','-','4','0','x','x','H','C','\0'}};
USHORT *Format4[8];
for(i=0;i<8;i++)
{
Format4[i]=Format3[i];
}
PictureFormat_t encodeType,subEncodeType ;
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);
if (dlg.m_iX >=0 && dlg.m_iY >=0)
SetInputVideoPosition(ChannelHandle[0],dlg.m_iX,dlg.m_iY);
//set main channel encode type
switch(dlg.m_iEncodeType)
{
case 0:
encodeType = ENC_CIF_FORMAT;
break;
case 1:
encodeType = ENC_4CIF_FORMAT;
break;
case 2:
encodeType = ENC_QCIF_FORMAT;
break;
case 3:
encodeType = ENC_2CIF_FORMAT;
break;
case 4:
encodeType = ENC_DCIF_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);
}
}
//set sub channel encode type
switch(dlg.m_iSubEncodeType)
{
case 0:
subEncodeType = ENC_CIF_FORMAT;
break;
case 1:
subEncodeType = ENC_4CIF_FORMAT;
break;
case 2:
subEncodeType = ENC_QCIF_FORMAT;
break;
case 3:
subEncodeType = ENC_2CIF_FORMAT;
break;
case 4:
subEncodeType = ENC_DCIF_FORMAT;
break;
default:
subEncodeType = ENC_CIF_FORMAT;
break;
}
for(i = 0; i < GetTotalDSPs(); i++)
{
SetSubEncoderPictureFormat(ChannelHandle[i],subEncodeType);
}
// setup quant value
for(i = 0; i < GetTotalDSPs(); i++)
{
SetDefaultQuant(ChannelHandle[i], dlg.m_iQuant, dlg.m_pQuant, dlg.m_bQuant);
}
if(dlg.m_OsdEnable){
for(i = 0; i < GetTotalDSPs(); i++){
SetOsdDisplayMode(ChannelHandle[i], 255, TRUE, 1, Format1, Format2);
// show osd with 8 rows
// SetOsdDisplayModeEx(ChannelHandle[i], 255, TRUE, 1, 8, Format4);
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 > 30) || (dlg.m_FrameRate <=0))
dlg.m_FrameRate = 30;
for( i = 0; i < GetTotalDSPs(); i++){
SetIBPMode(ChannelHandle[i], dlg.m_IFramesIntervals, 2, 1, dlg.m_FrameRate);
}
}
bAlarmFileSave = FALSE;
if(dlg.m_MotionDetect){
bAlarmFileSave = TRUE;
for( i = 0; i < GetTotalDSPs(); i++){
// user may dynamicly adjust motion detect precisions
//将运动分析灵敏度等级与0x80000000做或操作,启动自适应设置
VideoStandard_t videostandard;
int bright,constrast,sat,hue;
int bHeight;
GetVideoPara(ChannelHandle[i],&videostandard,&bright,&constrast,&sat,&hue);
AdjustMotionDetectPrecision(ChannelHandle[i], 0x80000000|(dlg.m_motionDetectPrec), 2, 0);
if(videostandard==1)
{
bHeight=480;
}
else
{
bHeight=576;
}
RECT areaList[4];
areaList[0].top = 0; areaList[0].left = 0;
areaList[0].right = 704/2; areaList[0].bottom = bHeight/2;
areaList[1].top = 0; areaList[1].left = 704/2;
areaList[1].right = 703; areaList[1].bottom = bHeight/2;
areaList[2].top = bHeight/2; areaList[2].left = 0;
areaList[2].right = 704/2; areaList[2].bottom = bHeight-1;
areaList[3].top = bHeight/2; areaList[3].left = 704/2;
areaList[3].right = 703; areaList[3].bottom = bHeight-1;
SetupMotionDetection(ChannelHandle[i], areaList, 4);
StartMotionDetection(ChannelHandle[i]);
}
}else{
for( i = 0; i < GetTotalDSPs(); i++){
StopMotionDetection(ChannelHandle[i]);
m_bMoving[i] = FALSE;
}
}
if(dlg.m_bMask)
{
int j;
RECT areaList[32];
for(i = 0; i < 4; i++)
for(j =0; j <8; j++)
{
areaList[i*8+j].left = (3*j+1)*16 +200;
areaList[i*8+j].top = (3*i+1)*16 +200;
areaList[i*8+j].right = (3*j+1)*16 + 32 +200;
areaList[i*8+j].bottom = (3*i+1)*16 + 16 +200;
}
for(i = 0; i < GetTotalDSPs(); i++)
SetupMask(ChannelHandle[i],areaList, 32);
}
else
{
for(i = 0; i < GetTotalDSPs(); i++)
StopMask(ChannelHandle[i]);
}
USHORT streamType = STREAM_TYPE_AVSYNC;
switch(dlg.m_StreamType){
case 0:
streamType = STREAM_TYPE_VIDEO;
break;
case 1:
streamType = STREAM_TYPE_AUDIO;
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;
if (LoadYUVFromBmpFile("logo.bmp", bitsBuffer, 128 * 128 * 2, &w, &h))
{
AfxMessageBox("logo.bmp not exsit!\n");
return;
}
for( i = 0; i < GetTotalDSPs(); i++){
SetLogo(ChannelHandle[i], 0, 0, w, h, (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++){
SetBitrateControlMode(ChannelHandle[i], dlg.m_CBR ? brCBR : brVBR);
}
if(dlg.m_Max_bps > 10000){
for( i = 0; i < GetTotalDSPs(); i++){
SetupBitrateControl(ChannelHandle[i], dlg.m_Max_bps);
}
}else{
for( i = 0; i < GetTotalDSPs(); i++){
SetupBitrateControl(ChannelHandle[i], 0);
}
}
}
}
static DWORD dwNum =0;
void CHKVisionDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// 10 seconds
static int bitrateControlInterval = 10;
static LARGE_INTEGER lastLen[MAX_CHANNELS];
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);
// }
// }
ULONG Bps = ((gChannelTotalLength[iLastSelect].QuadPart -
lastLen[iLastSelect].QuadPart)/1000 ) * 8;
lastLen[iLastSelect].QuadPart = gChannelTotalLength[iLastSelect].QuadPart;
CString strBps ;
// strBps.Format("%d", Bps);
// GetDlgItem(IDC_BPS)->SetWindowText((LPCTSTR)strBps);
CString str;
FRAMES_STATISTICS fs;
GetFramesStatistics(ChannelHandle[iLastSelect], &fs);
strBps.Format("%d",fs.CurBps/1024);
GetDlgItem(IDC_BPS)->SetWindowText((LPCTSTR)strBps);
if(fs.FramesLost || fs.QueueOverflow){
if((gChannelFramesLost[iLastSelect] != fs.FramesLost)||
(gChannelOverflow[iLastSelect] != fs.QueueOverflow)){
LogWrite("ch%d frame errors:%d-%d\r\n", iLastSelect, fs.FramesLost, fs.QueueOverflow);
gChannelFramesLost[iLastSelect] = fs.FramesLost;
gChannelOverflow[iLastSelect] = fs.QueueOverflow;
}
if(iLastSelect != -1){
GetFramesStatistics(ChannelHandle[iLastSelect], &fs);
str.Format("%d-%d", fs.FramesLost, fs.QueueOverflow);
}else {
GetFramesStatistics(ChannelHandle[0], &fs);
str.Format("%d-%d", fs.FramesLost, fs.QueueOverflow);
}
GetDlgItem(IDC_LOST_FRAMES)->SetWindowText((LPCTSTR)str);
}
ULONG currentTime = timeGetTime();
str.Format("%d", fs.VideoFrames + fs.AudioFrames);
GetDlgItem(IDC_IFRAMES)->SetWindowText((LPCTSTR)str);
ULONG s = (currentTime - StartTime)/1000;
if(s != 0){
str.Format("%2.1f-%2.1f", (float)fs.AudioFrames/s, (float)fs.VideoFrames/s);
GetDlgItem(IDC_FPS)->SetWindowText((LPCTSTR)str);
}
// TRACE("slevel=%d\n", GetSoundLevel(ChannelHandle[iLastSelect]));
}
else if (nIDEvent ==1010)
{
int iArea;
int iDecNum=0;
if(m_bSwitchMetrix)
{
dwNum ++;
if ( dwNum %5==0)
iArea =1;
else if (dwNum %5 ==1)
iArea =4;
else if (dwNum %5 ==2)
iArea =16;
else if (dwNum %5 ==3)
iArea =2;
else if (dwNum %5 ==4)
iArea =3;
}
SetupRegion(iDecNum,iArea);
}
CDialog::OnTimer(nIDEvent);
}
static int itimes = 0;
void CHKVisionDlg::OnCapimage()
{
// TODO: Add your control notification handler code here
UCHAR imageBuf[704 * 576*2];
DWORD Size = 704 * 576*2;
UCHAR *imageBuffer=new UCHAR[Size];
char fileName[256];
CTime m_StartTime1=CTime::GetCurrentTime();
CString csStartTime=m_StartTime1.Format("%Y%m%d%H%M%S");
int ret;
int jpegQuality=100;
{
//capture BMP picture
TRACE("start original image cap\n");
sprintf(fileName, "ch%02d_%s.bmp", iLastSelect,csStartTime);
GetOriginalImage(ChannelHandle[iLastSelect], imageBuf, &Size);
if(Size == 704 *576 * 2)
SaveYUVToBmpFile(fileName, imageBuf, 704, 576);
else if(Size == 704 * 480* 2)
SaveYUVToBmpFile(fileName, imageBuf, 704, 480);
if(Size == 352 *288 * 2)
SaveYUVToBmpFile(fileName, imageBuf, 352, 288);
else if(Size == 352 * 240* 2)
SaveYUVToBmpFile(fileName, imageBuf, 352, 240);
if(Size == 176 *144 * 2)
SaveYUVToBmpFile(fileName, imageBuf, 176, 144);
else if(Size == 176 * 120* 2)
SaveYUVToBmpFile(fileName, imageBuf, 176, 120);
//capture jpg picture
if(!imageBuffer)
return;
Size = 704 * 576*2;
int ret=GetJpegImage(ChannelHandle[iLastSelect],imageBuffer,&Size,jpegQuality);
if(ret==0)
{
CString str;
str.Format("ch%02d_%s.jpg",iLastSelect,csStartTime);
FILE *pFile=fopen(str.GetBuffer(0),"wb");
if(pFile)
{
fwrite(imageBuffer,Size,1,pFile);
fclose(pFile);
}
else
AfxMessageBox("Can not open JPEG file!");
}
else if(ret==ERR_OUTOF_MEMORY)
AfxMessageBox("Not enough memory to store bitstream! \n or \n Image is too complex!");
else if(ret==ERR_WAIT_TIMEOUT)
AfxMessageBox("System is too busy!");
delete []imageBuffer;
Sleep(10);
}
}
void CHKVisionDlg::OnAudioPreview()
{
// TODO: Add your control notification handler code here
if (bAudioPre) //close
{
GetDlgItem(IDC_AUDIO_PREVIEW)->SetWindowText("StartAuPre");
for(int i=0; i < GetTotalDSPs(); i++)
{
SetAudioPreview(ChannelHandle[i],FALSE);
}
bAudioPre = FALSE;
}
else
{
for(int i=0; i < GetTotalDSPs(); i++)
{
SetAudioPreview(ChannelHandle[i],FALSE);
}
SetAudioPreview(ChannelHandle[iLastSelect],TRUE);
GetDlgItem(IDC_AUDIO_PREVIEW)->SetWindowText("StopAuPre");
bAudioPre = TRUE;
}
}
void CHKVisionDlg::OnVideoPreview()
{
// TODO: Add your control notification handler code here
CSelectDSP selDialog;
selDialog.DSPPreset(m_bDspPreset, GetTotalDSPs());
m_VideoWin.CacRects(GetTotalDSPs());
if(selDialog.DoModal() == IDOK){
TRACE("SelectDSP:OK button clicked\n");
selDialog.GetDSPsChoiced(m_bDspPreset);
for(int i = 0; i < GetTotalDSPs(); i++){
if(m_bDspPreset[i])
::StartVideoPreview(ChannelHandle[i], /*GetDlgItem(IDC_VIDEOWIN)->m_hWnd*/m_hWnd, &rectList[i], FALSE, vdfYUV422Planar, 25);
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -