summaryrefslogtreecommitdiff
path: root/audio/SoundWire/Samples/SdcaVad/SdcaVDsp/private.h
blob: 065b337586201d655270848bb633d32333ad92da (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
/*++

Copyright (c) Microsoft Corporation.  All rights reserved.

    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
    PURPOSE.

Module Name:

    private.h

Abstract:

    Contains structure definitions and function prototypes private to
    the driver.

Environment:

    Kernel mode

Notes:

    Workarounds:

    ACX_WORKAROUND_ACXFACTORYCIRCUIT_01
    enables the logic to workaround an ACX v1.0 issue related to ACXFACTORYCIRCUIT race with Add/Remove child WDFDEVICE.
    this issue has been fixed in ACX v1.1.

    ACX_WORKAROUND_ACXPIN_01
    enables the logic to workaround an ACX v1.0 issue related to ACXPIN's KSPROPERTY_PIN_CINSTANCES to return the pin's
    stream instances vs. returning the total # of streams on a circuit. This # is not the same when circuit supports an
    audio engine node, and client has instantiated streams on several pins (host/loopback/offload).
    this issue has been fixed in ACX v1.1.

    ACX_WORKAROUND_ACXPIN_02
    enables the logic to workaround an ACX v1.1 issue related to ACXPIN's KSPROPERTY_PIN_PROPOSEDATAFORMAT set requests 
    directed to an 'offload' pin of an audio engine. The workaround fails the request if there are no enough resources
    (streams). ACX will be enhanced in the future to automatically check this when the pin is tagged as 'offload' pin.
    ACX_WORKAROUND_ACXPIN_01 must be enabled as well for ACX_WORKAROUND_ACXPIN_02 to work.

--*/

#ifndef _PRIVATE_H_
#define _PRIVATE_H_

#include "cpp_utils.h"

#include "stdunk.h"
#include <mmsystem.h>
#include <ks.h>
#include <ksmedia.h>

#include "NewDelete.h"

/* make prototypes usable from C++ */
#ifdef __cplusplus
extern "C" {
#endif

#pragma warning(disable:4200)  //
#pragma warning(disable:4201)  // nameless struct/union
#pragma warning(disable:4214)  // bit field types other than int

#include <initguid.h>
#include <ntddk.h>
#include <ntstrsafe.h>
#include <ntintsafe.h>
#include <TestProperties.h>

#pragma warning(default:4200)
#pragma warning(default:4201)
#pragma warning(default:4214)

#include <wdf.h>
#include <acx.h>

#include "AudioAggregation.h"
#include "soundwirecontroller.h"
#include "sdcastreaming.h"

#include "trace.h"

#define PAGED_CODE_SEG __declspec(code_seg("PAGE"))
#define INIT_CODE_SEG __declspec(code_seg("INIT"))

extern RECORDER_LOG g_SDCAVDspLog;

// Check for workaround dependencies.
#ifdef ACX_WORKAROUND_ACXPIN_02
    #ifndef ACX_WORKAROUND_ACXPIN_01
        #error ACX_WORKAROUND_ACXPIN_02 requires ACX_WORKAROUND_ACXPIN_01.
    #endif
#endif

// Copied from cfgmgr32.h
#if !defined(MAX_DEVICE_ID_LEN)
#define MAX_DEVICE_ID_LEN 200
#endif

// Define a NULL GUID if not already defined.
#if !defined(NULL_GUID)
#define NULL_GUID { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }
#endif

// SDCA Sample driver

#define DRIVER_TAG (ULONG) 'Dcds'

// Number of millisecs per sec. 
#define MS_PER_SEC 1000

// Number of hundred nanosecs per sec. 
#define HNS_PER_SEC 10000000

// Compatible ID for render/capture
#define ACX_DSP_RENDER_COMPATIBLE_ID   L"{ad164f4d-4149-41ed-82e8-99732ed7371a}"

// Container ID for render/capture
#define ACX_DSP_SYSTEM_CONTAINER_ID    L"{00000000-0000-0000-ffff-ffffffffffff}"


// Compatible ID for render/capture
#define ACX_DSP_TEST_COMPATIBLE_ID   L"{ad164f4d-4149-41ed-82e8-99732ed7371a}"
// Container ID for render/capture
#define ACX_DSP_TEST_CONTAINER_ID    L"{00000000-0000-0000-ffff-ffffffffffff}"

extern const GUID DSP_CIRCUIT_SPEAKER_GUID;
extern const GUID DSP_CIRCUIT_MICROPHONE_GUID;
extern const GUID DSP_CIRCUIT_UNIVERSALJACK_RENDER_GUID;
extern const GUID DSP_CIRCUIT_UNIVERSALJACK_CAPTURE_GUID;

extern const GUID SYSTEM_CONTAINER_GUID;

#undef MIN
#undef MAX
#define MIN(a,b) ((a) > (b) ? (b) : (a))
#define MAX(a,b) ((a) > (b) ? (a) : (b))

#define REQUEST_TIMEOUT_SECONDS 5

#ifndef SIZEOF_ARRAY
#define SIZEOF_ARRAY(ar)        (sizeof(ar)/sizeof((ar)[0]))
#endif // !defined(SIZEOF_ARRAY)

//
// Define DSP driver context.
//
typedef struct _DSP_DRIVER_CONTEXT {
    BOOLEAN         Dummy;
} DSP_DRIVER_CONTEXT, *PDSP_DRIVER_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_DRIVER_CONTEXT, GetDspDriverContext)

#define ALL_CHANNELS_ID             UINT32_MAX
#define MAX_CHANNELS                2
#define CHANNEL_MASK_INVALID        UINT32_MAX
    
//
// Define DSP device context.
//
typedef struct _DSP_DEVICE_CONTEXT {
    ACXCIRCUIT          Render;
    ACXCIRCUIT          Capture;
    ACXFACTORYCIRCUIT   Factory;
    WDFDEVICE           AudioSensorsDevice;
    WDFCHILDLIST        ChildList;
} DSP_DEVICE_CONTEXT, *PDSP_DEVICE_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_DEVICE_CONTEXT, GetDspDeviceContext)

