VideoDeviceManagerImpl.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. namespace Agora.Rtc
  3. {
  4. using IrisApiEnginePtr = IntPtr;
  5. using view_t = IntPtr;
  6. internal class VideoDeviceManagerImpl
  7. {
  8. private bool _disposed = false;
  9. private IrisApiEnginePtr _irisApiEngine;
  10. private CharAssistant _result;
  11. internal VideoDeviceManagerImpl(IrisApiEnginePtr irisApiEngine)
  12. {
  13. _result = new CharAssistant();
  14. _irisApiEngine = irisApiEngine;
  15. }
  16. ~VideoDeviceManagerImpl()
  17. {
  18. Dispose(false);
  19. }
  20. internal void Dispose()
  21. {
  22. Dispose(true);
  23. GC.SuppressFinalize(this);
  24. }
  25. internal void Dispose(bool disposing)
  26. {
  27. if (_disposed) return;
  28. if (disposing)
  29. {
  30. }
  31. _irisApiEngine = IntPtr.Zero;
  32. _result = new CharAssistant();
  33. _disposed = true;
  34. }
  35. public DeviceInfo[] EnumerateVideoDevices()
  36. {
  37. return AgoraRtcNative.CallIrisApi(_irisApiEngine,
  38. AgoraApiType.FUNC_VIDEODEVICEMANAGER_ENUMERATEVIDEODEVICES,
  39. "", 0, IntPtr.Zero, 0, out _result) != 0
  40. ? new DeviceInfo[0]
  41. : AgoraJson.JsonToStructArray<DeviceInfo>(_result.Result, "result");
  42. }
  43. public int SetDevice(string deviceIdUTF8)
  44. {
  45. var param = new
  46. {
  47. deviceIdUTF8
  48. };
  49. string jsonParam = AgoraJson.ToJson(param);
  50. var ret = AgoraRtcNative.CallIrisApi(_irisApiEngine,
  51. AgoraApiType.FUNC_VIDEODEVICEMANAGER_SETDEVICE,
  52. jsonParam, (UInt32)jsonParam.Length, IntPtr.Zero, 0, out _result);
  53. return ret != 0 ? ret : (int)AgoraJson.GetData<int>(_result.Result, "result");
  54. }
  55. public int GetDevice(ref string deviceIdUTF8)
  56. {
  57. var ret = AgoraRtcNative.CallIrisApi(_irisApiEngine,
  58. AgoraApiType.FUNC_VIDEODEVICEMANAGER_GETDEVICE,
  59. "", 0, IntPtr.Zero, 0, out _result);
  60. if (ret == 0)
  61. {
  62. deviceIdUTF8 = (string)AgoraJson.GetData<string>(_result.Result, "deviceIdUTF8");
  63. }
  64. else
  65. {
  66. deviceIdUTF8 = "";
  67. }
  68. return ret != 0 ? ret : (int)AgoraJson.GetData<int>(_result.Result, "result");
  69. }
  70. public int StartDeviceTest(view_t hwnd)
  71. {
  72. var param = new
  73. {
  74. hwnd = (ulong)hwnd
  75. };
  76. string jsonParam = AgoraJson.ToJson(param);
  77. var ret = AgoraRtcNative.CallIrisApi(_irisApiEngine,
  78. AgoraApiType.FUNC_VIDEODEVICEMANAGER_STARTDEVICETEST,
  79. jsonParam, (UInt32)jsonParam.Length, IntPtr.Zero, 0, out _result);
  80. return ret != 0 ? ret : (int)AgoraJson.GetData<int>(_result.Result, "result");
  81. }
  82. public int StopDeviceTest()
  83. {
  84. var ret = AgoraRtcNative.CallIrisApi(_irisApiEngine,
  85. AgoraApiType.FUNC_VIDEODEVICEMANAGER_STOPDEVICETEST,
  86. "", 0, IntPtr.Zero, 0, out _result);
  87. return ret != 0 ? ret : (int)AgoraJson.GetData<int>(_result.Result, "result");
  88. }
  89. public int GetCapability(string deviceIdUTF8, uint deviceCapabilityNumber, out VideoFormat capability)
  90. {
  91. var param = new
  92. {
  93. deviceIdUTF8,
  94. deviceCapabilityNumber
  95. };
  96. string jsonParam = AgoraJson.ToJson(param);
  97. var ret = AgoraRtcNative.CallIrisApi(_irisApiEngine,
  98. AgoraApiType.FUNC_VIDEODEVICEMANAGER_GETCAPABILITY,
  99. jsonParam, 0, IntPtr.Zero, 0, out _result);
  100. if (ret == 0)
  101. {
  102. capability = AgoraJson.JsonToStruct<VideoFormat>(_result.Result, "capability");
  103. }
  104. else
  105. {
  106. capability = new VideoFormat();
  107. }
  108. return ret != 0 ? ret : (int)AgoraJson.GetData<int>(_result.Result, "result");
  109. }
  110. public int NumberOfCapabilities(string deviceIdUTF8)
  111. {
  112. var param = new
  113. {
  114. deviceIdUTF8,
  115. };
  116. string jsonParam = AgoraJson.ToJson(param);
  117. var ret = AgoraRtcNative.CallIrisApi(_irisApiEngine,
  118. AgoraApiType.FUNC_VIDEODEVICEMANAGER_NUMBEROFCAPABILITIES,
  119. jsonParam, 0, IntPtr.Zero, 0, out _result);
  120. return ret != 0 ? ret : (int)AgoraJson.GetData<int>(_result.Result, "result");
  121. }
  122. }
  123. }