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.

195 lines
6.8 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dvengine.cpp
  6. * Content: Implementation of CDirectVoiceEngine's static functions
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/19/99 rodtoll Created
  12. * 07/29/99 rodtoll Added static members to load default settings
  13. * 08/10/99 rodtoll Removed the TODOs
  14. * 08/25/99 rodtoll General Cleanup/Modifications to support new
  15. * compression sub-system.
  16. * Added default parameter reads from the registry
  17. * 08/30/99 rodtoll Distinguish between primary buffer format and
  18. * playback format.
  19. * Changed playback format to be 8Khz, 16Bit mono
  20. * 10/05/99 rodtoll Additional comments/DPFs
  21. * 10/07/99 rodtoll Updated to work in Unicode
  22. * 02/08/2000 rodtoll Bug #131496 - Selecting DVTHRESHOLD_DEFAULT results in voice
  23. * never being detected
  24. * 03/03/2000 rodtoll Updated to handle alternative gamevoice build.
  25. * 04/21/2000 rodtoll Bug #32889 - Does not run on Win2k on non-admin account
  26. * 04/24/2000 rodtoll Bug #33203 - Aureal Vortex plays back at the wrong rate
  27. * 07/12/2000 rodtoll Bug #31468 - Add diagnostic spew to logfile to show what is failing the HW Wizard
  28. * 08/31/2000 rodtoll Bug #43804 - DVOICE: dwSensitivity structure member is confusing - should be dwThreshold
  29. * 10/10/2000 rodtoll Bug #46907 - 3D Sound position not working correctly with Win9X & VxD
  30. * 04/06/2001 kareemc Added Voice Defense
  31. * 02/28/2002 rodtoll WINBUG #550085 - SECURITY: DPVOICE: Non-validated registry reads
  32. * - Pull read of debug settings
  33. * rodtoll WINBUG #550009 - SECURITY: DPVOICE: Potential corruption of voice client state
  34. * - Confirm that speech is > 0 bytes.
  35. *
  36. ***************************************************************************/
  37. #include "dxvoicepch.h"
  38. #undef DPF_SUBCOMP
  39. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  40. // Registry settings and their defaults
  41. #define DPVOICE_REGISTRY_DEFAULTAGGRESSIVENESS L"DefaultAggressiveness"
  42. #define DPVOICE_DEFAULT_DEFAULTAGGRESSIVENESS 15
  43. #define DPVOICE_REGISTRY_DEFAULTQUALITY L"DefaultQuality"
  44. #define DPVOICE_DEFAULT_DEFAULTQUALITY 15
  45. #define DPVOICE_REGISTRY_DEFAULTSENSITIVITY L"DefaultSensitivity"
  46. #define DPVOICE_DEFAULT_DEFAULTSENSITIVITY 20
  47. #define DPVOICE_REGISTRY_ASO L"AltStart"
  48. #define DPVOICE_DEFAULT_ASO FALSE
  49. #define DPVOICE_REGISTRY_DUMPDIAGNOSTICS L"InitDiagnostics"
  50. #define DPVOICE_DEFAULT_DUMPDIAGNOSTICS FALSE
  51. // Fix for bug #33203 -- Some cards having trouble with playback at 8Khz.
  52. #define DPVOICE_REGISTRY_PLAYBACKFORMAT L"PlaybackFormat"
  53. #define DPVOICE_DEFAULT_PLAYBACKFORMAT CreateWaveFormat( WAVE_FORMAT_PCM, FALSE, 22050, 16 )
  54. #define DPVOICE_REGISTRY_PRIMARYFORMAT L"PrimaryFormat"
  55. #define DPVOICE_DEFAULT_PRIMARYFORMAT CreateWaveFormat( WAVE_FORMAT_PCM, TRUE, 22050, 16 )
  56. #define DPVOICE_REGISTRY_MIXERFORMAT L"MixerFormat"
  57. #define DPVOICE_DEFAULT_MIXERFORMAT CreateWaveFormat( WAVE_FORMAT_PCM, FALSE, 8000, 16 );
  58. // Initialize static member variables
  59. DWORD CDirectVoiceEngine::s_dwDefaultBufferAggressiveness = DPVOICE_DEFAULT_DEFAULTAGGRESSIVENESS;
  60. DWORD CDirectVoiceEngine::s_dwDefaultBufferQuality = DPVOICE_DEFAULT_DEFAULTQUALITY;
  61. DWORD CDirectVoiceEngine::s_dwDefaultSensitivity = DPVOICE_DEFAULT_DEFAULTSENSITIVITY;
  62. LPWAVEFORMATEX CDirectVoiceEngine::s_lpwfxPrimaryFormat = NULL;
  63. LPWAVEFORMATEX CDirectVoiceEngine::s_lpwfxPlaybackFormat = NULL;
  64. LPWAVEFORMATEX CDirectVoiceEngine::s_lpwfxMixerFormat = NULL;
  65. BOOL CDirectVoiceEngine::s_fASO = DPVOICE_DEFAULT_ASO;
  66. WCHAR CDirectVoiceEngine::s_szRegistryPath[_MAX_PATH];
  67. BOOL CDirectVoiceEngine::s_fDumpDiagnostics = DPVOICE_DEFAULT_DUMPDIAGNOSTICS;
  68. DNCRITICAL_SECTION CDirectVoiceEngine::s_csSTLLock;
  69. #undef DPF_MODNAME
  70. #define DPF_MODNAME "CDirectVoiceEngine::Startup"
  71. //
  72. // Startup
  73. //
  74. // Called to load global settings and compression info from the registry.
  75. //
  76. HRESULT CDirectVoiceEngine::Startup(const WCHAR *szPath)
  77. {
  78. HRESULT hr;
  79. DPFX(DPFPREP, DVF_WARNINGLEVEL, "Starting up global DLL state" );
  80. wcscpy( s_szRegistryPath, szPath );
  81. if (!DNInitializeCriticalSection( &s_csSTLLock ) )
  82. {
  83. return DVERR_OUTOFMEMORY;
  84. }
  85. hr = DVCDB_LoadCompressionInfo( s_szRegistryPath );
  86. if( FAILED( hr ) )
  87. {
  88. DPFX(DPFPREP, DVF_ERRORLEVEL, "Unable to load compression info: hr=0x%x", hr );
  89. return hr;
  90. }
  91. InitRecordFormats();
  92. // Removed code to load over-rides from registry.
  93. s_dwDefaultBufferQuality = DPVOICE_DEFAULT_DEFAULTAGGRESSIVENESS;
  94. s_dwDefaultBufferAggressiveness = DPVOICE_DEFAULT_DEFAULTQUALITY;
  95. s_dwDefaultSensitivity = DPVOICE_DEFAULT_DEFAULTSENSITIVITY;
  96. CDirectVoiceEngine::s_lpwfxPlaybackFormat = DPVOICE_DEFAULT_PLAYBACKFORMAT;
  97. CDirectVoiceEngine::s_lpwfxPrimaryFormat = DPVOICE_DEFAULT_PRIMARYFORMAT;
  98. CDirectVoiceEngine::s_lpwfxMixerFormat = DPVOICE_DEFAULT_MIXERFORMAT;
  99. CDirectVoiceEngine::s_fDumpDiagnostics = DPVOICE_DEFAULT_DUMPDIAGNOSTICS;
  100. CRegistry cregSettings;
  101. // Removed code to load over-rides from registry.
  102. if( cregSettings.Open( HKEY_CURRENT_USER, s_szRegistryPath, FALSE, TRUE ) )
  103. {
  104. cregSettings.ReadBOOL( DPVOICE_REGISTRY_DUMPDIAGNOSTICS, &s_fDumpDiagnostics );
  105. }
  106. return DV_OK;
  107. }
  108. #undef DPF_MODNAME
  109. #define DPF_MODNAME "CDirectVoiceEngine::Shutdown"
  110. //
  111. // Shutdown
  112. //
  113. // Called to free the global settings and compression list
  114. //
  115. HRESULT CDirectVoiceEngine::Shutdown()
  116. {
  117. HRESULT hr;
  118. DPFX(DPFPREP, DVF_WARNINGLEVEL, "Shutting down global DLL state" );
  119. DeInitRecordFormats();
  120. if( CDirectVoiceEngine::s_lpwfxPlaybackFormat != NULL )
  121. delete CDirectVoiceEngine::s_lpwfxPlaybackFormat;
  122. if( CDirectVoiceEngine::s_lpwfxMixerFormat != NULL )
  123. delete CDirectVoiceEngine::s_lpwfxMixerFormat;
  124. if( CDirectVoiceEngine::s_lpwfxPrimaryFormat != NULL )
  125. delete CDirectVoiceEngine::s_lpwfxPrimaryFormat;
  126. hr = DVCDB_FreeCompressionInfo();
  127. if( FAILED( hr ) )
  128. {
  129. DPFX(DPFPREP, DVF_ERRORLEVEL, "Unable to un-load compression info: hr=0x%x", hr );
  130. return hr;
  131. }
  132. DNDeleteCriticalSection( &s_csSTLLock );
  133. return DV_OK;
  134. }
  135. #undef DPF_MODNAME
  136. #define DPF_MODNAME "CDirectVoiceEngine::ValidateSpeechPacketSize"
  137. //
  138. // ValidateSpeechPacketSize
  139. //
  140. // Called to make sure the speech packet size is valid
  141. //
  142. BOOL CDirectVoiceEngine::ValidateSpeechPacketSize(const DVFULLCOMPRESSIONINFO* lpdvfCompressionInfo, DWORD dwSize)
  143. {
  144. BOOL bValid;
  145. // return true in this case because it isn't a hack attempt
  146. if( lpdvfCompressionInfo == NULL)
  147. return TRUE;
  148. // Check for VR12
  149. if( lpdvfCompressionInfo->guidType == DPVCTGUID_VR12 )
  150. bValid = ( dwSize <= lpdvfCompressionInfo->dwFrameLength && dwSize > 0 );
  151. else
  152. bValid = ( dwSize == lpdvfCompressionInfo->dwFrameLength );
  153. return bValid;
  154. }