RTSP protocol Detailed

Source: Internet
Author: User
Tags session id numeric value

Category: SIP/RTSP related 2012-09-18 14:55 1280 people read review (0) favorite Report session server streaming media server encryption network NULL RTSP introduction RTSP (Real time S Treaming Protocol) is an application-layer protocol that is presented by real Network and Netscape to effectively transmit streaming media data over an IP network. RTSP Streaming media provides control such as pause, fast forward, and it does not transmit data by itself, and RTSP acts as a remote control for streaming media servers. The server side can choose to use TCP or UDP to transmit the stream content, its syntax and operation is similar to HTTP 1.1, but does not particularly emphasize time synchronization, so the comparison can tolerate network latency. It also allows multiple streaming requirements control (multicast), in addition to reducing server-side network usage, and supports multi-party videoconferencing (video onference). Because it works in the same way as the HTTP1.1, the caching of proxy server "cache" also applies to RTSP, and because RTSP has a re-directed function, the actual load situation can be converted to serve the server, To avoid excessive load concentration on the same server and cause delays.

The difference between RTSP and HTTP (1) Contact: Both use plain text to send messages, and the RTSP protocol syntax is similar to HTTP.     RTSP was initially designed to be compatible with parsing code using previously written HTTP protocols. (2) Difference: RTSP is stateful, different is the RTSP command need to know now is in a state, that is, RTSP command always in order to send, a command always before another command to send. RTSP does not break the connection, no matter what state it is in. , and HTTP does not save the state, and the protocol disconnects when a command is sent, and there is no dependency between the commands. The RTSP protocol uses port 554, and HTTP uses 80 ports. The difference between RTSP and sip and the connection to sip (Session initiation Protocol) is an application-layer control protocol based on IP. Because SIP is a plain text based signaling protocol, you can manage sessions on different access networks. A session can be any type of communication between terminal devices, such as a video session, a time-consuming information processing, or a collaboration session.       The agreement does not define or limit the services that can be used, such as transmission, quality of service, billing, security, and other issues that are handled by the underlying core network and other protocols. (1) Contact: SIP and RTSP are Application Layer Control Protocol, responsible for the establishment and control of a communication process and end, not responsible for the intermediate transmission part. They are all based on a plain text signaling protocol with good wall-piercing performance. Support TCP, UDP, multi-party communication support. They all need server support, both of which support session redirection.     Both SIP and RTSP use the SDP protocol to transfer media parameters and use the RTP (RTCP) protocol to transfer media streams. (2) Difference: RTSP is a protocol developed specifically for streaming media, which is more powerful than SIP in time synchronization of multiple media streams. RTSP also provides Network Load balancing capabilities to reduce server pressure and network bandwidth requirements. SIP is generally used to create audio, video calls (bidirectional), while RTSP is generally used for video-on-demand, video surveillance, etc. (unidirectional).   Of course, in principle, RTSP can also do two-way video calls. RTSP and RTP (RTCP) Relationship RTSP is responsible for establishing and controlling the session, RTP is responsible for the transmission of multimedia, RTCP with RTP to do control and traffic statistics, they are cooperative relationship.
RTSP messages for RTSP have two main classes, one for the request message and one for the response message (response), and the two messages are in different formats. Request Message Format:
Method URI RTSP version CR LF
Message head CR LF CR LF
Message body CR LF

Methods include options, SETUP, PLAY, teardown Wait, URI is the address of the receiver (server side), for example: Rtsp://192.168.22.136:5000/v0, the CR LF after each line means carriage return, A corresponding resolution is required on the receiving side, and the last message header needs to have two CR LF.

Response Message Format:
RTSP version Status code interpretation CR LF
Message head CR LF CR LF
Message body CR LF
In which the RTSP version is generally rtsp/1.0, the status code is a numeric value, 200 indicates success, and the explanation is the text interpretation corresponding to the status code.

The status code consists of three digits, which represent the result of the method execution, defined as follows:

1XX: reserved, used in the future;

2XX: Success, Operation is received, understood, accepted (received,understand,accepted);

3XX: Redirect, to complete the operation must be further operated;

4XX: Client error, request syntax error or cannot be implemented;

5XX: Server error, the server cannot implement a legitimate request.

Methods of RTSP


