[CMAKE]
[reactos.git] / 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
18 #ifndef USE_MMIXER_LIB
19 #define FUNC_NAME(x) x##ByLegacy
20 #else
21 #define FUNC_NAME(x) x##ByMMixer
22 #endif
23
24 MMRESULT
25 QueryWdmWaveDeviceFormatSupport(
26 IN PSOUND_DEVICE Device,
27 IN PWAVEFORMATEX WaveFormat,
28 IN DWORD WaveFormatSize)
29 {
30 /* Whatever... */
31 return MMSYSERR_NOERROR;
32 }
33
34 MMRESULT
35 PopulateWdmDeviceList(
36 MMDEVICE_TYPE DeviceType)
37 {
38 MMRESULT Result;
39 DWORD DeviceCount = 0;
40 PSOUND_DEVICE SoundDevice = NULL;
41 MMFUNCTION_TABLE FuncTable;
42 DWORD i;
43
44 VALIDATE_MMSYS_PARAMETER( IS_VALID_SOUND_DEVICE_TYPE(DeviceType) );
45
46 Result = FUNC_NAME(WdmAudGetNumWdmDevs)(DeviceType, &DeviceCount);
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 FuncTable.GetCapabilities = FUNC_NAME(WdmAudGetCapabilities);
70 FuncTable.QueryWaveFormatSupport = QueryWdmWaveDeviceFormatSupport; //FIXME
71 FuncTable.Open = FUNC_NAME(WdmAudOpenSoundDevice);
72 FuncTable.Close = FUNC_NAME(WdmAudCloseSoundDevice);
73 FuncTable.GetDeviceInterfaceString = FUNC_NAME(WdmAudGetDeviceInterfaceString);
74
75 if (DeviceType == MIXER_DEVICE_TYPE)
76 {
77 FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetMixerDeviceFormat);
78 FuncTable.QueryMixerInfo = FUNC_NAME(WdmAudQueryMixerInfo);
79 }
80 else if (DeviceType == WAVE_IN_DEVICE_TYPE || DeviceType == WAVE_OUT_DEVICE_TYPE)
81 {
82 FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetWaveDeviceFormat);
83 FuncTable.SetState = FUNC_NAME(WdmAudSetWaveState);
84 FuncTable.ResetStream = FUNC_NAME(WdmAudResetStream);
85 FuncTable.GetPos = FUNC_NAME(WdmAudGetWavePosition);
86
87 #ifndef USERMODE_MIXER
88 FuncTable.CommitWaveBuffer = FUNC_NAME(WdmAudCommitWaveBuffer);
89 #else
90 FuncTable.CommitWaveBuffer = WriteFileEx_Remixer;
91 #endif
92 }
93 else if (DeviceType == MIDI_IN_DEVICE_TYPE || DeviceType == MIDI_OUT_DEVICE_TYPE)
94 {
95 FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetMixerDeviceFormat);
96 FuncTable.SetState = FUNC_NAME(WdmAudSetWaveState);
97 FuncTable.GetPos = FUNC_NAME(WdmAudGetWavePosition);
98 }
99
100 SetSoundDeviceFunctionTable(SoundDevice, &FuncTable);
101 }
102
103 return MMSYSERR_NOERROR;
104 }
105
106
107
108 LONG
109 APIENTRY
110 DriverProc(
111 DWORD DriverId,
112 HANDLE DriverHandle,
113 UINT Message,
114 LONG Parameter1,
115 LONG Parameter2)
116 {
117 switch ( Message )
118 {
119 case DRV_LOAD :
120 {
121 HANDLE Handle;
122 MMRESULT Result;
123 SND_TRACE(L"DRV_LOAD\n");
124
125 Result = InitEntrypointMutexes();
126
127 if ( ! MMSUCCESS(Result) )
128 return 0L;
129
130 Result = FUNC_NAME(WdmAudOpenSoundDevice)(NULL, &Handle);
131
132 if ( Result != MMSYSERR_NOERROR )
133 {
134 SND_ERR(L"Failed to open \\\\.\\wdmaud\n");
135 //UnlistAllSoundDevices();
136
137 return 0L;
138 }
139
140 /* Populate the device lists */
141 SND_TRACE(L"Populating device lists\n");
142 PopulateWdmDeviceList(WAVE_OUT_DEVICE_TYPE);
143 PopulateWdmDeviceList(WAVE_IN_DEVICE_TYPE);
144 PopulateWdmDeviceList(MIDI_OUT_DEVICE_TYPE);
145 PopulateWdmDeviceList(MIDI_IN_DEVICE_TYPE);
146 PopulateWdmDeviceList(AUX_DEVICE_TYPE);
147 PopulateWdmDeviceList(MIXER_DEVICE_TYPE);
148
149 SND_TRACE(L"Initialisation complete\n");
150
151 return 1L;
152 }
153
154 case DRV_FREE :
155 {
156 SND_TRACE(L"DRV_FREE\n");
157
158 FUNC_NAME(WdmAudCleanup)();
159
160 /* TODO: Clean up the path names! */
161 UnlistAllSoundDevices();
162
163 CleanupEntrypointMutexes();
164
165 SND_TRACE(L"Unfreed memory blocks: %d\n",
166 GetMemoryAllocationCount());
167
168 return 1L;
169 }
170
171 case DRV_ENABLE :
172 case DRV_DISABLE :
173 {
174 SND_TRACE(L"DRV_ENABLE / DRV_DISABLE\n");
175 return 1L;
176 }
177
178 case DRV_OPEN :
179 case DRV_CLOSE :
180 {
181 SND_TRACE(L"DRV_OPEN / DRV_CLOSE\n");
182 return 1L;
183 }
184
185 case DRV_QUERYCONFIGURE :
186 {
187 SND_TRACE(L"DRV_QUERYCONFIGURE\n");
188 return 0L;
189 }
190 case DRV_CONFIGURE :
191 return DRVCNF_OK;
192
193 default :
194 SND_TRACE(L"Unhandled message %d\n", Message);
195 return DefDriverProc(DriverId,
196 DriverHandle,
197 Message,
198 Parameter1,
199 Parameter2);
200 }
201 }
202
203
204 BOOL WINAPI DllMain(
205 HINSTANCE hinstDLL,
206 DWORD fdwReason,
207 LPVOID lpvReserved)
208 {
209 switch ( fdwReason )
210 {
211 case DLL_PROCESS_ATTACH :
212 SND_TRACE(L"WDMAUD.DRV - Process attached\n");
213 break;
214 case DLL_PROCESS_DETACH :
215 SND_TRACE(L"WDMAUD.DRV - Process detached\n");
216 break;
217 case DLL_THREAD_ATTACH :
218 SND_TRACE(L"WDMAUD.DRV - Thread attached\n");
219 break;
220 case DLL_THREAD_DETACH :
221 SND_TRACE(L"WDMAUD.DRV - Thread detached\n");
222 break;
223 }
224
225 return TRUE;
226 }