public void ParseICESessionAttributesUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=jdoe 2890844526 2890842807 IN IP4 10.0.1.1" + m_CRLF + "s=" + m_CRLF + "c=IN IP4 192.0.2.3" + m_CRLF + "t=0 0" + m_CRLF + "a=ice-pwd:asd88fgpdd777uzjYhagZg" + m_CRLF + "a=ice-ufrag:8hhY" + m_CRLF + "m=audio 45664 RTP/AVP 0" + m_CRLF + "b=RS:0" + m_CRLF + "b=RR:0" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=candidate:1 1 UDP 2130706431 10.0.1.1 8998 typ host" + m_CRLF + "a=candidate:2 1 UDP 1694498815 192.0.2.3 45664 typ srflx raddr 10.0.1.1 rport 8998"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Debug.WriteLine(sdp.ToString()); Assert.True(sdp.IceUfrag == "8hhY", "The ICE username was not parsed correctly."); Assert.True(sdp.IcePwd == "asd88fgpdd777uzjYhagZg", "The ICE password was not parsed correctly."); }
public void ParseMultipleMediaAnnouncementsUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=- 13064410510996677 3 IN IP4 10.1.1.2" + m_CRLF + "s=Bria 4 release 4.1.1 stamp 74246" + m_CRLF + "c=IN IP4 10.1.1.2" + m_CRLF + "b=AS:2064" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 49290 RTP/AVP 0" + m_CRLF + "a=sendrecv" + m_CRLF + "m=video 56674 RTP/AVP 96" + m_CRLF + "b=TIAS:2000000" + m_CRLF + "a=rtpmap:96 VP8/90000" + m_CRLF + "a=sendrecv" + m_CRLF + "a=rtcp-fb:* nack pli"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Debug.WriteLine(sdp.ToString()); Assert.Equal(2, sdp.Media.Count); Assert.Equal(49290, sdp.Media.Where(x => x.Media == SDPMediaTypesEnum.audio).FirstOrDefault().Port); Assert.Equal(56674, sdp.Media.Where(x => x.Media == SDPMediaTypesEnum.video).FirstOrDefault().Port); }
public void ParseSDPUnitTest() { Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=root 3285 3285 IN IP4 10.0.0.4" + m_CRLF + "s=session" + m_CRLF + "c=IN IP4 10.0.0.4" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 12228 RTP/AVP 0 101" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=fmtp:101 0-16" + m_CRLF + "a=silenceSupp:off - - - -" + m_CRLF + "a=ptime:20" + m_CRLF + "a=sendrecv"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Debug.WriteLine(sdp.ToString()); Assert.True(sdp.Connection.ConnectionAddress == "10.0.0.4", "The connection address was not parsed correctly."); Assert.True(sdp.Media[0].Media == SDPMediaTypesEnum.audio, "The media type not parsed correctly."); Assert.True(sdp.Media[0].Port == 12228, "The connection port was not parsed correctly."); Assert.True(sdp.Media[0].GetFormatListToString() == "0 101", "The media format list was incorrect."); Assert.True(sdp.Media[0].MediaFormats[0].FormatID == 0, "The highest priority media format ID was incorrect."); Assert.True(sdp.Media[0].MediaFormats[0].Name == "PCMU", "The highest priority media format name was incorrect."); Assert.True(sdp.Media[0].MediaFormats[0].ClockRate == 8000, "The highest priority media format clockrate was incorrect."); }
public void ParseAudioAndVideoConnectionsUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=Cisco-SIPUA 6396 0 IN IP4 101.180.234.134" + m_CRLF + "s=SIP Call" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 19586 RTP/AVP 0" + m_CRLF + "c=IN IP4 101.180.234.134" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=sendrecv" + m_CRLF + "m=video 0 RTP/AVP 96" + m_CRLF + "c=IN IP4 10.0.0.10"; SDP sdp = SDP.ParseSDPDescription(sdpStr); logger.LogDebug(sdp.ToString()); Assert.True(sdp.Connection.ConnectionAddress == "101.180.234.134", "The connection address was not parsed correctly."); Assert.NotEmpty(sdp.Media); Assert.True(sdp.Media[0].Media == SDPMediaTypesEnum.audio, "The media type not parsed correctly."); Assert.Equal(SDPMediaFormatsEnum.PCMU, sdp.Media[0].MediaFormats[0].FormatCodec); Assert.True(sdp.Media[1].Media == SDPMediaTypesEnum.video, "The media type not parsed correctly."); Assert.True(sdp.Media[1].Connection.ConnectionAddress == "10.0.0.10", "The connection address was not parsed correctly."); }
public void ParseBadFormatSDPUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = " v=0" + m_CRLF + " o=root 3285 3285 IN IP4 10.0.0.4" + m_CRLF + " s=session" + m_CRLF + " c=IN IP4 10.0.0.4" + m_CRLF + " t=0 0" + m_CRLF + " m=audio 12228 RTP/AVP 0 101" + m_CRLF + " a=rtpmap:0 PCMU/8000" + m_CRLF + " a=rtpmap:101 telephone-event/8000" + m_CRLF + " a=fmtp:101 0-16" + m_CRLF + " a=silenceSupp:off - - - -" + m_CRLF + " a=ptime:20" + m_CRLF + " a=sendrecv"; SDP sdp = SDP.ParseSDPDescription(sdpStr); logger.LogDebug(sdp.ToString()); logger.LogDebug($"audio format[0]: {sdp.Media[0].MediaFormats[0].ToString()}"); logger.LogDebug($"audio format[1]: {sdp.Media[0].MediaFormats[1].ToString()}"); Assert.True(sdp.Connection.ConnectionAddress == "10.0.0.4", "The connection address was not parsed correctly."); Assert.True(sdp.Username == "root", "The owner was not parsed correctly."); Assert.True(sdp.SessionName == "session", "The SessionName was not parsed correctly."); Assert.True(sdp.Media[0].Media == SDPMediaTypesEnum.audio, "The media type not parsed correctly."); Assert.Equal(SDPMediaFormatsEnum.PCMU, sdp.Media[0].MediaFormats[0].FormatCodec); Assert.Equal(SDPMediaFormatsEnum.Event, sdp.Media[0].MediaFormats[1].FormatCodec); }
public void ParseBriaSDPUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + "o=- 5 2 IN IP4 10.1.1.2" + m_CRLF + "s=CounterPath Bria" + m_CRLF + "c=IN IP4 144.137.16.240" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 34640 RTP/AVP 0 8 101" + m_CRLF + "a=sendrecv" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=fmtp:101 0-15" + m_CRLF + "a=alt:1 1 : STu/ZtOu 7hiLQmUp 10.1.1.2 34640"; SDP sdp = SDP.ParseSDPDescription(sdpStr); logger.LogDebug(sdp.ToString()); Assert.True(sdp.Connection.ConnectionAddress == "144.137.16.240", "The connection address was not parsed correctly."); Assert.True(sdp.Media[0].Port == 34640, "The connection port was not parsed correctly."); Assert.True(sdp.Media[0].MediaFormats[0].Name() == "PCMU", "The highest priority media format name was incorrect."); Assert.Equal(SDPWellKnownMediaFormatsEnum.PCMU.ToString(), sdp.Media[0].MediaFormats[0].Name()); }
public void ParseSDPUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=root 3285 3285 IN IP4 10.0.0.4" + m_CRLF + "s=session" + m_CRLF + "c=IN IP4 10.0.0.4" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 12228 RTP/AVP 0 101" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=fmtp:101 0-16" + m_CRLF + "a=silenceSupp:off - - - -" + m_CRLF + "a=ptime:20" + m_CRLF + "a=sendrecv"; SDP sdp = SDP.ParseSDPDescription(sdpStr); logger.LogDebug(sdp.ToString()); Assert.True(sdp.Connection.ConnectionAddress == "10.0.0.4", "The connection address was not parsed correctly."); Assert.True(sdp.Media[0].Media == SDPMediaTypesEnum.audio, "The media type not parsed correctly."); Assert.True(sdp.Media[0].Port == 12228, "The connection port was not parsed correctly."); Assert.True(sdp.Media[0].GetFormatListToString() == "0 101", "The media format list was incorrect."); Assert.True(sdp.Media[0].MediaFormats[0].ID == 0, "The highest priority media format ID was incorrect."); Assert.True(sdp.Media[0].MediaFormats[0].Name() == "PCMU", "The highest priority media format name was incorrect."); Assert.Equal(SDPWellKnownMediaFormatsEnum.PCMU.ToString(), sdp.Media[0].MediaFormats[0].Name()); Assert.True(sdp.Media[0].MediaFormats[0].Rtpmap == "PCMU/8000", "The highest priority media format rtpmap was incorrect."); }
/// <summary> /// 设置媒体参数请求(实时) /// </summary> /// <param name="localIp">本地ip</param> /// <param name="mediaPort">rtp/rtcp媒体端口(10000/10001)</param> /// <returns></returns> private string SetMediaReq(string localIp, int[] mediaPort) { SDPConnectionInformation sdpConn = new SDPConnectionInformation(localIp); SDP sdp = new SDP(); sdp.Version = 0; sdp.SessionId = "0"; sdp.Username = _msgCore.LocalSIPId; sdp.SessionName = CommandType.Play.ToString(); sdp.Connection = sdpConn; sdp.Timing = "0 0"; sdp.Address = localIp; SDPMediaFormat psFormat = new SDPMediaFormat(SDPMediaFormatsEnum.PS); psFormat.IsStandardAttribute = false; SDPMediaFormat h264Format = new SDPMediaFormat(SDPMediaFormatsEnum.H264); h264Format.IsStandardAttribute = false; SDPMediaAnnouncement media = new SDPMediaAnnouncement(); media.Media = SDPMediaTypesEnum.video; media.MediaFormats.Add(psFormat); media.MediaFormats.Add(h264Format); media.AddExtra("a=recvonly"); media.AddFormatParameterAttribute(psFormat.FormatID, psFormat.Name); media.AddFormatParameterAttribute(h264Format.FormatID, h264Format.Name); media.Port = mediaPort[0]; sdp.Media.Add(media); return(sdp.ToString()); }
private void Answered(SDP sdp) { Console.WriteLine("XMPP client call answered."); IsUACAnswered = true; SIPResponse okResponse = new SIPResponse(SIPResponseStatusCodesEnum.Ok, "Ok", new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 0))); okResponse.Header.ContentType = SDP.SDP_MIME_CONTENTTYPE; okResponse.Body = sdp.ToString(); SIPDialogue = new SIPDialogue(null, null, null, null, -1, null, null, null, Guid.NewGuid(), Owner, AdminMemberId, null, sdp.ToString()); SIPDialogue.CallDurationLimit = CallDescriptor.CallDurationLimit; CallAnswered(this, okResponse); }
internal void AcceptCall(SDP sdp, Message incomingCall) { foreach (UserAgent userAgent in Useragents.ToArray()) { if (userAgent.CallID == incomingCall.First("Call-ID").Value.ToString()) { Message response = userAgent.CreateResponse(200, "OK"); response.InsertHeader(new Header("application/sdp", "Content-Type")); response.Body = sdp.ToString(); userAgent.SendResponse(response); } } }
public void ParseBadFormatBriaSDPUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = " v=0\r\no=- 5 2 IN IP4 10.1.1.2\r\n s=CounterPath Bria\r\nc=IN IP4 144.137.16.240\r\nt=0 0\r\n m=audio 34640 RTP/AVP 0 8 101\r\na=sendrecv\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15\r\na=alt:1 1 : STu/ZtOu 7hiLQmUp 10.1.1.2 34640\r\n"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Debug.WriteLine(sdp.ToString()); Assert.True(sdp.Connection.ConnectionAddress == "144.137.16.240", "The connection address was not parsed correctly."); Assert.True(sdp.SessionName == "CounterPath Bria", "The SessionName was not parsed correctly."); }
public void ParseBriaSDPUnitTest() { Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0\r\no=- 5 2 IN IP4 10.1.1.2\r\ns=CounterPath Bria\r\nc=IN IP4 144.137.16.240\r\nt=0 0\r\nm=audio 34640 RTP/AVP 0 8 101\r\na=sendrecv\r\na=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15\r\na=alt:1 1 : STu/ZtOu 7hiLQmUp 10.1.1.2 34640\r\n"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Debug.WriteLine(sdp.ToString()); Assert.IsTrue(sdp.Connection.ConnectionAddress == "144.137.16.240", "The connection address was not parsed correctly."); Assert.IsTrue(sdp.Media[0].Port == 34640, "The connection port was not parsed correctly."); Assert.IsTrue(sdp.Media[0].MediaFormats[0].Name == "PCMU", "The highest priority media format name was incorrect."); }
/// <summary> /// Answers an incoming SIP call. /// </summary> public void Answer(MediaManager mediaManager) { _mediaManager = mediaManager; _mediaManager.NewCall(); SDP sdpAnswer = SDP.ParseSDPDescription(m_uas.CallRequest.Body); _mediaManager.SetRemoteSDP(sdpAnswer); SDP sdp = _mediaManager.GetSDP(false); m_uas.Answer(_sdpMimeContentType, sdp.ToString(), null, SIPDialogueTransferModesEnum.NotAllowed); }
/// <summary> /// Sends a re-INVITE request to the remote call party with the supplied SDP. /// </summary> private void SendReInviteRequest(SDP sdp) { if (Dialogue == null) { logger.LogWarning("No dialog available, re-INVITE request cannot be sent."); } else { Dialogue.SDP = sdp.ToString(); var reinviteRequest = Dialogue.GetInDialogRequest(SIPMethodsEnum.INVITE); reinviteRequest.Header.UserAgent = m_userAgent; reinviteRequest.Header.ContentType = m_sdpContentType; reinviteRequest.Body = sdp.ToString(); reinviteRequest.Header.Supported = SIPExtensionHeaders.PRACK; if (m_uac != null) { reinviteRequest.Header.Contact = m_uac.ServerTransaction.TransactionRequest.Header.Contact; reinviteRequest.SetSendFromHints(m_uac.ServerTransaction.TransactionRequest.LocalSIPEndPoint); } else if (m_uas != null) { reinviteRequest.Header.Contact = m_uas.ClientTransaction.TransactionFinalResponse.Header.Contact; reinviteRequest.SetSendFromHints(m_uas.ClientTransaction.TransactionFinalResponse.LocalSIPEndPoint); } else { reinviteRequest.Header.Contact = new List <SIPContactHeader>() { SIPContactHeader.GetDefaultSIPContactHeader() }; } UACInviteTransaction reinviteTransaction = new UACInviteTransaction(m_transport, reinviteRequest, m_outboundProxy); reinviteTransaction.SendInviteRequest(); reinviteTransaction.UACInviteTransactionFinalResponseReceived += ReinviteRequestFinalResponseReceived; } }
private void Answered(SDP xmppSDP) { //Console.WriteLine("Yay call answered."); //Console.WriteLine(sdp.ToString()); m_xmppServerEndPoint = SDP.GetSDPRTPEndPoint(xmppSDP.ToString()); logger.Debug("Sending STUN binding request to " + m_xmppServerEndPoint + "."); STUNMessage initMessage = new STUNMessage(STUNMessageTypesEnum.BindingRequest); initMessage.AddUsernameAttribute(xmppSDP.IceUfrag + m_localSTUNUFrag); byte[] stunMessageBytes = initMessage.ToByteBuffer(); m_xmppMediaSocket.Send(stunMessageBytes, stunMessageBytes.Length, m_xmppServerEndPoint); m_uas.Answer("application/sdp", GetSDPForSIPResponse().ToString(), null, SIPDialogueTransferModesEnum.NotAllowed); }
public void DescriptionAttributeRoundTripTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = @"v=0 o=root 5936658357711814578 0 IN IP4 0.0.0.0 s=- i=A session description t=0 0 m=audio 55316 RTP/AVP 0 101 a=rtpmap:0 PCMU/8000 a=label:1 i=speech a=rtpmap:101 telephone-event/8000 a=fmtp:101 0-15 a=ptime:20 a=sendrecv m=video 61682 UDP/TLS/RTP/SAVPF 96 c=IN IP4 192.168.11.50 a=rtpmap:96 VP8/90000 a=label:2 i=video title a=sendrecv "; SDP sdp = SDP.ParseSDPDescription(sdpStr); logger.LogDebug(sdp.ToString()); SDP rndTripSdp = SDP.ParseSDPDescription(sdp.ToString()); Assert.Equal("A session description", rndTripSdp.SessionDescription); Assert.Equal("speech", rndTripSdp.Media.Where(x => x.Media == SDPMediaTypesEnum.audio).Single().MediaDescription); Assert.Equal("video title", rndTripSdp.Media.Where(x => x.Media == SDPMediaTypesEnum.video).Single().MediaDescription); }
public void SendInvite(string uri, SDP sdp) { uri = checkURI(uri); UserAgent cua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(uri) }; Useragents.Add(cua); Message invite = cua.CreateRequest("INVITE"); invite.InsertHeader(new Header("application/sdp", "Content-Type")); invite.Body = sdp.ToString(); cua.SendRequest(invite); }
public void ParseDataChannelOnlyOfferSDPUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = @"v=0 o=- 2691666610091555147 2 IN IP4 127.0.0.1 s=- t=0 0 a=group:BUNDLE 0 a=msid-semantic: WMS m=application 9 UDP/DTLS/SCTP webrtc-datachannel c=IN IP4 0.0.0.0 a=ice-ufrag:KQVl a=ice-pwd:E+imlxJhaTN7Is+Qen3Hu6eK a=ice-options:trickle a=fingerprint:sha-256 6E:04:B9:05:60:84:22:B5:5A:A3:E9:00:6D:1A:29:FC:6F:C7:D9:79:D7:3B:BC:8D:BC:3D:7F:FC:94:3A:10:9E a=setup:actpass a=mid:0 a=sctp-port:5000 a=max-message-size:262144"; SDP sdp = SDP.ParseSDPDescription(sdpStr); logger.LogDebug(sdp.ToString()); SDP rndTripSdp = SDP.ParseSDPDescription(sdp.ToString()); Assert.Equal("BUNDLE 0", rndTripSdp.Group); Assert.Single(rndTripSdp.Media); Assert.Equal("sha-256 6E:04:B9:05:60:84:22:B5:5A:A3:E9:00:6D:1A:29:FC:6F:C7:D9:79:D7:3B:BC:8D:BC:3D:7F:FC:94:3A:10:9E", rndTripSdp.Media.Single().DtlsFingerprint); Assert.Single(rndTripSdp.Media.Single().ApplicationMediaFormats); Assert.Equal(5000, rndTripSdp.Media.Single().SctpPort.Value); Assert.Equal(262144, rndTripSdp.Media.Single().MaxMessageSize); }
/// <summary> /// Event handler for an answer on an outgoing Google Voice call. /// </summary> /// <param name="xmppSDP">The SDP packet received from the Google Voice gateway.</param> private void XMPPAnswered(SDP xmppSDP) { StatusMessage("Google Voice call answered."); IPEndPoint remoteSDPEndPoint = SDP.GetSDPRTPEndPoint(xmppSDP.ToString()); _audioChannel.SetRemoteRTPEndPoint(remoteSDPEndPoint); // Google Voice require that a STUN exchange occurs on the RTP socket before the RTP packet can flow. // This code block sends a STUN binding request to the Google Voice gateway. STUNMessage initMessage = new STUNMessage(STUNMessageTypesEnum.BindingRequest); initMessage.AddUsernameAttribute(xmppSDP.IceUfrag + m_localSTUNUFrag); byte[] stunMessageBytes = initMessage.ToByteBuffer(); //_audioChannel.SendRTPRaw(stunMessageBytes, stunMessageBytes.Length); }
/// <summary> /// Event handler for receiving a re-INVITE request on an established call. /// In call requests can be used for multitude of different purposes. In this /// example program we're only concerned with re-INVITE requests being used /// to place a call on/off hold. /// </summary> /// <param name="uasTransaction">The user agent server invite transaction that /// was created for the request. It needs to be used for sending responses /// to ensure reliable delivery.</param> private static void ReinviteRequestReceived(UASInviteTransaction uasTransaction) { SIPRequest reinviteRequest = uasTransaction.TransactionRequest; // Re-INVITEs can also be changing the RTP end point. We can update this each time. IPEndPoint dstRtpEndPoint = SDP.GetSDPRTPEndPoint(reinviteRequest.Body); _remoteRtpEndPoint = dstRtpEndPoint; // If the RTP callfow attribute has changed it's most likely due to being placed on/off hold. SDP newSDP = SDP.ParseSDPDescription(reinviteRequest.Body); if (GetRTPStatusAttribute(newSDP) == RTP_ATTRIBUTE_SENDONLY) { Log.LogInformation("Remote call party has placed us on hold."); _holdStatus = HoldStatus.RemotePutOnHold; _ourSDP = GetSDP(_ourRtpSocket.LocalEndPoint as IPEndPoint, RTP_ATTRIBUTE_RECVONLY); var okResponse = SIPTransport.GetResponse(reinviteRequest, SIPResponseStatusCodesEnum.Ok, null); okResponse.Header.ContentType = SDP.SDP_MIME_CONTENTTYPE; okResponse.Body = _ourSDP.ToString(); uasTransaction.SendFinalResponse(okResponse); } else if (GetRTPStatusAttribute(newSDP) == RTP_ATTRIBUTE_SENDRECV && _holdStatus != HoldStatus.None) { Log.LogInformation("Remote call party has taken us off hold."); _holdStatus = HoldStatus.None; _ourSDP = GetSDP(_ourRtpSocket.LocalEndPoint as IPEndPoint, RTP_ATTRIBUTE_SENDRECV); var okResponse = SIPTransport.GetResponse(reinviteRequest, SIPResponseStatusCodesEnum.Ok, null); okResponse.Header.ContentType = SDP.SDP_MIME_CONTENTTYPE; okResponse.Body = _ourSDP.ToString(); uasTransaction.SendFinalResponse(okResponse); } else { Log.LogWarning("Not sure what the remote call party wants us to do..."); // We'll just reply Ok and hope eveything is good. var okResponse = SIPTransport.GetResponse(reinviteRequest, SIPResponseStatusCodesEnum.Ok, null); okResponse.Header.ContentType = SDP.SDP_MIME_CONTENTTYPE; okResponse.Body = _ourSDP.ToString(); uasTransaction.SendFinalResponse(okResponse); } }
/// <summary> /// Places an outgoing SIP call. /// </summary> /// <param name="destination">The SIP URI to place a call to. The destination can be a full SIP URI in which case the all will /// be placed anonymously directly to that URI. Alternatively it can be just the user portion of a URI in which case it will /// be sent to the configured SIP server.</param> public void Call(MediaManager mediaManager, string destination) { //_initialisationTask.Wait(_cancelCallTokenSource.Token); _mediaManager = mediaManager; _mediaManager.NewCall(); // Determine if this is a direct anonymous call or whether it should be placed using the pre-configured SIP server account. SIPURI callURI = null; string sipUsername = null; string sipPassword = null; string fromHeader = null; if (destination.Contains("@") || m_sipServer == null) { // Anonymous call direct to SIP server specified in the URI. callURI = SIPURI.ParseSIPURIRelaxed(destination); fromHeader = (new SIPFromHeader(m_sipFromName, SIPURI.ParseSIPURI(SIPFromHeader.DEFAULT_FROM_URI), null)).ToString(); } else { // This call will use the pre-configured SIP account. callURI = SIPURI.ParseSIPURIRelaxed(destination + "@" + m_sipServer); sipUsername = m_sipUsername; sipPassword = m_sipPassword; fromHeader = (new SIPFromHeader(m_sipFromName, new SIPURI(m_sipUsername, m_sipServer, null), null)).ToString(); } StatusMessage("Starting call to " + callURI.ToString() + "."); m_uac = new SIPClientUserAgent(m_sipTransport, null, null, null, null); m_uac.CallTrying += CallTrying; m_uac.CallRinging += CallRinging; m_uac.CallAnswered += CallAnswered; m_uac.CallFailed += CallFailed; // Get the SDP requesting that the public IP address be used if the host on the call destination is not a private IP address. SDP sdp = _mediaManager.GetSDP(!(IPAddress.TryParse(callURI.Host, out _) && IPSocket.IsPrivateAddress(callURI.Host))); System.Diagnostics.Debug.WriteLine(sdp.ToString()); SIPCallDescriptor callDescriptor = new SIPCallDescriptor(sipUsername, sipPassword, callURI.ToString(), fromHeader, null, null, null, null, SIPCallDirection.Out, _sdpMimeContentType, sdp.ToString(), null); m_uac.Call(callDescriptor); }
[Ignore] // TODO: Look into test failure. public void ParseEdgeBrowserSdpUnitTest() { Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = @"v=0 o=- 8028343537520473029 0 IN IP4 127.0.0.1 s=- t=0 0 a=msid-semantic: WMS a=group:BUNDLE audio m=audio 7038 UDP/TLS/RTP/SAVPF 0 c=IN IP4 10.0.75.1 a=rtpmap:0 PCMU/8000 a=rtcp:9 IN IP4 0.0.0.0 a=setup:active a=mid:audio a=maxptime:60 a=recvonly a=ice-ufrag:1Fs+ a=ice-pwd:oiLbCgce1c9xzyamdrWtn9Q/ a=fingerprint:sha-256 B0:1F:2C:72:8F:1A:14:CD:92:15:47:F0:C3:0A:69:F9:A9:43:35:EE:10:CB:F0:11:18:B8:0E:F9:A6:95:5F:B1 a=candidate:1 1 udp 2130706431 10.0.75.1 7038 typ host a=candidate:2 1 udp 2130705919 172.22.240.1 31136 typ host a=candidate:3 1 udp 2130705407 172.22.48.1 21390 typ host a=candidate:4 1 udp 2130704895 192.168.11.50 26878 typ host a=candidate:5 1 tcp 1684797439 10.0.75.1 7038 typ srflx raddr 10.0.75.1 rport 7038 tcptype active a=rtcp-mux m=video 0 UDP/TLS/RTP/SAVPF c=IN IP4 0.0.0.0 a=inactive"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Debug.WriteLine(sdp.ToString()); Assert.AreEqual(2, sdp.Media.Count); Assert.IsTrue(sdp.Media.First().Media == SDPMediaTypesEnum.audio); Assert.IsTrue(sdp.Media.First().Transport == "UDP/TLS/RTP/SAVPF"); Assert.IsTrue(sdp.Media.Last().Media == SDPMediaTypesEnum.video); Assert.IsTrue(sdp.Media.Last().Transport == "UDP/TLS/RTP/SAVPF"); //Assert.AreEqual(2, sdp.Connection); //Assert.AreEqual(49290, sdp.Media.Where(x => x.Media == SDPMediaTypesEnum.audio).FirstOrDefault().Port); // Assert.AreEqual(56674, sdp.Media.Where(x => x.Media == SDPMediaTypesEnum.video).FirstOrDefault().Port); }
public void InvalidPortInRemoteOfferTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); var remoteOffer = new SDP(); var sessionPort = 5523; var sessionEndpoint = "10vMB2Ee;tcp"; remoteOffer.Connection = new SDPConnectionInformation(IPAddress.Loopback); var messageMediaFormat = new SDPMessageMediaFormat(); messageMediaFormat.IP = remoteOffer.Connection.ConnectionAddress; messageMediaFormat.Port = sessionPort.ToString(); messageMediaFormat.Endpoint = sessionEndpoint; messageMediaFormat.AcceptTypes = new List <string> { "text/plain", "text/x-msrp-heartbeat" }; SDPMediaAnnouncement messageAnnouncement = new SDPMediaAnnouncement( SDPMediaTypesEnum.message, remoteOffer.Connection, sessionPort, messageMediaFormat); messageAnnouncement.Transport = "TCP/MSRP"; remoteOffer.Media.Add(messageAnnouncement); var sdpOffer = remoteOffer.ToString(); var msrpMediaAttribute = $"{SDPMediaAnnouncement.MEDIA_FORMAT_PATH_MSRP_PREFIX}//{remoteOffer.Connection.ConnectionAddress}:{sessionPort}/{sessionEndpoint}"; var msrpMediaTypes = $"{SDPMediaAnnouncement.MEDIA_FORMAT_PATH_ACCEPT_TYPES_PREFIX}text/plain text/x-msrp-heartbeat"; var mediaDescription = $"m=message {sessionPort} TCP/MSRP *"; Assert.Contains(msrpMediaAttribute, sdpOffer); Assert.Contains(msrpMediaTypes, sdpOffer); Assert.Contains(mediaDescription, sdpOffer); }
public void ParseEdgeBrowserSdpUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=- 8028343537520473029 0 IN IP4 127.0.0.1" + m_CRLF + "s=-" + m_CRLF + "t=0 0" + m_CRLF + "a=msid-semantic: WMS" + m_CRLF + "a=group:BUNDLE audio" + m_CRLF + "m=audio 7038 UDP/TLS/RTP/SAVPF 0" + m_CRLF + "c=IN IP4 10.0.75.1" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtcp:9 IN IP4 0.0.0.0" + m_CRLF + "a=setup:active" + m_CRLF + "a=mid:audio" + m_CRLF + "a=maxptime:60" + m_CRLF + "a=recvonly" + m_CRLF + "a=ice-ufrag:1Fs+" + m_CRLF + "a=ice-pwd:oiLbCgce1c9xzyamdrWtn9Q/" + m_CRLF + "a=fingerprint:sha-256 B0:1F:2C:72:8F:1A:14:CD:92:15:47:F0:C3:0A:69:F9:A9:43:35:EE:10:CB:F0:11:18:B8:0E:F9:A6:95:5F:B1" + m_CRLF + "a=candidate:1 1 udp 2130706431 10.0.75.1 7038 typ host" + m_CRLF + "a=candidate:2 1 udp 2130705919 172.22.240.1 31136 typ host" + m_CRLF + "a=candidate:3 1 udp 2130705407 172.22.48.1 21390 typ host" + m_CRLF + "a=candidate:4 1 udp 2130704895 192.168.11.50 26878 typ host" + m_CRLF + "a=candidate:5 1 tcp 1684797439 10.0.75.1 7038 typ srflx raddr 10.0.75.1 rport 7038 tcptype active" + m_CRLF + "a=rtcp-mux" + m_CRLF + "m=video 0 UDP/TLS/RTP/SAVPF" + m_CRLF + "c=IN IP4 0.0.0.0" + m_CRLF + "a=inactive"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Debug.WriteLine(sdp.ToString()); Assert.Equal(2, sdp.Media.Count); Assert.True(sdp.Media.First().Media == SDPMediaTypesEnum.audio); Assert.True(sdp.Media.First().Transport == "UDP/TLS/RTP/SAVPF"); Assert.True(sdp.Media.Last().Media == SDPMediaTypesEnum.video); Assert.True(sdp.Media.Last().Transport == "UDP/TLS/RTP/SAVPF"); }
public void Invite(string uri, SDP sdp) { uri = checkURI(uri); if (IsRegistered()) { UserAgent cua = new UserAgent(Stack) { LocalParty = RegisterUA.LocalParty, RemoteParty = new Address(uri) }; Useragents.Add(cua); Message invite = cua.CreateRequest("INVITE"); invite.InsertHeader(new Header("application/sdp", "Content-Type")); invite.Body = sdp.ToString(); cua.SendRequest(invite); } else { Log.Error("isRegistered failed in invite message"); } }
public void ParseAudioAndVideoConnectionsUnitTest() { Logger.LogDebug(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=Cisco-SIPUA 6396 0 IN IP4 101.180.234.134" + m_CRLF + "s=SIP Call" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 19586 RTP/AVP 0" + m_CRLF + "c=IN IP4 101.180.234.134" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=sendrecv" + m_CRLF + "m=video 0 RTP/AVP 96" + m_CRLF + "c=IN IP4 10.0.0.10"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Logger.LogDebug(sdp.ToString()); Assert.True(sdp.Connection.ConnectionAddress == "101.180.234.134", "The connection address was not parsed correctly."); }
public void ParseIPv6SDPUnitTest() { Logger.LogDebug(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=nasa1 971731711378798081 0 IN IP6 2201:056D::112E:144A:1E24" + m_CRLF + "s=(Almost) live video feed from Mars-II satellite" + m_CRLF + "p=+1 713 555 1234" + m_CRLF + "c=IN IP6 FF1E:03AD::7F2E:172A:1E24" + m_CRLF + "t=3338481189 3370017201" + m_CRLF + "m=audio 6000 RTP/AVP 2" + m_CRLF + "a=rtpmap:2 G726-32/8000" + m_CRLF + "m=video 6024 RTP/AVP 107" + m_CRLF + "a=rtpmap:107 H263-1998/90000"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Logger.LogDebug(sdp.ToString()); Assert.True(sdp.Connection.ConnectionAddressType == "IP6", "The connection address type not parsed correctly."); Assert.True(sdp.Connection.ConnectionAddress == "FF1E:03AD::7F2E:172A:1E24", "The connection address was not parsed correctly."); }
/// <summary> /// 设置媒体参数请求(实时) /// </summary> /// <param name="localIp">本地ip</param> /// <param name="mediaPort">rtp/rtcp媒体端口(10000/10001)</param> /// <returns></returns> private string SetMediaAudio(string localIp, int port, string audioId) { var sdpConn = new SDPConnectionInformation(localIp); var sdp = new SDP { Version = 0, SessionId = "0", Username = audioId, SessionName = CommandType.Play.ToString(), Connection = sdpConn, Timing = "0 0", Address = localIp }; var psFormat = new SDPMediaFormat(SDPMediaFormatsEnum.PS) { IsStandardAttribute = false }; var media = new SDPMediaAnnouncement { Media = SDPMediaTypesEnum.audio }; media.MediaFormats.Add(psFormat); media.AddExtra("a=sendonly"); media.AddExtra("y=0100000002"); //media.AddExtra("f=v/////a/1/8/1"); media.AddFormatParameterAttribute(psFormat.FormatID, psFormat.Name); media.Port = port; sdp.Media.Add(media); return(sdp.ToString()); }
public void ParseMediaTypeImageUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=OfficeMasterDirectSIP 806542878 806542879 IN IP4 10.2.0.110" + m_CRLF + "s=FOIP Call" + m_CRLF + "c=IN IP4 10.2.0.110" + m_CRLF + "t=0 0" + m_CRLF + "m=image 50594 udptl t38" + m_CRLF + "a=T38FaxRateManagement:transferredTCF" + m_CRLF + "a=T38FaxVersion:0"; SDP sdp = SDP.ParseSDPDescription(sdpStr); logger.LogDebug(sdp.ToString()); Assert.True(sdp.Connection.ConnectionAddress == "10.2.0.110", "The connection address was not parsed correctly."); Assert.NotEmpty(sdp.Media); Assert.True(sdp.Media[0].Media == SDPMediaTypesEnum.image, "The media type not parsed correctly."); Assert.True(sdp.Media[0].HasMediaFormat("t38"), "The highest priority media format ID was incorrect."); Assert.True(sdp.Media[0].Transport == "udptl", "The media transport string was incorrect."); }
public void ParseAudioAndVideoConnectionsUnitTest() { Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name); string sdpStr = "v=0" + m_CRLF + "o=Cisco-SIPUA 6396 0 IN IP4 101.180.234.134" + m_CRLF + "s=SIP Call" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 19586 RTP/AVP 0" + m_CRLF + "c=IN IP4 101.180.234.134" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=sendrecv" + m_CRLF + "m=video 0 RTP/AVP 96" + m_CRLF + "c=IN IP4 10.0.0.10"; SDP sdp = SDP.ParseSDPDescription(sdpStr); Debug.WriteLine(sdp.ToString()); Assert.IsTrue(sdp.Connection.ConnectionAddress == "101.180.234.134", "The connection address was not parsed correctly."); //Assert.AreEqual(2, sdp.Connection); //Assert.AreEqual(49290, sdp.Media.Where(x => x.Media == SDPMediaTypesEnum.audio).FirstOrDefault().Port); // Assert.AreEqual(56674, sdp.Media.Where(x => x.Media == SDPMediaTypesEnum.video).FirstOrDefault().Port); }