(1)rtsp服务器既支持udp模式也支持tcp模式,使用VLC拉流时,默认回复的是udp模式。在测试过程中发现,当udp模式下,VLC播放器会检测服务器分配的视频流端口是否可用,不可用的话,会断掉连接,重新使用tcp模式进行连接。
OPTIONS rtsp://192.168.1.66:3365/username=xiaoming RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
RTSP/1.0 200 OK
CSeq: 2
Date: Thu Jul 9 11:39:06 2020
Public: OPTIONS, DESCRIBE, SETUP, PLAY, GET_PARAMETER, TEARDOWN
DESCRIBE rtsp://192.168.1.66:3365/username=xiaoming RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
RTSP/1.0 200 OK
CSeq: 3
Date: Thu Jul 9 11:39:06 2020
Content-Type: application/sdp
Content-Length: 168
v=0
o=- 0 0 IN IP4 192.168.1.166
s=sipproxy server
c=IN IP4 192.168.1.166
t=0 0
m=video 0 RTP/AVP 98
a=control:trackID=1
a=range:npt=0-
a=rtpmap:98 H264/90000
SETUP rtsp://192.168.1.66:3365/username=xiaoming/trackID=1 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=56440-56441
RTSP/1.0 200 OK
CSeq: 4
Date: Thu Jul 9 11:39:06 2020
Session: 1594265946-27971;timeout=60
Transport: RTP/AVP;unicast;destination=192.168.1.66;source=192.168.1.166;client_port=56440-56441;server_port=15721-15722;mode="play"
PLAY rtsp://192.168.1.66:3365/username=xiaoming RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
Session: 1594265946-27971
Range: npt=0.000-
RTSP/1.0 200 OK
CSeq: 5
Date: Thu Jul 9 11:39:06 2020
Session: 1594265946-27971
RTP-Info: url=rtsp://192.168.1.166:3365/username=xiaoming;seq=0;rtptime=0
Range: npt=0.000-
TEARDOWN rtsp://192.168.1.66:3365/username=xiaoming RTSP/1.0
CSeq: 6
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
Session: 1594265946-27971
RTSP/1.0 200 OK
CSeq: 6
Date: Thu Jul 9 11:39:16 2020
Session: 1594265946-27971
上述流程为先使用udp方式进行连接,从抓包来看,服务器端口15721-15722是不可达的
通过ICMP tcp/ip控制数据包来看,上面发送的udp包端口不可达,然后VLC直接断开了rtsp请求,改用tcp模式进行请求视频。
OPTIONS rtsp://192.168.1.166:3365/username=xiaoming RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
RTSP/1.0 200 OK
CSeq: 2
Date: Thu Jul 9 11:39:16 2020
Public: OPTIONS, DESCRIBE, SETUP, PLAY, GET_PARAMETER, TEARDOWN
DESCRIBE rtsp://192.168.1.166:3365/username=xiaoming RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
RTSP/1.0 200 OK
CSeq: 3
Date: Thu Jul 9 11:39:16 2020
Content-Type: application/sdp
Content-Length: 168
v=0
o=- 0 0 IN IP4 192.168.1.166
s=sipproxy server
c=IN IP4 192.168.1.166
t=0 0
m=video 0 RTP/AVP 98
a=control:trackID=1
a=range:npt=0-
a=rtpmap:98 H264/90000
SETUP rtsp://192.168.1.166:3365/username=xiaoming/trackID=1 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
RTSP/1.0 200 OK
CSeq: 4
Date: Thu Jul 9 11:39:16 2020
Session: 1594265956-27973;timeout=60
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=5db3;mode="play"
PLAY rtsp://192.168.1.166:3365/username=xiaoming RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.6 (LIVE555 Streaming Media v2016.11.28)
Session: 1594265956-27973
Range: npt=0.000-
RTSP/1.0 200 OK
CSeq: 5
Date: Thu Jul 9 11:39:16 2020
Session: 1594265956-27973
RTP-Info: url=rtsp://192.168.1.166:3365/username=xiaoming;seq=0;rtptime=0
Range: npt=0.000-
使用tcp发送视频流的端口就是用通信的端口进行接收数据包,这种方式可以灵活的对应两种不用的网络环境,当udp不满足条件时,转换为tcp模式进行通信。