用VFW,c++buider做视频传输,客户端在解压是ICDecompressBegin !=ICERR_OK是怎么回事呀?拜托高手指点指点呀。
客户端端
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ClientSocket1->Active=true;
memset(&m_CV,0,sizeof(COMPVARS));
m_CV.dwFlags=ICMF_COMPVARS_VALID;
m_CV.cbSize=sizeof(m_CV);
m_CV.fccHandler=mmioFOURCC('d','i','v','x');
m_CV.fccType=ICTYPE_VIDEO;
m_CV.hic=ICOpen(ICTYPE_VIDEO,mmioFOURCC('d','i','v','x'),ICMODE_COMPRESS);
m_CV.lDataRate=680;
m_CV.lFrame=0;
m_CV.lKey=15;
m_CV.lQ=ICQUALITY_DEFAULT;
dhic=ICOpen(ICTYPE_VIDEO,mmioFOURCC('d','i','v','x'),ICMODE_DECOMPRESS);
if (m_CV.hic!=NULL)
{
m_OutFormatSize=ICCompressGetFormatSize(m_CV.hic,&m_InInfo);
m_pOutInfo=(BITMAPINFO *)new BYTE[m_OutFormatSize];
ICCompressGetFormat(m_CV.hic,&m_InInfo,m_pOutInfo);
m_DOutFormatSize=ICDecompressGetFormatSize(dhic,m_pOutInfo);
m_pDOutInfo=(BITMAPINFO *)new BYTE[m_DOutFormatSize];
ICDecompressGetFormat(dhic,m_pOutInfo,m_pDOutInfo);
if(ICDecompressBegin(&m_CV,m_pOutInfo,m_pDOutInfo)!=ICERR_OK) //就在这里
ShowMessage("decompress isn't open");
}
}
//---------------------------------------
void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
Memo1->Lines->Add(ClientSocket1->Socket->ReceiveText());
//Form1->ClientSocket1->Socket->SendText("ri");
int size=ClientSocket1->Socket->ReceiveLength();
Form1->Caption="接收数据长度:"+IntToStr(size);
BYTE Buf1[410000]="";
ClientSocket1->Socket->ReceiveBuf(&Buf,size);
DWORD Result;
Result=ICDecompress(dhic,0,&m_pOutInfo->bmiHeader,&Buf,&m_pDOutInfo->bmiHeader,&Buf1);
if (Result==ICERR_OK)
{
HDC pDC=GetDC(Form1->GroupBox1->Handle);
StretchDIBits (pDC,0,0,GroupBox1->Width,GroupBox1->Height,
0,0,m_pDOutInfo->bmiHeader.biWidth,
m_pDOutInfo->bmiHeader.biHeight,&Buf1,m_pDOutInfo,
DIB_RGB_COLORS,SRCCOPY);
ReleaseDC(Form1->GroupBox1->Handle,pDC);
}
}
//---------------------------------------
void __fastcall TForm1::ClientSocket1Connect(TObject *Sender,
TCustomWinSocket *Socket)
{
Socket->SendText("hi server,i am connecting now") ;
}
//---------------------------------------
服务器端
void __fastcall TForm1::FormCreate(TObject *Sender)
{
m_InInfo.bmiHeader.biBitCount=24;
m_InInfo.bmiHeader.biClrImportant=m_InInfo.bmiHeader.biClrUsed=0; //
m_InInfo.bmiHeader.biCompression=BI_RGB;
m_InInfo.bmiHeader.biHeight=120;
m_InInfo.bmiHeader.biPlanes=1;
m_InInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
m_InInfo.bmiHeader.biSizeImage=0;
m_InInfo.bmiHeader.biWidth=160;
m_InInfo.bmiHeader.biXPelsPerMeter=m_InInfo.bmiHeader.biYPelsPerMeter=0;
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ServerSocket1->Active=true;
hWndC=capCreateCaptureWindow(
(LPSTR) "My Capture Window",WS_CHILD | WS_VISIBLE,0,0,
GroupBox1->Width,GroupBox1->Height,GroupBox1->Handle,0) ;
capDriverConnect(hWndC,0) ;
capSetVideoFormat(hWndC,&m_InInfo,sizeof(BITMAPINFO));
capPreviewRate(hWndC,25);
capPreview(hWndC,true);
capPreviewScale(hWndC,true);
char szCaptureFile[]="mycap.avi";
capFileSetCaptureFile(hWndC,szCaptureFile);
capFileAlloc(hWndC,(1024*1024L*5)) ;
capSetCallbackOnFrame(hWndC,FrameCallbackProc);
memset(&m_CV,0,sizeof(COMPVARS));
m_CV.dwFlags=ICMF_COMPVARS_VALID;
m_CV.cbSize=sizeof(m_CV);
m_CV.fccHandler=mmioFOURCC('d','i','v','x');//mmioFOURCC('d','i','v','3');
m_CV.fccType=ICTYPE_VIDEO;
m_CV.hic=ICOpen(ICTYPE_VIDEO,mmioFOURCC('d','i','v','x'),ICMODE_COMPRESS);
// m_CV.hic=ICOpen(ICTYPE_VIDEO,mmioFOURCC('d','i','v','x'),ICMODE_COMPRESS);
m_CV.lDataRate=780;
m_CV.lFrame=0;
m_CV.lKey=15;
m_CV.lQ=ICQUALITY_DEFAULT;
if (m_CV.hic!=NULL)
{ m_OutFormatSize=ICCompressGetFormatSize(m_CV.hic,&m_InInfo); ////////////////////////
m_pOutInfo=(BITMAPINFO *)new BYTE[m_OutFormatSize];
ICCompressGetFormat(m_CV.hic,&m_InInfo,m_pOutInfo);
ICCompressBegin(&m_CV,&m_InInfo,m_pOutInfo);
m_OutBufferSize=ICCompressGetSize(m_CV.hic,&m_InInfo,m_pOutInfo);
if (ICSeqCompressFrameStart(&m_CV,&m_InInfo))
ShowMessage("sucess iccompress");
else
ShowMessage("fail iccompress");
// if(ICDecompressBegin(m_CV.hic,m_pOutInfo,&m_InInfo)!=ICERR_OK)
// ShowMessage("fail decompress");
// else
// ShowMessage("sucess decompress");
}}
LRESULT CALLBACK FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)
{
DWORD bKeyFrame;
m_OutActSize=m_InInfo.bmiHeader.biSizeImage;
ICCompress(
m_CV.hic, 0, &m_pOutInfo->bmiHeader, Buf, &m_InInfo.bmiHeader, lpVHdr->lpData,
NULL, &bKeyFrame,lFrameNum++, lpVHdr->dwBufferLength,ICQUALITY_DEFAULT,NULL,NULL);
// m_OutActSize=m_InInfo.bmiHeader.biSizeImage;
if((Form1->ServerSocket1->Socket->ActiveConnections>0))
Form1->ServerSocket1->Socket->Connections[0]-> SendBuf(&Buf, m_OutActSize);
return (LRESULT)TRUE ;
}
//---------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
// capSetCallbackOnFrame(hWndC,FrameCallbackProc);
// memset(&m_CV,0,sizeof(COMPVARS));
// m_CV.dwFlags=ICMF_COMPVARS_VALID;
// m_CV.cbSize=sizeof(m_CV);
// m_CV.fccHandler=mmioFOURCC('d','i','v','3');//mmioFOURCC('d','i','v','3');
// m_CV.fccType=ICTYPE_VIDEO;
// m_CV.hic=ICOpen(ICTYPE_VIDEO,mmioFOURCC('d','i','v','3'),ICMODE_COMPRESS);
// m_CV.lDataRate=780;
// m_CV.lFrame=0;
// m_CV.lKey=15;
// m_CV.lQ=ICQUALITY_DEFAULT;
//if (m_CV.hic!=NULL)
//{ m_OutFormatSize=ICCompressGetFormatSize(m_CV.hic,&m_InInfo);
// m_pOutInfo=(BITMAPINFO *)new BYTE[m_OutFormatSize];
// ICCompressGetFormat(m_CV.hic,&m_InInfo,m_pOutInfo);
// ICCompressBegin(&m_CV,&m_InInfo,m_pOutInfo);
//}}
//LRESULT CALLBACK FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)
// {
// DWORD bKeyFrame;
// ICCompress(
// m_CV.hic, 0, &m_pOutInfo->bmiHeader, Buf, &m_InInfo.bmiHeader, lpVHdr->lpData,
// NULL, &bKeyFrame,lFrameNum++, lpVHdr->dwBufferLength,ICQUALITY_DEFAULT,NULL,NULL);
// m_OutActSize=m_pOutInfo->bmiHeader.biSizeImage;
/// if((Form1->ServerSocket1->Socket->ActiveConnections>0))
// Form1->ServerSocket1->Socket->Connections[0]->SendBuf(&Buf,m_OutActSize);
// return (LRESULT)TRUE ;
//
}
//---------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
capDriverDisconnect(hWndC);
if (m_CV.hic!=NULL)
{delete[] m_pOutInfo;
ICCompressEnd(&m_CV);
ICCompressorFree(&m_CV);
ICClose(m_CV.hic); }
}
//---------------------------------------
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
Memo1->Lines->Add(Socket->ReceiveText()) ;
}
//---------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
ServerSocket1->Socket->Connections[0]->SendText("hi client");
}
//---------------------------------------
[解决办法]
可以参看http://topic.csdn.net/u/20070324/20/75b11ad2-ca85-43af-994c-8013b2fff414.html
[解决办法]