//
// Define Audio Sensors device context.
//
typedef struct _AUDIO_SENSORS_DEVICE_CONTEXT
{
    WDFDEVICE           Device;
} AUDIO_SENSORS_DEVICE_CONTEXT, *PAUDIO_SENSORS_DEVICE_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(AUDIO_SENSORS_DEVICE_CONTEXT, GetAudioSensorsDeviceContext)

//
// Define DSP factory context.
//
typedef struct _DSP_FACTORY_CONTEXT {
    WDFDEVICE           Device;
#ifdef ACX_WORKAROUND_ACXFACTORYCIRCUIT_01
    WDFWAITLOCK         CacheLock;
    WDFCOLLECTION       Cache;
#endif
} DSP_FACTORY_CONTEXT, *PDSP_FACTORY_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_FACTORY_CONTEXT, GetDspFactoryContext)

#ifdef ACX_WORKAROUND_ACXFACTORYCIRCUIT_01
//
// Define DSP device ID context.
//
typedef struct _DSP_DEVICEID_CONTEXT {
    ACXFACTORYCIRCUIT   Factory;
    GUID                UniqueID;
} DSP_DEVICEID_CONTEXT, *PDSP_DEVICEID_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_DEVICEID_CONTEXT, GetDspDeviceIdContext)
#endif // ACX_WORKAROUND_ACXFACTORYCIRCUIT_01

//
// Define RENDER device context.
//
typedef struct _DSP_RENDER_DEVICE_CONTEXT {
    ACXCIRCUIT          Circuit;
    BOOLEAN             FirstTimePrepareHardware;
} DSP_RENDER_DEVICE_CONTEXT, *PDSP_RENDER_DEVICE_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_RENDER_DEVICE_CONTEXT, GetRenderDeviceContext)

// Special stream definitions
typedef enum _SDCA_SPECIALSTREAM_TYPE
{
    SpecialStreamTypeNotSupported           = 0,
    SpecialStreamTypeUltrasoundRender       = 1,
    SpecialStreamTypeUltrasoundCapture      = 2,
    SpecialStreamTypeReferenceStream        = 3,
    SpecialStreamTypeIvSense                = 4,
    SpecialStreamType_Count                 = 5,
} SDCA_SPECIALSTREAM_TYPE, *PSDCA_SPECIALSTREAM_TYPE;

inline const SDCA_SPECIALSTREAM_TYPE SpecialStreamTypeFromSdcaPath(SDCA_PATH path)
{
    switch(path)
    {
        case SdcaPathUltrasoundRender:
            return SpecialStreamTypeUltrasoundRender;
        case SdcaPathUltrasoundCapture:
            return SpecialStreamTypeUltrasoundCapture;
        case SdcaPathReferenceStream:
            return SpecialStreamTypeReferenceStream;
        case SdcaPathIvSense:
            return SpecialStreamTypeIvSense;
    }
    return SpecialStreamTypeNotSupported;
}

