📄 vddlg.cpp
字号:
// f.Write(test,4);
// f.Write(" ",6);
// buf[RecieveLen] = NULL;
// Copy the message to a CString
// strre = buf;
// m_re.SetWindowText(strre);
if(RecieveLen==4)
{
// memcpy(bufsend+4*sizeof(DWORD)+FrameSize,&dTime,sizeof(WORD));
decodesize=atoi(buf);
// temp=buf[0]; decodesize=temp;
// temp=buf[1]; decodesize=decodesize+(temp<<8);
// temp=buf[2]; decodesize=decodesize+(temp<<16);
// temp=buf[3]; decodesize=decodesize+(temp<<24);
// f.Write(&decodesize,4);
currentsize=0;
}
else
{
//
memcpy(DecodeSrc+currentsize,buf,RecieveLen);
currentsize=currentsize+RecieveLen;
if (currentsize >= decodesize)
{
// f.Write(decodesrc,decodesize);
// if(IsDlgButtonChecked(IDC_RGB888))
// SetVideoFormat(888);
// if(IsDlgButtonChecked(IDC_RGB555)) SetVideoFormat(555);
// if(IsDlgButtonChecked(IDC_RGB565)) SetVideoFormat(565);
// GetDlgItem(IDC_PLAY)->EnableWindow(TRUE);
pFilePlayThread = AfxBeginThread(FilePlayThreadProc, NULL);
pFilePlayThread->m_bAutoDelete = TRUE;
}
}
// DecodeOneFrame(decodesize);
/* char *pBuf = new char[163840];//[1025];
int iBufSize = 163840;//1024;
int iRcvd,iRcvd1;
CString strRecvd,strre,host;
UINT port;
iRcvd = m_ss.ReceiveFrom(pBuf, iBufSize,host,port);
MPEGDEC_PlayStream ((unsigned char *)pBuf, iRcvd);
delete pBuf;
*/
}
void CVdDlg::OnBind()
{
// TODO: Add your control notification handler code here
//UINT m_iPort=4000;
UpdateData(TRUE);
if(!m_ss.Create(m_localport, SOCK_DGRAM, FD_READ|FD_WRITE|FD_OOB))
{//套接字创建失败
//delete m_ss;
// m_ss = NULL;
// return -3;
}
CString name="wang";
m_ss.Bind(m_localport,name);
}
//DEL void CVdDlg::Oninit()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL RECT m_rOutputArea;
//DEL m_rOutputArea.left =1;
//DEL m_rOutputArea.top =1;
//DEL m_rOutputArea.right=176;
//DEL m_rOutputArea.bottom=144;
//DEL MPEGDEC_InitStream (this->m_hWnd, m_rOutputArea);
//DEL
//DEL }
void CVdDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
////////////////////////////////////
// BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biWidth = VideoW;
bmi.bmiHeader.biHeight = VideoH;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biWidth*bmi.bmiHeader.biHeight*bmi.bmiHeader.biPlanes*bmi.bmiHeader.biBitCount/8;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
/////////////////////////////////////
if(!InitEncoder((BYTE **)&CodeSrc, (BYTE **)&CodeDest, VideoW, VideoH))
return;
SetCompressRatio(ratio);
SetVideoFormat(888);
if(!InitDecoder((BYTE **)&DecodeSrc,(BYTE **)&DecodeDest,VideoW,VideoH))
return;
hMainWnd =m_hWnd;
// TODO: Add your message handler code here
vdlg=this;
// MessageBox("ok");
UpdateData(TRUE);
SetCursor(LoadCursor(NULL, IDC_WAIT));
hCapWnd = capCreateCaptureWindow((LPSTR)"Capture Window",
WS_CHILD | WS_VISIBLE,
16, 86, VideoW, VideoH,
m_hWnd, (int) 0) ;
FARPROC fpVideoCallback = MakeProcInstance((FARPROC)VideoCallbackProc, m_hInstance);
capSetCallbackOnVideoStream(hCapWnd, fpVideoCallback);
if(!capDriverConnect(hCapWnd, 0))
MessageBox("Error! Not found video card!");
ZeroMemory(&m_biInput, sizeof(BITMAPINFO));
m_biInput.bmiHeader.biSize = sizeof(BITMAPINFO);
m_biInput.bmiHeader.biWidth = VideoW;
m_biInput.bmiHeader.biHeight = VideoH;
m_biInput.bmiHeader.biPlanes = 1;
m_biInput.bmiHeader.biBitCount = 16;
m_biInput.bmiHeader.biCompression = BI_RGB;
m_biInput.bmiHeader.biSizeImage = VideoW * VideoH * m_biInput.bmiHeader.biBitCount / 8;
m_biInput.bmiHeader.biXPelsPerMeter = 0;
m_biInput.bmiHeader.biYPelsPerMeter = 0;
m_biInput.bmiHeader.biClrUsed = 0;
m_biInput.bmiHeader.biClrImportant = 0;
capSetVideoFormat(hCapWnd, &m_biInput, sizeof(m_biInput));
CAPTUREPARMS CapParam;
capCaptureGetSetup(hCapWnd, &CapParam, sizeof(CapParam));
CapParam.fAbortLeftMouse = FALSE;
CapParam.fAbortRightMouse = FALSE;
CapParam.fYield = TRUE;
CapParam.dwRequestMicroSecPerFrame = 1000000/25; //25 FPS
capCaptureSetSetup(hCapWnd, &CapParam, sizeof(CapParam));
capOverlay(hCapWnd, TRUE);
// capPreview(hCapWnd, TRUE);
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
LRESULT FAR PASCAL VideoCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)
{
char s[120];
int num,i,remain;
wsprintf(s, "%ld", FrameNo++);
SetDlgItemText(hMainWnd, IDC_CAPFRAME, s);
unsigned char *bufsend;
char bsend[5];
if(1)
{
//fwrite(lpVHdr->lpData, lpVHdr->dwBytesUsed, 1, fpCode);
memcpy(CodeSrc, lpVHdr->lpData, lpVHdr->dwBytesUsed);
// DWORD FrameSize;
// if(FrameNo%50==1)
FrameSize = EncodeOneIntra();
// else FrameSize = EncodeOneInter();
// fwrite(&FrameSize, sizeof(DWORD), 1, fpCode);
// fwrite(CodeDest, FrameSize, 1, fpCode);
//f.Write(&FrameSize, sizeof(DWORD));
// f.Write(CodeDest, FrameSize);
// sprintf(bsend,"%d",FrameSize);
_itoa(FrameSize,bsend,10);
// unsigned long a=170;
//f.Write(bsend,4);
// DWORD a=1234;
// _ltoa(a,bsend,10);
// f.Write(bsend,4);
//f.Write(bsend,4);
// bsend[0]=FrameSize & 0xFF;
// bsend[1]=(FrameSize>>8) & 0xFF;
// bsend[2]=(FrameSize>>16) & 0xFF;
// bsend[3]=(FrameSize>>24) & 0xFF;
//memcpy(bsend,&FrameSize,sizeof(DWORD));
vdlg->m_ss.SendTo(LPCTSTR(bsend), 4,vdlg->m_remoteport,vdlg->m_remotepc);
//memcpy(bufsend,CodeDest,FrameSize);
bufsend=CodeDest;
/* time2 = GetTickCount();
WORD dTime = WORD(time2-time1);
//fwrite(&dTime, sizeof(WORD), 1, fpCode);
f.Write(&dTime, sizeof(WORD));
// memcpy(bufsend+4*sizeof(DWORD)+FrameSize,&dTime,sizeof(WORD));
time1 = GetTickCount();
*/
//bufsend=CodeDest;
num=FrameSize/1024;
remain=FrameSize%1024;
for (i=0;i<num;i++)
{
int iSent;
iSent = vdlg->m_ss.SendTo(LPCTSTR(bufsend+i*1024), 1024,vdlg->m_remoteport,vdlg->m_remotepc);
// f.Write((bufsend+i*1024),1024);
}
if (remain>0)
vdlg->m_ss.SendTo(LPCTSTR(bufsend+i*1024), remain,vdlg->m_remoteport,vdlg->m_remotepc);
// f.Write((bufsend+i*1024),remain);
/*
time2 = GetTickCount();
WORD dTime = WORD(time2-time1);
//fwrite(&dTime, sizeof(WORD), 1, fpCode);
f.Write(&dTime, sizeof(WORD));
// memcpy(bufsend+4*sizeof(DWORD)+FrameSize,&dTime,sizeof(WORD));
time1 = GetTickCount();
*/
}
return (LRESULT)TRUE;
}
UINT FilePlayThreadProc(LPVOID pParam)
{
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biWidth = VideoW;
bmi.bmiHeader.biHeight = VideoH;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biWidth*bmi.bmiHeader.biHeight*bmi.bmiHeader.biPlanes*bmi.bmiHeader.biBitCount/8;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
// DWORD FrameSize, CurrentPlayFrameNo = 0;
// char s[120];
// DWORD PlayTime1, PlayTime2;
// WORD dTime;
// int delta;
HDC hDC = GetDC(hMainWnd);
// while(bFilePlay)
// {
//if(!fpDecode) break;
// if(feof(fpDecode)) break;
// CurrentPlayFrameNo++;
// wsprintf(s, "%d/%d", CurrentPlayFrameNo, PlayFrameNo);
// SetDlgItemText(hMainWnd, IDC_PLAYFRAME, s);
// if(CurrentPlayFrameNo>=PlayFrameNo) break;
// fread(&FrameSize, sizeof(DWORD), 1, fpDecode);
// fread(DecodeSrc, FrameSize, 1, fpDecode);
// fread(&dTime, sizeof(WORD), 1, fpDecode);
// PlayTime1 = GetTickCount();
DecodeOneFrame(decodesize);
SetDIBitsToDevice(hDC,
16+VideoW+116, 86, VideoW, VideoH,
0, 0, 0, VideoH,
DecodeDest, &bmi, 0);
/* PlayTime2 = GetTickCount();
delta = dTime+PlayTime1;
delta -= PlayTime2;
if(delta>0) Sleep(delta);*/
// }
ReleaseDC(hMainWnd, hDC);
return 0;
}
void CVdDlg::OnStop()
{
// TODO: Add your control notification handler code here
m_ss.Close();
}
void CVdDlg::OnCancel()
{
// TODO: Add extra cleanup here
capCaptureStop(hCapWnd);
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -