RTSP
Overview
The RTSP protocol starts when a Moonlight user launch an app, and it’s used to exchange information about the next streams (video, audio, control).
RTSP specifications
RTSP messages are plaintext packets of variable size over TCP.
Parsing of RTSP messages has been implemented using a formal PEG (Parsing Expression Grammars) definition; you can find it in parser.hpp.
There are two types of message: request and response
Request message
All messages have the following structure:
-
message: required
-
options: optional, zero or more key value options separated by newline
-
payload: optional, extra unstructured data that needs to be passed.
OPTIONS rtsp://192.168.1.100:48010 RTSP/1.0 (1) CSeq: 1 (2) X-GS-ClientVersion: 14 (3) (4) a=fmtp:97 surround-params=21101 (5)
1 | message: |
2 | option 1 |
3 | option 2 |
4 | empty new line (end of options) |
5 | payload |
Message
The message part is the first line, it’s delimited by the newline character (\r\n
) , and it’s composed by:
-
command: the first string, delimited by
<space>
, the command to be executed on the backend; one of:[OPTIONS, DESCRIBE, SETUP, ANNOUNCE, PLAY]
-
target: the second string, delimited by
<space>
, specifies the ip address and port that is the target of the session. -
protocol: last string, delimited by
<space>
, the RTSP protocol in use.
Response message
Like requests, responses have a message, zero or more options and an optional payload. The main difference is in the format of the message.
You can easily identify a response package by looking at the command part which is always RTSP
.
RTSP/1.0 200 OK (1) CSeq: 1 (2) a=fmtp:97 surround-params=21101 (3)
1 | message |
2 | option |
3 | payload |
Message
Unlike requests a message in a response is composed by different parts:
-
protocol: it’s always
RTSP/*
and it’s the easiest way to discriminate between request and response messages. -
status code: follows the HTTP status codes specification
-
status string: follows the HTTP status codes specification