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.

313 lines
7.6 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. MSPStrm.h
  5. Abstract:
  6. Definitions for CMSPStream class.
  7. --*/
  8. #ifndef _MSPSTRM_H_
  9. #define _MSPSTRM_H_
  10. /*++
  11. Class Description:
  12. Represents a stream in a call.
  13. --*/
  14. #define STRM_INITIAL 0x00000000
  15. #define STRM_TERMINALSELECTED 0x00000001
  16. #define STRM_CONFIGURED 0x00000002
  17. #define STRM_RUNNING 0x00000004
  18. #define STRM_PAUSED 0x00000008
  19. #define STRM_STOPPED 0x00000010
  20. class CMSPStream;
  21. class ATL_NO_VTABLE CPTEventSink :
  22. public CComObjectRootEx<CComMultiThreadModel>,
  23. public ITPluggableTerminalEventSink
  24. {
  25. public:
  26. CPTEventSink();
  27. ~CPTEventSink();
  28. BEGIN_COM_MAP( CPTEventSink )
  29. COM_INTERFACE_ENTRY( ITPluggableTerminalEventSink )
  30. END_COM_MAP()
  31. public:
  32. // --- ITDTEventSink ---
  33. STDMETHOD(FireEvent)(
  34. /* in */ const MSP_EVENT_INFO *pMspEventInfo
  35. );
  36. public:
  37. //
  38. // set the stream which will be processing our events
  39. //
  40. // this method is called by the stream when it creates and initializes
  41. // the sink object, and also when the stream is going away and want to
  42. // tell us that it is no longer available to process our events.
  43. //
  44. HRESULT SetSinkStream( CMSPStream *pStream );
  45. private:
  46. //
  47. // a nested structure that is used to pass event and stream to the
  48. // asynchronous event processing routine.
  49. //
  50. struct AsyncEventStruct
  51. {
  52. //
  53. // pointer to the stream on which to fire event
  54. //
  55. CMSPStream *pMSPStream;
  56. //
  57. // pointer to the event item to be processed
  58. //
  59. MSPEVENTITEM *pEventItem;
  60. //
  61. // as a public service, initialize structure's data members
  62. //
  63. AsyncEventStruct()
  64. :pMSPStream(NULL),
  65. pEventItem(NULL)
  66. {
  67. LOG((MSP_TRACE, "AsyncEventStruct::AsyncEventStruct[%p]", this));
  68. }
  69. //
  70. // as a safety measure, set data members to NULL's in destructor
  71. // to make sure no one attemopts to use them after the strcuture is
  72. // gone.
  73. //
  74. // note: we don't free any data members here -- that's responsibility
  75. // of the structure's client
  76. //
  77. ~AsyncEventStruct()
  78. {
  79. pMSPStream = NULL;
  80. pEventItem = NULL;
  81. LOG((MSP_TRACE, "AsyncEventStruct::~AsyncEventStruct[%p]", this));
  82. }
  83. }; // AsyncEventStruct
  84. //
  85. // the callback function that is submitted to thread pool api for async
  86. // event processing. The argument is the event structure containing stream
  87. // and the actual event
  88. //
  89. static DWORD WINAPI FireEventCallBack(LPVOID pEventStructure);
  90. private:
  91. CMSPStream* m_pMSPStream;
  92. };
  93. class ATL_NO_VTABLE CMSPStream :
  94. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  95. public IDispatchImpl<ITStream, &IID_ITStream, &LIBID_TAPI3Lib>
  96. {
  97. public:
  98. BEGIN_COM_MAP(CMSPStream)
  99. COM_INTERFACE_ENTRY(IDispatch)
  100. COM_INTERFACE_ENTRY(ITStream)
  101. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pFTM)
  102. END_COM_MAP()
  103. DECLARE_GET_CONTROLLING_UNKNOWN()
  104. CMSPStream();
  105. ~CMSPStream();
  106. // methods of the CComObject
  107. virtual void FinalRelease();
  108. // ITStream methods, called by the app.
  109. STDMETHOD (get_MediaType) (
  110. OUT long * plMediaType
  111. );
  112. STDMETHOD (get_Direction) (
  113. OUT TERMINAL_DIRECTION * pTerminalDirection
  114. );
  115. STDMETHOD (get_Name) (
  116. OUT BSTR * ppName
  117. ) = 0;
  118. STDMETHOD (SelectTerminal) (
  119. IN ITTerminal * pTerminal
  120. );
  121. STDMETHOD (UnselectTerminal) (
  122. IN ITTerminal * pTerminal
  123. );
  124. STDMETHOD (EnumerateTerminals) (
  125. OUT IEnumTerminal ** ppEnumTerminal
  126. );
  127. STDMETHOD (get_Terminals) (
  128. OUT VARIANT * pTerminals
  129. );
  130. STDMETHOD (StartStream) ();
  131. STDMETHOD (PauseStream) ();
  132. STDMETHOD (StopStream) ();
  133. // methods called by the MSPCall object.
  134. virtual HRESULT Init(
  135. IN HANDLE hAddress,
  136. IN CMSPCallBase * pMSPCall,
  137. IN IMediaEvent * pGraph,
  138. IN DWORD dwMediaType,
  139. IN TERMINAL_DIRECTION Direction
  140. );
  141. virtual HRESULT ShutDown();
  142. virtual HRESULT GetState(
  143. OUT DWORD * pdwStatus
  144. ) { return E_NOTIMPL; }
  145. virtual HRESULT HandleTSPData(
  146. IN BYTE * pData,
  147. IN DWORD dwSize
  148. );
  149. virtual HRESULT ProcessGraphEvent(
  150. IN long lEventCode,
  151. IN LONG_PTR lParam1,
  152. IN LONG_PTR lParam2
  153. );
  154. protected:
  155. // --- Helper functions ---
  156. HRESULT RegisterPluggableTerminalEventSink(
  157. /*[in]*/ ITTerminal* pTerminal
  158. );
  159. HRESULT UnregisterPluggableTerminalEventSink(
  160. /*[in]*/ ITTerminal* pTerminal
  161. );
  162. HRESULT ReleaseSink();
  163. //
  164. // we want to have control over our addref and release logic: we need to do
  165. // special tricks to avoid stream being accessed by the event sink while
  166. // the stream is being deleted.
  167. //
  168. ULONG InternalAddRef();
  169. ULONG InternalRelease();
  170. public:
  171. //
  172. // this method is called by CPTEventSink when it has an event for us to
  173. // process
  174. //
  175. HRESULT HandleSinkEvent(MSPEVENTITEM *pEventItem);
  176. protected:
  177. // Pointer to the free threaded marshaler.
  178. IUnknown * m_pFTM;
  179. // The current state of the stream.
  180. DWORD m_dwState;
  181. // The media type of this stream. Audio, video, or others.
  182. DWORD m_dwMediaType;
  183. // The direction of this stream. Incoming or outgoing.
  184. TERMINAL_DIRECTION m_Direction;
  185. // The address on which this stream is being used.
  186. HANDLE m_hAddress;
  187. // The reference to the call object.
  188. CMSPCallBase * m_pMSPCall;
  189. // The pointers to the graph object interfaces.
  190. IGraphBuilder * m_pIGraphBuilder;
  191. IMediaControl * m_pIMediaControl;
  192. // The list of stream objects in the call.
  193. CMSPArray <ITTerminal *> m_Terminals;
  194. // The lock that protects the stream object. The stream object
  195. // should never acquire the lock and then call a MSPCall method
  196. // that might lock.
  197. CMSPCritSection m_lock;
  198. // The lock that protects refcounting on the stream object. this is a
  199. // workaround needed to sync against event sink attempting to access the
  200. // stream object while it is being deleted.
  201. CMSPCritSection m_lockRefCount;
  202. // The Event Sink for pluggable terminals
  203. ITPluggableTerminalEventSink* m_pPTEventSink;
  204. //
  205. // we have to implement our own reference counting to work around the
  206. // problem of event sink addreffing us after we saw our last release
  207. //
  208. long m_lMyPersonalRefcount;
  209. //
  210. // this is a flag that we use to distingush between first addref and the
  211. // addref on the object whose refcount has gone down to 0.
  212. //
  213. BOOL m_bFirstAddRef;
  214. };
  215. #endif // __MSPSTRM_H_