123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 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;
- using Vinno.vCloud.FIS.CrossPlatform.Common.LiveVideo.Interface;
- namespace Vinno.vCloud.FIS.CrossPlatform.Android.LiveVideo.RTMP
- {
- public class RtmpSinglePusherV2 : PusherBase, ILiveVideoPusherV2
- {
- private DsRtmpPusher _pusher;
- public event EventHandler<ChannelStateEventArgsV2> ChannelStateChanged;
- public bool StartPusher(IExtendedData pushParams, IEnumerable<CPVideoDeviceOutputInfo> deviceInfos)
- {
- try
- {
- var rtmpParams = pushParams as RtmpExtendedData;
- if (rtmpParams == null || rtmpParams.UserInfos.Count == 0)
- {
- CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RtmpSinglePusherV2 Extended Data Is Null!");
- return false;
- }
- var url = rtmpParams.UserInfos.FirstOrDefault()?.PushUrl;
- if (string.IsNullOrEmpty(url))
- {
- CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RtmpSinglePusherV2 Push Url Is Null!");
- return false;
- }
- if (deviceInfos.Count() == 0)
- {
- CrossPlatformHelper.Instance.LogWriter?.WriteLineError("RtmpSinglePusherV2 Push not have device info!");
- return false;
- }
- var userInfo = rtmpParams.UserInfos.FirstOrDefault();
- var deviceInfo = deviceInfos.FirstOrDefault(x => x.Category == userInfo.Category);
- if (deviceInfo == null)
- {
- CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"RtmpSinglePusherV2 Category {userInfo.Category} No device found!");
- return false;
- }
- var device = (CPVideoDeviceOutputInfo)deviceInfo.Clone();
- _pusher = new DsRtmpPusher(device, url, pushParams.MicDeviceId, pushParams.IsMute, userInfo.Width, userInfo.Height);
- _pusher.LiveStatusChanged += OnLiveStatusChanged;
- _pusher.ImageFrameReceived += OnImageFrameReceived;
- _pusher.Start();
- return true;
- }
- catch (Exception ex)
- {
- CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Start Rtmp Single Push Error:{ex}");
- }
- return false;
- }
- public void SetMute(bool isMute)
- {
- _pusher?.SetMute(isMute);
- }
- public bool StopPusher()
- {
- try
- {
- if (_pusher != null)
- {
- _pusher.LiveStatusChanged -= OnLiveStatusChanged;
- _pusher.ImageFrameReceived -= OnImageFrameReceived;
- _pusher.Stop();
- }
- return true;
- }
- catch (Exception ex)
- {
- CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"Stop Rtmp Single Push Error:{ex}");
- }
- return false;
- }
- private void OnImageFrameReceived(object sender, ImageFrameData e)
- {
- var category = (EnumLiveChannelCategory)sender;
- CopyPreviewData(category, e);
- }
- private void OnLiveStatusChanged(object sender, EnumLiveStatus e)
- {
- if (e == EnumLiveStatus.Connected)
- {
- var category = (EnumLiveChannelCategory)sender;
- ChannelStateChanged?.Invoke(this, new ChannelStateEventArgsV2(category, EnumDeviceLiveState.Pushing));
- }
- }
- public override void DoDispose()
- {
- if (_pusher != null)
- {
- _pusher.Dispose();
- _pusher = null;
- }
- base.DoDispose();
- }
- public void SwitchMic(string micId)
- {
- }
- public bool StartSpeedTest(uint appId, string userId, string userSign)
- {
- CrossPlatformHelper.Instance.LogWriter?.WriteLineError($"RtmpSinglePusher Doesn't support StartSpeedTest");
- return false;
- }
- }
- }
|