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.

117 lines
3.6 KiB

  1. #ifndef __INPIN_H__
  2. #define __INPIN_H__
  3. class CWrapperInputPin : public CBaseInputPin
  4. {
  5. friend class CMediaWrapperFilter; // stuff at the bottom is owned by the filter
  6. public:
  7. CWrapperInputPin(CMediaWrapperFilter *pFilter,
  8. ULONG Id,
  9. HRESULT *phr);
  10. ~CWrapperInputPin();
  11. STDMETHODIMP EndOfStream();
  12. STDMETHODIMP Receive(IMediaSample *pSample);
  13. // Override GetAllocator and Notify Allocator to allow
  14. // for media object streams that hold on to buffer
  15. STDMETHODIMP GetAllocator(IMemAllocator **ppAllocator);
  16. STDMETHODIMP NotifyAllocator(IMemAllocator *pAllocator, BOOL bReadOnly);
  17. STDMETHODIMP GetAllocatorRequirements(ALLOCATOR_PROPERTIES *pProps);
  18. STDMETHODIMP NewSegment(
  19. REFERENCE_TIME tStart,
  20. REFERENCE_TIME tStop,
  21. double dRate);
  22. STDMETHODIMP BeginFlush();
  23. STDMETHODIMP EndFlush();
  24. HRESULT CheckMediaType(const CMediaType *pmt);
  25. HRESULT SetMediaType(const CMediaType *pmt);
  26. HRESULT GetMediaType(int iPosition,CMediaType *pMediaType);
  27. // Override to unset media type
  28. HRESULT BreakConnect();
  29. STDMETHODIMP Notify(IBaseFilter * pSender, Quality q);
  30. // Synclock for stop
  31. void SyncLock();
  32. BOOL HoldsOnToBuffers();
  33. protected:
  34. HRESULT MP3AndWMABufferSizeWorkAround(IMemAllocator* pProposedAllocator);
  35. HRESULT SetBufferSize(IMemAllocator* pAllocator, DWORD dwMinBufferSize);
  36. CMediaWrapperFilter *Filter() const
  37. {
  38. return static_cast<CMediaWrapperFilter *>(m_pFilter);
  39. }
  40. ULONG m_Id;
  41. _PinName_ *m_pNameObject;
  42. CCritSec m_csStream;
  43. // This stuff is owned by the filter and is declared here for allocation convenience
  44. bool m_fEOS; // have received EOS during this streaming session
  45. };
  46. // Special allocator class. This class allocators extra internal
  47. // buffers to satisfy the lookahead scheme that are not reported
  48. // in GetProperties. Thus the upstream pin's requirements are satisfied
  49. // in addition to our own.
  50. class CSpecialAllocator : public CMemAllocator
  51. {
  52. DWORD m_dwLookahead;
  53. public:
  54. CSpecialAllocator(DWORD dwLookahead, HRESULT *phr) :
  55. CMemAllocator(NAME("CSpecialAllocator"), NULL, phr),
  56. m_dwLookahead(dwLookahead)
  57. {
  58. }
  59. // Helper
  60. LONG BuffersRequired(LONG cbBuffer) const
  61. {
  62. if (cbBuffer <= 0 || m_dwLookahead == 0) {
  63. return 1;
  64. } else {
  65. return (m_dwLookahead + 2 * (cbBuffer - 1)) / cbBuffer;
  66. }
  67. }
  68. // Override Set/GetProperties to create extra buffers not
  69. // reported
  70. STDMETHODIMP GetProperties(ALLOCATOR_PROPERTIES *pProps)
  71. {
  72. CAutoLock lck(this);
  73. HRESULT hr = CMemAllocator::GetProperties(pProps);
  74. LONG cBuffersRequired = BuffersRequired(m_lSize);
  75. if (SUCCEEDED(hr)) {
  76. ASSERT(pProps->cBuffers >= cBuffersRequired);
  77. pProps->cBuffers -= cBuffersRequired - 1;
  78. }
  79. return hr;
  80. }
  81. STDMETHODIMP SetProperties(ALLOCATOR_PROPERTIES *pRequest,
  82. ALLOCATOR_PROPERTIES *pActual)
  83. {
  84. CAutoLock lck(this);
  85. // Compute the buffers required for this buffer size
  86. LONG cBuffersRequired = BuffersRequired(pRequest->cbBuffer);
  87. ALLOCATOR_PROPERTIES Request = *pRequest;
  88. Request.cBuffers += cBuffersRequired - 1;
  89. HRESULT hr = CMemAllocator::SetProperties(&Request, pActual);
  90. if (SUCCEEDED(hr)) {
  91. ASSERT(pActual->cBuffers >= pRequest->cBuffers);
  92. pActual->cBuffers -= cBuffersRequired - 1;
  93. }
  94. return hr;
  95. }
  96. };
  97. #endif //__INPIN_H__