Source code of Windows XP (NT5)
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.

267 lines
12 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. *
  43. ***************************************************************************/
  44. #ifndef __DVSERVERENGINE_H
  45. #define __DVSERVERENGINE_H
  46. struct DIRECTVOICESERVEROBJECT;
  47. typedef struct _MIXERTHREAD_CONTROL *PMIXERTHREAD_CONTROL;
  48. #define DVSSTATE_NOTINITIALIZED 0x00000000
  49. #define DVSSTATE_IDLE 0x00000001
  50. #define DVSSTATE_STARTUP 0x00000002
  51. #define DVSSTATE_RUNNING 0x00000003
  52. #define DVSSTATE_SHUTDOWN 0x00000004
  53. // CDirectVoiceClientEngine
  54. //
  55. // This class represents the IDirectXVoiceServer interface.
  56. //
  57. #define VSIG_SERVERENGINE 'EVSV'
  58. #define VSIG_SERVERENGINE_FREE 'EVS_'
  59. //
  60. volatile class CDirectVoiceServerEngine: public CDirectVoiceEngine
  61. {
  62. public:
  63. CDirectVoiceServerEngine( DIRECTVOICESERVEROBJECT *lpObject );
  64. ~CDirectVoiceServerEngine();
  65. public: // IDirectXVoiceServer Interface
  66. HRESULT HostMigrateStart(LPDVSESSIONDESC lpSessionDesc, DWORD dwHostOrderIDSeed = 0 );
  67. virtual HRESULT StartSession(LPDVSESSIONDESC lpSessionDesc, DWORD dwFlags, DWORD dwHostOrderIDSeed = 0 );
  68. virtual HRESULT StopSession(DWORD dwFlags, BOOL fSilent=FALSE, HRESULT hrResult = DV_OK );
  69. virtual HRESULT GetSessionDesc(LPDVSESSIONDESC lpSessionDescBuffer );
  70. virtual HRESULT SetSessionDesc(LPDVSESSIONDESC lpSessionDesc );
  71. HRESULT GetCaps(LPDVCAPS dvCaps);
  72. HRESULT GetCompressionTypes( LPVOID lpBuffer, LPDWORD lpdwBufferSize, LPDWORD lpdwNumElements, DWORD dwFlags);
  73. virtual HRESULT SetTransmitTarget(DVID dvidSource, PDVID pdvidTargets, DWORD dwNumTargets, DWORD dwFlags);
  74. virtual HRESULT GetTransmitTarget(DVID dvidSource, LPDVID lpdvidTargets, PDWORD pdwNumElements, DWORD dwFlags );
  75. virtual HRESULT MigrateHost( DVID dvidNewHost, LPDIRECTPLAYVOICESERVER lpdvServer );
  76. virtual HRESULT SetNotifyMask( LPDWORD lpdwMessages, DWORD dwNumElements );
  77. public: // CDirectVoiceEngine Members
  78. HRESULT Initialize( CDirectVoiceTransport *lpTransport, LPDVMESSAGEHANDLER lpdvHandler, LPVOID lpUserContext, LPDWORD lpdwMessages, DWORD dwNumElements );
  79. virtual BOOL ReceiveSpeechMessage( DVID dvidSource, LPVOID lpMessage, DWORD dwSize );
  80. HRESULT StartTransportSession();
  81. HRESULT StopTransportSession();
  82. HRESULT AddPlayer( DVID dvID );
  83. HRESULT RemovePlayer( DVID dvID );
  84. HRESULT CreateGroup( DVID dvID );
  85. HRESULT DeleteGroup( DVID dvID );
  86. HRESULT AddPlayerToGroup( DVID dvidGroup, DVID dvidPlayer );
  87. HRESULT RemovePlayerFromGroup( DVID dvidGroup, DVID dvidPlayer );
  88. inline DWORD GetCurrentState() { return m_dwCurrentState; };
  89. BOOL InitClass();
  90. public: // packet validation
  91. inline BOOL ValidateSettingsFlags( DWORD dwFlags );
  92. inline BOOL ValidatePacketType( PDVPROTOCOLMSG_FULLMESSAGE lpdvFullMessage );
  93. protected: // Protocol Layer Handling (protserver.cpp)
  94. HRESULT Send_SessionLost( HRESULT hrReason );
  95. HRESULT Send_HostMigrateLeave( );
  96. HRESULT Send_HostMigrated();
  97. HRESULT Send_DisconnectConfirm( DVID dvid, HRESULT hrReason );
  98. HRESULT Send_DeletePlayer( DVID dvid );
  99. HRESULT Send_CreatePlayer( DVID dvidTarget, CVoicePlayer *pPlayer );
  100. HRESULT Send_ConnectRefuse( DVID dvid, HRESULT hrReason );
  101. HRESULT Send_ConnectAccept( DVID dvid );
  102. HRESULT SendPlayerList( DVID dvidSource, DWORD dwHostOrderID );
  103. BOOL CheckProtocolCompatible( BYTE ucMajor, BYTE ucMinor, DWORD dwBuild );
  104. protected:
  105. HRESULT InternalSetNotifyMask( LPDWORD lpdwMessages, DWORD dwNumElements );
  106. void DoPlayerDisconnect( DVID dvidPlayer, BOOL bInformPlayer );
  107. void TransmitMessage( DWORD dwMessageType, LPVOID lpdvData, DWORD dwSize );
  108. void SetCurrentState( DWORD dwState );
  109. HRESULT CreatePlayerEntry( DVID dvidSource, PDVPROTOCOLMSG_SETTINGSCONFIRM lpdvSettingsConfirm, DWORD dwHostOrderID, CVoicePlayer **ppPlayer );
  110. BOOL HandleDisconnect( DVID dvidSource, PDVPROTOCOLMSG_GENERIC lpdvDisconnect, DWORD dwSize );
  111. BOOL HandleConnectRequest( DVID dvidSource, PDVPROTOCOLMSG_CONNECTREQUEST lpdvConnectRequest, DWORD dwSize );
  112. BOOL HandleSettingsConfirm( DVID dvidSource, PDVPROTOCOLMSG_SETTINGSCONFIRM lpdvSettingsConfirm, DWORD dwSize );
  113. BOOL HandleSettingsReject( DVID dvidSource, PDVPROTOCOLMSG_GENERIC lpdvGeneric, DWORD dwSize );
  114. BOOL HandleSpeechWithTarget( DVID dvidSource, PDVPROTOCOLMSG_SPEECHWITHTARGET lpdvSpeech, DWORD dwSize );
  115. BOOL HandleSpeech( DVID dvidSource, PDVPROTOCOLMSG_SPEECHHEADER lpdvSpeech, DWORD dwSize );
  116. PDVTRANSPORT_BUFFERDESC GetTransmitBuffer( DWORD dwSize, LPVOID *ppvContext );
  117. HRESULT SendComplete( PDVEVENTMSG_SENDCOMPLETE pSendComplete );
  118. void ReturnTransmitBuffer( PVOID pvContext );
  119. HRESULT BuildAndSendTargetUpdate( DVID dvidSource, CVoicePlayer *pPlayerInfo );
  120. BOOL CheckForMigrate( DWORD dwFlags, BOOL fSilent );
  121. HRESULT InformClientsOfMigrate();
  122. void WaitForBufferReturns();
  123. protected: // Client Server specific information (mixserver.cpp)
  124. static DWORD WINAPI MixerWorker( void *lpContext );
  125. static DWORD WINAPI MixerControl( void *pvContext );
  126. static BOOL MixingServerWakeupProc( DWORD_PTR param );
  127. void HandleMixerThreadError( HRESULT hr );
  128. void Mixer_Buffer_Reset(DWORD dwThreadIndex);
  129. void Mixer_Buffer_MixBuffer( DWORD dwThreadIndex,unsigned char *source );
  130. void Mixer_Buffer_Normalize( DWORD dwThreadIndex );
  131. HRESULT SetupBuffers();
  132. HRESULT FreeBuffers();
  133. HRESULT StartupClientServer();
  134. HRESULT ShutdownClientServer();
  135. HRESULT ShutdownWorkerThreads();
  136. HRESULT StartWorkerThreads();
  137. HRESULT HandleMixingReceive( CDVCSPlayer *pTargetPlayer, PDVPROTOCOLMSG_SPEECHWITHTARGET pdvSpeechWithtarget, DWORD dwSpeechSize, PBYTE pbSpeechData );
  138. void AddPlayerToMixingAddList( CVoicePlayer *pVoicePlayer );
  139. void UpdateActiveMixingPendingList( DWORD dwThreadIndex, DWORD *pdwNumActive );
  140. void CleanupMixingList();
  141. void SpinWorkToThread( LONG lThreadIndex );
  142. void FindAndRemoveDeadTarget( DVID dvidTargetID );
  143. protected: // Forwarding Server specific funcs (fwdserver.cpp)
  144. HRESULT StartupMulticast();
  145. HRESULT ShutdownMulticast();
  146. HRESULT HandleForwardingReceive( CVoicePlayer *pTargetPlayer,PDVPROTOCOLMSG_SPEECHWITHTARGET pdvSpeechWithtarget, DWORD dwSpeechSize, PBYTE pbSpeechData );
  147. void CleanupActiveList();
  148. protected:
  149. DWORD m_dwSignature; // Signature
  150. LPDVMESSAGEHANDLER m_lpMessageHandler; // User message handler
  151. LPVOID m_lpUserContext; // User context for message handler
  152. DVID m_dvidLocal; // DVID of the transport player for this host
  153. DWORD m_dwCurrentState; // Current state of the engine
  154. CDirectVoiceTransport *m_lpSessionTransport; // Transport for the session
  155. DVSESSIONDESC m_dvSessionDesc; // Description of session
  156. DWORD m_dwTransportFlags; // Flags for the transport session
  157. DWORD m_dwTransportSessionType;
  158. // Type of transport session (client/server or peer to peer)
  159. LPDVFULLCOMPRESSIONINFO m_lpdvfCompressionInfo; // Details of current compression type
  160. DWORD m_dwCompressedFrameSize;// Max size of compressed frame
  161. DWORD m_dwUnCompressedFrameSize;
  162. // Size of a single frame uncompressed
  163. DWORD m_dwNumPerBuffer; // Size of playback/record buffers in frames
  164. CFramePool *m_pFramePool; // Pool of frames for the queues
  165. // time of a frame size.
  166. DIRECTVOICESERVEROBJECT *m_lpObject; // Pointer to the COM object this is running in
  167. LPDWORD m_lpdwMessageElements; // Array containing the DVMSGID_XXXX values for all the
  168. // notifications developer wishes to receive.
  169. // If this is NULL all notifications are active
  170. DWORD m_dwNumMessageElements; // # of elements in the m_lpdwMessageElements array
  171. DWORD m_dwNextHostOrderID;
  172. HRESULT m_hrStopSessionResult; // Reason that the session was stopped
  173. BOOL m_mixerEightBit; // Is the mixer format 8-bit
  174. BYTE m_padding[3];
  175. ServerStats *m_pServerStats;
  176. DVCAPS m_dvCaps; // Caps
  177. DNCRITICAL_SECTION m_csClassLock;
  178. DNCRITICAL_SECTION m_csNotifyLock; // Lock protection notification mask
  179. BILINK m_blPlayerActiveList;
  180. DNCRITICAL_SECTION m_csPlayerActiveList;
  181. CVoiceNameTable m_voiceNameTable;
  182. CLockedFixedPool<CDVCSPlayer> m_fpCSPlayers;
  183. CLockedFixedPool<CVoicePlayer> m_fpPlayers;
  184. DNCRITICAL_SECTION m_csHostOrderLock;
  185. DNCRITICAL_SECTION m_csBufferLock;
  186. ServerStats m_dvsServerStatsFixed; // If global memory is unavailable
  187. PFPOOL m_pBufferDescPool;
  188. PFPOOL *m_pBufferPools;
  189. DWORD *m_pdwBufferPoolSizes;
  190. DWORD m_dwNumPools;
  191. protected: // Mixing server information
  192. DWORD m_dwNumMixingThreads;
  193. DWORD m_dwMixerSize; // # of samples in the high resolution mixer buffer
  194. DNCRITICAL_SECTION m_csMixingAddList;
  195. HANDLE m_hTickSemaphore; // Semaphore signalled by the timer
  196. HANDLE m_hShutdownMixerEvent; // Event signalled to shutdown the mixer
  197. HANDLE m_hMixerDoneEvent; // Signalled by the mixer thread when it's shutdown
  198. Timer *m_timer; // Timer that is signalled on a period equal to the
  199. PMIXERTHREAD_CONTROL m_prWorkerControl;
  200. DWORD m_dwMixerControlThreadID;
  201. HANDLE m_hMixerControlThread;
  202. MixingServerStats m_statMixingFixed;
  203. MixingServerStats *m_pStats;
  204. PERF_APPLICATION m_perfInfo; // Perf info entry for this object
  205. PERF_APPLICATION_INFO m_perfAppInfo; // APplication specific perrf info
  206. DNCRITICAL_SECTION m_csStats;
  207. BOOL m_fCritSecInited;
  208. };
  209. #endif