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.

267 lines
8.0 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dvserver.cpp
  6. * Content: Implements functions for the IDirectXVoiceServer interface
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/02/99 rodtoll Created It
  12. * 07/26/99 rodtoll Updated QueryInterface to support IDirectXVoiceNotify
  13. * 08/25/99 rodtoll General Cleanup/Modifications to support new
  14. * compression sub-system.
  15. * Added parameter to the GetCompressionTypes func
  16. * 09/10/99 rodtoll Object validity checking
  17. * 09/14/99 rodtoll Added DVS_SetNotifyMask
  18. * 10/05/99 rodtoll Reversed destruction order to destroy object before
  19. * transport. Fixes crash on host migration shutdown.
  20. * 10/18/99 rodtoll Fix: Passing NULL in QueryInterface casues crash
  21. * rodtoll Fix: Calling Initialize twice passes
  22. * 10/19/99 rodtoll Fix: Bug #113904 - Shutdown issues
  23. * - Added reference count for notify interface, allows
  24. * determination if stopsession should be called from release
  25. * 10/25/99 rodtoll Fix: Bug #114098 - Release/Addref failure from multiple threads
  26. * 01/14/2000 rodtoll Updated with new parameters for Set/GetTransmitTarget
  27. * rodtoll Removed DVFLAGS_SYNC from StopSession call
  28. * 08/23/2000 rodtoll DllCanUnloadNow always returning TRUE!
  29. * 10/05/2000 rodtoll Bug #46541 - DPVOICE: A/V linking to dpvoice.lib could cause application to fail init and crash
  30. *
  31. ***************************************************************************/
  32. #include "dxvoicepch.h"
  33. #undef DPF_MODNAME
  34. #define DPF_MODNAME "DVS_Release"
  35. STDAPI DVS_Release(LPDIRECTVOICESERVEROBJECT lpDV )
  36. {
  37. HRESULT hr=S_OK;
  38. LONG rc;
  39. if( !DV_ValidDirectXVoiceServerObject( lpDV ) )
  40. return DVERR_INVALIDOBJECT;
  41. DNEnterCriticalSection( &lpDV->csCountLock );
  42. if (lpDV->lIntRefCnt == 0)
  43. {
  44. DNLeaveCriticalSection( &lpDV->csCountLock );
  45. return 0;
  46. }
  47. // dec the interface count
  48. lpDV->lIntRefCnt--;
  49. // Special case: Releasing object without stopping session
  50. if( (lpDV->lIntRefCnt == 0) && lpDV->lpDVServerEngine->GetCurrentState() != DVSSTATE_IDLE )
  51. {
  52. DPFX(DPFPREP, DVF_INFOLEVEL, "Releasing interface without calling StopSession lIntRefCnt %u GetCurrentState %u",
  53. lpDV->lIntRefCnt , lpDV->lpDVServerEngine->GetCurrentState());
  54. lpDV->lIntRefCnt = 0;
  55. // We must release the lock because stopsession may call back into this function
  56. DNLeaveCriticalSection( &lpDV->csCountLock );
  57. hr = lpDV->lpDVServerEngine->StopSession( 0 );
  58. DNEnterCriticalSection( &lpDV->csCountLock );
  59. if( hr != DV_OK && hr != DVERR_SESSIONLOST )
  60. {
  61. DPFX(DPFPREP, DVF_INFOLEVEL, "StopSession Failed hr=0x%x", hr );
  62. }
  63. }
  64. rc = lpDV->lIntRefCnt;
  65. if ( lpDV->lIntRefCnt == 0 )
  66. {
  67. // Leave the critical section, we may call back into this func.
  68. // (Shouldn't though).
  69. DNLeaveCriticalSection( &lpDV->csCountLock );
  70. DNASSERT( lpDV->lpDVServerEngine );
  71. delete lpDV->lpDVServerEngine;
  72. lpDV->lpDVServerEngine = NULL;
  73. if( lpDV->lpDVTransport != 0 )
  74. {
  75. DNASSERT( lpDV->lpDVTransport->m_lRefCount == 0 );
  76. delete lpDV->lpDVTransport;
  77. lpDV->lpDVTransport = NULL;
  78. }
  79. DNDeleteCriticalSection( &lpDV->csCountLock );
  80. DNFree(lpDV);
  81. DecrementObjectCount();
  82. }
  83. else
  84. {
  85. DNLeaveCriticalSection( &lpDV->csCountLock );
  86. }
  87. return rc;
  88. }
  89. #undef DPF_MODNAME
  90. #define DPF_MODNAME "DVS_QueryInterface"
  91. STDMETHODIMP DVS_QueryInterface(LPDIRECTVOICESERVEROBJECT lpDVS, REFIID riid, LPVOID * ppvObj)
  92. {
  93. HRESULT hr = S_OK;
  94. if( ppvObj == NULL ||
  95. !DNVALID_WRITEPTR( ppvObj, sizeof(LPVOID) ) )
  96. {
  97. DPFX(DPFPREP, DVF_ERRORLEVEL, "Invalid pointer passed for object" );
  98. return DVERR_INVALIDPOINTER;
  99. }
  100. *ppvObj=NULL;
  101. if( !DV_ValidDirectXVoiceServerObject( lpDVS ) )
  102. return DVERR_INVALIDOBJECT;
  103. // hmmm, switch would be cleaner...
  104. if( IsEqualIID(riid, IID_IUnknown) ||
  105. IsEqualIID(riid, IID_IDirectPlayVoiceServer ) )
  106. {
  107. *ppvObj = lpDVS;
  108. DV_AddRef(lpDVS);
  109. }
  110. else if( IsEqualIID(riid, IID_IDirectPlayVoiceNotify ) )
  111. {
  112. *ppvObj = &lpDVS->dvNotify;
  113. DV_Notify_AddRef(&lpDVS->dvNotify);
  114. }
  115. else
  116. {
  117. hr = E_NOINTERFACE;
  118. }
  119. return hr;
  120. }//DVS_QueryInterface
  121. #undef DPF_MODNAME
  122. #define DPF_MODNAME "DVS_StartSession"
  123. STDMETHODIMP DVS_StartSession(LPDIRECTVOICESERVEROBJECT This, LPDVSESSIONDESC lpdvSessionDesc, DWORD dwFlags )
  124. {
  125. DNASSERT( This != NULL );
  126. DNASSERT( This->lpDVEngine != NULL );
  127. if( !DV_ValidDirectXVoiceServerObject( This ) )
  128. return DVERR_INVALIDOBJECT;
  129. return This->lpDVServerEngine->StartSession( lpdvSessionDesc, dwFlags );
  130. }
  131. #undef DPF_MODNAME
  132. #define DPF_MODNAME "DVS_StopSession"
  133. STDMETHODIMP DVS_StopSession(LPDIRECTVOICESERVEROBJECT This, DWORD dwFlags )
  134. {
  135. DNASSERT( This != NULL );
  136. DNASSERT( This->lpDVEngine != NULL );
  137. if( !DV_ValidDirectXVoiceServerObject( This ) )
  138. return DVERR_INVALIDOBJECT;
  139. return This->lpDVServerEngine->StopSession( dwFlags );
  140. }
  141. #undef DPF_MODNAME
  142. #define DPF_MODNAME "DVS_GetSessionDesc"
  143. STDMETHODIMP DVS_GetSessionDesc(LPDIRECTVOICESERVEROBJECT This, LPDVSESSIONDESC lpdvSessionDesc )
  144. {
  145. DNASSERT( This != NULL );
  146. DNASSERT( This->lpDVEngine != NULL );
  147. if( !DV_ValidDirectXVoiceServerObject( This ) )
  148. return DVERR_INVALIDOBJECT;
  149. return This->lpDVServerEngine->GetSessionDesc( lpdvSessionDesc );
  150. }
  151. #undef DPF_MODNAME
  152. #define DPF_MODNAME "DVS_SetSessionDesc"
  153. STDMETHODIMP DVS_SetSessionDesc(LPDIRECTVOICESERVEROBJECT This, LPDVSESSIONDESC lpdvSessionDesc )
  154. {
  155. DNASSERT( This != NULL );
  156. DNASSERT( This->lpDVEngine != NULL );
  157. if( !DV_ValidDirectXVoiceServerObject( This ) )
  158. return DVERR_INVALIDOBJECT;
  159. return This->lpDVServerEngine->SetSessionDesc( lpdvSessionDesc );
  160. }
  161. #undef DPF_MODNAME
  162. #define DPF_MODNAME "DVS_GetCaps"
  163. STDMETHODIMP DVS_GetCaps(LPDIRECTVOICESERVEROBJECT This, LPDVCAPS lpdvCaps )
  164. {
  165. DNASSERT( This != NULL );
  166. DNASSERT( This->lpDVEngine != NULL );
  167. if( !DV_ValidDirectXVoiceServerObject( This ) )
  168. return DVERR_INVALIDOBJECT;
  169. return This->lpDVServerEngine->GetCaps( lpdvCaps );
  170. }
  171. #undef DPF_MODNAME
  172. #define DPF_MODNAME "DVS_GetCompressionTypes"
  173. STDMETHODIMP DVS_GetCompressionTypes( LPDIRECTVOICESERVEROBJECT This, LPVOID lpDataBuffer, LPDWORD lpdwSize, LPDWORD lpdwNumElements, DWORD dwFlags)
  174. {
  175. DNASSERT( This != NULL );
  176. DNASSERT( This->lpDVEngine != NULL );
  177. if( !DV_ValidDirectXVoiceServerObject( This ) )
  178. return DVERR_INVALIDOBJECT;
  179. return This->lpDVServerEngine->GetCompressionTypes( lpDataBuffer, lpdwSize, lpdwNumElements, dwFlags );
  180. }
  181. #undef DPF_MODNAME
  182. #define DPF_MODNAME "DVS_SetTransmitTarget"
  183. STDMETHODIMP DVS_SetTransmitTarget( LPDIRECTVOICESERVEROBJECT This, DVID dvidSource, PDVID pdvidTargets, DWORD dwNumTargets, DWORD dwFlags)
  184. {
  185. DNASSERT( This != NULL );
  186. DNASSERT( This->lpDVEngine != NULL );
  187. if( !DV_ValidDirectXVoiceServerObject( This ) )
  188. return DVERR_INVALIDOBJECT;
  189. return This->lpDVServerEngine->SetTransmitTarget( dvidSource, pdvidTargets, dwNumTargets, dwFlags );
  190. }
  191. #undef DPF_MODNAME
  192. #define DPF_MODNAME "DVS_GetTransmitTarget"
  193. STDMETHODIMP DVS_GetTransmitTarget( LPDIRECTVOICESERVEROBJECT This, DVID dvidSource, LPDVID pdvidTargets, PDWORD pdwNumElements, DWORD dwFlags)
  194. {
  195. DNASSERT( This != NULL );
  196. DNASSERT( This->lpDVEngine != NULL );
  197. if( !DV_ValidDirectXVoiceServerObject( This ) )
  198. return DVERR_INVALIDOBJECT;
  199. return This->lpDVServerEngine->GetTransmitTarget( dvidSource, pdvidTargets, pdwNumElements, dwFlags );
  200. }
  201. #undef DPF_MODNAME
  202. #define DPF_MODNAME "DVS_SetNotifyMask"
  203. STDMETHODIMP DVS_SetNotifyMask( LPDIRECTVOICESERVEROBJECT This, LPDWORD lpdwMessages, DWORD dwNumElements )
  204. {
  205. DNASSERT( This != NULL );
  206. DNASSERT( This->lpDVEngine != NULL );
  207. if( !DV_ValidDirectXVoiceServerObject( This ) )
  208. return DVERR_INVALIDOBJECT;
  209. return This->lpDVServerEngine->SetNotifyMask( lpdwMessages, dwNumElements );
  210. }