public RtspSource(string name, string sourceLocation, NetworkCredential credential = null, AuthenticationSchemes authType = AuthenticationSchemes.None, Rtsp.RtspClient.ClientProtocolType? rtpProtocolType = null, int bufferSize = RtspClient.DefaultBufferSize, Sdp.MediaType? specificMedia = null, TimeSpan? startTime = null, TimeSpan? endTime = null) : this(name, new Uri(sourceLocation), credential, authType, rtpProtocolType, bufferSize, specificMedia, startTime, endTime) { //Check for a null Credential and UserInfo in the Location given. if (credential == null && !string.IsNullOrWhiteSpace(m_Source.UserInfo)) { RtspClient.Credential = Media.Common.Extensions.Uri.UriExtensions.ParseUserInfo(m_Source); //Remove the user info from the location RtspClient.CurrentLocation = new Uri(RtspClient.CurrentLocation.AbsoluteUri.Replace(RtspClient.CurrentLocation.UserInfo + (char)Common.ASCII.AtSign, string.Empty).Replace(RtspClient.CurrentLocation.UserInfo, string.Empty)); } }
public RtpSource(string name, Sdp.SessionDescription sessionDescription) : base(name, new Uri(Rtp.RtpClient.RtpProtcolScheme + "://" + ((Sdp.Lines.SessionConnectionLine)sessionDescription.ConnectionLine).IPAddress)) { if (sessionDescription == null) throw new ArgumentNullException("sessionDescription"); RtpClient = Rtp.RtpClient.FromSessionDescription(SessionDescription = sessionDescription); RtpClient.FrameChangedEventsEnabled = PerPacket == false; }
static void Main(string[] args) { Sdp sdp = SdpText.ToSdp(); var text = sdp.ToText(); }
public override int GetHashCode() { return(this.GetType().FullName.GetHashCode() ^ Type.GetHashCode() ^ Sdp.GetHashCode()); }
public bool Equals(WebRTCSessionDescription other) { return(true && Type.Equals(other.Type) && Sdp.Equals(other.Sdp)); }
internal RtpClient.TransportContext GetSourceContext(Sdp.MediaDescription md) { try { foreach (RtpClient.TransportContext context in Attached.Keys) if (md.MediaType == context.MediaDescription.MediaType) return context; } catch (InvalidOperationException) { return GetSourceContext(md); } catch { } return null; }
/// <summary> /// Removes an attachment from a ClientSession to the given source where the media desciprtion /// </summary> /// <param name="source"></param> /// <param name="md"></param> /// <param name="session"></param> internal void RemoveMedia(Sdp.MediaDescription md) { //Determine if we have a source which corresponds to the mediaDescription given RtpClient.TransportContext sourceContext = Attached.Keys.FirstOrDefault(c => c.MediaDescription == md); //If the sourceContext is not null if (sourceContext != null) { //Remove the entry from the sessions routing table Attached.Remove(sourceContext); } }
/// <summary> /// Constructs a RtspStream for use in a RtspServer /// </summary> /// <param name="name">The name given to the stream on the RtspServer</param> /// <param name="sourceLocation">The rtsp uri to the media</param> /// <param name="credential">The network credential the stream requires</param> /// /// <param name="authType">The AuthenticationSchemes the stream requires</param> public RtspSource(string name, Uri sourceLocation, NetworkCredential credential = null, AuthenticationSchemes authType = AuthenticationSchemes.None, Rtsp.RtspClient.ClientProtocolType? rtpProtocolType = null, int bufferSize = RtspClient.DefaultBufferSize, Sdp.MediaType? specificMedia = null, TimeSpan? startTime = null, TimeSpan? endTime = null, bool perPacket = false) : base(name, sourceLocation, perPacket) { //Create the listener if we are the top level stream (Parent) if (IsParent) { RtspClient = new RtspClient(m_Source, rtpProtocolType, bufferSize); } //else it is already assigned via the child if (credential != null) { RtspClient.Credential = SourceCredential = credential; if (authType != AuthenticationSchemes.None) RtspClient.AuthenticationScheme = SourceAuthenticationScheme = authType; } //If only certain media should be setup if (specificMedia.HasValue) SpecificMediaType = specificMedia; //If there was a start time given if (startTime.HasValue) MediaStartTime = startTime; if (endTime.HasValue) MediaEndTime = endTime; }
public RtspSource(string name, string location, RtspClient.ClientProtocolType rtpProtocolType, int bufferSize = RtspClient.DefaultBufferSize, Sdp.MediaType? specificMedia = null, TimeSpan? startTime = null, TimeSpan? endTime = null) : this(name, location, null, AuthenticationSchemes.None, rtpProtocolType, bufferSize, specificMedia, startTime, endTime) { }
//Writes a .Sdp file public virtual void WriteDescription(IMedia stream, Sdp.SessionDescription sdp) { if (!IsArchiving(stream)) return; //Add lines with Alias info? System.IO.File.WriteAllText(BaseDirectory + '/' + stream.Id +'/' + "SessionDescription.sdp", sdp.ToString()); }
public TransportContext GetContextForMediaDescription(Sdp.MediaDescription mediaDescription) { if (mediaDescription == null) return null; return TransportContexts.FirstOrDefault(c => c.MediaDescription.MediaType == mediaDescription.MediaType && c.MediaDescription.MediaFormat == mediaDescription.MediaFormat); }
/// <summary> /// Will create a <see cref="RtpClient"/> based on the given parameters /// </summary> /// <param name="sessionDescription"></param> /// <param name="sharedMemory"></param> /// <param name="incomingEvents"></param> /// <param name="rtcpEnabled"></param> /// <returns></returns> public static RtpClient FromSessionDescription(Sdp.SessionDescription sessionDescription, Common.MemorySegment sharedMemory = null, bool incomingEvents = true, bool rtcpEnabled = true, Socket existingSocket = null, int? rtpPort = null, int? rtcpPort = null, int remoteSsrc = 0, int minimumSequentialRtpPackets = 2) { if (sessionDescription == null) throw new ArgumentNullException("sessionDescription"); Sdp.Lines.SessionConnectionLine connectionLine = new Sdp.Lines.SessionConnectionLine(sessionDescription.ConnectionLine); IPAddress remoteIp = IPAddress.Parse(connectionLine.IPAddress), localIp = Media.Common.Extensions.Socket.SocketExtensions.GetFirstIPAddress(remoteIp.AddressFamily); RtpClient participant = new RtpClient(sharedMemory, incomingEvents); byte lastChannel = 0; bool hasSocket = existingSocket != null; foreach (Media.Sdp.MediaDescription md in sessionDescription.MediaDescriptions) { TransportContext tc = TransportContext.FromMediaDescription(sessionDescription, lastChannel++, lastChannel++, md, rtcpEnabled, remoteSsrc, minimumSequentialRtpPackets); //Find range info in the SDP var rangeInfo = md.RangeLine; //If there is a range directive if (rangeInfo == null) { rangeInfo = sessionDescription.RangeLine; if (rangeInfo != null) { string type; Sdp.SessionDescription.TryParseRange(rangeInfo.Parts[0], out type, out tc.m_StartTime, out tc.m_EndTime); } //else if (sessionDescription.TimeDescriptions.Count > 0) //{ //tc.MediaStartTime = TimeSpan.FromMilliseconds(); //tc.MediaEndTime = TimeSpan.FromMilliseconds(); //} } //Check for udp if no existing socket was given if (false == hasSocket && string.Compare(md.MediaProtocol, Media.Rtp.RtpClient.RtpAvpProfileIdentifier, true) == 0) { int localPort = Media.Common.Extensions.Socket.SocketExtensions.FindOpenPort(ProtocolType.Udp); tc.Initialize(localIp, remoteIp, localPort++, localPort++, rtpPort ?? md.MediaPort, rtcpPort ?? md.MediaPort + 1); } else if (hasSocket)//If had a socket use it { tc.Initialize(existingSocket); } else { tc.Initialize(localIp, remoteIp, rtpPort ?? md.MediaPort); } //Try to add the context try { participant.AddContext(tc); } catch (Exception ex) { Media.Common.Extensions.Exception.ExceptionExtensions.TryRaiseTaggedException(tc, "See Tag, Could not add the created TransportContext.", ex); } } //Return the participant return participant; }
public static TransportContext FromMediaDescription(Sdp.SessionDescription sessionDescription, byte dataChannel, byte controlChannel, Sdp.MediaDescription mediaDescription, bool rtcpEnabled = true, int remoteSsrc = 0, int minimumSequentialpackets = 2) { if (mediaDescription == null) throw new ArgumentNullException("mediaDescription"); TransportContext tc = new TransportContext(dataChannel, controlChannel, RFC3550.Random32(Media.Rtcp.SourceDescriptionReport.PayloadType), mediaDescription, rtcpEnabled, remoteSsrc, minimumSequentialpackets); int reportReceivingEvery = 0, reportSendingEvery = 0, asData = 0; if (rtcpEnabled) { //Set to the default interval reportSendingEvery = reportReceivingEvery = (int)DefaultReportInterval.TotalMilliseconds; //If any lines were parsed if (Media.Sdp.Lines.SessionBandwidthLine.TryParseBandwidthDirectives(mediaDescription, out reportReceivingEvery, out reportSendingEvery, out asData)) { //Determine if rtcp is disabled bool rtcpDisabled = reportReceivingEvery == 0 && reportSendingEvery == 0; //If Rtcp is not disabled then this will set the read and write timeouts. if (false == rtcpDisabled) { /* For the RTP A/V Profile [2], which specifies that the default RTCP interval algorithm defined in the RTP spec [1] is to be used, at least RS/(RS+RR) of the RTCP bandwidth is dedicated to active data senders. If the proportion of senders to total participants is less than or equal to RS/(RS+RR), each sender gets RS divided by the number of senders. When the proportion of senders is greater than RS/(RS+RR), the senders get their proportion of the sum of these parameters, which means that a sender and a non-sender each get the same allocation. Therefore, it is not possible to constrain the data senders to use less RTCP bandwidth than is allowed for non-senders. A few special cases are worth noting: */ tc.IsRtcpEnabled = true; if (reportReceivingEvery > 0) tc.m_ReceiveInterval = TimeSpan.FromSeconds(reportReceivingEvery / Media.Common.Extensions.TimeSpan.TimeSpanExtensions.MicrosecondsPerMillisecond); if (reportSendingEvery > 0) tc.m_SendInterval = TimeSpan.FromSeconds(reportSendingEvery / Media.Common.Extensions.TimeSpan.TimeSpanExtensions.MicrosecondsPerMillisecond); //Todo //Should set MaximumRtcpBandwidthPercentage } else if (rtcpEnabled) tc.IsRtcpEnabled = false; } } //check for range in mediaDescription var rangeInfo = mediaDescription.RangeLine ?? (sessionDescription != null ? sessionDescription.RangeLine : null); if (rangeInfo != null) { string type; Media.Sdp.SessionDescription.TryParseRange(rangeInfo.Parts[0], out type, out tc.m_StartTime, out tc.m_EndTime); } //rtcpAttribute indicates if RTCP should use a special port and not be dervied from the RtpPort algorithmically //"a=rtcp:" //rtcp-mux is handled in the Initialize call return tc; }
public TransportContext(byte dataChannel, byte controlChannel, int ssrc, Sdp.MediaDescription mediaDescription, Socket socket, bool rtcpEnabled = true, int senderSsrc = 0, int minimumSequentialRtpPackets = 2) : this(dataChannel, controlChannel, ssrc, mediaDescription, rtcpEnabled, senderSsrc, minimumSequentialRtpPackets) { RtpSocket = RtcpSocket = socket; }