inline const SDCA_PATH SdcaPathFromSpecialStreamType(SDCA_SPECIALSTREAM_TYPE type)
{
    switch(type)
    {
        case SpecialStreamTypeUltrasoundRender:
            return SdcaPathUltrasoundRender;
        case SpecialStreamTypeUltrasoundCapture:
            return SdcaPathUltrasoundCapture;
        case SpecialStreamTypeReferenceStream:
            return SdcaPathReferenceStream;
        case SpecialStreamTypeIvSense:
            return SdcaPathIvSense;
    }
    return (SDCA_PATH) 0;
}

// Maximum of 8 devices chosen for the purpose of making this sample simpler
#define MAX_AGGREGATED_DEVICES (8)

//
// Define circuit context.
//
typedef struct _DSP_CIRCUIT_CONTEXT {
    ULONG               EndpointId;
    ULONG               DataPortNumber;
    ACXAUDIOENGINE      AudioEngineElement;
    ACXPEAKMETER        PeakMeterElement;
    PVOID               peakMeter;
    ACXKEYWORDSPOTTER   KeywordSpotter;

    // If the VolumeMuteHandler is set, we will forward any
    // Volume/Mute requests for the current circuit to this
    // target circuit. If the target circuit was allocated
    // by this driver, it will also be copied to
    // TargetCircuitToDelete
    ACXTARGETCIRCUIT    TargetCircuitToDelete;
    ACXTARGETCIRCUIT    TargetVolumeMuteCircuit;
    ACXTARGETELEMENT    TargetVolumeHandler;
    ACXTARGETELEMENT    TargetMuteHandler;

    BOOLEAN             IsRenderCircuit;

    // This will contain information on the aggregated devices we're connected to
    BOOLEAN                         Aggregated;
    ULONG                           AggregatedDeviceCount;
    SDCA_AGGREGATION_DEVICE         AggregatedDevices[MAX_AGGREGATED_DEVICES];
    PSDCA_PATH_DESCRIPTORS2         AggregatedPathDescriptors;

    ULONG                           SpecialStreamAvailablePaths;
    PSDCA_PATH_DESCRIPTORS          SpecialStreamPathDescriptors[SpecialStreamType_Count];
    PSDCA_PATH_DESCRIPTORS2         SpecialStreamPathDescriptors2[SpecialStreamType_Count];
    ULONG                           SpecialStreamActive[SpecialStreamType_Count];
    ULONG                           SpecialStreamRunning[SpecialStreamType_Count];
    ACXTARGETCIRCUIT                SpecialStreamTargetCircuit;
    // The ConnectedFunctionInformation will be used with SpecialStream logic and also
    // for determining appropriate data ports to be used with each connected audio function
    PSDCA_FUNCTION_INFORMATION_LIST ConnectedFunctionInformation;

} DSP_CIRCUIT_CONTEXT, * PDSP_CIRCUIT_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_CIRCUIT_CONTEXT, GetDspCircuitContext)

//
// Define CAPTURE device context.
//
typedef struct _DSP_CAPTURE_DEVICE_CONTEXT {
    ACXCIRCUIT      Circuit;
    BOOLEAN         FirstTimePrepareHardware;
} DSP_CAPTURE_DEVICE_CONTEXT, *PDSP_CAPTURE_DEVICE_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_CAPTURE_DEVICE_CONTEXT, GetCaptureDeviceContext)

//
// Define DSP circuit/stream element context.
//
typedef struct _DSP_ELEMENT_CONTEXT {
    BOOLEAN         Dummy;
} DSP_ELEMENT_CONTEXT, *PDSP_ELEMENT_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_ELEMENT_CONTEXT, GetDspElementContext)

//
// Define DSP format context.
//
typedef struct _DSP_FORMAT_CONTEXT {
    BOOLEAN         Dummy;
} DSP_FORMAT_CONTEXT, *PDSP_FORMAT_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_FORMAT_CONTEXT, GetDspFormatContext)

typedef enum _DSP_PIN_TYPE {
    DspPinTypeHost,
    DspPinTypeOffload,
    DspPinTypeLoopback,
    DspPinTypeBridge,
    DspPinType_Count
} DSP_PIN_TYPE, * PDSP_PIN_TYPE;

typedef enum _DSP_CAPTURE_PIN_TYPE {
    DspCapturePinTypeHost,
    DspCapturePinTypeKeyword,
    DspCapturePinTypeBridge,
    DspCapturePinType_Count
} DSP_CAPTURE_PIN_TYPE, * PDSP_CAPTURE_PIN_TYPE;

