1 /* 2 * PROJECT: ReactOS Sound System 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: dll/win32/wdmaud.drv/wdmaud.c 5 * 6 * PURPOSE: WDM Audio Driver (User-mode part) 7 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org) 8 * 9 * NOTES: Looking for wodMessage & co? You won't find them here. Try 10 * the MME Buddy library, which is where these routines are 11 * actually implemented. 12 * 13 */ 14 15 #include "wdmaud.h" 16 17 #define NDEBUG 18 #include <debug.h> 19 #include <mmebuddy_debug.h> 20 21 #define USE_MMIXER_LIB 22 #ifndef USE_MMIXER_LIB 23 #define FUNC_NAME(x) x##ByLegacy 24 #else 25 #define FUNC_NAME(x) x##ByMMixer 26 #endif 27 28 MMRESULT 29 QueryWdmWaveDeviceFormatSupport( 30 IN PSOUND_DEVICE Device, 31 IN PWAVEFORMATEX WaveFormat, 32 IN DWORD WaveFormatSize) 33 { 34 /* Whatever... */ 35 return MMSYSERR_NOERROR; 36 } 37 38 MMRESULT 39 PopulateWdmDeviceList( 40 MMDEVICE_TYPE DeviceType) 41 { 42 MMRESULT Result; 43 DWORD DeviceCount = 0; 44 PSOUND_DEVICE SoundDevice = NULL; 45 MMFUNCTION_TABLE FuncTable; 46 DWORD i; 47 48 VALIDATE_MMSYS_PARAMETER( IS_VALID_SOUND_DEVICE_TYPE(DeviceType) ); 49 50 Result = FUNC_NAME(WdmAudGetNumWdmDevs)(DeviceType, &DeviceCount); 51 52 if ( ! MMSUCCESS(Result) ) 53 { 54 SND_ERR(L"Error %d while obtaining number of devices\n", Result); 55 return TranslateInternalMmResult(Result); 56 } 57 58 SND_TRACE(L"%d devices of type %d found\n", DeviceCount, DeviceType); 59 60 61 for ( i = 0; i < DeviceCount; ++ i ) 62 { 63 Result = ListSoundDevice(DeviceType, UlongToPtr(i), &SoundDevice); 64 65 if ( ! MMSUCCESS(Result) ) 66 { 67 SND_ERR(L"Failed to list sound device - error %d\n", Result); 68 return TranslateInternalMmResult(Result); 69 } 70 71 /* Set up our function table */ 72 ZeroMemory(&FuncTable, sizeof(MMFUNCTION_TABLE)); 73 FuncTable.GetCapabilities = FUNC_NAME(WdmAudGetCapabilities); 74 FuncTable.QueryWaveFormatSupport = QueryWdmWaveDeviceFormatSupport; //FIXME 75 FuncTable.Open = FUNC_NAME(WdmAudOpenSoundDevice); 76 FuncTable.Close = FUNC_NAME(WdmAudCloseSoundDevice); 77 FuncTable.GetDeviceInterfaceString = FUNC_NAME(WdmAudGetDeviceInterfaceString); 78 79 if (DeviceType == MIXER_DEVICE_TYPE) 80 { 81 FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetMixerDeviceFormat); 82 FuncTable.QueryMixerInfo = FUNC_NAME(WdmAudQueryMixerInfo); 83 } 84 else if (DeviceType == WAVE_IN_DEVICE_TYPE || DeviceType == WAVE_OUT_DEVICE_TYPE) 85 { 86 FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetWaveDeviceFormat); 87 FuncTable.SetState = FUNC_NAME(WdmAudSetWaveState); 88 FuncTable.ResetStream = FUNC_NAME(WdmAudResetStream); 89 FuncTable.GetPos = FUNC_NAME(WdmAudGetWavePosition); 90 91 #ifndef USERMODE_MIXER 92 FuncTable.CommitWaveBuffer = FUNC_NAME(WdmAudCommitWaveBuffer); 93 #else 94 FuncTable.CommitWaveBuffer = WriteFileEx_Remixer; 95 #endif 96 } 97 else if (DeviceType == MIDI_IN_DEVICE_TYPE || DeviceType == MIDI_OUT_DEVICE_TYPE) 98 { 99 FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetMixerDeviceFormat); 100 FuncTable.SetState = FUNC_NAME(WdmAudSetWaveState); 101 FuncTable.GetPos = FUNC_NAME(WdmAudGetWavePosition); 102 } 103 104 SetSoundDeviceFunctionTable(SoundDevice, &FuncTable); 105 } 106 107 return MMSYSERR_NOERROR; 108 } 109 110 111 112 LONG 113 APIENTRY 114 DriverProc( 115 DWORD DriverId, 116 HANDLE DriverHandle, 117 UINT Message, 118 LONG Parameter1, 119 LONG Parameter2) 120 { 121 switch ( Message ) 122 { 123 case DRV_LOAD : 124 { 125 HANDLE Handle; 126 MMRESULT Result; 127 SND_TRACE(L"DRV_LOAD\n"); 128 129 Result = InitEntrypointMutexes(); 130 131 if ( ! MMSUCCESS(Result) ) 132 return 0L; 133 134 Result = FUNC_NAME(WdmAudOpenSoundDevice)(NULL, &Handle); 135 136 if ( Result != MMSYSERR_NOERROR ) 137 { 138 SND_ERR(L"Failed to open \\\\.\\wdmaud\n"); 139 //UnlistAllSoundDevices(); 140 141 return 0L; 142 } 143 144 /* Populate the device lists */ 145 SND_TRACE(L"Populating device lists\n"); 146 PopulateWdmDeviceList(WAVE_OUT_DEVICE_TYPE); 147 PopulateWdmDeviceList(WAVE_IN_DEVICE_TYPE); 148 PopulateWdmDeviceList(MIDI_OUT_DEVICE_TYPE); 149 PopulateWdmDeviceList(MIDI_IN_DEVICE_TYPE); 150 PopulateWdmDeviceList(AUX_DEVICE_TYPE); 151 PopulateWdmDeviceList(MIXER_DEVICE_TYPE); 152 153 SND_TRACE(L"Initialisation complete\n"); 154 155 return 1L; 156 } 157 158 case DRV_FREE : 159 { 160 SND_TRACE(L"DRV_FREE\n"); 161 162 FUNC_NAME(WdmAudCleanup)(); 163 164 /* TODO: Clean up the path names! */ 165 UnlistAllSoundDevices(); 166 167 CleanupEntrypointMutexes(); 168 169 SND_TRACE(L"Unfreed memory blocks: %d\n", 170 GetMemoryAllocationCount()); 171 172 return 1L; 173 } 174 175 case DRV_ENABLE : 176 case DRV_DISABLE : 177 { 178 SND_TRACE(L"DRV_ENABLE / DRV_DISABLE\n"); 179 return 1L; 180 } 181 182 case DRV_OPEN : 183 case DRV_CLOSE : 184 { 185 SND_TRACE(L"DRV_OPEN / DRV_CLOSE\n"); 186 return 1L; 187 } 188 189 case DRV_QUERYCONFIGURE : 190 { 191 SND_TRACE(L"DRV_QUERYCONFIGURE\n"); 192 return 0L; 193 } 194 case DRV_CONFIGURE : 195 return DRVCNF_OK; 196 197 default : 198 SND_TRACE(L"Unhandled message %d\n", Message); 199 return DefDriverProc(DriverId, 200 DriverHandle, 201 Message, 202 Parameter1, 203 Parameter2); 204 } 205 } 206 207 208 BOOL WINAPI DllMain( 209 HINSTANCE hinstDLL, 210 DWORD fdwReason, 211 LPVOID lpvReserved) 212 { 213 switch ( fdwReason ) 214 { 215 case DLL_PROCESS_ATTACH : 216 SND_TRACE(L"WDMAUD.DRV - Process attached\n"); 217 break; 218 case DLL_PROCESS_DETACH : 219 SND_TRACE(L"WDMAUD.DRV - Process detached\n"); 220 break; 221 case DLL_THREAD_ATTACH : 222 SND_TRACE(L"WDMAUD.DRV - Thread attached\n"); 223 break; 224 case DLL_THREAD_DETACH : 225 SND_TRACE(L"WDMAUD.DRV - Thread detached\n"); 226 break; 227 } 228 229 return TRUE; 230 } 231