Chapter 2. Real Time Streaming Protocol

Table of Contents

1. Interleaved RTP in RTSP
2. RTSP-in-HTTP tunneling
3. The RTSP stateful parser

While the interleaved transport (see Interleaved RTP in RTSP) allows the RTSP protocol to pass through routers that disallow two-way UDP communication between client and server, this only enables RTSP to work behind firewalls and NAT routers, and does no good to pass through proxied networks.

To work around this problem, Apple introduced a technique called HTTP tunneling, that makes use of some particularities in the most common HTTP proxy implementations (namely, the ability to receive and proxy an indeterminate output) to allow a virtual two-way communication between client and server. [QTSS.pdf]


An RTSP protocol parser is a quite complex piece of software, since it has to cope with a number of possible situations:

To solve this problem, we implement a stateful parser for each of the client's connection. This parser simply ensures that even incomplete communication can be taken care of without having to parse it from the start each time.


With the help of a semi-blocking read to wait for enough data to be read from the socket, when we know the size of the following data, this makes it very suitable for high-performance parsing of partial messages.

The same basic function blocks for the stateful parser are re-used for a stateless sequential parser, optimised for message-oriented protocols such as SCTP (or UDP, that we don't currently implement)