RFC 2326
Real Time Streaming Protocol (RTSP)
Title Block ๐
okay bestie, let's get you situated ๐ This is RFC 2326, called Real Time Streaming Protocol (RTSP), published in April 1998 as a Standards Track doc in the Network Working Group ๐ฆ
The authors are H. Schulzrinne (Columbia U.), A. Rao (Netscape), and R. Lanphier (RealNetworks). The title block doesn't list any obsoletes or updates entries ๐
Status of This Memo โจ
okay so this doc is an Internet standards track protocol for the Internet community ๐ธ It's also asking people to talk about it and suggest improvements, which is so generous of them ๐ซถ
If you want to know where this protocol stands officially, check the current edition of the "Internet Official Protocol Standards" (STD 1). That's the source of truth for its standardization state and status ๐
Distribution of this memo is unlimited, so share it with everyone ๐
Copyright Notice ๐
Copyright (C) The Internet Society (1998). All Rights Reserved. ๐
Abstract ๐ฆ
so the Real Time Streaming Protocol, or RTSP, is an application-level protocol for controlling the delivery of data that has real-time properties ๐ฅ It gives you an extensible framework for controlled, on-demand delivery of real-time data, like audio and video ๐
The sources can be live data feeds or stored clips, both work ๐ง
RTSP is built to control multiple data delivery sessions at once. It also lets you choose your delivery channels, like UDP, multicast UDP, and TCP โจ On top of that, it lets you choose delivery mechanisms based on RTP (RFC 1889) ๐
Table of Contents ๐
* 1 Introduction ................................................. 5
+ 1.1 Purpose ............................................... 5
+ 1.2 Requirements .......................................... 6
+ 1.3 Terminology ........................................... 6
+ 1.4 Protocol Properties ................................... 9
+ 1.5 Extending RTSP ........................................ 11
+ 1.6 Overall Operation ..................................... 11
+ 1.7 RTSP States ........................................... 12
+ 1.8 Relationship with Other Protocols ..................... 13
* 2 Notational Conventions ....................................... 14
* 3 Protocol Parameters .......................................... 14
+ 3.1 RTSP Version .......................................... 14
+ 3.2 RTSP URL .............................................. 14
+ 3.3 Conference Identifiers ................................ 16
+ 3.4 Session Identifiers ................................... 16
+ 3.5 SMPTE Relative Timestamps ............................. 16
+ 3.6 Normal Play Time ...................................... 17
+ 3.7 Absolute Time ......................................... 18
+ 3.8 Option Tags ........................................... 18
o 3.8.1 Registering New Option Tags with IANA .......... 18
* 4 RTSP Message ................................................. 19
+ 4.1 Message Types ......................................... 19
+ 4.2 Message Headers ....................................... 19
+ 4.3 Message Body .......................................... 19
+ 4.4 Message Length ........................................ 20
* 5 General Header Fields ........................................ 20
* 6 Request ...................................................... 20
+ 6.1 Request Line .......................................... 21
+ 6.2 Request Header Fields ................................. 21
* 7 Response ..................................................... 22
+ 7.1 Status-Line ........................................... 22
o 7.1.1 Status Code and Reason Phrase .................. 22
o 7.1.2 Response Header Fields ......................... 26
* 8 Entity ....................................................... 27
+ 8.1 Entity Header Fields .................................. 27
+ 8.2 Entity Body ........................................... 28
* 9 Connections .................................................. 28
+ 9.1 Pipelining ............................................ 28
+ 9.2 Reliability and Acknowledgements ...................... 28
* 10 Method Definitions .......................................... 29
+ 10.1 OPTIONS .............................................. 30
+ 10.2 DESCRIBE ............................................. 31
+ 10.3 ANNOUNCE ............................................. 32
+ 10.4 SETUP ................................................ 33
+ 10.5 PLAY ................................................. 34
+ 10.6 PAUSE ................................................ 36
+ 10.7 TEARDOWN ............................................. 37
+ 10.8 GET_PARAMETER ........................................ 37
+ 10.9 SET_PARAMETER ........................................ 38
+ 10.10 REDIRECT ............................................ 39
+ 10.11 RECORD .............................................. 39
+ 10.12 Embedded (Interleaved) Binary Data .................. 40
* 11 Status Code Definitions ..................................... 41
+ 11.1 Success 2xx .......................................... 41
o 11.1.1 250 Low on Storage Space ...................... 41
+ 11.2 Redirection 3xx ...................................... 41
+ 11.3 Client Error 4xx ..................................... 42
o 11.3.1 405 Method Not Allowed ........................ 42
o 11.3.2 451 Parameter Not Understood .................. 42
o 11.3.3 452 Conference Not Found ...................... 42
o 11.3.4 453 Not Enough Bandwidth ...................... 42
o 11.3.5 454 Session Not Found ......................... 42
o 11.3.6 455 Method Not Valid in This State ............ 42
o 11.3.7 456 Header Field Not Valid for Resource ....... 42
o 11.3.8 457 Invalid Range ............................. 43
o 11.3.9 458 Parameter Is Read-Only .................... 43
o 11.3.10 459 Aggregate Operation Not Allowed .......... 43
o 11.3.11 460 Only Aggregate Operation Allowed ......... 43
o 11.3.12 461 Unsupported Transport .................... 43
o 11.3.13 462 Destination Unreachable .................. 43
o 11.3.14 551 Option not supported ..................... 43
* 12 Header Field Definitions .................................... 44
+ 12.1 Accept ............................................... 46
+ 12.2 Accept-Encoding ...................................... 46
+ 12.3 Accept-Language ...................................... 46
+ 12.4 Allow ................................................ 46
+ 12.5 Authorization ........................................ 46
+ 12.6 Bandwidth ............................................ 46
+ 12.7 Blocksize ............................................ 47
+ 12.8 Cache-Control ........................................ 47
+ 12.9 Conference ........................................... 49
+ 12.10 Connection .......................................... 49
+ 12.11 Content-Base ........................................ 49
+ 12.12 Content-Encoding .................................... 49
+ 12.13 Content-Language .................................... 50
+ 12.14 Content-Length ...................................... 50
+ 12.15 Content-Location .................................... 50
+ 12.16 Content-Type ........................................ 50
+ 12.17 CSeq ................................................ 50
+ 12.18 Date ................................................ 50
+ 12.19 Expires ............................................. 50
+ 12.20 From ................................................ 51
+ 12.21 Host ................................................ 51
+ 12.22 If-Match ............................................ 51
+ 12.23 If-Modified-Since ................................... 52
+ 12.24 Last-Modified........................................ 52
+ 12.25 Location ............................................ 52
+ 12.26 Proxy-Authenticate .................................. 52
+ 12.27 Proxy-Require ....................................... 52
+ 12.28 Public .............................................. 53
+ 12.29 Range ............................................... 53
+ 12.30 Referer ............................................. 54
+ 12.31 Retry-After ......................................... 54
+ 12.32 Require ............................................. 54
+ 12.33 RTP-Info ............................................ 55
+ 12.34 Scale ............................................... 56
+ 12.35 Speed ............................................... 57
+ 12.36 Server .............................................. 57
+ 12.37 Session ............................................. 57
+ 12.38 Timestamp ........................................... 58
+ 12.39 Transport ........................................... 58
+ 12.40 Unsupported ......................................... 62
+ 12.41 User-Agent .......................................... 62
+ 12.42 Vary ................................................ 62
+ 12.43 Via ................................................. 62
+ 12.44 WWW-Authenticate .................................... 62
* 13 Caching ..................................................... 62
* 14 Examples .................................................... 63
+ 14.1 Media on Demand (Unicast) ............................ 63
+ 14.2 Streaming of a Container file ........................ 65
+ 14.3 Single Stream Container Files ........................ 67
+ 14.4 Live Media Presentation Using Multicast .............. 69
+ 14.5 Playing media into an existing session ............... 70
+ 14.6 Recording ............................................ 71
* 15 Syntax ...................................................... 72
+ 15.1 Base Syntax .......................................... 72
* 16 Security Considerations ..................................... 73
* A RTSP Protocol State Machines ................................. 76
+ A.1 Client State Machine .................................. 76
+ A.2 Server State Machine .................................. 77
* B Interaction with RTP ......................................... 79
* C Use of SDP for RTSP Session Descriptions ..................... 80
+ C.1 Definitions ........................................... 80
o C.1.1 Control URL .................................... 80
o C.1.2 Media streams .................................. 81
o C.1.3 Payload type(s) ................................ 81
o C.1.4 Format-specific parameters ..................... 81
o C.1.5 Range of presentation .......................... 82
o C.1.6 Time of availability ........................... 82
o C.1.7 Connection Information ......................... 82
o C.1.8 Entity Tag ..................................... 82
+ C.2 Aggregate Control Not Available ....................... 83
+ C.3 Aggregate Control Available ........................... 83
* D Minimal RTSP implementation .................................. 85
+ D.1 Client ................................................ 85
o D.1.1 Basic Playback ................................. 86
o D.1.2 Authentication-enabled ......................... 86
+ D.2 Server ................................................ 86
o D.2.1 Basic Playback ................................. 87
o D.2.2 Authentication-enabled ......................... 87
* E Authors' Addresses ........................................... 88
* F Acknowledgements ............................................. 89
* References ..................................................... 90
* Full Copyright Statement ....................................... 92
1. Introduction โจ
bestie, the body text of Section 1 didn't come through in this part, so I've only got the heading for now. Send the next chunk and I'll pick up right where this leaves off ๐
1.1. Purpose โจ
okay so RTSP is giving "network remote control" ๐ฎ bestie. It sets up and controls either a single stream or several time-synchronized streams of continuous media, like audio and video ๐ฌ. It doesn't usually deliver the continuous streams itself, although interleaving the continuous media stream with the control stream is possible (see Section 10.12). Basically, RTSP is the remote control for multimedia servers ๐บ.
The set of streams being controlled is defined by a presentation description. This memorandum does not define a format for a presentation description ๐.
There is no notion of an RTSP connection ๐ . Instead, a server maintains a session labeled by an identifier. An RTSP session is in no way tied to a transport-level connection such as a TCP connection. During an RTSP session, an RTSP client may open and close many reliable transport connections to the server to issue RTSP requests. Or it may use a connectionless transport protocol such as UDP ๐.
The streams RTSP controls may use RTP [1], but how RTSP works doesn't depend on the transport mechanism that carries the continuous media. RTSP is intentionally similar in syntax and operation to HTTP/1.1 [2], so extension mechanisms for HTTP can in most cases also be added to RTSP ๐ซถ. However, RTSP differs from HTTP in a number of important aspects:
- RTSP introduces a number of new methods and has a different protocol identifier.
- An RTSP server needs to maintain state by default in almost all cases, as opposed to the stateless nature of HTTP.
- Both an RTSP server and client can issue requests.
- Data is carried out-of-band by a different protocol. (There is an exception to this.)
- RTSP is defined to use ISO 10646 (UTF-8) rather than ISO 8859-1, consistent with current HTML internationalization efforts [3].
- The Request-URI always contains the absolute URI. Because of backward compatibility with a historical blunder, HTTP/1.1 [2] carries only the absolute path in the request and puts the host name in a separate header field.
This makes "virtual hosting" easier, where a single host with one IP address hosts several document trees. ๐ธ
The protocol supports the following operations ๐ง:
- Retrieval of media from media server: The client can request a presentation description via HTTP or some other method. If the presentation is being multicast, the presentation description contains the multicast addresses and ports to be used for the continuous media. If the presentation is to be sent only to the client via unicast, the client provides the destination for security reasons. ๐
- Invitation of a media server to a conference: A media server can be "invited" to join an existing conference, either to play back media into the presentation or to record all or a subset of the media in a presentation. This mode is useful for distributed teaching applications. Several parties in the conference may take turns "pushing the remote control buttons." ๐
- Addition of media to an existing presentation: Particularly for live presentations, it is useful if the server can tell the client about additional media becoming available. ๐ก
RTSP requests may be handled by proxies, tunnels and caches, as in HTTP/1.1 [2]. ๐ฆ
1.2. Requirements ๐
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [4]. ๐
1.3. Terminology ๐
Some of the terminology has been adopted from HTTP/1.1 [2]. Terms not listed here are defined as in HTTP/1.1. ๐
- Aggregate control: The control of the multiple streams using a single timeline by the server. For audio/video feeds, this means that the client may issue a single play or pause message to control both the audio and video feeds. ๐ถ
- Conference: a multiparty, multimedia presentation, where "multi" implies greater than or equal to one. ๐
- Client: The client requests continuous media data from the media server. ๐
- Connection: A transport layer virtual circuit established between two programs for the purpose of communication. ๐
- Container file: A file which may contain multiple media streams which often comprise a presentation when played together. RTSP servers may offer aggregate control on these files, though the concept of a container file is not embedded in the protocol. ๐๏ธ
- Continuous media: Data where there is a timing relationship between source and sink; that is, the sink must reproduce the timing relationship that existed at the source. The most common examples of continuous media are audio and motion video. Continuous media can be real-time (interactive), where there is a "tight" timing relationship between source and sink, or streaming (playback), where the relationship is less strict. โฑ๏ธ
- Entity: The information transferred as the payload of a request or response. An entity consists of metainformation in the form of entity-header fields and content in the form of an entity-body, as described in Section 8. ๐ฆ
- Media initialization: Datatype/codec specific initialization. This includes such things as clockrates, color tables, etc. Any transport-independent information which is required by a client for playback of a media stream occurs in the media initialization phase of stream setup. ๐จ
- Media parameter: Parameter specific to a media type that may be changed before or during stream playback. ๐๏ธ
- Media server: The server providing playback or recording services for one or more media streams. Different media streams within a presentation may originate from different media servers. A media server may reside on the same or a different host as the web server the presentation is invoked from. ๐ฅ๏ธ
- Media server indirection: Redirection of a media client to a different media server. ๐
- (Media) stream: A single media instance, e.g., an audio stream or a video stream as well as a single whiteboard or shared application group. When using RTP, a stream consists of all RTP and RTCP packets created by a source within an RTP session. This is equivalent to the definition of a DSM-CC stream([5]). ๐
- Message: The basic unit of RTSP communication, consisting of a structured sequence of octets matching the syntax defined in Section 15 and transmitted via a connection or a connectionless protocol. โ๏ธ
- Participant: Member of a conference. A participant may be a machine, e.g., a media record or playback server. ๐งโ๐คโ๐ง
- Presentation: A set of one or more streams presented to the client as a complete media feed, using a presentation description as defined below. In most cases in the RTSP context, this implies aggregate control of those streams, but does not have to. ๐ฟ
- Presentation description: A presentation description contains information about one or more media streams within a presentation, such as the set of encodings, network addresses and information about the content. Other IETF protocols such as SDP (RFC 2327 [6]) use the term "session" for a live presentation. The presentation description may take several different formats, including but not limited to the session description format SDP. ๐บ๏ธ
- Response: An RTSP response. If an HTTP response is meant, that is indicated explicitly. ๐ฌ
- Request: An RTSP request. If an HTTP request is meant, that is indicated explicitly. ๐ฎ
- RTSP session: A complete RTSP "transaction", e.g., the viewing of a movie. A session typically consists of a client setting up a transport mechanism for the continuous media stream (SETUP), starting the stream with PLAY or RECORD, and closing the stream with TEARDOWN. ๐ฌ๐
- Transport initialization: The negotiation of transport information (e.g., port numbers, transport protocols) between the client and the server. ๐ค
1.4. Protocol Properties โจ
okay so RTSP has a whole list of properties, and honestly they're iconic ๐ Let's go:
- Extendable: new methods and parameters can be easily added to RTSP ๐ง
- Easy to parse: RTSP can be parsed by standard HTTP or MIME parsers. It's giving familiar ๐
- Secure: RTSP re-uses web security mechanisms. All HTTP authentication mechanisms such as basic (RFC 2068 [2, Section 11.1]) and digest authentication (RFC 2069 [8]) are directly applicable. One may also reuse transport or network layer security mechanisms ๐
- Transport-independent: RTSP may use an unreliable datagram protocol (UDP) (RFC 768 [9]), a reliable datagram protocol (RDP, RFC 1151, not widely used [10]), or a reliable stream protocol such as TCP (RFC 793 [11]). It can do this because it implements application-level reliability ๐ฆ
- Multi-server capable: each media stream within a presentation can live on a different server. The client automatically sets up several concurrent control sessions with the different media servers. Media synchronization is performed at the transport level ๐
- Control of recording devices: the protocol can control both recording and playback devices, as well as devices that can switch between the two modes ("VCR") ๐ผ
- Separation of stream control and conference initiation: stream control is divorced from inviting a media server to a conference. The only requirement is that the conference initiation protocol either provides or can be used to create a unique conference identifier. In particular, SIP [12] or H.323 [13] may be used to invite a server to a conference ๐
- Suitable for professional applications: RTSP supports frame-level accuracy through SMPTE time stamps, so remote digital editing is a go ๐ฌ
- Presentation description neutral: the protocol does not impose a particular presentation description or metafile format, and it can convey the type of format to be used. However, the presentation description must contain at least one RTSP URI ๐
- Proxy and firewall friendly: the protocol should be readily handled by both application and transport-layer (SOCKS [14]) firewalls. A firewall may need to understand the SETUP method to open a "hole" for the UDP media stream ๐งฑ
- HTTP-friendly: where sensible, RTSP reuses HTTP concepts so the existing infrastructure can be reused. This infrastructure includes PICS (Platform for Internet Content Selection [15,16]) for associating labels with content. However, RTSP does not just add methods to HTTP, since controlling continuous media requires server state in most cases ๐
- Appropriate server control: if a client can start a stream, it must be able to stop a stream. Servers should not start streaming to clients in such a way that clients cannot stop the stream ๐
- Transport negotiation: the client can negotiate the transport method before it actually needs to process a continuous media stream ๐ค
- Capability negotiation: if basic features are disabled, there must be some clean mechanism for the client to determine which methods are not going to be implemented. This lets clients present the appropriate user interface. For example, if seeking is not allowed, the user interface must be able to disallow moving a sliding position indicator ๐
An earlier requirement in RTSP was multi-client capability. However, it was determined that a better approach was to make sure that the protocol is easily extensible to the multi-client scenario. Stream identifiers can be used by several control streams, so that "passing the remote" would be possible. The protocol would not address how several clients negotiate access; this is left to either a "social protocol" or some other floor control mechanism. Main character energy, but for the remote ๐ฎ
1.5. Extending RTSP
okay, not every media server has the same functionality, so servers will by necessity support different sets of requests. For example:
- A server may only be capable of playback, so it has no need to support the RECORD request ๐ผ
- A server may not be capable of seeking (absolute positioning) if it is only supporting live events ๐ก
- Some servers may not support setting stream parameters, and so they don't support
GET_PARAMETERandSET_PARAMETER๐ โโ๏ธ
A server SHOULD implement all header fields described in Section 12. ๐
It is up to the creators of presentation descriptions not to ask the impossible of a server. This situation is similar in HTTP/1.1 [2], where the methods described in [H19.6] are not likely to be supported across all servers ๐ซถ
RTSP can be extended in three ways, listed here in order of the magnitude of changes supported:
- Existing methods can be extended with new parameters, as long as these parameters can be safely ignored by the recipient. (This is equivalent to adding new parameters to an HTML tag.) If the client needs negative acknowledgement when a method extension is not supported, a tag corresponding to the extension may be added in the
Require:field (see Section 12.32) โจ - New methods can be added. If the recipient of the message does not understand the request, it responds with error code 501 (Not implemented), and the sender should not attempt to use this method again. A client may also use the OPTIONS method to ask about methods supported by the server. The server SHOULD list the methods it supports using the
Publicresponse header ๐ - A new version of the protocol can be defined, allowing almost all aspects (except the position of the protocol version number) to change. Major glow-up ๐ฆ
1.6. Overall Operation
okay so each presentation and media stream may be identified by an RTSP URL ๐ The overall presentation, and the properties of the media that make it up, are defined by a presentation description file. Its format is outside the scope of this specification. The client may get the presentation description file using HTTP or other means, such as email, and it may not necessarily be stored on the media server ๐จ
For the purposes of this specification, a presentation description is assumed to describe one or more presentations, each of which maintains a common time axis. For simplicity of exposition and without loss of generality, it is assumed that the presentation description contains exactly one such presentation. A presentation may contain several media streams โฑ๏ธ
The presentation description file contains a description of the media streams making up the presentation, including their encodings, language, and other parameters that let the client choose the most appropriate combination of media. In this presentation description, each media stream that is individually controllable by RTSP is identified by an RTSP URL. That URL points to the media server handling that particular media stream and names the stream stored on that server. Several media streams can be located on different servers. For example, audio and video streams can be split across servers for load sharing โ๏ธ The description also lists which transport methods the server is capable of ๐
Besides the media parameters, the network destination address and port need to be determined. Several modes of operation can be distinguished:
- Unicast: the media is transmitted to the source of the RTSP request, with the port number chosen by the client. Alternatively, the media is transmitted on the same reliable stream as RTSP ๐ฏ
- Multicast, server chooses address: the media server picks the multicast address and port. This is the typical case for a live or near-media-on-demand transmission ๐ข
- Multicast, client chooses address: if the server is to participate in an existing multicast conference, the multicast address, port, and encryption key are given by the conference description. That description is established by means outside the scope of this specification ๐
1.7. RTSP States
RTSP controls a stream, which may be sent via a separate protocol, independent of the control channel. For example, RTSP control may occur on a TCP connection while the data flows via UDP. Thus, data delivery continues even if no RTSP requests are received by the media server. Also, during its lifetime, a single media stream may be controlled by RTSP requests issued sequentially on different TCP connections. Therefore, the server needs to maintain "session state" to be able to correlate RTSP requests with a stream. The state transitions are described in Section A ๐ง
Many methods in RTSP do not contribute to state. However, the following play a central role in defining the allocation and usage of stream resources on the server: SETUP, PLAY, RECORD, PAUSE, and TEARDOWN ๐๏ธ
- SETUP: causes the server to allocate resources for a stream and start an RTSP session ๐
- PLAY and RECORD: start data transmission on a stream allocated via SETUP โถ๏ธโบ๏ธ
- PAUSE: temporarily halts a stream without freeing server resources โธ๏ธ
- TEARDOWN: frees resources associated with the stream. The RTSP session ceases to exist on the server ๐
RTSP methods that contribute to state use the Session header field (Section 12.37) to identify the RTSP session whose state is being manipulated. The server generates session identifiers in response to SETUP requests (Section 10.4) ๐ชช
1.8. Relationship with Other Protocols
RTSP has some overlap in functionality with HTTP. It also may interact with HTTP, since the initial contact with streaming content is often made through a web page ๐ The current protocol specification aims to allow different hand-off points between a web server and the media server implementing RTSP. For example, the presentation description can be retrieved using HTTP or RTSP. That reduces roundtrips in web-browser-based scenarios, and it also allows for standalone RTSP servers and clients that don't rely on HTTP at all ๐ง
However, RTSP differs fundamentally from HTTP in that data delivery takes place out-of-band, in a different protocol. HTTP is an asymmetric protocol where the client issues requests and the server responds. In RTSP, both the media client and media server can issue requests. RTSP requests are also not stateless. They may set parameters and continue to control a media stream long after the request has been acknowledged ๐
Re-using HTTP functionality has advantages in at least two areas, namely security and proxies. The requirements are very similar, so being able to adopt HTTP work on caches, proxies, and authentication is valuable ๐
While most real-time media will use RTP as a transport protocol, RTSP is not tied to RTP ๐ถ
RTSP assumes the existence of a presentation description format that can express both static and temporal properties of a presentation containing several media streams ๐
2. Notational Conventions โจ
okay so, a LOT of this stuff is literally the same as HTTP/1.1 ๐ธ so instead of copy-pasting it everywhere, this spec just points you to the right section. when you see [H2.X] it means Section X of the current HTTP/1.1 spec (that's RFC 2068 [2]) ๐ง
the grammar we use is basically the same augmented Backus-Naur form as [H2.1], described in full in RFC 2234 [17]. the one twist is that RTSP keeps the "1#" notation for comma-separated lists ๐
also, the indented, smaller-type paragraphs you'll see around the spec are just little "here's WHY" asides ๐ they're there so people who weren't in the room when this was written can understand why RTSP does things the way it does. literally the best part imo ๐ฅน
3. Protocol Parameters ๐ฆ
3.1. RTSP Version
[H3.1] applies, with HTTP replaced by RTSP. ๐
3.2. RTSP URL
the rtsp and rtspu schemes are how you point at network resources through RTSP. this section is where the scheme-specific syntax and semantics live ๐
rtsp_URL = ( "rtsp:" | "rtspu:" )
"//" host [ ":" port ] [ abs_path ]
host = <A legal Internet host domain name of IP address
(in dotted decimal form), as defined by Section 2.1
of RFC 1123 \cite{rfc1123}>
port = *DIGIT
abs_path is defined in [H3.2.1]. โจ
fragment and query identifiers don't have a well-defined meaning right now, so how they're interpreted is left up to the RTSP server ๐
the rtsp scheme means commands go over a reliable protocol (on the internet, that's TCP) ๐. the rtspu scheme means an unreliable protocol (on the internet, that's UDP) ๐
if the port is empty or not given, port 554 is assumed ๐. the idea is that the resource can be controlled by RTSP at the server listening on that port of the host, either over TCP for rtsp connections or UDP packets for rtspu, and the Request-URI for the resource is the rtsp_URL ๐
the use of IP addresses in URLs SHOULD be avoided whenever possible (see RFC 1924 [19]). bestie, use names ๐
a presentation or a stream gets identified by a textual media identifier, using the character set and escape conventions [H3.2] of URLs (RFC 1738 [20]). URLs can point at a single stream OR an aggregate of streams, aka a presentation ๐ฌ. so requests from Section 10 can apply to the whole presentation or just one stream inside it. also, some request methods only work on streams and not presentations (and the other way around) ๐ค
for example, this RTSP URL:
rtsp://media.example.com:554/twister/audiotrack
identifies the audio stream inside the presentation "twister", which you can control with RTSP requests over a TCP connection to port 554 of media.example.com ๐ง
and this one:
rtsp://media.example.com:554/twister
identifies the presentation "twister" itself, which might be made of audio and video streams ๐ฅ
this does NOT mean there's one standard way to name streams in URLs!! the presentation description defines how everything is nested and what the URL for each stream is. a presentation description could name a stream "a.mov" and the whole presentation "b.mov" ๐ซ
the path parts of an RTSP URL are opaque to the client, and they don't imply any particular file system structure on the server ๐๏ธ
this decoupling also means presentation descriptions can be used with non-RTSP media control protocols, you just swap out the scheme in the URL ๐ง
3.3. Conference Identifiers
conference identifiers are opaque to RTSP, and they're encoded using standard URI encoding methods (so LWS gets escaped with %) ๐ซง. they can contain any octet value. the conference identifier MUST be globally unique ๐. for H.323, the conferenceID value is the one to use ๐
conference-id = 1*xchar
conference identifiers let RTSP sessions grab parameters from multimedia conferences the media server is part of. those conferences get created by protocols outside this spec, like H.323 [13] or SIP [12]. so instead of the RTSP client spelling out transport info itself, it just tells the media server to use the values in the conference description ๐ช
3.4. Session Identifiers
session identifiers are opaque strings of arbitrary length ๐งฉ. linear white space must be URL-escaped. a session identifier MUST be chosen randomly and MUST be at least eight octets long, so it's harder to guess (see Section 16.) ๐ no lazy session IDs, periodt ๐
session-id = 1*( ALPHA | DIGIT | safe )
3.5. SMPTE Relative Timestamps
a SMPTE relative timestamp expresses time relative to the start of the clip โฑ๏ธ. these are SMPTE time codes so you get frame-level accuracy. the format is hours:minutes:seconds:frames.subframes, with the origin at the start of the clip ๐๏ธ. the default smpte format is "SMPTE 30 drop", with a frame rate of 29.97 frames per second ๐ญ. other SMPTE codes MAY be supported (like "SMPTE 25") through the alternative use of "smpte time" ๐. for the "frames" field, the value can be 0 through 29. the gap between 30 and 29.97 is handled by dropping the first two frame indices (values 00 and 01) of every minute, EXCEPT every tenth minute ๐คฏ. if the frame value is zero, it may be omitted. subframes are measured in one-hundredth of a frame ๐ข
smpte-range = smpte-type "=" smpte-time "-" [ smpte-time ]
smpte-type = "smpte" | "smpte-30-drop" | "smpte-25"
; other timecodes may be added
smpte-time = 1*2DIGIT ":" 1*2DIGIT ":" 1*2DIGIT [ ":" 1*2DIGIT ]
[ "." 1*2DIGIT ]
examples, because we love a good example ๐ญ:
smpte=10:12:33:20-
smpte=10:07:33-
smpte=10:07:00-10:07:33:05.01
smpte-25=10:07:00-10:07:33:05.01
3.6. Normal Play Time
normal play time (NPT) tells you the stream's absolute position relative to the beginning of the presentation โฏ๏ธ. the timestamp is a decimal fraction. the part left of the decimal can be in seconds OR hours, minutes, and seconds. the part right of the decimal point measures fractions of a second ๐ฐ๏ธ
the beginning of a presentation is 0.0 seconds. negative values are not defined ๐ซ. the special constant now means the current instant of a live event, and it may be used only for live events ๐ก
NPT is defined as in DSM-CC, and the DSM-CC definition goes like this [5]:
"Intuitively, NPT is the clock the viewer associates with a program. It is often digitally displayed on a VCR. NPT advances normally when in normal play mode (scale = 1), advances at a faster rate when in fast scan forward (high positive scale ratio), decrements when in scan reverse (high negative scale ratio) and is fixed in pause mode. NPT is (logically) equivalent to SMPTE time codes."
the grammar, no cap, is kinda iconic ๐:
npt-range = ( npt-time "-" [ npt-time ] ) | ( "-" npt-time )
npt-time = "now" | npt-sec | npt-hhmmss
npt-sec = 1*DIGIT [ "." *DIGIT ]
npt-hhmmss = npt-hh ":" npt-mm ":" npt-ss [ "." *DIGIT ]
npt-hh = 1*DIGIT ; any positive number
npt-mm = 1*2DIGIT ; 0-59
npt-ss = 1*2DIGIT ; 0-59
examples:
npt=123.45-125
npt=12:05:35.3-
npt=now-
the syntax follows ISO 8601. the npt-sec notation is optimized for automatic generation, and the npt-hhmmss notation is for human readers (the spec says "ntp-hhmmss" there, but it's the npt-hhmmss form) ๐คญ. the "now" constant lets clients ask for the live feed instead of the stored or time-delayed version. this is needed because neither absolute time nor zero time makes sense for this case โณ
3.7. Absolute Time
absolute time is written as ISO 8601 timestamps, using UTC (GMT). fractions of a second may be included ๐
utc-range = "clock" "=" utc-time "-" [ utc-time ]
utc-time = utc-date "T" utc-time "Z"
utc-date = 8DIGIT ; < YYYYMMDD >
utc-time = 6DIGIT [ "." fraction ] ; < HHMMSS.fraction >
example for November 8, 1996 at 14:37 and 20.25 seconds UTC:
19961108T143720.25Z
3.8. Option Tags
option tags are unique identifiers used to designate new options in RTSP ๐ท๏ธ. they show up in the Require (Section 12.32) and Proxy-Require (Section 12.27) header fields ๐
syntax:
option-tag = 1*xchar
the creator of a new RTSP option should either prefix the option with a reverse domain name (like "com.foo.mynewfeature", which is an apt name for a feature whose inventor can be reached at "foo.com") ๐ชช, or register the new option with the Internet Assigned Numbers Authority (IANA) ๐๏ธ.
3.8.1. Registering New Option Tags with IANA
when you register a new RTSP option, you should provide the following info ๐:
- Name and description of option. The name may be of any length, but SHOULD be no more than twenty characters long. The name MUST not contain any spaces, control characters or periods. ๐
- Indication of who has change control over the option (for example, IETF, ISO, ITU-T, other international standardization bodies, a consortium or a particular company or group of companies);
- A reference to a further description, if available, for example (in order of preference) an RFC, a published paper, a patent filing, a technical report, documented source code or a computer manual;
- For proprietary options, contact information (postal and email address);
4. RTSP Message ๐
RTSP is a text-based protocol, and it uses the ISO 10646 character set in UTF-8 encoding (RFC 2279 [21]). lines are terminated by CRLF, but receivers should be prepared to also interpret CR and LF by themselves as line terminators ๐งพ
text-based protocols make it easier to add optional parameters in a self-describing way. since the number of parameters and the frequency of commands is low, processing efficiency isn't a concern. text-based protocols, if done carefully, also make it easy to build research prototypes in scripting languages like Tcl, Visual Basic and Perl ๐
the 10646 character set avoids tricky character set switching, and it's invisible to the application as long as US-ASCII is being used. this is also the encoding used for RTCP. ISO 8859-1 translates directly into Unicode with a high-order octet of zero. ISO 8859-1 characters with the most-significant bit set are represented as:
1100001x 10xxxxxx
(see RFC 2279 [21])
RTSP messages can be carried over any lower-layer transport protocol that is 8-bit clean ๐.
requests contain methods, the object the method is operating on, and parameters to further describe the method ๐ฏ. methods are idempotent, unless otherwise noted ๐. methods are also designed to require little or no state maintenance at the media server ๐ง
4.1. Message Types
See [H4.1] ๐ซ
4.2. Message Headers
See [H4.2] ๐ซ
4.3. Message Body
See [H4.3] ๐ซ
4.4 Message Length ๐
Okay so, when a message has a body hanging off it, the body's length gets decided by one of these three things, checked in this order of precedence ๐ :
- Any response that MUST NOT include a message body (like the 1xx, 204, and 304 responses) always ends at the first empty line after the header fields, no matter what entity-header fields are in there. (Note: an empty line is just CRLF, nothing else ๐ซถ)
- If a Content-Length header field (section 12.14) is present, its value in bytes is the length of the message-body. If that header isn't there, zero is assumed ๐ธ
- The server closes the connection. (Closing the connection can't mark the end of a request body, because then the server would have no way to send back a response ๐ญ)
Also, RTSP doesn't (for now) support the HTTP/1.1 "chunked" transfer coding (see [H3.6]), and it needs Content-Length to be there ๐
Presentation descriptions are usually a moderate size, so the server should always be able to figure out the length, even when it's generated on the fly. That means chunked encoding isn't needed! Content-Length must be present if there's any entity body, but the rules still keep things sensible even when the length isn't spelled out. โจ
5 General Header Fields โจ
Same as [H4.5], except Pragma, Transfer-Encoding and Upgrade headers aren't defined here ๐ฆ
general-header = Cache-Control ; Section 12.8
| Connection ; Section 12.10
| Date ; Section 12.18
| Via ; Section 12.43
6 Request ๐
A request message from a client to a server (or the other way around) includes, in its very first line, the method to apply to the resource, the identifier of the resource, and the protocol version being used ๐ง
Request = Request-Line ; Section 6.1
*( general-header ; Section 5
| request-header ; Section 6.2
| entity-header ) ; Section 8.1
CRLF
[ message-body ] ; Section 4.3
6.1 Request Line ๐
Request-Line = Method SP Request-URI SP RTSP-Version CRLF
Method = "DESCRIBE" ; Section 10.2
| "ANNOUNCE" ; Section 10.3
| "GET_PARAMETER" ; Section 10.8
| "OPTIONS" ; Section 10.1
| "PAUSE" ; Section 10.6
| "PLAY" ; Section 10.5
| "RECORD" ; Section 10.11
| "REDIRECT" ; Section 10.10
| "SETUP" ; Section 10.4
| "SET_PARAMETER" ; Section 10.9
| "TEARDOWN" ; Section 10.7
| extension-method
extension-method = token
Request-URI = "*" | absolute_URI
RTSP-Version = "RTSP" "/" 1*DIGIT "." 1*DIGIT
6.2 Request Header Fields ๐
request-header = Accept ; Section 12.1
| Accept-Encoding ; Section 12.2
| Accept-Language ; Section 12.3
| Authorization ; Section 12.5
| From ; Section 12.20
| If-Modified-Since ; Section 12.23
| Range ; Section 12.29
| Referer ; Section 12.30
| User-Agent ; Section 12.41
Okay, this one's a big deal: unlike HTTP/1.1 [2], RTSP requests always contain the absolute URL (scheme, host and port included) instead of just the absolute path ๐
HTTP/1.1 makes servers understand the absolute URL, but clients are supposed to use the Host request header. That's only there for backward-compatibility with HTTP/1.0 servers, and it doesn't apply to RTSP at all ๐
The asterisk "*" in the Request-URI means the request isn't about a particular resource, it's about the server itself. It's only allowed when the method doesn't necessarily apply to a resource. For example:
OPTIONS * RTSP/1.0
7 Response ๐ฆ
[H6] applies, except HTTP-Version gets swapped out for RTSP-Version. RTSP also defines extra status codes and skips some HTTP ones. The valid response codes, and which methods they can go with, are in Table 1 ๐
After a recipient gets and interprets a request message, it responds with an RTSP response message ๐ซถ
Response = Status-Line ; Section 7.1
*( general-header ; Section 5
| response-header ; Section 7.1.2
| entity-header ) ; Section 8.1
CRLF
[ message-body ] ; Section 4.3
7.1 Status-Line ๐ธ
The first line of a Response message is the Status-Line. It's the protocol version, then a numeric status code, then the textual phrase for that code, all separated by SP characters. No CR or LF is allowed except in the final CRLF sequence โจ
Status-Line = RTSP-Version SP Status-Code SP Reason-Phrase CRLF
7.1.1. Status Code and Reason Phrase โจ
Okay, so the Status-Code is a 3-digit integer result code showing the outcome of the server's attempt to understand and satisfy the request. These codes are fully defined in Section 11 ๐ฆ. The Reason-Phrase is a short textual description of the Status-Code. The Status-Code is for automata (machines, basically) and the Reason-Phrase is for the human user ๐. The client is not required to examine or display the Reason-Phrase, so you can ignore it if you want ๐ .
The first digit of the Status-Code tells you the class of the response. The last two digits don't have any categorization role, so they're just details within that class ๐ธ. There are 5 values for the first digit:
1xx: Informational - Request received, continuing process โญ2xx: Success - The action was successfully received, understood, and accepted ๐3xx: Redirection - Further action must be taken in order to complete the request ๐ง4xx: Client Error - The request contains bad syntax or cannot be fulfilled ๐5xx: Server Error - The server failed to fulfill an apparently valid request ๐ญ
The individual numeric status codes defined for RTSP/1.0 are listed below, along with an example set of matching Reason-Phrases. The reason phrases are only recommended, so they can be swapped for local equivalents without affecting the protocol ๐. Also, RTSP borrows most of the HTTP/1.1 [2] status codes and adds its own RTSP-specific ones starting at x50, so they don't clash with newly defined HTTP status codes ๐.
Status-Code = "100" ; Continue
| "200" ; OK
| "201" ; Created
| "250" ; Low on Storage Space
| "300" ; Multiple Choices
| "301" ; Moved Permanently
| "302" ; Moved Temporarily
| "303" ; See Other
| "304" ; Not Modified
| "305" ; Use Proxy
| "400" ; Bad Request
| "401" ; Unauthorized
| "402" ; Payment Required
| "403" ; Forbidden
| "404" ; Not Found
| "405" ; Method Not Allowed
| "406" ; Not Acceptable
| "407" ; Proxy Authentication Required
| "408" ; Request Time-out
| "410" ; Gone
| "411" ; Length Required
| "412" ; Precondition Failed
| "413" ; Request Entity Too Large
| "414" ; Request-URI Too Large
| "415" ; Unsupported Media Type
| "451" ; Parameter Not Understood
| "452" ; Conference Not Found
| "453" ; Not Enough Bandwidth
| "454" ; Session Not Found
| "455" ; Method Not Valid in This State
| "456" ; Header Field Not Valid for Resource
| "457" ; Invalid Range
| "458" ; Parameter Is Read-Only
| "459" ; Aggregate operation not allowed
| "460" ; Only aggregate operation allowed
| "461" ; Unsupported transport
| "462" ; Destination unreachable
| "500" ; Internal Server Error
| "501" ; Not Implemented
| "502" ; Bad Gateway
| "503" ; Service Unavailable
| "504" ; Gateway Time-out
| "505" ; RTSP Version not supported
| "551" ; Option not supported
| extension-code
extension-code = 3DIGIT
Reason-Phrase = *<TEXT, excluding CR, LF>
RTSP status codes are extensible ๐. RTSP applications don't have to understand every registered status code, though it's obviously desirable ๐. But applications MUST understand the class of any status code, based on its first digit. Any unrecognized response should be treated as the x00 status code of that class, with one exception: an unrecognized response MUST NOT be cached ๐ซถ.
Quick example: if a client gets an unrecognized status code of 431, it can safely assume something was wrong with its request and treat the response as if it were a 400. Also, in cases like this, user agents SHOULD show the user the entity returned with the response, since that entity will probably have human-readable info explaining the unusual status ๐ฅ.
Here's the table of status codes and where each one can be used. The "all" column means the code applies to every method, and the other entries name the specific methods ๐.
Table 1: Status codes and their usage with RTSP methods
Code reason methods
100 Continue all
200 OK all
201 Created RECORD
250 Low on Storage Space RECORD
300 Multiple Choices all
301 Moved Permanently all
302 Moved Temporarily all
303 See Other all
305 Use Proxy all
400 Bad Request all
401 Unauthorized all
402 Payment Required all
403 Forbidden all
404 Not Found all
405 Method Not Allowed all
406 Not Acceptable all
407 Proxy Authentication Required all
408 Request Timeout all
410 Gone all
411 Length Required all
412 Precondition Failed DESCRIBE, SETUP
413 Request Entity Too Large all
414 Request-URI Too Long all
415 Unsupported Media Type all
451 Invalid parameter SETUP
452 Illegal Conference Identifier SETUP
453 Not Enough Bandwidth SETUP
454 Session Not Found all
455 Method Not Valid In This State all
456 Header Field Not Valid all
457 Invalid Range PLAY
458 Parameter Is Read-Only SET_PARAMETER
459 Aggregate Operation Not Allowed all
460 Only Aggregate Operation Allowed all
461 Unsupported Transport all
462 Destination Unreachable all
500 Internal Server Error all
501 Not Implemented all
502 Bad Gateway all
503 Service Unavailable all
504 Gateway Timeout all
505 RTSP Version Not Supported all
551 Option not support all
7.1.2. Response Header Fields ๐
Response-header fields are how the request recipient passes extra info about the response that doesn't fit in the Status-Line ๐ . They tell you about the server and about how to get further access to the resource named in the Request-URI โจ.
response-header = Location ; Section 12.25
| Proxy-Authenticate ; Section 12.26
| Public ; Section 12.28
| Retry-After ; Section 12.31
| Server ; Section 12.36
| Vary ; Section 12.42
| WWW-Authenticate ; Section 12.44
Response-header field names can only be extended reliably together with a change in protocol version ๐ง. However, new or experimental header fields MAY be given the semantics of response-header fields, as long as all parties in the communication recognize them as response-header fields ๐ธ. Unrecognized header fields are treated as entity-header fields ๐.
8. Entity ๐
Request and Response messages MAY transfer an entity, as long as the request method or response status code doesn't restrict it ๐. An entity is made of entity-header fields and an entity-body, although some responses will only include the entity-headers ๐.
In this section, "sender" and "recipient" both mean either the client or the server, depending on who's sending and who's receiving the entity ๐ซถ.
8.1. Entity Header Fields ๐
Entity-header fields define optional metainformation about the entity-body or, if there's no body, about the resource identified by the request ๐ฆ.
entity-header = Allow ; Section 12.4
| Content-Base ; Section 12.11
| Content-Encoding ; Section 12.12
| Content-Language ; Section 12.13
| Content-Length ; Section 12.14
| Content-Location ; Section 12.15
| Content-Type ; Section 12.16
| Expires ; Section 12.19
| Last-Modified ; Section 12.24
| extension-header
extension-header = message-header
The extension-header mechanism lets you define extra entity-header fields without changing the protocol. But the recipient can't be assumed to recognize these fields ๐. Unrecognized header fields SHOULD be ignored by the recipient and forwarded by proxies ๐ฅ.
8.2. Entity Body โญ
See [H7.2]
9. Connections ๐ง
RTSP requests can be sent in a few different ways ๐:
- persistent transport connections used for several request-response transactions;
- one connection per request/response transaction;
- connectionless mode.
The type of transport connection is set by the RTSP URI (Section 3.2) ๐. For the scheme "rtsp", a persistent connection is assumed, while the scheme "rtspu" means RTSP requests get sent without setting up a connection ๐.
Unlike HTTP, RTSP lets the media server send requests to the media client ๐ธ. But this only works over persistent connections, because otherwise the media server has no reliable way of reaching the client ๐ญ. This is also the only way requests from media server to client are likely to get through firewalls ๐ฆ.
9.1. Pipelining ๐ซถ
A client that supports persistent connections or connectionless mode MAY "pipeline" its requests, meaning it sends multiple requests without waiting for each response ๐ . A server MUST send its responses to those requests in the same order the requests were received ๐.
9.2 Reliability and Acknowledgements โจ
Okay bestie, so requests get acknowledged by the receiver ๐ unless they're sent to a multicast group ๐ฆ. If there's no ack, the sender may resend the same message after a timeout of one round-trip time (RTT) โฑ๏ธ. The RTT gets estimated the same way TCP does it (RFC 1123) [18], starting from an initial round-trip value of 500 ms. An implementation MAY cache the last RTT measurement as the initial value for future connections ๐ง ๐ธ
If a reliable transport protocol is carrying RTSP, requests MUST NOT be retransmitted ๐ โโ๏ธ. The RTSP app MUST instead rely on the underlying transport for reliability ๐ซถ
Okay, this one is so important ๐ญ If both the underlying reliable transport (like TCP) AND the RTSP app retransmit requests, each packet loss can cause two retransmissions. The receiver usually can't take advantage of the app-layer retransmission, since the transport stack won't deliver it before the first attempt reaches the receiver. And if the loss is caused by congestion, multiple retransmissions at different layers will make the congestion worse ๐ If RTSP is used over a small-RTT LAN, standard procedures for optimizing initial TCP round trip estimates, such as those used in T/TCP (RFC 1644) [22], can be beneficial โจ
The Timestamp header (Section 12.38) is used to avoid the retransmission ambiguity problem [23, p. 301], and it obviates the need for Karn's algorithm. No more Karn's algorithm, iconic ๐
Each request carries a sequence number in the CSeq header (Section 12.17), which gets incremented by one for each distinct request transmitted ๐ข. If a request is repeated because of lack of acknowledgement, the request MUST carry the original sequence number (so the sequence number is not incremented). Don't bump it on a resend, periodt ๐
Systems implementing RTSP MUST support carrying RTSP over TCP and MAY support UDP ๐ The default port for the RTSP server is 554 for both UDP and TCP ๐
A bunch of RTSP packets destined for the same control end point may be packed into a single lower-layer PDU or encapsulated into a TCP stream ๐ฆ RTSP data MAY be interleaved with RTP and RTCP packets ๐ฆ Unlike HTTP, an RTSP message MUST contain a Content-Length header whenever that message contains a payload ๐ Otherwise, an RTSP packet is terminated with an empty line immediately following the last message header. That's the whole vibe โจ
10 Method Definitions ๐
The method token indicates the method to be performed on the resource identified by the Request-URI ๐ The method is case-sensitive. New methods may be defined in the future ๐ฎ Method names may not start with a $ character (decimal 24) and must be a token. The methods are summarized in Table 2, and yes, it's giving organized ๐
method direction object requirement
DESCRIBE C->S P,S recommended
ANNOUNCE C->S, S->C P,S optional
GET_PARAMETER C->S, S->C P,S optional
OPTIONS C->S, S->C P,S required
(S->C: optional)
PAUSE C->S P,S recommended
PLAY C->S P,S required
RECORD C->S P,S optional
REDIRECT S->C P,S optional
SETUP C->S S required
SET_PARAMETER C->S, S->C P,S optional
TEARDOWN C->S P,S required
Table 2: Overview of RTSP methods, their direction, and what
objects (P: presentation, S: stream) they operate on
Notes on Table 2 ๐ง PAUSE is recommended, but not required, because a fully functional server can be built that doesn't support this method (for example, for live feeds) ๐ก If a server does not support a particular method, it MUST return "501 Not Implemented" and a client SHOULD not try this method again for this server. Shooketh ๐ญ
10.1 OPTIONS ๐
The behavior is equivalent to that described in [H9.2] ๐ค An OPTIONS request may be issued at any time (for example, if the client is about to try a nonstandard request) โจ It does not influence server state, so it's totally chill ๐ซง
Example:
C->S: OPTIONS * RTSP/1.0
CSeq: 1
Require: implicit-play
Proxy-Require: gzipped-messages
S->C: RTSP/1.0 200 OK
CSeq: 1
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE
Note that these are necessarily fictional features (one would hope that we would not purposefully overlook a truly useful feature just so that we could have a strong example in this section) ๐ Iykyk ๐คญ
10.2 DESCRIBE ๐
The DESCRIBE method retrieves the description of a presentation or media object identified by the request URL from a server ๐ฅ It may use the Accept header to specify the description formats that the client understands ๐๏ธ The server responds with a description of the requested resource. The DESCRIBE reply-response pair constitutes the media initialization phase of RTSP ๐
Example:
C->S: DESCRIBE rtsp://server.example.com/fizzle/foo RTSP/1.0
CSeq: 312
Accept: application/sdp, application/rtsl, application/mheg
S->C: RTSP/1.0 200 OK
CSeq: 312
Date: 23 Jan 1997 15:35:06 GMT
Content-Type: application/sdp
Content-Length: 376
v=0
o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4
s=SDP Seminar
i=A Seminar on the session description protocol
u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps
e=mjh@isi.edu (Mark Handley)
c=IN IP4 224.2.17.12/127
t=2873397496 2873404696
a=recvonly
m=audio 3456 RTP/AVP 0
m=video 2232 RTP/AVP 31
m=whiteboard 32416 UDP WB
a=orient:portrait
The DESCRIBE response MUST contain all media initialization information for the resource(s) that it describes ๐ฏ If a media client gets a presentation description from a source other than DESCRIBE, and that description contains a complete set of media initialization parameters, the client SHOULD use those parameters and not then request a description for the same media via RTSP ๐
Additionally, servers SHOULD NOT use the DESCRIBE response as a means of media indirection ๐ซ
Okay, clear ground rules are needed so clients have an unambiguous way of knowing when to request media initialization info via DESCRIBE, and when not to ๐ง By forcing a DESCRIBE response to contain all media initialization for the set of streams it describes, and discouraging DESCRIBE for media indirection, we avoid the looping problems that other approaches might cause ๐ Media initialization is a requirement for any RTSP-based system, but the RTSP specification does not dictate that it has to be done via the DESCRIBE method ๐คทโโ๏ธ There are three ways an RTSP client may receive initialization information: - via RTSP's DESCRIBE method; - via some other protocol (HTTP, email attachment, etc.); - via the command line or standard input (thus working as a browser helper application launched with an SDP file or other media initialization format). In the interest of practical interoperability, it is highly recommended that minimal servers support the DESCRIBE method ๐ and highly recommended that minimal clients support the ability to act as a "helper application" that accepts a media initialization file from standard input, command line, and/or other means that are appropriate to the operating environment of the client ๐ง
10.3 ANNOUNCE ๐ฃ
The ANNOUNCE method serves two purposes ๐ฏโโ๏ธ
When sent from client to server, ANNOUNCE posts the description of a presentation or media object identified by the request URL to a server ๐ค When sent from server to client, ANNOUNCE updates the session description in real-time โฐ
If a new media stream gets added to a presentation (for example, during a live presentation), the whole presentation description should be sent again, rather than just the additional components, so that components can be deleted ๐๏ธ Main character energy for the whole description ๐ฌ
Example:
C->S: ANNOUNCE rtsp://server.example.com/fizzle/foo RTSP/1.0
CSeq: 312
Date: 23 Jan 1997 15:35:06 GMT
Session: 47112344
Content-Type: application/sdp
Content-Length: 332
v=0
o=mhandley 2890844526 2890845468 IN IP4 126.16.64.4
s=SDP Seminar
i=A Seminar on the session description protocol
u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps
e=mjh@isi.edu (Mark Handley)
c=IN IP4 224.2.17.12/127
t=2873397496 2873404696
a=recvonly
m=audio 3456 RTP/AVP 0
m=video 2232 RTP/AVP 31
S->C: RTSP/1.0 200 OK
CSeq: 312
10.4 SETUP ๐ ๏ธ
The SETUP request for a URI specifies the transport mechanism to be used for the streamed media ๐ A client can issue a SETUP request for a stream that's already playing to change transport parameters, which a server MAY allow. If it does not allow this, it MUST respond with error "455 Method Not Valid In This State" ๐ For the benefit of any intervening firewalls, a client must indicate the transport parameters even if it has no influence over them, for example, where the server advertises a fixed multicast address ๐งฑ
Since SETUP includes all the transport initialization information, firewalls and other intermediate network devices (which need this information) are spared the more arduous task of parsing the DESCRIBE response, which has been reserved for media initialization ๐ฅน
The Transport header specifies the transport parameters acceptable to the client for data transmission. The response will contain the transport parameters the server selected ๐ฏ
C->S: SETUP rtsp://example.com/foo/bar/baz.rm RTSP/1.0
CSeq: 302
Transport: RTP/AVP;unicast;client_port=4588-4589
S->C: RTSP/1.0 200 OK
CSeq: 302
Date: 23 Jan 1997 15:35:06 GMT
Session: 47112344
Transport: RTP/AVP;unicast;
client_port=4588-4589;server_port=6256-6257
The server generates session identifiers in response to SETUP requests ๐ชช If a SETUP request to a server includes a session identifier, the server MUST bundle this setup request into the existing session, or return error "459 Aggregate Operation Not Allowed" (see Section 11.3.10). Bundle it or bounce it, no in-between ๐ โจ
10.5 PLAY ๐ฌ
okay bestie, PLAY is literally the "start the stream" moment ๐ฌโจ It tells the server to start sending data through whatever mechanism was set up in SETUP. ngl, the client MUST NOT issue a PLAY request until every outstanding SETUP request has been acknowledged as successful. no skipping setup, babe ๐
A PLAY request sets normal play time to the start of the range you asked for, then keeps delivering stream data until it reaches the end of that range ๐ฆ. PLAY requests can be pipelined (aka queued) ๐, and the server MUST queue them and run them in order. So if a new PLAY shows up while an old one is still going, it just waits its turn until the first one is finished ๐
This allows precise editing. ๐
The example below shows how it works. No matter how closely together the two PLAY requests arrive, the server plays seconds 10 through 15, then immediately after that seconds 20 to 25, and finally seconds 30 through the end ๐
C->S: PLAY rtsp://audio.example.com/audio RTSP/1.0
CSeq: 835
Session: 12345678
Range: npt=10-15
C->S: PLAY rtsp://audio.example.com/audio RTSP/1.0
CSeq: 836
Session: 12345678
Range: npt=20-25
C->S: PLAY rtsp://audio.example.com/audio RTSP/1.0
CSeq: 837
Session: 12345678
Range: npt=30-
Check the PAUSE section for more examples, because it has a bunch ๐
A PLAY request without a Range header is totally legal ๐ธ. It starts playing the stream from the beginning, unless the stream was paused. If it was paused with PAUSE, delivery picks back up right at the pause point. If the stream is already playing, the request does nothing else, and the client can use it to check whether the server is still alive ๐ซถ
The Range header can also include a time parameter, which is a UTC time for playback to start โฐ. If the message shows up after that time, playback starts right away. This is handy for lining up streams that come from different sources ๐ง
For an on-demand stream, the server replies with the actual range it's going to play back ๐๏ธ. That can be different from what you asked for if the media source needs the range lined up to valid frame boundaries. If the request has no range, the reply gives back the current position. The unit of the range in the reply is the same as the unit in the request.
After the desired range finishes, the presentation automatically pauses, just like someone sent a PAUSE request ๐
This next one plays the whole presentation from SMPTE time code 0:10:20 until the end of the clip, and playback is supposed to start at 15:36 on 23 Jan 1997 โจ
C->S: PLAY rtsp://audio.example.com/twister.en RTSP/1.0
CSeq: 833
Session: 12345678
Range: smpte=0:10:20-;time=19970123T153600Z
S->C: RTSP/1.0 200 OK
CSeq: 833
Date: 23 Jan 1997 15:35:06 GMT
Range: smpte=0:10:22-;time=19970123T153600Z
If you're playing back a recording of a live presentation, clock units might be the move ๐ฐ๏ธ
C->S: PLAY rtsp://audio.example.com/meeting.en RTSP/1.0
CSeq: 835
Session: 12345678
Range: clock=19961108T142300Z-19961108T143520Z
S->C: RTSP/1.0 200 OK
CSeq: 835
Date: 23 Jan 1997 15:35:06 GMT
A media server that only supports playback MUST support the npt format and MAY support the clock and smpte formats ๐
10.6 PAUSE โธ๏ธ
PAUSE is the "hold up, wait" button ๐ โโ๏ธ It temporarily interrupts (halts) stream delivery. If the request URL names one stream, only playback or recording of that stream gets halted. For audio, that's basically muting ๐. If the URL names a presentation or a group of streams, delivery stops for every stream that's currently active in that presentation or group. After playback or recording resumes, the tracks MUST stay in sync ๐ถ. Server resources are kept around, though servers MAY close the session and free those resources once it's been paused for the duration given by the timeout parameter of the Session header in the SETUP message โณ
Here's a basic example ๐
C->S: PAUSE rtsp://example.com/fizzle/foo RTSP/1.0
CSeq: 834
Session: 12345678
S->C: RTSP/1.0 200 OK
CSeq: 834
Date: 23 Jan 1997 15:35:06 GMT
The PAUSE request can include a Range header that says when the stream or presentation should halt. This spot is called the "pause point" ๐. The header has to contain exactly one value, not a time range. The normal play time for the stream gets set to the pause point. The pause request takes effect the first time the server reaches the time point given in any of the PLAY requests that are still pending. If the Range header names a time outside every pending PLAY request, the server returns the error "457 Invalid Range" ๐ซ. If a media unit (like an audio or video frame) starts presenting at exactly the pause point, it doesn't get played or recorded. And if the Range header is missing, delivery stops immediately when the message arrives, and the pause point becomes the current normal play time ๐
A PAUSE request throws out all the queued PLAY requests ๐๏ธ. But the pause point in the media stream MUST still be maintained. A later PLAY request without a Range header picks up from the pause point ๐ฌ
Let's do some examples, because this is where it gets fun ๐ค Say the server has pending play requests for ranges 10 to 15 and 20 to 29, and then it gets a pause request for NPT 21. It starts playing the second range and stops at NPT 21. If the pause request is for NPT 12 and the server is playing NPT 13 for the first play request, it stops right away. If the pause request is for NPT 16, the server stops after finishing the first play request and throws away the second one ๐
Another one: the server has received requests to play ranges 10 to 15 and then 13 to 20, which overlap ๐ซ . A PAUSE for NPT=14 takes effect while the server is playing the first range, and the second PLAY request is basically ignored. That assumes the PAUSE shows up before the server has started the second, overlapping range. No matter when the PAUSE arrives, it sets the NPT to 14 ๐
If the server has already sent data past the time in the Range header, a PLAY still resumes at that point in time, because the client is assumed to have thrown away anything after that point. This keeps pause/play cycling smooth, with no gaps ๐
10.7 TEARDOWN ๐งน
TEARDOWN stops stream delivery for the URI you give it and frees up the resources tied to it ๐ . If that URI is the presentation URI for the presentation, the RTSP session identifier tied to the session stops being valid. Unless every transport parameter is defined by the session description, you have to send a SETUP request before the session can be played again ๐
C->S: TEARDOWN rtsp://example.com/fizzle/foo RTSP/1.0
CSeq: 892
Session: 12345678
S->C: RTSP/1.0 200 OK
CSeq: 892
10.8 GET_PARAMETER ๐
GET_PARAMETER asks for the value of a parameter of a presentation or stream named in the URI ๐. What's inside the reply and response is up to the implementation. GET_PARAMETER with no entity body can be used to check whether the client or server is alive (a "ping") ๐
S->C: GET_PARAMETER rtsp://example.com/fizzle/foo RTSP/1.0
CSeq: 431
Content-Type: text/parameters
Session: 12345678
Content-Length: 15
packets_received
jitter
C->S: RTSP/1.0 200 OK
CSeq: 431
Content-Length: 46
Content-Type: text/parameters
packets_received: 10
jitter: 0.3838
The "text/parameters" section is only an example type for parameter. This method is intentionally loosely defined, with the intention that the reply content and response content will be defined after further experimentation. ๐งช
10.9 SET_PARAMETER โ๏ธ
This method asks to set the value of a parameter for a presentation or stream named by the URI ๐๏ธ
A request SHOULD only contain a single parameter, so the client can tell why a particular request failed ๐ต๏ธโโ๏ธ If a request has several parameters, the server MUST only act on it if every one of those parameters can be set successfully. A server MUST allow a parameter to be set repeatedly to the same value, but it MAY disallow changing parameter values ๐
Note: transport parameters for the media stream MUST only be set with the SETUP command ๐จ
Restricting transport parameter setting to SETUP is for the benefit of firewalls ๐งฑ
The parameters are split up finely so there can be more meaningful error messages ๐ฌ That said, it can make sense to let you set several parameters together if you want an atomic setting. Picture device control, where the client doesn't want the camera to pan unless it can also tilt to the right angle at the same time ๐ท
Example:
C->S: SET_PARAMETER rtsp://example.com/fizzle/foo RTSP/1.0
CSeq: 421
Content-length: 20
Content-type: text/parameters
barparam: barstuff
S->C: RTSP/1.0 451 Invalid Parameter
CSeq: 421
Content-length: 10
Content-type: text/parameters
barparam
The "text/parameters" section is only an example type for parameter. This method is intentionally loosely defined, with the intention that the reply content and response content will be defined after further experimentation. ๐งช
10.10 REDIRECT ๐
A REDIRECT request tells the client it has to connect to a different server location ๐ฆ. It contains the mandatory Location header, which says the client should send its requests to that URL. It can also have a Range parameter, which says when the redirection takes effect. If the client wants to keep sending or receiving media for this URI, it MUST send a TEARDOWN request for the current session and a SETUP for the new session at the designated host ๐
Here's a redirect that sends traffic for this URI to a new server at the given play time ๐
S->C: REDIRECT rtsp://example.com/fizzle/foo RTSP/1.0
CSeq: 732
Location: rtsp://bigserver.com:8001
Range: clock=19960213T143205Z-
10.11 RECORD ๐ด
RECORD starts recording a range of media data according to the presentation description ๐๏ธ The timestamp reflects the start and end time (UTC). If no time range is given, use the start or end time from the presentation description. If the session has already started, recording begins right away โบ๏ธ
The server decides whether to store the recorded data under the request-URI or under another URI. If the server doesn't use the request-URI, the response SHOULD be 201 (Created) and contain an entity that describes the status of the request and refers to the new resource, plus a Location header ๐
A media server that supports recording live presentations MUST support the clock range format, because the smpte format doesn't make sense there ๐ฐ๏ธ
In this example, the media server was previously invited to the conference shown below ๐ค
C->S: RECORD rtsp://example.com/meeting/audio.en RTSP/1.0
CSeq: 954
Session: 12345678
Conference: 128.16.64.19/32492374
10.12. Embedded (Interleaved) Binary Data โจ
okay so sometimes a firewall (or some other annoying situation ๐) forces the server to mix RTSP methods and stream data together in one connection. bestie, avoid this unless you literally have no other choice, because it makes life harder for the client AND the server and adds overhead ๐. interleaved binary data SHOULD only be used if RTSP is carried over TCP ๐ซถ
here's the vibe for how stream data gets wrapped up: each chunk starts with an ASCII dollar sign (24 hexadecimal) ๐
, then a one-byte channel identifier ๐, then the length of the encapsulated binary data as a binary, two-byte integer in network byte order ๐ข. the stream data comes right after that with no CRLF, but it DOES include the upper-layer protocol headers ๐ง. every $ block holds exactly one upper-layer protocol data unit, like one RTP packet. one packet per block, no drama ๐
the channel identifier is set up in the Transport header with the interleaved parameter (Section 12.39) โจ
when the transport choice is RTP, the server also interleaves RTCP messages over the TCP connection ๐ฆ. by default, RTCP packets go out on the first available channel higher than the RTP channel, and the client MAY explicitly ask for RTCP packets on another channel. to do that, you list two channels in the interleaved parameter of the Transport header (Section 12.39) ๐ธ
RTCP is needed for synchronization when two or more streams are interleaved like this. it also gives you a cute way to tunnel RTP/RTCP packets through the TCP control connection when the network setup requires it, and then move them onto UDP whenever that's possible ๐ซถ
here's a full example conversation so you can see the flow ๐
C->S: SETUP rtsp://foo.com/bar.file RTSP/1.0
CSeq: 2
Transport: RTP/AVP/TCP;interleaved=0-1
S->C: RTSP/1.0 200 OK
CSeq: 2
Date: 05 Jun 1997 18:57:18 GMT
Transport: RTP/AVP/TCP;interleaved=0-1
Session: 12345678
C->S: PLAY rtsp://foo.com/bar.file RTSP/1.0
CSeq: 3
Session: 12345678
S->C: RTSP/1.0 200 OK
CSeq: 3
Session: 12345678
Date: 05 Jun 1997 18:59:15 GMT
RTP-Info: url=rtsp://foo.com/bar.file;
seq=232433;rtptime=972948234
S->C: $\000{2 byte length}{"length" bytes data, w/RTP header}
S->C: $\000{2 byte length}{"length" bytes data, w/RTP header}
S->C: $\001{2 byte length}{"length" bytes RTCP packet}
11. Status Code Definitions ๐
okay so wherever it makes sense, we just borrow the HTTP status [H10] codes ๐ซถ no need to repeat the ones that mean the same thing ๐ check Table 1 to see which status codes each request can return โจ
11.1. Success 2xx ๐
11.1.1. 250 Low on Storage Space ๐พ
the server sends this warning after getting a RECORD request it might not be able to fully finish, because storage space is running low ๐ผ. if it can, the server should use the Range header to show what time period it can still record ๐. other processes on the server might be eating up storage at the same time, so the client should treat this as just an estimate ๐คทโโ๏ธ
11.2. Redirection 3xx ๐ฆ
See [H10.3].
redirection in RTSP can help with load balancing, or send stream requests to a server that's closer to the client in network terms ๐ง figuring out who's topologically close is out of scope for this spec, so that's a whole other mystery ๐
11.3. Client Error 4xx ๐
11.3.1. 405 Method Not Allowed ๐ซ
the method in the request isn't allowed for the resource the request URI points to ๐ โโ๏ธ. the response MUST include an Allow header listing the valid methods for that resource ๐. this code also applies if the request tries a method that wasn't set up during SETUP ๐. like, if someone sends a RECORD request even though the mode parameter in the Transport header only said PLAY, that's a 405 moment ๐ญ
11.3.2. 451 Parameter Not Understood ๐ค
the recipient doesn't support one or more parameters in the request ๐
11.3.3. 452 Conference Not Found ๐
the conference named in a Conference header field isn't known to the media server ๐ป
11.3.4. 453 Not Enough Bandwidth ๐
the request got refused because there wasn't enough bandwidth ๐. for example, this could happen because a resource reservation failed ๐ซ
11.3.5. 454 Session Not Found ๐
the RTSP session identifier in the Session header is missing, invalid, or has timed out โฐ
11.3.6. 455 Method Not Valid in This State ๐
the client or server can't handle this request in its current state ๐ตโ๐ซ. the response SHOULD include an Allow header so error recovery is easier ๐ซถ
11.3.7. 456 Header Field Not Valid for Resource ๐
the server couldn't act on a required request header ๐. for example, if PLAY has the Range header field but the stream doesn't allow seeking, you get this one ๐ฌ
11.3.8. 457 Invalid Range ๐
the Range value is out of bounds, like going past the end of the presentation ๐
11.3.9. 458 Parameter Is Read-Only ๐
the parameter SET_PARAMETER is trying to set can be read, but it can't be modified ๐
11.3.10. 459 Aggregate Operation Not Allowed ๐งบ
the method can't be applied to this URL because it's an aggregate (presentation) URL ๐ซ. it CAN be applied to a stream URL though โจ
11.3.11. 460 Only Aggregate Operation Allowed ๐
this method can't be applied to this URL because it's NOT an aggregate (presentation) URL ๐ โโ๏ธ. the method can be applied on the presentation URL instead ๐ธ
11.3.12. 461 Unsupported Transport ๐
the Transport field didn't have a supported transport specification ๐ค
11.3.13. 462 Destination Unreachable ๐
the data transmission channel couldn't be set up because the client address couldn't be reached ๐. this will most likely happen if the client puts an invalid Destination parameter in the Transport field ๐
11.3.14. 551 Option not supported ๐ง
an option in the Require or Proxy-Require fields wasn't supported ๐ฌ. the Unsupported header should come back and say which option it doesn't support ๐ซถ
12. Header Field Definitions ๐
okay so HTTP/1.1 [2] or other non-standard header fields that aren't listed here don't have a well-defined meaning right now, and the recipient SHOULD ignore them ๐
Table 3 is your cheat sheet for the RTSP header fields โจ. type "g" means general headers that show up in both requests and responses, type "R" means request headers, type "r" means response headers, and type "e" means entity header fields ๐ฆ. fields marked "req." in the support column MUST be implemented by the recipient for a particular method, and fields marked "opt." are optional ๐. heads up though, not every "req." field will be sent in every request of that type ๐. "req." only means that the client (for response headers) and the server (for request headers) MUST implement those fields ๐ . the last column says which method the header is meaningful for, and "entity" means every method that returns a message body ๐. in this spec, DESCRIBE and GET_PARAMETER are in that entity club ๐
Header type support methods
Accept R opt. entity
Accept-Encoding R opt. entity
Accept-Language R opt. all
Allow r opt. all
Authorization R opt. all
Bandwidth R opt. all
Blocksize R opt. all but OPTIONS, TEARDOWN
Cache-Control g opt. SETUP
Conference R opt. SETUP
Connection g req. all
Content-Base e opt. entity
Content-Encoding e req. SET_PARAMETER
Content-Encoding e req. DESCRIBE, ANNOUNCE
Content-Language e req. DESCRIBE, ANNOUNCE
Content-Length e req. SET_PARAMETER, ANNOUNCE
Content-Length e req. entity
Content-Location e opt. entity
Content-Type e req. SET_PARAMETER, ANNOUNCE
Content-Type r req. entity
CSeq g req. all
Date g opt. all
Expires e opt. DESCRIBE, ANNOUNCE
From R opt. all
If-Modified-Since R opt. DESCRIBE, SETUP
Last-Modified e opt. entity
Proxy-Authenticate
Proxy-Require R req. all
Public r opt. all
Range R opt. PLAY, PAUSE, RECORD
Range r opt. PLAY, PAUSE, RECORD
Referer R opt. all
Require R req. all
Retry-After r opt. all
RTP-Info r req. PLAY
Scale Rr opt. PLAY, RECORD
Session Rr req. all but SETUP, OPTIONS
Server r opt. all
Speed Rr opt. PLAY
Transport Rr req. SETUP
Unsupported r req. all
User-Agent R opt. all
Via g opt. all
WWW-Authenticate r opt. all
Overview of RTSP header fields ๐
12.1. Accept ๐ง
the Accept request-header field lets you say which presentation description content types are acceptable in the response ๐
the "level" parameter for presentation descriptions is properly defined as part of the MIME type registration, not here ๐
See [H14.1] for syntax.
example of use ๐ธ
Accept: application/rtsl, application/sdp;level=2
12.2. Accept-Encoding ๐ฆ
See [H14.3]
12.3. Accept-Language ๐
See [H14.4]. the language you specify applies to the presentation description and any reason phrases, NOT the media content ๐ฌ
12.4. Allow ๐ฃ
the Allow response header field lists the methods the resource identified by the request-URI supports โจ. its whole job is to clearly tell the recipient which methods are valid for that resource ๐ซถ. an Allow header field must be present in a 405 (Method not allowed) response ๐ซ
example of use ๐
Allow: SETUP, PLAY, RECORD, SET_PARAMETER
12.5. Authorization ๐
See [H14.8]
12.6. Bandwidth ๐ถ
the Bandwidth request header field describes the estimated bandwidth available to the client ๐ซ. it's a positive integer measured in bits per second ๐ข. the client's bandwidth can change during an RTSP session, like when a modem retrains ๐
Bandwidth = "Bandwidth" ":" 1*DIGIT
example ๐ฆ
Bandwidth: 4000
12.7. Blocksize ๐งฉ
this request header field is how the client asks the media server for a particular media packet size ๐. the size doesn't include lower-layer headers like IP, UDP, or RTP ๐. the server is free to use a smaller blocksize than the one requested โจ. the server MAY truncate this packet size to the closest multiple of the minimum, media-specific block size, or swap in the media-specific size if it needs to ๐. the block size MUST be a positive decimal number, measured in octets ๐ข. the server only returns an error (416) if the value is syntactically invalid ๐จ
12.8 Cache-Control โจ
okay so the Cache-Control general header field is how you drop directives that every caching mechanism along the request/response chain MUST obey ๐ ๐
proxies and gateways have to pass cache directives through, even if the directive doesn't matter to them, because it might apply to everyone downstream ๐ซถ you also can't aim a cache-directive at one specific cache, so it's all or nothing ๐ฆ
Cache-Control should only be specified in a SETUP request and its response. ngl this part is so important ๐ญ Cache-Control doesn't control caching the way it does in HTTP. it controls the stream identified by the SETUP request ๐ธ and responses to RTSP requests are not cacheable, except for responses to DESCRIBE ๐
Cache-Control = "Cache-Control" ":" 1#cache-directive
cache-directive = cache-request-directive
| cache-response-directive
cache-request-directive = "no-cache"
| "max-stale"
| "min-fresh"
| "only-if-cached"
| cache-extension
cache-response-directive = "public"
| "private"
| "no-cache"
| "no-transform"
| "must-revalidate"
| "proxy-revalidate"
| "max-age" "=" delta-seconds
| cache-extension
cache-extension = token [ "=" ( token | quoted-string ) ]
no-cache
this one is the big lockdown ๐ the media stream MUST NOT be cached anywhere ๐ โโ๏ธ even caches that have been set up to hand out stale responses have to back off, so an origin server can stop caching no matter what ๐
public
the media stream is cacheable by any cache ๐
private
this stream is meant for one single user, so a shared cache MUST NOT cache it ๐ a private (non-shared) cache is totally allowed to hold onto it โจ
no-transform
okay this one is lowkey so deep ๐ฅน a proxy might want to convert a stream's media type, like switching video formats to save cache space or cut traffic on a slow link ๐ but that can cause serious operational problems for certain apps. medical imaging, scientific data analysis, and anything using end-to-end authentication all need the stream to be bit-for-bit identical to the original entity-body ๐ฌ
so if a response includes no-transform, an intermediate cache or proxy MUST NOT change the encoding of the stream ๐ and unlike HTTP, RTSP doesn't allow partial transformation here, like translating into a different language ๐
only-if-cached
sometimes the network is basically dead ๐ so a client might want the cache to return only the streams it already has, and not go to the origin server at all ๐ง to ask for that, the client includes only-if-cached in a request. when a cache gets it, it SHOULD either reply with a cached stream that matches the other constraints of the request, or reply with a 504 (Gateway Timeout) status โจ but if a group of caches runs as one unified system with good internal connectivity, the request MAY be forwarded within that group ๐ซง
max-stale
the client is down to accept a stream that's past its expiration time ๐ซ if max-stale has a value, the client will accept a response that's expired by no more than that many seconds. if there's no value, the client will accept a stale response of any age, no judgment ๐
min-fresh
the client will take a stream whose freshness lifetime is at least its current age plus the given number of seconds ๐ญ basically it wants something that will still be fresh for at least that long ๐ท
must-revalidate
when a cache receives a SETUP response with must-revalidate, that cache MUST NOT use the entry after it goes stale to answer a later request without revalidating it with the origin server first ๐ซ so every time the entry is stale based only on the origin server's Expires, the cache has to do an end-to-end revalidation. no skipping ๐ค)
12.9 Conference ๐
this request header field makes a logical connection between a pre-established conference and an RTSP stream โจ the conference-id must not be changed for the same RTSP session ๐
Conference = "Conference" ":" conference-id Example:
example:
Conference: 199702170042.SAA08642@obiwan.arl.wustl.edu%20Starr
if the conference-id isn't valid, you get a response code of 452 (452 Conference Not Found) ๐
12.10 Connection ๐
See [H14.10]
12.11 Content-Base ๐งธ
See [H14.11]
12.12 Content-Encoding ๐ฌ
See [H14.12]
12.13 Content-Language ๐
See [H14.13]
12.14 Content-Length ๐
this field tells you the length of the method's content, which is everything after the double CRLF that follows the last header ๐ฆ unlike HTTP, it MUST be included in every message that carries content past the header portion ๐ซถ if it's missing, the default value is zero. it gets interpreted according to [H14.14] ๐
12.15 Content-Location ๐
See [H14.15]
12.16 Content-Type ๐ธ
See [H14.18]. fr fr the content types that actually fit RTSP are probably going to be limited to presentation descriptions and parameter-value types in practice ๐
12.17 CSeq ๐ข
the CSeq field is the sequence number for an RTSP request-response pair, and it MUST be present in all requests and responses ๐ฅ every RTSP request with a given sequence number gets a matching response with that same number โจ and any retransmitted request has to carry the same sequence number as the original, so you don't increment it for retransmissions of the same request ๐ง
12.18 Date ๐
See [H14.19].
12.19 Expires โณ
the Expires entity-header field gives a date and time after which the description or media-stream should be considered stale ๐ฐ๏ธ what it means depends on the method:
DESCRIBE response
the Expires header tells you the date and time after which the description should be considered stale ๐
a stale cache entry normally can't be returned by a cache (a proxy cache or a user agent cache) unless it's validated first with the origin server, or with an intermediate cache that has a fresh copy of the entity ๐ โโ๏ธ check section 13 for more on the expiration model ๐
having an Expires field doesn't mean the original resource will change or disappear at, before, or after that time ๐
the format is an absolute date and time defined by HTTP-date in [H3.3], and it MUST be in RFC1123-date format ๐
Expires = "Expires" ":" HTTP-date
example:
Expires: Thu, 01 Dec 1994 16:00:00 GMT
RTSP/1.0 clients and caches MUST treat any other invalid date formats, especially the value "0", as already in the past (already expired) ๐
to mark a response as "already expired," an origin server should use an Expires date equal to the Date header value ๐ซ to mark a response as "never expires," an origin server should use an Expires date about one year from when the response is sent ๐ RTSP/1.0 servers should not send Expires dates more than one year in the future ๐ โโ๏ธ
if a media stream would normally be non-cacheable by default, but it has an Expires header with a future date, then it's cacheable, unless a Cache-Control header field (Section 12.8) says otherwise ๐ฆ
12.20 From ๐
See [H14.22].
12.21 Host ๐
this HTTP request header field isn't needed for RTSP ๐ซง if it does get sent, it should be silently ignored ๐
12.22 If-Match ๐
See [H14.25].
this field is super useful for keeping the presentation description intact, whether it was fetched outside RTSP (like over HTTP) or the server is guaranteeing the description stays the same between the DESCRIBE message and the SETUP message ๐
the identifier is opaque, so it isn't tied to any specific session description language ๐ง โจ
12.23 If-Modified-Since โฐ
the If-Modified-Since request-header field makes DESCRIBE and SETUP conditional ๐ฏ if the requested variant hasn't been modified since the time in this field, the server won't return a description (DESCRIBE) or set up a stream (SETUP). instead you get a 304 (not modified) response with no message-body ๐ซถ
If-Modified-Since = "If-Modified-Since" ":" HTTP-date
example:
If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
12.24 Last-Modified ๐๏ธ
the Last-Modified entity-header field shows the date and time the origin server believes the presentation description or media stream was last modified ๐ see [H14.29]. for DESCRIBE or ANNOUNCE, it's the last modification of the description, and for SETUP it's the last modification of the media stream ๐ฌ
12.25 Location ๐
See [H14.30].
12.26 Proxy-Authenticate ๐
See [H14.33].
12.27 Proxy-Require ๐ง
the Proxy-Require header is for proxy-sensitive features that MUST be supported by the proxy ๐ซก if the proxy doesn't support any Proxy-Require features, it MUST negatively acknowledge them to the client ๐ โโ๏ธ servers should treat this field the same way as the Require field ๐
see Section 12.32 for more on how this message works, plus a usage example ๐
12.28 Public ๐
See [H14.35].
12.29 Range ๐
okay so the Range header specifies a range of time ๐ฐ๏ธ and you can express it in a few different units. this spec defines the smpte (Section 3.5), npt (Section 3.6), and clock (Section 3.7) range units. byte ranges [H14.36.1] are NOT the vibe in RTSP, so they MUST NOT be used ๐
โโ๏ธ. the header can also carry a UTC time parameter that says when the operation takes effect. servers that support the Range header MUST understand the NPT range format and SHOULD understand the SMPTE range format ๐
. the Range response header tells you what range is actually being played or recorded โจ. if the Range header uses a time format the recipient doesn't understand, the recipient should return "501 Not Implemented" ๐ญ.
ranges are half-open intervals ๐ฆ: they include the lower point but exclude the upper point. so a range of a-b starts exactly at time a and stops just before b. only the start time of a media unit (like a video or audio frame) matters ๐ฌ. picture this: video frames are generated every 40 ms. a range of 10.0-10.1 would include a frame starting at 10.0 or later, AND a frame starting at 10.08, even though that frame keeps going past the interval ๐. a range of 10.0-10.08, though, excludes the frame at 10.08. no cap, that's so precise ๐ค.
Range = "Range" ":" 1\#ranges-specifier
[ ";" "time" "=" utc-time ]
ranges-specifier = npt-range | utc-range | smpte-range
Example:
Range: clock=19960213T143205Z-;time=19970123T143720Z
the notation is basically a copy of the HTTP/1.1 [2] byte-range header vibes ๐ธ. it lets clients grab an excerpt of the media object, play from a given point to the end, or play from the current location up to a given point ๐๏ธ. playback can be scheduled for any time in the future, although a server may refuse to hold onto its resources during long idle periods ๐ด.
12.30 Referer ๐ง
see [H14.37]. the URL here points at the presentation description, which is usually fetched over HTTP ๐.
12.31 Retry-After ๐
see [H14.38].
12.32 Require ๐ฅ
the Require header is how clients ask the server about options it might or might not support ๐ค. the server MUST respond to this header by using the Unsupported header to negatively acknowledge any options that are NOT supported ๐
โโ๏ธ.
this is all about keeping the client-server chat moving with zero delay when both sides understand every option โก. they only slow down if something isn't understood. for a well-matched pair, things go fast and you skip a round-trip that negotiation would normally need ๐โโ๏ธ. it also clears up state ambiguity when a client needs features the server doesn't know about ๐ซถ.
Require = "Require" ":" 1#option-tag
Example:
C->S: SETUP rtsp://server.com/foo/bar/baz.rm RTSP/1.0
CSeq: 302
Require: funky-feature
Funky-Parameter: funkystuff
S->C: RTSP/1.0 551 Option not supported
CSeq: 302
Unsupported: funky-feature
C->S: SETUP rtsp://server.com/foo/bar/baz.rm RTSP/1.0
CSeq: 303
S->C: RTSP/1.0 200 OK
CSeq: 303
in this example, "funky-feature" is the feature tag that tells the client the fictional Funky-Parameter field is required ๐งธ. the link between "funky-feature" and Funky-Parameter isn't sent over RTSP, because that relationship is a fixed property of "funky-feature" and shouldn't be repeated in every exchange ๐.
proxies and other intermediary devices SHOULD ignore features in this field that they don't understand ๐ซ . if an extension needs intermediate devices to support it, the extension should be tagged in the Proxy-Require field instead (see Section 12.27) ๐.
12.33 RTP-Info ๐
this field sets RTP-specific parameters in the PLAY response ๐ถ. it has three parameters:
url: the stream URL that the following RTP parameters belong to ๐.seq: the sequence number of the first packet in the stream. this helps clients handle packets gracefully when seeking ๐. clients use it to tell packets from before the seek apart from packets from after the seek โ๏ธ.rtptime: the RTP timestamp that matches the time value in theRangeresponse header ๐. (heads up: for aggregate control, a particular stream might not actually produce a packet at theRangetime value returned or implied. so there's no guarantee that the packet with the sequence number fromseqhas the timestamp fromrtptime๐ฌ.) clients use this value to work out the mapping from RTP time to NPT ๐งฎ.
RTP timestamps can be mapped to NTP (wall clock) timestamps through RTCP โฐ. but that info isn't enough to build a mapping from RTP timestamps to NPT ๐. so the mapping goes on the RTSP control channel, which makes sure it's available right when it's needed (right at startup or after a seek) and that it gets delivered reliably ๐ฌ.
to compensate for drift in long, uninterrupted presentations, RTSP clients should also map NPT to NTP ๐ฐ๏ธ. they use the initial RTCP sender reports to make that mapping, then check drift against it using later reports ๐.
Syntax:
RTP-Info = "RTP-Info" ":" 1#stream-url 1*parameter
stream-url = "url" "=" url
parameter = ";" "seq" "=" 1*DIGIT
| ";" "rtptime" "=" 1*DIGIT
Example:
RTP-Info: url=rtsp://foo.com/bar.avi/streamid=0;seq=45102,
url=rtsp://foo.com/bar.avi/streamid=1;seq=30211
12.34 Scale ๐
a scale value of 1 means normal play or record at the normal forward viewing rate โถ๏ธ. any other value is a rate relative to normal viewing. so 2 means twice the normal rate ("fast forward") โฉ, and 0.5 means half โช. put another way, a ratio of 2 makes normal play time run at twice the wallclock rate: every second of real time delivers 2 seconds of content ๐. a negative value means reverse direction ๐.
unless the Speed parameter asks for something different, the data rate SHOULD not be changed ๐ โโ๏ธ. how scale changes actually work depends on the server and the media type ๐๏ธ. for video, a server might deliver only key frames or selected key frames ๐ผ๏ธ. for audio, it could time-scale the audio while keeping the pitch, or (less ideal) deliver fragments of audio ๐ง.
the server should try to approximate the viewing rate, but it's allowed to limit the range of scale values it supports ๐ค. the response MUST contain the actual scale value the server chose ๐ฏ.
if the request has a Range parameter, the new scale value takes effect at that time โฏ๏ธ.
Scale = "Scale" ":" [ "-" ] 1*DIGIT [ "." *DIGIT ]
Example of playing in reverse at 3.5 times normal rate:
Scale: -3.5
12.35 Speed ๐๏ธ
this request header's parameter asks the server to deliver data to the client at a particular speed ๐จ. whether that happens depends on the server being able and willing to serve the stream at that speed. implementing this is OPTIONAL for the server ๐ซถ. the default is the bit rate of the stream ๐.
the parameter is a decimal ratio. a value of 2.0 means data should arrive twice as fast as normal ๐. a speed of zero is invalid ๐ซ. if the request has a Range parameter, the new speed takes effect at that time โฑ๏ธ.
Speed = "Speed" ":" 1*DIGIT [ "." *DIGIT ]
Example:
Speed: 2.5
using this field changes the bandwidth for data delivery ๐ถ. it's meant for specific situations where you want to preview the presentation faster or slower ๐. implementors should keep in mind that session bandwidth may have been negotiated beforehand (by means other than RTSP), so renegotiation might be needed ๐ค. when data goes over UDP, it is highly recommended to use something like RTCP to track packet loss rates ๐.
12.36 Server ๐
see [H14.39]
12.37 Session ๐
this request and response header identifies an RTSP session. the media server starts it in a SETUP response, and it ends with TEARDOWN on the presentation URL ๐. the media server picks the session identifier (see Section 3.4) ๐. once a client has a Session identifier, it MUST return it for any request related to that session ๐๏ธ. a server doesn't have to set up a session identifier if it already has other ways to identify a session, like dynamically generated URLs ๐.
Session = "Session" ":" session-id [ ";" "timeout" "=" delta-seconds ]
the timeout parameter is only allowed in a response header โณ. the server uses it to tell the client how long it will wait between RTSP commands before it closes the session for inactivity (see Section A) ๐ค. the timeout is measured in seconds, and the default is 60 seconds (1 minute) โฒ๏ธ.
a session identifier identifies an RTSP session across transport sessions or connections ๐. one RTSP session can carry control messages for more than one RTSP URL ๐งฉ. so clients can use the same session to control lots of streams that make up one presentation, as long as they all come from the same server (see example in Section 14) ๐ฌ. however, multiple "user" sessions for the same URL from the same client MUST use different session identifiers ๐ โโ๏ธ.
the session identifier is what lets the server tell apart several delivery requests for the same URL coming from the same client ๐ต๏ธโโ๏ธ.
a 454 (Session Not Found) response is returned if the session identifier is invalid ๐.
12.38 Timestamp โญ
the Timestamp general header tells the server when the client sent the request โฐ. the value only matters to the client, and it can use any timescale it likes ๐ง . the server MUST echo back the exact same value. if the server has accurate information about it, the server MAY also add a floating point number for how many seconds have passed since it got the request ๐งฎ. clients use this to compute round-trip time to the server, so they can tune their retransmission timeouts ๐.
Timestamp = "Timestamp" ":" *(DIGIT) [ "." *(DIGIT) ] [ delay ]
delay = *(DIGIT) [ "." *(DIGIT) ]
12.39 Transport ๐
okay bestie, this one is the big boss ๐ Transport tells the server which transport protocol to use and sets the knobs for a single stream: destination address, compression, multicast time-to-live, destination port, all of it. It only fills in the values that a presentation description hasn't already decided ๐
Transports are comma separated and listed in order of preference. You can tack parameters onto each transport with a semicolon ๐
The Transport header MAY also be used to change certain transport parameters. A server MAY refuse to change parameters of an existing stream ๐
The server MAY return a Transport response header in the response to show the values it actually chose โจ
If a Transport request header lists several transport options the client can accept, the server MUST return a single option, the one it actually chose. Only one! ๐
The syntax for the transport specifier is:
transport/profile/lower-transport.
The default for the "lower-transport" parameter depends on the profile. For RTP/AVP, it's UDP ๐ฆ
Here are the configuration parameters for transport ๐
General parameters:
unicast | multicast: these two are mutually exclusive. They say whether unicast or multicast delivery will be attempted, and multicast is the default. Clients that can handle both MUST show that by including two full transport-specs with separate parameters for each one ๐
destination: this is the address the stream gets sent to. The client can name a multicast address here. Now, the lowkey scary part: to avoid becoming the unwitting perpetrator of a remote-controlled denial-of-service attack, a server SHOULD authenticate the client and SHOULD log those attempts before it lets the client send a media stream to an address the server didn't pick itself. This matters a LOT if RTSP commands go over UDP, and implementations can't lean on TCP as reliable client identification all by itself ๐ A server SHOULD not allow a client to point media streams at an address that's different from the address the commands are coming from.
source: if the stream's source address is different from what can be derived from the RTSP endpoint address (the server in playback, or the client in recording), the source MAY be specified ๐ง
This information may also be available through SDP. However, since this is more a feature of transport than media initialization, the authoritative source for this information should be in the SETUP response. Main character rule: SETUP is the source of truth ๐
layers: the number of multicast layers used for this media stream. The layers go to consecutive addresses, starting at the destination address ๐
mode: this one says which methods are supported for the session. Valid values are PLAY and RECORD. If it's not provided, the default is PLAY โถ๏ธ
append: if mode includes RECORD, append says the media data should be added to the existing resource instead of overwriting it. If someone asks for appending and the server can't do it, the server MUST refuse the request instead of overwriting the resource at the URI. The append parameter gets ignored if mode doesn't include RECORD ๐ โโ๏ธ
interleaved: this one mixes the media stream into the control stream, using whatever protocol the control stream is already using, via the mechanism in Section 10.12. The argument is the channel number used in the $ statement, and it can be a range like interleaved=4-5 when the media transport needs one ๐ธ That lets RTP/RTCP get handled kind of like it does over UDP, with one channel for RTP and another for RTCP.
Multicast specific:
ttl: multicast time-to-live ๐ซถ
RTP Specific:
port: the RTP/RTCP port pair for a multicast session, written as a range like port=3456-3457 ๐
client_port: the unicast RTP/RTCP port pair the client picked to receive media data and control info, also a range like client_port=3456-3457 ๐
server_port: the unicast RTP/RTCP port pair the server picked to receive media data and control info, also a range like server_port=3456-3457 โจ
ssrc: the RTP SSRC [24, Sec. 3] value the media server should use (in a request) or will use (in a response). This only works for unicast transmission, and it identifies the synchronization source for the media stream ๐ฆ
Here's the grammar, verbatim:
Transport = "Transport" ":"
1\#transport-spec
transport-spec = transport-protocol/profile[/lower-transport]
*parameter
transport-protocol = "RTP"
profile = "AVP"
lower-transport = "TCP" | "UDP"
parameter = ( "unicast" | "multicast" )
| ";" "destination" [ "=" address ]
| ";" "interleaved" "=" channel [ "-" channel ]
| ";" "append"
| ";" "ttl" "=" ttl
| ";" "layers" "=" 1*DIGIT
| ";" "port" "=" port [ "-" port ]
| ";" "client_port" "=" port [ "-" port ]
| ";" "server_port" "=" port [ "-" port ]
| ";" "ssrc" "=" ssrc
| ";" "mode" = <"> 1\#mode <">
ttl = 1*3(DIGIT)
port = 1*5(DIGIT)
ssrc = 8*8(HEX)
channel = 1*3(DIGIT)
address = host
mode = <"> *Method <"> | Method
Example:
Transport: RTP/AVP;multicast;ttl=127;mode="PLAY",
RTP/AVP;unicast;client_port=3456-3457;mode="PLAY"
The Transport header is restricted to describing a single RTP stream. (RTSP can also control multiple streams as a single entity.) Keeping it inside RTSP, instead of relying on a bunch of different session description formats, makes firewalls way easier to design ๐งฑโจ
12.40 Unsupported ๐ โโ๏ธ
The Unsupported response header lists the features the server doesn't support. If the feature was requested through the Proxy-Require field (Section 12.32) and there's a proxy between the client and the server, the proxy MUST insert a message reply with the error message "551 Option Not Supported" ๐ญ
See Section 12.32 for a usage example ๐
12.41 User-Agent ๐ธ
See [H14.42] ๐ซถ
12.42 Vary ๐
See [H14.43] ๐ง
12.43 Via ๐ฆ
See [H14.44]. ๐
12.44 WWW-Authentica ๐
See [H14.46]. ๐
13 Caching ๐
okay so in HTTP, response-request pairs get cached. RTSP is different. Responses aren't cacheable, with one exception: the presentation description returned by DESCRIBE or included with ANNOUNCE. (Since the responses to anything other than DESCRIBE and GET_PARAMETER don't return any data, caching isn't really a thing for those requests, lol.) The continuous media data, though, which is usually delivered out-of-band from RTSP, is something people want cached, and so is the session description โจ
When a proxy gets a SETUP or PLAY request, it figures out whether it has an up-to-date copy of the continuous media and its description. It checks by sending a SETUP or DESCRIBE request, respectively, and comparing the Last-Modified header with the cached copy's. If the copy is stale, the proxy adjusts the SETUP transport parameters as needed and forwards the request to the origin server. After that, control commands like PLAY or PAUSE just pass straight through the proxy unchanged. The proxy delivers the media data to the client, and it may keep a local copy for later reuse ๐ The exact behavior the cache is allowed to have is set by the cache-response directives in Section 12.8. A cache MUST answer any DESCRIBE requests if it's currently serving the stream to the requestor, because the low-level details of the stream description might have changed on the origin server ๐
Note that an RTSP cache is a "cut-through" kind, unlike the HTTP cache. Instead of pulling the whole resource from the origin server, the cache just copies the streaming data as it goes by on its way to the client. So it doesn't add any extra latency ๐
To the client, an RTSP proxy cache looks like a regular media server. To the media origin server, it looks like a client ๐ช Just like an HTTP cache has to store the content type, content language, and so on for the objects it caches, a media cache has to store the presentation description. Usually a cache strips out all the transport references (that's the multicast info), since those don't matter for delivery from the cache to the client. The encoding info stays the same. If the cache can translate the cached media data, it creates a new presentation description listing all the encoding possibilities it can offer ๐
14 Examples ๐ฌ
The following examples refer to stream description formats that aren't standards, like RTSL. They're not meant to be used as a reference for those formats, so don't copy them as if they were ๐
14.1 Media on Demand (Unicast) ๐ฌ
okay so client C wants a movie from two media servers, A (audio.example.com) and V (video.example.com). The media description lives on a web server called W. It's giving full itinerary: the presentation details, every stream, the codecs on offer, dynamic RTP payload types, the protocol stack, and content info like language or copyright restrictions. It may also hint at the movie's timeline ๐
In this example, the client only wants the last part of the movie ๐ฟ
C->W: GET /twister.sdp HTTP/1.1
Host: www.example.com
Accept: application/sdp
W->C: HTTP/1.0 200 OK
Content-Type: application/sdp
v=0
o=- 2890844526 2890842807 IN IP4 192.16.24.202
s=RTSP Session
m=audio 0 RTP/AVP 0
a=control:rtsp://audio.example.com/twister/audio.en
m=video 0 RTP/AVP 31
a=control:rtsp://video.example.com/twister/video
C->A: SETUP rtsp://audio.example.com/twister/audio.en RTSP/1.0
CSeq: 1
Transport: RTP/AVP/UDP;unicast;client_port=3056-3057
A->C: RTSP/1.0 200 OK
CSeq: 1
Session: 12345678
Transport: RTP/AVP/UDP;unicast;client_port=3056-3057;
server_port=5000-5001
C->V: SETUP rtsp://video.example.com/twister/video RTSP/1.0
CSeq: 1
Transport: RTP/AVP/UDP;unicast;client_port=3058-3059
V->C: RTSP/1.0 200 OK
CSeq: 1
Session: 23456789
Transport: RTP/AVP/UDP;unicast;client_port=3058-3059;
server_port=5002-5003
C->V: PLAY rtsp://video.example.com/twister/video RTSP/1.0
CSeq: 2
Session: 23456789
Range: smpte=0:10:00-
V->C: RTSP/1.0 200 OK
CSeq: 2
Session: 23456789
Range: smpte=0:10:00-0:20:00
RTP-Info: url=rtsp://video.example.com/twister/video;
seq=12312232;rtptime=78712811
C->A: PLAY rtsp://audio.example.com/twister/audio.en RTSP/1.0
CSeq: 2
Session: 12345678
Range: smpte=0:10:00-
A->C: RTSP/1.0 200 OK
CSeq: 2
Session: 12345678
Range: smpte=0:10:00-0:20:00
RTP-Info: url=rtsp://audio.example.com/twister/audio.en;
seq=876655;rtptime=1032181
C->A: TEARDOWN rtsp://audio.example.com/twister/audio.en RTSP/1.0
CSeq: 3
Session: 12345678
A->C: RTSP/1.0 200 OK
CSeq: 3
C->V: TEARDOWN rtsp://video.example.com/twister/video RTSP/1.0
CSeq: 3
Session: 23456789
V->C: RTSP/1.0 200 OK
CSeq: 3
Even though the audio and video tracks are on two different servers, and may start at slightly different times and may drift with respect to each other, the client can synchronize the two using standard RTP methods, in particular the time scale contained in the RTCP sender reports. that's the iconic part ๐ซถโจ
14.2 Streaming of a Container file ๐ฆ
For purposes of this example, a container file is a storage entity in which multiple continuous media types pertaining to the same end-user presentation are present. basically the container file represents an RTSP presentation, and each of its components is an RTSP stream. Container files are a widely used way to store these presentations ๐ธ While the components are transported as independent streams, it is desirable to maintain a common context for those streams at the server end.
This enables the server to keep a single storage handle open easily. It also allows treating all the streams equally in case of any prioritization of streams by the server.
It's also possible that the presentation author wants to prevent the client from selectively retrieving streams, to preserve the artistic effect of the combined media presentation ๐ญ Similarly, in such a tightly bound presentation, it is desirable to be able to control all the streams via a single control message using an aggregate URL.
The following is an example of using a single RTSP session to control multiple streams. It also illustrates the use of aggregate URLs ๐ง
Client C requests a presentation from media server M. The movie is stored in a container file, and the client has obtained an RTSP URL to that container file.
C->M: DESCRIBE rtsp://foo/twister RTSP/1.0
CSeq: 1
M->C: RTSP/1.0 200 OK
CSeq: 1
Content-Type: application/sdp
Content-Length: 164
v=0
o=- 2890844256 2890842807 IN IP4 172.16.2.93
s=RTSP Session
i=An Example of RTSP Session Usage
a=control:rtsp://foo/twister
t=0 0
m=audio 0 RTP/AVP 0
a=control:rtsp://foo/twister/audio
m=video 0 RTP/AVP 26
a=control:rtsp://foo/twister/video
C->M: SETUP rtsp://foo/twister/audio RTSP/1.0
CSeq: 2
Transport: RTP/AVP;unicast;client_port=8000-8001
M->C: RTSP/1.0 200 OK
CSeq: 2
Transport: RTP/AVP;unicast;client_port=8000-8001;
server_port=9000-9001
Session: 12345678
C->M: SETUP rtsp://foo/twister/video RTSP/1.0
CSeq: 3
Transport: RTP/AVP;unicast;client_port=8002-8003
Session: 12345678
M->C: RTSP/1.0 200 OK
CSeq: 3
Transport: RTP/AVP;unicast;client_port=8002-8003;
server_port=9004-9005
Session: 12345678
C->M: PLAY rtsp://foo/twister RTSP/1.0
CSeq: 4
Range: npt=0-
Session: 12345678
M->C: RTSP/1.0 200 OK
CSeq: 4
Session: 12345678
RTP-Info: url=rtsp://foo/twister/video;
seq=9810092;rtptime=3450012
C->M: PAUSE rtsp://foo/twister/video RTSP/1.0
CSeq: 5
Session: 12345678
M->C: RTSP/1.0 460 Only aggregate operation allowed
CSeq: 5
C->M: PAUSE rtsp://foo/twister RTSP/1.0
CSeq: 6
Session: 12345678
M->C: RTSP/1.0 200 OK
CSeq: 6
Session: 12345678
C->M: SETUP rtsp://foo/twister RTSP/1.0
CSeq: 7
Transport: RTP/AVP;unicast;client_port=10000
M->C: RTSP/1.0 459 Aggregate operation not allowed
CSeq: 7
In the first instance of failure, the client tries to pause one stream (in this case, video) of the presentation. The server disallows this for that presentation. In the second instance, the aggregate URL may not be used for SETUP, and one control message is required per stream to set up transport parameters ๐
This keeps the syntax of the Transport header simple and allows easy parsing of transport information by firewalls.
14.3 Single Stream Container Files ๐ง
Some RTSP servers may treat all files as though they are "container files", yet other servers may not support such a concept. Because of this, clients SHOULD use the rules set forth in the session description for request URLs, rather than assuming that a consistent URL may always be used throughout. Here's an example of how a multi-stream server might expect a single-stream file to be served:
Accept: application/x-rtsp-mh, application/sdp
CSeq: 1
S->C RTSP/1.0 200 OK
CSeq: 1
Content-base: rtsp://foo.com/test.wav/
Content-type: application/sdp
Content-length: 48
v=0
o=- 872653257 872653257 IN IP4 172.16.2.187
s=mu-law wave file
i=audio test
t=0 0
m=audio 0 RTP/AVP 0
a=control:streamid=0
C->S SETUP rtsp://foo.com/test.wav/streamid=0 RTSP/1.0
Transport: RTP/AVP/UDP;unicast;
client_port=6970-6971;mode=play
CSeq: 2
S->C RTSP/1.0 200 OK
Transport: RTP/AVP/UDP;unicast;client_port=6970-6971;
server_port=6970-6971;mode=play
CSeq: 2
Session: 2034820394
C->S PLAY rtsp://foo.com/test.wav RTSP/1.0
CSeq: 3
Session: 2034820394
S->C RTSP/1.0 200 OK
CSeq: 3
Session: 2034820394
RTP-Info: url=rtsp://foo.com/test.wav/streamid=0;
seq=981888;rtptime=3781123
Note the different URL in the SETUP command, and then the switch back to the aggregate URL in the PLAY command. This makes complete sense when there are multiple streams with aggregate control, but it's less than intuitive in the special case where the number of streams is one ๐ค
In this special case, it is recommended that servers be forgiving of implementations that send:
C->S PLAY rtsp://foo.com/test.wav/streamid=0 RTSP/1.0
CSeq: 3
In the worst case, servers should send back:
S->C RTSP/1.0 460 Only aggregate operation allowed
CSeq: 3
One would also hope that server implementations are forgiving of the following:
C->S SETUP rtsp://foo.com/test.wav RTSP/1.0
Transport: rtp/avp/udp;client_port=6970-6971;mode=play
CSeq: 2
Since there is only a single stream in this file, it's not ambiguous what this means โจ
14.4 Live Media Presentation Using Multicast ๐ก
The media server M chooses the multicast address and port. Here, we assume that the web server only contains a pointer to the full description, while the media server M maintains the full description ๐
C->W: GET /concert.sdp HTTP/1.1
Host: www.example.com
W->C: HTTP/1.1 200 OK
Content-Type: application/x-rtsl
<session>
<track src="rtsp://live.example.com/concert/audio">
</session>
C->M: DESCRIBE rtsp://live.example.com/concert/audio RTSP/1.0
CSeq: 1
M->C: RTSP/1.0 200 OK
CSeq: 1
Content-Type: application/sdp
Content-Length: 44
v=0
o=- 2890844526 2890842807 IN IP4 192.16.24.202
s=RTSP Session
m=audio 3456 RTP/AVP 0
a=control:rtsp://live.example.com/concert/audio
c=IN IP4 224.2.0.1/16
C->M: SETUP rtsp://live.example.com/concert/audio RTSP/1.0
CSeq: 2
Transport: RTP/AVP;multicast
M->C: RTSP/1.0 200 OK
CSeq: 2
Transport: RTP/AVP;multicast;destination=224.2.0.1;
port=3456-3457;ttl=16
Session: 0456804596
C->M: PLAY rtsp://live.example.com/concert/audio RTSP/1.0
CSeq: 3
Session: 0456804596
M->C: RTSP/1.0 200 OK
CSeq: 3
Session: 0456804596
14.5. Playing media into an existing session โจ
Okay so picture this: a conference participant C wants the media server M to play a demo tape into a session that already exists ๐ฌ. C tells the server that the network addresses and encryption keys were already handed out by the conference, so the server should NOT pick new ones ๐ โโ๏ธ. (Lowercase "should" here is just the vibe, it's not a hard rule.) The example skips the simple ACK responses, so no need to panic about those ๐ .
C->M: DESCRIBE rtsp://server.example.com/demo/548/sound RTSP/1.0
CSeq: 1
Accept: application/sdp
M->C: RTSP/1.0 200 1 OK
Content-type: application/sdp
Content-Length: 44
v=0
o=- 2890844526 2890842807 IN IP4 192.16.24.202
s=RTSP Session
i=See above
t=0 0
m=audio 0 RTP/AVP 0
C->M: SETUP rtsp://server.example.com/demo/548/sound RTSP/1.0
CSeq: 2
Transport: RTP/AVP;multicast;destination=225.219.201.15;
port=7000-7001;ttl=127
Conference: 199702170042.SAA08642@obiwan.arl.wustl.edu%20Starr
M->C: RTSP/1.0 200 OK
CSeq: 2
Transport: RTP/AVP;multicast;destination=225.219.201.15;
port=7000-7001;ttl=127
Session: 91389234234
Conference: 199702170042.SAA08642@obiwan.arl.wustl.edu%20Starr
C->M: PLAY rtsp://server.example.com/demo/548/sound RTSP/1.0
CSeq: 3
Session: 91389234234
M->C: RTSP/1.0 200 OK
CSeq: 3
14.6. Recording ๐๏ธ
Next up, the conference participant client C asks the media server M to record the audio and video parts of a meeting ๐ฅ. To give the server some context, the client uses the ANNOUNCE method to send meta-information about the recorded session first. Very organised, very iconic ๐.
C->M: ANNOUNCE rtsp://server.example.com/meeting RTSP/1.0
CSeq: 90
Content-Type: application/sdp
Content-Length: 121
v=0
o=camera1 3080117314 3080118787 IN IP4 195.27.192.36
s=IETF Meeting, Munich - 1
i=The thirty-ninth IETF meeting will be held in Munich, Germany
u=http://www.ietf.org/meetings/Munich.html
e=IETF Channel 1 <ietf39-mbone@uni-koeln.de>
p=IETF Channel 1 +49-172-2312 451
c=IN IP4 224.0.1.11/127
t=3080271600 3080703600
a=tool:sdr v2.4a6
a=type:test
m=audio 21010 RTP/AVP 5
c=IN IP4 224.0.1.11/127
a=ptime:40
m=video 61010 RTP/AVP 31
c=IN IP4 224.0.1.12/127
M->C: RTSP/1.0 200 OK
CSeq: 90
C->M: SETUP rtsp://server.example.com/meeting/audiotrack RTSP/1.0
CSeq: 91
Transport: RTP/AVP;multicast;destination=224.0.1.11;
port=21010-21011;mode=record;ttl=127
M->C: RTSP/1.0 200 OK
CSeq: 91
Session: 50887676
Transport: RTP/AVP;multicast;destination=224.0.1.11;
port=21010-21011;mode=record;ttl=127
C->M: SETUP rtsp://server.example.com/meeting/videotrack RTSP/1.0
CSeq: 92
Session: 50887676
Transport: RTP/AVP;multicast;destination=224.0.1.12;
port=61010-61011;mode=record;ttl=127
M->C: RTSP/1.0 200 OK
CSeq: 92
Transport: RTP/AVP;multicast;destination=224.0.1.12;
port=61010-61011;mode=record;ttl=127
C->M: RECORD rtsp://server.example.com/meeting RTSP/1.0
CSeq: 93
Session: 50887676
Range: clock=19961110T1925-19961110T2015
M->C: RTSP/1.0 200 OK
CSeq: 93
15. Syntax ๐งฉ
Time for the grammar bit, bestie, and yes it's a bit nerdy but it's also kind of beautiful ๐ค๐ซถ. The RTSP syntax is written in an augmented Backus-Naur form (BNF), the same style used in RFC 2068 [2].
15.1. Base Syntax
Here are the building blocks everything else gets built from ๐งฑ:
OCTET = <any 8-bit sequence of data>
CHAR = <any US-ASCII character (octets 0 - 127)>
UPALPHA = <any US-ASCII uppercase letter "A".."Z">
LOALPHA = <any US-ASCII lowercase letter "a".."z">
ALPHA = UPALPHA | LOALPHA
DIGIT = <any US-ASCII digit "0".."9">
CTL = <any US-ASCII control character
(octets 0 - 31) and DEL (127)>
CR = <US-ASCII CR, carriage return (13)>
LF = <US-ASCII LF, linefeed (10)>
SP = <US-ASCII SP, space (32)>
HT = <US-ASCII HT, horizontal-tab (9)>
<"> = <US-ASCII double-quote mark (34)>
CRLF = CR LF
LWS = [CRLF] 1*( SP | HT )
TEXT = <any OCTET except CTLs>
tspecials = "(" | ")" | "<" | ">" | "@"
| "," | ";" | ":" | "\" | <">
| "/" | "[" | "]" | "?" | "="
| "{" | "}" | SP | HT
token = 1*<any CHAR except CTLs or tspecials>
quoted-string = ( <"> *(qdtext) <"> )
qdtext = <any TEXT except <">>
quoted-pair = "\" CHAR
message-header = field-name ":" [ field-value ] CRLF
field-name = token
field-value = *( field-content | LWS )
field-content = <the OCTETs making up the field-value and
consisting of either *TEXT or
combinations of token, tspecials, and
quoted-string>
safe = "\$" | "-" | "_" | "." | "+"
extra = "!" | "*" | "$'$" | "(" | ")" | ","
hex = DIGIT | "A" | "B" | "C" | "D" | "E" | "F" |
"a" | "b" | "c" | "d" | "e" | "f"
escape = "\%" hex hex
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "="
unreserved = alpha | digit | safe | extra
xchar = unreserved | reserved | escape
16. Security Considerations ๐
Okay bestie, this section is SERIOUS ๐ค. Read it like your passwords depend on it, because they kind of do ๐.
Here's the big picture: RTSP servers and HTTP servers look and act a lot alike, so the security advice from [H15] applies to RTSP too ๐ค. Here are the specifics, in order:
Authentication Mechanisms: RTSP and HTTP share common authentication schemes, so they should follow the same rules for authentication ๐. Check [H15.1] for client authentication issues and [H15.2] for issues about supporting multiple authentication mechanisms.
Abuse of Server Log Information: RTSP and HTTP servers will probably have similar logging, so they should be just as careful about protecting those logs, which keeps the users of the servers private ๐. For HTTP server advice on logs, see [H15.3].
Transfer of Sensitive Information: There's no reason to think information sent over RTSP is any less sensitive than what normally goes over HTTP ๐ฌ. So every precaution about data privacy and user privacy applies to RTSP clients, servers, and proxies. See [H15.4] for the full details.
Attacks Based On File and Path Names: RTSP URLs are opaque handles and don't have to mean anything to a file system ๐๏ธ. But lots of implementations will map parts of request URLs straight onto file system calls. In those cases, file systems SHOULD follow the precautions in [H15.5], such as checking for ".." in path components. Don't let a sneaky .. run away with your files, bestie ๐โโ๏ธ.
Personal Information: RTSP clients often know the same stuff HTTP clients do (user name, location, and so on), so they should be just as careful with it. See [H15.6] for more recommendations ๐ง.
Privacy Issues Connected to Accept Headers: Lots of the same "Accept" headers exist in RTSP as in HTTP, so the same caveats from [H15.7] about how to use them should be followed ๐ซง.
DNS Spoofing: Since RTSP sessions usually last longer than HTTP sessions, RTSP client DNS optimizations should be less common ๐. Still, the advice in [H15.8] is relevant to any implementation that tries to keep a DNS-to-IP mapping around beyond a single use.
Location Headers and Spoofing: If one server supports several organizations that don't trust each other, it MUST check the values of Location and Content-Location headers in responses generated under those organizations' control. This makes sure they can't try to invalidate resources they have no authority over ([H15.9]) ๐ซ.
Beyond that, the current HTTP specification still applies (RFC 2068 [2], as of this writing), and future HTTP specifications may give more guidance on security issues too ๐ฎ.
Next are the extra considerations just for RTSP implementations ๐ฆ.
Concentrated denial-of-service attack: RTSP can be used for a remote-controlled denial-of-service attack ๐ฑ. An attacker can send traffic flows to one or more IP addresses by naming them as the destination in SETUP requests. The attacker's IP address might be known here, but that doesn't always help stop more attacks or figure out who the attacker is. So an RTSP server SHOULD only allow client-specified destinations for RTSP-initiated traffic flows if the server has verified the client's identity, either against a database of known users using RTSP authentication mechanisms (preferably digest authentication or stronger), or by other secure means ๐ก๏ธ.
Session hijacking: A transport layer connection and an RTSP session aren't linked to each other, so a malicious client could send requests with random session identifiers and mess with unsuspecting clients ๐. The server SHOULD use a large, random and non-sequential session identifier to make this kind of attack less likely ๐ฒ.
Authentication: Servers SHOULD implement both basic and digest [8] authentication ๐. If the control messages need tighter security, the RTSP control stream may be encrypted ๐.
Stream issues: RTSP only handles stream control. Stream delivery issues aren't covered in this section, or anywhere else in this memo ๐ก. RTSP implementations will most likely rely on other protocols such as RTP, IP multicast, RSVP and IGMP, so they should also deal with the security considerations raised in those and other applicable specifications ๐ง .
Persistently suspicious behavior: RTSP servers SHOULD return error code 403 (Forbidden) the first time they see behaviour that counts as a security risk ๐จ. RTSP servers SHOULD also watch out for attempts to probe the server for weaknesses and entry points, and MAY arbitrarily disconnect and ignore further requests from clients that break local security policy ๐ โโ๏ธ๐ .
Appendix A: RTSP Protocol State Machines โจ
okay so this appendix is the state machine tour ๐ฆ the client and server state machines basically narrate the whole RTSP journey, from session initialization all the way to session termination ๐
state is tracked per object ๐ง an object is uniquely identified by the stream URL plus the RTSP session identifier. aggregate URLs (presentations made of multiple streams) affect the state of every stream inside them. so if the presentation /movie has /movie/audio and /movie/video, this request:
PLAY rtsp://foo.com/movie RTSP/1.0
CSeq: 559
Session: 12345678
hits the states of both movie/audio and movie/video ๐ฌ
this example does NOT imply a standard way to represent streams in URLs or any link to the filesystem. see Section 3.2 ๐
also, OPTIONS, ANNOUNCE, DESCRIBE, GET_PARAMETER, and SET_PARAMETER have zero effect on client or server state, so they're not in the tables ๐
A.1 Client State Machine
the client can be in these states:
- Init: SETUP has been sent, waiting for the reply.
- Ready: a SETUP reply came back, or a PAUSE reply came back while in Playing state.
- Playing: a PLAY reply came back.
- Recording: a RECORD reply came back.
generally, the client switches state when replies arrive ๐ some requests only take effect at a future time or position (like PAUSE), so the state changes at that point too โฐ if no explicit SETUP is needed for the object (for example, it's available through a multicast group), the state starts at Ready. in that case there are only two states, Ready and Playing. the client also goes from Playing or Recording back to Ready once the end of the requested range is reached ๐
the "next state" column is the state you land in after a success response (2xx). a 3xx status moves the client to Init, and a 4xx status changes nothing. messages that aren't listed for a given state MUST NOT be sent by the client in that state, unless they're the ones that don't affect state (the ones listed above) ๐ โโ๏ธ and getting a REDIRECT from the server counts the same as getting a 3xx redirect status ๐
state message sent next state after response
Init SETUP Ready
TEARDOWN Init
Ready PLAY Playing
RECORD Recording
TEARDOWN Init
SETUP Ready
Playing PAUSE Ready
TEARDOWN Init
PLAY Playing
SETUP Playing (changed transport)
Recording PAUSE Ready
TEARDOWN Init
RECORD Recording
SETUP Recording (changed transport)
A.2 Server State Machine
the server can be in these states:
- Init: the starting point, no valid SETUP has been received yet.
- Ready: the last SETUP was successful and its reply was sent, or after playing, the last PAUSE was successful and its reply was sent.
- Playing: the last PLAY was successful and its reply was sent. data is flowing ๐
- Recording: the server is recording media data ๐๏ธ
generally, the server changes state when it receives requests. if the server is in Playing or Recording and it's in unicast mode, it MAY drop back to Init and tear down the RTSP session if it hasn't gotten "wellness" information (like RTCP reports or RTSP commands) from the client for a set interval, which defaults to one minute โณ the server can declare a different timeout value in the Session response header (Section 12.37). if the server is in Ready, it MAY drop back to Init if it doesn't get an RTSP request for more than one minute. some requests (like PAUSE) might take effect at a future time or position, and the server state changes at that moment. the server goes from Playing or Recording back to Ready at the end of the range the client asked for ๐
the REDIRECT message takes effect immediately when sent, unless it has a Range header saying when the redirect kicks in. in that case, the server state also changes at the right time โฐ
if no explicit SETUP is needed for the object, the state starts at Ready and there are only two states, Ready and Playing ๐ฏ
the "next state" column is the state you land in after sending a success response (2xx). a 3xx status sends the state to Init, and a 4xx status results in no change.
state message received next state
Init SETUP Ready
TEARDOWN Init
Ready PLAY Playing
SETUP Ready
TEARDOWN Init
RECORD Recording
Playing PLAY Playing
PAUSE Ready
TEARDOWN Init
SETUP Playing
Recording RECORD Recording
PAUSE Ready
TEARDOWN Init
SETUP Recording
Appendix B: Interaction with RTP ๐ถ
RTSP lets media clients control selected, non-contiguous parts of a presentation, and those streams get rendered by an RTP media layer[24] ๐ง the media layer rendering the RTP stream shouldn't be bothered by jumps in NPT. so both RTP sequence numbers and RTP timestamps MUST stay continuous and monotonic across NPT jumps ๐
let's do an example ๐งฎ say we have a clock frequency of 8000 Hz, a packetization interval of 100 ms, and an initial sequence number and timestamp of zero. first we play NPT 10 through 15, then skip ahead and play NPT 18 through 20. the first segment shows up as RTP packets with sequence numbers 0 through 49 and timestamps 0 through 39,200. the second segment is RTP packets with sequence numbers 50 through 69, with timestamps 40,000 through 55,200 โจ
we can't assume the RTSP client can talk to the RTP media agent, since the two might be totally separate processes ๐ if the RTP timestamp shows the same gap as the NPT, the media agent will think the presentation just paused โธ๏ธ and if the NPT jump is big enough, the RTP timestamp can roll over, and then the media agent might think later packets are duplicates of ones it just played out ๐ฑ
for certain datatypes, the RTSP layer and the RTP layer need to be tightly integrated. that doesn't cancel out the restriction above ๐คทโโ๏ธ combined RTSP/RTP media clients should use the RTP-Info field to figure out whether incoming RTP packets were sent before or after a seek ๐
for continuous audio, the server SHOULD set the RTP marker bit at the start of serving a new PLAY request ๐ that lets the client do playout delay adaptation ๐๏ธ
for scaling (see Section 12.34), RTP timestamps should line up with the playback timing ๐๏ธ for example, say you're playing video recorded at 30 frames/second at a scale of two, and a speed (Section 12.35) of one. the server would drop every second frame so it can keep delivering video packets with the normal timestamp spacing of 3,000 per frame, but NPT goes up by 1/15 second for each video frame it shows โฉ
the client can keep a correct display of NPT by noting the RTP timestamp value of the first packet that arrives after repositioning ๐ and the sequence parameter of the RTP-Info header (Section 12.33) gives you the first sequence number of the next segment ๐งฉ
Appendix C: Use of SDP for RTSP Session Descriptions ๐
the Session Description Protocol (SDP, RFC 2327 [6]) can be used to describe streams or presentations in RTSP ๐ this usage is limited to spelling out the means of access and the encoding(s) for:
- aggregate control: a presentation made of streams from one or more servers that aren't available for aggregate control. this kind of description is usually fetched over HTTP or some other non-RTSP method. they can also show up through ANNOUNCE methods ๐
- non-aggregate control: a presentation made of multiple streams from a single server that ARE available for aggregate control. this description usually comes back in reply to a DESCRIBE request on a URL, or arrives in an ANNOUNCE method ๐จ
this appendix explains how an SDP file (say, one fetched through HTTP) decides how an RTSP session behaves ๐๏ธ it also explains how a client should read SDP content returned in reply to a DESCRIBE request. the tricky bit: SDP has no way for a client to tell, without a human's help, the difference between several media streams that should be rendered at the same time and a set of alternatives (like two audio streams in different languages) ๐๐ฃ๏ธ
C.1 Definitions
the terms "session-level", "media-level", and other key/attribute names and values used in this appendix are meant to be used as defined in SDP (RFC 2327 [6]): ๐
C.1.1 Control URL
the a=control: attribute carries the control URL ๐ it's used at both the session and media levels. when it's used for an individual media stream, it gives the URL to use for controlling that particular stream. when it's found at the session level, it gives the URL for aggregate control ๐ฏ
Example:
a=control:rtsp://example.com/foo
this attribute can hold either relative or absolute URLs, following the rules and conventions set out in RFC 1808 [25] ๐งญ implementations should look for a base URL in this order:
- The RTSP
Content-Basefield - The RTSP
Content-Locationfield - The RTSP request URL
if the attribute contains only an asterisk (*), the URL is treated like an empty embedded URL, so it inherits the entire base URL โญ
C.1.2 Media streams
the m= field is used to list the streams ๐ all the specified streams are expected to be rendered with proper synchronization ๐ถ if the session is unicast, the port number is just a recommendation from the server to the client. the client still has to include it in its SETUP request, but it may ignore that recommendation ๐คทโโ๏ธ if the server has no preference, it SHOULD set the port number value to zero 0๏ธโฃ
Example:
m=audio 0 RTP/AVP 31
C.1.3 Payload type(s)
the payload type(s) are specified in the m= field ๐ท๏ธ if the payload type is a static one from RFC 1890 [1], no other info is needed. if it's a dynamic payload type, the media attribute rtpmap says what the media is ๐ต the "encoding name" inside the rtpmap attribute can be one of the ones in RFC 1890 (Sections 5 and 6), or an experimental encoding with an X- prefix as specified in SDP (RFC 2327 [6]) ๐งช codec-specific parameters don't go in this field. they go in the fmtp attribute described below ๐
implementors who want to register new encodings should follow the procedure in RFC 1890 [1] ๐ and if the media type doesn't suit the RTP AV profile, it's recommended to create a new profile and use its name in place of RTP/AVP in the m= field ๐
C.1.4 Format-specific parameters โจ
okay so format-specific parameters get passed along with the fmtp media attribute ๐
The syntax of fmtp depends on whichever encoding(s) it's describing, so it's not one-size-fits-all. And ngl, the packetization interval is a different thing: it goes in the ptime attribute ๐
C.1.5 Range of presentation ๐๏ธ
the a=range attribute tells you the total time range of a stored session ๐ (for live sessions, you work out the length from the t and r parameters instead). Unless the presentation has media streams with different durations, range is a session-level attribute. You list the unit first, then the value range. The units and their values come from Section 3.5, 3.6 and 3.7.
Examples:
a=range:npt=0-34.4368
a=range:clock=19971113T2115-19971113T2203
C.1.6 Time of availability โฐ
the t= field MUST contain suitable values for the start and stop times for both aggregate and non-aggregate stream control. This part is so important ๐ญ With aggregate control, the server SHOULD give a stop time that it guarantees the description is valid until, and a start time that's equal to or before the moment the DESCRIBE request arrived. It MAY also use start and stop times of 0, which means the session is always available ๐ง With non-aggregate control, the values should match the real period the session is available, following SDP semantics. They shouldn't depend on other stuff (like how long the web page with the description stays up) to decide that ๐
C.1.7 Connection Information ๐
in SDP, the c= field holds the destination address for the media stream. But for on-demand unicast streams and some multicast streams, the client sets that destination address itself through the SETUP request. So unless the media has a fixed destination address, the c= field should be set to a suitable null value. For addresses of type IP4, that null value is 0.0.0.0 ๐ซถ
C.1.8 Entity Tag ๐ท๏ธ
the optional a=etag attribute identifies a version of the session description. It's opaque to the client, so don't try to read into it ๐ SETUP requests can include this identifier in the If-Match field (see section 12.22) so the session only gets set up if the attribute value still matches the current description. The attribute value is opaque and may contain any character allowed within SDP attribute values.
Example:
a=etag:158bb3e7c7fd62ce67f12b533f06b83a
One could argue that the o= field provides identical functionality. However, it does so in a manner that would put constraints on servers that need to support multiple session description types other than SDP for the same piece of media content. ๐
C.2 Aggregate Control Not Available ๐ โโ๏ธ
if a presentation doesn't support aggregate control and has multiple media sections, each section MUST have its control URL given through the a=control: attribute ๐
Example:
v=0
o=- 2890844256 2890842807 IN IP4 204.34.34.32
s=I came from a web page
t=0 0
c=IN IP4 0.0.0.0
m=video 8002 RTP/AVP 31
a=control:rtsp://audio.com/movie.aud
m=audio 8004 RTP/AVP 3
a=control:rtsp://video.com/movie.vid
Notice that where the control URL sits in the description tells the client it has to set up separate RTSP control sessions to the servers audio.com and video.com ๐ง
It is recommended that an SDP file contains the complete media initialization information even if it is delivered to the media client through non-RTSP means. This is necessary as there is no mechanism to indicate that the client should request more detailed media stream information via DESCRIBE. ๐ธ
C.3 Aggregate Control Available ๐
in this setup, the server has several streams that can all be controlled as one unit ๐ฌ So there are media-level a=control: attributes that give the stream URLs, and a session-level a=control: attribute that works as the request URL for aggregate control. If the media-level URL is relative, you resolve it to an absolute URL following Section C.1.1 above.
If the presentation only has one stream, the media-level a=control: attribute can be left out totally. But if there's more than one stream, each media stream section MUST contain its own a=control attribute โจ
Example:
v=0
o=- 2890844256 2890842807 IN IP4 204.34.34.32
s=I contain
i=<more info>
t=0 0
c=IN IP4 0.0.0.0
a=control:rtsp://example.com/movie/
m=video 8002 RTP/AVP 31
a=control:trackID=1
m=audio 8004 RTP/AVP 3
a=control:trackID=2
In this example, the client is required to set up a single RTSP session to the server. It uses rtsp://example.com/movie/trackID=1 and rtsp://example.com/movie/trackID=2 to set up the video and audio streams, respectively. The URL rtsp://example.com/movie/ controls the whole movie ๐ฟ
Appendix D: Minimal RTSP implementation ๐งฉ
D.1 Client ๐ป
a client implementation MUST be able to do the following:
- Generate the following requests: SETUP, TEARDOWN, and one of PLAY (i.e., a minimal playback client) or RECORD (i.e., a minimal recording client). If RECORD is implemented, ANNOUNCE must be implemented as well.
- Include the following headers in requests: CSeq, Connection, Session, Transport. If ANNOUNCE is implemented, the capability to include headers Content-Language, Content-Encoding, Content-Length, and Content-Type should be as well.
- Parse and understand the following headers in responses: CSeq, Connection, Session, Transport, Content-Language, Content-Encoding, Content-Length, Content-Type. If RECORD is implemented, the Location header must be understood as well. RTP-compliant implementations should also implement RTP-Info.
- Understand the class of each error code received and notify the end-user, if one is present, of error codes in classes 4xx and 5xx. The notification requirement may be relaxed if the end-user explicitly does not want it for one or all status codes.
- Expect and respond to asynchronous requests from the server, such as ANNOUNCE. This does not necessarily mean that it should implement the ANNOUNCE method, merely that it MUST respond positively or negatively to any request received from the server.
Though not required, the following are highly recommended at the time of publication for practical interoperability with initial implementations and/or to be a "good citizen". ๐ซถ
- Implement RTP/AVP/UDP as a valid transport.
- Inclusion of the User-Agent header.
- Understand SDP session descriptions as defined in Appendix C
- Accept media initialization formats (such as SDP) from standard input, command line, or other means appropriate to the operating environment to act as a "helper application" for other applications (such as web browsers).
There may be RTSP applications different from those initially envisioned by the contributors to the RTSP specification for which the requirements above do not make sense. Therefore, the recommendations above serve only as guidelines instead of strict requirements. ๐ท
D.1.1 Basic Playback โถ๏ธ
to support on-demand playback of media streams, the client MUST additionally be able to do the following:
- generate the PAUSE request;
- implement the REDIRECT method, and the Location header.
D.1.2 Authentication-enabled ๐
in order to access media presentations from RTSP servers that require authentication, the client MUST additionally be able to do the following:
- recognize the 401 status code;
- parse and include the WWW-Authenticate header;
- implement Basic Authentication and Digest Authentication.
D.2 Server ๐ฅ๏ธ
a minimal server implementation MUST be able to do the following:
- Implement the following methods: SETUP, TEARDOWN, OPTIONS and either PLAY (for a minimal playback server) or RECORD (for a minimal recording server). If RECORD is implemented, ANNOUNCE should be implemented as well.
- Include the following headers in responses: Connection, Content-Length, Content-Type, Content-Language, Content-Encoding, Transport, Public. The capability to include the Location header should be implemented if the RECORD method is. RTP-compliant implementations should also implement the RTP-Info field.
- Parse and respond appropriately to the following headers in requests: Connection, Session, Transport, Require.
Though not required, the following are highly recommended at the time of publication for practical interoperability with initial implementations and/or to be a "good citizen". ๐ซถ
- Implement RTP/AVP/UDP as a valid transport.
- Inclusion of the Server header.
- Implement the DESCRIBE method.
- Generate SDP session descriptions as defined in Appendix C
There may be RTSP applications different from those initially envisioned by the contributors to the RTSP specification for which the requirements above do not make sense. Therefore, the recommendations above serve only as guidelines instead of strict requirements. ๐ท
D.2.1 Basic Playback โถ๏ธ
to support on-demand playback of media streams, the server MUST additionally be able to do the following:
- Recognize the Range header, and return an error if seeking is not supported.
- Implement the PAUSE method.
In addition, to support commonly-accepted user interface features, the following are highly recommended for on-demand media servers:
- Include and parse the Range header, with NPT units. Implementation of SMPTE units is recommended.
- Include the length of the media presentation in the media initialization information.
- Include mappings from data-specific timestamps to NPT. When RTP is used, the rtptime portion of the RTP-Info field may be used to map RTP timestamps to NPT.
Client implementations may use the presence of length information to determine if the clip is seekable, and visibly disable seeking features for clips for which the length information is unavailable. A common use of the presentation length is to implement a "slider bar" which serves as both a progress indicator and a timeline positioning tool. ๐๏ธ
Mappings from RTP timestamps to NPT are necessary to ensure correct positioning of the slider bar. ๐
D.2.2 Authentication-enabled ๐
in order to correctly handle client authentication, the server MUST additionally be able to do the following:
- Generate the 401 status code when authentication is required for the resource.
- Parse and include the WWW-Authenticate header
- Implement Basic Authentication and Digest Authentication
Appendix E: Authors' Addresses ๐๏ธ
Henning Schulzrinne
Dept. of Computer Science
Columbia University
1214 Amsterdam Avenue
New York, NY 10027
USA
EMail: schulzrinne@cs.columbia.edu
Anup Rao
Netscape Communications Corp.
501 E. Middlefield Road
Mountain View, CA 94043
USA
EMail: anup@netscape.com
Robert Lanphier
RealNetworks
1111 Third Avenue Suite 2900
Seattle, WA 98101
USA
EMail: robla@real.com
Appendix F: Acknowledgements โจ
okay bestie, this memo is built on the original RTSP document that got submitted in October 96 ๐ it also borrowed a bunch of its format and descriptions from HTTP/1.1, which is so iconic of it honestly ๐ซถ
The MMUSIC-WG gave this doc SO many comments, and it literally wouldn't be this good without them ๐ besides the people already mentioned, these lovelies also contributed to the spec ๐ง:
Rahul Agarwal, Torsten Braun, Brent Browning, Bruce Butterfield, Steve Casner, Francisco Cortes, Kelly Djahandari, Martin Dunsmuir, Eric Fleischman, Jay Geagan, Andy Grignon, V. Guruprasad, Peter Haight, Mark Handley, Brad Hefta-Gaub, John K. Ho, Philipp Hoschka, Anne Jones, Anders Klemets, Ruth Lang, Stephanie Leif, Jonathan Lennox, Eduardo F. Llach, Rob McCool, David Oran, Maria Papadopouli, Sujal Patel, Ema Patki, Alagu Periyannan, Igor Plotnikov, Pinaki Shah, David Singer, Jeff Smith, Alexander Sokolsky, Dale Stammen, and John Francis Stracke. ๐๐
References ๐
- [1] Schulzrinne, H., "RTP profile for audio and video conferences with minimal control", RFC 1890, January 1996.
- [2] Fielding, R., Gettys, J., Mogul, J., Nielsen, H., and T. Berners-Lee, "Hypertext transfer protocol - HTTP/1.1", RFC 2068, January 1997.
- [3] Yergeau, F., Nicol, G., Adams, G., and M. Duerst, "Internationalization of the hypertext markup language", RFC 2070, January 1997.
- [4] Bradner, S., "Key words for use in RFCs to indicate requirement levels", BCP 14, RFC 2119, March 1997.
- [5] ISO/IEC, "Information technology - generic coding of moving pictures and associated audio information - part 6: extension for digital storage media and control," Draft International Standard ISO 13818-6, International Organization for Standardization ISO/IEC JTC1/SC29/WG11, Geneva, Switzerland, Nov. 1995.
- [6] Handley, M., and V. Jacobson, "SDP: Session Description Protocol", RFC 2327, April 1998.
- [7] Franks, J., Hallam-Baker, P., and J. Hostetler, "An extension to HTTP: digest access authentication", RFC 2069, January 1997.
- [8] Postel, J., "User Datagram Protocol", STD 6, RFC 768, August 1980.
- [9] Hinden, B. and C. Partridge, "Version 2 of the reliable data protocol (RDP)", RFC 1151, April 1990.
- [10] Postel, J., "Transmission control protocol", STD 7, RFC 793, September 1981.
- [11] H. Schulzrinne, "A comprehensive multimedia control architecture for the Internet," in Proc. International Workshop on Network and Operating System Support for Digital Audio and Video (NOSSDAV), (St. Louis, Missouri), May 1997.
- [12] International Telecommunication Union, "Visual telephone systems and equipment for local area networks which provide a non-guaranteed quality of service," Recommendation H.323, Telecommunication Standardization Sector of ITU, Geneva, Switzerland, May 1996.
- [13] McMahon, P., "GSS-API authentication method for SOCKS version 5", RFC 1961, June 1996.
- [14] J. Miller, P. Resnick, and D. Singer, "Rating services and rating systems (and their machine readable descriptions)," Recommendation REC-PICS-services-961031, W3C (World Wide Web Consortium), Boston, Massachusetts, Oct. 1996.
- [15] J. Miller, T. Krauskopf, P. Resnick, and W. Treese, "PICS label distribution label syntax and communication protocols," Recommendation REC-PICS-labels-961031, W3C (World Wide Web Consortium), Boston, Massachusetts, Oct. 1996.
- [16] Crocker, D. and P. Overell, "Augmented BNF for syntax specifications: ABNF", RFC 2234, November 1997.
- [17] Braden, B., "Requirements for internet hosts - application and support", STD 3, RFC 1123, October 1989.
- [18] Elz, R., "A compact representation of IPv6 addresses", RFC 1924, April 1996.
- [19] Berners-Lee, T., Masinter, L. and M. McCahill, "Uniform resource locators (URL)", RFC 1738, December 1994.
- [20] Yergeau, F., "UTF-8, a transformation format of ISO 10646", RFC 2279, January 1998.
- [22] Braden, B., "T/TCP - TCP extensions for transactions functional specification", RFC 1644, July 1994.
- [22] W. R. Stevens, TCP/IP illustrated: the implementation, vol. 2. Reading, Massachusetts: Addison-Wesley, 1994.
- [23] Schulzrinne, H., Casner, S., Frederick, R. and V. Jacobson, "RTP: a transport protocol for real-time applications", RFC 1889, January 1996.
- [24] Fielding, R., "Relative uniform resource locators", RFC 1808, June 1995.
Full Copyright Statement ๐
Copyright (C) The Internet Society (1998). All Rights Reserved.
This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations, except as needed for the purpose of developing Internet standards in which case the procedures for copyrights defined in the Internet Standards process must be followed, or as required to translate it into languages other than English.
The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns.
This document and the information contained herein is provided on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. ๐ฆ
๐ฆ where this page comes from
- ietf: rfc2326 1998-04
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms