Leaked source code of windows server 2003
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.

341 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. msptrmvc.cpp
  5. Abstract:
  6. MSP base classes: implementation of video capture terminal.
  7. --*/
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. #include <amvideo.h>
  11. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  13. CVideoCaptureTerminal::~CVideoCaptureTerminal()
  14. {
  15. LOG((MSP_TRACE, "CVideoCaptureTerminal::~CVideoCaptureTerminal() finished"));
  16. }
  17. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  19. HRESULT CVideoCaptureTerminal::CreateTerminal(
  20. IN CComPtr<IMoniker> pMoniker,
  21. IN MSP_HANDLE htAddress,
  22. OUT ITTerminal **ppTerm
  23. )
  24. {
  25. USES_CONVERSION;
  26. LOG((MSP_TRACE, "CVideoCaptureTerminal::CreateTerminal - enter"));
  27. //
  28. // Validate the parameters
  29. //
  30. if ( MSPB_IsBadWritePtr(ppTerm, sizeof(ITTerminal *) ) )
  31. {
  32. LOG((MSP_ERROR, "CVideoCaptureTerminal::CreateTerminal : "
  33. "bad terminal pointer; returning E_POINTER"));
  34. return E_POINTER;
  35. }
  36. if ( IsBadReadPtr(pMoniker, sizeof(IMoniker) ) )
  37. {
  38. LOG((MSP_ERROR, "CVideoCaptureTerminal::CreateTerminal : "
  39. "bad moniker pointer; returning E_POINTER"));
  40. return E_POINTER;
  41. }
  42. *ppTerm = NULL;
  43. HRESULT hr;
  44. //
  45. // Get the name for this filter out of the property bag.
  46. //
  47. CComPtr<IPropertyBag> pBag;
  48. hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pBag);
  49. if (FAILED(hr))
  50. {
  51. LOG((MSP_ERROR,
  52. "CVideoCaptureTerminal::CreateTerminal (BindToStorage) - returning %8x", hr));
  53. return hr;
  54. }
  55. VARIANT var;
  56. var.vt = VT_BSTR;
  57. hr = pBag->Read(L"FriendlyName", &var, 0);
  58. if (FAILED(hr))
  59. {
  60. LOG((MSP_ERROR, "CVideoCaptureTerminal::CreateTerminal (IPropertyBag::Read) - returning %8x", hr));
  61. return hr;
  62. }
  63. //
  64. // Create the actual terminal object
  65. //
  66. CMSPComObject<CVideoCaptureTerminal> *pLclTerm = new CMSPComObject<CVideoCaptureTerminal>;
  67. if (pLclTerm == NULL)
  68. {
  69. LOG((MSP_ERROR, "CVideoCaptureTerminal::CreateTerminal returning E_OUTOFMEMORY"));
  70. return E_OUTOFMEMORY;
  71. }
  72. //
  73. // Save some stuff we'll need later
  74. //
  75. pLclTerm->m_pMoniker = pMoniker;
  76. lstrcpyn(pLclTerm->m_szName, OLE2T(var.bstrVal), MAX_PATH);
  77. SysFreeString(var.bstrVal);
  78. //
  79. // Finally get the ITTerminal interface that we were asked for.
  80. //
  81. hr = pLclTerm->_InternalQueryInterface(IID_ITTerminal, (void**)ppTerm);
  82. if ( FAILED(hr) )
  83. {
  84. LOG((MSP_ERROR, "CVideoCaptureTerminal::CreateTerminal - "
  85. "Internal QI failed; returning 0x%08x", hr));
  86. delete pLclTerm;
  87. return hr;
  88. }
  89. //
  90. // Finish initializing the terminal.
  91. //
  92. hr = pLclTerm->Initialize(CLSID_VideoInputTerminal,
  93. TAPIMEDIATYPE_VIDEO,
  94. TD_CAPTURE,
  95. htAddress
  96. );
  97. if ( FAILED(hr) )
  98. {
  99. LOG((MSP_ERROR, "CVideoCaptureTerminal::CreateTerminal - "
  100. "Initialize failed; returning 0x%08x", hr));
  101. (*ppTerm)->Release();
  102. return hr;
  103. }
  104. LOG((MSP_TRACE, "CVideoCaptureTerminal::CreateTerminal - exit S_OK"));
  105. return S_OK;
  106. }
  107. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  108. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  109. // Create the filters used by this terminal
  110. HRESULT CVideoCaptureTerminal::CreateFilters()
  111. {
  112. LOG((MSP_TRACE, "CVideoCaptureTerminal::CreateFilters() - enter"));
  113. //
  114. // If we already have the filter, just return S_OK.
  115. //
  116. if ( m_pIFilter != NULL )
  117. {
  118. LOG((MSP_TRACE, "CVideoCaptureTerminal::CreateFilters() - "
  119. "already have a filter - exit S_OK"));
  120. return S_OK;
  121. }
  122. //
  123. // Now make the filter.
  124. //
  125. HRESULT hr = m_pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&m_pIFilter);
  126. if ( FAILED(hr) )
  127. {
  128. // reset the filer interface - it's a CComPointer so this releases it
  129. m_pIFilter = NULL;
  130. LOG((MSP_ERROR, "CVideoCaptureTerminal::CreateFilters() - "
  131. "BindToObject failed - exit 0x%08x", hr));
  132. return hr;
  133. }
  134. LOG((MSP_TRACE, "CVideoCaptureTerminal::CreateFilters() - exit S_OK"));
  135. return S_OK;
  136. }
  137. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  138. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  139. HRESULT
  140. CVideoCaptureTerminal::FindCapturePin(
  141. )
  142. {
  143. LOG((MSP_TRACE, "CVideoCaptureTerminal::FindCapturePin() - enter"));
  144. if ( m_pIPin != NULL )
  145. {
  146. LOG((MSP_INFO, "CVideoCaptureTerminal::FindCapturePin() - "
  147. "already called, so we already have a pin - exit S_OK"));
  148. return S_OK;
  149. }
  150. HRESULT hr;
  151. CComPtr<IEnumPins> pIEnumPins;
  152. ULONG cFetched;
  153. //
  154. // Find the capture pin for the filter.
  155. //
  156. if (FAILED(hr = m_pIFilter->EnumPins(&pIEnumPins)))
  157. {
  158. LOG((MSP_ERROR,
  159. "CVideoCaptureTerminal::FindCapturePin - can't enum pins %8x",
  160. hr));
  161. return hr;
  162. }
  163. IPin * pIPin;
  164. // Enumerate all the pins and break on the
  165. // first pin that meets requirement.
  166. for (;;)
  167. {
  168. if (pIEnumPins->Next(1, &pIPin, &cFetched) != S_OK)
  169. {
  170. LOG((MSP_ERROR,
  171. "CVideoCaptureTerminal::FindCapturePin - can't get a pin %8x",
  172. hr));
  173. return (hr == S_FALSE) ? E_FAIL : hr;
  174. }
  175. if (0 == cFetched)
  176. {
  177. LOG((MSP_ERROR, "CVideoCaptureTerminal::FindCapturePin - got zero pins"));
  178. return E_FAIL;
  179. }
  180. PIN_DIRECTION dir;
  181. if (FAILED(hr = pIPin->QueryDirection(&dir)))
  182. {
  183. LOG((MSP_ERROR,
  184. "CVideoCaptureTerminal::FindCapturePin - can't query pin direction %8x",
  185. hr));
  186. pIPin->Release();
  187. return hr;
  188. }
  189. if (PINDIR_OUTPUT == dir)
  190. {
  191. break;
  192. }
  193. pIPin->Release();
  194. }
  195. m_pIPin = pIPin;
  196. LOG((MSP_TRACE, "CVideoCaptureTerminal::FindCapturePin - exit S_OK"));
  197. return S_OK;
  198. }
  199. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  200. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  201. HRESULT
  202. CVideoCaptureTerminal::AddFiltersToGraph(
  203. )
  204. {
  205. LOG((MSP_TRACE, "CVideoCaptureTerminal::AddFiltersToGraph called"));
  206. if (m_pGraph == NULL)
  207. {
  208. LOG((MSP_ERROR, "CVideoCaptureTerminal::AddFiltersToGraph - "
  209. "no graph - exit E_UNEXPECTED"));
  210. return E_UNEXPECTED;
  211. }
  212. HRESULT hr;
  213. hr = CreateFilters();
  214. if ( FAILED(hr) )
  215. {
  216. LOG((MSP_ERROR, "CVideoCaptureTerminal::AddFiltersToGraph - "
  217. "CreateFilters failed - exit 0x%08x", hr));
  218. return hr;
  219. }
  220. //
  221. // Add the filter to the graph.
  222. //
  223. // A word about names:
  224. // If a filter has already been added with the same name (which will
  225. // happen if we have more than one video capture terminal in the same
  226. // graph) then that will return VFW_S_DUPLICATE_NAME, which is not
  227. // a failure.
  228. //
  229. try
  230. {
  231. USES_CONVERSION;
  232. hr = m_pGraph->AddFilter(m_pIFilter, T2CW(m_szName));
  233. }
  234. catch (...)
  235. {
  236. LOG((MSP_ERROR, "CVideoCaptureTerminal::AddFiltersToGraph - T2CW threw an exception - "
  237. "return E_OUTOFMEMORY"));
  238. return E_OUTOFMEMORY;
  239. }
  240. if ( FAILED(hr) )
  241. {
  242. LOG((MSP_ERROR, "CVideoCaptureTerminal::AddFiltersToGraph - "
  243. "AddFilter failed - exit 0x%08x", hr));
  244. return hr;
  245. }
  246. //
  247. // set the terminal's capture pin (output pin)
  248. //
  249. hr = FindCapturePin();
  250. if ( FAILED(hr) )
  251. {
  252. LOG((MSP_ERROR, "CVideoCaptureTerminal::AddFiltersToGraph - "
  253. "FindCapturePin failed - exit 0x%08x", hr));
  254. return hr;
  255. }
  256. LOG((MSP_TRACE, "CVideoCaptureTerminal::AddFiltersToGraph succeeded"));
  257. return S_OK;
  258. }
  259. // eof