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.

351 lines
7.3 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // Module: rdpsndc.h
  4. //
  5. // Purpose: Client-side audio redirection
  6. //
  7. // Copyright(C) Microsoft Corporation 2000
  8. //
  9. // History: 4-10-2000 vladimis [created]
  10. //
  11. /////////////////////////////////////////////////////////////////////
  12. #include <malloc.h>
  13. #include <winsock.h>
  14. #ifdef OS_WINCE
  15. #include "wsasync.h"
  16. #endif // OS_WINCE
  17. #include <mmsystem.h>
  18. #include "vcint.h"
  19. #include "rdpsndp.h"
  20. #ifndef INVALID_CHANNELID
  21. #define INVALID_CHANNELID ((DWORD)(-1))
  22. #endif
  23. #define MAX_UDP_SIZE 0x10000
  24. typedef struct _FRAGSLOT
  25. {
  26. DWORD dwAllocatedSize;
  27. BOOL bUsed;
  28. BYTE cBlockNo;
  29. DWORD dwBlockNo;
  30. DWORD dwFragSize;
  31. DWORD dwTotalSize;
  32. DWORD dwExpectedTotalSize;
  33. UINT16 wTimeStamp;
  34. UINT16 wFormatNo;
  35. PBYTE pData;
  36. struct _FRAGSLOT *pNext;
  37. } FRAGSLOT, *PFRAGSLOT;
  38. class CRDPSound {
  39. public:
  40. CRDPSound(
  41. PCHANNEL_ENTRY_POINTS_EX pEntries,
  42. PVOID pInitHandle
  43. ) :
  44. m_pInitHandle( pInitHandle ),
  45. m_dwChannel( INVALID_CHANNELID ),
  46. m_hWave( NULL ),
  47. m_hMsgWindow( NULL ),
  48. m_hDGramSocket( INVALID_SOCKET ),
  49. m_dwRemoteDGramPort( 0 ),
  50. m_ulRemoteDGramAddress( 0 ),
  51. m_bPrologReceived( FALSE ),
  52. m_dwBytesInProlog( 0 ),
  53. m_dwPrologAllocated( 0 ),
  54. m_pProlog( NULL ),
  55. m_dwBytesInBody( 0 ),
  56. m_dwBodyAllocated( 0 ),
  57. m_pMsgBody( NULL ),
  58. #if DBG
  59. m_lTimesWaveOutOpened( 0 ),
  60. m_lPrepdBlocks( 0 ),
  61. #endif
  62. m_ppFormats( NULL ),
  63. m_dwNumFormats( 0 ),
  64. m_dwCurrentFormat( 0 ),
  65. m_pFirstWave( NULL ),
  66. m_pLastWave( NULL ),
  67. m_dwWavesPlaying( 0 ),
  68. m_wServerVersion( 0 ),
  69. m_pFragSlots( NULL )
  70. {
  71. m_hInst = GetModuleHandle( NULL );
  72. memcpy( &m_ChannelEntries, pEntries, sizeof( m_ChannelEntries ));
  73. }
  74. //
  75. // virtual channel members
  76. //
  77. VOID
  78. InitEventFn(
  79. PVOID pInitHandle,
  80. UINT event,
  81. PVOID pData,
  82. UINT dataLength
  83. );
  84. VOID
  85. OpenEventFn(
  86. DWORD OpenHandle,
  87. UINT event,
  88. PVOID pData,
  89. UINT32 dataLength,
  90. UINT32 totalLength,
  91. UINT32 dataFlags
  92. );
  93. BOOL
  94. ChannelWriteNCopy(
  95. LPVOID pBuffer,
  96. UINT32 uiSize
  97. );
  98. BOOL
  99. ChannelWrite(
  100. HANDLE hGlobMem,
  101. UINT32 uiBlockSize
  102. );
  103. //
  104. // UDP (datagram) communication members
  105. //
  106. BOOL
  107. DGramInit(
  108. VOID
  109. );
  110. u_short
  111. DGramGetLocalPort(
  112. VOID
  113. );
  114. BOOL
  115. DGramSend(
  116. LPVOID pData,
  117. DWORD dwSize
  118. );
  119. BOOL
  120. DGramRecvWave(
  121. PSNDWAVE pSndWave,
  122. DWORD dwSize
  123. );
  124. VOID
  125. DGramSocketMessage(
  126. WPARAM wParam,
  127. LPARAM lParam
  128. );
  129. VOID
  130. DGramDone(
  131. VOID
  132. );
  133. //
  134. // received message demultiplexer
  135. //
  136. VOID
  137. DataArrived(
  138. PSNDPROLOG pProlog,
  139. LPVOID pBody
  140. );
  141. //
  142. // event/notifications demultiplexer members
  143. // (i.e. message window)
  144. //
  145. BOOL
  146. CreateMsgWindow(
  147. HINSTANCE hInstance
  148. );
  149. VOID
  150. DestroyMsgWindow(
  151. VOID
  152. );
  153. //
  154. // waveOut/waveFormat/dynamic sound resampling members
  155. //
  156. VOID
  157. vcwaveCallback(
  158. HWAVEOUT hWave,
  159. UINT uMsg,
  160. LPWAVEHDR lpWaveHdr
  161. );
  162. VOID
  163. vcwaveGetDevCaps(
  164. PSNDFORMATMSG pFmtMsg
  165. );
  166. BOOL
  167. vcwaveChooseSoundFormat(
  168. DWORD dwNumberOfFormats,
  169. PSNDFORMATITEM pSndFormats,
  170. PSNDFORMATITEM *ppSndFormatFound,
  171. DWORD *pdwListSize,
  172. DWORD *pdwNumFormats
  173. );
  174. VOID
  175. vcwaveCleanSoundFormats(
  176. VOID
  177. );
  178. BOOL
  179. vcwaveSaveSoundFormats(
  180. PSNDFORMATITEM pSndFormats,
  181. DWORD dwNumFormats
  182. );
  183. VOID
  184. vcwaveClose(
  185. VOID
  186. );
  187. BOOL
  188. vcwaveOpen(
  189. LPWAVEFORMATEX pFormat
  190. );
  191. VOID
  192. vcwaveFreeAllWaves(
  193. VOID
  194. );
  195. MMRESULT
  196. vcwaveOutWrite(
  197. LPWAVEHDR lpWaveHdr
  198. );
  199. BOOL
  200. vcwaveWrite(
  201. BYTE cBlockNo,
  202. DWORD dwFormatNo,
  203. DWORD dwTimeStamp,
  204. DWORD dwWaveDataLen,
  205. LPVOID pData
  206. );
  207. VOID
  208. vcwaveResample(
  209. VOID
  210. );
  211. VOID
  212. SL_Signature(
  213. PBYTE pSig,
  214. DWORD dwBlockNo
  215. );
  216. VOID
  217. SL_AudioSignature(
  218. PBYTE pSig,
  219. DWORD dwBlockNo,
  220. PBYTE pData,
  221. DWORD dwDataSize
  222. );
  223. BOOL
  224. SL_Encrypt(
  225. PBYTE pBits,
  226. DWORD BlockNo,
  227. DWORD dwBitsLen
  228. );
  229. private:
  230. BOOL
  231. ConstructFromDGramFrags(
  232. PSNDUDPWAVE pWave,
  233. DWORD dwSize,
  234. PSNDWAVE pReady,
  235. DWORD dwReadySize
  236. );
  237. BOOL
  238. ConstructFromDGramLastFrag(
  239. PSNDUDPWAVELAST pLast,
  240. DWORD dwSize,
  241. PSNDWAVE pReady,
  242. DWORD dwReadySize
  243. );
  244. BOOL
  245. _FragSlotFind(
  246. PFRAGSLOT *ppFragSlot,
  247. BYTE cBlockNo,
  248. DWORD dwEstimatedSize
  249. );
  250. VOID
  251. _FragSlotClear(
  252. PFRAGSLOT pSlot
  253. );
  254. BOOL
  255. _FragSlotToWave(
  256. PFRAGSLOT pSlot,
  257. PSNDWAVE pWave,
  258. DWORD dwWaveSize
  259. );
  260. VOID _FragSlotFreeAll( VOID );
  261. CHANNEL_ENTRY_POINTS_EX m_ChannelEntries;
  262. PVOID m_pInitHandle;
  263. DWORD m_dwChannel;
  264. HWAVEOUT m_hWave;
  265. BYTE m_cLastReceivedBlock;
  266. HWND m_hMsgWindow;
  267. SOCKET m_hDGramSocket;
  268. DWORD m_dwRemoteDGramPort;
  269. ULONG m_ulRemoteDGramAddress;
  270. DWORD m_wServerVersion;
  271. // receive buffers
  272. //
  273. BOOL m_bPrologReceived;
  274. DWORD m_dwBytesInProlog;
  275. DWORD m_dwPrologAllocated;
  276. LPVOID m_pProlog;
  277. DWORD m_dwBytesInBody;
  278. DWORD m_dwBodyAllocated;
  279. LPVOID m_pMsgBody;
  280. #ifdef DBG
  281. LONG m_lTimesWaveOutOpened;
  282. LONG m_lPrepdBlocks;
  283. #endif
  284. //
  285. // format cache
  286. //
  287. PSNDFORMATITEM *m_ppFormats;
  288. DWORD m_dwNumFormats;
  289. DWORD m_dwCurrentFormat;
  290. //
  291. // pending play blocks
  292. //
  293. LPWAVEHDR m_pFirstWave;
  294. LPWAVEHDR m_pLastWave;
  295. DWORD m_dwWavesPlaying;
  296. HINSTANCE m_hInst;
  297. BYTE m_EncryptKey[RANDOM_KEY_LENGTH + 4];
  298. PFRAGSLOT m_pFragSlots;
  299. };