VideoCapture.cpp
资源名称:网络视频电话系统.rar [点击查看]
上传用户:oldpeter23
上传日期:2013-01-09
资源大小:1111k
文件大小:3k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- //NetTalk
- /*------------------------------------------------------------------------------*
- =============================
- 模块名称: VideoCapture.cpp
- =============================
- [版权]
- 2000-2002 115软件工厂 版权所有
- *------------------------------------------------------------------------------*/
- #include "WndX.h"
- #include <vfw.h>
- #include "VideoCapture.h"
- #include "AVIOMgr.h"
- #pragma comment(lib,"vfw32")
- /*------------------------------------------------------------------------------*/
- CVideoCapture::CVideoCapture()
- {
- m_hWndCap = NULL;
- }
- /*------------------------------------------------------------------------------*/
- CVideoCapture::~CVideoCapture()
- {
- Destroy();
- }
- /*------------------------------------------------------------------------------*/
- BOOL CVideoCapture::Init()
- {
- BOOL bRet = FALSE;
- int i;
- Destroy();
- m_hWndCap=capCreateCaptureWindow(0,0,0,0,0,0,0,0);
- if(!m_hWndCap)
- goto RET;
- for(i=0;i<MAX_VFW_DEVICES;i++)
- m_DriverIndex[i]=-1;
- capSetUserData(m_hWndCap,this);
- bRet=TRUE;
- RET:
- return bRet;
- }
- /*------------------------------------------------------------------------------*/
- HWND CVideoCapture::GetCapWindow()
- {
- return m_hWndCap;
- }
- /*------------------------------------------------------------------------------*/
- VOID CVideoCapture::Destroy()
- {
- if (m_hWndCap)
- {
- if(IsWindow(m_hWndCap))
- capCaptureAbort(m_hWndCap);
- capSetCallbackOnVideoStream(m_hWndCap, NULL);
- DisconnectFromDriver();
- }
- DestroyWindow(m_hWndCap);
- m_hWndCap = NULL;
- }
- /*------------------------------------------------------------------------------*/
- //连接设备驱动
- BOOL CVideoCapture::ConnectToDriver(SHORT DriverIndex)
- {
- BOOL bRet = FALSE;
- CAPTUREPARMS CapParms = {0};
- if(DriverIndex>=MAX_VFW_DEVICES)
- {
- goto RET;
- }
- if (m_hWndCap==NULL||m_DriverIndex[DriverIndex]==-1)
- goto RET;
- capCaptureAbort(m_hWndCap);
- if(!capDriverConnect(m_hWndCap, m_DriverIndex[DriverIndex]))
- goto RET;
- capCaptureGetSetup(m_hWndCap,&CapParms,sizeof(CapParms));
- CapParms.vKeyAbort=0;
- CapParms.fAbortLeftMouse = FALSE;
- CapParms.fAbortRightMouse = FALSE;
- CapParms.fYield = TRUE;
- CapParms.fCaptureAudio=FALSE;
- CapParms.wPercentDropForError = 100;
- capCaptureSetSetup(m_hWndCap,&CapParms,sizeof(CapParms));
- bRet=TRUE;
- RET:
- return bRet;
- }
- /*------------------------------------------------------------------------------*/
- //得到设备数
- int CVideoCapture::GetDriverNum()
- {
- int iDriverNum=0;
- char achDeviceVersion[80] ;
- char achDeviceAndVersion[160] ;
- for(int i=0;i<MAX_VFW_DEVICES;i++)
- {
- if(capGetDriverDescription(i,
- achDeviceAndVersion,
- sizeof(achDeviceAndVersion),
- achDeviceVersion,
- sizeof(achDeviceVersion)))//buf fixed:the 24 param should not be null in win98
- {
- m_DriverIndex[iDriverNum]=(SHORT)i;
- iDriverNum++;
- }
- }
- return iDriverNum;
- }
- /*------------------------------------------------------------------------------*/
- //断开与驱动程序的连接
- BOOL CVideoCapture::DisconnectFromDriver()
- {
- BOOL bRet=FALSE;
- if(!m_hWndCap)
- goto RET;
- if(!capDriverDisconnect(m_hWndCap))
- goto RET;
- bRet=TRUE;
- RET:
- return bRet;
- }