rtsp网络协议的java实现

  一. 参考资料      
        1. 《RTSP简单命令》:http://blog.csdn.net/feidragon319/archive/2007/08/14/1742357.aspx 
        2. http://bbs.21eic.com/dispbbs.asp?boardid=15&Id=22948
        3. 《RTSP客户端的Java实现》:http://hi.baidu.com/ssyuan/blog/item/566df6defac1dc5094ee37eb.html

二. RTSP的常用命令与解释
       其中C是客户端,S是服务端。
2.1  OPTIONS
       C->S:       OPTION request //询问S有哪些方法可用
       S->C:       OPTION response //S回应信息中包括提供的所有可用方法
      使用举例:
客户端到服务端: 

Java代码 
  1. OPTIONS rtsp://218.207.101.236:554/mobile/3/67A451E937422331 RTSP/1.0  
  2. Cseq: 1  

 服务端对OPTIONS的回应:

Java代码 
  1. RTSP/1.0 200 OK  
  2. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  3. Cseq: 1  
  4. Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD  

 

2.2  DESCRIBE

      C->S:      DESCRIBE request //要求得到S提供的媒体初始化描述信息
      S->C:      DESCRIBE response //S回应媒体初始化描述信息,主要是sdp

     使用举例:
 客户端到服务端:

Java代码 
  1. DESCRIBE   
Java代码 
  1. rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp RTSP/1.0  
  2. Cseq: 2  

 服务端对OPTIONS的回应:

Java代码 
  1. RTSP/1.0 200 OK  
  2. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  3. Cseq: 2  
  4. Content-length: 421  
  5. Date: Mon, 03 Aug 2009 08:21:33 GMT  
  6. Expires: Mon, 03 Aug 2009 08:21:33 GMT  
  7. Content-Type: application/sdp  
  8. x-Accept-Retransmit: our-retransmit  
  9. x-Accept-Dynamic-Rate: 1  
  10. Content-Base: rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/  
  11.   
  12. v=0  
  13. o=MediaBox 127992 137813 IN IP4 0.0.0.0  
  14. s=RTSP Session  
  15. i=Starv Box Live Cast  
  16. c=IN IP4 218.207.101.236  
  17. t=0 0  
  18. a=range:npt=now-  
  19. a=control:*  
  20. m=video 0 RTP/AVP 96  
  21. b=AS:20  
  22. a=rtpmap:96 MP4V-ES/1000  
  23. a=fmtp:96 profile-level-id=8; config=000001b008000001b5090000010000000120008440fa282c2090a31f; decode_buf=12586  
  24. a=range:npt=now-  
  25. a=framerate:5  
  26. a=framesize:96 176-144  
  27. a=cliprect:0,0,144,176  
  28. a=control:trackID=1  

 2.3  SETUP 
        C->S:        SETUP request //设置会话的属性,以及传输模式,提醒S建立会话
        S->C:        SETUP response //S建立会话,返回会话标识符,以及会话相关信息
 客户端到服务端的请求举例:

Java代码 
  1. SETUP rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/trackID=1  
  2.  RTSP/1.0  
  3. Cseq: 3  
  4. Transport: RTP/AVP;UNICAST;client_port=16264-16265;mode=play  

 服务端对客户端的回应举例:

Java代码 
  1. RTSP/1.0 200 OK  
  2. Server: PVSS/1.4.8(Build/20090111;Platform/Win32;Release/StarValley; )  
  3. Cseq: 3  
  4. Session: 26633092229589  
  5. Date: Mon, 03 Aug 2009 08:21:33 GMT  
  6. Expires: Mon, 03 Aug 2009 08:21:33 GMT  
  7. Transport: RTP/AVP;UNICAST;mode=play;client_port=16264-16265;server_port=20026-20027  

 2.4  PLAY
        C->S:      PLAY request //C请求播放
        S->C:      PLAY response //S回应该请求的信息
  客户端到服务端的请求举例:

