RTSP实例解析
以下是某地IPTV的RTSP协商过程:
1、DESCRIBE
请求:
//方法和媒体URL DESCRIBE rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0 //协商用于描述媒体信息协议 Accept: application/sdp CSeq: 1 //User Agnet信息,显示是中兴的服务器,1.0的版本。如果是Helix服务器的话会有Helix 服务器的标识。 User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347 //主要用于NAT穿透 x-NAT:2.1.1.100:20081 x-zmssRtxSdp: yes
响应:
RTSP/1.0 200 OK //应答编号 Server: ZXUSS100 1.0 Cache-Control: no-cache Content-Base: rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp/ //内容长度信息 Content-Length: 320 //描述内容信息所用的协议 Content-Type: application/sdp CSeq: 1 Date: Wed, 29 Sep 2010 10:20:38 GMT Expires: Wed, 29 Sep 2010 10:20:38 GMT // SDP 描述信息 v=0 o=- 296874273 1 IN IP4 118.122.89.27 s=envivio c=IN IP4 0.0.0.0 b=AS:1500 t=0 0 a=range:clock=20100929T095038.00Z-20100929T102038.00Z m=video 5140 RTP/AVPF 33 96 a=control:trackID=2 a=rtpmap:33 MP2T/90000 a=3GPP-Adaptation-Support:5 a=rtcp-fb:33 nack a=rtpmap:96 rtx/90000 a=fmtp:96 apt=33;rtx-time=0
2、SETUP
请求:
//用于建立RTSP连接,协商传输用的协议。 SETUP rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp/trackID=2 RTSP/1.0 CSeq: 2 3GPP-Adaptation: url=rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp/trackID=2;size=1061400;target-time=2200 Transport: MP2T/RTP/UDP;unicast;destination=2.1.1.100;client_port=8360-8361,MP2T/RTP/TCP;unicast;destination=2.1.1.100;interleaved=0-1,MP2T/UDP;unicast;destination=2.1.1.100;client_port=8360-8361,MP2T/TCP;unicast;destination=2.1.1.100;interleaved=0-1 // MP2T/RTP/UDP表示是TS流用于RTP打包,基于UDP传输。MP2T/RTP/TCP表示是TS流用于RTP打包,基于TCP。 User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347
响应:
RTSP/1.0 200 OK Server: ZXUSS100 1.0 CSeq: 2 Date: Wed, 29 Sep 2010 10:20:38 GMT Expires: Wed, 29 Sep 2010 10:20:38 GMT Session: 65565885 Transport: MP2T/RTP/UDP;unicast;destination=2.1.1.100;client_port=8360-8361;server_port=13306-13307;source=118.122.89.29 // 通过协商MP2T/RTP/UDP表示是TS流用于RTP打包,基于UDP传输。server端端口:13306-13307。client端端口:8360-8361 3GPP-Adaptation:url=rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp/trackID=2;size=1061400;target-time=2200
3、PLAY
请求:
//播放视频。对于有些视频可能会分别要对音频视频进行play。 PLAY rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0 CSeq: 3 Session: 65565885 User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347 Scale: 1.0 //npt=end-在IPTV2.0里面有其自身的定义(可参看上海电信IPTV2.0标准) Range: npt=end-
响应:
RTSP/1.0 200 OK Server: ZXUSS100 1.0 CSeq: 3 Range: npt=end- Scale: 1.0 Session: 65565885 RTP-Info: url=rtsp://118.122.89.29:13306/live/ch10083121594790060557.sdp/trackID=2
play的另一种用法(快进和快退)。
请求:
//play的另外一种用法。用于快进和快退。 PLAY rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0 CSeq: 43 Session: 65565885 User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347 //Scale: -32.0,表示以32倍速快退。Scale: 32.0,表示以32倍速快进。 Scale: -32.0 Range: npt=now-
响应:
RTSP/1.0 200 OK Server: ZXUSS100 1.0 CSeq: 43 Range: clock=20100929T102609.02Z-20100929T095637.75Z Scale: -32.0 Session: 65565885 RTP-Info: url=rtsp://118.122.89.36:10084/live/ch10083121594790060557.sdp/trackID=2;seq=22277;rtptime=1792329138
4、GET_PARAMETER
请求:
//获取当前的一些播放参数。 GET_PARAMETER rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0 CSeq: 44 Session: 65565885 User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347 //请求时移的范围 x-Timeshift_Range //获取当前的时间点 x-Timeshift_Current
响应:
RTSP/1.0 200 OK //返回当前的媒体信息。 Server: ZXUSS100 1.0 CSeq: 44 Session: 65565885 x-Timeshift_Range: clock=20100929T095638.83Z-20100929T102638.83Z x-Timeshift_Current: clock=20100929T102530.20Z;rtptime=1788844914 //中间省去了45,46,47三个包。通过CSeq: 48字段可以看出来
5、PLAY
请求:
//用于恢复正常的播放速度。 PLAY rtsp://118.122.89.27:554/live/ch10083121594790060557.sdp?playtype=1&boid=001&backupagent=118.122.89.27:554&clienttype=1&time=20100929182111+08&life=172800&ifpricereqsnd=1&vcdnid=001&userid=123&mediaid=ch10083121594790060557&ctype=2&TSTVTimeLife=1800&contname=&authid=0&UserLiveType=1&nodelevel=3 RTSP/1.0 CSeq: 48 Session: 65565885 User-Agent:ZTE Ltd.co RTSP protocal verion 1.0 guid-2.1.1.100/B519D290-C0EC-EE35-7368-893BE4C0B347 Scale: 1.0 Range: npt=beginning-
响应:
RTSP/1.0 200 OK Server: ZXUSS100 1.0 CSeq: 48 Range: clock=20100929T095730.00Z-20100929T102730.61Z //可以时移的范围。 Scale: 1.0 Session: 65565885 RTP-Info: url=rtsp://118.122.89.36:10084/live/ch10083121594790060557.sdp/trackID=2;seq=39900;rtptime=1637595010