~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/third_party/portaudio/src/os/win/pa_win_wdmks_utils.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * PortAudio Portable Real-Time Audio Library
3
 
 * Windows WDM KS utilities
4
 
 *
5
 
 * Copyright (c) 1999 - 2007 Andrew Baldwin, Ross Bencina
6
 
 *
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:
14
 
 *
15
 
 * The above copyright notice and this permission notice shall be
16
 
 * included in all copies or substantial portions of the Software.
17
 
 *
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.
25
 
 */
26
 
 
27
 
/*
28
 
 * The text above constitutes the entire PortAudio license; however,
29
 
 * the PortAudio community also makes the following non-binding requests:
30
 
 *
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
35
 
 * license above.
36
 
 */
37
 
 
38
 
#include <windows.h>
39
 
#include <mmreg.h>
40
 
#include <ks.h>
41
 
#include <ksmedia.h>
42
 
#include <stdio.h>              // just for some development printfs
43
 
 
44
 
#include "portaudio.h"
45
 
#include "pa_util.h"
46
 
#include "pa_win_wdmks_utils.h"
47
 
 
48
 
 
49
 
static PaError WdmGetPinPropertySimple(
50
 
    HANDLE  handle,
51
 
    unsigned long pinId,
52
 
    unsigned long property,
53
 
    void* value,
54
 
    unsigned long valueSize )
55
 
{
56
 
    DWORD bytesReturned;
57
 
    KSP_PIN ksPProp;
58
 
    ksPProp.Property.Set = KSPROPSETID_Pin;
59
 
    ksPProp.Property.Id = property;
60
 
    ksPProp.Property.Flags = KSPROPERTY_TYPE_GET;
61
 
    ksPProp.PinId = pinId;
62
 
    ksPProp.Reserved = 0;
63
 
 
64
 
    if( DeviceIoControl( handle, IOCTL_KS_PROPERTY, &ksPProp, sizeof(KSP_PIN),
65
 
            value, valueSize, &bytesReturned, NULL ) == 0 || bytesReturned != valueSize )
66
 
    {
67
 
        return paUnanticipatedHostError;
68
 
    }
69
 
    else
70
 
    {
71
 
        return paNoError;
72
 
    }
73
 
}
74
 
 
75
 
 
76
 
static PaError WdmGetPinPropertyMulti(
77
 
    HANDLE handle,
78
 
    unsigned long pinId,
79
 
    unsigned long property,
80
 
    KSMULTIPLE_ITEM** ksMultipleItem)
81
 
{
82
 
    unsigned long multipleItemSize = 0;
83
 
    KSP_PIN ksPProp;
84
 
    DWORD bytesReturned;
85
 
 
86
 
    *ksMultipleItem = 0;
87
 
 
88
 
    ksPProp.Property.Set = KSPROPSETID_Pin;
89
 
    ksPProp.Property.Id = property;
90
 
    ksPProp.Property.Flags = KSPROPERTY_TYPE_GET;
91
 
    ksPProp.PinId = pinId;
92
 
    ksPProp.Reserved = 0;
93
 
 
94
 
    if( DeviceIoControl( handle, IOCTL_KS_PROPERTY, &ksPProp.Property,
95
 
            sizeof(KSP_PIN), NULL, 0, &multipleItemSize, NULL ) == 0 && GetLastError() != ERROR_MORE_DATA )
96
 
    {
97
 
        return paUnanticipatedHostError;
98
 
    }
99
 
 
100
 
    *ksMultipleItem = (KSMULTIPLE_ITEM*)PaUtil_AllocateMemory( multipleItemSize );
101
 
    if( !*ksMultipleItem )
102
 
    {
103
 
        return paInsufficientMemory;
104
 
    }
105
 
 
106
 
    if( DeviceIoControl( handle, IOCTL_KS_PROPERTY, &ksPProp, sizeof(KSP_PIN),
107
 
            (void*)*ksMultipleItem,  multipleItemSize, &bytesReturned, NULL ) == 0 || bytesReturned != multipleItemSize )
108
 
    {
109
 
        PaUtil_FreeMemory( ksMultipleItem );
110
 
        return paUnanticipatedHostError;
111
 
    }
112
 
 
113
 
    return paNoError;
114
 
}
115
 
 
116
 
 
117
 
static int GetKSFilterPinCount( HANDLE deviceHandle )
118
 
{
119
 
    DWORD result;
120
 
 
121
 
    if( WdmGetPinPropertySimple( deviceHandle, 0, KSPROPERTY_PIN_CTYPES, &result, sizeof(result) ) == paNoError ){
122
 
        return result;
123
 
    }else{
124
 
        return 0;
125
 
    }
126
 
}
127
 
 
128
 
 
129
 
static KSPIN_COMMUNICATION GetKSFilterPinPropertyCommunication( HANDLE deviceHandle, int pinId )
130
 
