- Silence debug garbage
[reactos.git] / reactos / lib / drivers / sound / mmebuddy / mixer / mxdMessage.c
1 /*
2 * PROJECT: ReactOS Sound System "MME Buddy" Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/sound/mmebuddy/mixer/mxdMessage.c
5 *
6 * PURPOSE: Provides the mxdMessage exported function, as required by
7 * the MME API, for mixer device support.
8 *
9 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
10 */
11
12 #include <windows.h>
13 #include <mmsystem.h>
14 #include <mmddk.h>
15
16 #include <ntddsnd.h>
17 #include <sndtypes.h>
18 #undef NDEBUG
19 #include <mmebuddy.h>
20
21 MMRESULT
22 MmeGetLineInfo(
23 IN DWORD Message,
24 IN DWORD PrivateHandle,
25 IN DWORD Parameter1,
26 IN DWORD Parameter2)
27 {
28 MMRESULT Result;
29 PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
30 PSOUND_DEVICE SoundDevice;
31 PMMFUNCTION_TABLE FunctionTable;
32
33 SND_TRACE(L"Getting mixer info %u\n", Message);
34
35 VALIDATE_MMSYS_PARAMETER( PrivateHandle );
36 SoundDeviceInstance = (PSOUND_DEVICE_INSTANCE) PrivateHandle;
37
38 Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
39 if ( ! MMSUCCESS(Result) )
40 return TranslateInternalMmResult(Result);
41
42 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
43 if ( ! MMSUCCESS(Result) )
44 return TranslateInternalMmResult(Result);
45
46 if ( ! FunctionTable->QueryMixerInfo )
47 return MMSYSERR_NOTSUPPORTED;
48
49 Result = FunctionTable->QueryMixerInfo(SoundDeviceInstance, Message, (LPVOID)Parameter1, Parameter2);
50
51 return Result;
52 }
53
54
55 MMRESULT
56 MmeCloseMixerDevice(
57 IN DWORD PrivateHandle)
58 {
59 MMRESULT Result;
60 PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
61 PSOUND_DEVICE SoundDevice;
62
63 SND_TRACE(L"Closing mixer device \n");
64
65 VALIDATE_MMSYS_PARAMETER( PrivateHandle );
66 SoundDeviceInstance = (PSOUND_DEVICE_INSTANCE) PrivateHandle;
67
68 if ( ! IsValidSoundDeviceInstance(SoundDeviceInstance) )
69 return MMSYSERR_INVALHANDLE;
70
71 Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
72 if ( ! MMSUCCESS(Result) )
73 return TranslateInternalMmResult(Result);
74
75
76 Result = DestroySoundDeviceInstance(SoundDeviceInstance);
77
78 return Result;
79 }
80
81 MMRESULT
82 MmeOpenMixerDevice(
83 IN MMDEVICE_TYPE DeviceType,
84 IN DWORD DeviceId,
85 IN LPMIXEROPENDESC OpenParameters,
86 IN DWORD Flags,
87 OUT DWORD* PrivateHandle)
88 {
89 MMRESULT Result;
90 PMMFUNCTION_TABLE FunctionTable;
91 PSOUND_DEVICE SoundDevice;
92 PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
93
94 SND_TRACE(L"Opening mixer device");
95
96 VALIDATE_MMSYS_PARAMETER( OpenParameters );
97
98 Result = GetSoundDevice(DeviceType, DeviceId, &SoundDevice);
99 if ( ! MMSUCCESS(Result) )
100 return TranslateInternalMmResult(Result);
101
102 /* Check that winmm gave us a private handle to fill */
103 VALIDATE_MMSYS_PARAMETER( PrivateHandle );
104
105 /* Create a sound device instance and open the sound device */
106 Result = CreateSoundDeviceInstance(SoundDevice, &SoundDeviceInstance);
107 if ( ! MMSUCCESS(Result) )
108 return TranslateInternalMmResult(Result);
109
110 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
111 if ( ! MMSUCCESS(Result) )
112 return TranslateInternalMmResult(Result);
113
114 if ( ! FunctionTable->SetWaveFormat )
115 return MMSYSERR_NOTSUPPORTED;
116
117 Result = FunctionTable->SetWaveFormat(SoundDeviceInstance, DeviceId, NULL, 0);
118 if ( ! MMSUCCESS(Result) )
119 {
120 /* TODO: Destroy sound instance */
121 return TranslateInternalMmResult(Result);
122 }
123
124 /* Store the device instance pointer in the private handle - is DWORD safe here? */
125 *PrivateHandle = (DWORD) SoundDeviceInstance;
126
127 /* Store the additional information we were given - FIXME: Need flags! */
128 SetSoundDeviceInstanceMmeData(SoundDeviceInstance,
129 (HDRVR)OpenParameters->hmx,
130 OpenParameters->dwCallback,
131 OpenParameters->dwInstance,
132 Flags);
133
134 /* Let the application know the device is open */
135 ReleaseEntrypointMutex(DeviceType);
136 #if 0
137 NotifyMmeClient(SoundDeviceInstance,
138 DeviceType == WAVE_OUT_DEVICE_TYPE ? WOM_OPEN : WIM_OPEN,
139 0);
140 #endif
141 AcquireEntrypointMutex(DeviceType);
142
143 SND_TRACE(L"Mixer device now open\n");
144
145 return MMSYSERR_NOERROR;
146 }
147
148 /*
149 Standard MME driver entry-point for messages relating to mixers.
150 */
151 DWORD
152 APIENTRY
153 mxdMessage(
154 DWORD DeviceId,
155 DWORD Message,
156 DWORD PrivateHandle,
157 DWORD Parameter1,
158 DWORD Parameter2)
159 {
160 MMRESULT Result = MMSYSERR_NOTSUPPORTED;
161
162 AcquireEntrypointMutex(MIXER_DEVICE_TYPE);
163
164 //SND_TRACE(L"mxdMessage - Message type %d\n", Message);
165
166 switch ( Message )
167 {
168 case MXDM_GETNUMDEVS :
169 {
170 Result = GetSoundDeviceCount(MIXER_DEVICE_TYPE);
171 break;
172 }
173
174 case MXDM_GETDEVCAPS :
175 {
176 Result = MmeGetSoundDeviceCapabilities(MIXER_DEVICE_TYPE,
177 DeviceId,
178 (PVOID) Parameter1,
179 Parameter2);
180 break;
181 }
182
183 case MXDM_INIT :
184 {
185 Result = MMSYSERR_NOERROR;
186 break;
187 }
188
189 case MXDM_OPEN :
190 {
191 Result = MmeOpenMixerDevice(MIXER_DEVICE_TYPE,
192 DeviceId,
193 (LPMIXEROPENDESC) Parameter1,
194 Parameter2,
195 (DWORD*) PrivateHandle);
196
197 break;
198 }
199
200 case MXDM_CLOSE :
201 {
202 Result = MmeCloseMixerDevice(PrivateHandle);
203
204 break;
205 }
206
207 case MXDM_GETCONTROLDETAILS :
208 {
209 Result = MmeGetLineInfo(Message,
210 PrivateHandle,
211 Parameter1,
212 Parameter2);
213
214 break;
215 }
216
217 case MXDM_SETCONTROLDETAILS :
218 {
219 Result = MmeGetLineInfo(Message,
220 PrivateHandle,
221 Parameter1,
222 Parameter2);
223
224 break;
225 }
226
227 case MXDM_GETLINECONTROLS :
228 {
229 Result = MmeGetLineInfo(Message,
230 PrivateHandle,
231 Parameter1,
232 Parameter2);
233
234 break;
235 }
236
237 case MXDM_GETLINEINFO :
238 {
239 Result = MmeGetLineInfo(Message,
240 PrivateHandle,
241 Parameter1,
242 Parameter2);
243
244 break;
245 }
246
247 case DRV_QUERYDEVICEINTERFACESIZE :
248 {
249 Result = MmeGetDeviceInterfaceString(MIXER_DEVICE_TYPE, DeviceId, NULL, 0, (DWORD*)Parameter1); //FIXME DWORD_PTR
250 break;
251 }
252
253 case DRV_QUERYDEVICEINTERFACE :
254 {
255 Result = MmeGetDeviceInterfaceString(MIXER_DEVICE_TYPE, DeviceId, (LPWSTR)Parameter1, Parameter2, NULL); //FIXME DWORD_PTR
256 break;
257 }
258
259 }
260
261 //SND_TRACE(L"mxdMessage returning MMRESULT %d\n", Result);
262
263 ReleaseEntrypointMutex(MIXER_DEVICE_TYPE);
264
265 return Result;
266 }