2
* PortAudio Portable Real-Time Audio Library
3
* Windows WDM KS utilities
5
* Copyright (c) 1999 - 2007 Andrew Baldwin, Ross Bencina
7
* Permission is hereby granted, free of charge, to any person obtaining
8
* a copy of this software and associated documentation files
9
* (the "Software"), to deal in the Software without restriction,
10
* including without limitation the rights to use, copy, modify, merge,
11
* publish, distribute, sublicense, and/or sell copies of the Software,
12
* and to permit persons to whom the Software is furnished to do so,
13
* subject to the following conditions:
15
* The above copyright notice and this permission notice shall be
16
* included in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
22
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
* The text above constitutes the entire PortAudio license; however,
29
* the PortAudio community also makes the following non-binding requests:
31
* Any person wishing to distribute modifications to the Software is
32
* requested to send the modifications to the original developer so that
33
* they can be incorporated into the canonical version. It is also
34
* requested that these non-binding requests be included along with the
42
#include <stdio.h> // just for some development printfs
44
#include "portaudio.h"
46
#include "pa_win_wdmks_utils.h"
49
static PaError WdmGetPinPropertySimple(
52
unsigned long property,
54
unsigned long valueSize )
58
ksPProp.Property.Set = KSPROPSETID_Pin;
59
ksPProp.Property.Id = property;
60
ksPProp.Property.Flags = KSPROPERTY_TYPE_GET;
61
ksPProp.PinId = pinId;
64
if( DeviceIoControl( handle, IOCTL_KS_PROPERTY, &ksPProp, sizeof(KSP_PIN),
65
value, valueSize, &bytesReturned, NULL ) == 0 || bytesReturned != valueSize )
67
return paUnanticipatedHostError;
76
static PaError WdmGetPinPropertyMulti(
79
unsigned long property,
80
KSMULTIPLE_ITEM** ksMultipleItem)
82
unsigned long multipleItemSize = 0;
88
ksPProp.Property.Set = KSPROPSETID_Pin;
89
ksPProp.Property.Id = property;
90
ksPProp.Property.Flags = KSPROPERTY_TYPE_GET;
91
ksPProp.PinId = pinId;
94
if( DeviceIoControl( handle, IOCTL_KS_PROPERTY, &ksPProp.Property,
95
sizeof(KSP_PIN), NULL, 0, &multipleItemSize, NULL ) == 0 && GetLastError() != ERROR_MORE_DATA )
97
return paUnanticipatedHostError;
100
*ksMultipleItem = (KSMULTIPLE_ITEM*)PaUtil_AllocateMemory( multipleItemSize );
101
if( !*ksMultipleItem )
103
return paInsufficientMemory;
106
if( DeviceIoControl( handle, IOCTL_KS_PROPERTY, &ksPProp, sizeof(KSP_PIN),
107
(void*)*ksMultipleItem, multipleItemSize, &bytesReturned, NULL ) == 0 || bytesReturned != multipleItemSize )
109
PaUtil_FreeMemory( ksMultipleItem );
110
return paUnanticipatedHostError;
117
static int GetKSFilterPinCount( HANDLE deviceHandle )
121
if( WdmGetPinPropertySimple( deviceHandle, 0, KSPROPERTY_PIN_CTYPES, &result, sizeof(result) ) == paNoError ){
129
static KSPIN_COMMUNICATION GetKSFilterPinPropertyCommunication( HANDLE deviceHandle, int pinId )
131
KSPIN_COMMUNICATION result;
133
if( WdmGetPinPropertySimple( deviceHandle, pinId, KSPROPERTY_PIN_COMMUNICATION, &result, sizeof(result) ) == paNoError ){
136
return KSPIN_COMMUNICATION_NONE;
141
static KSPIN_DATAFLOW GetKSFilterPinPropertyDataflow( HANDLE deviceHandle, int pinId )
143
KSPIN_DATAFLOW result;
145
if( WdmGetPinPropertySimple( deviceHandle, pinId, KSPROPERTY_PIN_DATAFLOW, &result, sizeof(result) ) == paNoError ){
148
return (KSPIN_DATAFLOW)0;
153
static int KSFilterPinPropertyIdentifiersInclude(
154
HANDLE deviceHandle, int pinId, unsigned long property, const GUID *identifierSet, unsigned long identifierId )
156
KSMULTIPLE_ITEM* item = NULL;
157
KSIDENTIFIER* identifier;
161
if( WdmGetPinPropertyMulti( deviceHandle, pinId, property, &item) != paNoError )
164
identifier = (KSIDENTIFIER*)(item+1);
166
for( i = 0; i < (int)item->Count; i++ )
168
if( !memcmp( (void*)&identifier[i].Set, (void*)identifierSet, sizeof( GUID ) ) &&
169
( identifier[i].Id == identifierId ) )
176
PaUtil_FreeMemory( item );
182
/* return the maximum channel count supported by any pin on the device.
183
if isInput is non-zero we query input pins, otherwise output pins.
185
int PaWin_WDMKS_QueryFilterMaximumChannelCount( void *wcharDevicePath, int isInput )
188
int pinCount, pinId, i;
190
KSPIN_DATAFLOW requiredDataflowDirection = (isInput ? KSPIN_DATAFLOW_OUT : KSPIN_DATAFLOW_IN );
192
if( !wcharDevicePath )
195
deviceHandle = CreateFileW( (LPCWSTR)wcharDevicePath, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
196
if( deviceHandle == INVALID_HANDLE_VALUE )
199
pinCount = GetKSFilterPinCount( deviceHandle );
200
for( pinId = 0; pinId < pinCount; ++pinId )
202
KSPIN_COMMUNICATION communication = GetKSFilterPinPropertyCommunication( deviceHandle, pinId );
203
KSPIN_DATAFLOW dataflow = GetKSFilterPinPropertyDataflow( deviceHandle, pinId );
204
if( ( dataflow == requiredDataflowDirection ) &&
205
(( communication == KSPIN_COMMUNICATION_SINK) ||
206
( communication == KSPIN_COMMUNICATION_BOTH))
207
&& ( KSFilterPinPropertyIdentifiersInclude( deviceHandle, pinId,
208
KSPROPERTY_PIN_INTERFACES, &KSINTERFACESETID_Standard, KSINTERFACE_STANDARD_STREAMING )
209
|| KSFilterPinPropertyIdentifiersInclude( deviceHandle, pinId,
210
KSPROPERTY_PIN_INTERFACES, &KSINTERFACESETID_Standard, KSINTERFACE_STANDARD_LOOPED_STREAMING ) )
211
&& KSFilterPinPropertyIdentifiersInclude( deviceHandle, pinId,
212
KSPROPERTY_PIN_MEDIUMS, &KSMEDIUMSETID_Standard, KSMEDIUM_STANDARD_DEVIO ) )
214
KSMULTIPLE_ITEM* item = NULL;
215
if( WdmGetPinPropertyMulti( deviceHandle, pinId, KSPROPERTY_PIN_DATARANGES, &item ) == paNoError )
217
KSDATARANGE *dataRange = (KSDATARANGE*)(item+1);
219
for( i=0; i < item->Count; ++i ){
221
if( IS_VALID_WAVEFORMATEX_GUID(&dataRange->SubFormat)
222
|| memcmp( (void*)&dataRange->SubFormat, (void*)&KSDATAFORMAT_SUBTYPE_PCM, sizeof(GUID) ) == 0
223
|| memcmp( (void*)&dataRange->SubFormat, (void*)&KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, sizeof(GUID) ) == 0
224
|| ( ( memcmp( (void*)&dataRange->MajorFormat, (void*)&KSDATAFORMAT_TYPE_AUDIO, sizeof(GUID) ) == 0 )
225
&& ( memcmp( (void*)&dataRange->SubFormat, (void*)&KSDATAFORMAT_SUBTYPE_WILDCARD, sizeof(GUID) ) == 0 ) ) )
227
KSDATARANGE_AUDIO *dataRangeAudio = (KSDATARANGE_AUDIO*)dataRange;
230
printf( ">>> %d %d %d %d %S\n", isInput, dataflow, communication, dataRangeAudio->MaximumChannels, devicePath );
232
if( memcmp((void*)&dataRange->Specifier, (void*)&KSDATAFORMAT_SPECIFIER_WAVEFORMATEX, sizeof(GUID) ) == 0 )
233
printf( "\tspecifier: KSDATAFORMAT_SPECIFIER_WAVEFORMATEX\n" );
234
else if( memcmp((void*)&dataRange->Specifier, (void*)&KSDATAFORMAT_SPECIFIER_DSOUND, sizeof(GUID) ) == 0 )
235
printf( "\tspecifier: KSDATAFORMAT_SPECIFIER_DSOUND\n" );
236
else if( memcmp((void*)&dataRange->Specifier, (void*)&KSDATAFORMAT_SPECIFIER_WILDCARD, sizeof(GUID) ) == 0 )
237
printf( "\tspecifier: KSDATAFORMAT_SPECIFIER_WILDCARD\n" );
239
printf( "\tspecifier: ?\n" );
243
We assume that very high values for MaximumChannels are not useful and indicate
244
that the driver isn't prepared to tell us the real number of channels which it supports.
246
if( dataRangeAudio->MaximumChannels < 0xFFFFUL && (int)dataRangeAudio->MaximumChannels > result )
247
result = (int)dataRangeAudio->MaximumChannels;
250
dataRange = (KSDATARANGE*)( ((char*)dataRange) + dataRange->FormatSize);
253
PaUtil_FreeMemory( item );
258
CloseHandle( deviceHandle );