CameraDetector.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. using ManageLiteAV;
  2. using System;
  3. using Vinno.FIS.TRTCClient.Common.Log;
  4. using static Vinno.FIS.TRTCClient.TRTCPusher;
  5. namespace Vinno.FIS.TRTCClient
  6. {
  7. internal class CameraDetector : ITRTCCloudCallback, IDisposable
  8. {
  9. private ITRTCCloud _tRTCCloud;
  10. private ITXDeviceManager _deviceManager;
  11. public event EventHandler<TRTCDeviceInfo> DeviceUpdated;
  12. public CameraDetector()
  13. {
  14. _tRTCCloud = ITRTCCloud.getTRTCShareInstance();
  15. _deviceManager = _tRTCCloud.getDeviceManager();
  16. _tRTCCloud.addCallback(this);
  17. }
  18. /// <summary>
  19. /// Get the Correct Id
  20. /// </summary>
  21. /// <param name="type"></param>
  22. /// <param name="deviceId"></param>
  23. /// <returns></returns>
  24. public string GetCorrectId(HardwareType type, string deviceId)
  25. {
  26. if (string.IsNullOrEmpty(deviceId))
  27. {
  28. return string.Empty;
  29. }
  30. TRTCDeviceType trtcDeviceType = TRTCDeviceType.TXMediaDeviceTypeUnknown;
  31. switch (type)
  32. {
  33. case HardwareType.Camera:
  34. trtcDeviceType = TRTCDeviceType.TXMediaDeviceTypeCamera;
  35. break;
  36. case HardwareType.Mic:
  37. trtcDeviceType = TRTCDeviceType.TXMediaDeviceTypeMic;
  38. break;
  39. case HardwareType.Speaker:
  40. trtcDeviceType = TRTCDeviceType.TXMediaDeviceTypeSpeaker;
  41. break;
  42. }
  43. var hardwareList = _deviceManager.getDevicesList(trtcDeviceType);
  44. try
  45. {
  46. var count = hardwareList.getCount();
  47. for (uint i = 0; i < count; i++)
  48. {
  49. var id = hardwareList.getDevicePID(i);
  50. if (deviceId.Contains(id) || id.Contains(deviceId))
  51. {
  52. return id;
  53. }
  54. }
  55. }
  56. finally
  57. {
  58. hardwareList.release();
  59. }
  60. return string.Empty;
  61. }
  62. public void onSpeedTest(TRTCSpeedTestResult currentResult, uint finishedCount, uint totalCount)
  63. {
  64. }
  65. public void onTestMicVolume(uint volume)
  66. {
  67. }
  68. public void onTestSpeakerVolume(uint volume)
  69. {
  70. }
  71. public void Dispose()
  72. {
  73. if (_tRTCCloud != null)
  74. {
  75. _tRTCCloud.removeCallback(this);
  76. _deviceManager = null;
  77. _tRTCCloud = null;
  78. }
  79. }
  80. #region Unused
  81. public void onAudioDeviceCaptureVolumeChanged(uint volume, bool muted)
  82. {
  83. // throw new NotImplementedException();
  84. }
  85. public void onAudioDevicePlayoutVolumeChanged(uint volume, bool muted)
  86. {
  87. // throw new NotImplementedException();
  88. }
  89. public void onAudioEffectFinished(int effectId, int code)
  90. {
  91. // throw new NotImplementedException();
  92. }
  93. public void onCameraDidReady()
  94. {
  95. Logger.WriteLineInfo("onCameraDidReady Invoke");
  96. }
  97. public void onConnectionLost()
  98. {
  99. // throw new NotImplementedException();
  100. }
  101. public void onConnectionRecovery()
  102. {
  103. // throw new NotImplementedException();
  104. }
  105. public void onConnectOtherRoom(string userId, TXLiteAVError errCode, string errMsg)
  106. {
  107. // throw new NotImplementedException();
  108. }
  109. public void onDeviceChange(string deviceId, TRTCDeviceType type, TRTCDeviceState state)
  110. {
  111. Logger.WriteLineInfo($"Camera Detector DeviceChange:{deviceId},type:{type},state:{state}");
  112. if (type == TRTCDeviceType.TXMediaDeviceTypeCamera)
  113. {
  114. DeviceUpdated?.Invoke(this, new TRTCDeviceInfo(deviceId, type, state));
  115. }
  116. }
  117. public void onDisconnectOtherRoom(TXLiteAVError errCode, string errMsg)
  118. {
  119. //throw new NotImplementedException();
  120. }
  121. public void onEnterRoom(int result)
  122. {
  123. //throw new NotImplementedException();
  124. }
  125. public void onError(TXLiteAVError errCode, string errMsg, IntPtr arg)
  126. {
  127. //throw new NotImplementedException();
  128. }
  129. public void onExitRoom(int reason)
  130. {
  131. //throw new NotImplementedException();
  132. }
  133. public void onFirstAudioFrame(string userId)
  134. {
  135. // throw new NotImplementedException();
  136. }
  137. public void onFirstVideoFrame(string userId, TRTCVideoStreamType streamType, int width, int height)
  138. {
  139. // throw new NotImplementedException();
  140. }
  141. public void onMicDidReady()
  142. {
  143. // throw new NotImplementedException();
  144. }
  145. public void onMissCustomCmdMsg(string userId, int cmdId, int errCode, int missed)
  146. {
  147. // throw new NotImplementedException();
  148. }
  149. public void onNetworkQuality(TRTCQualityInfo localQuality, TRTCQualityInfo[] remoteQuality, uint remoteQualityCount)
  150. {
  151. // throw new NotImplementedException();
  152. }
  153. public void onPlayBGMBegin(TXLiteAVError errCode)
  154. {
  155. // throw new NotImplementedException();
  156. }
  157. public void onPlayBGMComplete(TXLiteAVError errCode)
  158. {
  159. // throw new NotImplementedException();
  160. }
  161. public void onPlayBGMProgress(uint progressMS, uint durationMS)
  162. {
  163. // throw new NotImplementedException();
  164. }
  165. public void onRecvCustomCmdMsg(string userId, int cmdID, uint seq, byte[] msg, uint msgSize)
  166. {
  167. // throw new NotImplementedException();
  168. }
  169. public void onRecvSEIMsg(string userId, byte[] message, uint msgSize)
  170. {
  171. // throw new NotImplementedException();
  172. }
  173. public void onRemoteUserEnterRoom(string userId)
  174. {
  175. // throw new NotImplementedException();
  176. }
  177. public void onRemoteUserLeaveRoom(string userId, int reason)
  178. {
  179. // throw new NotImplementedException();
  180. }
  181. public void onScreenCaptureCovered()
  182. {
  183. // throw new NotImplementedException();
  184. }
  185. public void onScreenCapturePaused(int reason)
  186. {
  187. // throw new NotImplementedException();
  188. }
  189. public void onScreenCaptureResumed(int reason)
  190. {
  191. // throw new NotImplementedException();
  192. }
  193. public void onScreenCaptureStarted()
  194. {
  195. // throw new NotImplementedException();
  196. }
  197. public void onScreenCaptureStoped(int reason)
  198. {
  199. // throw new NotImplementedException();
  200. }
  201. public void onSendFirstLocalAudioFrame()
  202. {
  203. // throw new NotImplementedException();
  204. }
  205. public void onSendFirstLocalVideoFrame(TRTCVideoStreamType streamType)
  206. {
  207. // throw new NotImplementedException();
  208. }
  209. public void onSetMixTranscodingConfig(int errCode, string errMsg)
  210. {
  211. //throw new NotImplementedException();
  212. }
  213. public void onStartPublishCDNStream(int errCode, string errMsg)
  214. {
  215. // throw new NotImplementedException();
  216. }
  217. public void onStartPublishing(int errCode, string errMsg)
  218. {
  219. // throw new NotImplementedException();
  220. }
  221. public void onStatistics(TRTCStatistics statis)
  222. {
  223. //throw new NotImplementedException();
  224. }
  225. public void onStopPublishCDNStream(int errCode, string errMsg)
  226. {
  227. // throw new NotImplementedException();
  228. }
  229. public void onStopPublishing(int errCode, string errMsg)
  230. {
  231. // throw new NotImplementedException();
  232. }
  233. public void onSwitchRole(TXLiteAVError errCode, string errMsg)
  234. {
  235. // throw new NotImplementedException();
  236. }
  237. public void onSwitchRoom(TXLiteAVError errCode, string errMsg)
  238. {
  239. // throw new NotImplementedException();
  240. }
  241. public void onTryToReconnect()
  242. {
  243. // throw new NotImplementedException();
  244. }
  245. public void onUserAudioAvailable(string userId, bool available)
  246. {
  247. // throw new NotImplementedException();
  248. }
  249. public void onUserEnter(string userId)
  250. {
  251. // throw new NotImplementedException();
  252. }
  253. public void onUserExit(string userId, int reason)
  254. {
  255. // throw new NotImplementedException();
  256. }
  257. public void onUserSubStreamAvailable(string userId, bool available)
  258. {
  259. // throw new NotImplementedException();
  260. }
  261. public void onUserVideoAvailable(string userId, bool available)
  262. {
  263. // throw new NotImplementedException();
  264. }
  265. public void onUserVoiceVolume(TRTCVolumeInfo[] userVolumes, uint userVolumesCount, uint totalVolume)
  266. {
  267. // throw new NotImplementedException();
  268. }
  269. public void onWarning(TXLiteAVWarning warningCode, string warningMsg, IntPtr arg)
  270. {
  271. // throw new NotImplementedException();
  272. }
  273. #endregion Unused
  274. }
  275. }