Chinese translations of NTVDM by Samuel Lee. Bug #5087.
[reactos.git] / reactos / dll / win32 / wdmaud.drv / wdmaud.c
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 HANDLE KernelHandle = INVALID_HANDLE_VALUE;
18
19 MMRESULT
20 QueryWdmWaveDeviceFormatSupport(
21 IN PSOUND_DEVICE Device,
22 IN PWAVEFORMATEX WaveFormat,
23 IN DWORD WaveFormatSize)
24 {
25 /* Whatever... */
26 return MMSYSERR_NOERROR;
27 }
28
29
30 MMRESULT
31 PopulateWdmDeviceList(
32 MMDEVICE_TYPE DeviceType)
33 {
34 MMRESULT Result;
35 DWORD DeviceCount = 0;
36 PSOUND_DEVICE SoundDevice = NULL;
37 MMFUNCTION_TABLE FuncTable;
38 DWORD i;
39
40 VALIDATE_MMSYS_PARAMETER( IS_VALID_SOUND_DEVICE_TYPE(DeviceType) );
41
42 #ifdef USE_MMIXER_LIB
43 Result = WdmAudGetNumDevsByMMixer(DeviceType, &DeviceCount);
44 #else
45 Result = WdmAudGetNumWdmDevsByLegacy(DeviceType, &DeviceCount);
46 #endif
47
48 if ( ! MMSUCCESS(Result) )
49 {
50 SND_ERR(L"Error %d while obtaining number of devices\n", Result);
51 return TranslateInternalMmResult(Result);
52 }
53
54 SND_TRACE(L"%d devices of type %d found\n", DeviceCount, DeviceType);
55
56
57 for ( i = 0; i < DeviceCount; ++ i )
58 {
59 Result = ListSoundDevice(DeviceType, UlongToPtr(i), &SoundDevice);
60
61 if ( ! MMSUCCESS(Result) )
62 {
63 SND_ERR(L"Failed to list sound device - error %d\n", Result);
64 return TranslateInternalMmResult(Result);
65 }
66
67 /* Set up our function table */
68 ZeroMemory(&FuncTable, sizeof(MMFUNCTION_TABLE));
69 #ifdef USE_MMIXER_LIB
70 FuncTable.GetCapabilities = WdmAudGetCapabilitiesByMMixer;
71 FuncTable.Open = WdmAudOpenSoundDeviceByMMixer;
72 FuncTable.Close = WdmAudCloseSoundDeviceByMMixer;
73 FuncTable.GetDeviceInterfaceString = WdmAudGetDeviceInterfaceStringByMMixer;
74 #else
75 FuncTable.GetCapabilities = WdmAudGetCapabilitiesByLegacy;
76 FuncTable.Open = WdmAudOpenSoundDeviceByLegacy;
77 FuncTable.Close = WdmAudCloseSoundDeviceByLegacy;
78 FuncTable.GetDeviceInterfaceString = WdmAudGetDeviceInterfaceStringByLegacy;
79 #endif
80
81 FuncTable.QueryWaveFormatSupport = QueryWdmWaveDeviceFormatSupport;
82 if (DeviceType == MIXER_DEVICE_TYPE)
83 {
84 #ifdef USE_MMIXER_LIB
85 FuncTable.SetWaveFormat = WdmAudSetMixerDeviceFormatByMMixer;
86 FuncTable.QueryMixerInfo = WdmAudQueryMixerInfoByMMixer;
87 #else
88 FuncTable.SetWaveFormat = WdmAudSetMixerDeviceFormatByLegacy;
89 FuncTable.QueryMixerInfo = WdmAudQueryMixerInfoByLegacy;
90 #endif
91 }
92
93 if (DeviceType == WAVE_IN_DEVICE_TYPE || DeviceType == WAVE_OUT_DEVICE_TYPE)
94 {
95 #ifdef USE_MMIXER_LIB
96 FuncTable.SetWaveFormat = WdmAudSetWdmWaveDeviceFormatByMMixer;
97 FuncTable.SetState = WdmAudSetWdmWaveStateByMMixer;
98 FuncTable.ResetStream = WdmAudResetStreamByMMixer;
99 FuncTable.GetPos = WdmAudGetWdmPositionByMMixer;
100 #else
101 FuncTable.SetWaveFormat = WdmAudSetWaveDeviceFormatByLegacy;
102 FuncTable.SetState = WdmAudSetWaveStateByLegacy;
103 FuncTable.ResetStream = WdmAudResetStreamByLegacy;
104 FuncTable.GetPos = WdmAudGetWavePositionByLegacy;
105 #endif
106
107 #ifdef USE_MMIXER_LIB
108 FuncTable.CommitWaveBuffer = WdmAudCommitWaveBufferByMMixer;
109 #elif defined (USERMODE_MIXER)
110 FuncTable.CommitWaveBuffer = WriteFileEx_Remixer;
111 #else
112 FuncTable.CommitWaveBuffer = WriteFileEx_Committer2;
113 #endif
114 }
115
116 SetSoundDeviceFunctionTable(SoundDevice, &FuncTable);
117 }
118
119 return MMSYSERR_NOERROR;
120 }
121
122 LONG
123 APIENTRY
124 DriverProc(
125 DWORD DriverId,
126 HANDLE DriverHandle,
127 UINT Message,
128 LONG Parameter1,
129 LONG Parameter2)
130 {
131 MMRESULT Result;
132
133 switch ( Message )
134 {
135 case DRV_LOAD :
136 {
137 SND_TRACE(L"DRV_LOAD\n");
138
139 Result = InitEntrypointMutexes();
140
141 if ( ! MMSUCCESS(Result) )
142 return 0L;
143
144 #ifdef USE_MMIXER_LIB
145 if (!WdmAudInitUserModeMixer())
146 {
147 SND_ERR(L"Failed to initialize mmixer lib\n");
148 return 0;
149 }
150 #else
151 if (WdmAudOpenSoundDeviceByLegacy() != MMSYSERR_NOERROR)
152 {
153 SND_ERR(L"Failed to open \\\\.\\wdmaud\n");
154 CleanupEntrypointMutexes();
155
156 //UnlistAllSoundDevices();
157
158 return 0L;
159 }
160 #endif
161
162 /* Populate the device lists */
163 SND_TRACE(L"Populating device lists\n");
164 PopulateWdmDeviceList(WAVE_OUT_DEVICE_TYPE);
165 PopulateWdmDeviceList(WAVE_IN_DEVICE_TYPE);
166 PopulateWdmDeviceList(MIDI_OUT_DEVICE_TYPE);
167 PopulateWdmDeviceList(MIDI_IN_DEVICE_TYPE);
168 PopulateWdmDeviceList(AUX_DEVICE_TYPE);
169 PopulateWdmDeviceList(MIXER_DEVICE_TYPE);
170
171 SND_TRACE(L"Initialisation complete\n");
172
173 return 1L;
174 }
175
176 case DRV_FREE :
177 {
178 SND_TRACE(L"DRV_FREE\n");
179
180 #ifdef USE_MMIXER_LIB
181 WdmAudCleanupMMixer();
182 #else
183 WdmAudCleanupLegacy();
184 #endif
185
186 /* TODO: Clean up the path names! */
187 UnlistAllSoundDevices();
188
189 CleanupEntrypointMutexes();
190
191 SND_TRACE(L"Unfreed memory blocks: %d\n",
192 GetMemoryAllocationCount());
193
194 return 1L;
195 }
196
197 case DRV_ENABLE :
198 case DRV_DISABLE :
199 {
200 SND_TRACE(L"DRV_ENABLE / DRV_DISABLE\n");
201 return 1L;
202 }
203
204 case DRV_OPEN :
205 case DRV_CLOSE :
206 {
207 SND_TRACE(L"DRV_OPEN / DRV_CLOSE\n");
208 return 1L;
209 }
210
211 case DRV_QUERYCONFIGURE :
212 {
213 SND_TRACE(L"DRV_QUERYCONFIGURE\n");
214 return 0L;
215 }
216 case DRV_CONFIGURE :
217 return DRVCNF_OK;
218
219 default :
220 SND_TRACE(L"Unhandled message %d\n", Message);
221 return DefDriverProc(DriverId,
222 DriverHandle,
223 Message,
224 Parameter1,
225 Parameter2);
226 }
227 }
228
229
230 BOOL WINAPI DllMain(
231 HINSTANCE hinstDLL,
232 DWORD fdwReason,
233 LPVOID lpvReserved)
234 {
235 switch ( fdwReason )
236 {
237 case DLL_PROCESS_ATTACH :
238 SND_TRACE(L"WDMAUD.DRV - Process attached\n");
239 break;
240 case DLL_PROCESS_DETACH :
241 SND_TRACE(L"WDMAUD.DRV - Process detached\n");
242 break;
243 case DLL_THREAD_ATTACH :
244 SND_TRACE(L"WDMAUD.DRV - Thread attached\n");
245 break;
246 case DLL_THREAD_DETACH :
247 SND_TRACE(L"WDMAUD.DRV - Thread detached\n");
248 break;
249 }
250
251 return TRUE;
252 }