Hopefully fail to break anything in the process of syncing with trunk (r47786)
[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
94 SetSoundDeviceFunctionTable(SoundDevice, &FuncTable);
95 }
96
97 return MMSYSERR_NOERROR;
98 }
99
100
101
102 LONG
103 APIENTRY
104 DriverProc(
105 DWORD DriverId,
106 HANDLE DriverHandle,
107 UINT Message,
108 LONG Parameter1,
109 LONG Parameter2)
110 {
111 switch ( Message )
112 {
113 case DRV_LOAD :
114 {
115 HANDLE Handle;
116 MMRESULT Result;
117 SND_TRACE(L"DRV_LOAD\n");
118
119 Result = InitEntrypointMutexes();
120
121 if ( ! MMSUCCESS(Result) )
122 return 0L;
123
124 Result = FUNC_NAME(WdmAudOpenSoundDevice)(NULL, &Handle);
125
126 if ( Result != MMSYSERR_NOERROR )
127 {
128 SND_ERR(L"Failed to open \\\\.\\wdmaud\n");
129 //UnlistAllSoundDevices();
130
131 return 0L;
132 }
133
134 /* Populate the device lists */
135 SND_TRACE(L"Populating device lists\n");
136 PopulateWdmDeviceList(WAVE_OUT_DEVICE_TYPE);
137 PopulateWdmDeviceList(WAVE_IN_DEVICE_TYPE);
138 PopulateWdmDeviceList(MIDI_OUT_DEVICE_TYPE);
139 PopulateWdmDeviceList(MIDI_IN_DEVICE_TYPE);
140 PopulateWdmDeviceList(AUX_DEVICE_TYPE);
141 PopulateWdmDeviceList(MIXER_DEVICE_TYPE);
142
143 SND_TRACE(L"Initialisation complete\n");
144
145 return 1L;
146 }
147
148 case DRV_FREE :
149 {
150 SND_TRACE(L"DRV_FREE\n");
151
152 FUNC_NAME(WdmAudCleanup)();
153
154 /* TODO: Clean up the path names! */
155 UnlistAllSoundDevices();
156
157 CleanupEntrypointMutexes();
158
159 SND_TRACE(L"Unfreed memory blocks: %d\n",
160 GetMemoryAllocationCount());
161
162 return 1L;
163 }
164
165 case DRV_ENABLE :
166 case DRV_DISABLE :
167 {
168 SND_TRACE(L"DRV_ENABLE / DRV_DISABLE\n");
169 return 1L;
170 }
171
172 case DRV_OPEN :
173 case DRV_CLOSE :
174 {
175 SND_TRACE(L"DRV_OPEN / DRV_CLOSE\n");
176 return 1L;
177 }
178
179 case DRV_QUERYCONFIGURE :
180 {
181 SND_TRACE(L"DRV_QUERYCONFIGURE\n");
182 return 0L;
183 }
184 case DRV_CONFIGURE :
185 return DRVCNF_OK;
186
187 default :
188 SND_TRACE(L"Unhandled message %d\n", Message);
189 return DefDriverProc(DriverId,
190 DriverHandle,
191 Message,
192 Parameter1,
193 Parameter2);
194 }
195 }
196
197
198 BOOL WINAPI DllMain(
199 HINSTANCE hinstDLL,
200 DWORD fdwReason,
201 LPVOID lpvReserved)
202 {
203 switch ( fdwReason )
204 {
205 case DLL_PROCESS_ATTACH :
206 SND_TRACE(L"WDMAUD.DRV - Process attached\n");
207 break;
208 case DLL_PROCESS_DETACH :
209 SND_TRACE(L"WDMAUD.DRV - Process detached\n");
210 break;
211 case DLL_THREAD_ATTACH :
212 SND_TRACE(L"WDMAUD.DRV - Thread attached\n");
213 break;
214 case DLL_THREAD_DETACH :
215 SND_TRACE(L"WDMAUD.DRV - Thread detached\n");
216 break;
217 }
218
219 return TRUE;
220 }