typedef struct _DSP_PIN_CONTEXT {
    ACXTARGETCIRCUIT        TargetCircuit;
    ULONG                   TargetPinId;
    DSP_PIN_TYPE            PinType;
    DSP_CAPTURE_PIN_TYPE    CapturePinType;

    // The stream bridge below will only be valid for the Capture circuit Bridge Pin

    // Host stream bridge will be used to ensure host stream creations are passed
    // to the downlevel circuits. Since the HostStreamBridge won't have InModes set,
    // the ACX framework will not add streams automatically. We will add streams for
    // non KWS pin.
    ACXSTREAMBRIDGE         HostStreamBridge;
    ACXOBJECTBAG            HostStreamObjBag;

#ifdef ACX_WORKAROUND_ACXPIN_01
    ULONG                   MaxStreams;
    ULONG                   CurrentStreamsCount;
#endif
} DSP_PIN_CONTEXT, *PDSP_PIN_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_PIN_CONTEXT, GetDspPinContext)

//
// Define DSP render/capture stream context.
//
typedef struct _DSP_STREAM_CONTEXT {
    PVOID                   StreamEngine;
    DSP_PIN_TYPE            PinType;
    DSP_CAPTURE_PIN_TYPE    CapturePinType;
    ACXPIN                  Pin;                // used by acx workaround, and reference streams

#ifdef ACX_WORKAROUND_ACXPIN_01
    BOOLEAN                 StreamIsCounted;    // TRUE = stream is counted on the pin.
#endif

    ACXTARGETCIRCUIT        SpecialStreamTargetCircuit;
    BOOLEAN                 SpecialStreamInUse[SpecialStreamType_Count];
    BOOLEAN                 SpecialStreamRunning[SpecialStreamType_Count];
} DSP_STREAM_CONTEXT, *PDSP_STREAM_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_STREAM_CONTEXT, GetDspStreamContext)

typedef struct _DSP_ENGINE_CONTEXT {
    ACXDATAFORMAT   MixFormat;
    BOOLEAN         GFxEnabled;
} DSP_ENGINE_CONTEXT, * PDSP_ENGINE_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_ENGINE_CONTEXT, GetDspEngineContext)

typedef struct _DSP_STREAMAUDIOENGINE_CONTEXT {
    BOOLEAN         LFxEnabled;
} DSP_STREAMAUDIOENGINE_CONTEXT, * PDSP_STREAMAUDIOENGINE_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_STREAMAUDIOENGINE_CONTEXT, GetDspStreamAudioEngineContext)

//
// Define DSP keyword spotter context
//
typedef struct _DSP_KEYWORDSPOTTER_CONTEXT {
    ACXPNPEVENT Event;
    PVOID       KeywordDetector;
} DSP_KEYWORDSPOTTER_CONTEXT, *PDSP_KEYWORDSPOTTER_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_KEYWORDSPOTTER_CONTEXT, GetDspKeywordSpotterContext)

typedef struct _DSP_PNPEVENT_CONTEXT {
    BOOLEAN         Dummy;
} DSP_PNPEVENT_CONTEXT, *PDSP_PNPEVENT_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_PNPEVENT_CONTEXT, GetDspPnpEventContext)

//
// Define DSP peakmeter element context.
//
typedef struct _DSP_PEAKMETER_ELEMENT_CONTEXT {
    PVOID           peakMeter;
} DSP_PEAKMETER_ELEMENT_CONTEXT, * PDSP_PEAKMETER_ELEMENT_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_PEAKMETER_ELEMENT_CONTEXT, GetDspPeakMeterElementContext)

#define PEAKMETER_STEPPING_DELTA    0x1000
#define PEAKMETER_MAXIMUM           LONG_MAX
#define PEAKMETER_MINIMUM           LONG_MIN

//
// Define DSP circuit/stream element context.
//
typedef struct _DSP_MUTE_ELEMENT_CONTEXT {
    BOOL            MuteState[MAX_CHANNELS];
} DSP_MUTE_ELEMENT_CONTEXT, * PDSP_MUTE_ELEMENT_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_MUTE_ELEMENT_CONTEXT, GetDspMuteElementContext)

//
// Define DSP circuit/stream element context.
//
typedef struct _DSP_VOLUME_ELEMENT_CONTEXT {
    LONG            VolumeLevel[MAX_CHANNELS];
} DSP_VOLUME_ELEMENT_CONTEXT, * PDSP_VOLUME_ELEMENT_CONTEXT;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DSP_VOLUME_ELEMENT_CONTEXT, GetDspVolumeElementContext)

#define VOLUME_STEPPING         0x8000
#define VOLUME_LEVEL_MAXIMUM    0x00000000
#define VOLUME_LEVEL_MINIMUM    (-96 * 0x10000)

//
// Driver prototypes.
//
DRIVER_INITIALIZE                   DriverEntry;
EVT_WDF_DRIVER_UNLOAD               Dsp_DriverUnload;
EVT_WDF_DRIVER_DEVICE_ADD           Dsp_EvtBusDeviceAdd;
EVT_WDF_CHILD_LIST_CREATE_DEVICE    Dsp_AddAudioSensorsDevice;

