在客戶端相關的文章還沒有寫出來的時候,服務器端已經差不多了,沒有很及時的把文章一篇接一篇的寫是有理由的 ——有些功能我項目中暫時沒有加入,只是對照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);
}