AudioBeamFrameReader.cs 16 KB

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