INVITE sip:20002230000@39.106.209.165 SIP/2.0Via: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK56308Max-Forwards: 70To: <sip:20002230000@39.106.209.165>From: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736Call-ID: 509381976447CSeq: 1 INVITEContact: <sip:20002230001@10.230.9.106:45426;transport=udp>User-Agent: Zed-3-PDAService1-Extension: V1.0Content-Length: 351Content-Type: application/sdpv=0o=20002230001@39.106.209.165 0 0 IN IP4 10.230.9.106s=Session SIP/SDPc=IN IP4 10.230.9.106t=0 0m=audio 21000 RTP/AVP 114 101a=rtpmap:114 AMR/8000a=fmtp:114 mode-set=0a=rtpmap:101 telephone-event/8000a=fmtp:101 0-15a=ptime:100m=video 21070 RTP/AVP 126a=rtpmap:126 H264/90000a=fmtp:126 profile-level-id=42e00b;cif=1;fps=10
2、Server给客户端A发407 Proxy Authentication Required响应,表明要求对用户进行识别认证,并且通过Proxy-Authenticate字段携带Server支持的认证方式Digest和产生本次认证的nonce。SIP/2.0 407 Proxy Authentication RequiredVia: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK56308From: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736To: <sip:20002230000@39.106.209.165>;tag=04d930f20Call-ID: 509381976447CSeq: 1 INVITEUser-Agent: ASG SwitchContact: <sip:20002230000@39.106.209.165:7080>Proxy-Authenticate: Digest realm="ASG Switch", nonce="212a425d"Content-Length: 0
3、 客户端A发ACK消息给Server,证实已经收到Server对于INVITE请求的最终响应。ACK sip:20002230000@39.106.209.165 SIP/2.0Via: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK56308Max-Forwards: 70To: <sip:20002230000@39.106.209.165>;tag=04d930f20From: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736Call-ID: 509381976447CSeq: 1 ACKUser-Agent: Zed-3-PDAContent-Length: 0
4、客户端A重新发INVITE请求到Server。携带 Proxy-Authorization字段,包括认证方式DIGEST、用户标识(此时为电话号码)、域名、NONCE、URI和RESPONSE。INVITE sip:20002230000@39.106.209.165 SIP/2.0Via: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK16771Max-Forwards: 70To: <sip:20002230000@39.106.209.165>From: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736Call-ID: 509381976447CSeq: 2 INVITEContact: <sip:20002230001@10.230.9.106:45426;transport=udp>User-Agent: Zed-3-PDAService1-Extension: V1.0Proxy-Authorization: Digest username="20002230001", realm="ASG Switch", nonce="212a425d", uri="sip:20002230000@39.106.209.165", response="9a10b27ca9ea0e5a386df09896776ed7"Content-Length: 351Content-Type: application/sdpv=0o=20002230001@39.106.209.165 0 0 IN IP4 10.230.9.106s=Session SIP/SDPc=IN IP4 10.230.9.106t=0 0m=audio 21000 RTP/AVP 114 101a=rtpmap:114 AMR/8000a=fmtp:114 mode-set=0a=rtpmap:101 telephone-event/8000a=fmtp:101 0-15a=ptime:100m=video 21070 RTP/AVP 126a=rtpmap:126 H264/90000a=fmtp:126 profile-level-id=42e00b;cif=1;fps=10
5、Server给 客户端A回应100 Trying表示已经接收到请求消息,正在对其进行处理。SIP/2.0 100 TryingVia: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK16771From: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736To: <sip:20002230000@39.106.209.165>;tag=442048a6aCall-ID: 509381976447CSeq: 2 INVITEUser-Agent: ASG SwitchContact: <sip:20002230000@39.106.209.165:7080>Content-Length: 0
6、Server向客户端B发INVITE消息,并且通过该INVITE请求消息携带客户端A的SDP会话描述给客户端B。INVITE sip:20002230000@114.242.25.68 SIP/2.0Via: SIP/2.0/UDP 39.106.209.165:7080;branch=6d1da8e3From: "æµè¯APP2" <sip:20002230001@39.106.209.165>;tag=2fe8f607Contact: <sip:20002230001@39.106.209.165:7080>To: <sip:20002230000@114.242.25.68>Call-ID: Anta16897569715b5d4f9c177f8850024e5b3e@190010acCSeq: 26032645 INVITEMax-Forwards: 70User-Agent: Zed-3-PDAService1-Extension: V1.0 close 1689756971Supported: timerSession-Expires: 90Content-Type: application/sdpContent-Length: 562v=0o=root 1830660323 1830660323 IN IP4 39.106.209.165s=sessionc=IN IP4 39.106.209.165t=0 0m=audio 24594 RTP/AVP 114 0 8 18 3 101a=rtpmap:114 AMR/8000a=fmtp:114 mode-set=0a=rtpmap:0 PCMU/8000a=rtpmap:8 PCMA/8000a=rtpmap:18 G729/8000a=rtpmap:3 GSM/8000a=rtpmap:101 telephone-event/8000a=fmtp:101 0-15a=ptime:100m=video 40270 RTP/AVP 126 34 98a=rtpmap:126 H264/90000a=fmtp:126 profile-level-id=42e00b;cif=1;fps=10a=rtpmap:34 H263/90000a=fmtp:34 QCIF=1 CIF=1 MaxBR=4520a=rtpmap:98 MP4V-ES/90000a=fmtp:98 profile-level-id=3
7、客户端B给Server回应100 Trying表示已经接收到请求消息,正在对其进行处理。SIP/2.0 100 TryingVia: SIP/2.0/UDP 39.106.209.165:7080;branch=6d1da8e3To: <sip:20002230000@114.242.25.68>From: "æµè¯APP2" <sip:20002230001@39.106.209.165>;tag=2fe8f607Call-ID: Anta16897569715b5d4f9c177f8850024e5b3e@190010acCSeq: 26032645 INVITEUser-Agent: Zed-3-PDAContent-Length: 0
8、客户端B振铃,并回180 Ringing响应通知Server。SIP/2.0 180 RingingVia: SIP/2.0/UDP 39.106.209.165:7080;branch=6d1da8e3To: <sip:20002230000@114.242.25.68>;tag=9028d8f3a202e4f4From: "æµè¯APP2" <sip:20002230001@39.106.209.165>;tag=2fe8f607Call-ID: Anta16897569715b5d4f9c177f8850024e5b3e@190010acCSeq: 26032645 INVITEUser-Agent: Zed-3-PDAContent-Length: 0
9、Server回应180 Ringing响应给客户端A。SIP/2.0 180 RingingVia: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK16771From: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736To: <sip:20002230000@39.106.209.165>;tag=442048a6aCall-ID: 509381976447CSeq: 2 INVITEUser-Agent: ASG SwitchContact: <sip:20002230000@39.106.209.165:7080>Content-Length: 0
10、客户端B给Server回200 OK响应,表示其发过来的INVITE请求已经被成功接受、处理。并且通过该消息将自身的IP地址:192.168.2.63,音频端口21000,视频端口21070,以及SDP协商等信息传送给Server。SIP/2.0 200 OKVia: SIP/2.0/UDP 39.106.209.165:7080;branch=6d1da8e3To: <sip:20002230000@114.242.25.68>;tag=9028d8f3a202e4f4From: "æµè¯APP2" <sip:20002230001@39.106.209.165>;tag=2fe8f607Call-ID: Anta16897569715b5d4f9c177f8850024e5b3e@190010acCSeq: 26032645 INVITEContact: <sip:20002230000@192.168.2.63:43518;transport=udp>User-Agent: Zed-3-PDAService1-Extension: V1.0Content-Length: 351Content-Type: application/sdpv=0o=20002230000@39.106.209.165 0 0 IN IP4 192.168.2.63s=Session SIP/SDPc=IN IP4 192.168.2.63t=0 0m=audio 21000 RTP/AVP 114 101a=rtpmap:114 AMR/8000a=fmtp:114 mode-set=0a=rtpmap:101 telephone-event/8000a=fmtp:101 0-15a=ptime:100m=video 21070 RTP/AVP 126a=rtpmap:126 H264/90000a=fmtp:126 profile-level-id=42e00b;cif=1;fps=10
11、Server给客户端B回应ACK,证实已经收到客户端B对于INVITE请求的最终响应。ACK sip:20002230000@192.168.2.63:43518;transport=udp SIP/2.0Via: SIP/2.0/UDP 39.106.209.165:7080;branch=6d1da8e3From: "æµè¯APP2" <sip:20002230001@39.106.209.165>;tag=2fe8f607To: <sip:20002230000@114.242.25.68>;tag=9028d8f3a202e4f4Call-ID: Anta16897569715b5d4f9c177f8850024e5b3e@190010acCSeq: 26032645 ACKMax-Forwards: 70User-Agent: ASG SwitchContent-Length: 0
12、Server给客户端A回应200OK,表示接受INVITE请求,并且将客户端B最后选择使用的SDP协商信息传送给客户端A。SIP/2.0 200 OKVia: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK16771From: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736To: <sip:20002230000@39.106.209.165>;tag=442048a6aCall-ID: 509381976447CSeq: 2 INVITEUser-Agent: Zed-3-PDAContact: <sip:20002230000@39.106.209.165:7080>Service1-Extension: V1.0 close 1689756971Content-Type: application/sdpContent-Length: 343v=0o=root 1748269658 1748269658 IN IP4 39.106.209.165s=sessionc=IN IP4 39.106.209.165t=0 0m=audio 18582 RTP/AVP 114 101a=rtpmap:114 AMR/8000a=fmtp:114 mode-set=0a=rtpmap:101 telephone-event/8000a=fmtp:101 0-15a=ptime:100m=video 49166 RTP/AVP 126a=rtpmap:126 H264/90000a=fmtp:126 profile-level-id=42e00b;cif=1;fps=10
13、客户端A发ACK消息给Server,证实已经收到Server对于INVITE请求的最终响应。ACK sip:20002230000@39.106.209.165:7080 SIP/2.0Via: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK70120Max-Forwards: 70To: <sip:20002230000@39.106.209.165>;tag=442048a6aFrom: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736Call-ID: 509381976447CSeq: 2 ACKContact: <sip:20002230001@10.230.9.106:45426;transport=udp>User-Agent: Zed-3-PDAContent-Length: 0
在此刻,主被叫双方都知道了对方的会话描述,成功启动通话。中间就是conversation通话部分,主叫、被叫都把自己的音视频RTP包,发送到server协商好的音视频UDP端口,由server负责来交换转发RTP包。14、客户端A主动发起挂机,发BYE消息给Server,请求结束本次会话。BYE sip:20002230000@39.106.209.165:7080 SIP/2.0Via: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK00543Max-Forwards: 70To: <sip:20002230000@39.106.209.165>;tag=442048a6aFrom: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736Call-ID: 509381976447CSeq: 6 BYEUser-Agent: Zed-3-PDAContent-Length: 0
15、Server给客户端B回200 OK,表明接受请求。SIP/2.0 200 OKVia: SIP/2.0/UDP 10.230.9.106:45426;rport;branch=z9hG4bK00543From: <sip:20002230001@39.106.209.165>;tag=z9hG4bK73846736To: <sip:20002230000@39.106.209.165>;tag=442048a6aCall-ID: 509381976447CSeq: 6 BYEUser-Agent: Zed-3-PDAContact: <sip:20002230000@39.106.209.165:7080>Content-Length: 0
16、Server收到客户端A发过来的BYE消息,知道A已挂机,则给客户端B发BYE请求,请求结束本次会话。BYE sip:20002230000@192.168.2.63:43518;transport=udp SIP/2.0Via: SIP/2.0/UDP 39.106.209.165:7080;branch=6d1da8e3From: <sip:20002230001@39.106.209.165>;tag=2fe8f607To: <sip:20002230000@114.242.25.68>;tag=9028d8f3a202e4f4Call-ID: Anta16897569715b5d4f9c177f8850024e5b3e@190010acCSeq: 26032649 BYEMax-Forwards: 70User-Agent: ASG SwitchContent-Length: 0
17、客户端B给Server回200OK,表示接受请求。SIP/2.0 200 OKVia: SIP/2.0/UDP 39.106.209.165:7080;branch=6d1da8e3To: <sip:20002230000@114.242.25.68>;tag=9028d8f3a202e4f4From: <sip:20002230001@39.106.209.165>;tag=2fe8f607Call-ID: Anta16897569715b5d4f9c177f8850024e5b3e@190010acCSeq: 26032649 BYEUser-Agent: Zed-3-PDAContent-Length: 0
至此,就完成了一个SIP的音视频呼叫,是否感觉有点懂,又很多疑问呢?没事儿,接着往下看。<-----为你答疑解惑----->1.从开篇文章第一张图片中,可以看到,谁发出的一个INVITE信令,一定要再发一个ACK收尾,这是要对应的。2.这17个交互信令中,一定要明白传输SIP信令的UDP端口、SDP协商出来的传输音视频RTP的UDP端口。第一张图片中的客户端A的SIP信令发和收UDP端口是46117,而客户端B的SIP信令发和收UDP端口是43518,其中服务器server对外的SIP信令UDP端口是7080,服务器的这个端口是固定的。一张图带你理解上面整个过程之后,确定的UDP端口通信流程。3.简单说下SDP协商协议,这真没必要详细说,因为还要求你懂G711、H264常用的音视频编码。所以,我就简单说,让你懂大概,看关键。这是第1个信令交互中的SDP信息:v=0o=20002230001@39.106.209.165 0 0 IN IP4 10.230.9.106s=Session SIP/SDPc=IN IP4 10.230.9.106t=0 0m=audio 21000 RTP/AVP 114 101a=rtpmap:114 AMR/8000a=fmtp:114 mode-set=0a=rtpmap:101 telephone-event/8000a=fmtp:101 0-15a=ptime:100m=video 21070 RTP/AVP 126a=rtpmap:126 H264/90000a=fmtp:126 profile-level-id=42e00b;cif=1;fps=10
其中m行,代表media媒体行,audio代表音频,video代表视频。其中a行,代表媒体的属性行,这个就要懂点音视频编码了。<------好了到结尾线了--------->【多余的解释:】1.掌握SIP协议中的音视频呼叫时关键,记住开篇那张图;2.可以看我的另一篇文章:犹豫很久终于写下来了,从海康摄像头的ps流中提取h264原始数据(图片来源网络,侵删)
0 评论