예제 #1
0
        public bool GetParameter(RTSPRequestParser parser)
        {
            string media = parser.Media;


            ServerMediaSession session = _connection.Server.lookupServerMediaSession(media);

            if (session == null)
            {
                _connection.HandleNotFound(parser);
                return(false);
            }
            // Look up information for the specified subsession (track):


            ServerMediaSubsession subsession = session.LookupSubSession(media);

            // Not yet implemented
            //ParseGetParameter(parser);

            StringBuilder sb = new StringBuilder();

            sb.Append("RTSP/1.0 200 OK\r\n");
            sb.AppendFormat("Server: {0}\r\n", RTSPServer.ServerVersion);
            sb.AppendFormat("Cseq: {0}\r\n", parser.Headers["CSEQ"]);
            sb.AppendFormat("Session: {0}\r\n", SessionId);
            sb.Append("Last-Modified: Tue, 30 Aug 2016 01:33:17 GMT\r\n");
            sb.Append("Date: Sat, 22 Dec 2018 16:18:03 GMT\r\n");
            sb.Append("Expires: Sun, 23 Dec 2018 12:01:28 GMT\r\n\r\n");

            string reply = sb.ToString();

            _connection.SendResponse(reply);
            return(true);
        }
예제 #2
0
 public void AddSubsession(ServerMediaSubsession subsession)
 {
     if (_subSessions.Where(c => subsession.Name == c.Name).FirstOrDefault() == null)
     {
         _subSessions.Add(subsession);
     }
 }
예제 #3
0
        public bool Setup(TcpClient tcpSocket, RTSPRequestParser parser)
        {
            string media = parser.Media;


            ServerMediaSession session = _connection.Server.lookupServerMediaSession(media);

            if (session == null)
            {
                _connection.HandleNotFound(parser);
                return(false);
            }
            // Look up information for the specified subsession (track):


            ServerMediaSubsession subsession = session.LookupSubSession(media);


            Socket socket = null;

            if (String.Compare(parser.TransportType, "RTP/AVP/TCP") == 0)
            {
                socket       = tcpSocket.Client;
                IsRTPOverTCP = true;
            }

            if ((subsession.IsMulticast && parser.TransportMode == "UNICAST") || (!subsession.IsMulticast && parser.TransportMode == "MULTICAST"))
            {
                _connection.HandleUnsupportedTransport(parser);
                return(false);
            }

            int clientRTPPort  = parser.ClientPort1;
            int clientRTCPPort = parser.ClientPort2;

            int    serverRTPPort;
            int    serverRTCPPort;
            string multiCastAddress;
            var    clientAddress = tcpSocket.Client.RemoteEndPoint as IPEndPoint;

            subsession.GetStreamParameters(out serverRTPPort, out serverRTCPPort, out multiCastAddress);

            SetupDestinations(socket, clientAddress, null, clientRTPPort, clientRTCPPort, (byte)parser.Channel1, (byte)parser.Channel2);

            StringBuilder sb = new StringBuilder();

            sb.Append("RTSP/1.0 200 OK\r\n");
            sb.AppendFormat("Server: {0}\r\n", RTSPServer.ServerVersion);
            sb.AppendFormat("Cseq: {0}\r\n", parser.Headers["CSEQ"]);

            var localIP = SocketExtensions.GetLocalIPV4Address();

            if (parser.TransportMode == "UNICAST")
            {
                sb.AppendFormat("Session: {0}\r\n", SessionId);
                sb.Append("Last-Modified: Tue, 30 Aug 2016 01:33:17 GMT\r\n");
                sb.Append("Cache-Control: must-revalidate\r\n");
                sb.Append("Date: Sat, 22 Dec 2018 16:18:03 GMT\r\n");
                sb.Append("Expires: Sun, 23 Dec 2018 12:01:28 GMT\r\n");

                if (socket == null)
                {
                    // UDP
                    sb.AppendFormat("Transport: RTP/AVP;unicast;destination={0};source={1};client_port={2}-{3};server_port={4}-{5};\r\n\r\n",
                                    clientAddress.Address,
                                    localIP,
                                    parser.ClientPort1,
                                    parser.ClientPort2,
                                    serverRTPPort,
                                    serverRTCPPort);
                }
                else
                {
                    // TCP
                    sb.AppendFormat("Transport: RTP/AVP/TCP;unicast;destination={0};source={1};interleaved={2}-{3}\r\n\r\n",
                                    clientAddress.Address,
                                    localIP,
                                    parser.Channel1,
                                    parser.Channel2);
                }
            }
            // Multicast
            else
            {
                sb.Append("Date: Sat, 22 Dec 2018 16:18:03 GMT\r\n");
                sb.AppendFormat("Transport: RTP/AVP;multicast;destination={0};source={1};port={2}-{3};ttl=255\r\n",
                                multiCastAddress,
                                localIP,
                                serverRTPPort,
                                serverRTCPPort).
                AppendFormat("Session: {0};timeout=65\r\n\r\n", SessionId);
            }

            var reply = sb.ToString();

            _connection.SendResponse(reply);
            return(true);
        }