Java代码 
  1. PLAY rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp RTSP/1.0  
  2. Session: 26633092229589  
  3. Cseq: 4  

  服务端对客户端的回应举例:

Java代码 
  1. RTSP/1.0 200 OK  
  2. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  3. Cseq: 4  
  4. Session: 26633092229589  
  5. RTP-Info: url=rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/trackID=1;seq=0;rtptime=0  

 

2.5  PAUSE
        C->S:      PAUSE request //C请求暂停播放
        S->C:      PAUSE response //S回应该请求的信息
  客户端到服务端的请求举例:

Java代码 
  1. PAUSE rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/ RTSP/1.0  
  2. Cseq: 5  
  3. Session: 26633092229589  

 服务端对客户端的回应举例:

Java代码 
  1. RTSP/1.0 200 OK  
  2. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  3. Cseq: 5  
  4. Session: 26633092229589  

2.6  TEARDOWN 
        C->S:        TEARDOWN request //C请求关闭会话
        S->C:        TEARDOWN response //S回应该请求
  客户端到服务端的请求举例: 

Java代码 
  1. TEARDOWN rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/ RTSP/1.0  
  2. Cseq: 6  
  3. User-Agent: RealMedia Player HelixDNAClient/10.0.0.11279 (win32)  
  4. Session: 26633092229589  

 服务端对客户端的回应举例:

Java代码 
  1. RTSP/1.0 200 OK  
  2. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  3. Cseq: 6  
  4. Session: 26633092229589  
  5. Connection: Close  

 三. RTSP客户端的Java实现
3.1  接口IEvent.java 
     

 接口IEvent.java的代码如下:

Java代码 
  1. package com.amigo.rtsp;  
  2.   
  3. import java.io.IOException;  
  4. import java.nio.channels.SelectionKey;  
  5.   
  6. /** *//** 
  7. * IEvent.java 网络事件处理器,当Selector可以进行操作时,调用这个接口中的方法. 
  8. * 2007-3-22 下午03:35:51 
  9. * @author sycheng 
  10. * @version 1.0 
  11. */  
  12. public interface IEvent {  
  13.     /** *//** 
  14.     * 当channel得到connect事件时调用这个方法. 
  15.     * @param key 
  16.     * @throws IOException 
  17.     */  
  18.     void connect(SelectionKey key) throws IOException;  
  19.   
  20.     /** *//** 
  21.     * 当channel可读时调用这个方法. 
  22.     * @param key 
  23.     * @throws IOException 
  24.     */  
  25.     void read(SelectionKey key) throws IOException;  
  26.   
  27.     /** *//** 
  28.     * 当channel可写时调用这个方法. 
  29.     * @throws IOException 
  30.     */  
  31.     void write() throws IOException;  
  32.   
  33.     /** *//** 
  34.     * 当channel发生错误时调用. 
  35.     * @param e 
  36.     */  
  37.     void error(Exception e);  
  38. }  

 3.2  RTSP的测试类:RTSPClient.java
        RTSP的测试类RTSPClient.java类的代码如下所示:

