summaryrefslogtreecommitdiff
path: root/audio/simpleaudiosample/Source/Inc/kshelper.h
blob: 023f773a958613737a55bc4134100fb32a70a3ad (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
/*++

Copyright (c) Microsoft Corporation All Rights Reserved

Module Name:

    kshelper.h

Abstract:

    Helper functions for simple audio sample
--*/
#ifndef _SIMPLEAUDIOSAMPLE_KSHELPER_H_
#define _SIMPLEAUDIOSAMPLE_KSHELPER_H_

#include <portcls.h>
#include <ksdebug.h>

PWAVEFORMATEX                   
GetWaveFormatEx
(
    _In_  PKSDATAFORMAT           pDataFormat
);

NTSTATUS                        
ValidatePropertyParams
(
    _In_ PPCPROPERTY_REQUEST      PropertyRequest, 
    _In_ ULONG                    cbValueSize,
    _In_ ULONG                    cbInstanceSize = 0 
);

NTSTATUS
PropertyHandler_BasicSupport
(
    _In_  PPCPROPERTY_REQUEST     PropertyRequest,
    _In_  ULONG                   Flags,
    _In_  DWORD                   PropTypeSetId
);

NTSTATUS
PropertyHandler_BasicSupportVolume
(
    _In_  PPCPROPERTY_REQUEST   PropertyRequest,
    _In_  ULONG                 MaxChannels
);

NTSTATUS
PropertyHandler_BasicSupportMute
(
    _In_  PPCPROPERTY_REQUEST   PropertyRequest,
    _In_  ULONG                 MaxChannels
);

NTSTATUS
PropertyHandler_BasicSupportPeakMeter2
(
    _In_  PPCPROPERTY_REQUEST   PropertyRequest,
    _In_  ULONG                 MaxChannels
);

NTSTATUS
PropertyHandler_CpuResources
( 
    _In_  PPCPROPERTY_REQUEST     PropertyRequest 
);

NTSTATUS
PropertyHandler_Volume
(
    _In_  PADAPTERCOMMON        AdapterCommon,
    _In_  PPCPROPERTY_REQUEST   PropertyRequest,
    _In_  ULONG                 MaxChannels
);

NTSTATUS                            
PropertyHandler_Mute
(
    _In_  PADAPTERCOMMON        AdapterCommon,
    _In_  PPCPROPERTY_REQUEST   PropertyRequest,
    _In_  ULONG                 MaxChannels
);

NTSTATUS
PropertyHandler_PeakMeter2
(
    _In_  PADAPTERCOMMON        AdapterCommon,
    _In_  PPCPROPERTY_REQUEST   PropertyRequest,
    _In_  ULONG                 MaxChannels
);

//=============================================================================
// Property helpers
//=============================================================================

NTSTATUS
SimpleAudioSamplePropertyDispatch
(
    _In_ PPCPROPERTY_REQUEST PropertyRequest
);

// Use this structure to define property items with extra data allowing easier
// definition of separate get, set, and support handlers dispatched through
// SimpleAudioSamplePropertyDispatch.
typedef struct
{
    PCPROPERTY_ITEM         PropertyItem;       // Standard PCPROPERTY_ITEM
    ULONG                   MinProperty;        // Minimum size of the property instance data
    ULONG                   MinData;            // Minimum size of the property value
    PCPFNPROPERTY_HANDLER   GetHandler;         // Property get handler (NULL if GET not supported)
    PCPFNPROPERTY_HANDLER   SetHandler;         // Property set handler (NULL if SET not supported)
    PCPFNPROPERTY_HANDLER   SupportHandler;     // Property support handler (NULL for common handler)
    VOID                    *ContextData;        // Optional context information for the handler, NULL for unused
    ULONG                   ContextDataSize;     // Size of the data held at ContextData, 0 for unused
} SIMPLEAUDIOSAMPLE_PROPERTY_ITEM;

// The following macros facilitate adding property handlers to a class, allowing
// easier declaration and definition of a "thunk" routine that directly handles
// the property request and calls into a class instance method. Note that as
// written, the thunk routine assumes PAGED_CODE.
#define DECLARE_CLASSPROPERTYHANDLER(theClass, theMethod)                       \
NTSTATUS theClass##_##theMethod                                                 \
(                                                                               \
    _In_ PPCPROPERTY_REQUEST PropertyRequest                                    \
);

#define DECLARE_PROPERTYHANDLER(theMethod)                                      \
NTSTATUS theMethod                                                              \
(                                                                               \
    _In_ PPCPROPERTY_REQUEST PropertyRequest                                    \
);

#define DEFINE_CLASSPROPERTYHANDLER(theClass, theMethod)                        \
NTSTATUS theClass##_##theMethod                                                 \
(                                                                               \
    _In_ PPCPROPERTY_REQUEST PropertyRequest                                    \
)                                                                               \
{                                                                               \
    NTSTATUS status;                                                            \
                                                                                \
    PAGED_CODE();                                                               \
                                                                                \
    theClass* p = reinterpret_cast<theClass*>(PropertyRequest->MajorTarget);    \
                                                                                \
    p->AddRef();                                                                \
    status = p->theMethod(PropertyRequest);                                     \
    p->Release();                                                               \
                                                                                \
    return status;                                                              \
}                                                                               \
NTSTATUS theClass::theMethod                                                    \
(                                                                               \
    _In_ PPCPROPERTY_REQUEST PropertyRequest                                    \
)




#endif  // _SIMPLEAUDIOSAMPLE_KSHELPER_H_