RTC.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /*******************************************************************************
  2. Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
  3. NOTICE:All information contained herein is, and remains the property of
  4. PICO Technology Co., Ltd. The intellectual and technical concepts
  5. contained herein are proprietary to PICO Technology Co., Ltd. and may be
  6. covered by patents, patents in process, and are protected by trade secret or
  7. copyright law. Dissemination of this information or reproduction of this
  8. material is strictly forbidden unless prior written permission is obtained from
  9. PICO Technology Co., Ltd.
  10. *******************************************************************************/
  11. using System;
  12. using System.Runtime.InteropServices;
  13. namespace Pico.Platform.Models
  14. {
  15. /// <summary>
  16. /// The binary message received in a RTC room.
  17. /// </summary>
  18. public class RtcBinaryMessageReceived
  19. {
  20. /// The message sender's user ID.
  21. public readonly string UserId;
  22. /// The binary data of the message.
  23. public readonly byte[] Data;
  24. /// The ID of the room that the message is sent to.
  25. public readonly string RoomId;
  26. public RtcBinaryMessageReceived(IntPtr o)
  27. {
  28. UserId = CLIB.ppf_RtcBinaryMessageReceived_GetUserId(o);
  29. var ptr = CLIB.ppf_RtcBinaryMessageReceived_GetData(o);
  30. var sz = CLIB.ppf_RtcBinaryMessageReceived_GetLength(o);
  31. Data = MarshalUtil.ByteArrayFromNative(ptr, (uint) sz);
  32. RoomId = CLIB.ppf_RtcBinaryMessageReceived_GetRoomId(o);
  33. }
  34. }
  35. /// <summary>
  36. /// The audio frame is several frames of RTC recorded audio.
  37. /// </summary>
  38. public class RtcAudioFrame
  39. {
  40. /// The type of the audio channel for this audio frame.
  41. public readonly RtcAudioChannel Channel;
  42. /// The data pointer of the audio frame.
  43. public readonly IntPtr Data;
  44. /// The size of the data.
  45. public readonly long DataSize;
  46. /// The sample rate of the data.
  47. public readonly RtcAudioSampleRate SampleRate;
  48. /// The timestamp.Its value is always 0. So don't use it.
  49. public readonly long TimeStampInUs;
  50. public RtcAudioFrame(IntPtr o)
  51. {
  52. Channel = CLIB.ppf_RtcAudioFrame_GetChannel(o);
  53. DataSize = CLIB.ppf_RtcAudioFrame_GetDataSize(o);
  54. SampleRate = CLIB.ppf_RtcAudioFrame_GetSampleRate(o);
  55. TimeStampInUs = CLIB.ppf_RtcAudioFrame_GetTimeStampInUs(o);
  56. Data = CLIB.ppf_RtcAudioFrame_GetData(o);
  57. }
  58. public byte[] GetData()
  59. {
  60. return MarshalUtil.ByteArrayFromNative(this.Data, (uint) this.DataSize);
  61. }
  62. public void SetData(byte[] data)
  63. {
  64. Marshal.Copy(data, 0, this.Data, (int) this.DataSize);
  65. }
  66. }
  67. /// <summary>
  68. /// The message sending result that indicates whether the message is successfully sent.
  69. /// </summary>
  70. public class RtcMessageSendResult
  71. {
  72. /// The message ID.
  73. public readonly long MessageId;
  74. /// The error code returned in the result. `200` means success.
  75. public readonly int Error;
  76. /// The ID of the room that the message is sent to.
  77. public readonly string RoomId;
  78. public RtcMessageSendResult(IntPtr o)
  79. {
  80. MessageId = CLIB.ppf_RtcMessageSendResult_GetMessageId(o);
  81. Error = CLIB.ppf_RtcMessageSendResult_GetError(o);
  82. RoomId = CLIB.ppf_RtcMessageSendResult_GetRoomId(o);
  83. }
  84. }
  85. /// <summary>
  86. /// When the remote user canceled publshing stream to the room, you will receive a notification.
  87. /// </summary>
  88. public class RtcUserUnPublishInfo
  89. {
  90. /// The ID of the remote user.
  91. public readonly string UserId;
  92. /// The stream type.
  93. public readonly RtcMediaStreamType MediaStreamType;
  94. /// The reason why the remote user canceled publishing stream.
  95. public readonly RtcStreamRemoveReason Reason;
  96. /// The ID of the room that the remote user is in.
  97. public readonly string RoomId;
  98. public RtcUserUnPublishInfo(IntPtr o)
  99. {
  100. UserId = CLIB.ppf_RtcUserUnPublishInfo_GetUserId(o);
  101. MediaStreamType = CLIB.ppf_RtcUserUnPublishInfo_GetMediaStreamType(o);
  102. Reason = CLIB.ppf_RtcUserUnPublishInfo_GetReason(o);
  103. RoomId = CLIB.ppf_RtcUserUnPublishInfo_GetRoomId(o);
  104. }
  105. }
  106. /// <summary>
  107. /// The publish stream info.
  108. /// If the remote user publishes stream, you will receive a notification.
  109. /// </summary>
  110. public class RtcUserPublishInfo
  111. {
  112. /// The ID of the remote user.
  113. public readonly string UserId;
  114. /// The stream type.
  115. public readonly RtcMediaStreamType MediaStreamType;
  116. /// The ID of the room that the remote user is in.
  117. public readonly string RoomId;
  118. public RtcUserPublishInfo(IntPtr o)
  119. {
  120. UserId = CLIB.ppf_RtcUserPublishInfo_GetUserId(o);
  121. MediaStreamType = CLIB.ppf_RtcUserPublishInfo_GetMediaStreamType(o);
  122. RoomId = CLIB.ppf_RtcUserPublishInfo_GetRoomId(o);
  123. }
  124. }
  125. /// <summary>
  126. /// The message received by a certain room.
  127. /// The remote users can send messages to the room and you will receive this message.
  128. /// </summary>
  129. public class RtcRoomMessageReceived
  130. {
  131. /// The ID of the message sender.
  132. public readonly string UserId;
  133. /// The message.
  134. public readonly string Message;
  135. /// The ID of the room that the message was sent to.
  136. public readonly string RoomId;
  137. public RtcRoomMessageReceived(IntPtr o)
  138. {
  139. UserId = CLIB.ppf_RtcRoomMessageReceived_GetUserId(o);
  140. Message = CLIB.ppf_RtcRoomMessageReceived_GetMessage(o);
  141. RoomId = CLIB.ppf_RtcRoomMessageReceived_GetRoomId(o);
  142. }
  143. }
  144. /// <summary>
  145. /// The message sent to you by a certain user. You will receive a notification.
  146. /// </summary>
  147. public class RtcUserMessageReceived
  148. {
  149. /// The ID of the message sender.
  150. public readonly string UserId;
  151. /// The message.
  152. public readonly string Message;
  153. /// The ID of the room that the message sender and recipient are in.
  154. public readonly string RoomId;
  155. public RtcUserMessageReceived(IntPtr o)
  156. {
  157. UserId = CLIB.ppf_RtcUserMessageReceived_GetUserId(o);
  158. Message = CLIB.ppf_RtcUserMessageReceived_GetMessage(o);
  159. RoomId = CLIB.ppf_RtcUserMessageReceived_GetRoomId(o);
  160. }
  161. }
  162. /// <summary>
  163. /// The stream sync info sent to your room. You will receive a notification,
  164. /// </summary>
  165. public class RtcStreamSyncInfo
  166. {
  167. /// The key of the stream.
  168. public readonly RtcRemoteStreamKey StreamKey;
  169. /// The type of the stream.
  170. public readonly RtcSyncInfoStreamType StreamType;
  171. /// The stream sync info
  172. public readonly byte[] Data;
  173. public RtcStreamSyncInfo(IntPtr o)
  174. {
  175. StreamKey = new RtcRemoteStreamKey(CLIB.ppf_RtcStreamSyncInfo_GetStreamKey(o));
  176. StreamType = CLIB.ppf_RtcStreamSyncInfo_GetStreamType(o);
  177. var ptr = CLIB.ppf_RtcStreamSyncInfo_GetData(o);
  178. var sz = CLIB.ppf_RtcStreamSyncInfo_GetLength(o);
  179. Data = MarshalUtil.ByteArrayFromNative(ptr, (uint) sz);
  180. }
  181. }
  182. /// <summary>
  183. /// If you enable audio properties report, you will periodically receive audio property info.
  184. /// </summary>
  185. public class RtcAudioPropertyInfo
  186. {
  187. /// The volume detected. It's a value between `0` and `255`.
  188. public readonly int Volume;
  189. public RtcAudioPropertyInfo(IntPtr o)
  190. {
  191. Volume = CLIB.ppf_RtcAudioPropertyInfo_GetVolume(o);
  192. }
  193. }
  194. /// <summary>
  195. /// You will receive this message after you call \ref RtcService.JoinRoom.
  196. /// </summary>
  197. public class RtcJoinRoomResult
  198. {
  199. /// The ID of the room that the user joined.
  200. public readonly string RoomId;
  201. /// The ID of the user.
  202. public readonly string UserId;
  203. /// The error code. `0` indicates success.
  204. public readonly int ErrorCode;
  205. /// The time from calling \ref RtcService.JoinRoom to receiving the result.
  206. public readonly int Elapsed;
  207. /// Whether it is the first time that the user has joined the room or if the user is reconnected to the room.
  208. public readonly RtcJoinRoomType JoinType;
  209. public RtcJoinRoomResult(IntPtr o)
  210. {
  211. RoomId = CLIB.ppf_RtcJoinRoomResult_GetRoomId(o);
  212. UserId = CLIB.ppf_RtcJoinRoomResult_GetUserId(o);
  213. ErrorCode = CLIB.ppf_RtcJoinRoomResult_GetErrorCode(o);
  214. Elapsed = CLIB.ppf_RtcJoinRoomResult_GetElapsed(o);
  215. JoinType = CLIB.ppf_RtcJoinRoomResult_GetJoinType(o);
  216. }
  217. }
  218. /// <summary>
  219. /// You will receive this message after you call \ref RtcService.LeaveRoom.
  220. /// </summary>
  221. public class RtcLeaveRoomResult
  222. {
  223. /// The ID of the room that the user left.
  224. public readonly string RoomId;
  225. public RtcLeaveRoomResult(IntPtr o)
  226. {
  227. RoomId = CLIB.ppf_RtcLeaveRoomResult_GetRoomId(o);
  228. }
  229. }
  230. /// <summary>
  231. /// The local audio properties info.
  232. /// You will periodically receive this message after you
  233. /// call \ref RtcService.EnableAudioPropertiesReport.
  234. /// </summary>
  235. public class RtcLocalAudioPropertiesInfo
  236. {
  237. /// The stream index info.
  238. public readonly RtcStreamIndex StreamIndex;
  239. /// The audio property details.
  240. public readonly RtcAudioPropertyInfo AudioPropertyInfo;
  241. public RtcLocalAudioPropertiesInfo(IntPtr o)
  242. {
  243. StreamIndex = CLIB.ppf_RtcLocalAudioPropertiesInfo_GetStreamIndex(o);
  244. AudioPropertyInfo = new RtcAudioPropertyInfo(CLIB.ppf_RtcLocalAudioPropertiesInfo_GetAudioPropertyInfo(o));
  245. }
  246. }
  247. /// <summary>
  248. /// The local audio properties report.
  249. /// You will periodically receive this message after you
  250. /// call \ref RtcService.EnableAudioPropertiesReport.
  251. /// </summary>
  252. public class RtcLocalAudioPropertiesReport
  253. {
  254. public readonly RtcLocalAudioPropertiesInfo[] AudioPropertiesInfos;
  255. public RtcLocalAudioPropertiesReport(IntPtr o)
  256. {
  257. ulong total = (ulong) CLIB.ppf_RtcLocalAudioPropertiesReport_GetAudioPropertiesInfosSize(o);
  258. AudioPropertiesInfos = new RtcLocalAudioPropertiesInfo[total];
  259. for (uint i = 0; i < total; i++)
  260. {
  261. AudioPropertiesInfos[i] = new RtcLocalAudioPropertiesInfo(CLIB.ppf_RtcLocalAudioPropertiesReport_GetAudioPropertiesInfos(o, (UIntPtr) i));
  262. }
  263. }
  264. }
  265. /// <summary>
  266. /// The media device change info.
  267. /// RTC engine will send this message if media device change is detected.
  268. /// </summary>
  269. public class RtcMediaDeviceChangeInfo
  270. {
  271. /// <summary>
  272. /// Device ID.
  273. /// </summary>
  274. public readonly string DeviceId;
  275. /// <summary>
  276. /// Device type.
  277. /// </summary>
  278. public readonly RtcMediaDeviceType DeviceType;
  279. /// <summary>
  280. /// Device state.
  281. /// </summary>
  282. public readonly RtcMediaDeviceState DeviceState;
  283. /// <summary>
  284. /// Device error.
  285. /// </summary>
  286. public readonly RtcMediaDeviceError DeviceError;
  287. public RtcMediaDeviceChangeInfo(IntPtr o)
  288. {
  289. DeviceId = CLIB.ppf_RtcMediaDeviceChangeInfo_GetDeviceId(o);
  290. DeviceType = CLIB.ppf_RtcMediaDeviceChangeInfo_GetDeviceType(o);
  291. DeviceState = CLIB.ppf_RtcMediaDeviceChangeInfo_GetDeviceState(o);
  292. DeviceError = CLIB.ppf_RtcMediaDeviceChangeInfo_GetDeviceError(o);
  293. }
  294. }
  295. /// <summary>
  296. /// You will receive this notification if the remote user call \ref RtcService.MuteLocalAudio.
  297. /// </summary>
  298. public class RtcMuteInfo
  299. {
  300. /// The ID of the remote user who muted audio.
  301. public readonly string UserId;
  302. /// The state of audio muting: muted or canceled.
  303. public readonly RtcMuteState MuteState;
  304. public RtcMuteInfo(IntPtr o)
  305. {
  306. UserId = CLIB.ppf_RtcMuteInfo_GetUserId(o);
  307. MuteState = CLIB.ppf_RtcMuteInfo_GetMuteState(o);
  308. }
  309. }
  310. /// <summary>
  311. /// The remote audio properties info.
  312. /// You can check who is speaking by this method.
  313. /// </summary>
  314. public class RtcRemoteAudioPropertiesInfo
  315. {
  316. public readonly RtcRemoteStreamKey StreamKey;
  317. public readonly RtcAudioPropertyInfo AudioPropertiesInfo;
  318. public RtcRemoteAudioPropertiesInfo(IntPtr o)
  319. {
  320. StreamKey = new RtcRemoteStreamKey(CLIB.ppf_RtcRemoteAudioPropertiesInfo_GetStreamKey(o));
  321. AudioPropertiesInfo = new RtcAudioPropertyInfo(CLIB.ppf_RtcRemoteAudioPropertiesInfo_GetAudioPropertiesInfo(o));
  322. }
  323. }
  324. /// <summary>
  325. /// You will receive remote user's audio info if you call \ref RtcService.EnableAudioPropertiesReport.
  326. /// </summary>
  327. public class RtcRemoteAudioPropertiesReport
  328. {
  329. public readonly RtcRemoteAudioPropertiesInfo[] AudioPropertiesInfos;
  330. /// The total volume of remote users in the room.
  331. public readonly int TotalRemoteVolume;
  332. public RtcRemoteAudioPropertiesReport(IntPtr o)
  333. {
  334. AudioPropertiesInfos = new RtcRemoteAudioPropertiesInfo[(int) CLIB.ppf_RtcRemoteAudioPropertiesReport_GetAudioPropertiesInfosSize(o)];
  335. for (uint i = 0; i < AudioPropertiesInfos.Length; i++)
  336. {
  337. AudioPropertiesInfos[i] = new RtcRemoteAudioPropertiesInfo(CLIB.ppf_RtcRemoteAudioPropertiesReport_GetAudioPropertiesInfos(o, (UIntPtr) i));
  338. }
  339. TotalRemoteVolume = CLIB.ppf_RtcRemoteAudioPropertiesReport_GetTotalRemoteVolume(o);
  340. }
  341. }
  342. /// <summary>
  343. /// RtcRemoteStreamKey indicates the stream index of a remote user.
  344. /// </summary>
  345. public class RtcRemoteStreamKey
  346. {
  347. /// The ID of the room that the remote user is in.
  348. public readonly string RoomId;
  349. /// The ID of the remote user.
  350. public readonly string UserId;
  351. /// Indicates whether the stream is main stream or screen stream.
  352. public readonly RtcStreamIndex RtcStreamIndex;
  353. public RtcRemoteStreamKey(IntPtr o)
  354. {
  355. RoomId = CLIB.ppf_RtcRemoteStreamKey_GetRoomId(o);
  356. UserId = CLIB.ppf_RtcRemoteStreamKey_GetUserId(o);
  357. RtcStreamIndex = CLIB.ppf_RtcRemoteStreamKey_GetStreamIndex(o);
  358. }
  359. }
  360. /// <summary>
  361. /// You will receive an error code when an error occurred in the room.
  362. /// </summary>
  363. public class RtcRoomError
  364. {
  365. /// The error code.
  366. public readonly int Code;
  367. /// The ID of the room where the error occurred.
  368. public readonly string RoomId;
  369. public RtcRoomError(IntPtr o)
  370. {
  371. Code = CLIB.ppf_RtcRoomError_GetCode(o);
  372. RoomId = CLIB.ppf_RtcRoomError_GetRoomId(o);
  373. }
  374. }
  375. /// <summary>
  376. /// You will periodically receive this message after you successfully join a room.
  377. /// </summary>
  378. public class RtcRoomStats
  379. {
  380. /// The time elapsed since you joined the room .
  381. public readonly int TotalDuration;
  382. /// The number of users in the room.
  383. public readonly int UserCount;
  384. /// The ID of the room you joined.
  385. public readonly string RoomId;
  386. public RtcRoomStats(IntPtr o)
  387. {
  388. TotalDuration = CLIB.ppf_RtcRoomStats_GetTotalDuration(o);
  389. UserCount = CLIB.ppf_RtcRoomStats_GetUserCount(o);
  390. RoomId = CLIB.ppf_RtcRoomStats_GetRoomId(o);
  391. }
  392. }
  393. /// <summary>
  394. /// The warning info of the room.
  395. /// </summary>
  396. public class RtcRoomWarn
  397. {
  398. /// The error code.
  399. public readonly int Code;
  400. /// The ID of the room that the warning info comes from.
  401. public readonly string RoomId;
  402. public RtcRoomWarn(IntPtr o)
  403. {
  404. Code = CLIB.ppf_RtcRoomWarn_GetCode(o);
  405. RoomId = CLIB.ppf_RtcRoomWarn_GetRoomId(o);
  406. }
  407. }
  408. /// <summary>
  409. /// You will receive this message after a remote user joins the room.
  410. /// </summary>
  411. public class RtcUserJoinInfo
  412. {
  413. /// The ID of the user.
  414. public readonly string UserId;
  415. /// If the remote user set the `UserExtra` field when calling \ref RtcService.JoinRoom with extra info.
  416. public readonly string UserExtra;
  417. /// The time used for the remote user to join the room.
  418. public readonly int Elapsed;
  419. /// The ID of the room that the remote user joined.
  420. public readonly string RoomId;
  421. public RtcUserJoinInfo(IntPtr o)
  422. {
  423. UserId = CLIB.ppf_RtcUserJoinInfo_GetUserId(o);
  424. UserExtra = CLIB.ppf_RtcUserJoinInfo_GetUserExtra(o);
  425. Elapsed = CLIB.ppf_RtcUserJoinInfo_GetElapsed(o);
  426. RoomId = CLIB.ppf_RtcUserJoinInfo_GetRoomId(o);
  427. }
  428. }
  429. /// <summary>
  430. /// You will receive this message when the remote user leaves the room.
  431. /// </summary>
  432. public class RtcUserLeaveInfo
  433. {
  434. /// The ID of the user.
  435. public readonly string UserId;
  436. /// The reason why the user left the room, which can be network error or proactive quit.
  437. public readonly RtcUserLeaveReasonType OfflineReason;
  438. /// The ID of the room that the user left.
  439. public readonly string RoomId;
  440. public RtcUserLeaveInfo(IntPtr o)
  441. {
  442. UserId = CLIB.ppf_RtcUserLeaveInfo_GetUserId(o);
  443. OfflineReason = CLIB.ppf_RtcUserLeaveInfo_GetOfflineReason(o);
  444. RoomId = CLIB.ppf_RtcUserLeaveInfo_GetRoomId(o);
  445. }
  446. }
  447. }
粤ICP备19079148号