请大家帮忙!有两个摄像头,然后经过编码器,集线器,再通过网络连接到我的网卡上,如何显示保存从局域网传过来的摄像头视频呢。请问如何用VC实现该功能呢。
请大家帮忙!有两个摄像头,然后经过编码器,集线器,再通过网络连接到我的网卡上,如何显示保存从局域网传过来的摄像头视频呢。请问如何用VC实现该功能呢。
我现在用socket接收数据。但保存的文件有不能播放的情况。不知道如何解决。请指教。谢谢。我主要代码如下:
if (WSAStartup(MAKEWORD(2,2),&wsd)!=0)
{
AfxMessageBox("failed!");
return;
}
if ((sock=WSASocket(AF_INET,SOCK_DGRAM,0,NULL,0,WSA_FLAG_MULTIPOINT_D_LEAF|WSA_FLAG_OVERLAPPED))==INVALID_SOCKET)
{
AfxMessageBox("socket failed");
WSACleanup();
return;
}
locall.sin_family=AF_INET;
locall.sin_port=htons(DuanKouHao);
locall.sin_addr.s_addr=INADDR_ANY;
if (bind(sock,(struct sockaddr*)&locall,sizeof(locall))==SOCKET_ERROR)
{
AfxMessageBox("bind failed");
closesocket(sock);
WSACleanup();
return;
}
remotee.sin_family=AF_INET;
remotee.sin_port=htons(DuanKouHao);
remotee.sin_addr.s_addr=inet_addr(DuoBoZuDiZi);
//if ((sockM=WSAJoinLeaf(sock,(SOCKADDR*)&remotee,sizeof(remotee),NULL,NULL,NULL,NULL,JL_BOTH))
if((sockM=WSAJoinLeaf(sock,(SOCKADDR*)&remotee,sizeof(remotee),NULL,NULL,NULL,NULL,JL_BOTH))==INVALID_SOCKET)
{
AfxMessageBox("WSAJoinleaf fail");
closesocket(sock);
WSACleanup();
return;
}
CString str;
int len=sizeof(struct sockaddr_in);
int ret;
int bufsize1=10000;
int i=0;
CString ips,tips;
tips='0';
CString fname="d:\\gg1.ts";
CFile file((LPCTSTR)fname,CFile::modeCreate|CFile::modeReadWrite);
while (i <2000)
{
if((ret=recvfrom(sock,recvbuf,BUFSIZ,0,(struct sockaddr*)&from,&len))==SOCKET_ERROR)
{
AfxMessageBox("rec failed");
ret=WSAGetLastError();
str.Format("ret=%d",ret);
AfxMessageBox(str);
closesocket(sockM);
closesocket(sock);
WSACleanup();
return;
}
file.Write((void *)(LPCTSTR)recvbuf,ret);
ips.Format("%s\n",inet_ntoa(from.sin_addr));
str=ips;
if (i==1999)
{//m_reclist.InsertString(0,"message from ip is:"+str+" mes:"+recvbuf);
m_reclist.InsertString(0,"message from ip is:"+str+" mes:"+recvbuf);
UpdateData();
}
tips=ips;
i++;
}
file.Close;