Merge freeldr from amd64 branch:
[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 OUT PVOID Capabilities,
32 IN DWORD CapabilitiesSize)
33 {
34 MMDEVICE_TYPE DeviceType;
35 PMMFUNCTION_TABLE FunctionTable;
36 BOOLEAN GoodSize = FALSE;
37 MMRESULT Result;
38
39 VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) );
40 VALIDATE_MMSYS_PARAMETER( Capabilities );
41 VALIDATE_MMSYS_PARAMETER( CapabilitiesSize > 0 );
42
43 /* Obtain the device type */
44 Result = GetSoundDeviceType(SoundDevice, &DeviceType);
45 SND_ASSERT( Result == MMSYSERR_NOERROR );
46
47 if ( ! MMSUCCESS(Result) )
48 return TranslateInternalMmResult(Result);
49
50 /* Obtain the function table */
51 Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
52 SND_ASSERT( Result == MMSYSERR_NOERROR );
53
54 if ( ! MMSUCCESS(Result) )
55 return TranslateInternalMmResult(Result);
56
57 /* Check that the capabilities structure is of a valid size */
58 switch ( DeviceType )
59 {
60 case WAVE_OUT_DEVICE_TYPE :
61 {
62 GoodSize = CapabilitiesSize >= sizeof(WAVEOUTCAPS);
63 break;
64 }
65 case WAVE_IN_DEVICE_TYPE :
66 {
67 GoodSize = CapabilitiesSize >= sizeof(WAVEINCAPS);
68 break;
69 }
70 case MIDI_OUT_DEVICE_TYPE :
71 {
72 GoodSize = CapabilitiesSize >= sizeof(MIDIOUTCAPS);
73 break;
74 }
75 case MIDI_IN_DEVICE_TYPE :
76 {
77 GoodSize = CapabilitiesSize >= sizeof(MIDIINCAPS);
78 break;
79 }
80 /* TODO: Others... */
81 default :
82 {
83 SND_ASSERT(FALSE);
84 }
85 };
86
87 if ( ! GoodSize )
88 {
89 SND_ERR(L"Device capabilities structure too small\n");
90 return MMSYSERR_INVALPARAM;
91 }
92
93 /* Call the "get capabilities" function within the function table */
94 SND_ASSERT( FunctionTable->GetCapabilities );
95
96 if ( ! FunctionTable->GetCapabilities )
97 return MMSYSERR_NOTSUPPORTED;
98
99 return FunctionTable->GetCapabilities(SoundDevice,
100 Capabilities,
101 CapabilitiesSize);
102 }