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