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.

218 lines
6.3 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: diagnos.cpp
  6. * Content: Utility functions to write out diagnostic files when registry key is set.
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/13/00 rodtoll Created (Bug #31468 - Add diagnostic spew to logfile to show what is failing
  12. * 08/22/2000 rodtoll Bug #43060 - DPVOICE: Diagnostics data which is dumped to memory / debugger contains garbage
  13. * 02/28/2002 rodtoll Fix for regression caused by TCHAR conversion (Post DirectX 8.1 work)
  14. * - Source was updated to retrieve device information from DirectSound w/Unicode
  15. * but routines which wanted the information needed Unicode.
  16. *
  17. ***************************************************************************/
  18. #include "dxvutilspch.h"
  19. #undef DPF_SUBCOMP
  20. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  21. #define DPLOG_MAX_STRING 256
  22. FILE *g_hOutputFile = NULL;
  23. BOOL g_fDiagnosisEnabled = FALSE;
  24. #undef DPF_MODNAME
  25. #define DPF_MODNAME "Diagnostics_WriteDeviceInfo"
  26. void Diagnostics_WriteDeviceInfo( DWORD dwLevel, const char *szDeviceName, PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA pData )
  27. {
  28. Diagnostics_Write( dwLevel, "%hs Device Information:", szDeviceName );
  29. Diagnostics_Write( dwLevel, "Device Name:\n%hs", pData->Description ? pData->Description : "<NULL>");
  30. Diagnostics_Write( dwLevel, "Device ID:" );
  31. Diagnostics_WriteGUID(dwLevel, pData->DeviceId );
  32. switch( pData->Type )
  33. {
  34. case DIRECTSOUNDDEVICE_TYPE_EMULATED: Diagnostics_Write( dwLevel, "Device Type:\nEmulated" ); break;
  35. case DIRECTSOUNDDEVICE_TYPE_VXD: Diagnostics_Write( dwLevel, "Device Type:\nVXD" ); break;
  36. case DIRECTSOUNDDEVICE_TYPE_WDM: Diagnostics_Write( dwLevel, "Device Type:\nWDM" ); break;
  37. default: Diagnostics_Write( dwLevel, "Device Type:\n<UNKNOWN>" ); break;
  38. }
  39. Diagnostics_Write( dwLevel, "Description:\n%hs", pData->Description ? pData->Description : "<NULL>" );
  40. Diagnostics_Write( dwLevel, "Module:\n%hs", pData->Module ? pData->Module : "<NULL>" );
  41. Diagnostics_Write( dwLevel, "WaveID:\n%d", pData->WaveDeviceId );
  42. }
  43. #undef DPF_MODNAME
  44. #define DPF_MODNAME "Diagnostics_DeviceInfo"
  45. HRESULT Diagnostics_DeviceInfo( const GUID *pguidPlayback, const GUID *pguidCapture )
  46. {
  47. if( !g_fDiagnosisEnabled )
  48. return DV_OK;
  49. LPKSPROPERTYSET lpksProperty = NULL;
  50. HRESULT hr = DV_OK;
  51. GUID guidTruePlayback;
  52. GUID guidTrueCapture;
  53. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA pPlaybackDesc = NULL;
  54. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA pCaptureDesc = NULL;
  55. hr = DV_MapCaptureDevice( pguidPlayback, &guidTruePlayback );
  56. if( FAILED( hr ) )
  57. {
  58. DPFX(DPFPREP, 0, "Error getting true playback device hr=0x%x", hr );
  59. goto DEVICEINFO_EXIT;
  60. }
  61. hr = DV_MapPlaybackDevice( pguidCapture, &guidTrueCapture );
  62. if( FAILED( hr ) )
  63. {
  64. DPFX(DPFPREP, 0, "Error getting true capture device hr=0x%x", hr );
  65. goto DEVICEINFO_EXIT;
  66. }
  67. hr = DirectSoundPrivateCreate( &lpksProperty );
  68. if( FAILED( hr ) )
  69. {
  70. DPFX(DPFPREP, 0, "Error getting interface to get device name hr=0x%x", hr );
  71. goto DEVICEINFO_EXIT;
  72. }
  73. hr = PrvGetDeviceDescription( lpksProperty, guidTruePlayback, &pPlaybackDesc );
  74. if( FAILED( hr ) )
  75. {
  76. DPFX(DPFPREP, 0, "Error getting device description hr=0x%x", hr );
  77. goto DEVICEINFO_EXIT;
  78. }
  79. Diagnostics_WriteDeviceInfo( DVF_INFOLEVEL, "Playback", pPlaybackDesc );
  80. hr = PrvGetDeviceDescription( lpksProperty, guidTrueCapture, &pCaptureDesc );
  81. if( FAILED( hr ) )
  82. {
  83. DPFX(DPFPREP, 0, "Error getting device description hr=0x%x", hr );
  84. goto DEVICEINFO_EXIT;
  85. }
  86. Diagnostics_WriteDeviceInfo( DVF_INFOLEVEL, "Capture", pPlaybackDesc );
  87. DEVICEINFO_EXIT:
  88. if( pPlaybackDesc )
  89. delete pPlaybackDesc;
  90. if( pCaptureDesc )
  91. delete pCaptureDesc;
  92. if( lpksProperty )
  93. {
  94. lpksProperty->Release();
  95. }
  96. return hr;
  97. }
  98. #undef DPF_MODNAME
  99. #define DPF_MODNAME "Diagnostics_Begin"
  100. HRESULT Diagnostics_Begin( BOOL fEnabled, const char *szFileName )
  101. {
  102. // Prevent double-open
  103. if( g_fDiagnosisEnabled )
  104. return DV_OK;
  105. HRESULT hr = DV_OK;
  106. g_fDiagnosisEnabled = fEnabled;
  107. if( !fEnabled )
  108. return DV_OK;
  109. g_hOutputFile = fopen( szFileName, "w" );
  110. if( !g_hOutputFile )
  111. {
  112. hr = DVERR_GENERIC;
  113. DPFX(DPFPREP, 0, "Error opening diagnostics file" );
  114. goto BEGIN_ERROR;
  115. }
  116. return DV_OK;
  117. BEGIN_ERROR:
  118. Diagnostics_End();
  119. return hr;
  120. }
  121. #undef DPF_MODNAME
  122. #define DPF_MODNAME "Diagnostics_End"
  123. void Diagnostics_End()
  124. {
  125. if( g_fDiagnosisEnabled )
  126. {
  127. if( g_hOutputFile )
  128. {
  129. fclose( g_hOutputFile );
  130. g_hOutputFile = NULL;
  131. }
  132. g_fDiagnosisEnabled = FALSE;
  133. }
  134. }
  135. #undef DPF_MODNAME
  136. #define DPF_MODNAME "Diagnostics_Write"
  137. void Diagnostics_Write( DWORD dwLevel, const char *szFormat, ... )
  138. {
  139. char szBuffer[DPLOG_MAX_STRING];
  140. va_list argptr;
  141. va_start(argptr, szFormat);
  142. if( g_fDiagnosisEnabled )
  143. {
  144. vfprintf( g_hOutputFile, szFormat, argptr );
  145. fputs( "\n", g_hOutputFile );
  146. }
  147. _vsnprintf( szBuffer, DPLOG_MAX_STRING, szFormat, argptr );
  148. DPFX(DPFPREP, dwLevel, szBuffer );
  149. va_end(argptr);
  150. fflush( g_hOutputFile );
  151. }
  152. #undef DPF_MODNAME
  153. #define DPF_MODNAME "Diagnositcs_WriteWAVEFORMATEX"
  154. void Diagnostics_WriteGUID( DWORD dwLevel, GUID &guid )
  155. {
  156. Diagnostics_Write( dwLevel, "{%-08.8X-%-04.4X-%-04.4X-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}", guid.Data1, guid.Data2, guid.Data3,
  157. guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
  158. guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] );
  159. }
  160. #undef DPF_MODNAME
  161. #define DPF_MODNAME "Diagnositcs_WriteWAVEFORMATEX"
  162. void Diagnositcs_WriteWAVEFORMATEX( DWORD dwLevel, PWAVEFORMATEX lpwfxFormat )
  163. {
  164. Diagnostics_Write( dwLevel, "wFormatTag = %d", lpwfxFormat->wFormatTag );
  165. Diagnostics_Write( dwLevel, "nSamplesPerSec = %d", lpwfxFormat->nSamplesPerSec );
  166. Diagnostics_Write( dwLevel, "nChannels = %d", lpwfxFormat->nChannels );
  167. Diagnostics_Write( dwLevel, "wBitsPerSample = %d", lpwfxFormat->wBitsPerSample );
  168. Diagnostics_Write( dwLevel, "nAvgBytesPerSec = %d", lpwfxFormat->nAvgBytesPerSec );
  169. Diagnostics_Write( dwLevel, "nBlockAlign = %d", lpwfxFormat->nBlockAlign );
  170. Diagnostics_Write( dwLevel, "cbSize = %d", lpwfxFormat->cbSize );
  171. }