// Device callbacks.

EVT_WDF_DEVICE_PREPARE_HARDWARE     Dsp_EvtDevicePrepareHardware;
EVT_WDF_DEVICE_RELEASE_HARDWARE     Dsp_EvtDeviceReleaseHardware;
EVT_WDF_DEVICE_CONTEXT_CLEANUP      Dsp_EvtDeviceContextCleanup;

EVT_ACX_FACTORY_CIRCUIT_CREATE_CIRCUITDEVICE Dsp_EvtAcxFactoryCircuitCreateCircuitDevice;
EVT_ACX_FACTORY_CIRCUIT_CREATE_CIRCUIT Dsp_EvtAcxFactoryCircuitCreateCircuit;
EVT_WDF_DEVICE_CONTEXT_CLEANUP      Dsp_EvtFactoryContextCleanup;
EVT_WDF_DEVICE_CONTEXT_DESTROY      Dsp_EvtFactoryContextDestroy;

// Stream callbacks shared between Capture and Render

EVT_WDF_OBJECT_CONTEXT_DESTROY      Dsp_EvtStreamContextDestroy;
EVT_ACX_STREAM_GET_HW_LATENCY       Dsp_EvtStreamGetHwLatency;
EVT_ACX_STREAM_ALLOCATE_RTPACKETS   Dsp_EvtStreamAllocateRtPackets;
EVT_ACX_STREAM_FREE_RTPACKETS       Dsp_EvtStreamFreeRtPackets;
EVT_ACX_STREAM_PREPARE_HARDWARE     Dsp_EvtStreamPrepareHardware;
EVT_ACX_STREAM_RELEASE_HARDWARE     Dsp_EvtStreamReleaseHardware;
EVT_ACX_STREAM_RUN                  Dsp_EvtStreamRun;
EVT_ACX_STREAM_PAUSE                Dsp_EvtStreamPause;
EVT_ACX_STREAM_GET_CURRENT_PACKET   Dsp_EvtStreamGetCurrentPacket;
EVT_ACX_STREAM_ASSIGN_DRM_CONTENT_ID Dsp_EvtStreamAssignDrmContentId;
EVT_ACX_STREAM_GET_PRESENTATION_POSITION Dsp_EvtStreamGetPresentationPosition;
EVT_ACX_OBJECT_PREPROCESS_REQUEST DspC_EvtStreamRequestPreprocess;


// Render callbacks.
EVT_ACX_FACTORY_CIRCUIT_CREATE_CIRCUITDEVICE DspR_EvtAcxFactoryCircuitCreateCircuitDevice;

_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
NTAPI
DspR_EvtAcxFactoryCircuitCreateCircuit(
    _In_
    WDFDEVICE Parent,
    _In_
    WDFDEVICE Device,
    _In_
    ACXFACTORYCIRCUIT Factory,
    _In_
    PACX_FACTORY_CIRCUIT_ADD_CIRCUIT Config,
    _In_
    PACXCIRCUIT_INIT CircuitInit,
    _In_
    ULONG DataPortNumber,
    _In_opt_
    PSDCA_PATH_DESCRIPTORS2        PathDescriptors
);
    
EVT_ACX_CIRCUIT_COMPOSITE_CIRCUIT_INITIALIZE DspR_EvtCircuitCompositeCircuitInitialize;
EVT_ACX_CIRCUIT_COMPOSITE_INITIALIZE DspR_EvtCircuitCompositeInitialize;
    
EVT_WDF_DEVICE_CONTEXT_CLEANUP      DspR_EvtCircuitContextCleanup;
EVT_WDF_DEVICE_PREPARE_HARDWARE     DspR_EvtDevicePrepareHardware;
EVT_WDF_DEVICE_RELEASE_HARDWARE     DspR_EvtDeviceReleaseHardware;
EVT_WDF_DEVICE_SELF_MANAGED_IO_INIT DspR_EvtDeviceSelfManagedIoInit;
EVT_WDF_DEVICE_CONTEXT_CLEANUP      DspR_EvtDeviceContextCleanup;
EVT_ACX_OBJECT_PREPROCESS_REQUEST   DspR_EvtCircuitRequestPreprocess;
EVT_ACX_CIRCUIT_CREATE_STREAM       DspR_EvtCircuitCreateStream;
EVT_ACX_CIRCUIT_POWER_UP            DspR_EvtCircuitPowerUp;
EVT_ACX_CIRCUIT_POWER_DOWN          DspR_EvtCircuitPowerDown;
EVT_ACX_STREAM_SET_RENDER_PACKET    DspR_EvtStreamSetRenderPacket;
EVT_ACX_PIN_SET_DATAFORMAT          DspR_EvtAcxPinSetDataFormat;
EVT_WDF_DEVICE_CONTEXT_CLEANUP      DspR_EvtPinContextCleanup;
EVT_ACX_PIN_CONNECTED               DspR_EvtPinConnected;
EVT_ACX_PIN_DISCONNECTED            DspR_EvtPinDisconnected;

//Render Audio Engine
EVT_ACX_MUTE_ASSIGN_STATE                                   DspR_EvtMuteAssignState;
EVT_ACX_MUTE_RETRIEVE_STATE                                 DspR_EvtMuteRetrieveState;
EVT_ACX_VOLUME_ASSIGN_LEVEL                                 DspR_EvtVolumeAssignLevel;
EVT_ACX_VOLUME_RETRIEVE_LEVEL                               DspR_EvtVolumeRetrieveLevel;
EVT_ACX_PEAKMETER_RETRIEVE_LEVEL                            DspR_EvtPeakMeterRetrieveLevelCallback;
EVT_ACX_RAMPED_VOLUME_ASSIGN_LEVEL                          DspR_EvtRampedVolumeAssignLevel;
EVT_ACX_AUDIOENGINE_RETRIEVE_BUFFER_SIZE_LIMITS             DspR_EvtAcxAudioEngineRetrieveBufferSizeLimits;
EVT_ACX_AUDIOENGINE_RETRIEVE_EFFECTS_STATE                  DspR_EvtAcxAudioEngineRetrieveEffectsState;
EVT_ACX_AUDIOENGINE_ASSIGN_EFFECTS_STATE                    DspR_EvtAcxAudioEngineAssignEffectsState;
EVT_ACX_AUDIOENGINE_RETRIEVE_ENGINE_FORMAT                  DspR_EvtAcxAudioEngineRetrieveEngineMixFormat;
EVT_ACX_AUDIOENGINE_ASSIGN_ENGINE_FORMAT                    DspR_EvtAcxAudioEngineAssignEngineDeviceFormat;
EVT_ACX_STREAMAUDIOENGINE_RETRIEVE_EFFECTS_STATE            DspR_EvtAcxStreamAudioEngineRetrieveEffectsState;
EVT_ACX_STREAMAUDIOENGINE_ASSIGN_EFFECTS_STATE              DspR_EvtAcxStreamAudioEngineAssignEffectsState;
EVT_ACX_STREAMAUDIOENGINE_RETRIEVE_PRESENTATION_POSITION    DspR_EvtAcxStreamAudioEngineRetrievePresentationPosition;
EVT_ACX_STREAMAUDIOENGINE_ASSIGN_CURRENT_WRITE_POSITION     DspR_EvtAcxStreamAudioEngineAssignCurrentWritePosition;
EVT_ACX_STREAMAUDIOENGINE_RETRIEVE_LINEAR_BUFFER_POSITION   DspR_EvtAcxStreamAudioEngineRetrieveLinearBufferPosition;
EVT_ACX_STREAMAUDIOENGINE_ASSIGN_LAST_BUFFER_POSITION       DspR_EvtAcxStreamAudioEngineAssignLastBufferPosition;
EVT_ACX_STREAMAUDIOENGINE_ASSIGN_LOOPBACK_PROTECTION        DspR_EvtAcxStreamAudioEngineAssignLoopbackProtection;

// Capture callbacks.
EVT_ACX_FACTORY_CIRCUIT_CREATE_CIRCUITDEVICE DspC_EvtAcxFactoryCircuitCreateCircuitDevice;

_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
NTAPI
DspC_EvtAcxFactoryCircuitCreateCircuit(
    _In_
    WDFDEVICE Parent,
    _In_
    WDFDEVICE Device,
    _In_
    ACXFACTORYCIRCUIT Factory,
    _In_
    PACX_FACTORY_CIRCUIT_ADD_CIRCUIT Config,
    _In_
    PACXCIRCUIT_INIT CircuitInit,
    _In_
    ULONG DataPortNumber,
    _In_
    PSDCA_PATH_DESCRIPTORS2 PathDescriptors
);

EVT_ACX_CIRCUIT_COMPOSITE_CIRCUIT_INITIALIZE DspC_EvtCircuitCompositeCircuitInitialize;
EVT_ACX_CIRCUIT_COMPOSITE_INITIALIZE DspC_EvtCircuitCompositeInitialize;

