Ejemplo n.º 1
0
        public RtspStatusCode Play(string query)
        {
            if ((_rtspSocket == null))
            {
                Connect();
            }
            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            RtspResponse response;
            string       data;

            if (string.IsNullOrEmpty(query))
            {
                data = string.Format("rtsp://{0}:{1}/stream={2}", _address,
                                     554, _rtspStreamId);
            }
            else
            {
                data = string.Format("rtsp://{0}:{1}/stream={2}?{3}", _address,
                                     554, _rtspStreamId, query);
            }
            var request = new RtspRequest(RtspMethod.Play, data, 1, 0);

            request.Headers.Add("Session", _rtspSessionId);
            SendRequest(request);
            ReceiveResponse(out response);
            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP SETUP status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}
            //Logger.Info("RtspSession-Play : \r\n {0}", response);
            string sessionHeader;

            if (!response.Headers.TryGetValue("Session", out sessionHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate Session header in RTSP Play response"));
            }
            ProcessSessionHeader(sessionHeader, "Play");
            string rtpinfoHeader;

            if (!response.Headers.TryGetValue("RTP-Info", out rtpinfoHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate Rtp-Info header in RTSP Play response"));
            }
            return(response.StatusCode);
        }
Ejemplo n.º 2
0
        public RtspStatusCode Options()
        {
            if ((_rtspSocket == null))
            {
                Connect();
            }
            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            RtspRequest  request;
            RtspResponse response;


            if (string.IsNullOrEmpty(_rtspSessionId))
            {
                request = new RtspRequest(RtspMethod.Options, string.Format("rtsp://{0}:{1}/", _address, 554), 1, 0);
            }
            else
            {
                request = new RtspRequest(RtspMethod.Options, string.Format("rtsp://{0}:{1}/", _address, 554), 1, 0);
                request.Headers.Add("Session", _rtspSessionId);
            }
            SendRequest(request);
            ReceiveResponse(out response);
            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP SETUP status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}
            //Logger.Info("RtspSession-Options : \r\n {0}", response);
            string sessionHeader;

            if (!response.Headers.TryGetValue("Session", out sessionHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate session header in RTSP Options response"));
            }
            ProcessSessionHeader(sessionHeader, "Options");
            string optionsHeader;

            if (!response.Headers.TryGetValue("Public", out optionsHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to Options header in RTSP Options response"));
            }
            return(response.StatusCode);
        }
Ejemplo n.º 3
0
        public RtspStatusCode TearDown()
        {
            if ((_rtspSocket == null))
            {
                Connect();
            }
            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            RtspResponse response;

            var request = new RtspRequest(RtspMethod.Teardown, string.Format("rtsp://{0}:{1}/stream={2}", _address, 554, _rtspStreamId), 1, 0);

            request.Headers.Add("Session", _rtspSessionId);
            SendRequest(request);
            ReceiveResponse(out response);
            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP Teardown status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}
            return(response.StatusCode);
        }
Ejemplo n.º 4
0
 private void SendRequest(RtspRequest request)
 {
     if (_rtspSocket == null)
     {
         Connect();
     }
     try
     {
         request.Headers.Add("CSeq", _rtspSequenceNum.ToString());
         _rtspSequenceNum++;
         byte[] requestBytes = request.Serialise();
         if (_rtspSocket != null)
         {
             var requestBytesCount = _rtspSocket.Send(requestBytes, requestBytes.Length, SocketFlags.None);
             if (requestBytesCount < 1)
             {
             }
         }
     }
     catch (Exception e)
     {
         _logger.Error(e.Message);
     }
 }
Ejemplo n.º 5
0
        public RtspStatusCode Describe(out int level, out int quality)
        {
            if ((_rtspSocket == null))
            {
                Connect();
            }
            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            RtspRequest  request;
            RtspResponse response;

            level   = 0;
            quality = 0;

            if (string.IsNullOrEmpty(_rtspSessionId))
            {
                request = new RtspRequest(RtspMethod.Describe, string.Format("rtsp://{0}:{1}/", _address, 554), 1, 0);
                request.Headers.Add("Accept", "application/sdp");
            }
            else
            {
                request = new RtspRequest(RtspMethod.Describe, string.Format("rtsp://{0}:{1}/stream={2}", _address, 554, _rtspStreamId), 1, 0);
                request.Headers.Add("Accept", "application/sdp");
                request.Headers.Add("Session", _rtspSessionId);
            }
            SendRequest(request);
            ReceiveResponse(out response);
            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP Describe status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}
            //Logger.Info("RtspSession-Describe : \r\n {0}", response);
            string sessionHeader;

            if (!response.Headers.TryGetValue("Session", out sessionHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate session header in RTSP Describe response"));
            }
            ProcessSessionHeader(sessionHeader, "Describe");
            var m = RegexDescribeResponseSignalInfo.Match(response.Body);

            if (m.Success)
            {
                //isSignalLocked = m.Groups[2].Captures[0].Value.Equals("1");
                level   = int.Parse(m.Groups[1].Captures[0].Value) * 100 / 255;  // level: 0..255 => 0..100
                quality = int.Parse(m.Groups[3].Captures[0].Value) * 100 / 15;   // quality: 0..15 => 0..100
            }

            /*
             *  v=0
             *  o=- 1378633020884883 1 IN IP4 192.168.2.108
             *  s=SatIPServer:1 4
             *  t=0 0
             *  a=tool:idl4k
             *  m=video 52780 RTP/AVP 33
             *  c=IN IP4 0.0.0.0
             *  b=AS:5000
             *  a=control:stream=4
             *  a=fmtp:33 ver=1.0;tuner=1,0,0,0,12344,h,dvbs2,,off,,22000,34;pids=0,100,101,102,103,106
             *  =sendonly
             */


            return(response.StatusCode);
        }
Ejemplo n.º 6
0
        public RtspStatusCode Setup(string query, string transporttype)
        {
            RtspRequest  request;
            RtspResponse response;

            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            if ((_rtspSocket == null))
            {
                Connect();
            }
            if (string.IsNullOrEmpty(_rtspSessionId))
            {
                request = new RtspRequest(RtspMethod.Setup, string.Format("rtsp://{0}:{1}/?{2}", _address, 554, query), 1, 0);
                switch (transporttype)
                {
                case "multicast":
                    request.Headers.Add("Transport", string.Format("RTP/AVP;multicast"));
                    break;

                case "unicast":
                    var activeTcpConnections = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections();
                    var usedPorts            = new HashSet <int>();
                    foreach (var connection in activeTcpConnections)
                    {
                        usedPorts.Add(connection.LocalEndPoint.Port);
                    }
                    for (var port = 40000; port <= 65534; port += 2)
                    {
                        if (!usedPorts.Contains(port) && !usedPorts.Contains(port + 1))
                        {
                            _clientRtpPort  = port;
                            _clientRtcpPort = port + 1;
                            break;
                        }
                    }
                    request.Headers.Add("Transport", string.Format("RTP/AVP;unicast;client_port={0}-{1}", _clientRtpPort, _clientRtcpPort));
                    break;
                }
            }
            else
            {
                request = new RtspRequest(RtspMethod.Setup, string.Format("rtsp://{0}:{1}/?{2}", _address, 554, query), 1, 0);
                switch (transporttype)
                {
                case "multicast":
                    request.Headers.Add("Transport", string.Format("RTP/AVP;multicast"));
                    break;

                case "unicast":
                    request.Headers.Add("Transport", string.Format("RTP/AVP;unicast;client_port={0}-{1}", _clientRtpPort, _clientRtcpPort));
                    break;
                }
            }
            SendRequest(request);
            ReceiveResponse(out response);

            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP SETUP status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}
            if (!response.Headers.TryGetValue("com.ses.streamID", out _rtspStreamId))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate Stream ID header in RTSP SETUP response"));
            }
            string sessionHeader;

            if (!response.Headers.TryGetValue("Session", out sessionHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate Session header in RTSP SETUP response"));
            }
            ProcessSessionHeader(sessionHeader, "Setup");
            string transportHeader;

            if (!response.Headers.TryGetValue("Transport", out transportHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate Transport header in RTSP SETUP response"));
            }
            ProcessTransportHeader(transportHeader);
            return(response.StatusCode);
        }
Ejemplo n.º 7
0
        public RtspStatusCode TearDown()
        {
            if ((_rtspSocket == null))
            {
                Connect();
            }
            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            RtspResponse response;

            var request = new RtspRequest(RtspMethod.Teardown, string.Format("rtsp://{0}:{1}/stream={2}", _address, 554, _rtspStreamId), 1, 0);
            request.Headers.Add("Session", _rtspSessionId);
            SendRequest(request);
            ReceiveResponse(out response);
            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP Teardown status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}            
            return response.StatusCode;
        }
