Example #1
0
    /// <summary>
    /// Accepts the connection.
    /// </summary>
    private void AcceptConnection()
    {
        try
        {
            while (!_Stopping.WaitOne(0))
            {
                // Wait for an incoming TCP Connection
                TcpClient oneClient = _RTSPServerListener.AcceptTcpClient();
                Console.WriteLine("Connection from " + oneClient.Client.RemoteEndPoint.ToString());

                // Hand the incoming TCP connection over to the RTSP classes
                var          rtsp_socket = new RtspTcpTransport(oneClient);
                RtspListener newListener = new RtspListener(rtsp_socket);
                newListener.MessageReceived += new EventHandler <RtspChunkEventArgs>(async(s, e) => await RTSP_Message_ReceivedAsync(s, e));
                //RTSPDispatcher.Instance.AddListener(newListener);

                // Add the RtspListener to the RTSPConnections List


                newListener.Start();
            }
        }
        catch (SocketException error)
        {
            // _logger.Warn("Got an error listening, I have to handle the stopping which also throw an error", error);
        }
        catch (Exception error)
        {
            // _logger.Error("Got an error listening...", error);
            throw;
        }
    }
Example #2
0
    /// <summary>
    /// Accepts the connection.
    /// </summary>
    private void AcceptConnection()
    {
        try
        {
            while (!_Stopping.WaitOne(0))
            {
                TcpClient oneClient = _RTSPServerListener.AcceptTcpClient();
                Console.WriteLine("Connection from " + oneClient.Client.RemoteEndPoint.ToString());

                var          rtsp_socket = new RtspTcpTransport(oneClient);
                RtspListener newListener = new RtspListener(rtsp_socket);
                newListener.MessageReceived += RTSP_Message_Received;
                //RTSPDispatcher.Instance.AddListener(newListener);
                newListener.Start();
            }
        }
        catch (SocketException error)
        {
            // _logger.Warn("Got an error listening, I have to handle the stopping which also throw an error", error);
        }
        catch (Exception error)
        {
            // _logger.Error("Got an error listening...", error);
            throw;
        }
    }
Example #3
0
        public RTSPClient(string ipAddress, uint port, string username, string password)
        {
            _url = $"rtsp://{username}:{password}@{ipAddress}:{port}/Streaming/channels/1/";

            RtspUtils.RegisterUri();

            RtspTcpTransport socket = new RtspTcpTransport(ipAddress, (int)port);

            _client = new RtspListener(socket);

            _client.MessageReceived += MessageReceived;
            _client.DataReceived    += DataReceived;
        }
Example #4
0
    // /// <summary>
    // /// Starts the listen.
    // /// </summary>
    // public async Task StartListen()
    // {
    //     _RTSPServerListener.Start();
    //
    //     _Stopping = new ManualResetEvent(false);
    //     _ListenTread = new Thread(new ThreadStart(AcceptConnection));
    //     _ListenTread.Start();
    //
    //     /*
    //     // Initialise the H264 encoder
    //     h264_encoder = new SimpleH264Encoder(h264_width, h264_height, h264_fps);
    //     //h264_encoder = new TinyH264Encoder(); // hard coded to 192x128
    //
    //     // Start the VideoSource
    //     video_source = new TestCard(h264_width, h264_height, h264_fps);
    //     video_source.ReceivedYUVFrame += video_source_ReceivedYUVFrame;
    //     */
    // }

    public async Task ListenAsync()
    {
        rtspServerListener.Start();
        try
        {
            while (!stopping)
            {
                // Wait for an incoming TCP Connection
                TcpClient oneClient = await rtspServerListener.AcceptTcpClientAsync();

                Console.WriteLine("Connection from " + oneClient.Client.RemoteEndPoint.ToString());

                // Hand the incoming TCP connection over to the RTSP classes
                var          rtsp_socket = new RtspTcpTransport(oneClient);
                RtspListener newListener = new RtspListener(rtsp_socket);
                newListener.MessageReceived += RTSP_Message_Received;
                //RTSPDispatcher.Instance.AddListener(newListener);

                // Add the RtspListener to the RTSPConnections List
                lock (rtsp_list)
                {
                    RTSPConnection new_connection = new RTSPConnection();
                    new_connection.listener        = newListener;
                    new_connection.client_hostname = newListener.RemoteAdress.Split(':')[0];
                    new_connection.ssrc            = global_ssrc;

                    new_connection.time_since_last_rtsp_keepalive       = DateTime.UtcNow;
                    new_connection.video_time_since_last_rtcp_keepalive = DateTime.UtcNow;

                    rtsp_list.Add(new_connection);
                }

                newListener.Start();
                await UpdateClients();
            }
        }
        catch (SocketException error)
        {
            // _logger.Warn("Got an error listening, I have to handle the stopping which also throw an error", error);
        }
        catch (Exception error)
        {
            // _logger.Error("Got an error listening...", error);
            throw;
        }
    }
