RTSP introduction (zt) Real Time Streaming Protocol or RTSP (Real-Time Streaming Protocol) is an application layer protocol jointly proposed by real network and Netscape to effectively transmit streaming media data over an IP network. RTSP provides an extensible framework that enables controllable and on-demand transmission of real-time data, such as audio and video files. The source data can include on-site data feedback and stored files. RTSP provides control for streaming media such as pause and fast forward, but it does not transmit data itself. RTSP is equivalent to remote control of streaming media servers. Data can be transmitted through TCP, UDP, and RTSP at the transport layer, which also provides some effective methods based on the RTP transmission mechanism.
RTSP
Message format:There are two types of RTSP messages: request and response. The two types of messages have different formats. request Message: Method uri rtsp version cr lf message header cr lf message body cr lf The method includes all the commands in the option response. Uri is the recipient's address, for example: rtsp: // 192.168.20.136rtsp versions are generally RTSP/1. 0. the cr lf after each line indicates that the carriage return line breaks, and the receiver must have corresponding parsing. The last message header must have two cr lf response messages: the RTSP version Status Code explains the cr lf message header cr lf message body cr lf the RTSP version is generally RTSP/1.0, the status code is a value, 200 indicates success, the description is a text explanation corresponding to the status code.
Simple RTSP interaction process:C Indicates the RTSP client, and s indicates the RTSP Server 1. c-> S: Option request // ask s which methods are available. 1. s-> C: Option response // all available methods provided are included in the response information. c-> S: DESCRIBE request // obtain the media initialization description provided by S. 2. s-> C: Describe response // s response media initialization description, mainly SDP 3. c-> S: SETUP Request // sets the properties of the session and transmission mode to remind s to establish the session 3. s-> C: setup response // s creates a session and returns the session identifier and session-related information. 4. c-> S: Play request // C request playback 4. s-> C: Play response // s back the information that should be requested S-> C: Send streaming media data 5. c-> S: teardown request // C request to close the session 5. s-> C: teardown Response // s should request that the above process is a standard and friendly RTSP process, but the actual needs are not necessarily step by step. Steps 3rd and 4 are required! Step 1: The option request is optional as long as the server client has agreed on which methods are available. Step 2: If we have other ways to obtain media initialization descriptions (such as HTTP requests), we do not need to use the DESCRIBE request in RTSP. Step 5: determine whether or not to use the system based on the system requirements.
RTSP
Common Methods:1. option is used to obtain the available method provided by the server: Options rtsp: // 192.168.20.136: 5000/xxx666 RTSP/1.0 CSeq: 1 // each message is marked with a serial number, the first packet is usually the option request message User-Agent: VLC Media Player (live555 streaming media v2005.11.10). The server response information includes the provided methods, such as RTSP/1.0 200 okserver: userver 0.9.7 _ rc1cseq: 1 // The CSeq value of each Response Message corresponds to public: Options, describe, setup, teardown, play, pause, scale, get_parameter // available method provided by the server 2. describec initiates a DESCRIBE request to S. Description (SDP): Describe rtsp: // 192.168.20.136: 5000/xxx666 RTSP/1.0 CSeq: 2 token: accept: Application/sdpuser-AGENT: VLC Media Player (live555 streaming media v2005.11.10) the server responds to some descriptions of this session (SDP): RTSP/1.0 200 okserver: userver 0.9.7 _ rc1cseq: 2x-prev-url: rtsp: // 192.168.20.136: 5000x-next-url: rtsp: // 192.168.20.136: 5000x-accept-retransmit: Our-retransmitx-Accept-dynamic-rate: 1cache-control: Must-revalidatela St-modified: Fri, 10 Nov 2006 12:34:38 gmtdate: Fri, 10 Nov 2006 12:34:38 gmtexpires: Fri, 10 Nov 2006 12:34:38 gmtcontent-base: rtsp: // 192.168.20.136: 5000/xxx666/Content-Length: 344content-type: Application/sdp v = 0 // The following are all SDP Information o = onewaveuserverng 1451516402 1025358037 in ip4 192.168.20.136s =/xxx666u = http: // E = admin @ C = in ip4 0.0.0.0t = 0 0a = Isma-compliance: 1, 1.0, 1 A = range: treaty = 0-m = video 0 RTP/AVP 96 // M indicates the media description. The following is the media description of the video channel in the session a = rtpmap: 96 MP4V-ES/90000a = fmtp: 96 profile-level-id = 245; config = 000001b0f5000001b50900000000000012000c888b0e0e0fa62d089028307a = control: trackID = 0 // trackID = 0 indicates that the video stream uses channel 0 3. the setup client notifies the server to establish a session and determines the transmission 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 to set the channel. The transport parameter sets the transmission mode and package structure. The second byte location of the next packet header is interleaved. Its value is different for each channel. The interleaved value of trackID = 0 has two 0 or values, indicating the RTP packet, 1 indicates the RTCP package. The receiver distinguishes the packet based on the value of interleaved. Server Response Information: RTSP/1.0 200 okserver: userver 0.9.7 _ rc1cseq: 3 session: 6310936469860791894 // session identifier cache-control: No-cachetransport: RTP/AVP/tcp; unicast; interleaved = 0-1; SSRC = 6b8b45674. the play client sends a playback request: Play rtsp: // 192.168.20.136: 5000/xxx666 RTSP/1.0 CSeq: 4 session: 6310936469860791894 range: user-Agent: VLC Media Player (live555 streaming media v2005.11.10) Server Response Information: RTSP/0.000 1.0 okserver: userver 0.9.7 _ rc1cseq: 4 session: 6310936469860791894 range: Treaty = 0.000000-RTP-Info: url = trackID = 0; seq = 17040; rtptime = 1467265309 // seq and rtptime are information in the RTP Package 5. the teardown client initiates a close request: teardown rtsp: // 192.168.20.136: 5000/xxx666 RTSP/1.0 CSeq: 5 Session: Protocol: VLC Media Player (live555 streaming media v2005.11.10) server response: RTSP/1.0 200 okserver: userver 0.9.7 _ rc1cseq: 5 Session: 6310936469860791894 connection: Close the above methods are the most commonly used in the interaction process, and other important methods such as get/set_parameter, pause, redirect, etc.
PS:SDP format v = <version> O = <username> <session ID> <version> <network type> <address> S = <session Name> I = <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> <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 multiple session attribute rows) time Description: t = (Session Activity time) r = * (0 or multiple repetitions) Media description: M = (media name and transfer address) I = * (media title) C = * (connection information-this field is optional if it is included in the Session Layer) B = * (bandwidth information) k = * (encryption key) A = * (0 or multiple media attribute rows)
Reference: rfc2326 (RTSP); rfc2327 (SDP)