- Revert 49927 "Update to trunk" as it breaks KsStudio (again)
[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 MMRESULT Result;
115 //SND_TRACE(L"DRV_LOAD\n");
116
117 Result = InitEntrypointMutexes();
118
119 if ( ! MMSUCCESS(Result) )
120 return 0L;
121
122 Result = WdmAudOpenSoundDeviceByMMixer();
123
124 if ( Result != MMSYSERR_NOERROR )
125 {
126 SND_ERR(L"Failed to initialize MMixer Library");
127 //UnlistAllSoundDevices();
128
129 return 0L;
130 }
131
132 /* Populate the device lists */
133 //SND_TRACE(L"Populating device lists\n");
134 PopulateWdmDeviceList(WAVE_OUT_DEVICE_TYPE);
135 PopulateWdmDeviceList(WAVE_IN_DEVICE_TYPE);
136 PopulateWdmDeviceList(MIDI_OUT_DEVICE_TYPE);
137 PopulateWdmDeviceList(MIDI_IN_DEVICE_TYPE);
138 PopulateWdmDeviceList(AUX_DEVICE_TYPE);
139 PopulateWdmDeviceList(MIXER_DEVICE_TYPE);
140
141 //SND_TRACE(L"Initialisation complete\n");
142
143 return 1L;
144 }
145
146 case DRV_FREE :
147 {
148 SND_TRACE(L"DRV_FREE\n");
149
150 WdmAudCleanupByMMixer();
151
152 /* TODO: Clean up the path names! */
153 UnlistAllSoundDevices();
154
155 CleanupEntrypointMutexes();
156
157 SND_TRACE(L"Unfreed memory blocks: %d\n",
158 GetMemoryAllocationCount());
159
160 return 1L;
161 }
162
163 case DRV_ENABLE :
164 case DRV_DISABLE :
165 {
166 //SND_TRACE(L"DRV_ENABLE / DRV_DISABLE\n");
167 return 1L;
168 }
169
170 case DRV_OPEN :
171 case DRV_CLOSE :
172 {
173 //SND_TRACE(L"DRV_OPEN / DRV_CLOSE\n");
174 return 1L;
175 }
176
177 case DRV_QUERYCONFIGURE :
178 {
179 SND_TRACE(L"DRV_QUERYCONFIGURE\n");
180 return 0L;
181 }
182 case DRV_CONFIGURE :
183 return DRVCNF_OK;
184
185 default :
186 SND_TRACE(L"Unhandled message %d\n", Message);
187 return DefDriverProc(DriverId,
188 DriverHandle,
189 Message,
190 Parameter1,
191 Parameter2);
192 }
193 }
194
195
196 BOOL WINAPI DllMain(
197 HINSTANCE hinstDLL,
198 DWORD fdwReason,
199 LPVOID lpvReserved)
200 {
201 switch ( fdwReason )
202 {
203 case DLL_PROCESS_ATTACH :
204 SND_TRACE(L"WDMAUD.DRV - Process attached\n");
205 break;
206 case DLL_PROCESS_DETACH :
207 SND_TRACE(L"WDMAUD.DRV - Process detached\n");
208 break;
209 case DLL_THREAD_ATTACH :
210 SND_TRACE(L"WDMAUD.DRV - Thread attached\n");
211 break;
212 case DLL_THREAD_DETACH :
213 SND_TRACE(L"WDMAUD.DRV - Thread detached\n");
214 break;
215 }
216
217 return TRUE;
218 }