Example #5
0
        /// <summary>
        /// Accepts the connection.
        /// </summary>
        private void AcceptConnection()
        {
            Console.WriteLine($"Now streaming via RTSP on port {portNumber}");
            Console.WriteLine($"Connect with your player to rtsp://127.0.0.1:{portNumber}/");
            try
            {
                while (!_Stopping.WaitOne(0))
                {
                    // Wait for an incoming TCP Connection
                    TcpClient oneClient = _RTSPServerListener.AcceptTcpClient();
                    Console.WriteLine("Connection from " + oneClient.Client.RemoteEndPoint.ToString());

                    // Hand the incoming TCP connection over to the RTSP classes
                    var          rtsp_socket = new RtspTcpTransport(oneClient);
                    RtspListener newListener = new RtspListener(rtsp_socket);
                    newListener.MessageReceived += RTSP_Message_Received;
                    //RTSPDispatcher.Instance.AddListener(newListener);

                    // Add the RtspListener to the RTSPConnections List
                    lock (rtsp_list)
                    {
                        RTSPConnection new_connection = new RTSPConnection();
                        new_connection.listener        = newListener;
                        new_connection.client_hostname = newListener.RemoteAdress.Split(':')[0];
                        new_connection.ssrc            = global_ssrc;

                        new_connection.time_since_last_rtsp_keepalive = DateTime.UtcNow;
                        //new_connection.video_time_since_last_rtcp_keepalive = DateTime.UtcNow;

                        rtsp_list.Add(new_connection);
                    }

                    newListener.Start();
                }
            }
            catch (Exception error)
            {
                if (!_Stopping.WaitOne(0))
                {
                    Console.WriteLine("[AcceptConnection] Error: " + error.ToString());
                }
            }
        }
Example #6
0
        void AcceptConnection()
        {
            Guid newConnectionId = Guid.Empty;

            try
            {
                while (!_stopping.WaitOne(0))
                {
                    // Wait for an incoming TCP Connection
                    TcpClient oneClient = _RTSPServerListener.AcceptTcpClient();
                    newConnectionId = Guid.NewGuid();

                    // Hand the incoming TCP connection over to the RTSP classes
                    var            rtspSocket        = new RtspTcpTransport(oneClient);
                    RTSPConnection newRTSPConnection = null;
                    // Add the RtspListener to the RTSPConnections List
                    lock (_rtspList) {
                        newRTSPConnection = new RTSPConnection(newConnectionId, rtspSocket, _ipAddress, _requestUrlVideoSourceResolverStrategy);
                        newRTSPConnection.OnConnectionAdded   += ProcessConnectionAdded;
                        newRTSPConnection.OnConnectionRemoved += ProcessConnectionRemoved;
                        newRTSPConnection.OnProvideSdpData    += ProcessRtspProvideSdpData;
                        _rtspList.Add(newRTSPConnection);
                    }

                    newRTSPConnection.Start();
                }
            }
            catch (SocketException error)
            {
                _logger.Debug($"{newConnectionId} Got an error listening, I have to handle the stopping which also throw an error: " + error);
            }
            catch (Exception error)
            {
                _logger.Debug($"{newConnectionId} Got an error listening:" + error);
            }
        }