RtmpMergePusherV2.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Vinno.FIS.TRTCClient.Common.Enum;
  5. using Vinno.vCloud.FIS.CrossPlatform.Common;
  6. using Vinno.vCloud.FIS.CrossPlatform.Common.Enum;
  7. using Vinno.vCloud.FIS.CrossPlatform.Common.LiveVideo;
  8. namespace Vinno.vCloud.FIS.CrossPlatform.Android.LiveVideo.RTMP
  9. {
  10. public class RtmpMergePusherV2 : MergePusherBaseV2
  11. {
  12. private DaniuPusher _pusher;
  13. public RtmpMergePusherV2()
  14. {
  15. IsTRTCMode = false;
  16. InitCacheImage(false);
  17. }
  18. public override bool StartPusher(IExtendedData pushParams, IEnumerable<CPVideoDeviceOutputInfo> deviceInfos)
  19. {
  20. try
  21. {
  22. var rtmpParams = pushParams as RtmpExtendedData;
  23. if (rtmpParams == null || rtmpParams.UserInfos.Count == 0)
  24. {
  25. CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RtmpMergePusherV2 Extended Data Is Null!");
  26. return false;
  27. }
  28. var url = rtmpParams.UserInfos.FirstOrDefault()?.PushUrl;
  29. if (string.IsNullOrEmpty(url))
  30. {
  31. CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RtmpMergePusherV2 Push Url Is Null!");
  32. return false;
  33. }
  34. var micIndex = CrossPlatformHelper.Instance.HardwareDetector.GetMicIndex(pushParams.MicDeviceId);
  35. _pusher = new DaniuPusher(url, MergeWidth, MergeHeight, MergeFrameRate, EnumAudioMode.Mic, pushParams.IsMute);
  36. _pusher.StatusChanged += OnStatusChanged;
  37. _pusher.StartPush();
  38. return base.StartPusher(pushParams, deviceInfos);
  39. }
  40. catch (Exception e)
  41. {
  42. CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Start RtmpMergePusherV2 Error:{e}");
  43. }
  44. return false;
  45. }
  46. public override void SetMute(bool isMute)
  47. {
  48. _pusher?.SetMute(isMute);
  49. }
  50. public override bool StopPusher()
  51. {
  52. try
  53. {
  54. base.StopPusher();
  55. if (_pusher != null)
  56. {
  57. _pusher.StatusChanged -= OnStatusChanged;
  58. _pusher.StopPush();
  59. }
  60. return true;
  61. }
  62. catch (Exception e)
  63. {
  64. CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Stop RtmpMergePusherV2 Error:{e}");
  65. }
  66. return false;
  67. }
  68. private void OnStatusChanged(object sender, CPLiveStatusData e)
  69. {
  70. if (e.Status == EnumLiveStatus.Connected)
  71. {
  72. PushLiveStateChanged();
  73. }
  74. }
  75. protected override unsafe void DealWithFullBuffer(ImageFrameData frame)
  76. {
  77. _pusher?.PushImage(frame);
  78. }
  79. protected override EnumArea GetArea(EnumLiveChannelCategory category)
  80. {
  81. if (category == EnumLiveChannelCategory.Main)
  82. {
  83. return EnumArea.Main;
  84. }
  85. if (category == EnumLiveChannelCategory.Auxiliary1)
  86. {
  87. return EnumArea.RightUp;
  88. }
  89. if (category == EnumLiveChannelCategory.Auxiliary2)
  90. {
  91. return EnumArea.RightDown;
  92. }
  93. if (category == EnumLiveChannelCategory.Auxiliary3)
  94. {
  95. return EnumArea.BottomCenter;
  96. }
  97. throw new Exception($"RTMP Can not get correct area by category:{category}");
  98. }
  99. public override void DoDispose()
  100. {
  101. StopPusher();
  102. base.DoDispose();
  103. }
  104. public override void SwitchMic(string micId)
  105. {
  106. }
  107. }
  108. }