C# 视频监控系列(8):服务器端——预览和可被客户端连接
2009-04-08 08:23:42 来源:WEB开发网前言
在客户端相关的文章还没有写出来的时候,服务器端已经差不多了,没有很及时的把文章一篇接一篇的写是有理由的——有些功能我项目中暂时没有加入,只是对照API知道有这个功能,边写文章边做例子,这样一来发现有些API封装的不对,所以把这系列的文章写的速度都放慢了,以求尽量每一篇文章都正确。当然还是免不了找借口说太忙,现在在写播放器部分的代码,进展目前看来还顺利: )
正文
一、VC++ Demo里关于这两个功能的实现和分析
基本上每段代码都可以从OnInitDialog这个方法开始分析
1.1. VC++ Code:
HikVisionDlg.cpp 的OnInitDialog方法中的关键代码
for(i = 0; i < GetTotalDSPs(); i++)
{
ChannelHandle[i] = ChannelOpen(i);
if (ChannelHandle[i]<0)
{
AfxMessageBox("channel open error > 0");
}
else if (ChannelHandle[i] ==(HANDLE) 0xffff)
{
AfxMessageBox("channel open error 0xffff");
}
gChannelTotalLength[i] = 0;
nowstate[i]=0;
if (servertype == DIALTYPE)
{
SetIBPMode(ChannelHandle[i],211,2,1,8);
SetDefaultQuant(ChannelHandle[i],18,18,23);
SetStreamType(ChannelHandle[i],STREAM_TYPE_VIDEO);
}
else
{
SetIBPMode(ChannelHandle[i],100,2,1,25);
SetDefaultQuant(ChannelHandle[i],15,15,20);
}
}
if (servertype == DIALTYPE)
{
for(i = 0; i < GetTotalDSPs(); i++)
SetEncoderPictureFormat(ChannelHandle[i], ENC_QCIF_FORMAT);
}
else
{
for(i = 0; i < GetTotalDSPs(); i++)
{
if ( i==0 )
{
//when initiated,set the first channel as 4CIF encode,others as CIF
SetEncoderPictureFormat(ChannelHandle[0], ENC_4CIF_FORMAT);
bEncodeCifAndQcif[0] = FALSE;
}
else
{
SetEncoderPictureFormat(ChannelHandle[i], ENC_CIF_FORMAT);
}
}
}
// int id = IDC_CHECK2;
// for(i = 0; i < MAX_CHANNELS; i++){
// GetDlgItem(id + i)->EnableWindow(FALSE);
// }
RegisterStreamDirectReadCallback(::StreamDirectReadCallback,this);
RegisterMessageNotifyHandle(m_hWnd, MsgDataReady);
MP4_ServerSetMessage(WM_MYCOMMAND,this->m_hWnd);
gCapImages = 0;
SetOverlayColorKey(gBackgroundColor);
gTimer = SetTimer(1, 1000, 0);
SetTimer(2,2000,0);
SetTimer(5,5000,0);
for (i=0;i<MAX_CHANNELS;i++)
gCurrentFileLen[i] = 0;
SERVER_VIDEOINFO videoinfo;
g_nChannelTotal = GetTotalDSPs();
for( i=0 ; i < g_nChannelTotal; i++ )
{
if(i == 0)
{
MP4_ServerSetBufNum(i,90);
}
else
{
MP4_ServerSetBufNum(i,80);
}
if (servertype == DIALTYPE)
videoinfo.m_datatype[i] = DIALING;
else
videoinfo.m_datatype[i] = NORMAL;
}
videoinfo.m_datatype[0] = SMALLPIC;
videoinfo.m_channum = g_nChannelTotal;
videoinfo.m_waittime = 2;
MP4_ServerSetStart(StartCap);
MP4_ServerSetStop(StopCap);
MP4_ServerSetIBPMode(SetIBP);
MP4_ServerSetCapIFrame(MakeIFrame);
MP4_ServerSetTTL(64);
MP4_ServerSetNetPort(5050,6050);
MP4_ServerCheckIP(CheckIP);
MP4_ServerCheckPassword(checkpassword);
//set the max connector of channel 0
MP4_ServerMaxUser(0,24);
//如果想不使用缺省方式进行多播,
//可以调用下面的函数设置自己的多播信息
//详细信息请参考SDK文档
// MP4_ServerCastGroup(TRUE,0,"228.0.0.132",9988);
if (!MP4_ServerStart(&videoinfo))
{
MessageBox("error","error",MB_OK);
}
更多精彩
赞助商链接