live555 rtspserver端 创建并且接收客户端数据 环境下,用RawCap 抓取了完整的log
WireShark 打开预览如下
从 OPTIONS DESCRIBE SETUP PLAY TEARDOWN 完整的 RTSP协议流程
我在本地的操作,就是播放视频,然后teardown 点击vlc 停止播放,发送的请求
1. OPTIONS
VLC >>>>>>============= SEND OPTIONS REQUEST===============>>>> RTSPSERVER
Request: OPTIONS rtsp://10.0.2.15:554/ss1.mkv RTSP/1.0\r\n
CSeq: 2\r\n
User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
\r\n
VLC <<<<================== RESPONSE 200=============<<<<< RTSPSERVER
Response: RTSP/1.0 200 OK\r\n
CSeq: 2\r\n
Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER\r\n
\r\n
2. OPTIONS
VLC >>>>>============ SEND DESCRIBE REQUEST==============>>>>>> RTSPSERVER
Request: DESCRIBE rtsp://10.0.2.15:554/ss1.mkv RTSP/1.0\r\n
CSeq: 3\r\n
User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
Accept: application/sdp\r\n
\r\n
VLC <<<<================= RESPONSE 200===============<<<<< RTSPSERVER
Response: RTSP/1.0 200 OK\r\n
CSeq: 3\r\n
Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
Content-Base: rtsp://10.0.2.15/ss1.mkv/\r\n
Content-type: application/sdp
Content-length: 796
\r\n
Session Description Protocol
SDP信息(有省略):
Session Description Protocol
Session Description Protocol Version (v): 0
Owner/Creator, Session Id (o): - 1534399611960795 1 IN IP4 10.0.2.15
Owner Username: -
Session ID: 1534399611960795
Session Version: 1
Owner Network Type: IN
Owner Address Type: IP4
Owner Address: 10.0.2.15
Session Name (s): Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server
Session Information (i): ss1.mkv
Time Description, active time (t): 0 0
Session Attribute (a): tool:LIVE555 Streaming Media v2018.07.07
Session Attribute (a): range:npt=0-
Session Attribute (a): x-qt-text-nam:Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server
Session Attribute (a): x-qt-text-inf:ss1.mkv
Media Description, name and address (m): video 0 RTP/AVP 96
Media Type: video
Media Port: 0
Media Protocol: RTP/AVP
Media Format: DynamicRTP-Type-96
Connection Information (c): IN IP4 0.0.0.0
Connection Network Type: IN
Connection Address Type: IP4
Connection Address: 0.0.0.0
Bandwidth Information (b): AS:500
Bandwidth Modifier: AS [Application Specific (RTP session bandwidth)]
Bandwidth Value: 500 kb/s
Media Attribute (a): rtpmap:96 H264/90000
Media Attribute Fieldname: rtpmap
Media Format: 96
MIME Type: H264
Sample Rate: 90000
...
Media Attribute (a): control:track1
Media Attribute Fieldname: control
Media Attribute Value: track1
Media Description, name and address (m): audio 0 RTP/AVP 97
Media Type: audio
Media Port: 0
Media Protocol: RTP/AVP
Media Format: DynamicRTP-Type-97
Connection Information (c): IN IP4 0.0.0.0
Connection Network Type: IN
Connection Address Type: IP4
Connection Address: 0.0.0.0
Bandwidth Information (b): AS:96
Bandwidth Modifier: AS [Application Specific (RTP session bandwidth)]
Bandwidth Value: 96 kb/s
Media Attribute (a): rtpmap:97 MPEG4-GENERIC/48000/2
Media Attribute Fieldname: rtpmap
Media Format: 97
MIME Type: MPEG4-GENERIC
Sample Rate: 48000
....
Media Attribute (a): control:track2
Media Attribute Fieldname: control
Media Attribute Value: track2
内容解释 :
主要关注:
上面有两个轨道 track1 track2
track1:是发送video 、负载 96、 编码方式 H264 、传输方式 RTP/AVP 、RTP 会话的带宽 500kb/s 、采样率 90 KHz
track2: 发送 audio、负载 97 、编码方式 MPEG4-GENERIC、传输方式 RTP/AVP、RTP 会话的带宽 96 kb/s 、采样率 48000 KHz
3. SETUP Video & Audio
同时传输音频和视频两个轨道所以需要建立两个socket
VLC >>>>>============= SEND SETUP REQUEST==============>>>>> RTSPSERVER
视频
Request: SETUP rtsp://10.0.2.15/ss1.mkv/track1 RTSP/1.0\r\n
CSeq: 4\r\n
User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
Transport: RTP/AVP;unicast;client_port=49774-49775
\r\n
音频
Request: SETUP rtsp://10.0.2.15/ss1.mkv/track2 RTSP/1.0\r\n
CSeq: 5\r\n
User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
Transport: RTP/AVP;unicast;client_port=49776-49777
Session: AEB76530
\r\n
VLC <<<<<================= RESPONSE 200=================<<<<< RTSPSERVER
视频
Response: RTSP/1.0 200 OK\r\n
CSeq: 4\r\n
Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
Transport: RTP/AVP;unicast;destination=10.0.2.15;source=10.0.2.15;client_port=49774-49775;server_port=6970-6971
Session: AEB76530;timeout=65
\r\n
音频
Response: RTSP/1.0 200 OK\r\n
CSeq: 5\r\n
Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
Transport: RTP/AVP;unicast;destination=10.0.2.15;source=10.0.2.15;client_port=49776-49777;server_port=6972-6973
Session: AEB76530;timeout=65
\r\n
PS: 此时 Transport 确定,表示服务器端传输 RTP 视频流的包 的socket 已经准备好了
4. PLAY
VLC >>>>>============ SEND PLAY REQUEST=============>>>>> RTSPSERVER
Request: PLAY rtsp://10.0.2.15/ss1.mkv/ RTSP/1.0\r\n
CSeq: 6\r\n
User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
Session: AEB76530
Range: npt=0.000-\r\n
\r\n
VLC <<<<<================= RESPONSE 200==============>>>>> RTSPSERVER
Response: RTSP/1.0 200 OK\r\n
CSeq: 6\r\n
Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
Range: npt=0.000-\r\n
Session: AEB76530
RTP-Info: url=rtsp://10.0.2.15/ss1.mkv/track1;seq=57885;rtptime=4285367567,url=rtsp://10.0.2.15/ss1.mkv/track2;seq=41406;rtptime=1364100230\r\n
\r\n
5. TEARDOWN
VLC >>>>>============ SEND TEARDOWN REQUEST============>>>>> RTSPSERVER
Request: TEARDOWN rtsp://10.0.2.15/ss1.mkv/ RTSP/1.0\r\n
CSeq: 7\r\n
User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
Session: AEB76530
\r\n
VLC <<<<<================= RESPONSE 200================<<<<< RTSPSERVER
Response: RTSP/1.0 200 OK\r\n
CSeq: 7\r\n
Date: Thu, Aug 16 2018 06:06:54 GMT\r\n
\r\n
以上就是我测试环境的完整RTSP 协商过程
RTP : Real Time Protocol