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