/// <summary> /// Starts this instance. /// </summary> public void Start(CancellationToken token) { _stream = _transport.GetStream(); _listenTask = new Task((o) => DoJob(token), token); _listenTask.ContinueWith((task) => { if (task.Exception != null && !((CancellationToken)task.AsyncState).IsCancellationRequested) { _rtspErrorSubject?.OnNext(task.Exception.Message); } _logger.Info("RTPS Listen Task completed."); }); _listenTask.Start(); }
/// <summary> /// Reconnect this instance of RtspListener. /// </summary> /// <exception cref="System.Net.Sockets.SocketException">Error during socket </exception> public void Reconnect() { //if it is already connected do not reconnect if (_transport.Connected) { return; } // If it is not connected listenthread should have die. if (_listenTread != null && _listenTread.IsAlive) { _listenTread.Join(); } if (_stream != null) { _stream.Dispose(); } // reconnect _transport.Reconnect(); _stream = _transport.GetStream(); // If listen thread exist restart it if (_listenTread != null) { Start(); } }
/// <summary> /// Reconnect this instance of RtspListener. /// </summary> /// <exception cref="System.Net.Sockets.SocketException">Error during socket </exception> public void Reconnect() { //if it is already connected do not reconnect if (_transport.Connected) { return; } // If it is not connected listenthread should have die. if (_listenTask != null && !_listenTask.IsCompleted) { _listenTask.Wait(); } _stream?.Dispose(); // reconnect _transport.Reconnect(); _stream = _transport.GetStream(); // If listen thread exist restart it if (_listenTask != null) { Start(); } }
/// <summary> /// Reconnect this instance of RtspListener. /// </summary> /// <exception cref="System.Net.Sockets.SocketException">Error during socket </exception> public void Reconnect() { //if it is already connected do not reconnect if (_transport.Connected) { return; } // If it is not connected listenthread should have die. if (_listenTask != null && false == _listenTask.IsCompleted) { _listenTask.Wait(); } if (_stream != null) { _stream.Dispose(); } // reconnect _transport.Reconnect(); _stream = _transport.GetStream(); _listenTask = Task.Factory.StartNew(() => DoJob(), TaskCreationOptions.LongRunning); }
/// <summary> /// Initializes a new instance of the <see cref="RtspListener"/> class from a TCP connection. /// </summary> /// <param name="connection">The connection.</param> public RtspListener(IRtspTransport connection) { // Contract.EndContractBlock(); _transport = connection ?? throw new ArgumentNullException("connection"); _stream = connection.GetStream(); }
/// <summary> /// Initializes a new instance of the <see cref="RtspListener"/> class from a TCP connection. /// </summary> /// <param name="connection">The connection.</param> public RtspListener(IRtspTransport connection) { if (connection == null) throw new ArgumentNullException("connection"); Contract.EndContractBlock(); _transport = connection; _stream = connection.GetStream(); }
/// <summary> /// Initializes a new instance of the <see cref="RtspListener"/> class from a TCP connection. /// </summary> /// <param name="connection">The connection.</param> public RtspListener(IRtspTransport connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } Contract.EndContractBlock(); _transport = connection; _stream = connection.GetStream(); }
/// <summary> /// Initializes a new instance of the <see cref="RtspListener"/> class from a TCP connection. /// </summary> /// <param name="connection">The connection.</param> public RtspListener(IRtspTransport connection, Subject <string> rtspErrorSubject) { if (connection == null) { throw new ArgumentNullException("connection"); } Contract.EndContractBlock(); _transport = connection; _stream = connection.GetStream(); _rtspErrorSubject = rtspErrorSubject; }
/// <summary> /// Initializes a new instance of the <see cref="RtspListener"/> class from a TCP connection. /// </summary> /// <param name="connection">The connection.</param> public RtspListener(IRtspTransport connection, string logName, Guid sourceId, Guid connectionId) { if (connection == null) { throw new ArgumentNullException("connection"); } _sourceId = sourceId; ConnectionId = connectionId; _logger = NLog.LogManager.GetLogger(logName); Contract.EndContractBlock(); _transport = connection; _stream = connection.GetStream(); }
public void ReceiveOptionsMessage() { string message = string.Empty; message += "OPTIONS * RTSP/1.0\n"; message += "CSeq: 1\n"; message += "Require: implicit-play\n"; message += "Proxy-Require: gzipped-messages\n"; message += "\n"; MemoryStream stream = new MemoryStream(ASCIIEncoding.UTF8.GetBytes(message)); _mockTransport.GetStream().Returns(stream); // Setup test object. RtspListener testedListener = new RtspListener(_mockTransport); testedListener.MessageReceived += new EventHandler <RtspChunkEventArgs>(MessageReceived); testedListener.DataReceived += new EventHandler <RtspChunkEventArgs>(DataReceived); // Run testedListener.Start(); System.Threading.Thread.Sleep(100); testedListener.Stop(); // Check the transport was closed. _mockTransport.Received().Close(); //Check the message recevied Assert.AreEqual(1, _receivedMessage.Count); RtspChunk theMessage = _receivedMessage[0]; Assert.IsInstanceOf <RtspRequest>(theMessage); Assert.AreEqual(0, theMessage.Data.Length); Assert.AreSame(testedListener, theMessage.SourcePort); RtspRequest theRequest = theMessage as RtspRequest; Assert.AreEqual(RtspRequest.RequestType.OPTIONS, theRequest.RequestTyped); Assert.AreEqual(3, theRequest.Headers.Count); Assert.AreEqual(1, theRequest.CSeq); Assert.Contains("Require", theRequest.Headers.Keys); Assert.Contains("Proxy-Require", theRequest.Headers.Keys); Assert.AreEqual(null, theRequest.RtspUri); Assert.AreEqual(0, _receivedData.Count); }