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.

266 lines
7.7 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" );
  53. lpDV->lIntRefCnt = 0;
  54. // We must release the lock because stopsession may call back into this function
  55. DNLeaveCriticalSection( &lpDV->csCountLock );
  56. hr = lpDV->lpDVServerEngine->StopSession( 0 );
  57. DNEnterCriticalSection( &lpDV->csCountLock );
  58. if( hr != DV_OK && hr != DVERR_SESSIONLOST )
  59. {
  60. DPFX(DPFPREP, DVF_INFOLEVEL, "StopSession Failed hr=0x%x", hr );
  61. }
  62. }
  63. rc = lpDV->lIntRefCnt;
  64. if ( lpDV->lIntRefCnt == 0 )
  65. {
  66. // Leave the critical section, we may call back into this func.
  67. // (Shouldn't though).
  68. DNLeaveCriticalSection( &lpDV->csCountLock );
  69. DNASSERT( lpDV->lpDVServerEngine );
  70. delete lpDV->lpDVServerEngine;
  71. lpDV->lpDVServerEngine = NULL;
  72. if( lpDV->lpDVTransport != 0 )
  73. {
  74. DNASSERT( lpDV->lpDVTransport->m_lRefCount == 0 );
  75. delete lpDV->lpDVTransport;
  76. lpDV->lpDVTransport = NULL;
  77. }
  78. DNDeleteCriticalSection( &lpDV->csCountLock );
  79. DNFree(lpDV);
  80. DecrementObjectCount();
  81. }
  82. else
  83. {
  84. DNLeaveCriticalSection( &lpDV->csCountLock );
  85. }
  86. return rc;
  87. }
  88. #undef DPF_MODNAME
  89. #define DPF_MODNAME "DVS_QueryInterface"
  90. STDMETHODIMP DVS_QueryInterface(LPDIRECTVOICESERVEROBJECT lpDVS, REFIID riid, LPVOID * ppvObj)
  91. {
  92. HRESULT hr = S_OK;
  93. if( ppvObj == NULL ||
  94. !DNVALID_WRITEPTR( ppvObj, sizeof(LPVOID) ) )
  95. {
  96. DPFX(DPFPREP, DVF_ERRORLEVEL, "Invalid pointer passed for object" );
  97. return DVERR_INVALIDPOINTER;
  98. }
  99. *ppvObj=NULL;
  100. if( !DV_ValidDirectXVoiceServerObject( lpDVS ) )
  101. return DVERR_INVALIDOBJECT;
  102. // hmmm, switch would be cleaner...
  103. if( IsEqualIID(riid, IID_IUnknown) ||
  104. IsEqualIID(riid, IID_IDirectPlayVoiceServer ) )
  105. {
  106. *ppvObj = lpDVS;
  107. DV_AddRef(lpDVS);
  108. }
  109. else if( IsEqualIID(riid, IID_IDirectPlayVoiceNotify ) )
  110. {
  111. *ppvObj = &lpDVS->dvNotify;
  112. DV_Notify_AddRef(&lpDVS->dvNotify);
  113. }
  114. else
  115. {
  116. hr = E_NOINTERFACE;
  117. }
  118. return hr;
  119. }//DVS_QueryInterface
  120. #undef DPF_MODNAME
  121. #define DPF_MODNAME "DVS_StartSession"
  122. STDMETHODIMP DVS_StartSession(LPDIRECTVOICESERVEROBJECT This, LPDVSESSIONDESC lpdvSessionDesc, DWORD dwFlags )
  123. {
  124. DNASSERT( This != NULL );
  125. DNASSERT( This->lpDVEngine != NULL );
  126. if( !DV_ValidDirectXVoiceServerObject( This ) )
  127. return DVERR_INVALIDOBJECT;
  128. return This->lpDVServerEngine->StartSession( lpdvSessionDesc, dwFlags );
  129. }
  130. #undef DPF_MODNAME
  131. #define DPF_MODNAME "DVS_StopSession"
  132. STDMETHODIMP DVS_StopSession(LPDIRECTVOICESERVEROBJECT This, DWORD dwFlags )
  133. {
  134. DNASSERT( This != NULL );
  135. DNASSERT( This->lpDVEngine != NULL );
  136. if( !DV_ValidDirectXVoiceServerObject( This ) )
  137. return DVERR_INVALIDOBJECT;
  138. return This->lpDVServerEngine->StopSession( dwFlags );
  139. }
  140. #undef DPF_MODNAME
  141. #define DPF_MODNAME "DVS_GetSessionDesc"
  142. STDMETHODIMP DVS_GetSessionDesc(LPDIRECTVOICESERVEROBJECT This, LPDVSESSIONDESC lpdvSessionDesc )
  143. {
  144. DNASSERT( This != NULL );
  145. DNASSERT( This->lpDVEngine != NULL );
  146. if( !DV_ValidDirectXVoiceServerObject( This ) )
  147. return DVERR_INVALIDOBJECT;
  148. return This->lpDVServerEngine->GetSessionDesc( lpdvSessionDesc );
  149. }
  150. #undef DPF_MODNAME
  151. #define DPF_MODNAME "DVS_SetSessionDesc"
  152. STDMETHODIMP DVS_SetSessionDesc(LPDIRECTVOICESERVEROBJECT This, LPDVSESSIONDESC lpdvSessionDesc )
  153. {
  154. DNASSERT( This != NULL );
  155. DNASSERT( This->lpDVEngine != NULL );
  156. if( !DV_ValidDirectXVoiceServerObject( This ) )
  157. return DVERR_INVALIDOBJECT;
  158. return This->lpDVServerEngine->SetSessionDesc( lpdvSessionDesc );
  159. }
  160. #undef DPF_MODNAME
  161. #define DPF_MODNAME "DVS_GetCaps"
  162. STDMETHODIMP DVS_GetCaps(LPDIRECTVOICESERVEROBJECT This, LPDVCAPS lpdvCaps )
  163. {
  164. DNASSERT( This != NULL );
  165. DNASSERT( This->lpDVEngine != NULL );
  166. if( !DV_ValidDirectXVoiceServerObject( This ) )
  167. return DVERR_INVALIDOBJECT;
  168. return This->lpDVServerEngine->GetCaps( lpdvCaps );
  169. }
  170. #undef DPF_MODNAME
  171. #define DPF_MODNAME "DVS_GetCompressionTypes"
  172. STDMETHODIMP DVS_GetCompressionTypes( LPDIRECTVOICESERVEROBJECT This, LPVOID lpDataBuffer, LPDWORD lpdwSize, LPDWORD lpdwNumElements, DWORD dwFlags)
  173. {
  174. DNASSERT( This != NULL );
  175. DNASSERT( This->lpDVEngine != NULL );
  176. if( !DV_ValidDirectXVoiceServerObject( This ) )
  177. return DVERR_INVALIDOBJECT;
  178. return This->lpDVServerEngine->GetCompressionTypes( lpDataBuffer, lpdwSize, lpdwNumElements, dwFlags );
  179. }
  180. #undef DPF_MODNAME
  181. #define DPF_MODNAME "DVS_SetTransmitTarget"
  182. STDMETHODIMP DVS_SetTransmitTarget( LPDIRECTVOICESERVEROBJECT This, DVID dvidSource, PDVID pdvidTargets, DWORD dwNumTargets, DWORD dwFlags)
  183. {
  184. DNASSERT( This != NULL );
  185. DNASSERT( This->lpDVEngine != NULL );
  186. if( !DV_ValidDirectXVoiceServerObject( This ) )
  187. return DVERR_INVALIDOBJECT;
  188. return This->lpDVServerEngine->SetTransmitTarget( dvidSource, pdvidTargets, dwNumTargets, dwFlags );
  189. }
  190. #undef DPF_MODNAME
  191. #define DPF_MODNAME "DVS_GetTransmitTarget"
  192. STDMETHODIMP DVS_GetTransmitTarget( LPDIRECTVOICESERVEROBJECT This, DVID dvidSource, LPDVID pdvidTargets, PDWORD pdwNumElements, DWORD dwFlags)
  193. {
  194. DNASSERT( This != NULL );
  195. DNASSERT( This->lpDVEngine != NULL );
  196. if( !DV_ValidDirectXVoiceServerObject( This ) )
  197. return DVERR_INVALIDOBJECT;
  198. return This->lpDVServerEngine->GetTransmitTarget( dvidSource, pdvidTargets, pdwNumElements, dwFlags );
  199. }
  200. #undef DPF_MODNAME
  201. #define DPF_MODNAME "DVS_SetNotifyMask"
  202. STDMETHODIMP DVS_SetNotifyMask( LPDIRECTVOICESERVEROBJECT This, LPDWORD lpdwMessages, DWORD dwNumElements )
  203. {
  204. DNASSERT( This != NULL );
  205. DNASSERT( This->lpDVEngine != NULL );
  206. if( !DV_ValidDirectXVoiceServerObject( This ) )
  207. return DVERR_INVALIDOBJECT;
  208. return This->lpDVServerEngine->SetNotifyMask( lpdwMessages, dwNumElements );
  209. }