The methods defined in RTSP are: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, scale, Get_parameter, Set_parameter
1.OPTION is designed to get the available methods provided by the server: OPTIONS rtsp://192.168.20.136:5000/xxx666 rtsp/1.0 cseq:1        //each message has Sequence number to mark, the first packet is usually the option request message USER-AGENT:VLC Media Player (LIVE555 streaming media v2005.11.10) The response information for the server includes some of the methods provided, such as: rtsp/ 1.0 OK server:userver 0.9.7_rc1 cseq:1        //CSEQ value of each response message and request for a message that corresponds CSeq, DES Cribe, SETUP, TEARDOWN, PLAY, PAUSE, scale, Get_parameter//server available methods   2.DESCRIBE C initiates a DESCRIBE request to S, in order to get the session description information (SDP ): DESCRIBE rtsp://192.168.20.136:5000/xxx666 rtsp/1.0 cseq:2 TOKEN:ACCEPT:APPLICATION/SDP USER-AGENT:VLC Media Player (LIVE555 streaming Media v2005.11.10) server responds to some descriptive information about this session (SDP): rtsp/1.0 OK server:userver 0.9.7_rc1 cseq:2 x-prev-url : rtsp://192.168.20.136:5000 x-next-url:rtsp://192.168.20.136:5000 X-accept-retransmit:our-retransmit X-accept-dynamic-rate:1 cache-control:must-revalidate Last-modified:fri, Nov 2006 12:34:38 GMT Date:fri, 200 6 12:34:38 GMT Expires:fri, 2006 12:34:38 GMT content-base:rtsp://192.168.20.136:5000/xxx666/content-length:344 CONTENT-TYPE:APPLICATION/SDP v=0   & nbsp    //The following are SDP information o=onewaveuserverng 1451516402 1025358037 in IP4 192.168.20.136 s=/xxx666 u=http:///e=admin@ c=i N IP4 0.0.0.0 t=0 0 a=isma-compliance:1,1.0,1 a=range:npt=0-m=video 0 RTP/AVP    //m for media description, below is the media description for the video channel in the session a=rtpmap:96 mp4v-es/90000 a=fmtp:96 profile-level-id=245;config= 000001b0f5000001b509000001000000012000c888b0e0e0fa62d089028307 a=control:trackid=0//trackid=0 indicates that the video stream is using channel 0   3.SETUP Client alerts the server to establish a session and determine the transfer mode: SETUP rtsp://192.168.20.136:5000/xxx666/trackid=0 rtsp/1.0     Cseq:3 Transport:rtp/avp/tcp;unicast;interleaved=0-1       USER-AGENT:VLC Media Player (LIVE555 streaming media v2005.11.10)//uri with Trackid=0, indicating that the channel is set. The transport parameter sets the transport mode, the package structure. The second byte position of the next packet header is interleaved, whose value is different for each channel, the Trackid=0 interleaved value has two 0 or 1,0 for the RTP packet, 1 for the RTCP package, The receiving end distinguishes what kind of packet according to the value of the interleaved. Server Response information: rtsp/1.0 OK server:userver0.9.7_rc1 cseq:3 session:6310936469860791894    /server response session identifier Cache-control:no-cache TRANSPORT:RTP/AVP/TCP ; unicast;interleaved=0-1;ssrc=6b8b4567   4.PLAY client sends play request: Play rtsp://192.168.20.136:5000/xxx666 rtsp/1.0 CSeq: 4 session:6310936469860791894 range:npt=0.000-     //setting the range of playback time USER-AGENT:VLC Media Player (LIVE555 Str eaming Media v2005.11.10) server response information: rtsp/1.0 OK server:userver 0.9.7_rc1 cseq:4 session:6310936469860791894 range:n pt=0.000000-rtp-info:url=trackid=0;seq=17040;rtptime=1467265309     //seq and Rtptime are all information in the RTP package   5.TEARDOWN client initiated shutdown request: TEARDOWN rtsp://192.168.20.136:5000/xxx666 rtsp/1.0 cseq:5 session:6310936469860791894 USER-AGENT:VLC Media Player (LIVE555 streaming media v2005.11.10) server response: rtsp/1.0 OK server:userver 0.9.7_rc1 cseq: 5 session:6310936469860791894 Connection:close The above methods are the most commonly used in the interactive process, and there are some important methods such as get/set_parameter,pause,redirect and so on.   PS:SDP's format v=<version> o=<username> <session id> <version> <network type> <address type> <address> s=<session name> I=&L T;session description> u=<uri> e=<email address> p=<phone number> c=<network type> < Address type> <connection address> b=<modifier>:<bandwidth-value> t=<start time> <stop time> r=<repeat interval> <active duration> <list of offsets from start-time> z=<adjustment time& Gt <offset> <adjustment time> <offset> k=<method> k=<method>:<encryption key> a= <attribute> a=<attribute>:<value> m=<media> <port> <transport> <fmt list> V = (protocol version) O = (owner/creator and session identifier) s = (session name) i = * (Session information) U = * (URI description) E = * (Email address) p = * (phone number) c = * (connection information) b = * (Bandwidth information) z = * (time zone adjustment) k = * (encryption key) A = * (0 or more session property rows) Time Description: T = (session activity time) r = * (0 or more repetitions) media Description: M = (media name and transport address) i = * (media title) c = * (Connection information-This field is optional if included in the session layer) B = * (bandwidth information) K = * (encryption key) A = * (0 or more media property rows)

The Java implementation of the RTSP client


3.1 Interface Ievent.java

The code for the interface Ievent.java is as follows: Java code package COM.AMIGO.RTSP;   Import java.io.IOException;      Import Java.nio.channels.SelectionKey;  /** *//** * Ievent.java A network event handler that calls methods in this interface when the selector can be manipulated. * 2007-3-22 03:35:51

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.