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.

215 lines
5.9 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. *
  14. ***************************************************************************/
  15. #include "dxvutilspch.h"
  16. #undef DPF_SUBCOMP
  17. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  18. #define DPLOG_MAX_STRING 256
  19. FILE *g_hOutputFile = NULL;
  20. BOOL g_fDiagnosisEnabled = FALSE;
  21. #undef DPF_MODNAME
  22. #define DPF_MODNAME "Diagnostics_WriteDeviceInfo"
  23. void Diagnostics_WriteDeviceInfo( DWORD dwLevel, const char *szDeviceName, PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA pData )
  24. {
  25. Diagnostics_Write( dwLevel, "%s Device Information:", szDeviceName );
  26. Diagnostics_Write( dwLevel, "Device Name:\n%s", pData->Description ? pData->Description : "<NULL>");
  27. Diagnostics_Write( dwLevel, "Device ID:" );
  28. Diagnostics_WriteGUID(dwLevel, pData->DeviceId );
  29. switch( pData->Type )
  30. {
  31. case DIRECTSOUNDDEVICE_TYPE_EMULATED: Diagnostics_Write( dwLevel, "Device Type:\nEmulated" ); break;
  32. case DIRECTSOUNDDEVICE_TYPE_VXD: Diagnostics_Write( dwLevel, "Device Type:\nVXD" ); break;
  33. case DIRECTSOUNDDEVICE_TYPE_WDM: Diagnostics_Write( dwLevel, "Device Type:\nWDM" ); break;
  34. default: Diagnostics_Write( dwLevel, "Device Type:\n<UNKNOWN>" ); break;
  35. }
  36. Diagnostics_Write( dwLevel, "Description:\n%s", pData->Description ? pData->Description : "<NULL>" );
  37. Diagnostics_Write( dwLevel, "Module:\n%s", pData->Module ? pData->Module : "<NULL>" );
  38. Diagnostics_Write( dwLevel, "WaveID:\n%d", pData->WaveDeviceId );
  39. }
  40. #undef DPF_MODNAME
  41. #define DPF_MODNAME "Diagnostics_DeviceInfo"
  42. HRESULT Diagnostics_DeviceInfo( GUID *pguidPlayback, GUID *pguidCapture )
  43. {
  44. if( !g_fDiagnosisEnabled )
  45. return DV_OK;
  46. LPKSPROPERTYSET lpksProperty = NULL;
  47. HRESULT hr = DV_OK;
  48. GUID guidTruePlayback;
  49. GUID guidTrueCapture;
  50. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA pPlaybackDesc = NULL;
  51. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA pCaptureDesc = NULL;
  52. hr = DV_MapCaptureDevice( pguidPlayback, &guidTruePlayback );
  53. if( FAILED( hr ) )
  54. {
  55. DPFX(DPFPREP, 0, "Error getting true playback device hr=0x%x", hr );
  56. goto DEVICEINFO_EXIT;
  57. }
  58. hr = DV_MapPlaybackDevice( pguidCapture, &guidTrueCapture );
  59. if( FAILED( hr ) )
  60. {
  61. DPFX(DPFPREP, 0, "Error getting true capture device hr=0x%x", hr );
  62. goto DEVICEINFO_EXIT;
  63. }
  64. hr = DirectSoundPrivateCreate( &lpksProperty );
  65. if( FAILED( hr ) )
  66. {
  67. DPFX(DPFPREP, 0, "Error getting interface to get device name hr=0x%x", hr );
  68. goto DEVICEINFO_EXIT;
  69. }
  70. hr = PrvGetDeviceDescription( lpksProperty, guidTruePlayback, &pPlaybackDesc );
  71. if( FAILED( hr ) )
  72. {
  73. DPFX(DPFPREP, 0, "Error getting device description hr=0x%x", hr );
  74. goto DEVICEINFO_EXIT;
  75. }
  76. Diagnostics_WriteDeviceInfo( DVF_INFOLEVEL, "Playback", pPlaybackDesc );
  77. hr = PrvGetDeviceDescription( lpksProperty, guidTrueCapture, &pCaptureDesc );
  78. if( FAILED( hr ) )
  79. {
  80. DPFX(DPFPREP, 0, "Error getting device description hr=0x%x", hr );
  81. goto DEVICEINFO_EXIT;
  82. }
  83. Diagnostics_WriteDeviceInfo( DVF_INFOLEVEL, "Capture", pPlaybackDesc );
  84. DEVICEINFO_EXIT:
  85. if( pPlaybackDesc )
  86. delete pPlaybackDesc;
  87. if( pCaptureDesc )
  88. delete pCaptureDesc;
  89. if( lpksProperty )
  90. {
  91. lpksProperty->Release();
  92. }
  93. return hr;
  94. }
  95. #undef DPF_MODNAME
  96. #define DPF_MODNAME "Diagnostics_Begin"
  97. HRESULT Diagnostics_Begin( BOOL fEnabled, const char *szFileName )
  98. {
  99. // Prevent double-open
  100. if( g_fDiagnosisEnabled )
  101. return DV_OK;
  102. HRESULT hr = DV_OK;
  103. g_fDiagnosisEnabled = fEnabled;
  104. if( !fEnabled )
  105. return DV_OK;
  106. g_hOutputFile = fopen( szFileName, "w" );
  107. if( !g_hOutputFile )
  108. {
  109. hr = DVERR_GENERIC;
  110. DPFX(DPFPREP, 0, "Error opening diagnostics file" );
  111. goto BEGIN_ERROR;
  112. }
  113. return DV_OK;
  114. BEGIN_ERROR:
  115. Diagnostics_End();
  116. return hr;
  117. }
  118. #undef DPF_MODNAME
  119. #define DPF_MODNAME "Diagnostics_End"
  120. void Diagnostics_End()
  121. {
  122. if( g_fDiagnosisEnabled )
  123. {
  124. if( g_hOutputFile )
  125. {
  126. fclose( g_hOutputFile );
  127. g_hOutputFile = NULL;
  128. }
  129. g_fDiagnosisEnabled = FALSE;
  130. }
  131. }
  132. #undef DPF_MODNAME
  133. #define DPF_MODNAME "Diagnostics_Write"
  134. void Diagnostics_Write( DWORD dwLevel, const char *szFormat, ... )
  135. {
  136. char szBuffer[DPLOG_MAX_STRING];
  137. va_list argptr;
  138. va_start(argptr, szFormat);
  139. if( g_fDiagnosisEnabled )
  140. {
  141. vfprintf( g_hOutputFile, szFormat, argptr );
  142. fputs( "\n", g_hOutputFile );
  143. }
  144. _vsnprintf( szBuffer, DPLOG_MAX_STRING, szFormat, argptr );
  145. DPFX(DPFPREP, dwLevel, szBuffer );
  146. va_end(argptr);
  147. fflush( g_hOutputFile );
  148. }
  149. #undef DPF_MODNAME
  150. #define DPF_MODNAME "Diagnositcs_WriteWAVEFORMATEX"
  151. void Diagnostics_WriteGUID( DWORD dwLevel, GUID &guid )
  152. {
  153. 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,
  154. guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
  155. guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] );
  156. }
  157. #undef DPF_MODNAME
  158. #define DPF_MODNAME "Diagnositcs_WriteWAVEFORMATEX"
  159. void Diagnositcs_WriteWAVEFORMATEX( DWORD dwLevel, PWAVEFORMATEX lpwfxFormat )
  160. {
  161. Diagnostics_Write( dwLevel, "wFormatTag = %d", lpwfxFormat->wFormatTag );
  162. Diagnostics_Write( dwLevel, "nSamplesPerSec = %d", lpwfxFormat->nSamplesPerSec );
  163. Diagnostics_Write( dwLevel, "nChannels = %d", lpwfxFormat->nChannels );
  164. Diagnostics_Write( dwLevel, "wBitsPerSample = %d", lpwfxFormat->wBitsPerSample );
  165. Diagnostics_Write( dwLevel, "nAvgBytesPerSec = %d", lpwfxFormat->nAvgBytesPerSec );
  166. Diagnostics_Write( dwLevel, "nBlockAlign = %d", lpwfxFormat->nBlockAlign );
  167. Diagnostics_Write( dwLevel, "cbSize = %d", lpwfxFormat->cbSize );
  168. }