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.

285 lines
8.5 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: unk.c
  6. * Content: IUnknown implementation
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 07/02/99 rodtoll Modified existing unk.c for use w/DirectXVoice
  11. * 07/26/99 rodtoll Added the new IDirectXVoiceNotify Interfaces
  12. * 08/09/99 rodtoll Fixed VTable for server notify interface
  13. * 08/25/99 rodtoll General Cleanup/Modifications to support new
  14. * compression sub-system.
  15. * 08/31/99 rodtoll Updated to use new debug libs
  16. * 09/02/99 pnewson Added IDirectXVoiceSetup interface
  17. * 09/07/99 rodtoll Added DPF_MODNAMEs to the module
  18. * rodtoll Fixed vtable for server object
  19. * 09/10/99 rodtoll Vtables from static to non-static so other modules can access
  20. * 09/13/99 pnewson added dplobby.h include so lobby GUIDs get created
  21. * 09/14/99 rodtoll Modified VTable to add new SetNotifyMask func
  22. * 10/05/99 rodtoll Added DPFs
  23. * 10/07/99 rodtoll Updated to work in Unicode, Add Init of OS Abstraction Layer
  24. * 10/18/99 rodtoll Fix: Passing NULL in QueryInterface casues crash
  25. * 10/19/99 rodtoll Fix: Bug #113904 Release Issues
  26. * Added init for notify interface count
  27. * 10/25/99 rodtoll Fix: Bug #114098 - Release/Addref failure from multiple threads
  28. * 11/12/99 rodtoll Fixed to use new dsound header.
  29. * 11/30/99 pnewson Bug #117449 - IDirectPlayVoiceSetup Parameter validation
  30. * 12/01/99 rodtoll Added includes to define and instantiate GUID_NULL
  31. * 12/16/99 rodtoll Bug #117405 - 3D sound APIs misleading
  32. * 01/14/00 rodtoll Added new DVC_GetSoundDeviceConfig member to VTable
  33. * 02/17/00 rodtoll Bug #133691 - Choppy audio - queue was not adapting
  34. * Added instrumentation
  35. * rodtoll Removed self-registration code
  36. * 03/03/00 rodtoll Updated to handle alternative gamevoice build.
  37. * 04/11/00 rodtoll Added code for redirection for custom builds if registry bit is set
  38. * 04/21/00 rodtoll Bug #32889 - Does not run on Win2k on non-admin account
  39. * 06/07/00 rodtoll Bug #34383 Must provide CLSID for each IID to fix issues with Whistler
  40. * 06/09/00 rmt Updates to split CLSID and allow whistler compat and support external create funcs
  41. * 06/28/2000 rodtoll Prefix Bug #38022
  42. * 07/05/00 rodtoll Moved code to new dllmain.cpp
  43. * 08/23/2000 rodtoll DllCanUnloadNow always returning TRUE!
  44. * 08/28/2000 masonb Voice Merge: Removed dvosal.h, changed ccomutil.h to comutil.h
  45. * 10/05/2000 rodtoll Bug #46541 - DPVOICE: A/V linking to dpvoice.lib could cause application to fail init and crash
  46. *
  47. ***************************************************************************/
  48. #include "dxvoicepch.h"
  49. // VTable types
  50. typedef struct IDirectPlayVoiceClientVtbl DVCINTERFACE;
  51. typedef DVCINTERFACE FAR * LPDVCINTERFACE;
  52. typedef struct IDirectPlayVoiceServerVtbl DVSINTERFACE;
  53. typedef DVSINTERFACE FAR * LPDVSINTERFACE;
  54. typedef struct IDirectPlayVoiceSetupVtbl DVTINTERFACE;
  55. typedef DVTINTERFACE FAR * LPDVTINTERFACE;
  56. #define EXP __declspec(dllexport)
  57. /*#ifdef __MWERKS__
  58. #define EXP __declspec(dllexport)
  59. #else
  60. #define EXP
  61. #endif*/
  62. // Client VTable
  63. LPVOID dvcInterface[] =
  64. {
  65. (LPVOID)DVC_QueryInterface,
  66. (LPVOID)DV_AddRef,
  67. (LPVOID)DVC_Release,
  68. (LPVOID)DV_Initialize,
  69. (LPVOID)DVC_Connect,
  70. (LPVOID)DVC_Disconnect,
  71. (LPVOID)DVC_GetSessionDesc,
  72. (LPVOID)DVC_GetClientConfig,
  73. (LPVOID)DVC_SetClientConfig,
  74. (LPVOID)DVC_GetCaps,
  75. (LPVOID)DVC_GetCompressionTypes,
  76. (LPVOID)DVC_SetTransmitTarget,
  77. (LPVOID)DVC_GetTransmitTarget,
  78. (LPVOID)DVC_Create3DSoundBuffer,
  79. (LPVOID)DVC_Delete3DSoundBuffer,
  80. (LPVOID)DVC_SetNotifyMask,
  81. (LPVOID)DVC_GetSoundDeviceConfig
  82. };
  83. // Server VTable
  84. LPVOID dvsInterface[] =
  85. {
  86. (LPVOID)DVS_QueryInterface,
  87. (LPVOID)DV_AddRef,
  88. (LPVOID)DVS_Release,
  89. (LPVOID)DV_Initialize,
  90. (LPVOID)DVS_StartSession,
  91. (LPVOID)DVS_StopSession,
  92. (LPVOID)DVS_GetSessionDesc,
  93. (LPVOID)DVS_SetSessionDesc,
  94. (LPVOID)DVS_GetCaps,
  95. (LPVOID)DVS_GetCompressionTypes,
  96. (LPVOID)DVS_SetTransmitTarget,
  97. (LPVOID)DVS_GetTransmitTarget,
  98. (LPVOID)DVS_SetNotifyMask
  99. };
  100. // Setup VTable
  101. LPVOID dvtInterface[] =
  102. {
  103. (LPVOID)DVT_QueryInterface,
  104. (LPVOID)DVT_AddRef,
  105. (LPVOID)DVT_Release,
  106. (LPVOID)DVT_CheckAudioSetup,
  107. };
  108. // VTable for Client version of notification interface
  109. LPVOID dvClientNotifyInterface[] =
  110. {
  111. (LPVOID)DVC_Notify_QueryInterface,
  112. (LPVOID)DV_Notify_AddRef,
  113. (LPVOID)DVC_Notify_Release,
  114. (LPVOID)DV_Notify_Initialize,
  115. (LPVOID)DV_NotifyEvent,
  116. (LPVOID)DV_ReceiveSpeechMessage
  117. };
  118. // VTable for server version of notification interface
  119. LPVOID dvServerNotifyInterface[] =
  120. {
  121. (LPVOID)DVS_Notify_QueryInterface,
  122. (LPVOID)DV_Notify_AddRef,
  123. (LPVOID)DVS_Notify_Release,
  124. (LPVOID)DV_Notify_Initialize,
  125. (LPVOID)DV_NotifyEvent,
  126. (LPVOID)DV_ReceiveSpeechMessage
  127. };
  128. #undef DPF_MODNAME
  129. #define DPF_MODNAME "DVC_Create"
  130. HRESULT DVC_Create(LPDIRECTVOICECLIENTOBJECT *piDVC)
  131. {
  132. HRESULT hr = S_OK;
  133. LPDIRECTVOICECLIENTOBJECT pDVCInt;
  134. pDVCInt = static_cast<LPDIRECTVOICECLIENTOBJECT>( DNMalloc(sizeof(DIRECTVOICECLIENTOBJECT)) );
  135. if (pDVCInt == NULL)
  136. {
  137. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  138. return E_OUTOFMEMORY;
  139. }
  140. if (!DNInitializeCriticalSection( &pDVCInt->csCountLock ))
  141. {
  142. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  143. DNFree(pDVCInt);
  144. return E_OUTOFMEMORY;
  145. }
  146. pDVCInt->lpVtbl = &dvcInterface;
  147. pDVCInt->lpDVClientEngine = new CDirectVoiceClientEngine(pDVCInt);
  148. if (pDVCInt->lpDVClientEngine == NULL)
  149. {
  150. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  151. DNDeleteCriticalSection( &pDVCInt->csCountLock );
  152. DNFree( pDVCInt );
  153. return E_OUTOFMEMORY;
  154. }
  155. if (!pDVCInt->lpDVClientEngine->InitClass())
  156. {
  157. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  158. DNDeleteCriticalSection( &pDVCInt->csCountLock );
  159. delete pDVCInt->lpDVEngine;
  160. DNFree( pDVCInt );
  161. return E_OUTOFMEMORY;
  162. }
  163. pDVCInt->lpDVEngine = static_cast<CDirectVoiceEngine *>(pDVCInt->lpDVClientEngine);
  164. pDVCInt->lpDVTransport = NULL;
  165. pDVCInt->lIntRefCnt = 0;
  166. pDVCInt->dvNotify.lpDV = pDVCInt;
  167. pDVCInt->dvNotify.lpNotifyVtble = &dvClientNotifyInterface;
  168. pDVCInt->dvNotify.lRefCnt = 0;
  169. *piDVC = pDVCInt;
  170. return hr;
  171. }
  172. #undef DPF_MODNAME
  173. #define DPF_MODNAME "DVS_Create"
  174. HRESULT DVS_Create(LPDIRECTVOICESERVEROBJECT *piDVS)
  175. {
  176. HRESULT hr = S_OK;
  177. LPDIRECTVOICESERVEROBJECT pDVSInt;
  178. pDVSInt = static_cast<LPDIRECTVOICESERVEROBJECT>( DNMalloc(sizeof(DIRECTVOICESERVEROBJECT)) );
  179. if (pDVSInt == NULL)
  180. {
  181. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  182. return E_OUTOFMEMORY;
  183. }
  184. if (!DNInitializeCriticalSection( &pDVSInt->csCountLock ))
  185. {
  186. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  187. DNFree(pDVSInt);
  188. return E_OUTOFMEMORY;
  189. }
  190. pDVSInt->lpVtbl = &dvsInterface;
  191. pDVSInt->lpDVServerEngine = new CDirectVoiceServerEngine(pDVSInt);
  192. if (pDVSInt->lpDVServerEngine == NULL)
  193. {
  194. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  195. DNDeleteCriticalSection( &pDVSInt->csCountLock );
  196. DNFree( pDVSInt );
  197. return E_OUTOFMEMORY;
  198. }
  199. if (!pDVSInt->lpDVServerEngine->InitClass())
  200. {
  201. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  202. DNDeleteCriticalSection( &pDVSInt->csCountLock );
  203. delete pDVSInt->lpDVEngine;
  204. DNFree( pDVSInt );
  205. return E_OUTOFMEMORY;
  206. }
  207. pDVSInt->lpDVEngine = static_cast<CDirectVoiceEngine *>(pDVSInt->lpDVServerEngine);
  208. pDVSInt->lpDVTransport = NULL;
  209. pDVSInt->lIntRefCnt = 0;
  210. pDVSInt->dvNotify.lpDV = pDVSInt;
  211. pDVSInt->dvNotify.lpNotifyVtble = &dvServerNotifyInterface;
  212. pDVSInt->dvNotify.lRefCnt = 0;
  213. *piDVS = pDVSInt;
  214. return hr;
  215. }
  216. #undef DPF_MODNAME
  217. #define DPF_MODNAME "DVT_Create"
  218. HRESULT DVT_Create(LPDIRECTVOICESETUPOBJECT *piDVT)
  219. {
  220. HRESULT hr = S_OK;
  221. LPDIRECTVOICESETUPOBJECT pDVTInt;
  222. pDVTInt = static_cast<LPDIRECTVOICESETUPOBJECT>( DNMalloc(sizeof(DIRECTVOICESETUPOBJECT)) );
  223. if (pDVTInt == NULL)
  224. {
  225. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  226. return E_OUTOFMEMORY;
  227. }
  228. if (!DNInitializeCriticalSection( &pDVTInt->csCountLock ))
  229. {
  230. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  231. DNFree(pDVTInt);
  232. return E_OUTOFMEMORY;
  233. }
  234. pDVTInt->lpVtbl = &dvtInterface;
  235. pDVTInt->lpDVSetup = new CDirectVoiceSetup(pDVTInt);
  236. if (pDVTInt->lpDVSetup == NULL)
  237. {
  238. DPFX(DPFPREP, DVF_ERRORLEVEL, "Out of memory" );
  239. DNDeleteCriticalSection( &pDVTInt->csCountLock );
  240. DNFree( pDVTInt );
  241. return E_OUTOFMEMORY;
  242. }
  243. pDVTInt->lIntRefCnt = 0;
  244. *piDVT = pDVTInt;
  245. return hr;
  246. }