EVT_WDF_DEVICE_CONTEXT_CLEANUP          DspC_EvtCircuitContextCleanup;
EVT_WDF_DEVICE_PREPARE_HARDWARE         DspC_EvtDevicePrepareHardware;
EVT_WDF_DEVICE_RELEASE_HARDWARE         DspC_EvtDeviceReleaseHardware;
EVT_WDF_DEVICE_SELF_MANAGED_IO_INIT     DspC_EvtDeviceSelfManagedIoInit;
EVT_WDF_DEVICE_CONTEXT_CLEANUP          DspC_EvtDeviceContextCleanup;
EVT_ACX_OBJECT_PREPROCESS_REQUEST       DspC_EvtCircuitRequestPreprocess;
EVT_ACX_CIRCUIT_CREATE_STREAM           DspC_EvtCircuitCreateStream;
EVT_ACX_CIRCUIT_POWER_UP                DspC_EvtCircuitPowerUp;
EVT_ACX_CIRCUIT_POWER_DOWN              DspC_EvtCircuitPowerDown;
EVT_ACX_STREAM_GET_CAPTURE_PACKET       DspC_EvtStreamGetCapturePacket;
EVT_ACX_PIN_SET_DATAFORMAT              DspC_EvtAcxPinSetDataFormat;
EVT_WDF_DEVICE_CONTEXT_CLEANUP          DspC_EvtPinContextCleanup;
EVT_ACX_PIN_CONNECTED                   DspC_EvtPinConnected;
EVT_ACX_PIN_DISCONNECTED                DspC_EvtPinDisconnected;
EVT_ACX_KEYWORDSPOTTER_RETRIEVE_ARM     DspC_EvtAcxKeywordSpotterRetrieveArm;
EVT_ACX_KEYWORDSPOTTER_ASSIGN_ARM       DspC_EvtAcxKeywordSpotterAssignArm;
EVT_ACX_KEYWORDSPOTTER_ASSIGN_PATTERNS  DspC_EvtAcxKeywordSpotterAssignPatterns;
EVT_ACX_KEYWORDSPOTTER_ASSIGN_RESET     DspC_EvtAcxKeywordSpotterAssignReset;

// Property testing, todo: remove them.

EVT_ACX_OBJECT_PROCESS_REQUEST      DspR_EvtPinCInstancesCallback;
EVT_ACX_OBJECT_PROCESS_REQUEST      DspR_EvtPinCTypesCallback;
EVT_ACX_OBJECT_PROCESS_REQUEST      DspR_EvtPinDataFlowCallback;
EVT_ACX_OBJECT_PROCESS_REQUEST      DspR_EvtPinDataRangesCallback;
EVT_ACX_OBJECT_PROCESS_REQUEST      DspR_EvtPinDataIntersectionCallback;
EVT_ACX_OBJECT_PROCESS_REQUEST      DspR_EvtPinPhysicalConnectionCallback;


EVT_ACX_OBJECT_PREPROCESS_REQUEST   DspR_EvtStreamRequestPreprocess;
EVT_WDF_OBJECT_CONTEXT_CLEANUP      Dsp_EvtStreamContextCleanup;

#ifdef ACX_WORKAROUND_ACXPIN_01
EVT_ACX_OBJECT_PREPROCESS_REQUEST   Dsp_EvtStreamGetStreamCountRequestPreprocess;
#endif // ACX_WORKAROUND_ACXPIN_01

#ifdef ACX_WORKAROUND_ACXPIN_02
EVT_ACX_OBJECT_PREPROCESS_REQUEST   Dsp_EvtStreamProposeDataFormatRequestPreprocess;
#endif // ACX_WORKAROUND_ACXPIN_02

/* make internal prototypes usable from C++ */
#ifdef __cplusplus
}
#endif

//
// Used to store the registry settings path for the driver
//
extern UNICODE_STRING g_RegistryPath;

__drv_requiresIRQL(PASSIVE_LEVEL)
PAGED_CODE_SEG
NTSTATUS
CopyRegistrySettingsPath(
    _In_ PUNICODE_STRING RegistryPath
    );

PAGED_CODE_SEG
NTSTATUS
Dsp_CreateChildList(
    _In_ WDFDEVICE Device
);

PAGED_CODE_SEG
NTSTATUS
Dsp_AddFactoryCircuit(
    _In_ WDFDEVICE  Device
);

PAGED_CODE_SEG
VOID
Dsp_RemoveFactoryCircuit(
    _In_ WDFDEVICE  Device
);

#ifdef ACX_WORKAROUND_ACXFACTORYCIRCUIT_01
PAGED_CODE_SEG
NTSTATUS
Dsp_InitializeChildDevicesCache(
    _In_ ACXFACTORYCIRCUIT Factory
    );

