Friday, March 11, 2011

RTSP - Real Time Streaming Protocol (RTSP)

RFC 2326 define the specification for RTSP, Real Time Streaming Protocol.

RTSP is mainly use for setting up streaming and control for audio and video media. As an overview, RTSP will be used with RTP over UDP or TCP. In this entry, I will describe the how to use RTSP as media setup command

The common commands for RTSP is OPTION, DESCRIBE, SETUP, PLAY, TEARDOWN.

The above commands set is enough to connect or disconnect from a media stream. I will briefly describe each commands

OPTION

OPTION command is used by client to ask server what type of commands does it support. The request and response example is


DESCRIBE

DESCRIBE is used by client to ask server to provide media stream information for a certain media URL Commonly, the DESCRIBE command provide the SDP, Session Description Protocol, for the given media URL. The request and response example is

SETUP

SETUP is used by client to setup necessary port, track, etc for a given media stream. It is used to tell the server what type of transport, UDP or TCP, should be used for the media streaming. The request and response example is

PLAY

PLAY command is used by the client to tell server to start providing the media stream bytes via the setup channel. The request and response example is


TEARDOWN

TEARDOWN command is used by client to tell server that the current media stream to be stop. All resource related to this stream can be removed. The request and response example is


The General flow for the commands is

To setup and play a stream

1. OPTION
2. DESCRIBE
3. SETUP
4. PLAY

To Terminate

1. TEARDOWN

As a complete example, the flow of command for client and server to setup and play a unicast media stream is


Below is a screenshot of RTSP commands in action


JAVA - Create RTSP Connection

Using Java to create RTSP connection is simple. Below is an example for sending a OPTION command

Socket s = new Socket();
s.connect("rtsp://your.url:554/track.sdp", 60000);
s.connect(address, timeout);
PrintStream out = new PrintStream(s.getOutputStream());
StringBuffer b = new StringBuffer();
b.append("OPTIONS * RTSP/1.0 \r\n");
b.append("CSeq: 1\r\n");
b.append("User-Agent: MyClient \r\n");
b.append("Connection: Keep-Alive \r\n");
b.append("\r\n");
out.print(b.toString());
out.flush()

Above provide a skeleton code for using JAVA to create a RTSP OPTION command. As you can see, all you need to do is to the follow

1. Create a JAVA socket
2. Use the socket output stream to send the commands. Simple follow the respective command as state in the above section.
3. After sending, read in the response from socket input stream socket (s.getInputStream())and parse it respectiviely.

NOTE: If you have notice, at the end of the command, I provided an extra

b.append("\r\n");

This is needed to tell RTSP server that the command is ended. It is a common mistake when trying to communicate with a RTSP server.

For more details you can find in http://www.ietf.org/rfc/rfc2326.txt

4 comments:

  1. Thanks. Important commands nicely explained.

    ReplyDelete
  2. I am glad that my notes helps :)

    ReplyDelete
  3. hey
    I want to create a program in VC++/C++ using sockets to receive streaming data from live media server.
    can u give me a clue or pseudo code for that????

    ReplyDelete
  4. First, you need to know Socket Programming on C++.

    This site should help you. http://net.pku.edu.cn/~course/cs501/2011/code/BSD_Socket.t/sockets.pdf

    Base on the socket tutorial, you need to create a socket that specify RTSP connector. Get the socket output stream, write OPTION to the media server. The server should reply a RTSP response to you with status 200.

    RTSP is a simple protocol that is based on plain text. So, all you need is to perform text parsing on socket stream, request and response base on the RFC and you should be good to go.

    ReplyDelete

Oracle - Reclaim disk space

Oracle does not release disk space even if you had delete the data or tablespace. If you have enterprise manager, you should use it to  rec...