AudioDeviceManager.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. namespace Agora.Rtc
  2. {
  3. public sealed class AudioDeviceManager : IAudioDeviceManager
  4. {
  5. private IRtcEngine _rtcEngineInstance = null;
  6. private AudioDeviceManagerImpl _audioDeviecManagerImpl = null;
  7. private const int ErrorCode = -7;
  8. private AudioDeviceManager(IRtcEngine rtcEngine, AudioDeviceManagerImpl impl)
  9. {
  10. _rtcEngineInstance = rtcEngine;
  11. _audioDeviecManagerImpl = impl;
  12. }
  13. ~AudioDeviceManager()
  14. {
  15. _rtcEngineInstance = null;
  16. }
  17. private static IAudioDeviceManager instance = null;
  18. public static IAudioDeviceManager Instance
  19. {
  20. get
  21. {
  22. return instance;
  23. }
  24. }
  25. #region PlaybackDevices
  26. public override DeviceInfo[] EnumeratePlaybackDevices()
  27. {
  28. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  29. {
  30. return null;
  31. }
  32. return _audioDeviecManagerImpl.EnumeratePlaybackDevices();
  33. }
  34. public override int SetPlaybackDevice(string deviceId)
  35. {
  36. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  37. {
  38. return ErrorCode;
  39. }
  40. return _audioDeviecManagerImpl.SetPlaybackDevice(deviceId);
  41. }
  42. public override int GetPlaybackDevice(ref string deviceId)
  43. {
  44. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  45. {
  46. return ErrorCode;
  47. }
  48. return _audioDeviecManagerImpl.GetPlaybackDevice(ref deviceId);
  49. }
  50. public override int GetPlaybackDeviceInfo(ref string deviceId, ref string deviceName)
  51. {
  52. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  53. {
  54. return ErrorCode;
  55. }
  56. return _audioDeviecManagerImpl.GetPlaybackDeviceInfo(ref deviceId, ref deviceName);
  57. }
  58. public override int SetPlaybackDeviceVolume(int volume)
  59. {
  60. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  61. {
  62. return ErrorCode;
  63. }
  64. return _audioDeviecManagerImpl.SetPlaybackDeviceVolume(volume);
  65. }
  66. public override int GetPlaybackDeviceVolume(ref int volume)
  67. {
  68. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  69. {
  70. return ErrorCode;
  71. }
  72. return _audioDeviecManagerImpl.GetPlaybackDeviceVolume(ref volume);
  73. }
  74. public override int SetPlaybackDeviceMute(bool mute)
  75. {
  76. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  77. {
  78. return ErrorCode;
  79. }
  80. return _audioDeviecManagerImpl.SetPlaybackDeviceMute(mute);
  81. }
  82. public override int GetPlaybackDeviceMute(ref bool mute)
  83. {
  84. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  85. {
  86. return ErrorCode;
  87. }
  88. return _audioDeviecManagerImpl.GetPlaybackDeviceMute(ref mute);
  89. }
  90. public override int StartPlaybackDeviceTest(string testAudioFilePath)
  91. {
  92. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  93. {
  94. return ErrorCode;
  95. }
  96. return _audioDeviecManagerImpl.StartPlaybackDeviceTest(testAudioFilePath);
  97. }
  98. public override int StopPlaybackDeviceTest()
  99. {
  100. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  101. {
  102. return ErrorCode;
  103. }
  104. return _audioDeviecManagerImpl.StopPlaybackDeviceTest();
  105. }
  106. public override int FollowSystemPlaybackDevice(bool enable)
  107. {
  108. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  109. {
  110. return ErrorCode;
  111. }
  112. return _audioDeviecManagerImpl.FollowSystemPlaybackDevice(enable);
  113. }
  114. #endregion
  115. #region RecordingDevices
  116. public override DeviceInfo[] EnumerateRecordingDevices()
  117. {
  118. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  119. {
  120. return null;
  121. }
  122. return _audioDeviecManagerImpl.EnumerateRecordingDevices();
  123. }
  124. public override int SetRecordingDevice(string deviceId)
  125. {
  126. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  127. {
  128. return ErrorCode;
  129. }
  130. return _audioDeviecManagerImpl.SetRecordingDevice(deviceId);
  131. }
  132. public override int GetRecordingDevice(ref string deviceId)
  133. {
  134. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  135. {
  136. return ErrorCode;
  137. }
  138. return _audioDeviecManagerImpl.GetRecordingDevice(ref deviceId);
  139. }
  140. public override int GetRecordingDeviceInfo(ref string deviceId, ref string deviceName)
  141. {
  142. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  143. {
  144. return ErrorCode;
  145. }
  146. return _audioDeviecManagerImpl.GetRecordingDeviceInfo(ref deviceId, ref deviceName);
  147. }
  148. public override int SetRecordingDeviceVolume(int volume)
  149. {
  150. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  151. {
  152. return ErrorCode;
  153. }
  154. return _audioDeviecManagerImpl.SetRecordingDeviceVolume(volume);
  155. }
  156. public override int GetRecordingDeviceVolume(ref int volume)
  157. {
  158. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  159. {
  160. return ErrorCode;
  161. }
  162. return _audioDeviecManagerImpl.GetRecordingDeviceVolume(ref volume);
  163. }
  164. public override int SetRecordingDeviceMute(bool mute)
  165. {
  166. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  167. {
  168. return ErrorCode;
  169. }
  170. return _audioDeviecManagerImpl.SetRecordingDeviceMute(mute);
  171. }
  172. public override int GetRecordingDeviceMute(ref bool mute)
  173. {
  174. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  175. {
  176. return ErrorCode;
  177. }
  178. return _audioDeviecManagerImpl.GetRecordingDeviceMute(ref mute);
  179. }
  180. public override int StartRecordingDeviceTest(int indicationInterval)
  181. {
  182. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  183. {
  184. return ErrorCode;
  185. }
  186. return _audioDeviecManagerImpl.StartRecordingDeviceTest(indicationInterval);
  187. }
  188. public override int StopRecordingDeviceTest()
  189. {
  190. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  191. {
  192. return ErrorCode;
  193. }
  194. return _audioDeviecManagerImpl.StopRecordingDeviceTest();
  195. }
  196. public override int FollowSystemRecordingDevice(bool enable)
  197. {
  198. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  199. {
  200. return ErrorCode;
  201. }
  202. return _audioDeviecManagerImpl.FollowSystemRecordingDevice(enable);
  203. }
  204. #endregion
  205. #region AudioDevice
  206. public override int StartAudioDeviceLoopbackTest(int indicationInterval)
  207. {
  208. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  209. {
  210. return ErrorCode;
  211. }
  212. return _audioDeviecManagerImpl.StartAudioDeviceLoopbackTest(indicationInterval);
  213. }
  214. public override int StopAudioDeviceLoopbackTest()
  215. {
  216. if (_rtcEngineInstance == null || _audioDeviecManagerImpl == null)
  217. {
  218. return ErrorCode;
  219. }
  220. return _audioDeviecManagerImpl.StopAudioDeviceLoopbackTest();
  221. }
  222. #endregion
  223. internal static IAudioDeviceManager GetInstance(IRtcEngine rtcEngine, AudioDeviceManagerImpl impl)
  224. {
  225. return instance ?? (instance = new AudioDeviceManager(rtcEngine, impl));
  226. }
  227. internal static void ReleaseInstance()
  228. {
  229. instance = null;
  230. }
  231. }
  232. }