summaryrefslogtreecommitdiff
path: root/audio/sysvad/EndpointsCommon/micarraytopo.cpp
blob: 1898243af823877cd93628835d08cfbfe28b261f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
/*++

Copyright (c) Microsoft Corporation All Rights Reserved

Module Name:

    micarraytopo.cpp

Abstract:

    Implementation of topology miniport for the mic array.

--*/

#pragma warning (disable : 4127)

#include <sysvad.h>
#include "simple.h"
#include "micarraytopo.h"
#include "micarray1toptable.h"

constexpr float MICARRAY_SENSITIVITY = -46.5f;
constexpr float MICARRAY_SENSITIVITY2 = -23.5f;
constexpr float MICARRAY_SNR = 66.0f;

constexpr inline LONG FloatToFixedPoint16_16(float fl)
{
    return (static_cast<LONG>((fl)* (65536.0f)));
}

#pragma code_seg("PAGE")

//=============================================================================
NTSTATUS
CreateMicArrayMiniportTopology
( 
    _Out_           PUNKNOWN                              * Unknown,
    _In_            REFCLSID,
    _In_opt_        PUNKNOWN                                UnknownOuter,
    _In_            POOL_FLAGS                              PoolFlags, 
    _In_            PUNKNOWN                                UnknownAdapter,
    _In_opt_        PVOID                                   DeviceContext,
    _In_            PENDPOINT_MINIPAIR                      MiniportPair
)
/*++

Routine Description:

    Creates a new topology miniport.

Arguments:

  Unknown - 

  RefclsId -

  UnknownOuter -

  PoolType - 

  UnknownAdapter - 

  DeviceContext -

  MiniportPair - 

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(Unknown);
    ASSERT(MiniportPair);

    UNREFERENCED_PARAMETER(UnknownAdapter);
    UNREFERENCED_PARAMETER(DeviceContext);

    CMicArrayMiniportTopology *obj = 
        new (PoolFlags, MINTOPORT_POOLTAG) 
            CMicArrayMiniportTopology( UnknownOuter,
                                       MiniportPair->TopoDescriptor,
                                       MiniportPair->DeviceMaxChannels,
                                       MiniportPair->DeviceType );
    if (NULL == obj)
    {
        return STATUS_INSUFFICIENT_RESOURCES;
    }
    
    obj->AddRef();
    
    *Unknown = reinterpret_cast<IUnknown*>(obj);

    return STATUS_SUCCESS;
} // CreateMicArrayMiniportTopology

//=============================================================================
CMicArrayMiniportTopology::~CMicArrayMiniportTopology
(
    void
)
/*++

Routine Description:

  Topology miniport destructor

Arguments:

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    DPF_ENTER(("[CMicArrayMiniportTopology::~CMicArrayMiniportTopology]"));
} // ~CMicArrayMiniportTopology

//=============================================================================
NTSTATUS
CMicArrayMiniportTopology::DataRangeIntersection
( 
    _In_        ULONG                   PinId,
    _In_        PKSDATARANGE            ClientDataRange,
    _In_        PKSDATARANGE            MyDataRange,
    _In_        ULONG                   OutputBufferLength,
    _Out_writes_bytes_to_opt_(OutputBufferLength, *ResultantFormatLength)
                PVOID                   ResultantFormat     OPTIONAL,
    _Out_       PULONG                  ResultantFormatLength 
)
/*++

Routine Description:

  The DataRangeIntersection function determines the highest quality 
  intersection of two data ranges.

Arguments:

  PinId - Pin for which data intersection is being determined. 

  ClientDataRange - Pointer to KSDATARANGE structure which contains the data range 
                    submitted by client in the data range intersection property 
                    request. 

  MyDataRange - Pin's data range to be compared with client's data range. 

  OutputBufferLength - Size of the buffer pointed to by the resultant format 
                       parameter. 

  ResultantFormat - Pointer to value where the resultant format should be 
                    returned. 

  ResultantFormatLength - Actual length of the resultant format that is placed 
                          at ResultantFormat. This should be less than or equal 
                          to OutputBufferLength. 

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    return 
        CMiniportTopologySYSVAD::DataRangeIntersection
        (
            PinId,
            ClientDataRange,
            MyDataRange,
            OutputBufferLength,
            ResultantFormat,
            ResultantFormatLength
        );
} // DataRangeIntersection

//=============================================================================
STDMETHODIMP
CMicArrayMiniportTopology::GetDescription
( 
    _Out_ PPCFILTER_DESCRIPTOR *  OutFilterDescriptor 
)
/*++

Routine Description:

  The GetDescription function gets a pointer to a filter description. 
  It provides a location to deposit a pointer in miniport's description 
  structure. This is the placeholder for the FromNode or ToNode fields in 
  connections which describe connections to the filter's pins. 

Arguments:

  OutFilterDescriptor - Pointer to the filter description. 

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(OutFilterDescriptor);

    return CMiniportTopologySYSVAD::GetDescription(OutFilterDescriptor);        
} // GetDescription

//=============================================================================
STDMETHODIMP
CMicArrayMiniportTopology::Init
( 
    _In_ PUNKNOWN                 UnknownAdapter,
    _In_ PRESOURCELIST            ResourceList,
    _In_ PPORTTOPOLOGY            Port_ 
)
/*++

Routine Description:

  The Init function initializes the miniport. Callers of this function 
  should run at IRQL PASSIVE_LEVEL

Arguments:

  UnknownAdapter - A pointer to the IUnknown interface of the adapter object. 

  ResourceList - Pointer to the resource list to be supplied to the miniport 
                 during initialization. The port driver is free to examine the 
                 contents of the ResourceList. The port driver will not be 
                 modify the ResourceList contents. 

  Port - Pointer to the topology port object that is linked with this miniport. 

Return Value:

  NT status code.

--*/
{
    UNREFERENCED_PARAMETER(ResourceList);
    
    PAGED_CODE();

    ASSERT(UnknownAdapter);
    ASSERT(Port_);

    DPF_ENTER(("[CMicArrayMiniportTopology::Init]"));

    NTSTATUS                    ntStatus;

    ntStatus = 
        CMiniportTopologySYSVAD::Init
        (
            UnknownAdapter,
            Port_
        );

    return ntStatus;
} // Init

