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