Beispiel #1
0
        public static RtspResponseMessage Parse(ArraySegment <byte> byteSegment)
        {
            Debug.Assert(byteSegment.Array != null, "byteSegment.Array != null");

            var headersStream = new MemoryStream(byteSegment.Array, byteSegment.Offset, byteSegment.Count, false);
            var headersReader = new StreamReader(headersStream);

            string startLine = headersReader.ReadLine();

            if (startLine == null)
            {
                throw new RtspParseResponseException("Empty response");
            }

            string[] tokens = GetFirstLineTokens(startLine);

            string rtspVersion = tokens[0];

            Version        protocolVersion = ParseProtocolVersion(rtspVersion);
            RtspStatusCode statusCode      = ParseStatusCode(tokens[1]);

            NameValueCollection headers = HeadersParser.ParseHeaders(headersReader);

            uint   cSeq      = 0;
            string cseqValue = headers.Get("CSEQ");

            if (cseqValue != null)
            {
                uint.TryParse(cseqValue, out cSeq);
            }

            return(new RtspResponseMessage(statusCode, protocolVersion, cSeq, headers));
        }
Beispiel #2
0
        private string GetMessageFromStatuscode(RtspStatusCode code)
        {
            var retval = string.Empty;

            switch (code)
            {
            case RtspStatusCode.BadRequest:
                retval = "The request could not be understood by the server due to a malformed syntax. Returned when missing a character, inconsistent request (duplicate attributes), etc.";
                break;

            case RtspStatusCode.Forbidden:
                retval = "The server understood the request, but is refusing to fulfil it. Returned when passing an attribute value not understood by the server in a query, or an out-of-range value.";
                break;

            case RtspStatusCode.NotFound:
                retval = "The server has not found anything matching the Request-URI. Returned when requesting a stream with a streamID that does not exist.";
                break;

            case RtspStatusCode.MethodNotAllowed:
                retval = "The method specified in the request is not allowed for the resource identified by the Request-URI. Returned when applying a SETUP, PLAY or TEARDOWN method on an RTSP URI identifying the server.";
                break;

            case RtspStatusCode.NotAcceptable:
                retval = "The resource identified by the request is only capable of generating response message bodies which have content characteristics not acceptable according to the accept headers sent in the request. Issuing a DESCRIBE request with an accept header different from application/sdp.";
                break;

            case RtspStatusCode.RequestTimeOut:
                retval = "The client did not produce a request within the time that the server was prepared to wait. The client may repeat the request without modifications at any later time. E.g. issuing a PLAY request after the communication link had been idle for a period of time. The time interval has exceeded the value specified by the timeout parameter in the Session: header field of a SETUP response.";
                break;

            case RtspStatusCode.RequestUriTooLarge:
                retval = "The server is refusing to service the request because the Request-URI is longer than the server is willing to interpret. The RTSP protocol does not place any limit on the length of a URI. Servers should be able to handle URIs of unbounded length.";
                break;

            case RtspStatusCode.NotEnoughBandwidth:
                retval = "The request was refused because there is insufficient bandwidth on the in-home LAN. Returned when clients are requesting more streams than the network can carry.";
                break;

            case RtspStatusCode.SessionNotFound:
                retval = "The RTSP session identifier value in the Session: header field of the request is missing, invalid, or has timed out. Returned when issuing the wrong session identifier value in a request.";
                break;

            case RtspStatusCode.MethodNotValidInThisState:
                retval = "The client or server cannot process this request in its current state. Returned e.g. when trying to change transport parameters while the server is in the play state (e.g. change of port values, etc.).";
                break;

            case RtspStatusCode.UnsupportedTransport:
                retval = "The Transport: header field of the request did not contain a supported transport specification. Returned e.g. when issuing a profile that is different from RTP/AVP.";
                break;

            case RtspStatusCode.InternalServerError:
                retval = "The server encountered an error condition preventing it to fulfil the request. Returned when the server is not functioning correctly due to a hardware failure or a software bug or anything else that can go wrong.";
                break;

            case RtspStatusCode.ServiceUnavailable:
                retval = "The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. Returned when reaching the maximum number of hardware and software resources, the maximum number of sessions.";
                break;

            case RtspStatusCode.RtspVersionNotSupported:
                retval = "The server does not support the RTSP protocol version that was used in the request message.";
                break;

            case RtspStatusCode.OptionNotSupported:
                retval = "A feature-tag given in the Require: header field of the request was not supported. Issuing a request with a Require: header field.";
                break;
            }
            return(retval);
        }
Beispiel #3
0
 public RtspResponseMessage(RtspStatusCode statusCode, Version protocolVersion, uint cSeq,
                            NameValueCollection headers)
     : base(cSeq, protocolVersion, headers)
 {
     StatusCode = statusCode;
 }
        /// <summary>
        /// Creates a RtspResponse based on the SequenceNumber contained in the given RtspRequest
        /// </summary>
        /// <param name="request">The request to utilize the SequenceNumber from, if null the current SequenceNumber is used</param>
        /// <param name="statusCode">The StatusCode of the generated response</param>
        /// <returns>The RtspResponse created</returns>
        internal RtspMessage CreateRtspResponse(RtspMessage request = null, RtspStatusCode statusCode = RtspStatusCode.OK, string body = null)
        {
            RtspMessage response = new RtspMessage(RtspMessageType.Response);

            response.StatusCode = statusCode;

            /*
             12.4.1 400 Bad Request

               The request could not be understood by the server due to malformed
               syntax. The client SHOULD NOT repeat the request without
               modifications [H10.4.1]. If the request does not have a CSeq header,
               the server MUST NOT include a CSeq in the response.
             */

            if (request != null)
            {
                if (request.ContainsHeader(RtspHeaders.Session)) response.SetHeader(RtspHeaders.Session, request.GetHeader(RtspHeaders.Session));

                if (statusCode != RtspStatusCode.BadRequest) response.CSeq = request.CSeq;
            }
            else if (statusCode != RtspStatusCode.BadRequest && LastRequest.CSeq >= 0) response.CSeq = LastRequest.CSeq;

            //Include any body.
            if (false == string.IsNullOrWhiteSpace(body)) response.Body = body;

            return response;
        }
Beispiel #5
0
 /// <summary>
 /// Sends a Rtsp Response on the given client session
 /// </summary>
 /// <param name="ci">The client session to send the response on</param>
 /// <param name="code">The status code of the response if other than BadRequest</param>
 //Should allow a header to be put into the response or a KeyValuePair<string,string> headers
 internal void ProcessInvalidRtspRequest(ClientSession session, RtspStatusCode code = RtspStatusCode.BadRequest, string body = null, bool sendResponse = true)
 {
     //Create and Send the response
     ProcessInvalidRtspRequest(session != null ? session.CreateRtspResponse(null, code, body) : new RtspMessage(RtspMessageType.Response) { StatusCode = code, Body = body, CSeq = Utility.Random.Next() }, session);
 }
Beispiel #6
0
 public RtspBadResponseCodeException(RtspStatusCode code)
     : base($"Bad response code: {code}")
 {
     Code = code;
 }