using Com.Tencent.Trtc; 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.Android.LiveVideo.RTC { public class USRtcMergePusherV2 : USMergePusherBaseV2 { private TRTCPusher _pusher; private int _videoResolution; public USRtcMergePusherV2() : base() { IsTRTCMode = true; InitCacheImage(true); } 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 = TRTCCloudDef.TrtcVideoResolution1280720; _pusher = new TRTCPusher(); _pusher.FirstFrameSend += OnFirstFrameSend; var userInfo = rtcParams.UserInfos?.FirstOrDefault(f => f.Category == EnumLiveChannelCategory.Main) ?? rtcParams.UserInfos?.FirstOrDefault(); _pusher.EnterRoom(userInfo.UserId, rtcParams.RoomId, userInfo.UserSign, rtcParams.AppId, _videoResolution, userInfo.VideoFps, userInfo.VideoBitrate, userInfo.MinVideoBitrate, 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(ImageFrameData frame) { _pusher?.SendData(MergeWidth, MergeHeight, frame.Data); } 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(); } } }