1
|
#if !(UNITY_WSA_10_0 && NETFX_CORE)
|
2
|
using RootSystem = System;
|
3
|
using System.Linq;
|
4
|
using System.Collections.Generic;
|
5
|
namespace Windows.Kinect
|
6
|
{
|
7
|
//
|
8
|
// Windows.Kinect.DepthFrameReader
|
9
|
//
|
10
|
public sealed partial class DepthFrameReader : RootSystem.IDisposable, Helper.INativeWrapper
|
11
|
|
12
|
{
|
13
|
internal RootSystem.IntPtr _pNative;
|
14
|
RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
|
15
|
|
16
|
// Constructors and Finalizers
|
17
|
internal DepthFrameReader(RootSystem.IntPtr pNative)
|
18
|
{
|
19
|
_pNative = pNative;
|
20
|
Windows_Kinect_DepthFrameReader_AddRefObject(ref _pNative);
|
21
|
}
|
22
|
|
23
|
~DepthFrameReader()
|
24
|
{
|
25
|
Dispose(false);
|
26
|
}
|
27
|
|
28
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
29
|
private static extern void Windows_Kinect_DepthFrameReader_ReleaseObject(ref RootSystem.IntPtr pNative);
|
30
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
31
|
private static extern void Windows_Kinect_DepthFrameReader_AddRefObject(ref RootSystem.IntPtr pNative);
|
32
|
private void Dispose(bool disposing)
|
33
|
{
|
34
|
if (_pNative == RootSystem.IntPtr.Zero)
|
35
|
{
|
36
|
return;
|
37
|
}
|
38
|
|
39
|
__EventCleanup();
|
40
|
|
41
|
Helper.NativeObjectCache.RemoveObject<DepthFrameReader>(_pNative);
|
42
|
|
43
|
if (disposing)
|
44
|
{
|
45
|
Windows_Kinect_DepthFrameReader_Dispose(_pNative);
|
46
|
}
|
47
|
Windows_Kinect_DepthFrameReader_ReleaseObject(ref _pNative);
|
48
|
|
49
|
_pNative = RootSystem.IntPtr.Zero;
|
50
|
}
|
51
|
|
52
|
|
53
|
// Public Properties
|
54
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
55
|
private static extern RootSystem.IntPtr Windows_Kinect_DepthFrameReader_get_DepthFrameSource(RootSystem.IntPtr pNative);
|
56
|
public Windows.Kinect.DepthFrameSource DepthFrameSource
|
57
|
{
|
58
|
get
|
59
|
{
|
60
|
if (_pNative == RootSystem.IntPtr.Zero)
|
61
|
{
|
62
|
throw new RootSystem.ObjectDisposedException("DepthFrameReader");
|
63
|
}
|
64
|
|
65
|
RootSystem.IntPtr objectPointer = Windows_Kinect_DepthFrameReader_get_DepthFrameSource(_pNative);
|
66
|
Helper.ExceptionHelper.CheckLastError();
|
67
|
if (objectPointer == RootSystem.IntPtr.Zero)
|
68
|
{
|
69
|
return null;
|
70
|
}
|
71
|
|
72
|
return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.DepthFrameSource>(objectPointer, n => new Windows.Kinect.DepthFrameSource(n));
|
73
|
}
|
74
|
}
|
75
|
|
76
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
77
|
private static extern bool Windows_Kinect_DepthFrameReader_get_IsPaused(RootSystem.IntPtr pNative);
|
78
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
79
|
private static extern void Windows_Kinect_DepthFrameReader_put_IsPaused(RootSystem.IntPtr pNative, bool isPaused);
|
80
|
public bool IsPaused
|
81
|
{
|
82
|
get
|
83
|
{
|
84
|
if (_pNative == RootSystem.IntPtr.Zero)
|
85
|
{
|
86
|
throw new RootSystem.ObjectDisposedException("DepthFrameReader");
|
87
|
}
|
88
|
|
89
|
return Windows_Kinect_DepthFrameReader_get_IsPaused(_pNative);
|
90
|
}
|
91
|
set
|
92
|
{
|
93
|
if (_pNative == RootSystem.IntPtr.Zero)
|
94
|
{
|
95
|
throw new RootSystem.ObjectDisposedException("DepthFrameReader");
|
96
|
}
|
97
|
|
98
|
Windows_Kinect_DepthFrameReader_put_IsPaused(_pNative, value);
|
99
|
Helper.ExceptionHelper.CheckLastError();
|
100
|
}
|
101
|
}
|
102
|
|
103
|
|
104
|
// Events
|
105
|
private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handle;
|
106
|
[RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
|
107
|
private delegate void _Windows_Kinect_DepthFrameArrivedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
|
108
|
private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.DepthFrameArrivedEventArgs>>> Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.DepthFrameArrivedEventArgs>>>();
|
109
|
[AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_DepthFrameArrivedEventArgs_Delegate))]
|
110
|
private static void Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
|
111
|
{
|
112
|
List<RootSystem.EventHandler<Windows.Kinect.DepthFrameArrivedEventArgs>> callbackList = null;
|
113
|
Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
|
114
|
lock(callbackList)
|
115
|
{
|
116
|
var objThis = Helper.NativeObjectCache.GetObject<DepthFrameReader>(pNative);
|
117
|
var args = new Windows.Kinect.DepthFrameArrivedEventArgs(result);
|
118
|
foreach(var func in callbackList)
|
119
|
{
|
120
|
Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
|
121
|
}
|
122
|
}
|
123
|
}
|
124
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
125
|
private static extern void Windows_Kinect_DepthFrameReader_add_FrameArrived(RootSystem.IntPtr pNative, _Windows_Kinect_DepthFrameArrivedEventArgs_Delegate eventCallback, bool unsubscribe);
|
126
|
public event RootSystem.EventHandler<Windows.Kinect.DepthFrameArrivedEventArgs> FrameArrived
|
127
|
{
|
128
|
add
|
129
|
{
|
130
|
Helper.EventPump.EnsureInitialized();
|
131
|
|
132
|
Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
133
|
var callbackList = Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks[_pNative];
|
134
|
lock (callbackList)
|
135
|
{
|
136
|
callbackList.Add(value);
|
137
|
if(callbackList.Count == 1)
|
138
|
{
|
139
|
var del = new _Windows_Kinect_DepthFrameArrivedEventArgs_Delegate(Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handler);
|
140
|
_Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
|
141
|
Windows_Kinect_DepthFrameReader_add_FrameArrived(_pNative, del, false);
|
142
|
}
|
143
|
}
|
144
|
}
|
145
|
remove
|
146
|
{
|
147
|
if (_pNative == RootSystem.IntPtr.Zero)
|
148
|
{
|
149
|
return;
|
150
|
}
|
151
|
|
152
|
Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
153
|
var callbackList = Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks[_pNative];
|
154
|
lock (callbackList)
|
155
|
{
|
156
|
callbackList.Remove(value);
|
157
|
if(callbackList.Count == 0)
|
158
|
{
|
159
|
Windows_Kinect_DepthFrameReader_add_FrameArrived(_pNative, Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handler, true);
|
160
|
_Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handle.Free();
|
161
|
}
|
162
|
}
|
163
|
}
|
164
|
}
|
165
|
|
166
|
private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle;
|
167
|
[RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
|
168
|
private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
|
169
|
private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>> Windows_Data_PropertyChangedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>>();
|
170
|
[AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))]
|
171
|
private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
|
172
|
{
|
173
|
List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null;
|
174
|
Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
|
175
|
lock(callbackList)
|
176
|
{
|
177
|
var objThis = Helper.NativeObjectCache.GetObject<DepthFrameReader>(pNative);
|
178
|
var args = new Windows.Data.PropertyChangedEventArgs(result);
|
179
|
foreach(var func in callbackList)
|
180
|
{
|
181
|
Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
|
182
|
}
|
183
|
}
|
184
|
}
|
185
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
186
|
private static extern void Windows_Kinect_DepthFrameReader_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe);
|
187
|
public event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged
|
188
|
{
|
189
|
add
|
190
|
{
|
191
|
Helper.EventPump.EnsureInitialized();
|
192
|
|
193
|
Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
194
|
var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
|
195
|
lock (callbackList)
|
196
|
{
|
197
|
callbackList.Add(value);
|
198
|
if(callbackList.Count == 1)
|
199
|
{
|
200
|
var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
|
201
|
_Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
|
202
|
Windows_Kinect_DepthFrameReader_add_PropertyChanged(_pNative, del, false);
|
203
|
}
|
204
|
}
|
205
|
}
|
206
|
remove
|
207
|
{
|
208
|
if (_pNative == RootSystem.IntPtr.Zero)
|
209
|
{
|
210
|
return;
|
211
|
}
|
212
|
|
213
|
Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
214
|
var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
|
215
|
lock (callbackList)
|
216
|
{
|
217
|
callbackList.Remove(value);
|
218
|
if(callbackList.Count == 0)
|
219
|
{
|
220
|
Windows_Kinect_DepthFrameReader_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
|
221
|
_Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
|
222
|
}
|
223
|
}
|
224
|
}
|
225
|
}
|
226
|
|
227
|
|
228
|
// Public Methods
|
229
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
230
|
private static extern RootSystem.IntPtr Windows_Kinect_DepthFrameReader_AcquireLatestFrame(RootSystem.IntPtr pNative);
|
231
|
public Windows.Kinect.DepthFrame AcquireLatestFrame()
|
232
|
{
|
233
|
if (_pNative == RootSystem.IntPtr.Zero)
|
234
|
{
|
235
|
throw new RootSystem.ObjectDisposedException("DepthFrameReader");
|
236
|
}
|
237
|
|
238
|
RootSystem.IntPtr objectPointer = Windows_Kinect_DepthFrameReader_AcquireLatestFrame(_pNative);
|
239
|
Helper.ExceptionHelper.CheckLastError();
|
240
|
if (objectPointer == RootSystem.IntPtr.Zero)
|
241
|
{
|
242
|
return null;
|
243
|
}
|
244
|
|
245
|
return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.DepthFrame>(objectPointer, n => new Windows.Kinect.DepthFrame(n));
|
246
|
}
|
247
|
|
248
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
249
|
private static extern void Windows_Kinect_DepthFrameReader_Dispose(RootSystem.IntPtr pNative);
|
250
|
public void Dispose()
|
251
|
{
|
252
|
if (_pNative == RootSystem.IntPtr.Zero)
|
253
|
{
|
254
|
return;
|
255
|
}
|
256
|
|
257
|
Dispose(true);
|
258
|
RootSystem.GC.SuppressFinalize(this);
|
259
|
}
|
260
|
|
261
|
private void __EventCleanup()
|
262
|
{
|
263
|
{
|
264
|
Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
265
|
var callbackList = Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_callbacks[_pNative];
|
266
|
lock (callbackList)
|
267
|
{
|
268
|
if (callbackList.Count > 0)
|
269
|
{
|
270
|
callbackList.Clear();
|
271
|
if (_pNative != RootSystem.IntPtr.Zero)
|
272
|
{
|
273
|
Windows_Kinect_DepthFrameReader_add_FrameArrived(_pNative, Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handler, true);
|
274
|
}
|
275
|
_Windows_Kinect_DepthFrameArrivedEventArgs_Delegate_Handle.Free();
|
276
|
}
|
277
|
}
|
278
|
}
|
279
|
{
|
280
|
Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
281
|
var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
|
282
|
lock (callbackList)
|
283
|
{
|
284
|
if (callbackList.Count > 0)
|
285
|
{
|
286
|
callbackList.Clear();
|
287
|
if (_pNative != RootSystem.IntPtr.Zero)
|
288
|
{
|
289
|
Windows_Kinect_DepthFrameReader_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
|
290
|
}
|
291
|
_Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
|
292
|
}
|
293
|
}
|
294
|
}
|
295
|
}
|
296
|
}
|
297
|
|
298
|
}
|
299
|
#endif
|