c8ff6586a748be7b6725eca85d49febc96b0894e
[reactos.git] / reactos / lib / drivers / sound / mmebuddy / capabilities.c
1 /*
2 * PROJECT: ReactOS Sound System "MME Buddy" Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/drivers/sound/mmebuddy/capabilities.c
5 *
6 * PURPOSE: Queries sound devices for their capabilities.
7 *
8 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
9 */
10
11 #include <windows.h>
12 #include <mmsystem.h>
13 #include <mmddk.h>
14 #include <ntddsnd.h>
15 #include <sndtypes.h>
16 #include <mmebuddy.h>
17
18 /*
19 Obtains the capabilities of a sound device. This routine ensures that the
20 supplied CapabilitiesSize parameter at least meets the minimum size of the
21 relevant capabilities structure.
22
23 Ultimately, it will call the GetCapabilities function specified in the
24 sound device's function table. Note that there are several of these, in a
25 union. This is simply to avoid manually typecasting when implementing the
26 functions.
27 */
28 MMRESULT
29 GetSoundDeviceCapabilities(
30 IN PSOUND_DEVICE SoundDevice,
31 IN DWORD DeviceId,
32 OUT PVOID Capabilities,
33 IN DWORD CapabilitiesSize)
34 {
35 MMDEVICE_TYPE DeviceType;
36 PMMFUNCTION_TABLE FunctionTable;
37 BOOLEAN GoodSize = FALSE;
38 MMRESULT Result;
39
40 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) );
41 VALIDATE_MMSYS_PARAMETER( Capabilities );
42 VALIDATE_MMSYS_PARAMETER( CapabilitiesSize > 0 );
43
44 /* Obtain the device type */
45 Result = GetSoundDeviceType(SoundDevice, &DeviceType);
46 SND_ASSERT( Result == MMSYSERR_NOERROR );
47
48 if ( ! MMSUCCESS(Result) )
49 return TranslateInternalMmResult(Result);
50
51 /* Obtain the function table */
52 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
53 SND_ASSERT( Result == MMSYSERR_NOERROR );
54
55 if ( ! MMSUCCESS(Result) )
56 return TranslateInternalMmResult(Result);
57
58 SND_ASSERT( IS_VALID_SOUND_DEVICE_TYPE(DeviceType) );
59
60 /* Check that the capabilities structure is of a valid size */
61 switch ( DeviceType )
62 {
63 case WAVE_OUT_DEVICE_TYPE :
64 {
65 GoodSize = CapabilitiesSize >= sizeof(WAVEOUTCAPS);
66 break;
67 }
68 case WAVE_IN_DEVICE_TYPE :
69 {
70 GoodSize = CapabilitiesSize >= sizeof(WAVEINCAPS);
71 break;
72 }
73 case MIDI_OUT_DEVICE_TYPE :
74 {
75 GoodSize = CapabilitiesSize >= sizeof(MIDIOUTCAPS);
76 break;
77 }
78 case MIDI_IN_DEVICE_TYPE :
79 {
80 GoodSize = CapabilitiesSize >= sizeof(MIDIINCAPS);
81 break;
82 }
83 case AUX_DEVICE_TYPE :
84 {
85 GoodSize = CapabilitiesSize >= sizeof(AUXCAPS);
86 break;
87 }
88 case MIXER_DEVICE_TYPE :
89 {
90 GoodSize = CapabilitiesSize >= sizeof(MIXERCAPS);
91 break;
92 }
93 };
94
95 if ( ! GoodSize )
96 {
97 SND_ERR(L"Device capabilities structure too small\n");
98 return MMSYSERR_INVALPARAM;
99 }
100
101 /* Call the "get capabilities" function within the function table */
102 SND_ASSERT( FunctionTable->GetCapabilities );
103
104 if ( ! FunctionTable->GetCapabilities )
105 return MMSYSERR_NOTSUPPORTED;
106
107 return FunctionTable->GetCapabilities(SoundDevice,
108 DeviceId,
109 Capabilities,
110 CapabilitiesSize);
111 }