Java代码 
  1. package com.amigo.rtsp;  
  2.   
  3. import java.io.IOException;  
  4. import java.net.InetSocketAddress;  
  5. import java.nio.ByteBuffer;  
  6. import java.nio.channels.SelectionKey;  
  7. import java.nio.channels.Selector;  
  8. import java.nio.channels.SocketChannel;  
  9. import java.util.Iterator;  
  10. import java.util.concurrent.atomic.AtomicBoolean;  
  11.   
  12. public class RTSPClient extends Thread implements IEvent {  
  13.   
  14.     private static final String VERSION = " RTSP/1.0/r/n";  
  15.     private static final String RTSP_OK = "RTSP/1.0 200 OK";  
  16.   
  17.     /** *//** 远程地址 */  
  18.     private final InetSocketAddress remoteAddress;  
  19.   
  20.     /** *//** * 本地地址 */  
  21.     private final InetSocketAddress localAddress;  
  22.   
  23.     /** *//** * 连接通道 */  
  24.     private SocketChannel socketChannel;  
  25.   
  26.     /** *//** 发送缓冲区 */  
  27.     private final ByteBuffer sendBuf;  
  28.   
  29.     /** *//** 接收缓冲区 */  
  30.     private final ByteBuffer receiveBuf;  
  31.   
  32.     private static final int BUFFER_SIZE = 8192;  
  33.   
  34.     /** *//** 端口选择器 */  
  35.     private Selector selector;  
  36.   
  37.     private String address;  
  38.   
  39.     private Status sysStatus;  
  40.   
  41.     private String sessionid;  
  42.   
  43.     /** *//** 线程是否结束的标志 */  
  44.     private AtomicBoolean shutdown;  
  45.       
  46.     private int seq=1;  
  47.       
  48.     private boolean isSended;  
  49.       
  50.     private String trackInfo;  
  51.       
  52.   
  53.     private enum Status {  
  54.         init, options, describe, setup, play, pause, teardown  
  55.     }  
  56.   
  57.     public RTSPClient(InetSocketAddress remoteAddress,  
  58.             InetSocketAddress localAddress, String address) {  
  59.         this.remoteAddress = remoteAddress;  
  60.         this.localAddress = localAddress;  
  61.         this.address = address;  
  62.   
  63.         // 初始化缓冲区  
  64.         sendBuf = ByteBuffer.allocateDirect(BUFFER_SIZE);  
  65.         receiveBuf = ByteBuffer.allocateDirect(BUFFER_SIZE);  
  66.         if (selector == null) {  
  67.             // 创建新的Selector  
  68.             try {  
  69.                 selector = Selector.open();  
  70.             } catch (final IOException e) {  
  71.                 e.printStackTrace();  
  72.             }  
  73.         }  
  74.   
  75.         startup();  
  76.         sysStatus = Status.init;  
  77.         shutdown=new AtomicBoolean(false);  
  78.         isSended=false;  
  79.     }  
  80.   
  81.     public void startup() {  
  82.         try {  
  83.             // 打开通道  
  84.             socketChannel = SocketChannel.open();  
  85.             // 绑定到本地端口  
  86.             socketChannel.socket().setSoTimeout(30000);  
  87.             socketChannel.configureBlocking(false);  
  88.             socketChannel.socket().bind(localAddress);  
  89.             if (socketChannel.connect(remoteAddress)) {  
  90.                 System.out.println("开始建立连接:" + remoteAddress);  
  91.             }  
  92.             socketChannel.register(selector, SelectionKey.OP_CONNECT  
  93.                     | SelectionKey.OP_READ | SelectionKey.OP_WRITE, this);  
  94.             System.out.println("端口打开成功");  
  95.   
  96.         } catch (final IOException e1) {  
  97.             e1.printStackTrace();  
  98.         }  
  99.     }  
  100.   
  101.     public void send(byte[] out) {  
  102.         if (out == null || out.length < 1) {  
  103.             return;  
  104.         }  
  105.         synchronized (sendBuf) {  
  106.             sendBuf.clear();  
  107.             sendBuf.put(out);  
  108.             sendBuf.flip();  
  109.         }  
  110.   
  111.         // 发送出去  
  112.         try {  
  113.             write();  
  114.             isSended=true;  
  115.         } catch (final IOException e) {  
  116.             e.printStackTrace();  
  117.         }  
  118.     }  
  119.   
  120.     public void write() throws IOException {  
  121.         if (isConnected()) {  
  122.             try {  
  123.                 socketChannel.write(sendBuf);  
  124.             } catch (final IOException e) {  
  125.             }  
  126.         } else {  
  127.             System.out.println("通道为空或者没有连接上");  
  128.         }  
  129.     }  
  130.   
  131.     public byte[] recieve() {  
  132.         if (isConnected()) {  
  133.             try {  
  134.                 int len = 0;  
  135.                 int readBytes = 0;  
  136.   
  137.                 synchronized (receiveBuf) {  
  138.                     receiveBuf.clear();  
  139.                     try {  
  140.                         while ((len = socketChannel.read(receiveBuf)) > 0) {  
  141.                             readBytes += len;  
  142.                         }  
  143.                     } finally {  
  144.                         receiveBuf.flip();  
  145.                     }  
  146.                     if (readBytes > 0) {  
  147.                         final byte[] tmp = new byte[readBytes];  
  148.                         receiveBuf.get(tmp);  
  149.                         return tmp;  
  150.                     } else {  
  151.                         System.out.println("接收到数据为空,重新启动连接");  
  152.                         return null;  
  153.                     }  
  154.                 }  
  155.             } catch (final IOException e) {  
  156.                 System.out.println("接收消息错误:");  
  157.             }  
  158.         } else {  
  159.             System.out.println("端口没有连接");  
  160.         }  
  161.         return null;  
  162.     }  
  163.   
  164.     public boolean isConnected() {  
  165.         return socketChannel != null && socketChannel.isConnected();  
  166.     }  
  167.   
  168.     private void select() {  
  169.         int n = 0;  
  170.         try {  
  171.             if (selector == null) {  
  172.                 return;  
  173.             }  
  174.             n = selector.select(1000);  
  175.   
  176.         } catch (final Exception e) {  
  177.             e.printStackTrace();  
  178.         }  
  179.   
  180.         // 如果select返回大于0,处理事件  
  181.         if (n > 0) {  
  182.             for (final Iterator<SelectionKey> i = selector.selectedKeys()  
  183.                     .iterator(); i.hasNext();) {  
  184.                 // 得到下一个Key  
  185.                 final SelectionKey sk = i.next();  
  186.                 i.remove();  
  187.                 // 检查其是否还有效  
  188.                 if (!sk.isValid()) {  
  189.                     continue;  
  190.                 }  
  191.   
  192.                 // 处理事件  
  193.                 final IEvent handler = (IEvent) sk.attachment();  
  194.                 try {  
  195.                     if (sk.isConnectable()) {  
  196.                         handler.connect(sk);  
  197.                     } else if (sk.isReadable()) {  
  198.                         handler.read(sk);  
  199.                     } else {  
  200.                         // System.err.println("Ooops");  
  201.                     }  
  202.                 } catch (final Exception e) {  
  203.                     handler.error(e);  
  204.                     sk.cancel();  
  205.                 }  
  206.             }  
  207.         }  
  208.     }  
  209.   
  210.     public void shutdown() {  
  211.         if (isConnected()) {  
  212.             try {  
  213.                 socketChannel.close();  
  214.                 System.out.println("端口关闭成功");  
  215.             } catch (final IOException e) {  
  216.                 System.out.println("端口关闭错误:");  
  217.             } finally {  
  218.                 socketChannel = null;  
  219.             }  
  220.         } else {  
  221.             System.out.println("通道为空或者没有连接");  
  222.         }  
  223.     }  
  224.   
  225.     @Override  
  226.     public void run() {  
  227.         // 启动主循环流程  
  228.         while (!shutdown.get()) {  
  229.             try {  
  230.                 if (isConnected()&&(!isSended)) {  
  231.                     switch (sysStatus) {  
  232.                     case init:  
  233.                         doOption();  
  234.                         break;  
  235.                     case options:  
  236.                         doDescribe();  
  237.                         break;  
  238.                     case describe:  
  239.                         doSetup();  
  240.                         break;  
  241.                     case setup:  
  242.                         if(sessionid==null&&sessionid.length()>0){  
  243.                             System.out.println("setup还没有正常返回");  
  244.                         }else{  
  245.                             doPlay();  
  246.                         }  
  247.                         break;  
  248.                     case play:  
  249.                         doPause();  
  250.                         break;  
  251.                           
  252.                     case pause:  
  253.                         doTeardown();  
  254.                         break;  
  255.                     default:  
  256.                         break;  
  257.                     }  
  258.                 }  
  259.                 // do select  
  260.                 select();  
  261.                 try {  
  262.                     Thread.sleep(1000);  
  263.                 } catch (final Exception e) {  
  264.                 }  
  265.             } catch (final Exception e) {  
  266.                 e.printStackTrace();  
  267.             }  
  268.         }  
  269.           
  270.         shutdown();  
  271.     }  
  272.   
  273.     public void connect(SelectionKey key) throws IOException {  
  274.         if (isConnected()) {  
  275.             return;  
  276.         }  
  277.         // 完成SocketChannel的连接  
  278.         socketChannel.finishConnect();  
  279.         while (!socketChannel.isConnected()) {  
  280.             try {  
  281.                 Thread.sleep(300);  
  282.             } catch (final InterruptedException e) {  
  283.                 e.printStackTrace();  
  284.             }  
  285.             socketChannel.finishConnect();  
  286.         }  
  287.   
  288.     }  
  289.   
  290.     public void error(Exception e) {  
  291.         e.printStackTrace();  
  292.     }  
  293.   
  294.     public void read(SelectionKey key) throws IOException {  
  295.         // 接收消息  
  296.         final byte[] msg = recieve();  
  297.         if (msg != null) {  
  298.             handle(msg);  
  299.         } else {  
  300.             key.cancel();  
  301.         }  
  302.     }  
  303.   
  304.     private void handle(byte[] msg) {  
  305.         String tmp = new String(msg);  
  306.         System.out.println("返回内容:");  
  307.         System.out.println(tmp);  
  308.         if (tmp.startsWith(RTSP_OK)) {  
  309.             switch (sysStatus) {  
  310.             case init:  
  311.                 sysStatus = Status.options;  
  312.                 break;  
  313.             case options:  
  314.                 sysStatus = Status.describe;  
  315.                 trackInfo=tmp.substring(tmp.indexOf("trackID"));  
  316.                 break;  
  317.             case describe:  
  318.                 sessionid = tmp.substring(tmp.indexOf("Session: ") + 9, tmp  
  319.                         .indexOf("Date:"));  
  320.                 if(sessionid!=null&&sessionid.length()>0){  
  321.                     sysStatus = Status.setup;  
  322.                 }  
  323.                 break;  
  324.             case setup:  
  325.                 sysStatus = Status.play;  
  326.                 break;  
  327.             case play:  
  328.                 sysStatus = Status.pause;  
  329.                 break;  
  330.             case pause:  
  331.                 sysStatus = Status.teardown;  
  332.                 shutdown.set(true);  
  333.                 break;  
  334.             case teardown:  
  335.                 sysStatus = Status.init;  
  336.                 break;  
  337.             default:  
  338.                 break;  
  339.             }  
  340.             isSended=false;  
  341.         } else {  
  342.             System.out.println("返回错误:" + tmp);  
  343.         }  
  344.   
  345.     }  
  346.   
  347.     private void doTeardown() {  
  348.         StringBuilder sb = new StringBuilder();  
  349.         sb.append("TEARDOWN ");  
  350.         sb.append(this.address);  
  351.         sb.append("/");  
  352.         sb.append(VERSION);  
  353.         sb.append("Cseq: ");  
  354.         sb.append(seq++);  
  355.         sb.append("/r/n");  
  356.         sb.append("User-Agent: RealMedia Player HelixDNAClient/10.0.0.11279 (win32)/r/n");  
  357.         sb.append("Session: ");  
  358.         sb.append(sessionid);  
  359.         sb.append("/r/n");  
  360.         send(sb.toString().getBytes());  
  361.         System.out.println(sb.toString());  
  362.     }  
  363.   
  364.     private void doPlay() {  
  365.         StringBuilder sb = new StringBuilder();  
  366.         sb.append("PLAY ");  
  367.         sb.append(this.address);  
  368.         sb.append(VERSION);  
  369.         sb.append("Session: ");  
  370.         sb.append(sessionid);  
  371.         sb.append("Cseq: ");  
  372.         sb.append(seq++);  
  373.         sb.append("/r/n");  
  374.         sb.append("/r/n");  
  375.         System.out.println(sb.toString());  
  376.         send(sb.toString().getBytes());  
  377.   
  378.     }  
  379.   
  380.     private void doSetup() {  
  381.         StringBuilder sb = new StringBuilder();  
  382.         sb.append("SETUP ");  
  383.         sb.append(this.address);  
  384.         sb.append("/");  
  385.         sb.append(trackInfo);  
  386.         sb.append(VERSION);  
  387.         sb.append("Cseq: ");  
  388.         sb.append(seq++);  
  389.         sb.append("/r/n");  
  390.         sb.append("Transport: RTP/AVP;UNICAST;client_port=16264-16265;mode=play/r/n");  
  391.         sb.append("/r/n");  
  392.         System.out.println(sb.toString());  
  393.         send(sb.toString().getBytes());  
  394.     }  
  395.   
  396.     private void doOption() {  
  397.         StringBuilder sb = new StringBuilder();  
  398.         sb.append("OPTIONS ");  
  399.         sb.append(this.address.substring(0, address.lastIndexOf("/")));  
  400.         sb.append(VERSION);  
  401.         sb.append("Cseq: ");  
  402.         sb.append(seq++);  
  403.         sb.append("/r/n");  
  404.         sb.append("/r/n");  
  405.         System.out.println(sb.toString());  
  406.         send(sb.toString().getBytes());  
  407.     }  
  408.   
  409.     private void doDescribe() {  
  410.         StringBuilder sb = new StringBuilder();  
  411.         sb.append("DESCRIBE ");  
  412.         sb.append(this.address);  
  413.         sb.append(VERSION);  
  414.         sb.append("Cseq: ");  
  415.         sb.append(seq++);  
  416.         sb.append("/r/n");  
  417.         sb.append("/r/n");  
  418.         System.out.println(sb.toString());  
  419.         send(sb.toString().getBytes());  
  420.     }  
  421.       
  422.     private void doPause() {  
  423.         StringBuilder sb = new StringBuilder();  
  424.         sb.append("PAUSE ");  
  425.         sb.append(this.address);  
  426.         sb.append("/");  
  427.         sb.append(VERSION);  
  428.         sb.append("Cseq: ");  
  429.         sb.append(seq++);  
  430.         sb.append("/r/n");  
  431.         sb.append("Session: ");  
  432.         sb.append(sessionid);  
  433.         sb.append("/r/n");  
  434.         send(sb.toString().getBytes());  
  435.         System.out.println(sb.toString());  
  436.     }  
  437.       
  438.     public static void main(String[] args) {  
  439.         try {  
  440.             // RTSPClient(InetSocketAddress remoteAddress,  
  441.             // InetSocketAddress localAddress, String address)  
  442.             RTSPClient client = new RTSPClient(  
  443.                     new InetSocketAddress("218.207.101.236"554),  
  444.                     new InetSocketAddress("192.168.2.28"0),  
  445.                     "rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp");  
  446.             client.start();  
  447.         } catch (Exception e) {  
  448.             e.printStackTrace();  
  449.         }  
  450.     }  
  451. }  

 其中:rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp为我在网上找到的一个rtsp的sdp地址,读者可自行更换,RTSP的默认端口为554.
