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.

347 lines
10 KiB

  1. /*++
  2. Copyright (c) 1995-1996 Microsoft Corporation
  3. Module Name:
  4. datapump.h
  5. Abstract:
  6. Contains constants and class declarations for the DataPump object. The DataPump controls
  7. the streaming of audio/video information between the network and the local record/playback
  8. source. It contains or references several subclasses that deal with the multimedia devices,
  9. compression apis, buffer streaming and the network transport.
  10. --*/
  11. #ifndef _DATAPUMP_H_
  12. #define _DATAPUMP_H_
  13. #include "PacketSender.h"
  14. #include "imstream.h"
  15. #include "ThreadEvent.h"
  16. #include <pshpack8.h> /* Assume 8 byte packing throughout */
  17. typedef HANDLE DPHANDLE;
  18. //move this to nac..
  19. #define MEDIA_ID_AUDIO 1
  20. #define MEDIA_ID_VIDEO 2
  21. #define DEF_SILENCE_LIMIT 10
  22. #define DEF_MISSING_LIMIT 10
  23. #define DP_PROP_DUPLEX_TYPE 100 // internal version of PROP_DUPLEX_TYPE
  24. // needs to be above the PROP_xxx range in iprop.h
  25. #define DP_MASK_PLATFORM 0xFF000000UL
  26. #define DP_FLAG_ACM 0x01000000UL
  27. #define DP_FLAG_QUARTZ 0x02000000UL
  28. #define DP_FLAG_MMSYSTEM 0x04000000UL
  29. #define DP_FLAG_AUDIO DP_FLAG_MMSYSTEM
  30. #define DP_FLAG_DIRECTSOUND 0x08000000UL
  31. #define DP_FLAG_VCM 0x10000000UL
  32. #define DP_FLAG_VIDEO 0x20000000UL
  33. #define DP_MASK_TRANSPORT 0x00F00000UL
  34. #define DP_FLAG_SEND 0x00100000UL
  35. #define DP_FLAG_RECV 0x00200000UL
  36. #define DP_MASK_DUPLEX 0x00030000UL
  37. #define DP_FLAG_HALF_DUPLEX 0x00010000UL
  38. #define DP_FLAG_FULL_DUPLEX 0x00020000UL
  39. #define DP_MASK_WAVE_DEVICE 0x00000300UL
  40. #define DP_FLAG_PLAY_CAP 0x00000100UL
  41. #define DP_FLAG_RECORD_CAP 0x00000200UL
  42. #define DP_MASK_VOICESWITCH 0x00007000UL // used to r/w mode of voice switching
  43. #define DP_FLAG_AUTO_SWITCH 0x00001000UL // MODE:normal operation
  44. #define DP_FLAG_MIC_ON 0x00002000UL // MODE:manual "talk" control
  45. #define DP_FLAG_MIC_OFF 0x00004000UL // MODE:"mute"
  46. #define DP_FLAG_AUTO_SILENCE_DETECT 0x00008000 // use auto thresholding (when auto-switching)
  47. // m_DPFlags is made up of the following plus some of the DP_XXX flags above
  48. #define DPFLAG_INITIALIZED 0x00000001
  49. #define DPFLAG_STARTED_SEND 0x00000002
  50. #define DPFLAG_STARTED_RECV 0x00000004
  51. #define DPFLAG_CONFIGURED_SEND 0x00000008
  52. #define DPFLAG_CONFIGURED_RECV 0x00000010
  53. #define DPFLAG_ENABLE_PREVIEW 0x00000020 // preview mode (video)
  54. #define DPFLAG_AV_SYNC 0x00000040 // enable synchronization
  55. #define DPFLAG_REAL_THING 0x00000080 // Allows distinction between preview and real call in Configure/Unconfigure
  56. #define DPFLAG_ENABLE_SEND 0x00400000 // packets are recorded and sent
  57. #define DPFLAG_ENABLE_RECV 0x00800000 // packets are recved and played
  58. // ThreadFlags
  59. #define DPTFLAG_STOP_MASK 0xFF
  60. #define DPTFLAG_STOP_SEND 0x1
  61. #define DPTFLAG_STOP_RECV 0x2
  62. #define DPTFLAG_STOP_RECORD 0x4
  63. #define DPTFLAG_STOP_PLAY 0x8
  64. #define DPTFLAG_PAUSE_RECV 0x10
  65. #define DPTFLAG_PAUSE_SEND 0x20
  66. #define DPTFLAG_PAUSE_CAPTURE 0x40
  67. #define DPTFLAG_SEND_PREAMBLE 0x100 // send I frames
  68. #define MAX_MMIO_PATH 128
  69. // the number of times the device must "fail" before a
  70. // stream event notification gets sent
  71. #define MAX_FAILCOUNT 3
  72. typedef struct tagMMIOSRC
  73. {
  74. BOOL fPlayFromFile;
  75. HMMIO hmmioSrc;
  76. MMCKINFO ckSrc;
  77. MMCKINFO ckSrcRIFF;
  78. DWORD dwDataLength;
  79. DWORD dwMaxDataLength;
  80. TCHAR szInputFileName[MAX_MMIO_PATH];
  81. BOOL fLoop;
  82. BOOL fStart;
  83. BOOL fStop;
  84. BOOL fDisconnectAfterPlayback;
  85. WAVEFORMATEX wfx;
  86. } MMIOSRC;
  87. typedef struct tagMMIODEST
  88. {
  89. BOOL fRecordToFile;
  90. HMMIO hmmioDst;
  91. MMCKINFO ckDst;
  92. MMCKINFO ckDstRIFF;
  93. DWORD dwDataLength;
  94. DWORD dwMaxDataLength;
  95. TCHAR szOutputFileName[MAX_MMIO_PATH];
  96. } MMIODEST;
  97. namespace AudioFile
  98. {
  99. HRESULT OpenSourceFile(MMIOSRC *pSrcFile, WAVEFORMATEX *pwf);
  100. HRESULT ReadSourceFile(MMIOSRC *pSrcFile, BYTE *pData, DWORD dwBytesToRead);
  101. HRESULT CloseSourceFile(MMIOSRC *pSrcFile);
  102. HRESULT OpenDestFile(MMIODEST *pDestFile, WAVEFORMATEX *pwf);
  103. HRESULT WriteDestFile(MMIODEST *pDestFile, BYTE *pData, DWORD dwBytesToWrite);
  104. HRESULT CloseDestFile(MMIODEST *pDestFile);
  105. };
  106. extern HANDLE g_hEventHalfDuplex;
  107. #define MAX_TIMESTAMP 0xffffffffUL
  108. /*
  109. TTimeout is used to schedule a thread timeout notification and is used along with
  110. the ThreadTimer class.
  111. Derive from the TTimeOut abstract class by defining the TimeoutIndication virtual function and
  112. pass an instance of the derived class to ThreadTimer::SetTimeout() after setting the time interval.
  113. */
  114. class TTimeout
  115. {
  116. public:
  117. TTimeout() {pNext = pPrev = this;}
  118. void SetDueTime(DWORD msWhen) {m_DueTime = msWhen;}
  119. DWORD GetDueTime(void) {return m_DueTime;}
  120. friend class ThreadTimer;
  121. private:
  122. class TTimeout *pNext; // ptrs for doubly-linked-list
  123. class TTimeout *pPrev; //
  124. DWORD m_DueTime; // absolute time when this will fire
  125. void InsertAfter(class TTimeout *pFirst) {
  126. pNext = pFirst->pNext;
  127. pPrev = pFirst;
  128. pFirst->pNext = this;
  129. pNext->pPrev = this;
  130. };
  131. void Remove(void) {
  132. pNext->pPrev = pPrev;
  133. pPrev->pNext = pNext;
  134. pNext = this; // make next and prev self-referential so that Remove() is idempotent
  135. pPrev = this;
  136. }
  137. protected:
  138. virtual void TimeoutIndication() {};
  139. };
  140. /*
  141. Implements a mechanism for a worker thread to schedule timeouts.
  142. The client calls SetTimeout(TTimeout *) to schedule an interval callback and CancelTimeout()
  143. to cancel a scheduled timeout. The main loop of the worker thread must call UpdateTime(curTime) periodically, at
  144. which point any elapsed timeouts will be triggered. UpdateTime() returns the time when it next needs to be called,
  145. which is usually the time of the earliest scheduled timeout.
  146. NOTE: All methods are expected to be called from the same thread so there is no need for critical sections..
  147. */
  148. class ThreadTimer {
  149. public:
  150. void SetTimeout(TTimeout *pTObj);
  151. void CancelTimeout(TTimeout *pTObj);
  152. DWORD UpdateTime (DWORD curTime);
  153. private:
  154. TTimeout m_TimeoutList;
  155. DWORD m_CurTime;
  156. BOOL IsEmpty() {return (&m_TimeoutList == m_TimeoutList.pNext);}
  157. };
  158. //flags for Start()/Stop()
  159. #define DP_STREAM_SEND 1
  160. #define DP_STREAM_RECV 2
  161. // Number of video frames used to compute QoS stats
  162. // We need at least 30 entries since the max frames
  163. // per sec capture rate is 30. 32 allows us to figure
  164. // out the integer stats per frame using a simple shift.
  165. #define NUM_QOS_VID_ENTRIES 32
  166. // The sizes of the IP and UDP header added to each packet
  167. // need to be added to the size of the compressed packet
  168. #define IP_HEADER_SIZE 20
  169. #define UDP_HEADER_SIZE 8
  170. class MediaStream;
  171. class SendMediaStream;
  172. class RecvMediaStream;
  173. class DataPump : public IMediaChannelBuilder, public IVideoDevice, public IAudioDevice
  174. {
  175. friend class SendAudioStream;
  176. friend class RecvAudioStream;
  177. friend class RecvDSAudioStream;
  178. public:
  179. DataPump();
  180. ~DataPump();
  181. // IMediaChannelBuilder
  182. STDMETHODIMP Initialize(HWND hWnd, HINSTANCE hInst);
  183. STDMETHODIMP CreateMediaChannel(UINT flags, IMediaChannel **ppObj);
  184. STDMETHODIMP SetStreamEventObj(IStreamEventNotify *pNotify);
  185. // Internal
  186. void AddMediaChannel(UINT flags, IMediaChannel *pMediaChannel);
  187. void RemoveMediaChannel(UINT flags, IMediaChannel *pMediaChannel);
  188. HRESULT GetMediaChannelInterface(UINT flags, IMediaChannel **ppI);
  189. HRESULT StartReceiving(RecvMediaStream *pMS);
  190. HRESULT StopReceiving(RecvMediaStream *pMS);
  191. void ReleaseResources();
  192. STDMETHODIMP StreamEvent(UINT uDirection, UINT uMediaType,
  193. UINT uEventType, UINT uSubCode);
  194. // IUnknown methods
  195. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  196. STDMETHODIMP_(ULONG) AddRef();
  197. STDMETHODIMP_(ULONG) Release();
  198. // IQOS interface pointer and two resources requests: one for BW and one for CPU
  199. LPIQOS m_pIQoS;
  200. // Recv thread timeout scheduler
  201. ThreadTimer m_RecvTimer;
  202. CRITICAL_SECTION m_crs; // serializes access to multithread-safe methods
  203. // the app handles are global
  204. static HWND m_hAppWnd;
  205. static HINSTANCE m_hAppInst;
  206. PacketSender m_PacketSender;
  207. ThreadEventProxy *m_pTEP;
  208. BOOL m_bDisableRSVP;
  209. // IVideoDevice Methods
  210. // Capture Device related methods
  211. HRESULT __stdcall GetNumCapDev();
  212. HRESULT __stdcall GetMaxCapDevNameLen();
  213. HRESULT __stdcall EnumCapDev(DWORD *pdwCapDevIDs, TCHAR *pszCapDevNames, DWORD dwNumCapDev);
  214. HRESULT __stdcall GetCurrCapDevID();
  215. HRESULT __stdcall SetCurrCapDevID(int nCapDevID);
  216. // IAudioDevice Methods
  217. HRESULT __stdcall GetRecordID(UINT *puWaveDevID);
  218. HRESULT __stdcall SetRecordID(UINT uWaveDevID);
  219. HRESULT __stdcall GetPlaybackID(UINT *puWaveDevID);
  220. HRESULT __stdcall SetPlaybackID(UINT uWaveDevID);
  221. HRESULT __stdcall GetDuplex(BOOL *pbFullDuplex);
  222. HRESULT __stdcall SetDuplex(BOOL bFullDuplex);
  223. HRESULT __stdcall GetSilenceLevel(UINT *puLevel);
  224. HRESULT __stdcall SetSilenceLevel(UINT uLevel);
  225. HRESULT __stdcall GetAutoMix(BOOL *pbAutoMix);
  226. HRESULT __stdcall SetAutoMix(BOOL bAutoMix);
  227. HRESULT __stdcall GetDirectSound(BOOL *pbDS);
  228. HRESULT __stdcall SetDirectSound(BOOL bDS);
  229. HRESULT __stdcall GetMixer(HWND hwnd, BOOL bPlayback, IMixer **ppMixer);
  230. protected:
  231. struct MediaChannel {
  232. public:
  233. SendMediaStream *pSendStream;
  234. RecvMediaStream *pRecvStream;
  235. }
  236. m_Audio, m_Video;
  237. UINT m_uRef;
  238. // receive thread stuff
  239. HANDLE m_hRecvThread;
  240. DWORD m_RecvThId,m_nReceivers;
  241. HANDLE m_hRecvThreadAckEvent; // ack from recv thread
  242. // temp variables for communicating with recv thread
  243. HANDLE m_hRecvThreadSignalEvent; // signal to recv thread
  244. RecvMediaStream *m_pCurRecvStream;
  245. UINT m_CurRecvMsg;
  246. friend DWORD __stdcall StartDPRecvThread(PVOID pDP); // pDP == pointer to DataPump
  247. DWORD CommonRecvThread(void);
  248. DWORD CommonWS2RecvThread(void);
  249. HRESULT RecvThreadMessage(UINT msg, RecvMediaStream *pMS);
  250. HRESULT SetStreamDuplex(IMediaChannel *pStream, BOOL bFullDuplex);
  251. // datapump only needs to keep track of the device ID for
  252. // video. Gets a bit more complicated for Audio.
  253. UINT m_uVideoCaptureId;
  254. // IAudioDevice stuff
  255. UINT m_uWaveInID;
  256. UINT m_uWaveOutID;
  257. BOOL m_bFullDuplex;
  258. UINT m_uSilenceLevel; // 0-999 (manual) 1000- (automatic)
  259. BOOL m_bAutoMix;
  260. BOOL m_bDirectSound;
  261. };
  262. // messages used to signal recv thread
  263. // must not conflict with message ids used by AsyncSock
  264. #define MSG_START_RECV (WM_USER + 20)
  265. #define MSG_STOP_RECV (WM_USER + 21)
  266. #define MSG_EXIT_RECV (WM_USER + 22)
  267. #define MSG_PLAY_SOUND (WM_USER + 23)
  268. #include <poppack.h> /* End byte packing */
  269. #endif //_DATAPUMP_H