PAGED_CODE_SEG
VOID
Dsp_CleanupChildDevicesCache(
    _In_ ACXFACTORYCIRCUIT  Factory
    );

PAGED_CODE_SEG
VOID
Dsp_DeleteChildDevicesCache(
    _In_ ACXFACTORYCIRCUIT  Factory
    );

PAGED_CODE_SEG
bool
Dsp_IsChildDeviceInCacheLocked(
    _In_ ACXFACTORYCIRCUIT  Factory,
    _In_ const GUID *       UniqueId
    );

PAGED_CODE_SEG
NTSTATUS
Dsp_AddChildDeviceToCache(
    _In_ ACXFACTORYCIRCUIT  Factory,
    _In_ const GUID *       UniqueId,
    _In_ WDFDEVICE          Device
    );

PAGED_CODE_SEG
WDFDEVICE
Dsp_RemoveChildDeviceFromCache(
    _In_ ACXFACTORYCIRCUIT  Factory,
    _In_ const GUID *       UniqueId
    );

PAGED_CODE_SEG
VOID
Dsp_PurgeChildDeviceFromCache(
    _In_ ACXFACTORYCIRCUIT  Factory,
    _In_ WDFDEVICE          Device
    );

EVT_ACX_OBJECT_PREPROCESS_REQUEST   Dsp_EvtFactoryRemoveCircuitRequestPreprocess;
EVT_WDF_DEVICE_CONTEXT_CLEANUP      Dsp_EvtDeviceIdContextCleanup;
EVT_ACX_OBJECT_PROCESS_REQUEST      Dsp_EvtFactoryCircuitRemoveCircuitCallback;
#endif  // ACX_WORKAROUND_ACXFACTORYCIRCUIT_01

PAGED_CODE_SEG
NTSTATUS
DspC_CircuitCleanup(
    _In_ ACXCIRCUIT Device
    );

PAGED_CODE_SEG
NTSTATUS
Dsp_SetPowerPolicy(
    _In_ WDFDEVICE      Device
    );

PAGED_CODE_SEG
NTSTATUS
DspR_SetPowerPolicy(
    _In_ WDFDEVICE      Device
    );

PAGED_CODE_SEG
NTSTATUS
DspC_SetPowerPolicy(
    _In_ WDFDEVICE      Device
    );

PAGED_CODE_SEG
NTSTATUS
DSP_SendPropertyTo
(
    _In_ WDFDEVICE Device,
    _In_ ACXTARGETCIRCUIT TargetCircuit,
    _In_ GUID PropertySet,
    _In_ ULONG PropertyId,
    _In_ ACX_PROPERTY_VERB Verb,
    _In_ PVOID Control,
    _In_ ULONG ControlCb,
    _Inout_ PVOID Value,
    _In_ ULONG ValueCb,
    _Out_ ULONG_PTR* Information
);

PAGED_CODE_SEG
NTSTATUS
Dsp_SendTestPropertyTo(
    _In_ WDFDEVICE Device,
    _In_ ACXCIRCUIT Circuit,
    _In_ GUID PropertySet,
    _In_ ULONG PropertyId,
    _In_ ACX_PROPERTY_VERB Verb,
    _In_ PVOID Control,
    _In_ ULONG ControlCb,
    _Inout_ PVOID Value,
    _In_ ULONG ValueCb,
    _Out_ ULONG_PTR* Information
    );

PAGED_CODE_SEG
VOID
Dsp_SendVendorSpecificProperties(
    _In_ WDFDEVICE Device,
    _In_ ACXCIRCUIT Circuit,
    _In_ BOOLEAN SetValue
    );


// Create a single SDCA_PATH for special streaming associated
// with the given ACXSTREAM
PAGED_CODE_SEG
NTSTATUS
Dsp_PrepareSpecialStreamForStream(
    _In_ ACXSTREAM Stream,
    _In_ SDCA_SPECIALSTREAM_TYPE SpecialStreamType,
    _In_ ULONG FunctionBitMask = 0xffffffff
    );

// Destroy all SDCA_PATHs associated with the given ACXSTREAM
PAGED_CODE_SEG
NTSTATUS
Dsp_ReleaseSpecialStreamsForStream(
    _In_ ACXSTREAM Stream
    );

// Start all SDCA_PATHs associated with the given ACXSTREAM
PAGED_CODE_SEG
NTSTATUS
Dsp_StartSpecialStreamsForStream(
    _In_ ACXSTREAM  Stream
    );

// Stop all SDCA_PATHs associated with the given ACXSTREAM
PAGED_CODE_SEG
NTSTATUS
Dsp_StopSpecialStreamsForStream(
    _In_ ACXSTREAM  Stream
    );

#endif // _PRIVATE_H_