USRtcMergePusherV2.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using Com.Tencent.Trtc;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Vinno.FIS.TRTCClient.Common.Enum;
  6. using Vinno.vCloud.FIS.CrossPlatform.Common;
  7. using Vinno.vCloud.FIS.CrossPlatform.Common.Enum;
  8. using Vinno.vCloud.FIS.CrossPlatform.Common.LiveVideo;
  9. namespace Vinno.vCloud.FIS.CrossPlatform.Android.LiveVideo.RTC
  10. {
  11. public class USRtcMergePusherV2 : USMergePusherBaseV2
  12. {
  13. private TRTCPusher _pusher;
  14. private int _videoResolution;
  15. public USRtcMergePusherV2() : base()
  16. {
  17. IsTRTCMode = true;
  18. InitCacheImage(true);
  19. }
  20. public override bool StartPusher(IExtendedData pushParams, IEnumerable<CPVideoDeviceOutputInfo> deviceInfos)
  21. {
  22. try
  23. {
  24. var rtcParams = pushParams as RtcExtendedData;
  25. if (rtcParams == null || rtcParams.AppId == 0 || rtcParams.UserInfos.Count == 0)
  26. {
  27. CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RTC Merge Extended Data Is Null!");
  28. return false;
  29. }
  30. _videoResolution = TRTCCloudDef.TrtcVideoResolution1280720;
  31. _pusher = new TRTCPusher();
  32. _pusher.FirstFrameSend += OnFirstFrameSend;
  33. var userInfo = rtcParams.UserInfos?.FirstOrDefault(f => f.Category == EnumLiveChannelCategory.Main) ?? rtcParams.UserInfos?.FirstOrDefault();
  34. _pusher.EnterRoom(userInfo.UserId, rtcParams.RoomId, userInfo.UserSign, rtcParams.AppId, _videoResolution, userInfo.VideoFps, userInfo.VideoBitrate, userInfo.MinVideoBitrate, pushParams.IsMute, pushParams.MicDeviceId);
  35. return base.StartPusher(pushParams, deviceInfos);
  36. }
  37. catch (Exception e)
  38. {
  39. CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Start Rtc Merge Pusher Error:{e}");
  40. }
  41. return false;
  42. }
  43. public override void SetMute(bool isMute)
  44. {
  45. _pusher?.SetMute(isMute);
  46. }
  47. public override void SwitchMic(string micId)
  48. {
  49. _pusher?.SwitchMic(micId);
  50. }
  51. private void OnFirstFrameSend(object sender, EventArgs e)
  52. {
  53. PushLiveStateChanged();
  54. }
  55. public override bool StopPusher()
  56. {
  57. try
  58. {
  59. base.StopPusher();
  60. if (_pusher != null)
  61. {
  62. _pusher.FirstFrameSend -= OnFirstFrameSend;
  63. _pusher.ExitRoom();
  64. }
  65. return true;
  66. }
  67. catch (Exception e)
  68. {
  69. CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Stop Pusher Error:{e}");
  70. }
  71. return false;
  72. }
  73. protected override unsafe void DealWithFullBuffer(ImageFrameData frame)
  74. {
  75. _pusher?.SendData(MergeWidth, MergeHeight, frame.Data);
  76. }
  77. protected override EnumArea GetArea(EnumLiveChannelCategory category)
  78. {
  79. if (category == EnumLiveChannelCategory.Main)
  80. {
  81. return EnumArea.Main;
  82. }
  83. if (category == EnumLiveChannelCategory.Auxiliary1)
  84. {
  85. return EnumArea.Bottom;
  86. }
  87. throw new Exception($"RTC Can not get correct area by category:{category}");
  88. }
  89. public override void DoDispose()
  90. {
  91. _pusher?.Dispose();
  92. base.DoDispose();
  93. }
  94. }
  95. }