3.3  运行结果
       运行RTSPClient.java,运行结果如下所示:

Java代码 
  1. 端口打开成功  
  2. OPTIONS rtsp://218.207.101.236:554/mobile/3/67A451E937422331 RTSP/1.0  
  3. Cseq: 1  
  4.   
  5.   
  6. 返回内容:  
  7. RTSP/1.0 200 OK  
  8. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  9. Cseq: 1  
  10. Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD  
  11.   
  12.   
  13. DESCRIBE rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp RTSP/1.0  
  14. Cseq: 2  
  15.   
  16.   
  17. 返回内容:  
  18. RTSP/1.0 200 OK  
  19. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  20. Cseq: 2  
  21. Content-length: 421  
  22. Date: Mon, 03 Aug 2009 08:50:36 GMT  
  23. Expires: Mon, 03 Aug 2009 08:50:36 GMT  
  24. Content-Type: application/sdp  
  25. x-Accept-Retransmit: our-retransmit  
  26. x-Accept-Dynamic-Rate: 1  
  27. Content-Base: rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/  
  28.   
  29. v=0  
  30. o=MediaBox 127992 137813 IN IP4 0.0.0.0  
  31. s=RTSP Session  
  32. i=Starv Box Live Cast  
  33. c=IN IP4 218.207.101.236  
  34. t=0 0  
  35. a=range:npt=now-  
  36. a=control:*  
  37. m=video 0 RTP/AVP 96  
  38. b=AS:20  
  39. a=rtpmap:96 MP4V-ES/1000  
  40. a=fmtp:96 profile-level-id=8; config=000001b008000001b5090000010000000120008440fa282c2090a31f; decode_buf=12586  
  41. a=range:npt=now-  
  42. a=framerate:5  
  43. a=framesize:96 176-144  
  44. a=cliprect:0,0,144,176  
  45. a=control:trackID=1  
  46.   
  47. SETUP rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/trackID=1  
  48.  RTSP/1.0  
  49. Cseq: 3  
  50. Transport: RTP/AVP;UNICAST;client_port=16264-16265;mode=play  
  51.   
  52.   
  53. 返回内容:  
  54. RTSP/1.0 200 OK  
  55. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  56. Cseq: 3  
  57. Session: 15470472221769  
  58. Date: Mon, 03 Aug 2009 08:50:36 GMT  
  59. Expires: Mon, 03 Aug 2009 08:50:36 GMT  
  60. Transport: RTP/AVP;UNICAST;mode=play;client_port=16264-16265;server_port=20080-20081  
  61.   
  62.   
  63. PLAY rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp RTSP/1.0  
  64. Session: 15470472221769  
  65. Cseq: 4  
  66.   
  67.   
  68. 返回内容:  
  69. RTSP/1.0 200 OK  
  70. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  71. Cseq: 4  
  72. Session: 15470472221769  
  73. RTP-Info: url=rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/trackID=1;seq=0;rtptime=0  
  74.   
  75.   
  76. PAUSE rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/ RTSP/1.0  
  77. Cseq: 5  
  78. Session: 15470472221769  
  79.   
  80.   
  81. 返回内容:  
  82. RTSP/1.0 200 OK  
  83. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  84. Cseq: 5  
  85. Session: 15470472221769  
  86.   
  87.   
  88. TEARDOWN rtsp://218.207.101.236:554/mobile/3/67A451E937422331/8jH5QPU5GWS07Ugn.sdp/ RTSP/1.0  
  89. Cseq: 6  
  90. User-Agent: RealMedia Player HelixDNAClient/10.0.0.11279 (win32)  
  91. Session: 15470472221769  
  92.   
  93.   
  94. 返回内容:  
  95. RTSP/1.0 200 OK  
  96. Server: PVSS/1.4.8 (Build/20090111; Platform/Win32; Release/StarValley; )  
  97. Cseq: 6  
  98. Session: 15470472221769  
  99. Connection: Close  
  100.   
  101.   
  102. 端口关闭成功  

 对照运行结果,读者可以熟悉RTSP的常用命令.

发布了272 篇原创文章 · 获赞 75 · 访问量 606万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览