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.

235 lines
7.2 KiB

  1. // Copyright (c) 1997 - 1998 Microsoft Corporation. All Rights Reserved.
  2. // Stream.h : Declaration of the CStream
  3. #ifndef __STREAM_H_
  4. #define __STREAM_H_
  5. class CSample;
  6. class CPump;
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CStream
  9. class ATL_NO_VTABLE CStream :
  10. public CComObjectRootEx<CComMultiThreadModel>,
  11. public IPin,
  12. public IMemInputPin,
  13. public IAMMediaStream,
  14. public IMemAllocator
  15. {
  16. friend CPump;
  17. public:
  18. typedef CComObjectRootEx<CComMultiThreadModel> _BaseClass;
  19. DECLARE_GET_CONTROLLING_UNKNOWN()
  20. //
  21. // METHODS
  22. //
  23. CStream();
  24. virtual ~CStream();
  25. //
  26. // IMediaStream
  27. //
  28. STDMETHODIMP GetMultiMediaStream(
  29. /* [out] */ IMultiMediaStream **ppMultiMediaStream);
  30. STDMETHODIMP GetInformation(
  31. /* [optional][out] */ MSPID *pPurposeId,
  32. /* [optional][out] */ STREAM_TYPE *pType);
  33. STDMETHODIMP SendEndOfStream(DWORD dwFlags);
  34. //
  35. // IAMMediaStream
  36. //
  37. STDMETHODIMP Initialize(
  38. IUnknown *pSourceObject,
  39. DWORD dwFlags,
  40. /* [in] */ REFMSPID PurposeId,
  41. /* [in] */ const STREAM_TYPE StreamType);
  42. STDMETHODIMP SetState(
  43. /* [in] */ FILTER_STATE State);
  44. STDMETHODIMP JoinAMMultiMediaStream(
  45. /* [in] */ IAMMultiMediaStream *pAMMultiMediaStream);
  46. STDMETHODIMP JoinFilter(
  47. /* [in] */ IMediaStreamFilter *pMediaStreamFilter);
  48. STDMETHODIMP JoinFilterGraph(
  49. /* [in] */ IFilterGraph *pFilterGraph);
  50. //
  51. // IPin
  52. //
  53. STDMETHODIMP Disconnect();
  54. STDMETHODIMP ConnectedTo(IPin **pPin);
  55. STDMETHODIMP ConnectionMediaType(AM_MEDIA_TYPE *pmt);
  56. STDMETHODIMP QueryPinInfo(PIN_INFO * pInfo);
  57. STDMETHODIMP QueryDirection(PIN_DIRECTION * pPinDir);
  58. STDMETHODIMP QueryId(LPWSTR * Id);
  59. STDMETHODIMP QueryAccept(const AM_MEDIA_TYPE *pmt);
  60. STDMETHODIMP QueryInternalConnections(IPin* *apPin, ULONG *nPin);
  61. STDMETHODIMP EndOfStream(void);
  62. STDMETHODIMP BeginFlush(void);
  63. STDMETHODIMP EndFlush(void);
  64. STDMETHODIMP NewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
  65. //
  66. // IMemInputPin
  67. //
  68. STDMETHODIMP GetAllocator(IMemAllocator ** ppAllocator);
  69. STDMETHODIMP NotifyAllocator(IMemAllocator * pAllocator, BOOL bReadOnly);
  70. STDMETHODIMP GetAllocatorRequirements(ALLOCATOR_PROPERTIES*pProps);
  71. STDMETHODIMP ReceiveMultiple(IMediaSample **pSamples, long nSamples, long *nSamplesProcessed);
  72. STDMETHODIMP ReceiveCanBlock();
  73. STDMETHODIMP Connect(IPin * pReceivePin, const AM_MEDIA_TYPE *pmt);
  74. STDMETHODIMP EnumMediaTypes(IEnumMediaTypes **ppEnum);
  75. //
  76. // IMemAllocator
  77. //
  78. STDMETHODIMP Commit();
  79. STDMETHODIMP Decommit();
  80. STDMETHODIMP ReleaseBuffer(IMediaSample *pBuffer);
  81. // Note that NotifyAllocator calls this so override it
  82. // if you care. Audio doesn't care becuase it's not
  83. // really using this allocator at all.
  84. STDMETHODIMP SetProperties(
  85. ALLOCATOR_PROPERTIES* pRequest,
  86. ALLOCATOR_PROPERTIES* pActual)
  87. {
  88. return S_OK;
  89. }
  90. STDMETHODIMP GetProperties(ALLOCATOR_PROPERTIES* pProps)
  91. {
  92. return E_UNEXPECTED;
  93. }
  94. //
  95. // Special CStream methods
  96. //
  97. virtual HRESULT GetMediaType(ULONG Index, AM_MEDIA_TYPE **ppMediaType) = 0;
  98. // Special to make sample to discard stuff into
  99. virtual HRESULT CreateTempSample(CSample **ppSample)
  100. {
  101. return E_FAIL;
  102. }
  103. virtual LONG GetChopSize()
  104. {
  105. return 0;
  106. }
  107. public:
  108. //
  109. // Private methods
  110. //
  111. void GetName(LPWSTR);
  112. HRESULT AllocSampleFromPool(const REFERENCE_TIME * pStartTime, CSample **ppSample);
  113. void AddSampleToFreePool(CSample *pSample);
  114. bool StealSampleFromFreePool(CSample *pSample, BOOL bAbort);
  115. HRESULT FinalConstruct(void);
  116. HRESULT ConnectThisMediaType(IPin *pReceivePin, const AM_MEDIA_TYPE *pmt);
  117. HRESULT CheckReceiveConnectionPin(IPin * pConnector);
  118. #ifdef DEBUG
  119. #define CHECKSAMPLELIST _ASSERTE(CheckSampleList());
  120. bool CheckSampleList();
  121. #else
  122. #define CHECKSAMPLELIST
  123. #endif
  124. BEGIN_COM_MAP(CStream)
  125. COM_INTERFACE_ENTRY(IPin)
  126. COM_INTERFACE_ENTRY(IMemInputPin)
  127. COM_INTERFACE_ENTRY(IMemAllocator)
  128. COM_INTERFACE_ENTRY2(IMediaStream, IAMMediaStream)
  129. COM_INTERFACE_ENTRY(IAMMediaStream)
  130. END_COM_MAP()
  131. //
  132. // MEMBER VARIABLES
  133. //
  134. public:
  135. //
  136. // These SHOULD NOT BE CCOMPTRS since we hold weak references to both of them
  137. // (we never addref them).
  138. //
  139. IMediaStreamFilter *m_pFilter;
  140. IBaseFilter *m_pBaseFilter;
  141. IFilterGraph *m_pFilterGraph;
  142. IAMMultiMediaStream *m_pMMStream;
  143. // Allocator held during connection
  144. CComPtr<IMemAllocator> m_pAllocator;
  145. // Writable streams
  146. CPump *m_pWritePump;
  147. // Stream configuration
  148. STREAM_TYPE m_StreamType;
  149. PIN_DIRECTION m_Direction;
  150. MSPID m_PurposeId;
  151. REFERENCE_TIME m_rtSegmentStart;
  152. // Allocator state information
  153. bool m_bUsingMyAllocator;
  154. bool m_bSamplesAreReadOnly;
  155. bool m_bCommitted;
  156. long m_lRequestedBufferCount;
  157. // Sample list and semaphores
  158. CSample *m_pFirstFree;
  159. CSample *m_pLastFree;
  160. long m_cAllocated;
  161. long m_lWaiting;
  162. HANDLE m_hWaitFreeSem;
  163. REFERENCE_TIME m_rtWaiting;
  164. // Filter state
  165. FILTER_STATE m_FilterState;
  166. // Pin state
  167. CComPtr<IPin> m_pConnectedPin;
  168. CComPtr<IQualityControl> m_pQC;
  169. CComQIPtr<IMemInputPin, &IID_IMemInputPin> m_pConnectedMemInputPin;
  170. AM_MEDIA_TYPE m_ConnectedMediaType;
  171. AM_MEDIA_TYPE m_ActualMediaType;
  172. bool m_bFlushing;
  173. bool m_bEndOfStream;
  174. bool m_bStopIfNoSamples;
  175. bool m_bNoStall;
  176. };
  177. //
  178. // Pump class used for write streams
  179. //
  180. class CPump
  181. {
  182. public:
  183. CPump(CStream *pStream);
  184. ~CPump();
  185. static HRESULT CreatePump(CStream *pStream, CPump **ppNewPump);
  186. HRESULT PumpMainLoop(void);
  187. void Run(bool);
  188. public:
  189. CStream *m_pStream;
  190. HANDLE m_hThread;
  191. HANDLE m_hRunEvent;
  192. bool m_bShutDown;
  193. CComAutoCriticalSection m_CritSec;
  194. };
  195. #endif //__STREAM_H_