using System; using System.Diagnostics; namespace Inspectron.HawkEye.RTSP.Messages { /// /// An Rtsp Request /// public class RtspRequest : RtspMessage { /// /// Request type. /// public enum RequestType { UNKNOWN, DESCRIBE, ANNOUNCE, GET_PARAMETER, OPTIONS, PAUSE, PLAY, RECORD, REDIRECT, SETUP, SET_PARAMETER, TEARDOWN, } /// /// Parses the request command. /// /// A string request command. /// The typed request. internal static RequestType ParseRequest(string aStringRequest) { RequestType returnValue; if (!Enum.TryParse(aStringRequest, true, out returnValue)) returnValue = RequestType.UNKNOWN; return returnValue; } /// /// Gets the Rtsp request. /// /// A request parts. /// the parsed request internal static RtspMessage GetRtspRequest(string[] aRequestParts) { // Debug.Assert(aRequestParts != (string[])null, "aRequestParts"); Debug.Assert(aRequestParts.Length != 0, "aRequestParts.Length == 0"); // // we already know this is a Request RtspRequest returnValue; switch (ParseRequest(aRequestParts[0])) { case RequestType.OPTIONS: returnValue = new RtspRequestOptions(); break; case RequestType.DESCRIBE: returnValue = new RtspRequestDescribe(); break; case RequestType.SETUP: returnValue = new RtspRequestSetup(); break; case RequestType.PLAY: returnValue = new RtspRequestPlay(); break; case RequestType.PAUSE: returnValue = new RtspRequestPause(); break; case RequestType.TEARDOWN: returnValue = new RtspRequestTeardown(); break; case RequestType.GET_PARAMETER: returnValue = new RtspRequestGetParameter(); break; case RequestType.ANNOUNCE: returnValue = new RtspRequestAnnounce(); break; case RequestType.RECORD: returnValue = new RtspRequestRecord(); break; /* case RequestType.REDIRECT: break; case RequestType.SET_PARAMETER: break; */ case RequestType.UNKNOWN: default: returnValue = new RtspRequest(); break; } return returnValue; } /// /// Initializes a new instance of the class. /// public RtspRequest() { Command = "OPTIONS * RTSP/1.0"; } /// /// Gets the request. /// /// The request in string format. public string Request { get { return commandArray[0]; } } /// /// Gets the request. /// The return value is typed with if the value is not /// reconise the value is sent. The string value can be get by /// /// The request. public RequestType RequestTyped { get { return ParseRequest(commandArray[0]); } set { if (Enum.IsDefined(typeof(RequestType), value)) commandArray[0] = value.ToString(); else commandArray[0] = RequestType.UNKNOWN.ToString(); } } private Uri _RtspUri; /// /// Gets or sets the Rtsp asked URI. /// /// The Rtsp asked URI. /// The request with uri * is return with null URI public Uri RtspUri { get { if (commandArray.Length < 2 || commandArray[1]=="*") return null; if (_RtspUri == null) Uri.TryCreate(commandArray[1], UriKind.Absolute, out _RtspUri); return _RtspUri; } set { _RtspUri = value; if (commandArray.Length < 2) { Array.Resize(ref commandArray, 3); } commandArray[1] = (value != null ? value.ToString().TrimEnd('/') : "*"); } } /// /// Gets the assiociate OK response with the request. /// /// an Rtsp response correcponding to request. public virtual RtspResponse CreateResponse() { RtspResponse returnValue = new RtspResponse(); returnValue.ReturnCode = 200; returnValue.CSeq = this.CSeq; if (this.Headers.ContainsKey(RtspHeaderNames.Session)) { returnValue.Headers[RtspHeaderNames.Session] = this.Headers[RtspHeaderNames.Session]; } return returnValue; } public Object ContextData { get; set; } } }