using FFmpeg.AutoGen; using ManageLiteAV; using System; using System.Collections.Generic; using System.Linq; using Vinno.FIS.TRTCClient.Common.Enum; using Vinno.vCloud.FIS.CrossPlatform.Common; using Vinno.vCloud.FIS.CrossPlatform.Common.Enum; using Vinno.vCloud.FIS.CrossPlatform.Common.LiveVideo; namespace Vinno.vCloud.FIS.CrossPlatform.Windows.LiveVideo.RTC { public class USRtcMergePusherV2 : USMergePusherBaseV2 { private TRTCPusher _pusher; private TRTCVideoResolution _videoResolution; public USRtcMergePusherV2() : base() { IsTRTCMode = true; InitCacheImage(AVPixelFormat.AV_PIX_FMT_YUV420P); } public override bool StartPusher(IExtendedData pushParams, IEnumerable deviceInfos) { try { var rtcParams = pushParams as RtcExtendedData; if (rtcParams == null || rtcParams.AppId == 0 || rtcParams.UserInfos.Count == 0) { CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RTC Merge Extended Data Is Null!"); return false; } _videoResolution = TRTCVideoResolution.TRTCVideoResolution_1280_720; _pusher = new TRTCPusher(); _pusher.FirstFrameSend += OnFirstFrameSend; var userInfo = rtcParams.UserInfos?.FirstOrDefault(f => f.Category == EnumLiveChannelCategory.Main) ?? rtcParams.UserInfos?.FirstOrDefault(); _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); return base.StartPusher(pushParams, deviceInfos); } catch (Exception e) { CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Start Rtc Merge Pusher Error:{e}"); } return false; } public override void SetMute(bool isMute) { _pusher?.SetMute(isMute); } public override void SwitchMic(string micId) { _pusher?.SwitchMic(micId); } private void OnFirstFrameSend(object sender, EventArgs e) { PushLiveStateChanged(); } public override bool StopPusher() { try { base.StopPusher(); if (_pusher != null) { _pusher.FirstFrameSend -= OnFirstFrameSend; _pusher.ExitRoom(); } return true; } catch (Exception e) { CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Stop Pusher Error:{e}"); } return false; } protected override unsafe void DealWithFullBuffer(AVFrame* frame) { _pusher?.SendData(MergeWidth, MergeHeight, new IntPtr(frame->data[0])); } protected override EnumArea GetArea(EnumLiveChannelCategory category) { if (category == EnumLiveChannelCategory.Main) { return EnumArea.Main; } if (category == EnumLiveChannelCategory.Auxiliary1) { return EnumArea.Bottom; } throw new Exception($"RTC Can not get correct area by category:{category}"); } public override void DoDispose() { _pusher?.Dispose(); base.DoDispose(); } } }