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
|
/**************************************************************************
A/V Stream Camera Sample
Copyright (c) 2013, Microsoft Corporation.
File:
util.h
Abstract:
Contains miscellaneous helper functions such as random number
generation and bounds checking functions.
History:
created 7/12/2013
**************************************************************************/
//
// Generate a random number using the standard Crypto library.
// Fall back to the QPC, if crypto library reports an error.
//
ULONG
GetRandom(
_In_ ULONG Minimum,
_In_ ULONG Maximum
);
//
// Generate a random number using the standard Crypto library.
// Fall back to the QPC, if crypto library reports an error.
//
LONG
GetRandom(
_In_ LONG Minimum,
_In_ LONG Maximum
);
//
// Convert an EV Compensation flag into the denominator of a fraction.
//
LONG
EVFlags2Denominator(
_In_ ULONGLONG Flags
);
//
// Convert a WhiteBalance Extended Property Enum to temperature
//
ULONG
WhiteBalancePreset2Temperature(
_In_ ULONG WBPreset
);
//
// Checks if a legacy Exposure setting is in range
//
BOOL
ExposureBinaryLogIsValid(
_In_ LONG ExposureBL
);
//
// Converts a legacy Exposure setting into 100 ns
//
LONGLONG
ExposureBinaryLogTo100ns(
_In_ LONG ExposureBL
);
//
// Converts a Exposure setting into a Binary log preset
//
LONG
Exposure100nsToBinaryLog(
_In_ LONGLONG Exposure100ns
);
//
// Convert ISO preset flags to a preset number
//
ULONG
IsoPreset2Value(
_In_ ULONGLONG Flags
);
//
// Convert ISO Mode & Value to legacy presets.
//
// Note: This function will simply pass legacy presets through.
//
ULONGLONG
IsoModeValue2Preset(
_In_ ULONGLONG Mode,
_In_ ULONG Value
);
LPCSTR
KSStateToStateName(
_In_ KSSTATE state
);
BOOL
MultiplyCheckOverflow (
ULONG a,
ULONG b,
ULONG *pab
);
// Note: I overload this function intentionally. Just use
// the correct type as the first parameter and the
// compiler figures out the function to use.
template<class T>
inline
NTSTATUS
BoundsCheck(
_In_ T Value,
_In_ const KSCAMERA_EXTENDEDPROP_VIDEOPROCSETTING &Bounds
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
if( (Bounds.Step==0 && Bounds.Min!=Bounds.Max) ||
(Bounds.Step!=0 && ((Value - T(Bounds.Min) ) % T(Bounds.Step)) != 0) ||
Value > T(Bounds.Max) ||
Value < T(Bounds.Min) )
{
ntStatus = STATUS_INVALID_PARAMETER;
}
return ntStatus;
}
inline
NTSTATUS
BoundsCheckSigned(
_In_ LONGLONG Value,
_In_ const KSCAMERA_EXTENDEDPROP_VIDEOPROCSETTING &Bounds
)
{
return BoundsCheck<LONGLONG>( Value, Bounds );
}
inline
NTSTATUS
BoundsCheckSigned(
_In_ LONG Value,
_In_ const KSPROPERTY_STEPPING_LONG &Bounds
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
if( (Bounds.SteppingDelta==0 && Bounds.Bounds.SignedMinimum!=Bounds.Bounds.SignedMaximum) ||
(Bounds.SteppingDelta!=0 && (Value - Bounds.Bounds.SignedMinimum) % Bounds.SteppingDelta) != 0 ||
Value > Bounds.Bounds.SignedMaximum ||
Value < Bounds.Bounds.SignedMinimum )
{
ntStatus = STATUS_INVALID_PARAMETER;
}
return ntStatus;
}
inline
NTSTATUS
BoundsCheckSigned(
_In_ LONGLONG Value,
_In_ const KSPROPERTY_STEPPING_LONGLONG &Bounds
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
if( (Bounds.SteppingDelta==0 && Bounds.Bounds.SignedMinimum!=Bounds.Bounds.SignedMaximum) ||
(Bounds.SteppingDelta!=0 && ((Value - Bounds.Bounds.SignedMinimum) % Bounds.SteppingDelta) != 0) ||
Value > Bounds.Bounds.SignedMaximum ||
Value < Bounds.Bounds.SignedMinimum )
{
ntStatus = STATUS_INVALID_PARAMETER;
}
return ntStatus;
}
// Note: I overload this function intentionally. Just use
// the correct type as the first parameter and the
// compiler figures out the function to use.
inline
NTSTATUS
BoundsCheckUnsigned(
_In_ ULONG Value,
_In_ const KSPROPERTY_STEPPING_LONG &Bounds
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
if( (Bounds.SteppingDelta==0 && Bounds.Bounds.UnsignedMinimum!=Bounds.Bounds.UnsignedMaximum) ||
(Bounds.SteppingDelta!=0 && ((Value - Bounds.Bounds.UnsignedMinimum) % Bounds.SteppingDelta) != 0) ||
Value > Bounds.Bounds.UnsignedMaximum ||
Value < Bounds.Bounds.UnsignedMinimum )
{
ntStatus = STATUS_INVALID_PARAMETER;
}
return ntStatus;
}
inline
NTSTATUS
BoundsCheckUnsigned(
_In_ ULONGLONG Value,
_In_ const KSPROPERTY_STEPPING_LONGLONG &Bounds
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
if( (Bounds.SteppingDelta==0 && Bounds.Bounds.UnsignedMinimum!=Bounds.Bounds.UnsignedMaximum) ||
(Bounds.SteppingDelta!=0 && ((Value - Bounds.Bounds.UnsignedMinimum) % Bounds.SteppingDelta) != 0) ||
Value > Bounds.Bounds.UnsignedMaximum ||
Value < Bounds.Bounds.UnsignedMinimum )
{
ntStatus = STATUS_INVALID_PARAMETER;
}
return ntStatus;
}
//
// This function is used internally to translate KSCAMERA_PERFRAMESETTING
// AUTO & MANUAL flags to KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG AUTO & MANUAL
// flags. There is no need to translate them back.
//
inline
ULONGLONG
TranslatePFS2VideoProcFlags(
ULONGLONG FromMode
)
{
// The PFS settings and VideoProc flags are mixed.
// To handle that, we'll first remove any PFS flags
// and hang onto the rest.
ULONGLONG ToMode=
FromMode & ~(KSCAMERA_PERFRAMESETTING_AUTO|KSCAMERA_PERFRAMESETTING_MANUAL);
if( FromMode & KSCAMERA_PERFRAMESETTING_AUTO )
{
ToMode |= KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG_AUTO;
}
if( FromMode & KSCAMERA_PERFRAMESETTING_MANUAL )
{
ToMode |= KSCAMERA_EXTENDEDPROP_VIDEOPROCFLAG_MANUAL;
}
return ToMode;
}
//
// Debugging Helper
//
PCSTR
FocusStateDbgTxt(
_In_ KSCAMERA_EXTENDEDPROP_FOCUSSTATE State
);
//
// Debugging Helper - translate ACPI rotation enum to degrees.
//
int
DbgRotation2Degrees(
AcpiPldRotation r
);
// Create a definition that self-initialize a KS_CAMERA_EXTRINSIC structure.
class CCameraExtrinsics_2Transforms : public KS_CAMERA_EXTRINSICS
{
public:
KS_CAMERA_EXTRINSICS_CALIBRATEDTRANSFORM CalibratedTransform2;
public:
CCameraExtrinsics_2Transforms()
{
RtlZeroMemory(this, sizeof(*this));
}
CCameraExtrinsics_2Transforms( ULONG Seed );
};
// Create a definition that self-initialize a KS_CAMERA_EXTRINSIC structure.
class CCameraIntrinsics_2Models : public KS_CAMERA_INTRINSICS
{
public:
KS_PINHOLECAMERAINTRINSIC_INTRINSICMODEL IntrinsicModel2;
public:
CCameraIntrinsics_2Models();
};
#define SAFE_FREE(_x_) \
if( _x_ ) \
{ \
ExFreePool( _x_ ); \
_x_ = nullptr; \
}
#define SAFE_DELETE(_x_) \
if( _x_ ) \
{ \
delete _x_; \
_x_ = nullptr; \
}
#define SAFE_DELETE_ARRAY(_x_) \
if( _x_ ) \
{ \
delete [] _x_; \
_x_ = nullptr; \
}
#define SAFE_CLOSE_HANDLE(_x_) \
if( (_x_ != NULL) && (_x_ != INVALID_HANDLE_VALUE) ) \
{ \
ZwClose( _x_ ); \
_x_ = INVALID_HANDLE_VALUE; \
}
|