VideoCapture.cpp
上传用户:oldpeter23
上传日期:2013-01-09
资源大小:1111k
文件大小:3k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. //NetTalk
  2. /*------------------------------------------------------------------------------*
  3.  =============================
  4.    模块名称: VideoCapture.cpp
  5.  =============================
  6.  
  7.  [版权]
  8.  
  9.    2000-2002  115软件工厂  版权所有
  10.                                               
  11. *------------------------------------------------------------------------------*/
  12. #include "WndX.h"
  13. #include <vfw.h>
  14. #include "VideoCapture.h"
  15. #include "AVIOMgr.h"
  16. #pragma comment(lib,"vfw32")
  17. /*------------------------------------------------------------------------------*/
  18. CVideoCapture::CVideoCapture()
  19. {
  20. m_hWndCap = NULL;
  21. }
  22. /*------------------------------------------------------------------------------*/
  23. CVideoCapture::~CVideoCapture()
  24. {
  25. Destroy();
  26. }
  27. /*------------------------------------------------------------------------------*/
  28. BOOL CVideoCapture::Init()
  29. {
  30. BOOL bRet = FALSE;
  31. int i;
  32. Destroy();
  33. m_hWndCap=capCreateCaptureWindow(0,0,0,0,0,0,0,0);
  34. if(!m_hWndCap)
  35. goto RET;
  36. for(i=0;i<MAX_VFW_DEVICES;i++)
  37. m_DriverIndex[i]=-1;
  38. capSetUserData(m_hWndCap,this);
  39. bRet=TRUE;
  40. RET:
  41. return bRet;
  42. }
  43. /*------------------------------------------------------------------------------*/
  44. HWND CVideoCapture::GetCapWindow()
  45. {
  46. return m_hWndCap;
  47. }
  48. /*------------------------------------------------------------------------------*/
  49. VOID CVideoCapture::Destroy()
  50. {
  51. if (m_hWndCap)
  52. {
  53. if(IsWindow(m_hWndCap))
  54. capCaptureAbort(m_hWndCap);
  55. capSetCallbackOnVideoStream(m_hWndCap, NULL);
  56. DisconnectFromDriver();
  57. }
  58. DestroyWindow(m_hWndCap);
  59. m_hWndCap = NULL;
  60. }
  61. /*------------------------------------------------------------------------------*/
  62. //连接设备驱动
  63. BOOL CVideoCapture::ConnectToDriver(SHORT DriverIndex)
  64. {
  65. BOOL bRet = FALSE;
  66. CAPTUREPARMS CapParms = {0};
  67. if(DriverIndex>=MAX_VFW_DEVICES)
  68. {
  69. goto RET;
  70. }
  71. if (m_hWndCap==NULL||m_DriverIndex[DriverIndex]==-1)
  72. goto RET;
  73. capCaptureAbort(m_hWndCap);
  74. if(!capDriverConnect(m_hWndCap, m_DriverIndex[DriverIndex]))
  75. goto RET;
  76. capCaptureGetSetup(m_hWndCap,&CapParms,sizeof(CapParms));
  77. CapParms.vKeyAbort=0;
  78. CapParms.fAbortLeftMouse = FALSE;
  79. CapParms.fAbortRightMouse = FALSE;
  80. CapParms.fYield = TRUE;
  81. CapParms.fCaptureAudio=FALSE;
  82. CapParms.wPercentDropForError = 100;
  83. capCaptureSetSetup(m_hWndCap,&CapParms,sizeof(CapParms));
  84. bRet=TRUE;
  85. RET:
  86. return bRet;
  87. }
  88. /*------------------------------------------------------------------------------*/
  89. //得到设备数
  90. int CVideoCapture::GetDriverNum()
  91. {
  92. int iDriverNum=0;
  93. char    achDeviceVersion[80] ;
  94.     char    achDeviceAndVersion[160] ;
  95. for(int i=0;i<MAX_VFW_DEVICES;i++)
  96. {
  97. if(capGetDriverDescription(i,
  98. achDeviceAndVersion,
  99. sizeof(achDeviceAndVersion),
  100.             achDeviceVersion,
  101. sizeof(achDeviceVersion)))//buf fixed:the 24 param should not be null in win98
  102. {
  103. m_DriverIndex[iDriverNum]=(SHORT)i;
  104. iDriverNum++;
  105. }
  106. }
  107. return iDriverNum;
  108. }
  109. /*------------------------------------------------------------------------------*/
  110. //断开与驱动程序的连接
  111. BOOL CVideoCapture::DisconnectFromDriver()
  112. {
  113. BOOL bRet=FALSE;
  114. if(!m_hWndCap)
  115. goto RET;
  116. if(!capDriverDisconnect(m_hWndCap))
  117. goto RET;
  118. bRet=TRUE;
  119. RET:
  120. return bRet;
  121. }