Beispiel #1
0
            internal Dictionary <string, object> GetUpdateDicts(RtmpConfig rtmpConfig)
            {
                var dict = new Dictionary <string, object>();

                if (!object.Equals(HandshakeSecond, rtmpConfig.HandshakeSecond))
                {
                    dict.Add($"{RtmpConfig.PrefixName}handshakeSecond", HandshakeSecond);
                }
                if (!object.Equals(KeepAliveSecond, rtmpConfig.KeepAliveSecond))
                {
                    dict.Add($"{RtmpConfig.PrefixName}keepAliveSecond", KeepAliveSecond);
                }
                if (!object.Equals(ModifyStamp, rtmpConfig.ModifyStamp))
                {
                    dict.Add($"{RtmpConfig.PrefixName}modifyStamp", ModifyStamp);
                }
                if (!object.Equals(Port, rtmpConfig.Port))
                {
                    dict.Add($"{RtmpConfig.PrefixName}port", Port);
                }
                if (!object.Equals(Sslport, rtmpConfig.Sslport))
                {
                    dict.Add($"{RtmpConfig.PrefixName}sslport", Sslport);
                }
                return(dict);
            }
Beispiel #2
0
        private void ServerTimer_Tick(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(ViewModel.SelectedVpnFriendlyName) &&
                !string.IsNullOrEmpty(ViewModel.VpnUsername) &&
                !string.IsNullOrEmpty(ViewModel.VpnPassword))
            {
                try
                {
                    RasEntry entry = new RasEntry()
                    {
                        FriendlyName = ViewModel.SelectedVpnFriendlyName,
                        UserName     = ViewModel.VpnUsername,
                        Password     = ViewModel.VpnPassword
                    };
                    RequestStatus result = _client.CheckRequestStatus();
                    if (result.RequestVpnStatus)
                    {
                        if (!entry.Connected)
                        {
                            if (entry.Connect())
                            {
                                if (!result.RemoteServerConnected)
                                {
                                    _client.SetRemoteServerStatus("1");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (entry.Connected)
                        {
                            if (entry.Disconnect())
                            {
                                if (result.RemoteServerConnected)
                                {
                                    _client.SetRemoteServerStatus("0");
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            if (!string.IsNullOrEmpty(ViewModel.CameraSource) && !string.IsNullOrEmpty(ViewModel.PushUrl))
            {
                try
                {
                    RequestStatus result = _client.CheckRequestStatus();
                    if (result.RequestIPCamera)
                    {
                        if (!_streamer.IsStarted)
                        {
                            RtmpConfig rtmpConfig = new RtmpConfig()
                            {
                                Width     = ViewModel.Width,
                                Height    = ViewModel.Height,
                                FrameRate = ViewModel.FPS
                            };
                            _streamer = new BitmapStreamer
                            {
                                PushUrl = ViewModel.PushUrl,
                                Config  = rtmpConfig
                            };
                            _streamer.StartPush();
                            VideoCapture capture    = new VideoCapture(ViewModel.CameraSource);
                            Stopwatch    fpsStopper = new Stopwatch();
                            _streamCts = new CancellationTokenSource();
                            Task.Run(async() =>
                            {
                                while (!_streamCts.IsCancellationRequested)
                                {
                                    try
                                    {
                                        fpsStopper.Restart();
                                        using (Image <Bgr, byte> frame = CaptureBGR(capture))
                                        {
                                            _streamer.AddImage(frame.Bitmap);
                                        }

                                        int elapsedMilliseconds = (int)fpsStopper.ElapsedMilliseconds;
                                        if (elapsedMilliseconds < (1000 / ViewModel.FPS))
                                        {
                                            await Task.Delay((1000 / ViewModel.FPS) - elapsedMilliseconds);
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                                capture.Dispose();
                            });
                        }
                    }
                    else
                    {
                        if (_streamer.IsStarted)
                        {
                            _streamCts.Cancel();
                            _streamer.Stop();
                        }
                    }
                }
                catch
                {
                }
            }
        }
Beispiel #3
0
 public RtmpMessageHandler(ConcurrentDictionary <StreamName, MediaStream> mediaStreamDic, Action <IChannelHandlerContext, StreamName, AbstractRtmpMessage> readAction, RtmpConfig rtmpConfig) : this(mediaStreamDic)
 {
     _readAction         = readAction;
     RtmpConfig.Instance = rtmpConfig;
 }