Ejemplo n.º 8
0
        public RtspStatusCode Describe(out int level, out int quality)
        {
            if ((_rtspSocket == null))
            {
                Connect();
            }
            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            RtspRequest request;
            RtspResponse response;
            level = 0;
            quality = 0;

            if (string.IsNullOrEmpty(_rtspSessionId))
            {
                request = new RtspRequest(RtspMethod.Describe, string.Format("rtsp://{0}:{1}/", _address, 554), 1, 0);
                request.Headers.Add("Accept", "application/sdp");

            }
            else
            {
                request = new RtspRequest(RtspMethod.Describe, string.Format("rtsp://{0}:{1}/stream={2}", _address, 554, _rtspStreamId), 1, 0);
                request.Headers.Add("Accept", "application/sdp");
                request.Headers.Add("Session", _rtspSessionId);
            }
            SendRequest(request);
            ReceiveResponse(out response);
            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP Describe status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}
            //Logger.Info("RtspSession-Describe : \r\n {0}", response);
            string sessionHeader;
            if (!response.Headers.TryGetValue("Session", out sessionHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate session header in RTSP Describe response"));
            }
            ProcessSessionHeader(sessionHeader, "Describe");
            var m = RegexDescribeResponseSignalInfo.Match(response.Body);
            if (m.Success)
            {

                //isSignalLocked = m.Groups[2].Captures[0].Value.Equals("1");
                level = int.Parse(m.Groups[1].Captures[0].Value) * 100 / 255;    // level: 0..255 => 0..100
                quality = int.Parse(m.Groups[3].Captures[0].Value) * 100 / 15;   // quality: 0..15 => 0..100

            }
            /*              
                v=0
                o=- 1378633020884883 1 IN IP4 192.168.2.108
                s=SatIPServer:1 4
                t=0 0
                a=tool:idl4k
                m=video 52780 RTP/AVP 33
                c=IN IP4 0.0.0.0
                b=AS:5000
                a=control:stream=4
                a=fmtp:33 ver=1.0;tuner=1,0,0,0,12344,h,dvbs2,,off,,22000,34;pids=0,100,101,102,103,106
                =sendonly
             */


            return response.StatusCode;
        }