//=============================================================================
STDMETHODIMP
CMicArrayMiniportTopology::NonDelegatingQueryInterface
( 
    _In_         REFIID                  Interface,
    _COM_Outptr_ PVOID                   * Object 
)
/*++

Routine Description:

  QueryInterface for MiniportTopology

Arguments:

  Interface - GUID of the interface

  Object - interface object to be returned.

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(Object);

    if (IsEqualGUIDAligned(Interface, IID_IUnknown))
    {
        *Object = PVOID(PUNKNOWN(this));
    }
    else if (IsEqualGUIDAligned(Interface, IID_IMiniport))
    {
        *Object = PVOID(PMINIPORT(this));
    }
    else if (IsEqualGUIDAligned(Interface, IID_IMiniportTopology))
    {
        *Object = PVOID(PMINIPORTTOPOLOGY(this));
    }
    else
    {
        *Object = NULL;
    }

    if (*Object)
    {
        // We reference the interface for the caller.
        PUNKNOWN(*Object)->AddRef();
        return(STATUS_SUCCESS);
    }

    return(STATUS_INVALID_PARAMETER);
} // NonDelegatingQueryInterface

//=============================================================================
NTSTATUS
CMicArrayMiniportTopology::PropertyHandlerMicArrayGeometry
( 
    _In_ PPCPROPERTY_REQUEST      PropertyRequest 
)
/*++

Routine Description:

  Handles ( KSPROPSETID_Audio, KSPROPERTY_AUDIO_MIC_ARRAY_GEOMETRY )

Arguments:

  PropertyRequest - 

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(PropertyRequest);

    DPF_ENTER(("[PropertyHandlerMicArrayGeometry]"));

    NTSTATUS    ntStatus = STATUS_INVALID_DEVICE_REQUEST;
    ULONG       nPinId = (ULONG)-1;

    if (PropertyRequest->InstanceSize >= sizeof(ULONG))
    {
        nPinId = *(PULONG(PropertyRequest->Instance));

        if (nPinId == KSPIN_TOPO_MIC_ELEMENTS)
        {
            if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT)
            {
                ntStatus = 
                    PropertyHandler_BasicSupport
                    (
                        PropertyRequest,
                        KSPROPERTY_TYPE_BASICSUPPORT | KSPROPERTY_TYPE_GET,
                        VT_ILLEGAL
                    );
            }
            else
            {
                ULONG cElements = IsCombined()? 4 : 2;
                ULONG cbNeeded = FIELD_OFFSET(KSAUDIO_MIC_ARRAY_GEOMETRY, KsMicCoord) +
                                 cElements * sizeof(KSAUDIO_MICROPHONE_COORDINATES);

                if (PropertyRequest->ValueSize == 0)
                {
                    PropertyRequest->ValueSize = cbNeeded;
                    ntStatus = STATUS_BUFFER_OVERFLOW;
                }
                else if (PropertyRequest->ValueSize < cbNeeded)
                {
                    ntStatus = STATUS_BUFFER_TOO_SMALL;
                }
                else
                {
                    if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET)
                    {
                        PKSAUDIO_MIC_ARRAY_GEOMETRY pMAG = (PKSAUDIO_MIC_ARRAY_GEOMETRY)PropertyRequest->Value;
                        const SHORT MicArray_180_Degrees = 31416; // 10000 * pi
                        const SHORT MicArray_45_Degrees  = 7854;  // 10000 * pi / 4

                        if (IsFront())
                        {
                            // fill in mic array geometry fields
                            pMAG->usVersion = 0x0100;           // Version of Mic array specification (0x0100)
                            pMAG->usMicArrayType = (USHORT)KSMICARRAY_MICARRAYTYPE_LINEAR;        // Type of Mic Array
                            pMAG->wVerticalAngleBegin = -MicArray_45_Degrees; // Work Volume Vertical Angle Begin
                            pMAG->wVerticalAngleEnd   =  MicArray_45_Degrees; // Work Volume Vertical Angle End
                            pMAG->wHorizontalAngleBegin = 0;    // Work Volume HorizontalAngle Begin
                            pMAG->wHorizontalAngleEnd   = 0;    // Work Volume HorizontalAngle End
                            pMAG->usFrequencyBandLo = 100;      // Low end of Freq Range
                            pMAG->usFrequencyBandHi = 8000;     // High end of Freq Range
                            
                            pMAG->usNumberOfMicrophones = 2;    // Count of microphone coordinate structures to follow.

                            pMAG->KsMicCoord[0].usType = (USHORT)KSMICARRAY_MICTYPE_CARDIOID;          
                            pMAG->KsMicCoord[0].wXCoord = 0; 
                            pMAG->KsMicCoord[0].wYCoord = -100; // mic elements are 200 mm apart        
                            pMAG->KsMicCoord[0].wZCoord = 0;         
                            pMAG->KsMicCoord[0].wVerticalAngle = 0;  
                            pMAG->KsMicCoord[0].wHorizontalAngle = 0;

                            pMAG->KsMicCoord[1].usType = (USHORT)KSMICARRAY_MICTYPE_CARDIOID;          
                            pMAG->KsMicCoord[1].wXCoord = 0;  
                            pMAG->KsMicCoord[1].wYCoord = 100; // mic elements are 200 mm apart        
                            pMAG->KsMicCoord[1].wZCoord = 0;         
                            pMAG->KsMicCoord[1].wVerticalAngle = 0;  
                            pMAG->KsMicCoord[1].wHorizontalAngle = 0;
                        }
                        else if (IsBack()) // in this sample the geometries for front and back are the same.
                        {
                            // fill in mic array geometry fields
                            pMAG->usVersion = 0x0100;           // Version of Mic array specification (0x0100)
                            pMAG->usMicArrayType = (USHORT)KSMICARRAY_MICARRAYTYPE_LINEAR;        // Type of Mic Array
                            pMAG->wVerticalAngleBegin = -MicArray_45_Degrees;  // Work Volume Vertical Angle Begin
                            pMAG->wVerticalAngleEnd   =  MicArray_45_Degrees;  // Work Volume Vertical Angle End
                            pMAG->wHorizontalAngleBegin = 0;    // Work Volume HorizontalAngle Begin
                            pMAG->wHorizontalAngleEnd   = 0;    // Work Volume HorizontalAngle End
                            pMAG->usFrequencyBandLo = 100;      // Low end of Freq Range
                            pMAG->usFrequencyBandHi = 8000;     // High end of Freq Range
                            
                            pMAG->usNumberOfMicrophones = 2;    // Count of microphone coordinate structures to follow.

                            pMAG->KsMicCoord[0].usType = (USHORT)KSMICARRAY_MICTYPE_CARDIOID;          
                            pMAG->KsMicCoord[0].wXCoord = 0; 
                            pMAG->KsMicCoord[0].wYCoord = -100; // mic elements are 200 mm apart        
                            pMAG->KsMicCoord[0].wZCoord = 0;         
                            pMAG->KsMicCoord[0].wVerticalAngle = 0;  
                            pMAG->KsMicCoord[0].wHorizontalAngle = 0;

                            pMAG->KsMicCoord[1].usType = (USHORT)KSMICARRAY_MICTYPE_CARDIOID;          
                            pMAG->KsMicCoord[1].wXCoord = 0;  
                            pMAG->KsMicCoord[1].wYCoord = 100; // mic elements are 200 mm apart        
                            pMAG->KsMicCoord[1].wZCoord = 0;         
                            pMAG->KsMicCoord[1].wVerticalAngle = 0;  
                            pMAG->KsMicCoord[1].wHorizontalAngle = 0;
                        }
                        else 
                        {
                            // fill in mic array geometry fields
                            pMAG->usVersion = 0x0100;           // Version of Mic array specification (0x0100)
                            pMAG->usMicArrayType = (USHORT)KSMICARRAY_MICARRAYTYPE_LINEAR;        // Type of Mic Array
                            pMAG->wVerticalAngleBegin = -MicArray_45_Degrees; // Work Volume Vertical Angle Begin 
                            pMAG->wVerticalAngleEnd   =  MicArray_45_Degrees; // Work Volume Vertical Angle End
                            pMAG->wHorizontalAngleBegin = -MicArray_180_Degrees; // Work Volume HorizontalAngle Begin
                            pMAG->wHorizontalAngleEnd   =  MicArray_180_Degrees; // Work Volume HorizontalAngle End
                            pMAG->usFrequencyBandLo = 100;      // Low end of Freq Range
                            pMAG->usFrequencyBandHi = 8000;     // High end of Freq Range
                            
                            pMAG->usNumberOfMicrophones = 4;    // Count of microphone coordinate structures to follow.

                            // front elements
                            pMAG->KsMicCoord[0].usType = (USHORT)KSMICARRAY_MICTYPE_CARDIOID;          
                            pMAG->KsMicCoord[0].wXCoord = 0; 
                            pMAG->KsMicCoord[0].wYCoord = -100; // mic elements are 200 mm apart        
                            pMAG->KsMicCoord[0].wZCoord = 0;         
                            pMAG->KsMicCoord[0].wVerticalAngle = 0;  
                            pMAG->KsMicCoord[0].wHorizontalAngle = 0;

                            pMAG->KsMicCoord[1].usType = (USHORT)KSMICARRAY_MICTYPE_CARDIOID;          
                            pMAG->KsMicCoord[1].wXCoord = 0;  
                            pMAG->KsMicCoord[1].wYCoord = 100; // mic elements are 200 mm apart        
                            pMAG->KsMicCoord[1].wZCoord = 0;         
                            pMAG->KsMicCoord[1].wVerticalAngle = 0;  
                            pMAG->KsMicCoord[1].wHorizontalAngle = 0;

                            // back elements
                            pMAG->KsMicCoord[2].usType = (USHORT)KSMICARRAY_MICTYPE_CARDIOID;          
                            pMAG->KsMicCoord[2].wXCoord = 0; 
                            pMAG->KsMicCoord[2].wYCoord = -100; // mic elements are 200 mm apart        
                            pMAG->KsMicCoord[2].wZCoord = 0;         
                            pMAG->KsMicCoord[2].wVerticalAngle = 0;  
                            pMAG->KsMicCoord[2].wHorizontalAngle = -MicArray_180_Degrees;
                            
                            pMAG->KsMicCoord[3].usType = (USHORT)KSMICARRAY_MICTYPE_CARDIOID;          
                            pMAG->KsMicCoord[3].wXCoord = 0;  
                            pMAG->KsMicCoord[3].wYCoord = 100; // mic elements are 200 mm apart        
                            pMAG->KsMicCoord[3].wZCoord = 0;         
                            pMAG->KsMicCoord[3].wVerticalAngle = 0;  
                            pMAG->KsMicCoord[3].wHorizontalAngle = -MicArray_180_Degrees;
                            
                        }
                        
                        ntStatus = STATUS_SUCCESS;
                    }
                }
            }
        }
    }

    return ntStatus;
}

//=============================================================================
NTSTATUS
CMicArrayMiniportTopology::PropertyHandlerMicProperties
(
    _In_ PPCPROPERTY_REQUEST      PropertyRequest
)
/*++

Routine Description:

Handles ( KSPROPSETID_Audio, KSPROPERTY_AUDIO_MIC_SNR )
Handles ( KSPROPSETID_Audio, KSPROPERTY_AUDIO_MIC_SENSITIVITY2 )

Arguments:

PropertyRequest -

Return Value:

NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(PropertyRequest);

    DPF_ENTER(("[PropertyHandlerMicProperties]"));

    NTSTATUS    ntStatus = STATUS_INVALID_DEVICE_REQUEST;
    ULONG       nPinId = (ULONG)-1;
    KFLOATING_SAVE saveData;
    NTSTATUS fstatus;

    if (PropertyRequest->InstanceSize >= sizeof(ULONG))
    {
        nPinId = *(PULONG(PropertyRequest->Instance));

        if (nPinId == KSPIN_TOPO_MIC_ELEMENTS)
        {
            if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT)
            {
                ntStatus =
                    PropertyHandler_BasicSupport
                    (
                    PropertyRequest,
                    KSPROPERTY_TYPE_BASICSUPPORT | KSPROPERTY_TYPE_GET,
                    VT_ILLEGAL
                    );
            }
            else
            {
                ntStatus =
                    ValidatePropertyParams
                    (
                        PropertyRequest,
                        sizeof(LONG),
                        0
                    );

                if (NT_SUCCESS(ntStatus))
                {
                    if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET)
                    {
                        if (PropertyRequest->PropertyItem->Id == KSPROPERTY_AUDIO_MIC_SNR)
                        {
                            LONG* micSNR = (LONG*)PropertyRequest->Value;
                            fstatus = KeSaveFloatingPointState(&saveData);
                            if (NT_SUCCESS(fstatus))
                            {
                                // Return microphone SNR information.
                                *micSNR = FloatToFixedPoint16_16(MICARRAY_SNR); // convert float dB to fixed point arithmetic
                                KeRestoreFloatingPointState(&saveData);
                            }
                            ntStatus = STATUS_SUCCESS;
                        }
                        else if (PropertyRequest->PropertyItem->Id == KSPROPERTY_AUDIO_MIC_SENSITIVITY2)
                        {
                            LONG* micSensitivity2 = (LONG*)PropertyRequest->Value;
                            fstatus = KeSaveFloatingPointState(&saveData);
                            if (NT_SUCCESS(fstatus))
                            {
                                // Return microphone SNR information.
                                *micSensitivity2 = FloatToFixedPoint16_16(MICARRAY_SENSITIVITY2); // convert float dB to fixed point arithmetic
                                KeRestoreFloatingPointState(&saveData);
                            }
                            ntStatus = STATUS_SUCCESS;
                        }
                    }
                    else
                    {
                        ntStatus = STATUS_INVALID_DEVICE_REQUEST;
                    }
                }
            }
        }
    }

    return ntStatus;
}

//=============================================================================
NTSTATUS
CMicArrayMiniportTopology::PropertyHandlerJackDescription
( 
    _In_ PPCPROPERTY_REQUEST      PropertyRequest 
)
/*++

Routine Description:

  Handles ( KSPROPSETID_Jack, KSPROPERTY_JACK_DESCRIPTION )

Arguments:

  PropertyRequest - 

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(PropertyRequest);

    DPF_ENTER(("[PropertyHandlerJackDescription]"));

    NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
    ULONG    nPinId = (ULONG)-1;

    if (PropertyRequest->InstanceSize >= sizeof(ULONG))
    {
        nPinId = *(PULONG(PropertyRequest->Instance));

        if (nPinId == KSPIN_TOPO_MIC_ELEMENTS)
        {
            if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT)
            {
                ntStatus = 
                    PropertyHandler_BasicSupport
                    (
                        PropertyRequest,
                        KSPROPERTY_TYPE_BASICSUPPORT | KSPROPERTY_TYPE_GET,
                        VT_ILLEGAL
                    );
            }
            else
            {
                ULONG cbNeeded = sizeof(KSMULTIPLE_ITEM) + sizeof(KSJACK_DESCRIPTION);

                if (PropertyRequest->ValueSize == 0)
                {
                    PropertyRequest->ValueSize = cbNeeded;
                    ntStatus = STATUS_BUFFER_OVERFLOW;
                }
                else if (PropertyRequest->ValueSize < cbNeeded)
                {
                    ntStatus = STATUS_BUFFER_TOO_SMALL;
                }
                else
                {
                    if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET)
                    {
                        PKSMULTIPLE_ITEM pMI = (PKSMULTIPLE_ITEM)PropertyRequest->Value;
                        PKSJACK_DESCRIPTION pDesc = (PKSJACK_DESCRIPTION)(pMI+1);

                        pMI->Size = cbNeeded;
                        pMI->Count = 1;

                        pDesc->ChannelMapping   = 0;                // Don't specify channel mask for array mic
                        pDesc->Color            = 0x00000000;       // Black.  This is an integrated device
                        pDesc->ConnectionType   = eConnTypeUnknown; // Integrated.
                        pDesc->GenLocation      = eGenLocPrimaryBox;
                        pDesc->GeoLocation      = IsFront() ? eGeoLocFront : 
                                                    (IsBack() ? eGeoLocRear : eGeoLocNotApplicable);
                        pDesc->PortConnection   = ePortConnIntegratedDevice;
                        pDesc->IsConnected      = TRUE;             // This is an integrated device, so it's always "connected"
                        
                        ntStatus = STATUS_SUCCESS;
                    }
                }
            }
        }
    }

    return ntStatus;
}

//=============================================================================
NTSTATUS
CMicArrayMiniportTopology::PropertyHandlerJackDescription2
( 
    _In_ PPCPROPERTY_REQUEST      PropertyRequest 
)
/*++

Routine Description:

  Handles ( KSPROPSETID_Jack, KSPROPERTY_JACK_DESCRIPTION2 )

Arguments:

  PropertyRequest - 

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(PropertyRequest);

    DPF_ENTER(("[PropertyHandlerJackDescription2]"));

    NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
    ULONG    nPinId = (ULONG)-1;

    if (PropertyRequest->InstanceSize >= sizeof(ULONG))
    {
        nPinId = *(PULONG(PropertyRequest->Instance));

        if (nPinId == KSPIN_TOPO_MIC_ELEMENTS)
        {
            if (PropertyRequest->Verb & KSPROPERTY_TYPE_BASICSUPPORT)
            {
                ntStatus = 
                    PropertyHandler_BasicSupport
                    (
                        PropertyRequest,
                        KSPROPERTY_TYPE_BASICSUPPORT | KSPROPERTY_TYPE_GET,
                        VT_ILLEGAL
                    );
            }
            else
            {
                ULONG cbNeeded = sizeof(KSMULTIPLE_ITEM) + sizeof(KSJACK_DESCRIPTION2);

                if (PropertyRequest->ValueSize == 0)
                {
                    PropertyRequest->ValueSize = cbNeeded;
                    ntStatus = STATUS_BUFFER_OVERFLOW;
                }
                else if (PropertyRequest->ValueSize < cbNeeded)
                {
                    ntStatus = STATUS_BUFFER_TOO_SMALL;
                }
                else
                {
                    if (PropertyRequest->Verb & KSPROPERTY_TYPE_GET)
                    {
                        PKSMULTIPLE_ITEM pMI = (PKSMULTIPLE_ITEM)PropertyRequest->Value;
                        PKSJACK_DESCRIPTION2 pDesc = (PKSJACK_DESCRIPTION2)(pMI+1);

                        pMI->Size = cbNeeded;
                        pMI->Count = 1;
                        
                        RtlZeroMemory(pDesc, sizeof(KSJACK_DESCRIPTION2));

                        //
                        // Specifies the lower 16 bits of the DWORD parameter. This parameter indicates whether 
                        // the jack is currently active, streaming, idle, or hardware not ready.
                        //
                        pDesc->DeviceStateInfo = 0;

                        //
                        // From MSDN:
                        // "If an audio device lacks jack presence detection, the IsConnected member of
                        // the KSJACK_DESCRIPTION structure must always be set to TRUE. To remove the 
                        // ambiguity that results from this dual meaning of the TRUE value for IsConnected, 
                        // a client application can call IKsJackDescription2::GetJackDescription2 to read 
                        // the JackCapabilities flag of the KSJACK_DESCRIPTION2 structure. If this flag has
                        // the JACKDESC2_PRESENCE_DETECT_CAPABILITY bit set, it indicates that the endpoint 
                        // does in fact support jack presence detection. In that case, the return value of 
                        // the IsConnected member can be interpreted to accurately reflect the insertion status
                        // of the jack."
                        //
                        // Bit definitions:
                        // 0x00000001 - JACKDESC2_PRESENCE_DETECT_CAPABILITY
                        // 0x00000002 - JACKDESC2_DYNAMIC_FORMAT_CHANGE_CAPABILITY 
                        //
                        pDesc->JackCapabilities = 0;
                        
                        ntStatus = STATUS_SUCCESS;
                    }
                }
            }
        }
    }

    return ntStatus;
}

//=============================================================================
NTSTATUS
PropertyHandler_MicArrayTopoFilter
( 
    _In_ PPCPROPERTY_REQUEST      PropertyRequest 
)
/*++

Routine Description:

  Redirects property request to miniport object

Arguments:

  PropertyRequest - 

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(PropertyRequest);

    DPF_ENTER(("[PropertyHandler_MicArrayTopoFilter]"));

    // PropertryRequest structure is filled by portcls. 
    // MajorTarget is a pointer to miniport object for miniports.
    //
    NTSTATUS            ntStatus = STATUS_INVALID_DEVICE_REQUEST;
    PCMicArrayMiniportTopology  pMiniport = (PCMicArrayMiniportTopology)PropertyRequest->MajorTarget;

    if (IsEqualGUIDAligned(*PropertyRequest->PropertyItem->Set, KSPROPSETID_Audio))
    {
        if (PropertyRequest->PropertyItem->Id == KSPROPERTY_AUDIO_MIC_ARRAY_GEOMETRY)
        {
            ntStatus = pMiniport->PropertyHandlerMicArrayGeometry(PropertyRequest);
        }
        else if (PropertyRequest->PropertyItem->Id == KSPROPERTY_AUDIO_MIC_SENSITIVITY2)
        {
            ntStatus = pMiniport->PropertyHandlerMicProperties(PropertyRequest);
        }
        else if (PropertyRequest->PropertyItem->Id == KSPROPERTY_AUDIO_MIC_SNR)
        {
            ntStatus = pMiniport->PropertyHandlerMicProperties(PropertyRequest);
        }
    }
    else if (IsEqualGUIDAligned(*PropertyRequest->PropertyItem->Set, KSPROPSETID_Jack))
    {
        if (PropertyRequest->PropertyItem->Id == KSPROPERTY_JACK_DESCRIPTION)
        {
            ntStatus = pMiniport->PropertyHandlerJackDescription(PropertyRequest);
        }
        else if (PropertyRequest->PropertyItem->Id == KSPROPERTY_JACK_DESCRIPTION2)
        {
            ntStatus = pMiniport->PropertyHandlerJackDescription2(PropertyRequest);
        }
    }

    return ntStatus;
} // PropertyHandler_TopoFilter

//=============================================================================
NTSTATUS
PropertyHandler_MicArrayTopology
( 
    _In_ PPCPROPERTY_REQUEST      PropertyRequest 
)
/*++

Routine Description:

  Redirects property request to miniport object

Arguments:

  PropertyRequest - 

Return Value:

  NT status code.

--*/
{
    PAGED_CODE();

    ASSERT(PropertyRequest);

    DPF_ENTER(("[PropertyHandler_MicArrayTopology]"));

    // PropertryRequest structure is filled by portcls. 
    // MajorTarget is a pointer to miniport object for miniports.
    //
    PCMicArrayMiniportTopology pMiniport = (PCMicArrayMiniportTopology)PropertyRequest->MajorTarget;

    return pMiniport->PropertyHandlerGeneric(PropertyRequest);
} // PropertyHandler_MicArrayTopology

#pragma code_seg()