Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendetect.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Sound System "MME Buddy" NT4 Library 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: lib/drivers/sound/mment4/detect.c 00005 * 00006 * PURPOSE: Assists in locating Windows NT4 compatible sound devices, 00007 * which mostly use the same device naming convention and/or 00008 * store their created device names within their service key 00009 * within the registry. 00010 * 00011 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org) 00012 */ 00013 00014 #include "precomp.h" 00015 00016 /* 00017 This is the "nice" way to discover audio devices in NT4 - go into the 00018 service registry key and enumerate the Parameters\Device*\Devices 00019 values. The value names represent the device name, whereas the data 00020 assigned to them identifies the type of device. 00021 */ 00022 MMRESULT 00023 EnumerateNt4ServiceSoundDevices( 00024 IN LPWSTR ServiceName, 00025 IN MMDEVICE_TYPE DeviceType, 00026 IN SOUND_DEVICE_DETECTED_PROC SoundDeviceDetectedProc) 00027 { 00028 HKEY Key; 00029 DWORD KeyIndex = 0; 00030 00031 VALIDATE_MMSYS_PARAMETER( ServiceName ); 00032 00033 /* Device type zero means "all" */ 00034 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceType(DeviceType) || 00035 DeviceType == 0 ); 00036 00037 while ( OpenSoundDeviceRegKey(ServiceName, KeyIndex, &Key) == MMSYSERR_NOERROR ) 00038 { 00039 HKEY DevicesKey; 00040 DWORD ValueType = REG_NONE, ValueIndex = 0; 00041 DWORD MaxNameLength = 0, ValueNameLength = 0; 00042 PWSTR DevicePath = NULL, ValueName = NULL; 00043 DWORD ValueDataLength = sizeof(DWORD); 00044 DWORD ValueData; 00045 00046 if ( RegOpenKeyEx(Key, 00047 REG_DEVICES_KEY_NAME_U, 00048 0, 00049 KEY_READ, 00050 &DevicesKey) == ERROR_SUCCESS ) 00051 { 00052 /* Find out how much memory is needed for the key name */ 00053 if ( RegQueryInfoKey(DevicesKey, 00054 NULL, NULL, NULL, NULL, NULL, NULL, NULL, 00055 &MaxNameLength, 00056 NULL, NULL, NULL) != ERROR_SUCCESS ) 00057 { 00058 SND_ERR(L"Failed to query registry key information\n"); 00059 RegCloseKey(DevicesKey); 00060 RegCloseKey(Key); 00061 00062 return MMSYSERR_ERROR; 00063 } 00064 00065 DevicePath = AllocateWideString(MaxNameLength + 00066 strlen("\\\\.\\")); 00067 00068 /* Check that the memory allocation was successful */ 00069 if ( ! DevicePath ) 00070 { 00071 /* There's no point in going further */ 00072 RegCloseKey(DevicesKey); 00073 RegCloseKey(Key); 00074 00075 return MMSYSERR_NOMEM; 00076 } 00077 00078 /* Insert the device path prefix */ 00079 wsprintf(DevicePath, L"\\\\.\\"); 00080 00081 /* The offset of the string following this prefix */ 00082 ValueName = DevicePath + strlen("\\\\.\\"); 00083 00084 /* Copy this so that it may be overwritten - include NULL */ 00085 ValueNameLength = MaxNameLength + sizeof(WCHAR); 00086 00087 SND_TRACE(L"Interested in devices beginning with %wS\n", DevicePath); 00088 00089 while ( RegEnumValue(DevicesKey, 00090 ValueIndex, 00091 ValueName, 00092 &ValueNameLength, 00093 NULL, 00094 &ValueType, 00095 (LPBYTE) &ValueData, 00096 &ValueDataLength) == ERROR_SUCCESS ) 00097 { 00098 /* Device types are stored as DWORDs */ 00099 if ( ( ValueType == REG_DWORD ) && 00100 ( ValueDataLength == sizeof(DWORD) ) ) 00101 { 00102 if ( ( DeviceType == 0 ) || 00103 ( DeviceType == ValueData ) ) 00104 { 00105 SND_TRACE(L"Found device: %wS\n", DevicePath); 00106 SoundDeviceDetectedProc(ValueData, DevicePath); 00107 } 00108 } 00109 00110 /* Reset variables for the next iteration */ 00111 ValueNameLength = MaxNameLength + sizeof(WCHAR); 00112 ZeroMemory(ValueName, (MaxNameLength+1)*sizeof(WCHAR)); 00113 /*ZeroWideString(ValueName);*/ 00114 ValueDataLength = sizeof(DWORD); 00115 ValueData = 0; 00116 ValueType = REG_NONE; 00117 00118 ++ ValueIndex; 00119 } 00120 00121 FreeMemory(DevicePath); 00122 00123 RegCloseKey(DevicesKey); 00124 } 00125 else 00126 { 00127 SND_WARN(L"Unable to open the Devices key!\n"); 00128 } 00129 00130 ++ KeyIndex; 00131 00132 RegCloseKey(Key); 00133 } 00134 00135 return MMSYSERR_NOERROR; 00136 } 00137 00138 /* 00139 Brute-force device detection, using a base device name (eg: \\.\WaveOut). 00140 00141 This will add the device number as a suffix to the end of the string and 00142 attempt to open the device based on that name. On success, it will 00143 increment the device number and repeat this process. 00144 00145 When it runs out of devices, it will give up. 00146 */ 00147 MMRESULT 00148 DetectNt4SoundDevices( 00149 IN MMDEVICE_TYPE DeviceType, 00150 IN PWSTR BaseDeviceName, 00151 IN SOUND_DEVICE_DETECTED_PROC SoundDeviceDetectedProc) 00152 { 00153 ULONG DeviceNameLength = 0; 00154 PWSTR DeviceName = NULL; 00155 ULONG Index = 0; 00156 HANDLE DeviceHandle; 00157 BOOLEAN DoSearch = TRUE; 00158 00159 VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceType(DeviceType) ); 00160 00161 DeviceNameLength = wcslen(BaseDeviceName); 00162 /* Consider the length of the number */ 00163 DeviceNameLength += GetDigitCount(Index); 00164 00165 DeviceName = AllocateWideString(DeviceNameLength); 00166 00167 if ( ! DeviceName ) 00168 { 00169 return MMSYSERR_NOMEM; 00170 } 00171 00172 while ( DoSearch ) 00173 { 00174 /* Nothing like a nice clean device name */ 00175 ZeroWideString(DeviceName); 00176 wsprintf(DeviceName, L"%ls%d", BaseDeviceName, Index); 00177 00178 if ( OpenKernelSoundDeviceByName(DeviceName, 00179 TRUE, 00180 &DeviceHandle) == MMSYSERR_NOERROR ) 00181 { 00182 /* Notify the callback function */ 00183 SND_TRACE(L"Found device: %wS\n", DeviceName); 00184 SoundDeviceDetectedProc(DeviceType, DeviceName); 00185 00186 CloseHandle(DeviceHandle); 00187 00188 ++ Index; 00189 } 00190 else 00191 { 00192 DoSearch = FALSE; 00193 } 00194 } 00195 00196 FreeMemory(DeviceName); 00197 00198 return MMSYSERR_NOERROR; 00199 } Generated on Fri May 25 2012 04:26:03 for ReactOS by
1.7.6.1
|