1 /*
2  * PROJECT:     ReactOS Sound System "MME Buddy" Library
3  * LICENSE:     GPL - See COPYING in the top level directory
4  * FILE:        lib/sound/mmebuddy/wave/widMessage.c
5  *
6  * PURPOSE:     Provides the widMessage exported function, as required by
7  *              the MME API, for wave input device support.
8  *
9  * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
10 */
11 
12 #include "precomp.h"
13 
14 /*
15     Standard MME driver entry-point for messages relating to wave audio
16     input.
17 */
18 DWORD
19 APIENTRY
20 widMessage(
21     UINT DeviceId,
22     UINT Message,
23     DWORD_PTR PrivateHandle,
24     DWORD_PTR Parameter1,
25     DWORD_PTR Parameter2)
26 {
27     MMRESULT Result = MMSYSERR_NOTSUPPORTED;
28 
29     AcquireEntrypointMutex(WAVE_IN_DEVICE_TYPE);
30 
31     SND_TRACE(L"widMessage - Message type %d\n", Message);
32 
33     switch ( Message )
34     {
35         case WIDM_GETNUMDEVS :
36         {
37             Result = GetSoundDeviceCount(WAVE_IN_DEVICE_TYPE);
38             break;
39         }
40 
41         case WIDM_START :
42         {
43             Result = MmeSetState(PrivateHandle, TRUE);
44             break;
45         }
46 
47         case WIDM_STOP :
48         {
49             Result = MmeSetState(PrivateHandle, FALSE);
50             break;
51         }
52 
53         case WIDM_GETDEVCAPS :
54         {
55 
56             Result = MmeGetSoundDeviceCapabilities(WAVE_IN_DEVICE_TYPE,
57                                                    DeviceId,
58                                                    (PVOID) Parameter1,
59                                                    Parameter2);
60             break;
61         }
62         case WIDM_OPEN :
63         {
64 
65             /* Do sanity checks for 'recording' SamplesPerSec value */
66             LPWAVEOPENDESC OpenParameters = (LPWAVEOPENDESC)Parameter1;
67             if (OpenParameters->lpFormat->nSamplesPerSec > 100000)
68                 OpenParameters->lpFormat->nSamplesPerSec = 100000;
69             if (OpenParameters->lpFormat->nSamplesPerSec < 5000)
70                 OpenParameters->lpFormat->nSamplesPerSec = 5000;
71 
72             Result = MmeOpenDevice(WAVE_IN_DEVICE_TYPE,
73                                        DeviceId,
74                                        (LPWAVEOPENDESC) Parameter1,
75                                        Parameter2,
76                                        (DWORD_PTR*) PrivateHandle);
77             break;
78         }
79 
80         case WIDM_CLOSE :
81         {
82             Result = MmeCloseDevice(PrivateHandle);
83 
84             break;
85         }
86 
87         case WIDM_PREPARE :
88         {
89             /* TODO: Do we need to pass 2nd parameter? */
90             Result = MmePrepareWaveHeader(PrivateHandle, Parameter1);
91             break;
92         }
93 
94         case WIDM_UNPREPARE :
95         {
96             Result = MmeUnprepareWaveHeader(PrivateHandle, Parameter1);
97             break;
98         }
99 
100         case WIDM_RESET :
101         {
102             /* Stop playback, reset position to zero */
103             Result = MmeResetWavePlayback(PrivateHandle);
104             break;
105         }
106 
107         case WIDM_ADDBUFFER :
108         {
109             Result = MmeWriteWaveHeader(PrivateHandle, Parameter1);
110             break;
111         }
112 
113         case DRV_QUERYDEVICEINTERFACESIZE :
114         {
115             Result = MmeGetDeviceInterfaceString(WAVE_IN_DEVICE_TYPE, DeviceId, NULL, 0, (DWORD*)Parameter1); //FIXME DWORD_PTR
116             break;
117         }
118 
119         case DRV_QUERYDEVICEINTERFACE :
120         {
121             Result = MmeGetDeviceInterfaceString(WAVE_IN_DEVICE_TYPE, DeviceId, (LPWSTR)Parameter1, Parameter2, NULL); //FIXME DWORD_PTR
122             break;
123         }
124 
125 
126     }
127 
128     SND_TRACE(L"widMessage returning MMRESULT %d\n", Result);
129 
130     ReleaseEntrypointMutex(WAVE_IN_DEVICE_TYPE);
131 
132     return Result;
133 }
134