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.

481 lines
11 KiB

  1. //
  2. // FPPin.cpp
  3. //
  4. #include "stdafx.h"
  5. #include "FPPin.h"
  6. //////////////////////////////////////////////////////////////////////
  7. //
  8. // Constructor / Destructor - Methods implementation
  9. //
  10. //////////////////////////////////////////////////////////////////////
  11. CFPPin::CFPPin(
  12. CFPFilter* pFilter,
  13. HRESULT* phr,
  14. LPCWSTR pPinName
  15. ) :
  16. CSourceStream(NAME("Output"), phr, pFilter, pPinName),
  17. m_pFPFilter(pFilter),
  18. m_bFinished(FALSE)
  19. {
  20. LOG((MSP_TRACE, "CFPPin::CFPPin - enter"));
  21. LOG((MSP_TRACE, "CFPPin::CFPPin - exit"));
  22. }
  23. CFPPin::~CFPPin()
  24. {
  25. LOG((MSP_TRACE, "CFPPin::~CFPPin - enter"));
  26. LOG((MSP_TRACE, "CFPPin::~CFPPin - exit"));
  27. }
  28. //////////////////////////////////////////////////////////////////////
  29. //
  30. // IUnknown - Methods implementation
  31. //
  32. //////////////////////////////////////////////////////////////////////
  33. /*++
  34. NonDelegatingQueryInterface
  35. Description;
  36. What interfaces support
  37. --*/
  38. STDMETHODIMP CFPPin::NonDelegatingQueryInterface(
  39. REFIID riid,
  40. void** ppv
  41. )
  42. {
  43. LOG((MSP_TRACE, "CFPPin::NonDelegatingQueryInterface - enter"));
  44. if (riid == IID_IAMStreamControl)
  45. {
  46. LOG((MSP_TRACE, "CFPPin::NQI IAMStreamControl - exit"));
  47. return GetInterface((LPUNKNOWN)(IAMStreamControl *)this, ppv);
  48. }
  49. else if (riid == IID_IAMStreamConfig)
  50. {
  51. LOG((MSP_TRACE, "CFPPin::NQI IAMStreamconfig - exit"));
  52. return GetInterface((LPUNKNOWN)(IAMStreamConfig *)this, ppv);
  53. }
  54. else if (riid == IID_IAMBufferNegotiation)
  55. {
  56. LOG((MSP_TRACE, "CFPPin::NQI IAMBufferNegotiation - exit"));
  57. return GetInterface((LPUNKNOWN)(IAMBufferNegotiation *)this, ppv);
  58. }
  59. LOG((MSP_TRACE, "CFPPin::NQI call base NQI - exit"));
  60. return CSourceStream::NonDelegatingQueryInterface(riid, ppv);
  61. }
  62. //////////////////////////////////////////////////////////////////////
  63. //
  64. // CSourceStream - Methods implementation
  65. //
  66. //////////////////////////////////////////////////////////////////////
  67. // stuff an audio buffer with the current format
  68. HRESULT CFPPin::FillBuffer(
  69. IN IMediaSample *pms
  70. )
  71. {
  72. LOG((MSP_TRACE, "CFPPin::FillBuffer - enter"));
  73. //
  74. // Critical section
  75. //
  76. CLock lock(m_Lock);
  77. if( m_pFPFilter == NULL)
  78. {
  79. LOG((MSP_ERROR, "CFPPin::FillBuffer - exit "
  80. " pointer to the filter is NULL. Returns E_UNEXPECTED"));
  81. return E_UNEXPECTED;
  82. }
  83. HRESULT hr = m_pFPFilter->PinFillBuffer( pms );
  84. if( FAILED(hr) )
  85. {
  86. LOG((MSP_ERROR, "CFPPin::FillBuffer - exit "
  87. " PinFillBuffer failed. Returns 0x%08x", hr));
  88. return hr;
  89. }
  90. LOG((MSP_TRACE, "CFPPin::FillBuffer - exit S_OK"));
  91. return S_OK;
  92. }
  93. // ask for buffers of the size appropriate to the agreed media type.
  94. HRESULT CFPPin::DecideBufferSize(
  95. IN IMemAllocator *pAlloc,
  96. OUT ALLOCATOR_PROPERTIES *pProperties
  97. )
  98. {
  99. LOG((MSP_TRACE, "CFPPin::DecideBufferSize - enter"));
  100. //
  101. // Validates arguments
  102. //
  103. if( NULL == pAlloc)
  104. {
  105. LOG((MSP_ERROR, "CFPPin::DecideBufferSize - "
  106. "inavlid IMemAllocator pointer - returns E_INVALIDARG"));
  107. return E_INVALIDARG;
  108. }
  109. if( IsBadWritePtr( pProperties, sizeof(ALLOCATOR_PROPERTIES)) )
  110. {
  111. LOG((MSP_ERROR, "CFPPin::DecideBufferSize - "
  112. "inavlid ALLOCATOR_PROPERTIES pointer - returns E_INVALIDARG"));
  113. return E_INVALIDARG;
  114. }
  115. //
  116. // Critical section
  117. //
  118. CLock lock(m_Lock);
  119. //
  120. // Validates filter
  121. //
  122. if( NULL == m_pFPFilter )
  123. {
  124. LOG((MSP_ERROR, "CFPPin::DecideBufferSize - "
  125. "inavlid pointer to filter. Returns E_UNEXPECTED"));
  126. return E_UNEXPECTED;
  127. }
  128. HRESULT hr = m_pFPFilter->PinGetBufferSize(
  129. pAlloc,
  130. pProperties
  131. );
  132. if( FAILED(hr) )
  133. {
  134. LOG((MSP_ERROR, "CFPPin::DecideBufferSize - "
  135. "PinGetBufferSize failed. Returns 0x%08x", hr));
  136. return hr;
  137. }
  138. LOG((MSP_TRACE, "CFPPin::DecideBufferSize - exit"));
  139. return S_OK;
  140. }
  141. HRESULT CFPPin::GetMediaType(
  142. OUT CMediaType *pmt
  143. )
  144. {
  145. //
  146. // Critical section
  147. //
  148. CLock lock(m_Lock);
  149. LOG((MSP_TRACE, "CFPPin::GetMediaType - enter"));
  150. //
  151. // Validates argument
  152. //
  153. if( IsBadWritePtr( pmt, sizeof( CMediaType)) )
  154. {
  155. LOG((MSP_ERROR, "CFPPin::GetMediaType - "
  156. "invalid CmediaType pointer - returns E_POINTER"));
  157. return E_POINTER;
  158. }
  159. //
  160. // Validates filter
  161. //
  162. if( NULL == m_pFPFilter )
  163. {
  164. LOG((MSP_ERROR, "CFPPin::GetMediaType - "
  165. "inavlid pointer to filter. Returns E_UNEXPECTED"));
  166. return E_UNEXPECTED;
  167. }
  168. //
  169. // Get media type from the filter
  170. //
  171. HRESULT hr = m_pFPFilter->PinGetMediaType( pmt );
  172. if( FAILED(hr) )
  173. {
  174. LOG((MSP_ERROR, "CFPPin::GetMediaType - "
  175. "inavlid pointer to filter. Returns 0x%08x", hr));
  176. return hr;
  177. }
  178. LOG((MSP_TRACE, "CFPPin::GetMediaType - exit S_OK"));
  179. return S_OK;
  180. }
  181. // verify we can handle this format
  182. HRESULT CFPPin::CheckMediaType(
  183. IN const CMediaType *pMediaType
  184. )
  185. {
  186. LOG((MSP_TRACE, "CFPPin::CheckMediaType - enter"));
  187. //
  188. // Validates argument
  189. //
  190. if( IsBadReadPtr( pMediaType, sizeof(CMediaType)) )
  191. {
  192. LOG((MSP_ERROR, "CFPPin::CheckMediaType - "
  193. "inavlid pointer - returns E_POINTER"));
  194. return E_POINTER;
  195. }
  196. //
  197. // Validates filter
  198. //
  199. if( NULL == m_pFPFilter )
  200. {
  201. LOG((MSP_ERROR, "CFPPin::CheckMediaType - "
  202. "inavlid pointer to filter. Returns E_UNEXPECTED"));
  203. return E_UNEXPECTED;
  204. }
  205. HRESULT hr = m_pFPFilter->PinCheckMediaType( pMediaType );
  206. if( FAILED(hr) )
  207. {
  208. LOG((MSP_ERROR, "CFPPin::CheckMediaType - "
  209. "inavlid pointer to stream. Returns 0x%08x", hr));
  210. return hr;
  211. }
  212. LOG((MSP_TRACE, "CFPPin::CheckMediaType - exit"));
  213. return S_OK;
  214. }
  215. HRESULT CFPPin::SetMediaType(
  216. IN const CMediaType *pMediaType
  217. )
  218. {
  219. LOG((MSP_TRACE, "CFPPin::SetMediaType - enter"));
  220. HRESULT hr;
  221. // Pass the call up to my base class
  222. hr = CSourceStream::SetMediaType(pMediaType);
  223. LOG((MSP_TRACE, "CFPPin::SetMediaType - exit (0x%08x)", hr));
  224. return hr;
  225. }
  226. //////////////////////////////////////////////////////////////////////
  227. //
  228. // IAMStreamConfig - Methods implementation
  229. //
  230. //////////////////////////////////////////////////////////////////////
  231. STDMETHODIMP CFPPin::SetFormat(
  232. AM_MEDIA_TYPE* pmt
  233. )
  234. {
  235. //
  236. // Critical section
  237. //
  238. CLock lock(m_Lock);
  239. LOG((MSP_TRACE, "CFPPin::SetFormat - enter"));
  240. //
  241. // Validates argument
  242. //
  243. if( IsBadReadPtr( pmt, sizeof(AM_MEDIA_TYPE)) )
  244. {
  245. LOG((MSP_ERROR, "CFPPin::SetFormat - "
  246. "inavlid pointer. Returns E_POINTER"));
  247. return E_POINTER;
  248. }
  249. //
  250. // Validates filter
  251. //
  252. if( NULL == m_pFPFilter )
  253. {
  254. LOG((MSP_ERROR, "CFPPin::SetFormat - "
  255. "inavlid pointer to filter. Returns E_UNEXPECTED"));
  256. return E_UNEXPECTED;
  257. }
  258. HRESULT hr = m_pFPFilter->PinSetFormat( pmt );
  259. if( FAILED(hr) )
  260. {
  261. LOG((MSP_ERROR, "CFPPin::SetFormat - "
  262. "PinSetFormat failed. Returns 0x%08x", hr));
  263. return hr;
  264. }
  265. LOG((MSP_TRACE, "CFPPin::SetFormat - exit"));
  266. return S_OK;
  267. }
  268. STDMETHODIMP CFPPin::GetFormat(
  269. AM_MEDIA_TYPE** ppmt
  270. )
  271. {
  272. LOG((MSP_TRACE, "CFPPin::GetFormat - enter"));
  273. LOG((MSP_TRACE, "CFPPin::GetFormat - exit E_NOTIMPL"));
  274. return E_NOTIMPL;
  275. }
  276. STDMETHODIMP CFPPin::GetNumberOfCapabilities(
  277. int* piCount,
  278. int* piSize
  279. )
  280. {
  281. LOG((MSP_TRACE, "CFPPin::GetNumberOfCapabilities - enter"));
  282. LOG((MSP_TRACE, "CFPPin::GetNumberOfCapabilities - exit E_NOTIMPL"));
  283. return E_NOTIMPL;
  284. }
  285. STDMETHODIMP CFPPin::GetStreamCaps(
  286. int i,
  287. AM_MEDIA_TYPE** ppmt,
  288. LPBYTE pSCC
  289. )
  290. {
  291. LOG((MSP_TRACE, "CFPPin::GetStreamCaps - enter"));
  292. LOG((MSP_TRACE, "CFPPin::GetStreamCaps - exit E_NOTIMPL"));
  293. return E_NOTIMPL;
  294. }
  295. //////////////////////////////////////////////////////////////////////
  296. //
  297. // IAMBufferNegotiation - Methods implementation
  298. //
  299. //////////////////////////////////////////////////////////////////////
  300. STDMETHODIMP CFPPin::SuggestAllocatorProperties(
  301. const ALLOCATOR_PROPERTIES* pprop
  302. )
  303. {
  304. LOG((MSP_TRACE, "CFPPin::SuggestAllocatorProperties - enter"));
  305. //
  306. // Validates argument
  307. //
  308. if( IsBadReadPtr( pprop, sizeof(ALLOCATOR_PROPERTIES)) )
  309. {
  310. LOG((MSP_ERROR, "CFPPin::SuggestAllocatorProperties - "
  311. "inavlid pointer - returns E_POINTER"));
  312. return E_POINTER;
  313. }
  314. //
  315. // Validates filter
  316. //
  317. if( NULL == m_pFPFilter )
  318. {
  319. LOG((MSP_ERROR, "CFPPin::SuggestAllocatorProperties - "
  320. "inavlid pointer to filter. Returns E_UNEXPECTED"));
  321. return E_UNEXPECTED;
  322. }
  323. //
  324. // Set the allocator properties
  325. //
  326. LOG((MSP_TRACE, "CFPPin::SuggestAllocatorProperties - "
  327. "Size=%ld, Count=%ld",
  328. pprop->cbBuffer,
  329. pprop->cBuffers));
  330. HRESULT hr = m_pFPFilter->PinSetAllocatorProperties( pprop );
  331. if( FAILED(hr) )
  332. {
  333. LOG((MSP_ERROR, "CFPPin::SuggestAllocatorProperties - "
  334. "PinSetAllocatorProperties failed. Returns 0x%08x", hr));
  335. return hr;
  336. }
  337. LOG((MSP_TRACE, "CFPPin::SuggestAllocatorProperties - exit"));
  338. return S_OK;
  339. }
  340. STDMETHODIMP CFPPin::GetAllocatorProperties(
  341. ALLOCATOR_PROPERTIES* pprop
  342. )
  343. {
  344. LOG((MSP_TRACE, "CFPPin::GetAllocatorProperties - enter"));
  345. LOG((MSP_TRACE, "CFPPin::GetAllocatorProperties - exit E_NOTIMPL"));
  346. return E_NOTIMPL;
  347. }
  348. HRESULT CFPPin::OnThreadStartPlay()
  349. {
  350. LOG((MSP_TRACE, "CFPPin::OnThreadStartPlay - enter"));
  351. //
  352. // Critical section
  353. //
  354. CLock lock(m_Lock);
  355. //
  356. // Validates filter
  357. //
  358. if( NULL == m_pFPFilter )
  359. {
  360. LOG((MSP_ERROR, "CFPPin::OnThreadStartPlay - "
  361. "inavlid pointer to filter. Returns E_UNEXPECTED"));
  362. return E_UNEXPECTED;
  363. }
  364. HRESULT hr = m_pFPFilter->PinThreadStart( );
  365. LOG((MSP_TRACE, "CFPPin::OnThreadStartPlay - exit 0x%08x", hr));
  366. return hr;
  367. }
  368. /*++
  369. Deliver
  370. We overite CSourceStream::Deliver() method
  371. and right now we don't deliver 0 length samples
  372. It's just an optimization.
  373. --*/
  374. HRESULT CFPPin::Deliver(
  375. IN IMediaSample* pSample
  376. )
  377. {
  378. if (m_pInputPin == NULL)
  379. {
  380. return VFW_E_NOT_CONNECTED;
  381. }
  382. if( pSample == NULL )
  383. {
  384. return E_UNEXPECTED;
  385. }
  386. long nLength = pSample->GetActualDataLength();
  387. if( nLength == 0 )
  388. {
  389. return S_OK;
  390. }
  391. return CSourceStream::Deliver( pSample );
  392. }
  393. // eof