CMpegInputPin.cpp
上传用户:hhs829
上传日期:2022-06-17
资源大小:586k
文件大小:3k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. //
  2. // CMpegInputPin.cpp
  3. //
  4. #include <streams.h>
  5. #include "CFilterMpeg2VD.h"
  6. #include "CMpegInputPin.h"
  7. /////////////////////////////////////////////////////////////////////////////
  8. CMpegInputPin::CMpegInputPin(TCHAR * inObjectName, 
  9. CFilterMpeg2VD * inFilter, 
  10. HRESULT * outResult) :
  11. CBaseInputPin(inObjectName, inFilter, inFilter->pStateLock(), outResult, L"Input")
  12. {
  13. mDecodeFilter = inFilter;
  14. }
  15. CMpegInputPin::~CMpegInputPin()
  16. {
  17. }
  18. //
  19. // Check input type
  20. HRESULT CMpegInputPin::CheckMediaType(const CMediaType * mtIn)
  21. {
  22. if ((mtIn->majortype == MEDIATYPE_Video ||
  23. mtIn->majortype == MEDIATYPE_MPEG2_PES) &&
  24. mtIn->subtype == MEDIASUBTYPE_MPEG2_VIDEO)
  25. {
  26. return NOERROR;
  27. }
  28. return E_FAIL;
  29. }
  30. STDMETHODIMP CMpegInputPin::Receive(IMediaSample *pSample)
  31. {
  32. CAutoLock lck(&mDecodeFilter->m_csReceive);
  33.     ASSERT(pSample);
  34.     // check all is well with the base class
  35. HRESULT hr = CBaseInputPin::Receive(pSample);
  36. if (hr == S_OK) 
  37. {
  38.         hr = mDecodeFilter->Receive(pSample);
  39.     }
  40.     return hr;
  41. }
  42. STDMETHODIMP CMpegInputPin::EndOfStream(void) 
  43. {
  44. CAutoLock  lck(&mDecodeFilter->m_csReceive);
  45. HRESULT hr = CheckStreaming();
  46. if (hr == S_OK) 
  47. {
  48. hr = mDecodeFilter->EndOfStream();
  49. }
  50. return hr;
  51. }
  52. // enter flushing state. Call default handler to block Receives, then
  53. // pass to overridable method in filter
  54. STDMETHODIMP CMpegInputPin::BeginFlush(void)
  55. {
  56. CAutoLock lck(mDecodeFilter->pStateLock());
  57. //  Are we actually doing anything?
  58. if (!IsConnected() || !mDecodeFilter->m_paStreams[0]->IsConnected()) 
  59. {
  60. return VFW_E_NOT_CONNECTED;
  61. }
  62. HRESULT hr = CBaseInputPin::BeginFlush();
  63. if (FAILED(hr)) 
  64. {
  65. return hr;
  66. }
  67. return mDecodeFilter->BeginFlush();
  68. }
  69. // leave flushing state.
  70. // Pass to overridable method in filter, then call base class
  71. // to unblock receives (finally)
  72. STDMETHODIMP CMpegInputPin::EndFlush(void)
  73. {
  74. CAutoLock lck(mDecodeFilter->pStateLock());
  75. //  Are we actually doing anything?
  76. if (!IsConnected() || !mDecodeFilter->m_paStreams[0]->IsConnected()) 
  77. {
  78. return VFW_E_NOT_CONNECTED;
  79. }
  80. HRESULT hr = mDecodeFilter->EndFlush();
  81. if (FAILED(hr)) 
  82. {
  83. return hr;
  84. }
  85. return CBaseInputPin::EndFlush();
  86. }
  87. //
  88. // Called when we are seeked
  89. //
  90. STDMETHODIMP CMpegInputPin::NewSegment(REFERENCE_TIME tStart, 
  91.   REFERENCE_TIME tStop, double dRate)
  92. {
  93. CBasePin::NewSegment(tStart, tStop, dRate);
  94. return mDecodeFilter->NewSegment(tStart, tStop, dRate);
  95. }
  96. HRESULT CMpegInputPin::CompleteConnect(IPin *pReceivePin)
  97. {
  98. HRESULT hr = mDecodeFilter->CompleteConnect(PINDIR_INPUT, pReceivePin);
  99.     if (FAILED(hr)) 
  100. {
  101.         return hr;
  102.     }
  103.     return CBaseInputPin::CompleteConnect(pReceivePin);
  104. }