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 command is used by client to ask server what type of commands does it support. The request and response example is
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 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 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 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
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();
PrintStream out = new PrintStream(s.getOutputStream());
StringBuffer b = new StringBuffer();
b.append("OPTIONS * RTSP/1.0 \r\n");
b.append("User-Agent: MyClient \r\n");
b.append("Connection: Keep-Alive \r\n");
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
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