1 |
3
|
KTH
|
#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.DepthFrameSource
|
9 |
|
|
//
|
10 |
|
|
public sealed partial class DepthFrameSource : 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 DepthFrameSource(RootSystem.IntPtr pNative)
|
18 |
|
|
{
|
19 |
|
|
_pNative = pNative;
|
20 |
|
|
Windows_Kinect_DepthFrameSource_AddRefObject(ref _pNative);
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
~DepthFrameSource()
|
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_DepthFrameSource_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_DepthFrameSource_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<DepthFrameSource>(_pNative);
|
42 |
|
|
Windows_Kinect_DepthFrameSource_ReleaseObject(ref _pNative);
|
43 |
|
|
|
44 |
|
|
_pNative = RootSystem.IntPtr.Zero;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
// Public Properties
|
49 |
|
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
50 |
|
|
private static extern ushort Windows_Kinect_DepthFrameSource_get_DepthMaxReliableDistance(RootSystem.IntPtr pNative);
|
51 |
|
|
public ushort DepthMaxReliableDistance
|
52 |
|
|
{
|
53 |
|
|
get
|
54 |
|
|
{
|
55 |
|
|
if (_pNative == RootSystem.IntPtr.Zero)
|
56 |
|
|
{
|
57 |
|
|
throw new RootSystem.ObjectDisposedException("DepthFrameSource");
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
return Windows_Kinect_DepthFrameSource_get_DepthMaxReliableDistance(_pNative);
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
65 |
|
|
private static extern ushort Windows_Kinect_DepthFrameSource_get_DepthMinReliableDistance(RootSystem.IntPtr pNative);
|
66 |
|
|
public ushort DepthMinReliableDistance
|
67 |
|
|
{
|
68 |
|
|
get
|
69 |
|
|
{
|
70 |
|
|
if (_pNative == RootSystem.IntPtr.Zero)
|
71 |
|
|
{
|
72 |
|
|
throw new RootSystem.ObjectDisposedException("DepthFrameSource");
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
return Windows_Kinect_DepthFrameSource_get_DepthMinReliableDistance(_pNative);
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
80 |
|
|
private static extern RootSystem.IntPtr Windows_Kinect_DepthFrameSource_get_FrameDescription(RootSystem.IntPtr pNative);
|
81 |
|
|
public Windows.Kinect.FrameDescription FrameDescription
|
82 |
|
|
{
|
83 |
|
|
get
|
84 |
|
|
{
|
85 |
|
|
if (_pNative == RootSystem.IntPtr.Zero)
|
86 |
|
|
{
|
87 |
|
|
throw new RootSystem.ObjectDisposedException("DepthFrameSource");
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
RootSystem.IntPtr objectPointer = Windows_Kinect_DepthFrameSource_get_FrameDescription(_pNative);
|
91 |
|
|
Helper.ExceptionHelper.CheckLastError();
|
92 |
|
|
if (objectPointer == RootSystem.IntPtr.Zero)
|
93 |
|
|
{
|
94 |
|
|
return null;
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.FrameDescription>(objectPointer, n => new Windows.Kinect.FrameDescription(n));
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
102 |
|
|
private static extern bool Windows_Kinect_DepthFrameSource_get_IsActive(RootSystem.IntPtr pNative);
|
103 |
|
|
public bool IsActive
|
104 |
|
|
{
|
105 |
|
|
get
|
106 |
|
|
{
|
107 |
|
|
if (_pNative == RootSystem.IntPtr.Zero)
|
108 |
|
|
{
|
109 |
|
|
throw new RootSystem.ObjectDisposedException("DepthFrameSource");
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
return Windows_Kinect_DepthFrameSource_get_IsActive(_pNative);
|
113 |
|
|
}
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
117 |
|
|
private static extern RootSystem.IntPtr Windows_Kinect_DepthFrameSource_get_KinectSensor(RootSystem.IntPtr pNative);
|
118 |
|
|
public Windows.Kinect.KinectSensor KinectSensor
|
119 |
|
|
{
|
120 |
|
|
get
|
121 |
|
|
{
|
122 |
|
|
if (_pNative == RootSystem.IntPtr.Zero)
|
123 |
|
|
{
|
124 |
|
|
throw new RootSystem.ObjectDisposedException("DepthFrameSource");
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
RootSystem.IntPtr objectPointer = Windows_Kinect_DepthFrameSource_get_KinectSensor(_pNative);
|
128 |
|
|
Helper.ExceptionHelper.CheckLastError();
|
129 |
|
|
if (objectPointer == RootSystem.IntPtr.Zero)
|
130 |
|
|
{
|
131 |
|
|
return null;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectSensor>(objectPointer, n => new Windows.Kinect.KinectSensor(n));
|
135 |
|
|
}
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
// Events
|
140 |
|
|
private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle;
|
141 |
|
|
[RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
|
142 |
|
|
private delegate void _Windows_Kinect_FrameCapturedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
|
143 |
|
|
private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>>> Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>>>();
|
144 |
|
|
[AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_FrameCapturedEventArgs_Delegate))]
|
145 |
|
|
private static void Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
|
146 |
|
|
{
|
147 |
|
|
List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>> callbackList = null;
|
148 |
|
|
Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
|
149 |
|
|
lock(callbackList)
|
150 |
|
|
{
|
151 |
|
|
var objThis = Helper.NativeObjectCache.GetObject<DepthFrameSource>(pNative);
|
152 |
|
|
var args = new Windows.Kinect.FrameCapturedEventArgs(result);
|
153 |
|
|
foreach(var func in callbackList)
|
154 |
|
|
{
|
155 |
|
|
Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
160 |
|
|
private static extern void Windows_Kinect_DepthFrameSource_add_FrameCaptured(RootSystem.IntPtr pNative, _Windows_Kinect_FrameCapturedEventArgs_Delegate eventCallback, bool unsubscribe);
|
161 |
|
|
public event RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs> FrameCaptured
|
162 |
|
|
{
|
163 |
|
|
add
|
164 |
|
|
{
|
165 |
|
|
Helper.EventPump.EnsureInitialized();
|
166 |
|
|
|
167 |
|
|
Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
168 |
|
|
var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
|
169 |
|
|
lock (callbackList)
|
170 |
|
|
{
|
171 |
|
|
callbackList.Add(value);
|
172 |
|
|
if(callbackList.Count == 1)
|
173 |
|
|
{
|
174 |
|
|
var del = new _Windows_Kinect_FrameCapturedEventArgs_Delegate(Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler);
|
175 |
|
|
_Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
|
176 |
|
|
Windows_Kinect_DepthFrameSource_add_FrameCaptured(_pNative, del, false);
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
remove
|
181 |
|
|
{
|
182 |
|
|
if (_pNative == RootSystem.IntPtr.Zero)
|
183 |
|
|
{
|
184 |
|
|
return;
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
188 |
|
|
var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
|
189 |
|
|
lock (callbackList)
|
190 |
|
|
{
|
191 |
|
|
callbackList.Remove(value);
|
192 |
|
|
if(callbackList.Count == 0)
|
193 |
|
|
{
|
194 |
|
|
Windows_Kinect_DepthFrameSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true);
|
195 |
|
|
_Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free();
|
196 |
|
|
}
|
197 |
|
|
}
|
198 |
|
|
}
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle;
|
202 |
|
|
[RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
|
203 |
|
|
private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
|
204 |
|
|
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>>>();
|
205 |
|
|
[AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))]
|
206 |
|
|
private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
|
207 |
|
|
{
|
208 |
|
|
List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null;
|
209 |
|
|
Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
|
210 |
|
|
lock(callbackList)
|
211 |
|
|
{
|
212 |
|
|
var objThis = Helper.NativeObjectCache.GetObject<DepthFrameSource>(pNative);
|
213 |
|
|
var args = new Windows.Data.PropertyChangedEventArgs(result);
|
214 |
|
|
foreach(var func in callbackList)
|
215 |
|
|
{
|
216 |
|
|
Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
|
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
221 |
|
|
private static extern void Windows_Kinect_DepthFrameSource_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe);
|
222 |
|
|
public event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged
|
223 |
|
|
{
|
224 |
|
|
add
|
225 |
|
|
{
|
226 |
|
|
Helper.EventPump.EnsureInitialized();
|
227 |
|
|
|
228 |
|
|
Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
229 |
|
|
var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
|
230 |
|
|
lock (callbackList)
|
231 |
|
|
{
|
232 |
|
|
callbackList.Add(value);
|
233 |
|
|
if(callbackList.Count == 1)
|
234 |
|
|
{
|
235 |
|
|
var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
|
236 |
|
|
_Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
|
237 |
|
|
Windows_Kinect_DepthFrameSource_add_PropertyChanged(_pNative, del, false);
|
238 |
|
|
}
|
239 |
|
|
}
|
240 |
|
|
}
|
241 |
|
|
remove
|
242 |
|
|
{
|
243 |
|
|
if (_pNative == RootSystem.IntPtr.Zero)
|
244 |
|
|
{
|
245 |
|
|
return;
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
249 |
|
|
var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
|
250 |
|
|
lock (callbackList)
|
251 |
|
|
{
|
252 |
|
|
callbackList.Remove(value);
|
253 |
|
|
if(callbackList.Count == 0)
|
254 |
|
|
{
|
255 |
|
|
Windows_Kinect_DepthFrameSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
|
256 |
|
|
_Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
|
257 |
|
|
}
|
258 |
|
|
}
|
259 |
|
|
}
|
260 |
|
|
}
|
261 |
|
|
|
262 |
|
|
|
263 |
|
|
// Public Methods
|
264 |
|
|
[RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
|
265 |
|
|
private static extern RootSystem.IntPtr Windows_Kinect_DepthFrameSource_OpenReader(RootSystem.IntPtr pNative);
|
266 |
|
|
public Windows.Kinect.DepthFrameReader OpenReader()
|
267 |
|
|
{
|
268 |
|
|
if (_pNative == RootSystem.IntPtr.Zero)
|
269 |
|
|
{
|
270 |
|
|
throw new RootSystem.ObjectDisposedException("DepthFrameSource");
|
271 |
|
|
}
|
272 |
|
|
|
273 |
|
|
RootSystem.IntPtr objectPointer = Windows_Kinect_DepthFrameSource_OpenReader(_pNative);
|
274 |
|
|
Helper.ExceptionHelper.CheckLastError();
|
275 |
|
|
if (objectPointer == RootSystem.IntPtr.Zero)
|
276 |
|
|
{
|
277 |
|
|
return null;
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.DepthFrameReader>(objectPointer, n => new Windows.Kinect.DepthFrameReader(n));
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
private void __EventCleanup()
|
284 |
|
|
{
|
285 |
|
|
{
|
286 |
|
|
Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
287 |
|
|
var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
|
288 |
|
|
lock (callbackList)
|
289 |
|
|
{
|
290 |
|
|
if (callbackList.Count > 0)
|
291 |
|
|
{
|
292 |
|
|
callbackList.Clear();
|
293 |
|
|
if (_pNative != RootSystem.IntPtr.Zero)
|
294 |
|
|
{
|
295 |
|
|
Windows_Kinect_DepthFrameSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true);
|
296 |
|
|
}
|
297 |
|
|
_Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free();
|
298 |
|
|
}
|
299 |
|
|
}
|
300 |
|
|
}
|
301 |
|
|
{
|
302 |
|
|
Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
|
303 |
|
|
var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
|
304 |
|
|
lock (callbackList)
|
305 |
|
|
{
|
306 |
|
|
if (callbackList.Count > 0)
|
307 |
|
|
{
|
308 |
|
|
callbackList.Clear();
|
309 |
|
|
if (_pNative != RootSystem.IntPtr.Zero)
|
310 |
|
|
{
|
311 |
|
|
Windows_Kinect_DepthFrameSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
|
312 |
|
|
}
|
313 |
|
|
_Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
|
314 |
|
|
}
|
315 |
|
|
}
|
316 |
|
|
}
|
317 |
|
|
}
|
318 |
|
|
}
|
319 |
|
|
|
320 |
|
|
}
|
321 |
|
|
#endif |