Sample Code

Windows Driver Samples/ Microsoft slate system virtual audio device driver sample/ C++/ SlateAudioSample/ minwavert.h/

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
/*++
 
Copyright (c) Microsoft Corporation All Rights Reserved
 
Module Name:
 
    minwavert.h
 
Abstract:
 
    Definition of wavert miniport class.
 
--*/
 
#ifndef _SYSVAD_MINWAVERT_H_
#define _SYSVAD_MINWAVERT_H_
 
#ifdef SYSVAD_BTH_BYPASS
#include "bthhfpmicwavtable.h"
#endif // SYSVAD_BTH_BYPASS
 
//=============================================================================
// Referenced Forward
//=============================================================================
class CMiniportWaveRTStream;
typedef CMiniportWaveRTStream *PCMiniportWaveRTStream;
 
//=============================================================================
// Classes
//=============================================================================
///////////////////////////////////////////////////////////////////////////////
// CMiniportWaveRT
//  
class CMiniportWaveRT :
    public IMiniportWaveRT,
    public IMiniportAudioEngineNode,
    public IMiniportAudioSignalProcessing,
    public CUnknown
{
private:
    ULONG                               m_ulLoopbackAllocated;
    ULONG                               m_ulSystemAllocated;
    ULONG                               m_ulOffloadAllocated;
     
    ULONG                               m_ulMaxSystemStreams;
    ULONG                               m_ulMaxOffloadStreams;
    ULONG                               m_ulMaxLoopbackStreams;
    // weak ref of running streams.
    PCMiniportWaveRTStream            * m_SystemStreams;
    PCMiniportWaveRTStream            * m_OffloadStreams;
    PCMiniportWaveRTStream            * m_LoopbackStreams;
 
    BOOL                                m_bGfxEnabled;
    PBOOL                               m_pbMuted;
    PLONG                               m_plVolumeLevel;
    PLONG                               m_plPeakMeter;
    PKSDATAFORMAT_WAVEFORMATEXTENSIBLE  m_pMixFormat;
    PKSDATAFORMAT_WAVEFORMATEXTENSIBLE  m_pDeviceFormat;
    PCFILTER_DESCRIPTOR                 m_FilterDesc;
    eDeviceType                         m_DeviceType;
    PADAPTERCOMMON                      m_pAdapterCommon;
    PIN_DEVICE_FORMATS_AND_MODES *      m_DeviceFormatsAndModes;
    ULONG                               m_DeviceFormatsAndModesCount;
    USHORT                              m_DeviceMaxChannels;
    PDRMPORT                            m_pDrmPort;
    DRMRIGHTS                           m_MixDrmRights;
    ULONG                               m_ulMixDrmContentId;
    CONSTRICTOR_OPTION                  m_LoopbackProtection;
    union {
        PVOID                           m_DeviceContext;
#ifdef SYSVAD_BTH_BYPASS
        PBTHHFPDEVICECOMMON             m_BthHfpDevice;
#endif  // SYSVAD_BTH_BYPASS
    };
    ULONG                               m_DeviceFlags;
 
public:
    NTSTATUS ValidateStreamCreate
    (
        _In_ ULONG _Pin,
        _In_ BOOLEAN _Capture
    );
     
    NTSTATUS StreamCreated
    (
        _In_ ULONG                  _Pin,
        _In_ PCMiniportWaveRTStream _Stream
    );
     
    NTSTATUS StreamClosed
    (
        _In_ ULONG _Pin,
        _In_ PCMiniportWaveRTStream _Stream
    );
     
    NTSTATUS IsFormatSupported
    (
        _In_ ULONG          _ulPin,
        _In_ BOOLEAN        _bCapture,
        _In_ PKSDATAFORMAT  _pDataFormat
    );
 
    static NTSTATUS GetAttributesFromAttributeList
    (
        _In_ const KSMULTIPLE_ITEM *_pAttributes,
        _In_ size_t _Size,
        _Out_ GUID* _pSignalProcessingMode
    );
 
protected:
    NTSTATUS UpdateDrmRights
    (
        void
    );
     
    NTSTATUS SetLoopbackProtection
    (
        _In_ CONSTRICTOR_OPTION ulProtectionOption
    );
 
public:
    DECLARE_STD_UNKNOWN();
 
    CMiniportWaveRT(
        _In_            PUNKNOWN                                UnknownAdapter,
        _In_            PENDPOINT_MINIPAIR                      MiniportPair,
        _In_opt_        PVOID                                   DeviceContext
        )
        :CUnknown(0),
        m_ulMaxSystemStreams(0),
        m_ulMaxOffloadStreams(0),
        m_ulMaxLoopbackStreams(0),
        m_DeviceType(MiniportPair->DeviceType),
        m_DeviceContext(DeviceContext),
        m_DeviceMaxChannels(MiniportPair->DeviceMaxChannels),
        m_DeviceFormatsAndModes(MiniportPair->PinDeviceFormatsAndModes),
        m_DeviceFormatsAndModesCount(MiniportPair->PinDeviceFormatsAndModesCount),
        m_DeviceFlags(MiniportPair->DeviceFlags)
    {
        m_pAdapterCommon = (PADAPTERCOMMON)UnknownAdapter; // weak ref.
         
        if (MiniportPair->WaveDescriptor)
        {
            RtlCopyMemory(&m_FilterDesc, MiniportPair->WaveDescriptor, sizeof(m_FilterDesc));
             
            //
            // Get the max # of pin instances.
            //
            if (IsRenderDevice())
            {
                if (IsOffloadSupported())
                {
                    if (m_FilterDesc.PinCount > KSPIN_WAVE_RENDER_SOURCE)
                    {
                        m_ulMaxSystemStreams = m_FilterDesc.Pins[KSPIN_WAVE_RENDER_SINK_SYSTEM].MaxFilterInstanceCount;
                        m_ulMaxOffloadStreams = m_FilterDesc.Pins[KSPIN_WAVE_RENDER_SINK_OFFLOAD].MaxFilterInstanceCount;
                        m_ulMaxLoopbackStreams = m_FilterDesc.Pins[KSPIN_WAVE_RENDER_SINK_LOOPBACK].MaxFilterInstanceCount;
                    }
                }
                else
                {
                    if (m_FilterDesc.PinCount > KSPIN_WAVE_RENDER2_SOURCE)
                    {
                        m_ulMaxSystemStreams = m_FilterDesc.Pins[KSPIN_WAVE_RENDER2_SINK_SYSTEM].MaxFilterInstanceCount;
                        m_ulMaxLoopbackStreams = m_FilterDesc.Pins[KSPIN_WAVE_RENDER2_SINK_LOOPBACK].MaxFilterInstanceCount;
                    }
                }
            }
        }
         
#ifdef SYSVAD_BTH_BYPASS
        if (IsBthHfpDevice())
        {
            if (m_BthHfpDevice != NULL)
            {
                // This ref is released on dtor.
                m_BthHfpDevice->AddRef(); // strong ref.
            }
        }
#endif // SYSVAD_BTH_BYPASS
    }
 
    ~CMiniportWaveRT();
 
    IMP_IMiniportWaveRT;
    IMP_IMiniportAudioEngineNode;
    IMP_IMiniportAudioSignalProcessing;
     
    // Friends
    friend class        CMiniportWaveRTStream;
    friend class        CMiniportTopologySimple;
     
    friend NTSTATUS PropertyHandler_WaveFilter(  
                        _In_ PPCPROPERTY_REQUEST      PropertyRequest
                        );  
 
public:
    NTSTATUS PropertyHandlerEffectListRequest
    (
        _In_ PPCPROPERTY_REQUEST PropertyRequest
    );   
 
    NTSTATUS PropertyHandlerProposedFormat
    (
        _In_ PPCPROPERTY_REQUEST PropertyRequest
    );
 
    NTSTATUS PropertyHandlerProposedFormat2
    (
        _In_ PPCPROPERTY_REQUEST PropertyRequest
    );
 
    PADAPTERCOMMON GetAdapterCommObj()
    {
        return m_pAdapterCommon;
    };
 
#ifdef SYSVAD_BTH_BYPASS
    NTSTATUS PropertyHandler_BthHfpAudioEffectsDiscoveryEffectsList 
    (
        _In_ PPCPROPERTY_REQUEST PropertyRequest
    );
#endif  // SYSVAD_BTH_BYPASS
 
    //---------------------------------------------------------------------------------------------------------
    // volume
    //---------------------------------------------------------------------------------------------------------
    NTSTATUS GetVolumeChannelCount
    (
        _Out_  UINT32 * pulChannelCount
    );
     
    NTSTATUS GetVolumeSteppings
    (
        _Out_writes_bytes_(_ui32DataSize)  PKSPROPERTY_STEPPING_LONG _pKsPropStepLong,
        _In_  UINT32    _ui32DataSize
    );
     
    NTSTATUS GetChannelVolume
    (
        _In_  UINT32    _uiChannel,
        _Out_  LONG *   _pVolume
    );
     
    NTSTATUS SetChannelVolume
    (
        _In_  UINT32    _uiChannel,
        _In_  LONG      _Volume
    );
 
    //-----------------------------------------------------------------------------
    // metering
    //-----------------------------------------------------------------------------
    NTSTATUS GetPeakMeterChannelCount
    (
        _Out_  UINT32 * pulChannelCount
    );
     
    NTSTATUS GetPeakMeterSteppings
    (
        _Out_writes_bytes_(_ui32DataSize)  PKSPROPERTY_STEPPING_LONG _pKsPropStepLong,
        _In_  UINT32    _ui32DataSize
    );
     
    NTSTATUS GetChannelPeakMeter
    (
        _In_  UINT32    _uiChannel,
        _Out_  LONG *   _plPeakMeter
    );
 
    //-----------------------------------------------------------------------------
    // mute
    //-----------------------------------------------------------------------------
    NTSTATUS GetMuteChannelCount
    (
        _Out_  UINT32 * pulChannelCount
    );
     
    NTSTATUS GetMuteSteppings
    (
        _Out_writes_bytes_(_ui32DataSize)  PKSPROPERTY_STEPPING_LONG _pKsPropStepLong,
        _In_  UINT32    _ui32DataSize
    );
     
    NTSTATUS GetChannelMute
    (
        _In_  UINT32    _uiChannel,
        _Out_  BOOL *   _pbMute
    );
     
    NTSTATUS SetChannelMute
    (
        _In_  UINT32    _uiChannel,
        _In_  BOOL      _bMute
    );
 
private:
    //-----------------------------------------------------------------------------
    // Supported formats index array:
    //
    // capture endpoint:
    // [0] Pin 1 - wave source.
    //
    // render endpoints:
    // [0] Audio-engine device formats.
    // [1] Pin 0 - Host
    // [2] Pin 1 - Offload
    // [3] Pin 2 - Loopback
    //
    KSDATAFORMAT_WAVEFORMATEXTENSIBLE * GetCapturePinSupportedDeviceFormats()
    {
        ASSERT(m_DeviceFormatsAndModesCount > CAPTURE_DEVICE_FORMATS);
        ASSERT(m_DeviceFormatsAndModes[CAPTURE_DEVICE_FORMATS].WaveFormats != NULL);
        ASSERT(GetCapturePinSupportedDeviceFormatsCount() > 0);
         
        return m_DeviceFormatsAndModes[CAPTURE_DEVICE_FORMATS].WaveFormats;
    }
     
    ULONG GetCapturePinSupportedDeviceFormatsCount()
    {
        ASSERT(m_DeviceFormatsAndModesCount > CAPTURE_DEVICE_FORMATS);
         
        return m_DeviceFormatsAndModes[CAPTURE_DEVICE_FORMATS].WaveFormatsCount;
    }
     
    KSDATAFORMAT_WAVEFORMATEXTENSIBLE * GetAudioEngineSupportedDeviceFormats()
    {
        ASSERT(m_DeviceFormatsAndModesCount > AUDIO_DEVICE_FORMATS);
        ASSERT(m_DeviceFormatsAndModes[AUDIO_DEVICE_FORMATS].WaveFormats != NULL);
        ASSERT(GetAudioEngineSupportedDeviceFormatsCount() > 0);
         
        return m_DeviceFormatsAndModes[AUDIO_DEVICE_FORMATS].WaveFormats;
    }
     
    ULONG GetAudioEngineSupportedDeviceFormatsCount()
    {
        ASSERT(m_DeviceFormatsAndModesCount > AUDIO_DEVICE_FORMATS);
        return m_DeviceFormatsAndModes[AUDIO_DEVICE_FORMATS].WaveFormatsCount;
    }
     
    KSDATAFORMAT_WAVEFORMATEXTENSIBLE * GetHostPinSupportedDeviceFormats()
    {
        ASSERT(m_DeviceFormatsAndModesCount > HOST_DEVICE_FORMATS);
        ASSERT(m_DeviceFormatsAndModes[HOST_DEVICE_FORMATS].WaveFormats != NULL);
        ASSERT(GetHostPinSupportedDeviceFormatsCount() > 0);
         
        return m_DeviceFormatsAndModes[HOST_DEVICE_FORMATS].WaveFormats;
    }
         
    ULONG GetHostPinSupportedDeviceFormatsCount()
    {
        ASSERT(m_DeviceFormatsAndModesCount > HOST_DEVICE_FORMATS);
         
        return m_DeviceFormatsAndModes[HOST_DEVICE_FORMATS].WaveFormatsCount;
    }
     
    KSDATAFORMAT_WAVEFORMATEXTENSIBLE * GetOffloadPinSupportedDeviceFormats()
    {
        ASSERT(m_DeviceFormatsAndModesCount > OFFLOAD_DEVICE_FORMATS);
        ASSERT(m_DeviceFormatsAndModes[OFFLOAD_DEVICE_FORMATS].WaveFormats != NULL);
        ASSERT(GetOffloadPinSupportedDeviceFormatsCount() > 0);
         
        return m_DeviceFormatsAndModes[OFFLOAD_DEVICE_FORMATS].WaveFormats;
    }
         
    ULONG GetOffloadPinSupportedDeviceFormatsCount()
    {
        ASSERT(m_DeviceFormatsAndModesCount > OFFLOAD_DEVICE_FORMATS);
         
        return m_DeviceFormatsAndModes[OFFLOAD_DEVICE_FORMATS].WaveFormatsCount;
    }
     
    KSDATAFORMAT_WAVEFORMATEXTENSIBLE * GetLoopbackPinSupportedDeviceFormats()
    {
        ASSERT(m_DeviceFormatsAndModesCount > LOOPBACK_DEVICE_FORMATS);
        ASSERT(m_DeviceFormatsAndModes[LOOPBACK_DEVICE_FORMATS].WaveFormats != NULL);
        ASSERT(GetLoopbackPinSupportedDeviceFormatsCount() > 0);
         
        return m_DeviceFormatsAndModes[LOOPBACK_DEVICE_FORMATS].WaveFormats;
    }
         
    ULONG GetLoopbackPinSupportedDeviceFormatsCount()
    {
        ASSERT(m_DeviceFormatsAndModesCount > LOOPBACK_DEVICE_FORMATS);
         
        return m_DeviceFormatsAndModes[LOOPBACK_DEVICE_FORMATS].WaveFormatsCount;
    }
     
    //-----------------------------------------------------------------------------
    // Supported modes index array:
    //
    // capture endpoint:
    // [0] Pin 1 - wave source.
    //
    // render endpoints:
    // [0] Audio-engine device formats - no support
    // [1] Pin 0 - Host
    // [2] Pin 1 - Offload
    // [3] Pin 2 - Loopback - no support
    //
    MODE_AND_DEFAULT_FORMAT * GetCapturePinSupportedDeviceModes()
    {
        ASSERT(m_DeviceFormatsAndModesCount > CAPTURE_DEVICE_FORMATS);
        ASSERT(GetCapturePinSupportedDeviceModesCount() > 0);
         
#ifdef SYSVAD_BTH_BYPASS
        if (m_DeviceType == eBthHfpMicDevice)
        {
            ASSERT(m_BthHfpDevice != NULL);
            if (m_BthHfpDevice->IsNRECSupported())
            {
                return BthHfpMicPinSupportedDeviceModesNrec;
            }
            else
            {
                return BthHfpMicPinSupportedDeviceModesNoNrec;
            }
        }
#endif // SYSVAD_BTH_BYPASS
         
        ASSERT(m_DeviceFormatsAndModes[CAPTURE_DEVICE_FORMATS].ModeAndDefaultFormat != NULL);
        return m_DeviceFormatsAndModes[CAPTURE_DEVICE_FORMATS].ModeAndDefaultFormat;
    }
     
    ULONG GetCapturePinSupportedDeviceModesCount()
    {
        ASSERT(m_DeviceFormatsAndModesCount > CAPTURE_DEVICE_FORMATS);
         
#ifdef SYSVAD_BTH_BYPASS
        if (m_DeviceType == eBthHfpMicDevice)
        {
            ASSERT(m_BthHfpDevice != NULL);
            if (m_BthHfpDevice->IsNRECSupported())
            {
                return SIZEOF_ARRAY(BthHfpMicPinSupportedDeviceModesNrec);
            }
            else
            {
                return SIZEOF_ARRAY(BthHfpMicPinSupportedDeviceModesNoNrec);
            }
        }
#endif // SYSVAD_BTH_BYPASS
         
        return m_DeviceFormatsAndModes[CAPTURE_DEVICE_FORMATS].ModeAndDefaultFormatCount;
    }
     
    MODE_AND_DEFAULT_FORMAT * GetHostPinSupportedDeviceModes()
    {
        ASSERT(m_DeviceFormatsAndModesCount > HOST_DEVICE_FORMATS);
        ASSERT(m_DeviceFormatsAndModes[HOST_DEVICE_FORMATS].ModeAndDefaultFormat != NULL);
        ASSERT(GetHostPinSupportedDeviceModesCount() > 0);
         
        return m_DeviceFormatsAndModes[HOST_DEVICE_FORMATS].ModeAndDefaultFormat;
    }
         
    ULONG GetHostPinSupportedDeviceModesCount()
    {
        ASSERT(m_DeviceFormatsAndModesCount > HOST_DEVICE_FORMATS);
         
        return m_DeviceFormatsAndModes[HOST_DEVICE_FORMATS].ModeAndDefaultFormatCount;
    }
     
    MODE_AND_DEFAULT_FORMAT * GetOffloadPinSupportedDeviceModes()
    {
        ASSERT(m_DeviceFormatsAndModesCount > OFFLOAD_DEVICE_FORMATS);
        ASSERT(m_DeviceFormatsAndModes[OFFLOAD_DEVICE_FORMATS].ModeAndDefaultFormat != NULL);
        ASSERT(GetOffloadPinSupportedDeviceModesCount() > 0);
         
        return m_DeviceFormatsAndModes[OFFLOAD_DEVICE_FORMATS].ModeAndDefaultFormat;
    }
         
    ULONG GetOffloadPinSupportedDeviceModesCount()
    {
        ASSERT(m_DeviceFormatsAndModesCount > OFFLOAD_DEVICE_FORMATS);
         
        return m_DeviceFormatsAndModes[OFFLOAD_DEVICE_FORMATS].ModeAndDefaultFormatCount;
    }
     
    BOOL IsRenderDevice()
    {
        return (m_DeviceType == eSpeakerDevice   ||
                m_DeviceType == eSpeakerHpDevice ||
                m_DeviceType == eHdmiDevice      ||
                m_DeviceType == eBthHfpSpeakerDevice) ? TRUE : FALSE;
    }
 
    BOOL IsOffloadSupported()
    {
        return (m_DeviceFlags & ENDPOINT_OFFLOAD_SUPPORTED) ? TRUE : FALSE;
    }
 
    ULONG GetSystemPinId()
    {
        ASSERT(IsRenderDevice());
        return IsOffloadSupported() ? KSPIN_WAVE_RENDER_SINK_SYSTEM : KSPIN_WAVE_RENDER2_SINK_SYSTEM;
    }
     
    ULONG GetLoopbackPinId()
    {
        ASSERT(IsRenderDevice());
        return IsOffloadSupported() ? KSPIN_WAVE_RENDER_SINK_LOOPBACK : KSPIN_WAVE_RENDER2_SINK_LOOPBACK;
    }
     
    ULONG GetOffloadPinId()
    {
        ASSERT(IsRenderDevice());
        ASSERT(IsOffloadSupported());
         
        return KSPIN_WAVE_RENDER_SINK_OFFLOAD;
    }
 
    ULONG GetSourcePinId()
    {
        ASSERT(IsRenderDevice());
        return IsOffloadSupported() ? KSPIN_WAVE_RENDER_SOURCE : KSPIN_WAVE_RENDER2_SOURCE;
    }
 
#ifdef SYSVAD_BTH_BYPASS
public:
    BOOL IsBthHfpDevice()
    {
        return (m_DeviceType == eBthHfpMicDevice ||
                m_DeviceType == eBthHfpSpeakerDevice) ? TRUE : FALSE;
    }
 
    // Returns a weak ref to the Bluetooth HFP device.
    PBTHHFPDEVICECOMMON GetBthHfpDevice()
    {
        PBTHHFPDEVICECOMMON bthHfpDevice = NULL;
         
        if (IsBthHfpDevice())
        {
            if (m_BthHfpDevice != NULL)
            {
                bthHfpDevice = m_BthHfpDevice;
            }
        }
     
        return bthHfpDevice;
    }
#endif // SYSVAD_BTH_BYPASS
};
typedef CMiniportWaveRT *PCMiniportWaveRT;
 
#endif // _SYSVAD_MINWAVERT_H_

Our Services

  • What our customers say about us?

© 2011-2025 All Rights Reserved. Joya Systems. 4425 South Mopac Building II Suite 101 Austin, TX 78735 Tel: 800-DEV-KERNEL

Privacy Policy. Terms of use. Valid XHTML & CSS