VideoDeviceManager.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. namespace Agora.Rtc
  3. {
  4. public sealed class VideoDeviceManager : IVideoDeviceManager
  5. {
  6. private IRtcEngine _rtcEngineInstance = null;
  7. private VideoDeviceManagerImpl _videoDeviecManagerImpl = null;
  8. private const int ErrorCode = -7;
  9. private VideoDeviceManager(IRtcEngine rtcEngine, VideoDeviceManagerImpl impl)
  10. {
  11. _rtcEngineInstance = rtcEngine;
  12. _videoDeviecManagerImpl = impl;
  13. }
  14. ~VideoDeviceManager()
  15. {
  16. _rtcEngineInstance = null;
  17. }
  18. private static IVideoDeviceManager instance = null;
  19. public static IVideoDeviceManager Instance
  20. {
  21. get
  22. {
  23. return instance;
  24. }
  25. }
  26. public override DeviceInfo[] EnumerateVideoDevices()
  27. {
  28. if (_rtcEngineInstance == null || _videoDeviecManagerImpl == null)
  29. {
  30. return null;
  31. }
  32. return _videoDeviecManagerImpl.EnumerateVideoDevices();
  33. }
  34. public override int SetDevice(string deviceIdUTF8)
  35. {
  36. if (_rtcEngineInstance == null || _videoDeviecManagerImpl == null)
  37. {
  38. return ErrorCode;
  39. }
  40. return _videoDeviecManagerImpl.SetDevice(deviceIdUTF8);
  41. }
  42. public override int GetDevice(ref string deviceIdUTF8)
  43. {
  44. if (_rtcEngineInstance == null || _videoDeviecManagerImpl == null)
  45. {
  46. return ErrorCode;
  47. }
  48. return _videoDeviecManagerImpl.GetDevice(ref deviceIdUTF8);
  49. }
  50. public override int StartDeviceTest(IntPtr hwnd)
  51. {
  52. if (_rtcEngineInstance == null || _videoDeviecManagerImpl == null)
  53. {
  54. return ErrorCode;
  55. }
  56. return _videoDeviecManagerImpl.StartDeviceTest(hwnd);
  57. }
  58. public override int StopDeviceTest()
  59. {
  60. if (_rtcEngineInstance == null || _videoDeviecManagerImpl == null)
  61. {
  62. return ErrorCode;
  63. }
  64. return _videoDeviecManagerImpl.StopDeviceTest();
  65. }
  66. public override int GetCapability(string deviceIdUTF8, uint deviceCapabilityNumber, out VideoFormat capability)
  67. {
  68. if (_rtcEngineInstance == null || _videoDeviecManagerImpl == null)
  69. {
  70. capability = new VideoFormat();
  71. return ErrorCode;
  72. }
  73. return _videoDeviecManagerImpl.GetCapability(deviceIdUTF8, deviceCapabilityNumber, out capability);
  74. }
  75. public override int NumberOfCapabilities(string deviceIdUTF8)
  76. {
  77. if (_rtcEngineInstance == null || _videoDeviecManagerImpl == null)
  78. {
  79. return ErrorCode;
  80. }
  81. return _videoDeviecManagerImpl.NumberOfCapabilities(deviceIdUTF8);
  82. }
  83. internal static IVideoDeviceManager GetInstance(IRtcEngine rtcEngine, VideoDeviceManagerImpl impl)
  84. {
  85. return instance ?? (instance = new VideoDeviceManager(rtcEngine, impl));
  86. }
  87. internal static void ReleaseInstance()
  88. {
  89. instance = null;
  90. }
  91. }
  92. }