示例#1
0
        /// <summary>
        /// Accepts call.
        /// </summary>
        /// <param name="sdp">Media answer.</param>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when call is not in valid state and this method is called.</exception>
        /// <exception cref="ArgumentNullException">Is raised when <b>sdp</b> is null reference.</exception>
        public void Accept(SDP_Message sdp)
        {
            if (m_State == SIP_UA_CallState.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if (m_State != SIP_UA_CallState.WaitingToAccept)
            {
                throw new InvalidOperationException("Accept method can be called only in 'SIP_UA_CallState.WaitingToAccept' state.");
            }
            if (sdp == null)
            {
                throw new ArgumentNullException("sdp");
            }

            m_pLocalSDP = sdp;

            // TODO: We must add Contact header and SDP to response.

            SIP_Response response = m_pUA.Stack.CreateResponse(SIP_ResponseCodes.x200_Ok, m_pInitialInviteTransaction.Request, m_pInitialInviteTransaction.Flow);

            response.ContentType = "application/sdp";
            response.Data        = sdp.ToByte();
            m_pInitialInviteTransaction.SendResponse(response);

            SetState(SIP_UA_CallState.Active);

            m_pDialog = m_pUA.Stack.TransactionLayer.GetOrCreateDialog(m_pInitialInviteTransaction, response);
            m_pDialog.StateChanged += new EventHandler(m_pDialog_StateChanged);
        }
示例#2
0
        private void toResponse(SIP_RequestReceivedEventArgs e)
        {
            SIP_Uri uri = e.Request.RequestLine.Uri as SIP_Uri;

            try
            {
                _sdp     = SDP_Message.Parse(MyEncoder.Encoder.GetString(e.Request.Data));
                RemoteIP = _sdp.Origin.UnicastAddress;
                if (_sdp.MediaDescriptions.Count == 0)
                {
                    e.ServerTransaction.SendResponse(_sipServer.Stack.CreateResponse(SIP_ResponseCodes.x400_Bad_Request, e.Request));
                    return;
                }
                else
                {
                    RemotePort = _sdp.MediaDescriptions[0].Port;
                }
            }
            catch (Exception)
            {
                //解析SDP失败。
                e.ServerTransaction.SendResponse(_sipServer.Stack.CreateResponse(SIP_ResponseCodes.x400_Bad_Request, e.Request));
                return;
            }

            //send 100 Trying;
            e.ServerTransaction.SendResponse(_sipServer.Stack.CreateResponse(SIP_ResponseCodes.x100_Trying, e.Request));

            _videoId = _sipServer.DeviceManager.GetVideoId(uri.User);
            if (_videoId != null)
            {
                RTPServer   rtp     = _sipServer.RTPManager.GetOrAddServer(_videoId);
                SDP_Message respSDP = new SDP_Message();
                respSDP.Version     = "0";
                respSDP.Origin      = new SDP_Origin(uri.User, 0, 0, "IN", "IPV4", rtp.LocalIP);
                respSDP.SessionName = "Play";
                respSDP.Connection  = new SDP_Connection("IN", "IPV4", rtp.LocalIP);
                respSDP.SSRC        = SDP_Utils.SSRC2String(SDP_Utils.GenSSRC(uri.User, true)); //根据国标补充协议标准生成SSRC。
                respSDP.Times.Add(new SDP_Time(0, 0));
                respSDP.MediaDescriptions.Add(new SDP_MediaDescription("video", rtp.Port, 2, "RTP/AVP", new string[] { "96", "97", "98" }));
                respSDP.Attributes.Add(new SDP_Attribute("sendonly", ""));
                respSDP.Attributes.Add(new SDP_Attribute("rtpmap", "96 PS/90000"));
                respSDP.Attributes.Add(new SDP_Attribute("rtpmap", "97 MPEG4/90000"));
                respSDP.Attributes.Add(new SDP_Attribute("rtpmap", "98 H264/90000"));

                SIP_Response resp = _sipServer.Stack.CreateResponse(SIP_ResponseCodes.x200_Ok, e.Request);
                resp.Data = respSDP.ToByte();
                e.ServerTransaction.SendResponse(resp);
            }
            else
            {
                //没有找到视频源。
                e.ServerTransaction.SendResponse(_sipServer.Stack.CreateResponse(SIP_ResponseCodes.x404_Not_Found, e.Request));
            }
        }
示例#3
0
        /// <summary>
        /// Sends ringing to remote party.
        /// </summary>
        /// <param name="sdp">Early media answer or early media offer when initial INVITE don't have SDP.</param>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when call is not in valid state and this method is called.</exception>
        public void SendRinging(SDP_Message sdp)
        {
            if (m_State == SIP_UA_CallState.Disposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if (m_State != SIP_UA_CallState.WaitingToAccept)
            {
                throw new InvalidOperationException("Accept method can be called only in 'SIP_UA_CallState.WaitingToAccept' state.");
            }

            SIP_Response response = m_pUA.Stack.CreateResponse(SIP_ResponseCodes.x180_Ringing, m_pInitialInviteTransaction.Request, m_pInitialInviteTransaction.Flow);

            if (sdp != null)
            {
                response.ContentType = "application/sdp";
                response.Data        = sdp.ToByte();

                m_pLocalSDP = sdp;
            }
            m_pInitialInviteTransaction.SendResponse(response);
        }