Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. IPConfvidt.cpp
  5. Abstract:
  6. IPConf MSP implementation of vido capture terminal.
  7. Author:
  8. Zoltan Szilagyi (zoltans) September 6,1998
  9. Mu Han (muhan) June 6, 1999
  10. --*/
  11. #include "stdafx.h"
  12. CIPConfVideoCaptureTerminal::CIPConfVideoCaptureTerminal()
  13. {
  14. LOG((MSP_TRACE, "CIPConfVideoCaptureTerminal::CIPConfVideoCaptureTerminal"));
  15. m_TerminalClassID = CLSID_VideoInputTerminal;
  16. m_TerminalDirection = TD_CAPTURE;
  17. m_TerminalType = TT_STATIC;
  18. m_TerminalState = TS_NOTINUSE;
  19. m_dwMediaType = TAPIMEDIATYPE_VIDEO;
  20. }
  21. CIPConfVideoCaptureTerminal::~CIPConfVideoCaptureTerminal()
  22. {
  23. LOG((MSP_TRACE, "CIPConfVideoCaptureTerminal::~CIPConfVideoCaptureTerminal"));
  24. }
  25. HRESULT CIPConfVideoCaptureTerminal::CreateTerminal(
  26. IN char * strDeviceName,
  27. IN UINT VideoCaptureID,
  28. IN MSP_HANDLE htAddress,
  29. OUT ITTerminal **ppTerm
  30. )
  31. /*++
  32. Routine Description:
  33. This method creates a terminal object base to identify a video capture
  34. device.
  35. Arguments:
  36. strDeviceName - the name of the device.
  37. VideoCaptureID - the index of the device.
  38. htAddress - the handle to the address object.
  39. ppTerm - memory to store the returned terminal pointer.
  40. Return Value:
  41. S_OK
  42. --*/
  43. {
  44. ENTER_FUNCTION("CIPConfVideoCaptureTerminal::CreateTerminal");
  45. LOG((MSP_TRACE, "%s, htAddress:%x", __fxName, htAddress));
  46. _ASSERT(!IsBadWritePtr(ppTerm, sizeof(ITTerminal *)));
  47. HRESULT hr;
  48. // Create the filter.
  49. CMSPComObject<CIPConfVideoCaptureTerminal> *pTerminal = NULL;
  50. hr = ::CreateCComObjectInstance(&pTerminal);
  51. if (FAILED(hr))
  52. {
  53. LOG((MSP_ERROR,
  54. "%s can't create the terminal object hr = %8x", __fxName, hr));
  55. return hr;
  56. }
  57. // query for the ITTerminal interface
  58. ITTerminal *pITTerminal;
  59. hr = pTerminal->_InternalQueryInterface(
  60. __uuidof(ITTerminal), (void**)&pITTerminal
  61. );
  62. if (FAILED(hr))
  63. {
  64. LOG((MSP_ERROR,
  65. "%s, query terminal interface failed, %x", __fxName, hr));
  66. delete pTerminal;
  67. return hr;
  68. }
  69. // initialize the terminal
  70. hr = pTerminal->Initialize(
  71. strDeviceName,
  72. VideoCaptureID,
  73. htAddress
  74. );
  75. if ( FAILED(hr) )
  76. {
  77. LOG((MSP_ERROR,
  78. "%s, Initialize failed; returning 0x%08x", __fxName, hr));
  79. pITTerminal->Release();
  80. return hr;
  81. }
  82. LOG((MSP_TRACE, "%s, %s created", __fxName, strDeviceName));
  83. *ppTerm = pITTerminal;
  84. return S_OK;
  85. }
  86. HRESULT CIPConfVideoCaptureTerminal::Initialize(
  87. IN char * strName,
  88. IN UINT VideoCaptureID,
  89. IN MSP_HANDLE htAddress
  90. )
  91. /*++
  92. Routine Description:
  93. This function sets the video capture device ID and then calls the
  94. Initialize method of the base class.
  95. Arguments:
  96. strName - The name of the terminal.
  97. VideoCaptureID - The ID of the video capture device. Later it will be used
  98. in creating the video capture filer.
  99. htAddress - The handle that identifies the address object that this
  100. terminal belongs to.
  101. Return Value:
  102. S_OK
  103. --*/
  104. {
  105. m_VideoCaptureID = VideoCaptureID;
  106. return CIPConfBaseTerminal::Initialize(strName, htAddress);
  107. }
  108. HRESULT CIPConfVideoCaptureTerminal::CreateFilter(void)
  109. /*++
  110. Routine Description:
  111. This method creates the filter in this terminal. It creates the tapi video
  112. capture filter and configures the device it uses.
  113. Arguments:
  114. nothing.
  115. Return Value:
  116. S_OK
  117. --*/
  118. {
  119. ENTER_FUNCTION("CIPConfVideoCaptureTerminal::CreateFilters");
  120. LOG((MSP_TRACE, "%s, entered", __fxName));
  121. // This should only be called atmost once in the lifetime of this instance
  122. if (m_pFilter != NULL)
  123. {
  124. return S_OK;
  125. }
  126. IBaseFilter *pICaptureFilter;
  127. // Create the filter.
  128. HRESULT hr = CoCreateInstance(
  129. __uuidof(TAPIVideoCapture),
  130. NULL,
  131. CLSCTX_INPROC_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  132. __uuidof(IBaseFilter),
  133. (void **)&pICaptureFilter
  134. );
  135. if (FAILED(hr))
  136. {
  137. LOG((MSP_ERROR,
  138. "%s, CoCreate filter failed, %x", __fxName, hr));
  139. return hr;
  140. }
  141. // get the config interface.
  142. IVideoDeviceControl *pIVideoDeviceControl;
  143. hr = pICaptureFilter->QueryInterface(
  144. __uuidof(IVideoDeviceControl),
  145. (void **)&pIVideoDeviceControl
  146. );
  147. if (FAILED(hr))
  148. {
  149. pICaptureFilter->Release();
  150. LOG((MSP_ERROR,
  151. "%s, can't get the IVideoDeviceControl interface, %x",
  152. __fxName, hr));
  153. return hr;
  154. }
  155. // tell the filter the device IDs.
  156. hr = pIVideoDeviceControl->SetCurrentDevice(m_VideoCaptureID);
  157. pIVideoDeviceControl->Release();
  158. if (FAILED(hr))
  159. {
  160. pICaptureFilter->Release();
  161. LOG((MSP_ERROR,
  162. "%s, set device ID failed, %x", __fxName, hr));
  163. return hr;
  164. }
  165. // remember the filter, keep the refcount as well.
  166. m_pFilter = pICaptureFilter;
  167. LOG((MSP_TRACE, "%s succeeded", __fxName));
  168. return S_OK;
  169. }
  170. HRESULT CIPConfVideoCaptureTerminal::GetExposedPins(
  171. IN IPin ** ppPins,
  172. IN DWORD dwNumPins
  173. )
  174. /*++
  175. Routine Description:
  176. This method returns the output pins of the video capture filter.
  177. Arguments:
  178. ppPins - memory buffer to store the returned pins.
  179. dwNumPins - the number pins asked.
  180. Return Value:
  181. S_OK
  182. --*/
  183. {
  184. ENTER_FUNCTION("CIPConfVideoRenderTerminal::GetExposedPins");
  185. LOG((MSP_TRACE, "%s entered, dwNumPins:%d", __fxName, dwNumPins));
  186. _ASSERT(m_pFilter != NULL);
  187. _ASSERT(dwNumPins != 0);
  188. _ASSERT(!IsBadWritePtr(ppPins, sizeof (IPin*) * dwNumPins));
  189. // Get the enumerator of pins on the filter.
  190. IEnumPins * pIEnumPins;
  191. HRESULT hr = m_pFilter->EnumPins(&pIEnumPins);
  192. if (FAILED(hr))
  193. {
  194. LOG((MSP_ERROR,
  195. "%s enumerate pins on the filter failed. hr=%x", __fxName, hr));
  196. return hr;
  197. }
  198. // TODO: get only the outptu pins.
  199. // get the pins.
  200. DWORD dwFetched;
  201. hr = pIEnumPins->Next(dwNumPins, ppPins, &dwFetched);
  202. pIEnumPins->Release();
  203. if (FAILED(hr))
  204. {
  205. LOG((MSP_ERROR,
  206. "%s IEnumPins->Next failed. hr=%x", __fxName, hr));
  207. return hr;
  208. }
  209. _ASSERT(dwFetched == dwNumPins);
  210. return S_OK;
  211. }