2 * PROJECT: ReactOS Sound System
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/wdmaud.drv/wdmaud.c
6 * PURPOSE: WDM Audio Driver (User-mode part)
7 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
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.
17 HANDLE KernelHandle
= INVALID_HANDLE_VALUE
;
20 QueryWdmWaveDeviceFormatSupport(
21 IN PSOUND_DEVICE Device
,
22 IN PWAVEFORMATEX WaveFormat
,
23 IN DWORD WaveFormatSize
)
26 return MMSYSERR_NOERROR
;
31 PopulateWdmDeviceList(
32 MMDEVICE_TYPE DeviceType
)
35 DWORD DeviceCount
= 0;
36 PSOUND_DEVICE SoundDevice
= NULL
;
37 MMFUNCTION_TABLE FuncTable
;
40 VALIDATE_MMSYS_PARAMETER( IS_VALID_SOUND_DEVICE_TYPE(DeviceType
) );
43 Result
= WdmAudGetNumDevsByMMixer(DeviceType
, &DeviceCount
);
45 Result
= WdmAudGetNumWdmDevsByLegacy(DeviceType
, &DeviceCount
);
48 if ( ! MMSUCCESS(Result
) )
50 SND_ERR(L
"Error %d while obtaining number of devices\n", Result
);
51 return TranslateInternalMmResult(Result
);
54 SND_TRACE(L
"%d devices of type %d found\n", DeviceCount
, DeviceType
);
57 for ( i
= 0; i
< DeviceCount
; ++ i
)
59 Result
= ListSoundDevice(DeviceType
, UlongToPtr(i
), &SoundDevice
);
61 if ( ! MMSUCCESS(Result
) )
63 SND_ERR(L
"Failed to list sound device - error %d\n", Result
);
64 return TranslateInternalMmResult(Result
);
67 /* Set up our function table */
68 ZeroMemory(&FuncTable
, sizeof(MMFUNCTION_TABLE
));
70 FuncTable
.GetCapabilities
= WdmAudGetCapabilitiesByMMixer
;
71 FuncTable
.Open
= WdmAudOpenSoundDeviceByMMixer
;
72 FuncTable
.Close
= WdmAudCloseSoundDeviceByMMixer
;
73 FuncTable
.GetDeviceInterfaceString
= WdmAudGetDeviceInterfaceStringByMMixer
;
75 FuncTable
.GetCapabilities
= WdmAudGetCapabilitiesByLegacy
;
76 FuncTable
.Open
= WdmAudOpenSoundDeviceByLegacy
;
77 FuncTable
.Close
= WdmAudCloseSoundDeviceByLegacy
;
78 FuncTable
.GetDeviceInterfaceString
= WdmAudGetDeviceInterfaceStringByLegacy
;
81 FuncTable
.QueryWaveFormatSupport
= QueryWdmWaveDeviceFormatSupport
;
82 if (DeviceType
== MIXER_DEVICE_TYPE
)
85 FuncTable
.SetWaveFormat
= WdmAudSetMixerDeviceFormatByMMixer
;
86 FuncTable
.QueryMixerInfo
= WdmAudQueryMixerInfoByMMixer
;
88 FuncTable
.SetWaveFormat
= WdmAudSetMixerDeviceFormatByLegacy
;
89 FuncTable
.QueryMixerInfo
= WdmAudQueryMixerInfoByLegacy
;
93 if (DeviceType
== WAVE_IN_DEVICE_TYPE
|| DeviceType
== WAVE_OUT_DEVICE_TYPE
)
96 FuncTable
.SetWaveFormat
= WdmAudSetWdmWaveDeviceFormatByMMixer
;
97 FuncTable
.SetState
= WdmAudSetWdmWaveStateByMMixer
;
98 FuncTable
.ResetStream
= WdmAudResetStreamByMMixer
;
99 FuncTable
.GetPos
= WdmAudGetWdmPositionByMMixer
;
101 FuncTable
.SetWaveFormat
= WdmAudSetWaveDeviceFormatByLegacy
;
102 FuncTable
.SetState
= WdmAudSetWaveStateByLegacy
;
103 FuncTable
.ResetStream
= WdmAudResetStreamByLegacy
;
104 FuncTable
.GetPos
= WdmAudGetWavePositionByLegacy
;
107 #ifdef USE_MMIXER_LIB
108 FuncTable
.CommitWaveBuffer
= WdmAudCommitWaveBufferByMMixer
;
109 #elif defined (USERMODE_MIXER)
110 FuncTable
.CommitWaveBuffer
= WriteFileEx_Remixer
;
112 FuncTable
.CommitWaveBuffer
= WriteFileEx_Committer2
;
116 SetSoundDeviceFunctionTable(SoundDevice
, &FuncTable
);
119 return MMSYSERR_NOERROR
;
137 #ifndef USE_MMIXER_LIB
141 SND_TRACE(L
"DRV_LOAD\n");
143 Result
= InitEntrypointMutexes();
145 if ( ! MMSUCCESS(Result
) )
148 #ifdef USE_MMIXER_LIB
149 if (!WdmAudInitUserModeMixer())
151 SND_ERR(L
"Failed to initialize mmixer lib\n");
155 if (WdmAudOpenSoundDeviceByLegacy() != MMSYSERR_NOERROR
)
157 SND_ERR(L
"Failed to open %s\n", KERNEL_DEVICE_NAME
);
158 CleanupEntrypointMutexes();
160 //UnlistAllSoundDevices();
166 /* Populate the device lists */
167 SND_TRACE(L
"Populating device lists\n");
168 PopulateWdmDeviceList(WAVE_OUT_DEVICE_TYPE
);
169 PopulateWdmDeviceList(WAVE_IN_DEVICE_TYPE
);
170 PopulateWdmDeviceList(MIDI_OUT_DEVICE_TYPE
);
171 PopulateWdmDeviceList(MIDI_IN_DEVICE_TYPE
);
172 PopulateWdmDeviceList(AUX_DEVICE_TYPE
);
173 PopulateWdmDeviceList(MIXER_DEVICE_TYPE
);
175 SND_TRACE(L
"Initialisation complete\n");
182 SND_TRACE(L
"DRV_FREE\n");
184 #ifdef USE_MMIXER_LIB
185 WdmAudCleanupMMixer();
187 WdmAudCleanupLegacy();
190 /* TODO: Clean up the path names! */
191 UnlistAllSoundDevices();
193 CleanupEntrypointMutexes();
195 SND_TRACE(L
"Unfreed memory blocks: %d\n",
196 GetMemoryAllocationCount());
204 SND_TRACE(L
"DRV_ENABLE / DRV_DISABLE\n");
211 SND_TRACE(L
"DRV_OPEN / DRV_CLOSE\n");
215 case DRV_QUERYCONFIGURE
:
217 SND_TRACE(L
"DRV_QUERYCONFIGURE\n");
224 SND_TRACE(L
"Unhandled message %d\n", Message
);
225 return DefDriverProc(DriverId
,
241 case DLL_PROCESS_ATTACH
:
242 SND_TRACE(L
"WDMAUD.DRV - Process attached\n");
244 case DLL_PROCESS_DETACH
:
245 SND_TRACE(L
"WDMAUD.DRV - Process detached\n");
247 case DLL_THREAD_ATTACH
:
248 SND_TRACE(L
"WDMAUD.DRV - Thread attached\n");
250 case DLL_THREAD_DETACH
:
251 SND_TRACE(L
"WDMAUD.DRV - Thread detached\n");