USRtcMergePusherV2.cs 3.6 KB

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