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.RTMP { public class RtmpMergePusherV2 : MergePusherBaseV2 { private DaniuPusher _pusher; public RtmpMergePusherV2() { IsTRTCMode = false; InitCacheImage(false); } public override bool StartPusher(IExtendedData pushParams, IEnumerable deviceInfos) { try { var rtmpParams = pushParams as RtmpExtendedData; if (rtmpParams == null || rtmpParams.UserInfos.Count == 0) { CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RtmpMergePusherV2 Extended Data Is Null!"); return false; } var url = rtmpParams.UserInfos.FirstOrDefault()?.PushUrl; if (string.IsNullOrEmpty(url)) { CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RtmpMergePusherV2 Push Url Is Null!"); return false; } var micIndex = CrossPlatformHelper.Instance.HardwareDetector.GetMicIndex(pushParams.MicDeviceId); _pusher = new DaniuPusher(url, MergeWidth, MergeHeight, MergeFrameRate, EnumAudioMode.Mic, pushParams.IsMute); _pusher.StatusChanged += OnStatusChanged; _pusher.StartPush(); return base.StartPusher(pushParams, deviceInfos); } catch (Exception e) { CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Start RtmpMergePusherV2 Error:{e}"); } return false; } public override void SetMute(bool isMute) { _pusher?.SetMute(isMute); } public override bool StopPusher() { try { base.StopPusher(); if (_pusher != null) { _pusher.StatusChanged -= OnStatusChanged; _pusher.StopPush(); } return true; } catch (Exception e) { CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Stop RtmpMergePusherV2 Error:{e}"); } return false; } private void OnStatusChanged(object sender, CPLiveStatusData e) { if (e.Status == EnumLiveStatus.Connected) { PushLiveStateChanged(); } } protected override unsafe void DealWithFullBuffer(ImageFrameData frame) { _pusher?.PushImage(frame); } protected override EnumArea GetArea(EnumLiveChannelCategory category) { if (category == EnumLiveChannelCategory.Main) { return EnumArea.Main; } if (category == EnumLiveChannelCategory.Auxiliary1) { return EnumArea.RightUp; } if (category == EnumLiveChannelCategory.Auxiliary2) { return EnumArea.RightDown; } if (category == EnumLiveChannelCategory.Auxiliary3) { return EnumArea.BottomCenter; } throw new Exception($"RTMP Can not get correct area by category:{category}"); } public override void DoDispose() { StopPusher(); base.DoDispose(); } public override void SwitchMic(string micId) { } } }