{
131
 
    KSPIN_COMMUNICATION result;
132
 
 
133
 
    if( WdmGetPinPropertySimple( deviceHandle, pinId, KSPROPERTY_PIN_COMMUNICATION, &result, sizeof(result) ) == paNoError ){
134
 
        return result;
135
 
    }else{
136
 
        return KSPIN_COMMUNICATION_NONE;
137
 
    }
138
 
}
139
 
 
140
 
 
141
 
static KSPIN_DATAFLOW GetKSFilterPinPropertyDataflow( HANDLE deviceHandle, int pinId )
142
 
{
143
 
    KSPIN_DATAFLOW result;
144
 
 
145
 
    if( WdmGetPinPropertySimple( deviceHandle, pinId, KSPROPERTY_PIN_DATAFLOW, &result, sizeof(result) ) == paNoError ){
146
 
        return result;
147
 
    }else{
148
 
        return (KSPIN_DATAFLOW)0;
149
 
    }
150
 
}
151
 
 
152
 
 
153
 
static int KSFilterPinPropertyIdentifiersInclude(
154
 
        HANDLE deviceHandle, int pinId, unsigned long property, const GUID *identifierSet, unsigned long identifierId  )
155
 
{
156
 
    KSMULTIPLE_ITEM* item = NULL;
157
 
    KSIDENTIFIER* identifier;
158
 
    int i;
159
 
    int result = 0;
160
 
 
161
 
    if( WdmGetPinPropertyMulti( deviceHandle, pinId, property, &item) != paNoError )
162
 
        return 0;
163
 
 
164
 
    identifier = (KSIDENTIFIER*)(item+1);
165
 
 
166
 
    for( i = 0; i < (int)item->Count; i++ )
167
 
    {
168
 
        if( !memcmp( (void*)&identifier[i].Set, (void*)identifierSet, sizeof( GUID ) ) &&
169
 
           ( identifier[i].Id == identifierId ) )
170
 
        {
171
 
            result = 1;
172
 
            break;
173
 
        }
174
 
    }
175
 
 
176
 
    PaUtil_FreeMemory( item );
177
 
 
178
 
    return result;
179
 
}
180
 
 
181
 
 
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.
184
 
*/
185
 
int PaWin_WDMKS_QueryFilterMaximumChannelCount( void *wcharDevicePath, int isInput )
186
 
{
187
 
    HANDLE deviceHandle;
188
 
    int pinCount, pinId, i;
189
 
    int result = 0;
190
 
    KSPIN_DATAFLOW requiredDataflowDirection = (isInput ? KSPIN_DATAFLOW_OUT : KSPIN_DATAFLOW_IN );
191
 
 
192
 
    if( !wcharDevicePath )
193
 
        return 0;
194
 
 
195
 
    deviceHandle = CreateFileW( (LPCWSTR)wcharDevicePath, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );
196
 
    if( deviceHandle == INVALID_HANDLE_VALUE )
197
 
        return 0;
198
 
 
199
 
    pinCount = GetKSFilterPinCount( deviceHandle );
200
 
    for( pinId = 0; pinId < pinCount; ++pinId )
201
 
    {
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 ) )
213
 
         {
214
 
            KSMULTIPLE_ITEM* item = NULL;
215
 
            if( WdmGetPinPropertyMulti( deviceHandle, pinId, KSPROPERTY_PIN_DATARANGES, &item ) == paNoError )
216
 
            {
217
 
                KSDATARANGE *dataRange = (KSDATARANGE*)(item+1);
218
 
 
219
 
                for( i=0; i < item->Count; ++i ){
220
 
 
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 ) ) )
226
 
                    {
227
 
                        KSDATARANGE_AUDIO *dataRangeAudio = (KSDATARANGE_AUDIO*)dataRange;
228
 
 
229
 
                        /*
230
 
                        printf( ">>> %d %d %d %d %S\n", isInput, dataflow, communication, dataRangeAudio->MaximumChannels, devicePath );
231
 
 
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" );
238
 
                        else
239
 
                            printf( "\tspecifier: ?\n" );
240
 
                        */
241
 
 
242
 
                        /*
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.
245
 
                        */
246
 
                        if( dataRangeAudio->MaximumChannels  < 0xFFFFUL && (int)dataRangeAudio->MaximumChannels > result )
247
 
                            result = (int)dataRangeAudio->MaximumChannels;
248
 
                    }
249
 
 
250
 
                    dataRange = (KSDATARANGE*)( ((char*)dataRange) + dataRange->FormatSize);
251
 
                }
252
 
 
253
 
                PaUtil_FreeMemory( item );
254
 
            }
255
 
        }
256
 
    }
257
 
 
258
 
    CloseHandle( deviceHandle );
259
 
    return result;
260
 
}