reactos/lib/drivers/sound/mmebuddy/capabilities.c
Timo Kreuzer 6afbc8f483 Hopefully create a branch and not destroy the svn repository.
svn path=/branches/reactos-yarotows/; revision=45219
2010-01-23 23:25:04 +00:00

111 lines
3.3 KiB
C

/*
* PROJECT: ReactOS Sound System "MME Buddy" Library
* LICENSE: GPL - See COPYING in the top level directory
* FILE: lib/drivers/sound/mmebuddy/capabilities.c
*
* PURPOSE: Queries sound devices for their capabilities.
*
* PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
*/
#include <windows.h>
#include <mmsystem.h>
#include <mmddk.h>
#include <ntddsnd.h>
#include <sndtypes.h>
#include <mmebuddy.h>
/*
Obtains the capabilities of a sound device. This routine ensures that the
supplied CapabilitiesSize parameter at least meets the minimum size of the
relevant capabilities structure.
Ultimately, it will call the GetCapabilities function specified in the
sound device's function table. Note that there are several of these, in a
union. This is simply to avoid manually typecasting when implementing the
functions.
*/
MMRESULT
GetSoundDeviceCapabilities(
IN PSOUND_DEVICE SoundDevice,
IN DWORD DeviceId,
OUT PVOID Capabilities,
IN DWORD CapabilitiesSize)
{
MMDEVICE_TYPE DeviceType;
PMMFUNCTION_TABLE FunctionTable;
BOOLEAN GoodSize = FALSE;
MMRESULT Result;
VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) );
VALIDATE_MMSYS_PARAMETER( Capabilities );
VALIDATE_MMSYS_PARAMETER( CapabilitiesSize > 0 );
/* Obtain the device type */
Result = GetSoundDeviceType(SoundDevice, &DeviceType);
SND_ASSERT( Result == MMSYSERR_NOERROR );
if ( ! MMSUCCESS(Result) )
return TranslateInternalMmResult(Result);
/* Obtain the function table */
Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
SND_ASSERT( Result == MMSYSERR_NOERROR );
if ( ! MMSUCCESS(Result) )
return TranslateInternalMmResult(Result);
SND_ASSERT( IS_VALID_SOUND_DEVICE_TYPE(DeviceType) );
/* Check that the capabilities structure is of a valid size */
switch ( DeviceType )
{
case WAVE_OUT_DEVICE_TYPE :
{
GoodSize = CapabilitiesSize >= sizeof(WAVEOUTCAPS);
break;
}
case WAVE_IN_DEVICE_TYPE :
{
GoodSize = CapabilitiesSize >= sizeof(WAVEINCAPS);
break;
}
case MIDI_OUT_DEVICE_TYPE :
{
GoodSize = CapabilitiesSize >= sizeof(MIDIOUTCAPS);
break;
}
case MIDI_IN_DEVICE_TYPE :
{
GoodSize = CapabilitiesSize >= sizeof(MIDIINCAPS);
break;
}
case AUX_DEVICE_TYPE :
{
GoodSize = CapabilitiesSize >= sizeof(AUXCAPS);
break;
}
case MIXER_DEVICE_TYPE :
{
GoodSize = CapabilitiesSize >= sizeof(MIXERCAPS);
break;
}
};
if ( ! GoodSize )
{
SND_ERR(L"Device capabilities structure too small\n");
return MMSYSERR_INVALPARAM;
}
/* Call the "get capabilities" function within the function table */
SND_ASSERT( FunctionTable->GetCapabilities );
if ( ! FunctionTable->GetCapabilities )
return MMSYSERR_NOTSUPPORTED;
return FunctionTable->GetCapabilities(SoundDevice,
DeviceId,
Capabilities,
CapabilitiesSize);
}