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.

612 lines
13 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. bgbase.cpp
  5. Abstract:
  6. Implementation of the base classes of the bridge filters.
  7. Author:
  8. Mu Han (muhan) 11/16/1998
  9. --*/
  10. #include "stdafx.h"
  11. CTAPIBridgeSinkInputPin::CTAPIBridgeSinkInputPin(
  12. IN CTAPIBridgeSinkFilter *pFilter,
  13. IN CCritSec *pLock,
  14. OUT HRESULT *phr
  15. )
  16. : CBaseInputPin(
  17. NAME("CTAPIBridgeSinkInputPin"),
  18. pFilter, // Filter
  19. pLock, // Locking
  20. phr, // Return code
  21. L"Input" // Pin name
  22. )
  23. {
  24. }
  25. #define MTU_SIZE 1450
  26. STDMETHODIMP CTAPIBridgeSinkInputPin::GetAllocatorRequirements(
  27. ALLOCATOR_PROPERTIES *pProperties
  28. )
  29. /*++
  30. Routine Description:
  31. This is a hint to the upstream RTP source filter about the buffers to
  32. allocate.
  33. Arguments:
  34. pProperties -
  35. Pointer to the allocator properties.
  36. Return Value:
  37. S_OK - success.
  38. E_FAIL - the buffer size can't fulfill our requirements.
  39. --*/
  40. {
  41. _ASSERT(pProperties);
  42. if (!pProperties)
  43. return E_POINTER;
  44. pProperties->cBuffers = 8;
  45. pProperties->cbAlign = 0;
  46. pProperties->cbPrefix = 0;
  47. pProperties->cbBuffer = MTU_SIZE;
  48. return NOERROR;
  49. }
  50. inline STDMETHODIMP CTAPIBridgeSinkInputPin::Receive(IN IMediaSample *pSample)
  51. {
  52. return ((CTAPIBridgeSinkFilter*)m_pFilter)->ProcessSample(pSample);
  53. }
  54. inline HRESULT CTAPIBridgeSinkInputPin::GetMediaType(IN int iPosition, IN CMediaType *pMediaType)
  55. {
  56. return ((CTAPIBridgeSinkFilter*)m_pFilter)->GetMediaType(iPosition, pMediaType);
  57. }
  58. inline HRESULT CTAPIBridgeSinkInputPin::CheckMediaType(IN const CMediaType *pMediaType)
  59. {
  60. return ((CTAPIBridgeSinkFilter*)m_pFilter)->CheckMediaType(pMediaType);
  61. }
  62. CTAPIBridgeSourceOutputPin::CTAPIBridgeSourceOutputPin(
  63. IN CTAPIBridgeSourceFilter *pFilter,
  64. IN CCritSec *pLock,
  65. OUT HRESULT *phr
  66. )
  67. : CBaseOutputPin(
  68. NAME("CTAPIBridgeSourceOutputPin"),
  69. pFilter, // Filter
  70. pLock, // Locking
  71. phr, // Return code
  72. L"Output" // Pin name
  73. )
  74. {
  75. }
  76. CTAPIBridgeSourceOutputPin::~CTAPIBridgeSourceOutputPin ()
  77. {
  78. }
  79. STDMETHODIMP
  80. CTAPIBridgeSourceOutputPin::NonDelegatingQueryInterface(
  81. IN REFIID riid,
  82. OUT PVOID* ppv
  83. )
  84. /*++
  85. Routine Description:
  86. Overrides CBaseOutputPin::NonDelegatingQueryInterface().
  87. The nondelegating interface query function. Returns a pointer to the
  88. specified interface if supported.
  89. Arguments:
  90. riid -
  91. The identifier of the interface to return.
  92. ppv -
  93. The place in which to put the interface pointer.
  94. Return Value:
  95. Returns NOERROR if the interface was returned, else E_NOINTERFACE.
  96. --*/
  97. {
  98. HRESULT hr;
  99. if (riid == __uuidof(IAMBufferNegotiation)) {
  100. return GetInterface(static_cast<IAMBufferNegotiation*>(this), ppv);
  101. }
  102. else if (riid == __uuidof(IAMStreamConfig)) {
  103. return GetInterface(static_cast<IAMStreamConfig*>(this), ppv);
  104. }
  105. return CBaseOutputPin::NonDelegatingQueryInterface(riid, ppv);
  106. }
  107. inline HRESULT CTAPIBridgeSourceOutputPin::GetMediaType(IN int iPosition, IN CMediaType *pMediaType)
  108. {
  109. return ((CTAPIBridgeSourceFilter*)m_pFilter)->GetMediaType(iPosition, pMediaType);
  110. }
  111. inline HRESULT CTAPIBridgeSourceOutputPin::CheckMediaType(IN const CMediaType *pMediaType)
  112. {
  113. return ((CTAPIBridgeSourceFilter*)m_pFilter)->CheckMediaType(pMediaType);
  114. }
  115. HRESULT CTAPIBridgeSourceOutputPin::DecideBufferSize(
  116. IMemAllocator *pAlloc,
  117. ALLOCATOR_PROPERTIES *pProperties
  118. )
  119. /*++
  120. Routine Description:
  121. This fuction is called during the process of deciding an allocator. We tell
  122. the allocator what we want. It is also a chance to find out what the
  123. downstream pin wants when we don't have a preference.
  124. Arguments:
  125. pAlloc -
  126. Pointer to a IMemAllocator interface.
  127. pProperties -
  128. Pointer to the allocator properties.
  129. Return Value:
  130. S_OK - success.
  131. E_FAIL - the buffer size can't fulfill our requirements.
  132. --*/
  133. {
  134. ENTER_FUNCTION("CTAPIBridgeSourceOutputPin::DecideBufferSize");
  135. BGLOG((BG_TRACE, "%s entered", __fxName));
  136. ALLOCATOR_PROPERTIES Actual;
  137. pProperties->cbBuffer = 1024;
  138. pProperties->cBuffers = 4;
  139. HRESULT hr = pAlloc->SetProperties(pProperties, &Actual);
  140. if (FAILED(hr))
  141. {
  142. return hr;
  143. }
  144. *pProperties = Actual;
  145. return S_OK;
  146. }
  147. HRESULT CTAPIBridgeSourceOutputPin::GetAllocatorProperties (OUT ALLOCATOR_PROPERTIES *pprop)
  148. {
  149. return ((CTAPIBridgeSourceFilter*)m_pFilter)->GetAllocatorProperties (pprop);
  150. }
  151. HRESULT CTAPIBridgeSourceOutputPin::SuggestAllocatorProperties (IN const ALLOCATOR_PROPERTIES *pprop)
  152. {
  153. return ((CTAPIBridgeSourceFilter*)m_pFilter)->SuggestAllocatorProperties (pprop);
  154. }
  155. HRESULT CTAPIBridgeSourceOutputPin::GetFormat (OUT AM_MEDIA_TYPE **ppmt)
  156. {
  157. return ((CTAPIBridgeSourceFilter*)m_pFilter)->GetFormat (ppmt);
  158. }
  159. HRESULT CTAPIBridgeSourceOutputPin::SetFormat (IN AM_MEDIA_TYPE *pmt)
  160. {
  161. return ((CTAPIBridgeSourceFilter*)m_pFilter)->SetFormat (pmt);
  162. }
  163. HRESULT CTAPIBridgeSourceOutputPin::GetNumberOfCapabilities (OUT int *piCount, OUT int *piSize)
  164. /*++
  165. Routine Description:
  166. Retrieves the number of stream capabilities structures for the compressor
  167. Arguments:
  168. piCount -
  169. Pointer to the number of stream capabilites structures
  170. piSize -
  171. Pointer to the size of the configuration structure.
  172. Return Value:
  173. TBD
  174. --*/
  175. {
  176. ENTER_FUNCTION ("CTAPIBridgeSourceOutputPin::GetNumberOfCapabilities");
  177. BGLOG ((BG_ERROR, "%s is not implemented", __fxName));
  178. return E_NOTIMPL;
  179. }
  180. HRESULT CTAPIBridgeSourceOutputPin::GetStreamCaps (IN int iIndex, OUT AM_MEDIA_TYPE **ppmt, BYTE *pSCC)
  181. /*++
  182. Routine Description:
  183. Obtains capabilites of a stream depending on which type of structure is
  184. pointed to in the pSCC parameter
  185. Arguments:
  186. iIndex -
  187. Index to the desired media type and capablity pair
  188. ppmt -
  189. Address of a pointer to an AM_MEDIA_TYPE structure
  190. pSCC -
  191. Pointer to a stream configuration structure
  192. Return Value:
  193. TBD
  194. --*/
  195. {
  196. ENTER_FUNCTION ("CTAPIBridgeSourceOutputPin::GetStreamCaps");
  197. BGLOG ((BG_ERROR, "%s is not implemented", __fxName));
  198. return E_NOTIMPL;
  199. }
  200. CTAPIBridgeSinkFilter::CTAPIBridgeSinkFilter(
  201. IN LPUNKNOWN pUnk,
  202. IN IDataBridge * pIDataBridge,
  203. OUT HRESULT *phr
  204. ) :
  205. CBaseFilter(
  206. NAME("CTAPIBridgeSinkFilter"),
  207. pUnk,
  208. &m_Lock,
  209. __uuidof(TAPIBridgeSinkFilter)
  210. ),
  211. m_pInputPin(NULL)
  212. {
  213. _ASSERT(pIDataBridge != NULL);
  214. m_pIDataBridge = pIDataBridge;
  215. m_pIDataBridge->AddRef();
  216. }
  217. CTAPIBridgeSinkFilter::~CTAPIBridgeSinkFilter()
  218. {
  219. _ASSERT(m_pIDataBridge != NULL);
  220. m_pIDataBridge->Release();
  221. if (m_pInputPin)
  222. {
  223. delete m_pInputPin;
  224. }
  225. }
  226. int CTAPIBridgeSinkFilter::GetPinCount()
  227. /*++
  228. Routine Description:
  229. Implements pure virtual CBaseFilter::GetPinCount().
  230. Get the total number of pins on this filter.
  231. Arguments:
  232. Nothing.
  233. Return Value:
  234. The number of pins.
  235. --*/
  236. {
  237. // There is only one pin on this filter.
  238. return 1;
  239. }
  240. CBasePin * CTAPIBridgeSinkFilter::GetPin(
  241. int n
  242. )
  243. /*++
  244. Routine Description:
  245. Implements pure virtual CBaseFilter::GetPin().
  246. Get the pin object at position n. n is zero based.
  247. Arguments:
  248. n -
  249. The index of the pin, zero based.
  250. Return Value:
  251. Returns a pointer to the pin object if the index is valid. Otherwise,
  252. NULL is returned. Note: the pointer doesn't add refcount.
  253. --*/
  254. {
  255. ENTER_FUNCTION("CTAPIBridgeSinkFilter::GetPin");
  256. BGLOG((BG_TRACE,
  257. "%s, pin number:%d", __fxName, n));
  258. if (n != 0)
  259. {
  260. // there is only one pin on this filter.
  261. return NULL;
  262. }
  263. HRESULT hr;
  264. CAutoLock Lock(m_pLock);
  265. if (m_pInputPin == NULL)
  266. {
  267. hr = S_OK; // hr may not be set in constructor
  268. m_pInputPin = new CTAPIBridgeSinkInputPin(this, &m_Lock, &hr);
  269. if (m_pInputPin == NULL)
  270. {
  271. BGLOG((BG_ERROR, "%s, out of memory.", __fxName));
  272. return NULL;
  273. }
  274. // If there was anything failed during the creation of the pin, delete it.
  275. if (FAILED(hr))
  276. {
  277. delete m_pInputPin;
  278. m_pInputPin = NULL;
  279. BGLOG((BG_ERROR, "%s, create pin failed. hr=%x.", __fxName, hr));
  280. return NULL;
  281. }
  282. }
  283. return m_pInputPin;
  284. }
  285. HRESULT CTAPIBridgeSinkFilter::ProcessSample(
  286. IN IMediaSample *pSample
  287. )
  288. /*++
  289. Routine Description:
  290. Process a sample from the input pin. This method just pass it on to the
  291. bridge source filter's IDataBridge interface
  292. Arguments:
  293. pSample - The media sample object.
  294. Return Value:
  295. HRESULT.
  296. --*/
  297. {
  298. _ASSERT(m_pIDataBridge != NULL);
  299. return m_pIDataBridge->SendSample(pSample);
  300. }
  301. CTAPIBridgeSourceFilter::CTAPIBridgeSourceFilter(
  302. IN LPUNKNOWN pUnk,
  303. OUT HRESULT *phr
  304. ) :
  305. CBaseFilter(
  306. NAME("CTAPIBridgeSourceFilter"),
  307. pUnk,
  308. &m_Lock,
  309. __uuidof(TAPIBridgeSourceFilter)
  310. ),
  311. m_pOutputPin(NULL)
  312. {
  313. }
  314. CTAPIBridgeSourceFilter::~CTAPIBridgeSourceFilter()
  315. {
  316. if (m_pOutputPin)
  317. {
  318. delete m_pOutputPin;
  319. }
  320. }
  321. STDMETHODIMP
  322. CTAPIBridgeSourceFilter::NonDelegatingQueryInterface(
  323. IN REFIID riid,
  324. OUT PVOID* ppv
  325. )
  326. /*++
  327. Routine Description:
  328. Overrides CBaseFilter::NonDelegatingQueryInterface().
  329. The nondelegating interface query function. Returns a pointer to the
  330. specified interface if supported.
  331. Arguments:
  332. riid -
  333. The identifier of the interface to return.
  334. ppv -
  335. The place in which to put the interface pointer.
  336. Return Value:
  337. Returns NOERROR if the interface was returned, else E_NOINTERFACE.
  338. --*/
  339. {
  340. if (riid == __uuidof(IDataBridge)) {
  341. return GetInterface(static_cast<IDataBridge*>(this), ppv);
  342. }
  343. return CBaseFilter::NonDelegatingQueryInterface(riid, ppv);
  344. }
  345. int CTAPIBridgeSourceFilter::GetPinCount()
  346. /*++
  347. Routine Description:
  348. Implements pure virtual CBaseFilter::GetPinCount().
  349. Get the total number of pins on this filter.
  350. Arguments:
  351. Nothing.
  352. Return Value:
  353. The number of pins.
  354. --*/
  355. {
  356. // There is only one pin on this filter.
  357. return 1;
  358. }
  359. CBasePin * CTAPIBridgeSourceFilter::GetPin(
  360. int n
  361. )
  362. /*++
  363. Routine Description:
  364. Implements pure virtual CBaseFilter::GetPin().
  365. Get the pin object at position n. n is zero based.
  366. Arguments:
  367. n - The index of the pin, zero based.
  368. Return Value:
  369. Returns a pointer to the pin object if the index is valid. Otherwise,
  370. NULL is returned. Note: the pointer doesn't add refcount.
  371. --*/
  372. {
  373. ENTER_FUNCTION("CTAPIBridgeSourceFilter::GetPin");
  374. BGLOG((BG_TRACE,
  375. "%s, pin number:%d", __fxName, n));
  376. if (n != 0)
  377. {
  378. // there is only one pin on this filter.
  379. return NULL;
  380. }
  381. HRESULT hr;
  382. CAutoLock Lock(m_pLock);
  383. if (m_pOutputPin == NULL)
  384. {
  385. hr = S_OK; // hr may not be set in constructor
  386. m_pOutputPin = new CTAPIBridgeSourceOutputPin(this, &m_Lock, &hr);
  387. if (m_pOutputPin == NULL)
  388. {
  389. BGLOG((BG_ERROR, "%s, out of memory.", __fxName));
  390. return NULL;
  391. }
  392. // If there was anything failed during the creation of the pin, delete it.
  393. if (FAILED(hr))
  394. {
  395. delete m_pOutputPin;
  396. m_pOutputPin = NULL;
  397. BGLOG((BG_ERROR, "%s, create pin failed. hr=%x.", __fxName, hr));
  398. return NULL;
  399. }
  400. }
  401. return m_pOutputPin;
  402. }
  403. // override GetState to report that we don't send any data when paused, so
  404. // renderers won't starve expecting that
  405. //
  406. STDMETHODIMP CTAPIBridgeSourceFilter::GetState(DWORD dwMSecs, FILTER_STATE *State)
  407. {
  408. UNREFERENCED_PARAMETER(dwMSecs);
  409. CheckPointer(State,E_POINTER);
  410. ValidateReadWritePtr(State,sizeof(FILTER_STATE));
  411. *State = m_State;
  412. if (m_State == State_Paused)
  413. return VFW_S_CANT_CUE;
  414. else
  415. return S_OK;
  416. }
  417. HRESULT CTAPIBridgeSourceFilter::SendSample(
  418. IN IMediaSample *pSample
  419. )
  420. /*++
  421. Routine Description:
  422. Process a sample from the bridge sink filter. The base implementation just
  423. deliver it directly to the next filter.
  424. Arguments:
  425. pSample - The media sample object.
  426. Return Value:
  427. HRESULT.
  428. --*/
  429. {
  430. CAutoLock Lock(m_pLock);
  431. // we don't deliver anything if the filter is not in running state.
  432. if (m_State != State_Running)
  433. {
  434. return S_OK;
  435. }
  436. _ASSERT(m_pOutputPin != NULL);
  437. return m_pOutputPin->Deliver(pSample);
  438. }