Ejemplo n.º 9
0
        public RtspStatusCode Options()
        {
            if ((_rtspSocket == null))
            {
                Connect();
            }
            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            RtspRequest request;
            RtspResponse response;


            if (string.IsNullOrEmpty(_rtspSessionId))
            {
                request = new RtspRequest(RtspMethod.Options, string.Format("rtsp://{0}:{1}/", _address, 554), 1, 0);
            }
            else
            {
                request = new RtspRequest(RtspMethod.Options, string.Format("rtsp://{0}:{1}/", _address, 554), 1, 0);
                request.Headers.Add("Session", _rtspSessionId);
            }
            SendRequest(request);
            ReceiveResponse(out response);
            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP SETUP status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}
            //Logger.Info("RtspSession-Options : \r\n {0}", response);
            string sessionHeader;
            if (!response.Headers.TryGetValue("Session", out sessionHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate session header in RTSP Options response"));
            }
            ProcessSessionHeader(sessionHeader, "Options");
            string optionsHeader;
            if (!response.Headers.TryGetValue("Public", out optionsHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to Options header in RTSP Options response"));
            }
            return response.StatusCode;
        }
Ejemplo n.º 10
0
 public RtspStatusCode Play(string query)
 {
     if ((_rtspSocket == null))
     {
         Connect();
     }
     //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
     RtspResponse response;
     string data;
     if (string.IsNullOrEmpty(query))
     {
         data = string.Format("rtsp://{0}:{1}/stream={2}", _address,
             554, _rtspStreamId);
     }
     else
     {
         data = string.Format("rtsp://{0}:{1}/stream={2}?{3}", _address,
             554, _rtspStreamId, query);
     }
     var request = new RtspRequest(RtspMethod.Play, data, 1, 0);
     request.Headers.Add("Session", _rtspSessionId);
     SendRequest(request);
     ReceiveResponse(out response);
     //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
     //{
     //    Logger.Error("Failed to tune, non-OK RTSP SETUP status code {0} {1}", response.StatusCode, response.ReasonPhrase);
     //}
     //Logger.Info("RtspSession-Play : \r\n {0}", response);
     string sessionHeader;
     if (!response.Headers.TryGetValue("Session", out sessionHeader))
     {
         _logger.Error(string.Format("Failed to tune, not able to locate Session header in RTSP Play response"));
     }
     ProcessSessionHeader(sessionHeader, "Play");
     string rtpinfoHeader;
     if (!response.Headers.TryGetValue("RTP-Info", out rtpinfoHeader))
     {
         _logger.Error(string.Format("Failed to tune, not able to locate Rtp-Info header in RTSP Play response"));
     }
     return response.StatusCode;
 }
Ejemplo n.º 11
0
        public RtspStatusCode Setup(string query, string transporttype)
        {

            RtspRequest request;
            RtspResponse response;
            //_rtspClient = new RtspClient(_rtspDevice.ServerAddress);
            if ((_rtspSocket == null))
            {
                Connect();
            }
            if (string.IsNullOrEmpty(_rtspSessionId))
            {
                request = new RtspRequest(RtspMethod.Setup, string.Format("rtsp://{0}:{1}/?{2}", _address, 554, query), 1, 0);
                switch (transporttype)
                {
                    case "multicast":
                        request.Headers.Add("Transport", string.Format("RTP/AVP;multicast"));
                        break;
                    case "unicast":
                        var activeTcpConnections = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections();
                        var usedPorts = new HashSet<int>();
                        foreach (var connection in activeTcpConnections)
                        {
                            usedPorts.Add(connection.LocalEndPoint.Port);
                        }
                        for (var port = 40000; port <= 65534; port += 2)
                        {
                            if (!usedPorts.Contains(port) && !usedPorts.Contains(port + 1))
                            {

                                _clientRtpPort = port;
                                _clientRtcpPort = port + 1;
                                break;
                            }
                        }
                        request.Headers.Add("Transport", string.Format("RTP/AVP;unicast;client_port={0}-{1}", _clientRtpPort, _clientRtcpPort));
                        break;
                }
            }
            else
            {
                request = new RtspRequest(RtspMethod.Setup, string.Format("rtsp://{0}:{1}/?{2}", _address, 554, query), 1, 0);
                switch (transporttype)
                {
                    case "multicast":
                        request.Headers.Add("Transport", string.Format("RTP/AVP;multicast"));
                        break;
                    case "unicast":
                        request.Headers.Add("Transport", string.Format("RTP/AVP;unicast;client_port={0}-{1}", _clientRtpPort, _clientRtcpPort));
                        break;
                }

            }
            SendRequest(request);
            ReceiveResponse(out response);

            //if (_rtspClient.SendRequest(request, out response) != RtspStatusCode.Ok)
            //{
            //    Logger.Error("Failed to tune, non-OK RTSP SETUP status code {0} {1}", response.StatusCode, response.ReasonPhrase);
            //}
            if (!response.Headers.TryGetValue("com.ses.streamID", out _rtspStreamId))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate Stream ID header in RTSP SETUP response"));
            }
            string sessionHeader;
            if (!response.Headers.TryGetValue("Session", out sessionHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate Session header in RTSP SETUP response"));
            }
            ProcessSessionHeader(sessionHeader, "Setup");
            string transportHeader;
            if (!response.Headers.TryGetValue("Transport", out transportHeader))
            {
                _logger.Error(string.Format("Failed to tune, not able to locate Transport header in RTSP SETUP response"));
            }
            ProcessTransportHeader(transportHeader);
            return response.StatusCode;
        }
Ejemplo n.º 12
0
        private void SendRequest(RtspRequest request)
        {
            if (_rtspSocket == null)
            {
                Connect();
            }
            try
            {
                request.Headers.Add("CSeq", _rtspSequenceNum.ToString());
                _rtspSequenceNum++;
                byte[] requestBytes = request.Serialise();
                if (_rtspSocket != null)
                {
                    var requestBytesCount = _rtspSocket.Send(requestBytes, requestBytes.Length, SocketFlags.None);
                    if (requestBytesCount < 1)
                    {

                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
            }
        }