UVCDevice.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //#define ENABLE_LOG
  2. /*
  3. * Copyright (c) 2014 - 2022 t_saki@serenegiant.com
  4. */
  5. using System;
  6. using System.Runtime.InteropServices;
  7. /*
  8. * THETA S vid:1482, pid:1001
  9. * THETA V vid:1482, pid:1002
  10. * THETA Z1 vid:1482, pid:1005
  11. */
  12. namespace Serenegiant.UVC
  13. {
  14. [Serializable]
  15. public class UVCDevice
  16. {
  17. private readonly IntPtr ptr;
  18. public readonly Int32 id;
  19. public readonly int vid;
  20. public readonly int pid;
  21. public readonly int deviceClass;
  22. public readonly int deviceSubClass;
  23. public readonly int deviceProtocol;
  24. public readonly string name;
  25. public UVCDevice(IntPtr devicePtr) {
  26. ptr = devicePtr;
  27. id = GetId(devicePtr);
  28. vid = GetVendorId(devicePtr);
  29. pid = GetProductId(devicePtr);
  30. name = GetName(devicePtr);
  31. deviceClass = GetDeviceClass(devicePtr);
  32. deviceSubClass = GetDeviceSubClass(devicePtr);
  33. deviceProtocol = GetDeviceProtocol(devicePtr);
  34. }
  35. public override string ToString()
  36. {
  37. return $"{base.ToString()}(id={id},vid={vid},pid={pid},name={name},deviceClass={deviceClass},deviceSubClass={deviceSubClass},deviceProtocol={deviceProtocol})";
  38. }
  39. /**
  40. * Ricohの製品かどうか
  41. * @param info
  42. */
  43. public bool IsRicoh
  44. {
  45. get { return (vid == 1482); }
  46. }
  47. /**
  48. * THETA S/V/Z1のいずれかかどうか
  49. */
  50. public bool IsTHETA
  51. {
  52. get { return IsTHETA_S || IsTHETA_V || IsTHETA_Z1; }
  53. }
  54. /**
  55. * THETA Sかどうか
  56. */
  57. public bool IsTHETA_S
  58. {
  59. get { return (vid == 1482) && (pid == 10001); }
  60. }
  61. /**
  62. * THETA Vかどうか
  63. */
  64. public bool IsTHETA_V
  65. {
  66. // THETA Vからのpid=872はUVCでなくて動かないので注意(THETA側は静止画/動画モード)
  67. get { return (vid == 1482) && (pid == 10002); }
  68. }
  69. /**
  70. * THETA Z1かどうか
  71. * @param info
  72. */
  73. public bool IsTHETA_Z1
  74. {
  75. // THETA Z1からのpid=877はUVCではなくて動かないので注意(THETA側は静止画/動画モード)
  76. get { return (vid == 1482) && (pid == 10005); }
  77. }
  78. /**
  79. * UACに対応しているかどうか
  80. * XXX UACに対応していると応答するUVC機器でも実際にはUACに未対応なバギーな機器も存在するので注意!
  81. */
  82. public bool isUAC
  83. {
  84. get { return Match(1, 1, 0xff) && Match(1, 2, 0xff); }
  85. }
  86. /**
  87. * デバイスまたはインターフェースが指定した条件に一致するかどうかを確認
  88. * @param bClass 0xffなら常にマッチする(ワイルドカード)
  89. * @param bSubClass 0xffなら常にマッチする(ワイルドカード)
  90. * @param bProtocol 0xffなら常にマッチする(ワイルドカード)
  91. * @returtn 1: 一致した, 0: 一致しなかった
  92. */
  93. public bool Match(byte bClass, byte bSubClass, byte bProtocol)
  94. {
  95. var result = InternalMatch(ptr, bClass, bSubClass, bProtocol);
  96. return result != 0;
  97. }
  98. //--------------------------------------------------------------------------------
  99. // プラグインのインターフェース関数
  100. //--------------------------------------------------------------------------------
  101. /**
  102. * 機器idを取得(これだけはpublicにする)
  103. */
  104. [DllImport("unityuvcplugin", EntryPoint = "DeviceInfo_get_id")]
  105. public static extern Int32 GetId(IntPtr devicePtr);
  106. /**
  107. * デバイスクラスを取得
  108. */
  109. [DllImport("unityuvcplugin", EntryPoint = "DeviceInfo_get_device_class")]
  110. private static extern Byte GetDeviceClass(IntPtr devicePtr);
  111. /**
  112. * デバイスサブクラスを取得
  113. */
  114. [DllImport("unityuvcplugin", EntryPoint = "DeviceInfo_get_device_sub_class")]
  115. private static extern Byte GetDeviceSubClass(IntPtr devicePtr);
  116. /**
  117. * デバイスプロトコルを取得
  118. */
  119. [DllImport("unityuvcplugin", EntryPoint = "DeviceInfo_get_device_protocol")]
  120. private static extern Byte GetDeviceProtocol(IntPtr devicePtr);
  121. /**
  122. * ベンダーIDを取得
  123. */
  124. [DllImport("unityuvcplugin", EntryPoint = "DeviceInfo_get_vendor_id")]
  125. private static extern UInt16 GetVendorId(IntPtr devicePtr);
  126. /**
  127. * プロダクトIDを取得
  128. */
  129. [DllImport("unityuvcplugin", EntryPoint = "DeviceInfo_get_product_id")]
  130. private static extern UInt16 GetProductId(IntPtr devicePtr);
  131. /**
  132. * 機器名を取得
  133. */
  134. [DllImport("unityuvcplugin", EntryPoint = "DeviceInfo_get_name")]
  135. [return: MarshalAs(UnmanagedType.LPStr)]
  136. private static extern string GetName(IntPtr devicePtr);
  137. /**
  138. * デバイスまたはインターフェースが指定した条件に一致するかどうかを確認
  139. * @param device
  140. * @param bClass 0xffなら常にマッチする(ワイルドカード)
  141. * @param bSubClass 0xffなら常にマッチする(ワイルドカード)
  142. * @param bProtocol 0xffなら常にマッチする(ワイルドカード)
  143. * @returtn 1: 一致した, 0: 一致しなかった
  144. */
  145. [DllImport("unityuvcplugin", EntryPoint = "DeviceInfo_match")]
  146. private static extern Int32 InternalMatch(IntPtr devicePtr, byte bClass, byte bSubClass, byte bProtocol);
  147. } // UVCDevice
  148. } // namespace Serenegiant.UVC