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.

277 lines
12 KiB

  1. /*
  2. * File: commchan.h
  3. *
  4. * Network media channel interface implementation
  5. *
  6. * Revision History:
  7. *
  8. * 10/09/96 mikev created
  9. */
  10. #ifndef _COMMCHAN_H
  11. #define _COMMCHAN_H
  12. #ifdef COARSE_PROFILE
  13. typedef struct {
  14. DWORD dwStart;
  15. DWORD dwLast;
  16. // DWORD dwElapsed; // to take advantage of thread timers
  17. }CP_TIME;
  18. #define CPT_LOCAL CP_TIME _cpt_
  19. #define OBJ_CPT CP_TIME m_cpt_
  20. #define OBJ_CPT_RESET m_cpt_.dwStart = m_cpt_.dwLast = GetTickCount()
  21. #define OBJ_ETIME ((m_cpt_.dwLast = GetTickCount()) - m_cpt_.dwStart)
  22. #define OBJ_ETIME_RESET m_cpt_.dwStart = m_cpt_.dwLast
  23. // tricky macro
  24. #define OBJ_NEW_ETIME ((m_cpt_.dwLast = GetTickCount()) - m_cpt_.dwStart); m_cpt_.dwStart = m_cpt_.dwLast
  25. // SHOW_OBJ_ETIME snaps elapsed time since last show or reset, then resets
  26. #ifdef DEBUG
  27. #define SHOW_OBJ_ETIME(s) DEBUGMSG(ZONE_PROFILE,("\r\n** (%s) ELAPSED TIME(ms):%d, ticks:%d **\r\n", \
  28. (s), OBJ_ETIME, m_cpt_.dwLast)); OBJ_ETIME_RESET
  29. #else
  30. #define SHOW_OBJ_ETIME(s) RETAILMSG(("\r\n** (%s) ELAPSED TIME(ms):%d, ticks:%d **\r\n", \
  31. (s), OBJ_ETIME, m_cpt_.dwLast )); OBJ_ETIME_RESET
  32. #endif
  33. #else // not COARSE_PROFILE
  34. #define CPT_LOCAL
  35. #define CPT_RESET
  36. #define CPT_DELTA
  37. #define OBJ_CPT
  38. #define OBJ_CPT_RESET
  39. #define OBJ_NEW_ETIME
  40. #define SHOW_OBJ_ETIME(s)
  41. #endif // COARSE_PROFILE
  42. #undef INTERFACE
  43. #define INTERFACE ICtrlCommChan
  44. DECLARE_INTERFACE_(ICtrlCommChan, IUnknown)
  45. {
  46. STDMETHOD(StandbyInit)(LPGUID lpMID, LPIH323PubCap pCapObject,
  47. IMediaChannel* pMediaStreamSend) PURE;
  48. STDMETHOD_(BOOL, Init)(LPGUID lpMID, IH323ConfAdvise *pH323ConfAdvise,
  49. BOOL fSendDirection) PURE;
  50. STDMETHOD(GetMediaType)(LPGUID pGuid) PURE;
  51. // EnableOpen is needed temporaraily until NMCOM is master of channels
  52. STDMETHOD(EnableOpen)(BOOL bEnable) PURE;
  53. // The CtrlChanSetProperty() method is only used for 4 things:
  54. // 1&2 - (Boolean) local and remote Temporal/Spatial tradeoff capability,
  55. // 3&4 (word) local & remote Temporal/Spatial tradeoff value
  56. STDMETHOD(CtrlChanSetProperty)(THIS_ DWORD prop, PVOID pBuf, DWORD cbBuf)PURE;
  57. STDMETHOD( PauseNet)(THIS_ BOOL bPause, BOOL bRemote) PURE;
  58. STDMETHOD( BeginControlSession)(IControlChannel *pCtlChan, LPIH323PubCap pCapObject) PURE;
  59. STDMETHOD( EndControlSession)(THIS) PURE;
  60. STDMETHOD_(IControlChannel *, GetControlChannel)(THIS) PURE;
  61. STDMETHOD( OnChannelOpening)(THIS) PURE;
  62. STDMETHOD( OnChannelOpen)(THIS_ DWORD dwStatus) PURE;
  63. STDMETHOD( OnChannelClose)(THIS_ DWORD dwStatus) PURE;
  64. STDMETHOD_(UINT, Reset) (THIS) PURE;
  65. STDMETHOD_(BOOL, SelectPorts) (THIS_ LPIControlChannel pCtlChannel) PURE;
  66. STDMETHOD_(PSOCKADDR_IN, GetLocalAddress)(THIS) PURE;
  67. STDMETHOD_( PORT, GetLocalRTPPort) (THIS) PURE;
  68. STDMETHOD_( PORT, GetLocalRTCPPort) (THIS) PURE;
  69. STDMETHOD( AcceptRemoteAddress) (THIS_ PSOCKADDR_IN pSinD) PURE;
  70. STDMETHOD( AcceptRemoteRTCPAddress) (THIS_ PSOCKADDR_IN pSinC) PURE;
  71. STDMETHOD_(BOOL, IsChannelOpen)(THIS) PURE;
  72. STDMETHOD_(BOOL, IsOpenPending)(THIS) PURE;
  73. STDMETHOD_(BOOL, IsSendChannel) (THIS) PURE;
  74. STDMETHOD_(BOOL, IsChannelEnabled) (THIS) PURE;
  75. STDMETHOD( ConfigureCapability)(THIS_ LPVOID lpvRemoteChannelParams, UINT uRemoteParamSize,
  76. LPVOID lpvLocalParams, UINT uLocalParamSize) PURE;
  77. STDMETHOD( GetLocalParams)(THIS_ LPVOID lpvChannelParams, UINT uBufSize) PURE;
  78. STDMETHOD_(LPVOID, GetRemoteParams)(THIS) PURE;
  79. STDMETHOD_(VOID, SetNegotiatedLocalFormat)(THIS_ DWORD dwF) PURE;
  80. STDMETHOD_(VOID, SetNegotiatedRemoteFormat)(THIS_ DWORD dwF) PURE;
  81. // GetHChannel, SetHChannel simply store and retrieve a handle. This is an Intel
  82. // call control handle.
  83. STDMETHOD_(DWORD_PTR, GetHChannel) (THIS) PURE;
  84. STDMETHOD_(VOID, SetHChannel) (THIS_ DWORD_PTR dwSetChannel) PURE;
  85. };
  86. class ImpICommChan : public ICommChannel, public ICtrlCommChan, public IStreamSignal
  87. {
  88. protected:
  89. UINT m_uRef;
  90. GUID m_MediaID;
  91. BOOL bIsSendDirection; // true if send, false if receive
  92. OBJ_CPT; // profiling timer
  93. LPVOID pRemoteParams;
  94. LPVOID pLocalParams;
  95. UINT uLocalParamSize;
  96. // so far there is no reason to remember size of remote params.
  97. protected:
  98. IMediaChannel *m_pMediaStream;
  99. IRTPSession *m_pRTPChan;
  100. IControlChannel *m_pCtlChan;
  101. LPIH323PubCap m_pCapObject;
  102. IH323ConfAdvise *m_pH323ConfAdvise;
  103. DWORD m_dwFlags;
  104. #define COMCH_ENABLED 0x00000010 // enabled. (ok to attempt or accept open)
  105. #define COMCH_OPEN_PENDING 0x00008000
  106. #define COMCH_STRM_STANDBY 0x00010000 // preview needs to be on always
  107. #define COMCH_STRM_LOCAL 0x00020000
  108. #define COMCH_STRM_NETWORK 0x00040000
  109. #define COMCH_OPEN 0x00080000
  110. #define COMCH_RESPONSE_PENDING 0x00100000
  111. #define COMCH_SUPPRESS_NOTIFICATION 0x00200000
  112. #define COMCH_STRM_REMOTE 0x00400000
  113. #define COMCH_PAUSE_LOCAL 0x00800000
  114. #define COMCH_STRM_CONFIGURE_STANDBY 0x01000000 // stream needs to remain configured
  115. #define IsComchOpen() (m_dwFlags & COMCH_OPEN)
  116. #define IsStreamingStandby() (m_dwFlags & COMCH_STRM_STANDBY)
  117. #define IsConfigStandby() (m_dwFlags & COMCH_STRM_CONFIGURE_STANDBY)
  118. #define IsStreamingLocal() (m_dwFlags & COMCH_STRM_LOCAL)
  119. #define IsStreamingRemote() (m_dwFlags & COMCH_STRM_REMOTE)
  120. #define IsStreamingNet() (m_dwFlags & COMCH_STRM_NETWORK)
  121. #define IsResponsePending() (m_dwFlags & COMCH_RESPONSE_PENDING)
  122. #define IsNotificationSupressed() (m_dwFlags & COMCH_SUPPRESS_NOTIFICATION)
  123. #define StandbyFlagOff() (m_dwFlags &= ~COMCH_STRM_STANDBY)
  124. #define StandbyFlagOn() (m_dwFlags |= COMCH_STRM_STANDBY)
  125. #define StandbyConfigFlagOff() (m_dwFlags &= ~COMCH_STRM_CONFIGURE_STANDBY)
  126. #define StandbyConfigFlagOn() (m_dwFlags |= COMCH_STRM_CONFIGURE_STANDBY)
  127. #define LocalStreamFlagOff() (m_dwFlags &= ~COMCH_STRM_LOCAL)
  128. #define LocalStreamFlagOn() (m_dwFlags |= COMCH_STRM_LOCAL)
  129. #define RemoteStreamFlagOff() (m_dwFlags &= ~COMCH_STRM_REMOTE)
  130. #define RemoteStreamFlagOn() (m_dwFlags |= COMCH_STRM_REMOTE)
  131. #define LocalPauseFlagOff() (m_dwFlags &= ~COMCH_PAUSE_LOCAL)
  132. #define LocalPauseFlagOn() (m_dwFlags |= COMCH_PAUSE_LOCAL)
  133. #define IsPausedLocal() (m_dwFlags & COMCH_PAUSE_LOCAL)
  134. #define StreamFlagsOff() (m_dwFlags &= ~(COMCH_STRM_LOCAL | COMCH_STRM_NETWORK))
  135. #define StreamFlagsOn() (m_dwFlags |= (COMCH_STRM_LOCAL | COMCH_STRM_NETWORK))
  136. #define NetworkStreamFlagOff() (m_dwFlags &= ~COMCH_STRM_NETWORK)
  137. #define NetworkStreamFlagOn() (m_dwFlags |= COMCH_STRM_NETWORK)
  138. #define ResponseFlagOn() (m_dwFlags |= COMCH_RESPONSE_PENDING)
  139. #define ResponseFlagOff() (m_dwFlags &= ~COMCH_RESPONSE_PENDING)
  140. #define SuppressNotification() (m_dwFlags |= COMCH_SUPPRESS_NOTIFICATION)
  141. #define AllowNotifications() (m_dwFlags &= ~COMCH_SUPPRESS_NOTIFICATION)
  142. MEDIA_FORMAT_ID m_LocalFmt; // format ID of what we are sending or receiving
  143. MEDIA_FORMAT_ID m_RemoteFmt;// remote's format ID of the complimentary format
  144. DWORD m_TemporalSpatialTradeoff; // For send channels, this is the local value.
  145. // For receive channels, this is the remote value.
  146. // A magic number between 1 and 31 that describes
  147. // the relative tradeoff between compression and
  148. // bitrate. This is part of H.323/H.245.
  149. // The ITU decided on the weird range.
  150. BOOL m_bPublicizeTSTradeoff; // For send channels, this indicates our willingness
  151. // to accept remote control of T/S tradeoff, and
  152. // also signal changes in our local TS value to
  153. // the remote.
  154. // For receive channels, it indicates the remote's
  155. // willingness.
  156. DWORD m_dwLastUpdateTick; // tick count of last attempt to request I-Frame
  157. #define MIN_IFRAME_REQ_TICKS 5000 // minimum #of elapsed ticks between requests
  158. DWORD_PTR dwhChannel; //General purpose handle. Whatever
  159. // creates an instance of this class can use this for whatever it wants
  160. STDMETHODIMP StreamStandby(BOOL bStandby);
  161. STDMETHODIMP ConfigureStream(MEDIA_FORMAT_ID idLocalFormat);
  162. public:
  163. // ICtrlCommChannel methods
  164. STDMETHODIMP_(IControlChannel *) GetControlChannel(VOID) {return m_pCtlChan;};
  165. STDMETHODIMP StandbyInit(LPGUID lpMID, LPIH323PubCap pCapObject,
  166. IMediaChannel* pMediaStreamSend);
  167. STDMETHODIMP_(BOOL) Init(LPGUID lpMID, IH323ConfAdvise *pH323ConfAdvise, BOOL fSendDirection)
  168. {
  169. m_MediaID = *lpMID;
  170. bIsSendDirection = fSendDirection;
  171. m_pH323ConfAdvise = pH323ConfAdvise;
  172. return TRUE;
  173. };
  174. STDMETHODIMP CtrlChanSetProperty(DWORD prop, PVOID pBuf, DWORD cbBuf);
  175. STDMETHODIMP PauseNet(BOOL bPause, BOOL bRemote);
  176. STDMETHODIMP BeginControlSession(IControlChannel *pCtlChan, LPIH323PubCap pCapObject);
  177. STDMETHODIMP EndControlSession();
  178. STDMETHODIMP OnChannelOpening();
  179. STDMETHODIMP OnChannelOpen(DWORD dwStatus);
  180. STDMETHODIMP OnChannelClose(DWORD dwStatus);
  181. STDMETHODIMP_(UINT) Reset(VOID);
  182. STDMETHODIMP_(BOOL) SelectPorts(LPIControlChannel pCtlChannel);
  183. STDMETHODIMP_(PSOCKADDR_IN) GetLocalAddress();
  184. STDMETHODIMP_(PORT) GetLocalRTPPort();
  185. STDMETHODIMP_(PORT) GetLocalRTCPPort ();
  186. STDMETHODIMP AcceptRemoteAddress (PSOCKADDR_IN pSinD);
  187. STDMETHODIMP AcceptRemoteRTCPAddress(PSOCKADDR_IN pSinC);
  188. STDMETHODIMP_(BOOL) IsSendChannel () {return bIsSendDirection;};
  189. STDMETHODIMP_(BOOL) IsChannelOpen(){return ((m_dwFlags & COMCH_OPEN) !=0);};
  190. STDMETHODIMP_(BOOL) IsOpenPending(){return ((m_dwFlags & COMCH_OPEN_PENDING ) !=0);};
  191. STDMETHODIMP_(BOOL) IsChannelEnabled(){return ((m_dwFlags & COMCH_ENABLED ) !=0);};
  192. STDMETHODIMP ConfigureCapability(LPVOID lpvRemoteChannelParams, UINT uRemoteParamSize,
  193. LPVOID lpvLocalParams, UINT uLocalParamSize);
  194. STDMETHODIMP GetLocalParams(LPVOID lpvChannelParams, UINT uBufSize);
  195. STDMETHODIMP_(PVOID) GetRemoteParams(VOID) {return pRemoteParams;}
  196. STDMETHODIMP_(VOID) SetNegotiatedLocalFormat(DWORD dwF) {m_LocalFmt = dwF;};
  197. STDMETHODIMP_(VOID) SetNegotiatedRemoteFormat(DWORD dwF) {m_RemoteFmt = dwF;};
  198. STDMETHODIMP_(DWORD_PTR) GetHChannel(VOID) {return dwhChannel;};
  199. STDMETHODIMP_(VOID) SetHChannel (DWORD_PTR dwSetChannel) {dwhChannel = dwSetChannel;};
  200. // ICommChannel Methods
  201. STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR * ppvObj);
  202. STDMETHOD_(ULONG,AddRef());
  203. STDMETHOD_(ULONG,Release());
  204. STDMETHOD(GetProperty(DWORD prop, PVOID pBuf, LPUINT pcbBuf));
  205. STDMETHOD(SetProperty(DWORD prop, PVOID pBuf, UINT cbBuf));
  206. STDMETHOD(IsChannelOpen(BOOL *pbOpen));
  207. STDMETHOD(Open(MEDIA_FORMAT_ID idLocalFormat,IH323Endpoint *pConnection));
  208. STDMETHOD(Close());
  209. STDMETHOD(SetAdviseInterface(IH323ConfAdvise *pH323ConfAdvise));
  210. STDMETHOD(EnableOpen(BOOL bEnable));
  211. STDMETHODIMP GetMediaType(LPGUID pGuid);
  212. STDMETHODIMP_(IMediaChannel *) GetMediaChannel(VOID) {return m_pMediaStream;};
  213. STDMETHOD(Preview(MEDIA_FORMAT_ID idLocalFormat, IMediaChannel * pMediaChannel));
  214. STDMETHOD(PauseNetworkStream(BOOL fPause));
  215. STDMETHOD_(BOOL, IsNetworkStreamPaused(VOID));
  216. STDMETHOD_(BOOL, IsRemotePaused(VOID));
  217. STDMETHODIMP_(MEDIA_FORMAT_ID) GetConfiguredFormatID() {return m_LocalFmt;};
  218. STDMETHODIMP GetRemoteAddress(PSOCKADDR_IN pAddrOutput);
  219. // IStreamSignal Methods
  220. STDMETHOD(PictureUpdateRequest());
  221. STDMETHOD(GetVersionInfo(
  222. PCC_VENDORINFO* ppLocalVendorInfo, PCC_VENDORINFO *ppRemoteVendorInfo));
  223. ImpICommChan ();
  224. ~ImpICommChan ();
  225. };
  226. #endif // _ICOMCHAN_H
  227.