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.

275 lines
13 KiB

  1. /*==========================================================================
  2. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  3. *
  4. * File: dvserverengine.h
  5. * Content: Definition of class for DirectXVoice Server
  6. * History:
  7. * Date By Reason
  8. * ==== == ======
  9. * 07/06/99 rodtoll Created It
  10. * 07/21/99 rodtoll Added settings confirm message to protocol.
  11. * 07/22/99 rodtoll Added multiple reader/single writer guard to class
  12. * 07/23/99 rodtoll Additional members for client/server and multicast
  13. * 07/26/99 rodtoll Added support for new interfaces and access for DIRECTVOICESERVEROBJECT
  14. * 08/25/99 rodtoll General Cleanup/Modifications to support new
  15. * compression sub-system.
  16. * Added parameter to the GetCompression Func
  17. * 09/14/99 rodtoll Added new SetNotifyMask function
  18. * rodtoll Updated Iniitalize parameters to take notification masks.
  19. * rodtoll Implemented notification masks. (Allows user to choose which notifications to receive)
  20. * 10/29/99 rodtoll Bug #113726 - Integrate Voxware Codecs, updating to use new
  21. * pluggable codec architecture.
  22. * 11/23/99 rodtoll Updated Initialize/SetNotifyMask so error checking behaviour is consistant
  23. * 12/16/99 rodtoll Fix: Bug #122629 - Host migration broken in unusual configurations.
  24. * Updated to use new algorithm described in dvprot.h
  25. * - Generate and added host order IDs to player table messages
  26. * - Added send of new hostmigrateleave message when shutting down and
  27. * host should migrate
  28. * - Sends session lost when shutting down if no one available to take over hosting
  29. * - Added new player list message
  30. * - Fixed handling of refusing player connections
  31. * 01/14/2000 rodtoll Updated to allow multiple targets for a single player
  32. * rodtoll Updated to use FPM for managing memory for Multicast mode
  33. * rodtoll Updated to use new callback semantics
  34. * 03/29/2000 rodtoll Bug #30753 - Added volatile to the class definition
  35. * 04/07/2000 rodtoll Bug #32179 - Prevent registration of > 1 interface
  36. * rodtoll Updated to use no copy sends, so handles pooling frames to be sent, proper
  37. * pulling of frames from pools and returns.
  38. * 07/09/2000 rodtoll Added signature bytes
  39. * 11/16/2000 rodtoll Bug #40587 - DPVOICE: Mixing server needs to use multi-processors
  40. * 11/28/2000 rodtoll Bug #47333 - DPVOICE: Server controlled targetting - invalid targets are not removed automatically
  41. * 04/06/2001 kareemc Added Voice Defense
  42. * 02/28/2002 rodtoll WINBUG #549959 - SECURITY: DPVOICE: Voice server trusts client's target list
  43. * - Update receive path to use server's copy of client target list when server controlled targetting enabled
  44. * rodtoll WINBUG #549943 - SECURITY: DPVOICE: Possible corruption of voice server state
  45. * - Harden receive paths - i.e. ensure host migration processing only when host migration available,
  46. * prevent double disconnects from crashing server
  47. * rodtoll WINBUG #550124 - SECURITY: DPVOICE: Shared memory region with NULL DACL
  48. * - Remove performance statistics dumping to shared memory
  49. * 06/13/2002 simonpow BUG #59944 Switched over to using Threadpool based timers rather than multimedia
  50. ***************************************************************************/
  51. #ifndef __DVSERVERENGINE_H
  52. #define __DVSERVERENGINE_H
  53. struct DIRECTVOICESERVEROBJECT;
  54. typedef struct _MIXERTHREAD_CONTROL *PMIXERTHREAD_CONTROL;
  55. #define DVSSTATE_NOTINITIALIZED 0x00000000
  56. #define DVSSTATE_IDLE 0x00000001
  57. #define DVSSTATE_STARTUP 0x00000002
  58. #define DVSSTATE_RUNNING 0x00000003
  59. #define DVSSTATE_SHUTDOWN 0x00000004
  60. // CDirectVoiceClientEngine
  61. //
  62. // This class represents the IDirectXVoiceServer interface.
  63. //
  64. #define VSIG_SERVERENGINE 'EVSV'
  65. #define VSIG_SERVERENGINE_FREE 'EVS_'
  66. //
  67. volatile class CDirectVoiceServerEngine: public CDirectVoiceEngine
  68. {
  69. public:
  70. CDirectVoiceServerEngine( DIRECTVOICESERVEROBJECT *lpObject );
  71. ~CDirectVoiceServerEngine();
  72. public: // IDirectXVoiceServer Interface
  73. HRESULT HostMigrateStart(LPDVSESSIONDESC lpSessionDesc, DWORD dwHostOrderIDSeed = 0 );
  74. virtual HRESULT StartSession(LPDVSESSIONDESC lpSessionDesc, DWORD dwFlags, DWORD dwHostOrderIDSeed = 0 );
  75. virtual HRESULT StopSession(DWORD dwFlags, BOOL fSilent=FALSE, HRESULT hrResult = DV_OK );
  76. virtual HRESULT GetSessionDesc(LPDVSESSIONDESC lpSessionDescBuffer );
  77. virtual HRESULT SetSessionDesc(LPDVSESSIONDESC lpSessionDesc );
  78. HRESULT GetCaps(LPDVCAPS dvCaps);
  79. static HRESULT GetCompressionTypes( LPVOID lpBuffer, LPDWORD lpdwBufferSize, LPDWORD lpdwNumElements, DWORD dwFlags);
  80. virtual HRESULT SetTransmitTarget(DVID dvidSource, PDVID pdvidTargets, DWORD dwNumTargets, DWORD dwFlags);
  81. virtual HRESULT GetTransmitTarget(DVID dvidSource, LPDVID lpdvidTargets, PDWORD pdwNumElements, DWORD dwFlags );
  82. virtual HRESULT MigrateHost( DVID dvidNewHost, LPDIRECTPLAYVOICESERVER lpdvServer );
  83. virtual HRESULT SetNotifyMask( LPDWORD lpdwMessages, DWORD dwNumElements );
  84. public: // CDirectVoiceEngine Members
  85. HRESULT Initialize( CDirectVoiceTransport *lpTransport, LPDVMESSAGEHANDLER lpdvHandler, LPVOID lpUserContext, LPDWORD lpdwMessages, DWORD dwNumElements );
  86. virtual BOOL ReceiveSpeechMessage( DVID dvidSource, LPVOID lpMessage, DWORD dwSize );
  87. HRESULT StartTransportSession();
  88. HRESULT StopTransportSession();
  89. HRESULT AddPlayer( DVID dvID );
  90. HRESULT RemovePlayer( DVID dvID );
  91. HRESULT CreateGroup( DVID dvID );
  92. HRESULT DeleteGroup( DVID dvID );
  93. HRESULT AddPlayerToGroup( DVID dvidGroup, DVID dvidPlayer );
  94. HRESULT RemovePlayerFromGroup( DVID dvidGroup, DVID dvidPlayer );
  95. inline DWORD GetCurrentState() const { return m_dwCurrentState; };
  96. BOOL InitClass();
  97. public: // packet validation
  98. static inline BOOL ValidateSettingsFlags( DWORD dwFlags );
  99. inline BOOL ValidatePacketType( const DVPROTOCOLMSG_FULLMESSAGE* lpdvFullMessage ) const;
  100. protected: // Protocol Layer Handling (protserver.cpp)
  101. HRESULT Send_SessionLost( HRESULT hrReason );
  102. HRESULT Send_HostMigrateLeave( );
  103. HRESULT Send_HostMigrated();
  104. HRESULT Send_DisconnectConfirm( DVID dvid, HRESULT hrReason );
  105. HRESULT Send_DeletePlayer( DVID dvid );
  106. HRESULT Send_CreatePlayer( DVID dvidTarget, const CVoicePlayer *pPlayer );
  107. HRESULT Send_ConnectRefuse( DVID dvid, HRESULT hrReason );
  108. HRESULT Send_ConnectAccept( DVID dvid );
  109. HRESULT SendPlayerList( DVID dvidSource, DWORD dwHostOrderID );
  110. static BOOL CheckProtocolCompatible( BYTE ucMajor, BYTE ucMinor, DWORD dwBuild );
  111. protected:
  112. BOOL IsHostMigrationEnabled() const;
  113. HRESULT InternalSetNotifyMask( LPDWORD lpdwMessages, DWORD dwNumElements );
  114. void DoPlayerDisconnect( DVID dvidPlayer, BOOL bInformPlayer );
  115. void TransmitMessage( DWORD dwMessageType, LPVOID lpdvData, DWORD dwSize );
  116. void SetCurrentState( DWORD dwState );
  117. HRESULT CreatePlayerEntry( DVID dvidSource, PDVPROTOCOLMSG_SETTINGSCONFIRM lpdvSettingsConfirm, DWORD dwHostOrderID, CVoicePlayer **ppPlayer );
  118. BOOL HandleDisconnect( DVID dvidSource, PDVPROTOCOLMSG_GENERIC lpdvDisconnect, DWORD dwSize );
  119. BOOL HandleConnectRequest( DVID dvidSource, PDVPROTOCOLMSG_CONNECTREQUEST lpdvConnectRequest, DWORD dwSize );
  120. BOOL HandleSettingsConfirm( DVID dvidSource, PDVPROTOCOLMSG_SETTINGSCONFIRM lpdvSettingsConfirm, DWORD dwSize );
  121. static BOOL HandleSettingsReject( DVID dvidSource, PDVPROTOCOLMSG_GENERIC lpdvGeneric, DWORD dwSize );
  122. BOOL HandleSpeechWithTarget( DVID dvidSource, PDVPROTOCOLMSG_SPEECHWITHTARGET lpdvSpeech, DWORD dwSize );
  123. BOOL HandleSpeech( DVID dvidSource, PDVPROTOCOLMSG_SPEECHHEADER lpdvSpeech, DWORD dwSize );
  124. PDVTRANSPORT_BUFFERDESC GetTransmitBuffer( DWORD dwSize, LPVOID *ppvContext );
  125. HRESULT SendComplete( PDVEVENTMSG_SENDCOMPLETE pSendComplete );
  126. void ReturnTransmitBuffer( PVOID pvContext );
  127. HRESULT BuildAndSendTargetUpdate( DVID dvidSource, CVoicePlayer *pPlayerInfo );
  128. BOOL CheckForMigrate( DWORD dwFlags, BOOL fSilent );
  129. HRESULT InformClientsOfMigrate();
  130. void WaitForBufferReturns();
  131. protected: // Client Server specific information (mixserver.cpp)
  132. static DWORD WINAPI MixerWorker( void *lpContext );
  133. static DWORD WINAPI MixerControl( void *pvContext );
  134. static void MixingServerWakeupProc( void * pvUserData );
  135. void HandleMixerThreadError( HRESULT hr );
  136. void Mixer_Buffer_Reset(DWORD dwThreadIndex);
  137. void Mixer_Buffer_MixBuffer( DWORD dwThreadIndex,const unsigned char *source );
  138. void Mixer_Buffer_Normalize( DWORD dwThreadIndex );
  139. HRESULT SetupBuffers();
  140. HRESULT FreeBuffers();
  141. HRESULT StartupClientServer();
  142. HRESULT ShutdownClientServer();
  143. HRESULT ShutdownWorkerThreads();
  144. HRESULT StartWorkerThreads();
  145. HRESULT HandleMixingReceive( CDVCSPlayer *pTargetPlayer, PDVPROTOCOLMSG_SPEECHWITHTARGET pdvSpeechWithtarget, DWORD dwSpeechSize, PBYTE pbSpeechData );
  146. void AddPlayerToMixingAddList( CVoicePlayer *pVoicePlayer );
  147. void UpdateActiveMixingPendingList( DWORD dwThreadIndex, DWORD *pdwNumActive );
  148. void CleanupMixingList();
  149. void SpinWorkToThread( LONG lThreadIndex );
  150. void FindAndRemoveDeadTarget( DVID dvidTargetID );
  151. protected: // Forwarding Server specific funcs (fwdserver.cpp)
  152. static HRESULT StartupMulticast();
  153. static HRESULT ShutdownMulticast();
  154. HRESULT HandleForwardingReceive( CVoicePlayer *pTargetPlayer,PDVPROTOCOLMSG_SPEECHWITHTARGET pdvSpeechWithtarget, DWORD dwSpeechSize, PBYTE pbSpeechData );
  155. void CleanupActiveList();
  156. protected:
  157. DWORD m_dwSignature; // Signature
  158. LPDVMESSAGEHANDLER m_lpMessageHandler; // User message handler
  159. LPVOID m_lpUserContext; // User context for message handler
  160. DVID m_dvidLocal; // DVID of the transport player for this host
  161. DWORD m_dwCurrentState; // Current state of the engine
  162. CDirectVoiceTransport *m_lpSessionTransport; // Transport for the session
  163. DVSESSIONDESC m_dvSessionDesc; // Description of session
  164. DWORD m_dwTransportFlags; // Flags for the transport session
  165. DWORD m_dwTransportSessionType;
  166. // Type of transport session (client/server or peer to peer)
  167. LPDVFULLCOMPRESSIONINFO m_lpdvfCompressionInfo; // Details of current compression type
  168. DWORD m_dwCompressedFrameSize;// Max size of compressed frame
  169. DWORD m_dwUnCompressedFrameSize;
  170. // Size of a single frame uncompressed
  171. DWORD m_dwNumPerBuffer; // Size of playback/record buffers in frames
  172. CFramePool *m_pFramePool; // Pool of frames for the queues
  173. // time of a frame size.
  174. DIRECTVOICESERVEROBJECT *m_lpObject; // Pointer to the COM object this is running in
  175. LPDWORD m_lpdwMessageElements; // Array containing the DVMSGID_XXXX values for all the
  176. // notifications developer wishes to receive.
  177. // If this is NULL all notifications are active
  178. DWORD m_dwNumMessageElements; // # of elements in the m_lpdwMessageElements array
  179. DWORD m_dwNextHostOrderID;
  180. HRESULT m_hrStopSessionResult; // Reason that the session was stopped
  181. BOOL m_mixerEightBit; // Is the mixer format 8-bit
  182. BYTE m_padding[3];
  183. ServerStats *m_pServerStats;
  184. DVCAPS m_dvCaps; // Caps
  185. DNCRITICAL_SECTION m_csClassLock;
  186. DNCRITICAL_SECTION m_csNotifyLock; // Lock protection notification mask
  187. CBilink m_blPlayerActiveList;
  188. DNCRITICAL_SECTION m_csPlayerActiveList;
  189. CVoiceNameTable m_voiceNameTable;
  190. CFixedPool m_fpPlayers;
  191. DNCRITICAL_SECTION m_csHostOrderLock;
  192. DNCRITICAL_SECTION m_csBufferLock;
  193. ServerStats m_dvsServerStatsFixed; // If global memory is unavailable
  194. CFixedPool m_BufferDescPool;
  195. CFixedPool* m_pBufferPools;
  196. DWORD *m_pdwBufferPoolSizes;
  197. DWORD m_dwNumPools;
  198. protected: // Mixing server information
  199. DWORD m_dwNumMixingThreads;
  200. DWORD m_dwMixerSize; // # of samples in the high resolution mixer buffer
  201. DNCRITICAL_SECTION m_csMixingAddList;
  202. HANDLE m_hTickSemaphore; // Semaphore signalled by the timer
  203. HANDLE m_hShutdownMixerEvent; // Event signalled to shutdown the mixer
  204. HANDLE m_hMixerDoneEvent; // Signalled by the mixer thread when it's shutdown
  205. DvTimer * m_pTimer;
  206. PMIXERTHREAD_CONTROL m_prWorkerControl;
  207. DWORD m_dwMixerControlThreadID;
  208. HANDLE m_hMixerControlThread;
  209. MixingServerStats m_statMixingFixed;
  210. MixingServerStats *m_pStats;
  211. DNCRITICAL_SECTION m_csStats;
  212. BOOL m_fCritSecInited;
  213. BOOL m_fHostMigrationEnabled; // Is host migration enabled in this session?
  214. };
  215. #endif